From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/14945 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Florian Weimer 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 20:57:32 +0100 Message-ID: <8736eiqq1f.fsf@mid.deneb.enyo.de> References: <20191120001522.GA25139@brightrain.aerifal.cx> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="179822"; mail-complaints-to="usenet@blaine.gmane.org" 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: Rich Felker Original-X-From: linux-kernel-owner@vger.kernel.org Wed Nov 20 20:57:38 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 1iXW6b-000i0p-NJ for glk-linux-kernel-4@m.gmane.org; Wed, 20 Nov 2019 20:57:38 +0100 Original-Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727629AbfKTT5g (ORCPT ); Wed, 20 Nov 2019 14:57:36 -0500 Original-Received: from albireo.enyo.de ([37.24.231.21]:58154 "EHLO albireo.enyo.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727085AbfKTT5g (ORCPT ); Wed, 20 Nov 2019 14:57:36 -0500 Original-Received: from [172.17.203.2] (helo=deneb.enyo.de) by albireo.enyo.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) id 1iXW6X-0001jY-1c; Wed, 20 Nov 2019 19:57:33 +0000 Original-Received: from fw by deneb.enyo.de with local (Exim 4.92) (envelope-from ) id 1iXW6W-0006rH-Vv; Wed, 20 Nov 2019 20:57:32 +0100 In-Reply-To: <20191120001522.GA25139@brightrain.aerifal.cx> (Rich Felker's message of "Tue, 19 Nov 2019 19:15:22 -0500") 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:3293209 gmane.linux.file-systems:159613 gmane.linux.lib.musl.general:14945 gmane.linux.nfs:89593 gmane.linux.kernel.cifs:15743 Archived-At: * 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: | 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. 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.