]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: clean up statmount syscall-related functions
authorKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2025 16:16:07 +0000 (18:16 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 24 Apr 2025 16:31:14 +0000 (18:31 +0200)
* Rename the raw version of the syscall from ul_statmount() to
  ul_statmount_syscall().

* Rename `sys_statmount()` to `ul_statmount()`. The goal is to use the
  same naming convention as `ul_listmount()` for a function that is
  expected to be called from code.

* Move ul_statmount() to be in the same #ifdef block as the rest of
  the statmount code in the header file.

* Add has_statmount() to make it easy to verify the usability of the
  statmount syscall.

Signed-off-by: Karel Zak <kzak@redhat.com>
include/mount-api-utils.h
libmount/src/fs_statmount.c
tests/helpers/test_sysinfo.c

index 02bb326c6c21f78f7e3155a90da60b9fae9892de..ea9aeb816b5ca93fe8f462ceec476b8d4a13d6b9 100644 (file)
@@ -348,8 +348,9 @@ struct ul_statmount {
 # define LISTMOUNT_REVERSE      BIT(0)               /* List later mounts first */
 #endif
 
+/* Don't use this "raw" version. See ul_statmount() below. */
 #if defined(SYS_statmount)
-static inline int ul_statmount(uint64_t mnt_id,
+static inline int ul_statmount_syscall(uint64_t mnt_id,
                        uint64_t ns_id,
                        uint64_t mask,
                        struct ul_statmount *buf,
@@ -364,31 +365,21 @@ static inline int ul_statmount(uint64_t mnt_id,
 
        return syscall(SYS_statmount, &req, buf, bufsize, flags);
 }
-#endif
 
-#if defined(SYS_listmount)
-static inline ssize_t ul_listmount(uint64_t mnt_id,
-                       uint64_t ns_id,
-                       uint64_t last_mnt_id,
-                       uint64_t list[], size_t num,
-                       unsigned int flags)
+static inline int has_statmount(void)
 {
-       struct ul_mnt_id_req req = {
-               .size = MNT_ID_REQ_SIZE_VER1,
-               .mnt_id = mnt_id,
-               .param = last_mnt_id,
-               .mnt_ns_id = ns_id
-       };
+       errno = 0;
 
-       return syscall(SYS_listmount, &req, list, num, flags);
+       if (ul_statmount_syscall(0, 0, 0, NULL, 0, 0) < 0 && errno == ENOSYS)
+               return 0;
+       return 1;
 }
-#endif
 
 /* This is a version of statmount() that reallocates @buf to be large enough to
  * store data for the requested @id. This function never deallocates; it is the
  * caller's responsibility.
  */
-static inline int sys_statmount(uint64_t id,
+static inline int ul_statmount(uint64_t id,
                        uint64_t ns_id,
                        uint64_t mask,
                        struct ul_statmount **buf,
@@ -415,7 +406,7 @@ static inline int sys_statmount(uint64_t id,
                }
 
                errno = 0;
-               rc = ul_statmount(id, ns_id, mask, *buf, *bufsiz, flags);
+               rc = ul_statmount_syscall(id, ns_id, mask, *buf, *bufsiz, flags);
                if (!rc)
                        break;
                if (errno != EOVERFLOW)
@@ -427,6 +418,26 @@ static inline int sys_statmount(uint64_t id,
 
        return rc;
 }
+#endif /* SYS_statmount */
+
+
+#if defined(SYS_listmount)
+static inline ssize_t ul_listmount(uint64_t mnt_id,
+                       uint64_t ns_id,
+                       uint64_t last_mnt_id,
+                       uint64_t list[], size_t num,
+                       unsigned int flags)
+{
+       struct ul_mnt_id_req req = {
+               .size = MNT_ID_REQ_SIZE_VER1,
+               .mnt_id = mnt_id,
+               .param = last_mnt_id,
+               .mnt_ns_id = ns_id
+       };
+
+       return syscall(SYS_listmount, &req, list, num, flags);
+}
+#endif
 
 #endif /* HAVE_STATMOUNT_API */
 
index a998ee23cfafe243366e511a58e2f65a2e3f165f..3993c7b69ea16536dcb851c4c97c4dcaa5729cd5 100644 (file)
@@ -33,7 +33,7 @@ struct libmnt_statmnt *mnt_new_statmnt(void)
        struct libmnt_statmnt *sm;
 
        errno = 0;
-       if (ul_statmount(0, 0, 0, NULL, 0, 0) < 0 && errno == ENOSYS) {
+       if (!has_statmount()) {
                DBG(FS, ul_debug("statmount: unsuppported"));
                return NULL;
        }
@@ -361,13 +361,14 @@ int mnt_fs_fetch_statmount(struct libmnt_fs *fs, uint64_t mask)
        if (fs->stmnt) {
                DBG(FS, ul_debugobj(fs, " reuse libmnt_stmnt"));
                memset(fs->stmnt->buf, 0, fs->stmnt->bufsiz);
-               rc = sys_statmount(fs->uniq_id, 0, mask,
+
+               rc = ul_statmount(fs->uniq_id, 0, mask,
                                   &fs->stmnt->buf, &fs->stmnt->bufsiz, 0);
                buf = fs->stmnt->buf;
                bufsiz = fs->stmnt->bufsiz;
        } else {
                DBG(FS, ul_debugobj(fs, " use private buffer"));
-               rc = sys_statmount(fs->uniq_id, 0, mask, &buf, &bufsiz, 0);
+               rc = ul_statmount(fs->uniq_id, 0, mask, &buf, &bufsiz, 0);
        }
        DBG(FS, ul_debugobj(fs, " statmount [rc=%d bufsiz=%zu ns=%" PRIu64 " mask: %s%s%s%s%s%s%s]",
                                rc, bufsiz, ns,
@@ -378,11 +379,9 @@ int mnt_fs_fetch_statmount(struct libmnt_fs *fs, uint64_t mask)
                                mask & STATMOUNT_FS_TYPE ? "fs-type " : "",
                                mask & STATMOUNT_MNT_OPTS ? "mnt-opts " : "",
                                mask & STATMOUNT_SB_SOURCE ? "sb-source " : ""));
-
        if (!rc)
                rc = apply_statmount(fs, buf);
 done:
-
        if (fs->stmnt)
                mnt_statmnt_disable_fetching(fs->stmnt, status);
        else
index 95f50f3f6c336907af3d9f767cf9c6b3ea7da12b..00bf12727dea19a17ab35fd28ece1e275dcc87c4 100644 (file)
@@ -145,13 +145,13 @@ static int hlp_fsopen_ok(void)
 
 static int hlp_statmount_ok(void)
 {
+       printf("%d\n",
 #ifdef HAVE_STATMOUNT_API
-       errno = 0;
-       ul_statmount(0, 0, 0, NULL, 0, 0);
+               has_statmount()
 #else
-       errno = ENOSYS;
+               0
 #endif
-       printf("%d\n", errno != ENOSYS);
+       );
        return 0;
 }