Subject: bug#49298: closed (Re: bug#49298: [PATCH] df: do not print duplicated entires with NFS and bind mounts)

From: [email-masked] (GNU bug Tracking System)
Date: Fri, 02 Jul 2021 15:08:02 +0000

Your bug report

#49298: [PATCH] df: do not print duplicated entires with NFS and bind mounts

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
49298: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=49298
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#49298: [PATCH] df: do not print duplicated entires with NFS and bind mounts
From: Pádraig Brady <[email-masked]>
To: Kamil Dudka <[email-masked]>, [email-masked]
Date: Fri, 2 Jul 2021 16:07:38 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

On 30/06/2021 16:53, Kamil Dudka wrote:
> 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.

Indeed order is significant here as we can have multiple entries for the same dev nums.
The patch looks good and restores the ordering from before commit 1c17f61ef.
I'll will apply this.
Marking as done.

thanks!
Pádraig

Subject: [PATCH] df: do not print duplicated entires with NFS and bind mounts
From: Kamil Dudka <[email-masked]>
To: [email-masked]
Date: Wed, 30 Jun 2021 17:53:22 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

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.
---
 src/df.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/df.c b/src/df.c
index aadc3483f22..16a7b5524df 100644
--- 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 *inserted = hash_insert (devlist_table, devlist);
+          if (inserted == NULL)
             xalloc_die ();
+          /* Remember the last devlist entry we have seen with this dev_num */
+          inserted->seen_last = devlist;
 
           me = me->me_next;
         }
-- 
2.31.1