From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 90121C432C3 for ; Wed, 20 Nov 2019 19:57:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 695EA2186D for ; Wed, 20 Nov 2019 19:57:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727287AbfKTT5g (ORCPT ); Wed, 20 Nov 2019 14:57:36 -0500 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 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 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 From: Florian Weimer To: Rich Felker 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 References: <20191120001522.GA25139@brightrain.aerifal.cx> Date: 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") Message-ID: <8736eiqq1f.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org * 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.