]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
df: fix duplicated remote entries due to bind mounts
authorKamil Dudka <kdudka@redhat.com>
Wed, 30 Jun 2021 15:53:22 +0000 (17:53 +0200)
committerPádraig Brady <P@draigBrady.com>
Fri, 2 Jul 2021 16:32:46 +0000 (17:32 +0100)
As originally reported in <https://bugzilla.redhat.com/1962515>,
df invoked without -a printed duplicated entries for NFS mounts
of bind mounts.  This is a regression from commit v8.25-54-g1c17f61ef99,
which introduced the use of a hash table.

The proposed patch makes sure that the devlist entry seen the last time
is used for comparison when eliminating duplicated mount entries.  This
way it worked before introducing the hash table.

Patch co-authored by Roberto Bergantinos.

* src/ls.c (struct devlist): Introduce the seen_last pointer.
(devlist_for_dev): Return the devlist entry seen the last time if found.
(filter_mount_list): Remember the devlist entry seen the last time for
each hashed item.
* NEWS: Mention the bug fix.
Fixes https://bugs.gnu.org/49298

NEWS
src/df.c

diff --git a/NEWS b/NEWS
index 97532d3d0578a5d0b998ba974c93b7c4aa353ccb..5a1a98acebf5dfa143b3b4848a1bfeb44f7a61fe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   when a specific number of pattern matches are performed.
   [bug introduced with the --suppress-matched feature in coreutils-8.22]
 
+  df no longer outputs duplicate remote mounts in the presence of bind mounts.
+  [bug introduced in coreutils-8.26]
+
   du no longer crashes on XFS file systems when the directory hierarchy is
   heavily changed during the run.
   [bug introduced in coreutils-8.25]
index aadc3483f228d73c5de62d978cb667a600a135d3..927365cfaa070a177d8cb8d3f8a2cea8fce5fd9d 100644 (file)
--- a/src/df.c
+++ b/src/df.c
@@ -54,6 +54,7 @@ struct devlist
   dev_t dev_num;
   struct mount_entry *me;
   struct devlist *next;
+  struct devlist *seen_last; /* valid for hashed devlist entries only */
 };
 
 /* Filled with device numbers of examined file systems to avoid
@@ -681,7 +682,13 @@ devlist_for_dev (dev_t dev)
     return NULL;
   struct devlist dev_entry;
   dev_entry.dev_num = dev;
-  return hash_lookup (devlist_table, &dev_entry);
+
+  struct devlist *found = hash_lookup (devlist_table, &dev_entry);
+  if (found == NULL)
+    return NULL;
+
+  /* Return the last devlist entry we have seen with this dev_num */
+  return found->seen_last;
 }
 
 static void
@@ -799,8 +806,12 @@ filter_mount_list (bool devices_only)
           devlist->dev_num = buf.st_dev;
           devlist->next = device_list;
           device_list = devlist;
-          if (hash_insert (devlist_table, devlist) == NULL)
+
+          struct devlist *hash_entry = hash_insert (devlist_table, devlist);
+          if (hash_entry == NULL)
             xalloc_die ();
+          /* Ensure lookups use this latest devlist.  */
+          hash_entry->seen_last = devlist;
 
           me = me->me_next;
         }