[Pkg-utopia-maintainers] udisks/udisksmountmonitor, util-linux/libblkid: PATCHES: btrfs multiple device handling

Mike Mestnik cheako+systemd-devel at mikemestnik.net
Thu Jul 8 16:20:29 BST 2021


Since this effects multiple packages, I wasn't sure how to open a bug
report. The patches fix a random process to be deterministic.  There
are already bug reports, my fav:

https://gitlab.gnome.org/GNOME/gvfs/-/issues/519

Been in discussions and have ruffled feathers and had gotten nowhere.
Some ppl seem to want to complicate the issue by introducing
unnecessary complications, my fav is to take every `char *` device
name or `uint64_t` device id and unionize it with a UUID.  This
complicates every piece of code that operates on all these variables
and is an utter trash idea, IMHO.

The approach taken in these patches is to use a canonical device.  As
long as every function that chooses/finds/enumerates/scans devices
resolves the same canonical device, everything works.  It may take
some time to find and augment every program, but currently those
programs have a bug without any proposed solution.  With these
patches, I no-longer have extra icons on my XFCE desktop.  One reason
to adopt these patches instead of working out some other solution is
that these make small changes.

Hadn't considered partial application of these patches, so there is
more work that needs to be done.  Am finished with this, aside from
answering questions and taking part in discussions.  Won't be opening
more bug reports, making changes to these patches, or gathering the
justice league.  May assist in testing and will attempt to make
comments/offer corrections, for other patches.

Further to-do items discovered while researching this:
1. btrfs on disk representation should expose the following 3 unsigned
integers to blkid and others X of N where Y are unhealthy/unavailable.
Add them to the superblock works, but because these are dynamic, a
journal and timestamps may be appropriate.  Discussion with filesystem
and block device exports would help.  Things that come to mind are
like if a shared resource is having problems and the removal of one
drive shouldn't cause every superblock on another effected drive to be
updated, that could lead to disaster.  This aids in knowing whether
all devices are good, and also `X == 1` could be how a canonical
device is chosen.
2. kernel can easily be changed to list a UUID instead of device name
in mountinfo and others, I wrote a patch but it needs love.  Applying
the patch doesn't break things so badly you can't boot, but I did note
that grub-probe had trouble with it.
```
diff --git a/fs/proc_namespace.c b/fs/proc_namespace.c
index 392ef5162..2e62bb906 100644
--- a/fs/proc_namespace.c
+++ b/fs/proc_namespace.c
@@ -98,6 +98,30 @@ static void show_type(struct seq_file *m, struct
super_block *sb)
        }
 }

+__always_inline int show_devname(struct seq_file *m, struct vfsmount *mnt,
+                                struct super_block *sb, struct mount *r)
+{
+       int err = 0;
+       if (memcmp(sb->s_type->name, "btrfs", 6) != 0 ||
+           uuid_is_null(&sb->s_uuid)) {
+               if (sb->s_op->show_devname) {
+                       struct path mnt_path = { .dentry = mnt->mnt_root,
+                                                .mnt = mnt };
+                       err = sb->s_op->show_devname(m, mnt_path.dentry);
+                       if (err)
+                               goto out;
+               } else {
+                       mangle(m, r->mnt_devname ? r->mnt_devname : "none");
+               }
+               seq_putc(m, ' ');
+       } else {
+               seq_printf(m, "UUID=%pUb ", &sb->s_uuid);
+       }
+
+out:
+       return err;
+}
+
 static int show_vfsmnt(struct seq_file *m, struct vfsmount *mnt)
 {
        struct proc_mounts *p = m->private;
@@ -106,14 +130,9 @@ static int show_vfsmnt(struct seq_file *m, struct
vfsmount *mnt)
        struct super_block *sb = mnt_path.dentry->d_sb;
        int err;

-       if (sb->s_op->show_devname) {
-               err = sb->s_op->show_devname(m, mnt_path.dentry);
-               if (err)
-                       goto out;
-       } else {
-               mangle(m, r->mnt_devname ? r->mnt_devname : "none");
-       }
-       seq_putc(m, ' ');
+       err = show_devname(m, mnt, sb, r);
+       if (err)
+               goto out;
        /* mountpoints outside of chroot jail will give SEQ_SKIP on this */
        err = seq_path_root(m, &mnt_path, &p->root, " \t\n\\");
        if (err)
@@ -176,14 +195,10 @@ static int show_mountinfo(struct seq_file *m,
struct vfsmount *mnt)
        seq_puts(m, " - ");
        show_type(m, sb);
        seq_putc(m, ' ');
-       if (sb->s_op->show_devname) {
-               err = sb->s_op->show_devname(m, mnt->mnt_root);
-               if (err)
-                       goto out;
-       } else {
-               mangle(m, r->mnt_devname ? r->mnt_devname : "none");
-       }
-       seq_puts(m, sb_rdonly(sb) ? " ro" : " rw");
+       err = show_devname(m, mnt, sb, r);
+       if (err)
+               goto out;
+       seq_puts(m, sb_rdonly(sb) ? "ro" : "rw");
        err = show_sb_opts(m, sb);
        if (err)
                goto out;
```

Someone pointed out that `show_devname` would be perfect for this, I
just didn't think about it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: udisks_udisksmountmonitor-redirect-mountinfo-btrfs-device-l.patch
Type: application/x-patch
Size: 2557 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-utopia-maintainers/attachments/20210708/563f5614/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: udisks_daemon-Link-with-libblkid.patch
Type: application/x-patch
Size: 2214 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-utopia-maintainers/attachments/20210708/563f5614/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: util-linux_libblkid-Treat-btrfs-multidevice-with-care.patch
Type: application/x-patch
Size: 3795 bytes
Desc: not available
URL: <http://alioth-lists.debian.net/pipermail/pkg-utopia-maintainers/attachments/20210708/563f5614/attachment-0002.bin>


More information about the Pkg-utopia-maintainers mailing list