Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2363056ybc; Wed, 20 Nov 2019 13:00:34 -0800 (PST) X-Google-Smtp-Source: APXvYqzwtfMcQ2XLDJ3QFIG1MAZjwu9UzlOIdizNQq1AiNy3XwThnkEOfeMDYDZR5iPF7L/n2AeP X-Received: by 2002:adf:f4c9:: with SMTP id h9mr6056534wrp.354.1574283634290; Wed, 20 Nov 2019 13:00:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574283634; cv=none; d=google.com; s=arc-20160816; b=KL7TdRSZOLT92rOLGAlIqiu6jhx+RzF5YM3khWxx7tk/5lTpQwz03XR92MMqubqnCd YyPhHxjr7qiwIkxaA+EfbaoxxzUWyEXti3JQMsPJHSrex83Patl4Z76vT6tDqav3cD22 u/LzYMhmGQTxgrkdRRYYtbHAFeGMOp909/Mc+qpB/7bCImSps1J5NkPcGmKo+iR55eU/ r/ygkgtVi/6rBVnpHpvaxzV6y6UUz0hmGCbZeASPzVarPF9mxzeubPXnWEx9cU5AcQjS SfQ8RlpyO+QX6mGno5sjFmiLKDyFmY3W5m6ncGtcr5zYx4YaGhpfyvCXGOqbcqc2e30l m9nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=5ByWjljq2vUmhz1HSwUk3TkwSggkNJOMLzr9syXQIjo=; b=mIyOmfcJLBTDmVrNTuOslNYCK9vMCxXeH01wQ+TiF4Z+vmbwlc+4oBTTHgcREhJmNW h2uJUlddf1DsTGeM/8b2lBoco9lOumV2nGeR2GNhMVi4k19sct9C/b62PnXrTiwJw3iH kdRV2apIkYAZDRXG0OwyfLvM37CBDbCMdqqiGy9WViixNT0SEzF+MSHyuMnfVJZV/T5G yfToZS1hdsbhbij4xB+7OFDyZ4ji4+tMUqUpImtwvLBnnNEyWOsueQyf7SdQHYYL/fA5 9wKYKu/JsO73Db/LEoRe1DVJ7jIZwVXo+nH+WC1ojQ0+SZ182macZHVuBJriNMM/44uf dbPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=libc.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p7si400420edq.227.2019.11.20.12.59.58; Wed, 20 Nov 2019 13:00:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=libc.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726132AbfKTU7S (ORCPT + 99 others); Wed, 20 Nov 2019 15:59:18 -0500 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 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 Date: Wed, 20 Nov 2019 15:59:13 -0500 From: Rich Felker To: Florian Weimer 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 Subject: Re: [musl] getdents64 lost direntries with SMB/NFS and buffer size < unknown threshold 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 Content-Disposition: inline In-Reply-To: <8736eiqq1f.fsf@mid.deneb.enyo.de> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org 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