]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: remember parsed propagation
authorKarel Zak <kzak@redhat.com>
Thu, 13 Jun 2024 08:30:24 +0000 (10:30 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jan 2025 12:57:42 +0000 (13:57 +0100)
This change allows propagation flags to be retained from another
source, such as statmount().

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/fs.c
libmount/src/mountP.h

index 26f2c69e90a36d0727805c45720c8f40afd51b98..5b3a5511f424f7d563446ef56f4001d9022ca2ca 100644 (file)
@@ -100,6 +100,7 @@ void mnt_reset_fs(struct libmnt_fs *fs)
        fs->optlist = NULL;
 
        fs->opts_age = 0;
+       fs->propagation = 0;
 
        memset(fs, 0, sizeof(*fs));
        INIT_LIST_HEAD(&fs->ents);
@@ -657,21 +658,21 @@ int mnt_fs_get_propagation(struct libmnt_fs *fs, unsigned long *flags)
        if (!fs || !flags)
                return -EINVAL;
 
-       *flags = 0;
-
-       if (!fs->opt_fields)
-               return 0;
-
-        /*
-        * The optional fields format is incompatible with mount options
-        * ... we have to parse the field here.
-        */
-       *flags |= strstr(fs->opt_fields, "shared:") ? MS_SHARED : MS_PRIVATE;
+       if (!fs->propagation && fs->opt_fields) {
+                /*
+                * The optional fields format is incompatible with mount options
+                * ... we have to parse the field here.
+                */
+               fs->propagation |= strstr(fs->opt_fields, "shared:") ?
+                                               MS_SHARED : MS_PRIVATE;
+
+               if (strstr(fs->opt_fields, "master:"))
+                       fs->propagation |= MS_SLAVE;
+               if (strstr(fs->opt_fields, "unbindable"))
+                       fs->propagation |= MS_UNBINDABLE;
+       }
 
-       if (strstr(fs->opt_fields, "master:"))
-               *flags |= MS_SLAVE;
-       if (strstr(fs->opt_fields, "unbindable"))
-               *flags |= MS_UNBINDABLE;
+       *flags = fs->propagation;
 
        return 0;
 }
index 9835415c4355c77831de5648db326233589ca30e..bfdf8f451422b9bc53c30729905fada7c605ed19 100644 (file)
@@ -217,7 +217,10 @@ struct libmnt_fs {
 
        char            *optstr;        /* fstab[4], merged options */
        char            *vfs_optstr;    /* mountinfo[6]: fs-independent (VFS) options */
+
        char            *opt_fields;    /* mountinfo[7]: optional fields */
+       uint64_t        propagation;    /* statmmount() or parsed opt_fields */
+
        char            *fs_optstr;     /* mountinfo[11]: fs-dependent options */
        char            *user_optstr;   /* userspace mount options */
        char            *attrs;         /* mount attributes */