From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14946 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.kernel,gmane.linux.file-systems,gmane.linux.lib.musl.general,gmane.linux.nfs,gmane.linux.kernel.cifs Subject: Re: [musl] getdents64 lost direntries with SMB/NFS and buffer size < unknown threshold Date: Wed, 20 Nov 2019 15:59:13 -0500 Message-ID: <20191120205913.GD16318@brightrain.aerifal.cx> References: <20191120001522.GA25139@brightrain.aerifal.cx> <8736eiqq1f.fsf@mid.deneb.enyo.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="175717"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.5.21 (2010-09-15) Cc: linux-fsdevel@vger.kernel.org, musl@lists.openwall.com, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org To: Florian Weimer Original-X-From: linux-kernel-owner@vger.kernel.org Wed Nov 20 21:59:29 2019 Return-path: Envelope-to: glk-linux-kernel-4@m.gmane.org Original-Received: from vger.kernel.org ([209.132.180.67]) by blaine.gmane.org with esmtp (Exim 4.89) (envelope-from ) id 1iXX4T-000jXG-8c for glk-linux-kernel-4@m.gmane.org; Wed, 20 Nov 2019 21:59:29 +0100 Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726335AbfKTU7S (ORCPT ); Wed, 20 Nov 2019 15:59:18 -0500 Original-Received: from 216-12-86-13.cv.mvl.ntelos.net ([216.12.86.13]:50234 "EHLO brightrain.aerifal.cx" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725306AbfKTU7S (ORCPT ); Wed, 20 Nov 2019 15:59:18 -0500 Original-Received: from dalias by brightrain.aerifal.cx with local (Exim 3.15 #2) id 1iXX4D-0001vK-00; Wed, 20 Nov 2019 20:59:13 +0000 Content-Disposition: inline In-Reply-To: <8736eiqq1f.fsf@mid.deneb.enyo.de> Original-Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Xref: news.gmane.org gmane.linux.kernel:3293247 gmane.linux.file-systems:159617 gmane.linux.lib.musl.general:14946 gmane.linux.nfs:89594 gmane.linux.kernel.cifs:15744 Archived-At: On Wed, Nov 20, 2019 at 08:57:32PM +0100, Florian Weimer wrote: > * Rich Felker: > > > An issue was reported today on the Alpine Linux tracker at > > https://gitlab.alpinelinux.org/alpine/aports/issues/10960 regarding > > readdir results from SMB/NFS shares with musl libc. > > > > After a good deal of analysis, we determined the root cause to be that > > the second and subsequent calls to getdents64 are dropping/skipping > > direntries (that have not yet been deleted) when some entries were > > deleted following the previous call. The issue appears to happen only > > when the buffer size passed to getdents64 is below some threshold > > greater than 2k (the size musl uses) but less than 32k (the size glibc > > uses, with which we were unable to reproduce the issue). > > >From the Gitlab issue: > > while ((dp = readdir(dir)) != NULL) { > unlink(dp->d_name); > ++file_cnt; > } > > I'm not sure that this is valid code to delete the contents of a > directory. It's true that POSIX says this: I think it is. > | If a file is removed from or added to the directory after the most > | recent call to opendir() or rewinddir(), whether a subsequent call > | to readdir() returns an entry for that file is unspecified. ^^^^^^^^^^^^^ POSIX only allows both behaviors (showing or not showing) the entry that was deleted. It does not allow deletion of one entry to cause other entries not to be seen. > But many file systems simply provide not the necessary on-disk data > structures which are need to ensure stable iteration in the face of > modification of the directory. There are hacks, of course, such as > compacting the on-disk directory only on file creation, which solves > the file removal case. > > For deleting an entire directory, that is not really a problem because > you can stick another loop around this while loop which re-reads the > directory after rewinddir. Eventually, it will become empty. This is still a serious problem and affects usage other than deletion of an entire directory. Rich