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

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