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