From: Karel Zak Date: Wed, 6 Aug 2025 12:09:12 +0000 (+0200) Subject: libmount: (monitor) rename public API to "mountinfo" X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cfebab23ab06cf2b646b4c0afdbc0ebb9e25c6dd;p=thirdparty%2Futil-linux.git libmount: (monitor) rename public API to "mountinfo" 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 --- diff --git a/libmount/docs/libmount-sections.txt b/libmount/docs/libmount-sections.txt index 95ad55fe5..68cfbff8c 100644 --- a/libmount/docs/libmount-sections.txt +++ b/libmount/docs/libmount-sections.txt @@ -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 diff --git a/libmount/src/libmount.h.in b/libmount/src/libmount.h.in index 23cf0a4fd..a009b9212 100644 --- a/libmount/src/libmount.h.in +++ b/libmount/src/libmount.h.in @@ -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); diff --git a/libmount/src/libmount.sym b/libmount/src/libmount.sym index cd3c5fb86..9a142f428 100644 --- a/libmount/src/libmount.sym +++ b/libmount/src/libmount.sym @@ -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; diff --git a/libmount/src/monitor.c b/libmount/src/monitor.c index 6bede6b58..dca037d46 100644 --- a/libmount/src/monitor.c +++ b/libmount/src/monitor.c @@ -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, " monitor in epoll" }, - { "--epoll-clean", test_epoll_cleanup, " monitor in epoll and clean events" }, - { "--wait", test_wait, " monitor wait function" }, + { "--epoll", test_epoll, " monitor in epoll" }, + { "--epoll-clean", test_epoll_cleanup, " monitor in epoll and clean events" }, + { "--wait", test_wait, " monitor wait function" }, { NULL } }; diff --git a/libmount/src/monitor_mountinfo.c b/libmount/src/monitor_mountinfo.c index 0b9dda664..171d2e172 100644 --- a/libmount/src/monitor_mountinfo.c +++ b/libmount/src/monitor_mountinfo.c @@ -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