Blame SOURCES/coreutils-8.32-df-duplicated-entries.patch

965c50
From 0f053de4bc3ca0cfd88a42d236881dfdddb10ee9 Mon Sep 17 00:00:00 2001
965c50
From: Kamil Dudka <kdudka@redhat.com>
965c50
Date: Wed, 30 Jun 2021 17:53:22 +0200
965c50
Subject: [PATCH] df: fix duplicated remote entries due to bind mounts
965c50
965c50
As originally reported in <https://bugzilla.redhat.com/1962515>,
965c50
df invoked without -a printed duplicated entries for NFS mounts
965c50
of bind mounts.  This is a regression from commit v8.25-54-g1c17f61ef99,
965c50
which introduced the use of a hash table.
965c50
965c50
The proposed patch makes sure that the devlist entry seen the last time
965c50
is used for comparison when eliminating duplicated mount entries.  This
965c50
way it worked before introducing the hash table.
965c50
965c50
Patch co-authored by Roberto Bergantinos.
965c50
965c50
* src/ls.c (struct devlist): Introduce the seen_last pointer.
965c50
(devlist_for_dev): Return the devlist entry seen the last time if found.
965c50
(filter_mount_list): Remember the devlist entry seen the last time for
965c50
each hashed item.
965c50
Fixes https://bugs.gnu.org/49298
965c50
965c50
Upstream-commit: d6125af095c9553f38cba0696f15158f5abe4ecc
965c50
Signed-off-by: Kamil Dudka <kdudka@redhat.com>
965c50
---
965c50
 src/df.c | 15 +++++++++++++--
965c50
 1 file changed, 13 insertions(+), 2 deletions(-)
965c50
965c50
diff --git a/src/df.c b/src/df.c
965c50
index 7e01839..3e9247f 100644
965c50
--- a/src/df.c
965c50
+++ b/src/df.c
965c50
@@ -54,6 +54,7 @@ struct devlist
965c50
   dev_t dev_num;
965c50
   struct mount_entry *me;
965c50
   struct devlist *next;
965c50
+  struct devlist *seen_last; /* valid for hashed devlist entries only */
965c50
 };
965c50
 
965c50
 /* Filled with device numbers of examined file systems to avoid
965c50
@@ -689,7 +690,13 @@ devlist_for_dev (dev_t dev)
965c50
     return NULL;
965c50
   struct devlist dev_entry;
965c50
   dev_entry.dev_num = dev;
965c50
-  return hash_lookup (devlist_table, &dev_entry);
965c50
+
965c50
+  struct devlist *found = hash_lookup (devlist_table, &dev_entry);
965c50
+  if (found == NULL)
965c50
+    return NULL;
965c50
+
965c50
+  /* Return the last devlist entry we have seen with this dev_num */
965c50
+  return found->seen_last;
965c50
 }
965c50
 
965c50
 static void
965c50
@@ -807,8 +814,12 @@ filter_mount_list (bool devices_only)
965c50
           devlist->dev_num = buf.st_dev;
965c50
           devlist->next = device_list;
965c50
           device_list = devlist;
965c50
-          if (hash_insert (devlist_table, devlist) == NULL)
965c50
+
965c50
+          struct devlist *hash_entry = hash_insert (devlist_table, devlist);
965c50
+          if (hash_entry == NULL)
965c50
             xalloc_die ();
965c50
+          /* Ensure lookups use this latest devlist.  */
965c50
+          hash_entry->seen_last = devlist;
965c50
 
965c50
           me = me->me_next;
965c50
         }
965c50
-- 
965c50
2.31.1
965c50