]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: use regular function to save/reset syscalls status
authorKarel Zak <kzak@redhat.com>
Tue, 21 May 2024 10:44:11 +0000 (12:44 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 21 May 2024 10:44:11 +0000 (12:44 +0200)
This commit is just cleanup to keep internal API consistent.

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

index 5206c1d58797c52105f9f0be90b94453a3048b18..ef5da32a0de12f4c2350b373c865d6ff2df3535f 100644 (file)
@@ -314,7 +314,7 @@ int mnt_context_reset_status(struct libmnt_context *cxt)
        if (!cxt)
                return -EINVAL;
 
-       reset_syscall_status(cxt);
+       mnt_context_syscall_reset_status(cxt);
 
        cxt->syscall_status = 1;                /* means not called yet */
        cxt->helper_exec_status = 1;
@@ -2599,8 +2599,8 @@ int mnt_context_get_syscall_errno(struct libmnt_context *cxt)
  *
  * The @status should be 0 on success, or negative number on error (-errno).
  *
- * This function should only be used if the [u]mount(2) syscall is NOT called by
- * libmount code.
+ * This function is intended for cases where mount/umount is called externally,
+ * rather than by libmount.
  *
  * Returns: 0 or negative number in case of error.
  */
@@ -2614,6 +2614,31 @@ int mnt_context_set_syscall_status(struct libmnt_context *cxt, int status)
        return 0;
 }
 
+/* Use this for syscalls called from libmount */
+void mnt_context_syscall_save_status(  struct libmnt_context *cxt,
+                                       const char *syscallname,
+                                       int success)
+{
+       if (!success) {
+               DBG(CXT, ul_debug("syscall '%s' [failed: %m]", syscallname));
+               cxt->syscall_status = -errno;
+               cxt->syscall_name = syscallname;
+       } else {
+               DBG(CXT, ul_debug("syscall '%s' [success]", syscallname));
+               cxt->syscall_status = 0;
+       }
+}
+
+void mnt_context_syscall_reset_status(struct libmnt_context *cxt)
+{
+       DBG(CXT, ul_debug("reset syscall status"));
+       cxt->syscall_status = 0;
+       cxt->syscall_name = NULL;
+
+       free(cxt->syscall_errmsg);
+       cxt->syscall_errmsg = NULL;
+}
+
 /**
  * mnt_context_strerror
  * @cxt: context
index f0cc381963dba1dbdabe9b5887b9877e8035adb9..c85c92b983dd10551a63b59bff902cb6b45f8c95 100644 (file)
@@ -92,7 +92,7 @@ static void hookset_set_syscall_status(struct libmnt_context *cxt,
 {
        struct libmnt_sysapi *api;
 
-       set_syscall_status(cxt, name, x);
+       mnt_context_syscall_save_status(cxt, name, x);
 
        if (!x) {
                api = get_sysapi(cxt);
@@ -819,7 +819,7 @@ enosys:
        /* we need to recover from this error, so hook_mount_legacy.c
         * can try to continue */
        DBG(HOOK, ul_debugobj(hs, "failed to init new API"));
-       reset_syscall_status(cxt);
+       mnt_context_syscall_reset_status(cxt);
        hookset_deinit(cxt, hs);
        return 1;
 }
index 7da563b85d4650549c7bf1f30be0993840704c0d..65674aa9e8e68d99889e63a392d6d40a866e551b 100644 (file)
@@ -189,7 +189,7 @@ static int do_mount_subdir(
                DBG(HOOK, ul_debug("attach subdir  %s", subdir));
                fd = open_tree(api->fd_tree, subdir,
                                        OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE);
-               set_syscall_status(cxt, "open_tree", fd >= 0);
+               mnt_context_syscall_save_status(cxt, "open_tree", fd >= 0);
                if (fd < 0)
                        rc = -errno;
 
@@ -201,7 +201,7 @@ static int do_mount_subdir(
                        setns(hsd->old_ns_fd, CLONE_NEWNS);
 
                        rc = move_mount(fd, "", AT_FDCWD, target, MOVE_MOUNT_F_EMPTY_PATH);
-                       set_syscall_status(cxt, "move_mount", rc == 0);
+                       mnt_context_syscall_save_status(cxt, "move_mount", rc == 0);
                        if (rc)
                                rc = -errno;
 
@@ -223,8 +223,7 @@ static int do_mount_subdir(
                /* Classic mount(2) based way */
                DBG(HOOK, ul_debug("mount subdir %s to %s", src, target));
                rc = mount(src, target, NULL, MS_BIND, NULL);
-
-               set_syscall_status(cxt, "mount", rc == 0);
+               mnt_context_syscall_save_status(cxt, "mount", rc == 0);
                if (rc)
                        rc = -errno;
                free(src);
@@ -233,7 +232,7 @@ static int do_mount_subdir(
        if (!rc) {
                DBG(HOOK, ul_debug("umount old root %s", root));
                rc = umount(root);
-               set_syscall_status(cxt, "umount", rc == 0);
+               mnt_context_syscall_save_status(cxt, "umount", rc == 0);
                if (rc)
                        rc = -errno;
                hsd->tmp_umounted = 1;
index fcc40bffc599dd904ddd737edac465223a12817d..63a9675bbd7fee8524ccec2edd70ef66e4919a2a 100644 (file)
@@ -480,27 +480,6 @@ struct libmnt_context
 /* Flags usable with MS_BIND|MS_REMOUNT */
 #define MNT_BIND_SETTABLE      (MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_NOATIME|MS_NODIRATIME|MS_RELATIME|MS_RDONLY|MS_NOSYMFOLLOW)
 
-static inline void set_syscall_status(struct libmnt_context *cxt, const char *name, int x)
-{
-       if (!x) {
-               DBG(CXT, ul_debug("syscall '%s' [%m]", name));
-               cxt->syscall_status = -errno;
-               cxt->syscall_name = name;
-       } else {
-               DBG(CXT, ul_debug("syscall '%s' [success]", name));
-               cxt->syscall_status = 0;
-       }
-}
-
-static inline void reset_syscall_status(struct libmnt_context *cxt)
-{
-       DBG(CXT, ul_debug("reset syscall status"));
-       cxt->syscall_status = 0;
-       cxt->syscall_name = NULL;
-
-       free(cxt->syscall_errmsg);
-       cxt->syscall_errmsg = NULL;
-}
 
 /* optmap.c */
 extern const struct libmnt_optmap *mnt_optmap_get_entry(
@@ -621,6 +600,10 @@ extern int __mnt_fs_set_target_ptr(struct libmnt_fs *fs, char *tgt)
                        __attribute__((nonnull(1)));
 
 /* context.c */
+extern void mnt_context_syscall_save_status(struct libmnt_context *cxt,
+                                        const char *syscallname, int success);
+extern void mnt_context_syscall_reset_status(struct libmnt_context *cxt);
+
 extern struct libmnt_context *mnt_copy_context(struct libmnt_context *o);
 extern int mnt_context_utab_writable(struct libmnt_context *cxt);
 extern const char *mnt_context_get_writable_tabpath(struct libmnt_context *cxt);