]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: (monitor) rename public API to "mountinfo"
authorKarel Zak <kzak@redhat.com>
Wed, 6 Aug 2025 12:09:12 +0000 (14:09 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Aug 2025 13:08:38 +0000 (15:08 +0200)
There will be more kernel monitors in the future. Ensure the API is
easy to understand.

* Rename MNT_MONITOR_TYPE_KERNEL to MNT_MONITOR_TYPE_MOUNTINFO

* Rename mnt_monitor_enable_kernel() to mnt_monitor_enable_mountinfo()

The change is backward compatible; the old names are still usable.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/docs/libmount-sections.txt
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/monitor.c
libmount/src/monitor_mountinfo.c

index 95ad55fe57c5f09b15fc8f5b8fdaad67bc0a548a..68cfbff8c1d2311b9b78b3b1e092bfe04673a800 100644 (file)
@@ -485,8 +485,9 @@ libmnt_monitor
 mnt_new_monitor
 mnt_ref_monitor
 mnt_unref_monitor
-mnt_monitor_enable_userspace
 mnt_monitor_enable_kernel
+mnt_monitor_enable_mountinfo
+mnt_monitor_enable_userspace
 mnt_monitor_get_fd
 mnt_monitor_close_fd
 mnt_monitor_next_change
index 23cf0a4fdadca8f7d0a25d6863ab525d6097404f..a009b92122ba3d031b7c72697f4f12caa4e42404 100644 (file)
@@ -746,14 +746,19 @@ extern int mnt_tabdiff_next_change(struct libmnt_tabdiff *df,
 /* monitor.c */
 enum {
        MNT_MONITOR_TYPE_USERSPACE = 1, /* userspace mount options */
-       MNT_MONITOR_TYPE_KERNEL         /* kernel mount table */
+       MNT_MONITOR_TYPE_MOUNTINFO = 2, /* /proc/self/mountinfo based kernel monitor */
+
+       MNT_MONITOR_TYPE_KERNEL = MNT_MONITOR_TYPE_MOUNTINFO,   /* deprecated */
 };
 
 extern struct libmnt_monitor *mnt_new_monitor(void);
 extern void mnt_ref_monitor(struct libmnt_monitor *mn);
 extern void mnt_unref_monitor(struct libmnt_monitor *mn);
 
+/* deprecated alias to mnt_monitor_enable_mountinfo() */
 extern int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable);
+
+extern int mnt_monitor_enable_mountinfo(struct libmnt_monitor *mn, int enable);
 extern int mnt_monitor_enable_userspace(struct libmnt_monitor *mn,
                                int enable, const char *filename);
 
index cd3c5fb869e3293588105d7644f1a05fb5b7a0b7..9a142f4287cbd542a7a3029584901f43c2db4009 100644 (file)
@@ -412,6 +412,7 @@ MOUNT_2_41 {
 MOUNT_2_42 {
        mnt_context_enable_exclusive;
        mnt_context_is_exclusive;
+       mnt_monitor_enable_mountinfo;
        mnt_monitor_event_next_fs;
        mnt_fs_is_moved;
        mnt_fs_is_attached;
index 6bede6b58f9a2af5feef3a11c5fb146bdf012ef7..dca037d46fb3c159cfd205644f1bbdf84e4d8f30 100644 (file)
@@ -22,7 +22,7 @@
  * const char *filename;
  * struct libmount_monitor *mn = mnt_new_monitor();
  *
- * mnt_monitor_enable_kernel(mn, TRUE));
+ * mnt_monitor_enable_mountinfo(mn, TRUE));
  *
  * printf("waiting for changes...\n");
  * while (mnt_monitor_wait(mn, -1) > 0) {
@@ -530,8 +530,8 @@ static struct libmnt_monitor *create_test_monitor(int argc, char *argv[])
                                goto err;
                        }
 
-               } else if (strcmp(argv[i], "kernel") == 0) {
-                       if (mnt_monitor_enable_kernel(mn, TRUE)) {
+               } else if (strcmp(argv[i], "mountinfo") == 0) {
+                       if (mnt_monitor_enable_mountinfo(mn, TRUE)) {
                                warn("failed to initialize kernel monitor");
                                goto err;
                        }
@@ -658,9 +658,9 @@ static int test_wait(struct libmnt_test *ts __attribute__((unused)),
 int main(int argc, char *argv[])
 {
        struct libmnt_test tss[] = {
-               { "--epoll", test_epoll, "<userspace kernel veil ...>  monitor in epoll" },
-               { "--epoll-clean", test_epoll_cleanup, "<userspace kernel veil ...>  monitor in epoll and clean events" },
-               { "--wait",  test_wait,  "<userspace kernel veil ...>  monitor wait function" },
+               { "--epoll", test_epoll, "<userspace mountinfo veil ...>  monitor in epoll" },
+               { "--epoll-clean", test_epoll_cleanup, "<userspace mountinfo veil ...>  monitor in epoll and clean events" },
+               { "--wait",  test_wait,  "<userspace mountinfo veil ...>  monitor wait function" },
                { NULL }
        };
 
index 0b9dda664a16ffa47d593185a93024822faf20e1..171d2e172ff4d784e3180ca8e472762250ba9485 100644 (file)
@@ -78,19 +78,22 @@ static const struct monitor_opers mountinfo_opers = {
 };
 
 /**
- * mnt_monitor_enable_kernel:
+ * mnt_monitor_enable_mountinfo:
  * @mn: monitor
  * @enable: 0 or 1
  *
- * Enables or disables kernel VFS monitoring. If the monitor does not exist and
- * enable=1 then allocates new resources necessary for the monitor.
+ * Enables or disables kernel VFS monitoring based on /proc/self/mountinfo. If
+ * the monitor does not exist and enable=1 then allocates new resources
+ * necessary for the monitor.
  *
  * If the top-level monitor has been already created (by mnt_monitor_get_fd()
  * or mnt_monitor_wait()) then it's updated according to @enable.
  *
  * Return: 0 on success and <0 on error
+ *
+ * Since: v2.42
  */
-int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable)
+int mnt_monitor_enable_mountinfo(struct libmnt_monitor *mn, int enable)
 {
        struct monitor_entry *me;
        int rc = 0;
@@ -98,7 +101,7 @@ int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable)
        if (!mn)
                return -EINVAL;
 
-       me = monitor_get_entry(mn, MNT_MONITOR_TYPE_KERNEL, -1);
+       me = monitor_get_entry(mn, MNT_MONITOR_TYPE_MOUNTINFO, -1);
        if (me) {
                rc = monitor_modify_epoll(mn, me, enable);
                if (!enable)
@@ -129,7 +132,7 @@ int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable)
         */
        me->events = EPOLLIN | EPOLLET;
 
-       me->type = MNT_MONITOR_TYPE_KERNEL;
+       me->type = MNT_MONITOR_TYPE_MOUNTINFO;
        me->opers = &mountinfo_opers;
        me->path = strdup(_PATH_PROC_MOUNTINFO);
        if (!me->path)
@@ -143,6 +146,18 @@ err:
        return rc;
 }
 
+/**
+ * mnt_monitor_enable_kernel:
+ * @mn: monitor
+ * @enable: 0 or 1
+ *
+ * Deprecated alias to mnt_monitor_enable_mountinfo().
+ *
+ * Return: 0 on success and <0 on error
+ */
+int mnt_monitor_enable_kernel(struct libmnt_monitor *mn, int enable)
+                __attribute__((alias("mnt_monitor_enable_mountinfo")));
+
 /**
  * mnt_monitor_veil_kernel:
  * @mn: monitor instance