From unknown Tue Jun 17 01:27:38 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#19238 <19238@debbugs.gnu.org> To: bug#19238 <19238@debbugs.gnu.org> Subject: Status: Fully fix du circular warning on bind mounts Reply-To: bug#19238 <19238@debbugs.gnu.org> Date: Tue, 17 Jun 2025 08:27:38 +0000 retitle 19238 Fully fix du circular warning on bind mounts reassign 19238 coreutils submitter 19238 Boris Ranto severity 19238 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 01 04:01:15 2014 Received: (at submit) by debbugs.gnu.org; 1 Dec 2014 09:01:15 +0000 Received: from localhost ([127.0.0.1]:50348 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XvMr3-0005nG-Sv for submit@debbugs.gnu.org; Mon, 01 Dec 2014 04:01:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38278) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XvMkz-0005d5-6X for submit@debbugs.gnu.org; Mon, 01 Dec 2014 03:54:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XvMku-0007er-FR for submit@debbugs.gnu.org; Mon, 01 Dec 2014 03:54:56 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,T_DKIM_INVALID autolearn=disabled version=3.3.2 Received: from lists.gnu.org ([2001:4830:134:3::11]:40991) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvMku-0007en-CF for submit@debbugs.gnu.org; Mon, 01 Dec 2014 03:54:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvMkp-0007nY-IN for bug-coreutils@gnu.org; Mon, 01 Dec 2014 03:54:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XvMkl-0007dS-0m for bug-coreutils@gnu.org; Mon, 01 Dec 2014 03:54:47 -0500 Received: from mail-qc0-x22b.google.com ([2607:f8b0:400d:c01::22b]:52015) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvMkk-0007dM-Ra for bug-coreutils@gnu.org; Mon, 01 Dec 2014 03:54:42 -0500 Received: by mail-qc0-f171.google.com with SMTP id r5so7269366qcx.16 for ; Mon, 01 Dec 2014 00:54:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:date:content-type:mime-version; bh=/izR3lWPu13uUjQNXQz10xtOyPgdDm1tiJnhlD2GNlY=; b=yxwODsynI1wvyUo6B3rv9BOAVvX5ak0tImg2alrhACUlP9GTjI2hUEhmAn5ExnR5ho 8e3yfrRdZHk9ls8Uqp354gumy6/XHEhF9mTgDimJSrnHsCKVc3W4J2wE73w42F8mHxvM 2mHkBSfLgheCM6YDX1Fo8yyIo2LrheAHmWcj3NQlb0s3OKqeqV5ZR1QKujwTZI1eq8Br Xhra2fRbauRU8jctCmqpD8RKHnv+0yO7WVLyYwuWRdiSCOIui5Nsaz2kRI0Jbnc0HMXS oVtffTol68Jf1Boh+5gbrolhHH80UGt5Lt2Na7Q0L0uQsUn1BUw+2p069vGBsqS70rlC 98DA== X-Received: by 10.224.165.148 with SMTP id i20mr52973160qay.67.1417424082179; Mon, 01 Dec 2014 00:54:42 -0800 (PST) Received: from [192.168.1.20] (ip-213-220-214-203.net.upcbroadband.cz. [213.220.214.203]) by mx.google.com with ESMTPSA id p10sm16766477qab.39.2014.12.01.00.54.40 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Mon, 01 Dec 2014 00:54:41 -0800 (PST) Message-ID: <1417424078.27166.50.camel@unused-4-145.brq.redhat.com> Subject: Fully fix du circular warning on bind mounts From: Boris Ranto To: bug-coreutils@gnu.org Date: Mon, 01 Dec 2014 09:54:38 +0100 Content-Type: multipart/mixed; boundary="=-eJNdK8vD4qWd4qcYf+Zc" X-Mailer: Evolution 3.10.4 (3.10.4-4.fc20) Mime-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:4830:134:3::11 X-Spam-Score: -3.8 (---) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 01 Dec 2014 04:01:12 -0500 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.8 (---) --=-eJNdK8vD4qWd4qcYf+Zc Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit The du circular warning can still be hit even though a file system is in good condition. All we need to do is to get the message is to begin traversing the file system between the bind mount source and bind mount target directories, i.e this short script reproduces the problem: # mkdir -p a/b/c # mount -o bind a a/b/c # du a/b The problem is that in this case, the first directory that is detected by fts as a duplicate directory is directory a/b/c/b which is not a mount point. The solution is to traverse the structure all the way to a/b (excluding a/b) which is detected as the base of the cycle and look up all these directories in the mount table. I'm attaching the patch that fixed this problem for me. -Boris --=-eJNdK8vD4qWd4qcYf+Zc Content-Disposition: attachment; filename="0001-du-handle-sub-bind-mount-cycles-gracefully.patch" Content-Type: text/x-patch; name="0001-du-handle-sub-bind-mount-cycles-gracefully.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 2359875e69d7dedfe505c45beea9277561368b45 Mon Sep 17 00:00:00 2001 From: Boris Ranto Date: Mon, 1 Dec 2014 09:24:14 +0100 Subject: [PATCH] du: handle sub-bind-mount cycles gracefully This patch fixes the handling of sub-bind-mount cycles which are incorrectly detected as the filesystem errors. If you bind mount the directory 'a' to its subdirectory 'a/b/c' and then run 'du a/b' you will get the circular dependency warning even though nothing is wrong with the file system. This happens because the first directory that is traversed twice in this case is not a bind mount but a child of bind mount. The solution is to traverse all the directories in the cycle that fts detected and check whether they are not a (bind) mount. * src/du.c (mount_point_in_fts_cycle): New function that checks whether any of the directories in the cycle that fts detected is a mount point. * src/du.c (process_file): Update the function to use the new function that looks up all the directories in the fts cycle instead of only the last one. * tests/du/bind-mount-dir-cycle-v2.sh: New test case that exhibits the described behaviour. --- src/du.c | 21 +++++++++++++++++++- tests/du/bind-mount-dir-cycle-v2.sh | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100755 tests/du/bind-mount-dir-cycle-v2.sh diff --git a/src/du.c b/src/du.c index ba20120..a145a4c 100644 --- a/src/du.c +++ b/src/du.c @@ -419,6 +419,25 @@ print_size (const struct duinfo *pdui, const char *string) fflush (stdout); } +/* This function checks whether any of the directories in the cycle that + * fts detected is a mount point. */ + +static bool +mount_point_in_fts_cycle(FTSENT *ent) +{ + FTSENT *cycle_ent = ent->fts_cycle; + + while(ent && ent != cycle_ent) + { + if (di_set_lookup(di_mnt, ent->fts_statp->st_dev, ent->fts_statp->st_ino) > 0) + { + return true; + } + ent = ent->fts_parent; + } + return false; +} + /* This function is called once for every file system object that fts encounters. fts does a depth-first traversal. This function knows that and accumulates per-directory totals based on changes in @@ -516,7 +535,7 @@ process_file (FTS *fts, FTSENT *ent) case FTS_DC: /* If not following symlinks and not a (bind) mount point. */ if (cycle_warning_required (fts, ent) - && ! di_set_lookup (di_mnt, sb->st_dev, sb->st_ino)) + && ! mount_point_in_fts_cycle (ent)) { emit_cycle_warning (file); return false; diff --git a/tests/du/bind-mount-dir-cycle-v2.sh b/tests/du/bind-mount-dir-cycle-v2.sh new file mode 100755 index 0000000..384d3e2 --- /dev/null +++ b/tests/du/bind-mount-dir-cycle-v2.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# Check that du can handle sub-bind-mounts cycles as well. + +# Copyright (C) 2014 Free Software foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ du +require_root_ + +cleanup_() { umount a/b/c; } + +mkdir -p a/b/c || framework_failure_ +mount --bind a a/b/c \ + || skip_ "This test requires mount with a working --bind option." + +echo a/b/c > exp || framework_failure_ +echo a/b >> exp || framework_failure_ + +du a/b > out 2> err || fail=1 +sed 's/^[0-9][0-9]*\t//' out > k && mv k out + +compare /dev/null err || fail=1 +compare exp out || fail=1 + +Exit $fail -- 1.9.3 --=-eJNdK8vD4qWd4qcYf+Zc-- From debbugs-submit-bounces@debbugs.gnu.org Mon Dec 01 07:50:03 2014 Received: (at 19238-done) by debbugs.gnu.org; 1 Dec 2014 12:50:03 +0000 Received: from localhost ([127.0.0.1]:50500 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XvQQV-0004Ru-EM for submit@debbugs.gnu.org; Mon, 01 Dec 2014 07:50:03 -0500 Received: from mail5.vodafone.ie ([213.233.128.176]:41316) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1XvQQT-0004RQ-E5 for 19238-done@debbugs.gnu.org; Mon, 01 Dec 2014 07:50:02 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtAFAE9jfFRtTvvh/2dsb2JhbABbgwaCS4ETUMcagxICgRQWAQEBAQF9hAMBAQQjDwFWCw0BCgICBSECAg8CRgYBDAgBARYBiCkBvQCFfpAHAQsggS6PVIJ1gVMFpD+NS4N7P4J3AQEB Received: from unknown (HELO localhost.localdomain) ([109.78.251.225]) by mail3.vodafone.ie with ESMTP; 01 Dec 2014 12:49:59 +0000 Message-ID: <547C63F7.20005@draigBrady.com> Date: Mon, 01 Dec 2014 12:49:59 +0000 From: =?UTF-8?B?UMOhZHJhaWcgQnJhZHk=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: Boris Ranto , 19238-done@debbugs.gnu.org Subject: Re: bug#19238: Fully fix du circular warning on bind mounts References: <1417424078.27166.50.camel@unused-4-145.brq.redhat.com> In-Reply-To: <1417424078.27166.50.camel@unused-4-145.brq.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 19238-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.0 (/) On 01/12/14 08:54, Boris Ranto wrote: > The du circular warning can still be hit even though a file system is in > good condition. All we need to do is to get the message is to begin > traversing the file system between the bind mount source and bind mount > target directories, i.e this short script reproduces the problem: > > # mkdir -p a/b/c > # mount -o bind a a/b/c > # du a/b > > The problem is that in this case, the first directory that is detected > by fts as a duplicate directory is directory a/b/c/b which is not a > mount point. > > The solution is to traverse the structure all the way to a/b (excluding > a/b) which is detected as the base of the cycle and look up all these > directories in the mount table. > > I'm attaching the patch that fixed this problem for me. Very nice. Thanks for the test! I'll add a NEWS entry and push later. thanks! Pádraig From unknown Tue Jun 17 01:27:38 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Tue, 30 Dec 2014 12:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator