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

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