]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: fix mount hooks use
authorKarel Zak <kzak@redhat.com>
Fri, 10 Jun 2022 08:24:10 +0000 (10:24 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Jan 2023 11:53:12 +0000 (12:53 +0100)
The function do_mount() is possible to call in loop, for example when
libmount try FS types ("mount -t foo,bar,ext4 /dev/sdc1 /mnt"). In
this case it's bad idea to call in the loop also hooks that do
non-mount operations.

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

index 3931af973086203fd5deeaaa259066ce3862f181..2f1668724f0ac046b4bc96d88c04645d885e3b60 100644 (file)
@@ -601,8 +601,7 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
                rc = exec_helper(cxt);
 
                if (mnt_context_helper_executed(cxt)
-                   && mnt_context_get_helper_status(cxt) == 0
-                   && mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT_POST))
+                   && mnt_context_get_helper_status(cxt) == 0)
                        return -MNT_ERR_APPLYFLAGS;
 
                return rc;
@@ -624,11 +623,8 @@ static int do_mount(struct libmnt_context *cxt, const char *try_type)
        /*
         * mount(2) or others syscalls
         */
-       rc = mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT_PRE);
        if (!rc)
                rc = mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT);
-       if (!rc)
-               rc = mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT_POST);
 
        if (org_type && rc != 0)
                __mnt_fs_set_fstype_ptr(cxt->fs, org_type);
@@ -916,7 +912,7 @@ end:
 int mnt_context_do_mount(struct libmnt_context *cxt)
 {
        const char *type;
-       int res;
+       int res, rc;
        struct libmnt_ns *ns_old;
 
        assert(cxt);
@@ -936,6 +932,12 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
        if (!ns_old)
                return -MNT_ERR_NAMESPACE;
 
+       /* before mount stage */
+       rc = mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT_PRE);
+       if (rc)
+               return rc;
+
+       /* mount stage */
        type = mnt_fs_get_fstype(cxt->fs);
        if (type) {
                if (strchr(type, ','))
@@ -946,6 +948,11 @@ int mnt_context_do_mount(struct libmnt_context *cxt)
        } else
                res = do_mount_by_pattern(cxt, cxt->fstype_pattern);
 
+       /* after mount stage */
+       rc = mnt_context_call_hooks(cxt, MNT_STAGE_MOUNT_POST);
+       if (rc)
+               return rc;
+
        /* Cleanup will be immediate on failure, and deferred to umount on success */
        if (mnt_context_is_veritydev(cxt))
                mnt_context_deferred_delete_veritydev(cxt);