From: David Howells <dhowells@redhat.com> To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, raven@themaw.net, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/10] fsinfo: Export superblock notification counter [ver #3] Date: Thu, 06 Jun 2019 10:42:57 +0100 [thread overview] Message-ID: <155981417717.17513.456246833950321215.stgit@warthog.procyon.org.uk> (raw) In-Reply-To: <155981411940.17513.7137844619951358374.stgit@warthog.procyon.org.uk> Provide an fsinfo attribute to export the superblock notification counter so that it can be polled in the case of a notification buffer overrun. This is accessed with: struct fsinfo_params params = { .request = FSINFO_ATTR_SB_NOTIFICATIONS, }; and returns a structure that looks like: struct fsinfo_sb_notifications { __u64 watch_id; __u32 notify_counter; __u32 __reserved[1]; }; Where watch_id is a number uniquely identifying the superblock in notification records and notify_counter is incremented for each superblock notification posted. Signed-off-by: David Howells <dhowells@redhat.com> --- fs/fsinfo.c | 12 ++++++++++++ fs/super.c | 1 + include/linux/fs.h | 1 + include/uapi/linux/fsinfo.h | 10 ++++++++++ include/uapi/linux/watch_queue.h | 2 +- samples/vfs/test-fsinfo.c | 13 +++++++++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fs/fsinfo.c b/fs/fsinfo.c index 3ec64d3cba08..1456e26d2f7c 100644 --- a/fs/fsinfo.c +++ b/fs/fsinfo.c @@ -284,6 +284,16 @@ static int fsinfo_generic_param_enum(struct file_system_type *f, return sizeof(*p); } +static int fsinfo_generic_sb_notifications(struct path *path, + struct fsinfo_sb_notifications *p) +{ + struct super_block *sb = path->dentry->d_sb; + + p->watch_id = sb->s_unique_id; + p->notify_counter = atomic_read(&sb->s_notify_counter); + return sizeof(*p); +} + static void fsinfo_insert_sb_flag_parameters(struct path *path, struct fsinfo_kparams *params) { @@ -331,6 +341,7 @@ int generic_fsinfo(struct path *path, struct fsinfo_kparams *params) case _genp(MOUNT_DEVNAME, mount_devname); case _genp(MOUNT_CHILDREN, mount_children); case _genp(MOUNT_SUBMOUNT, mount_submount); + case _gen(SB_NOTIFICATIONS, sb_notifications); default: return -EOPNOTSUPP; } @@ -606,6 +617,7 @@ static const struct fsinfo_attr_info fsinfo_buffer_info[FSINFO_ATTR__NR] = { FSINFO_STRING_N (SERVER_NAME, server_name), FSINFO_STRUCT_NM (SERVER_ADDRESS, server_address), FSINFO_STRING (CELL_NAME, cell_name), + FSINFO_STRUCT (SB_NOTIFICATIONS, sb_notifications), }; /** diff --git a/fs/super.c b/fs/super.c index cddf23f1d648..da428702e725 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1823,6 +1823,7 @@ EXPORT_SYMBOL(thaw_super); */ void post_sb_notification(struct super_block *s, struct superblock_notification *n) { + atomic_inc(&s->s_notify_counter); post_watch_notification(s->s_watchers, &n->watch, current_cred(), s->s_unique_id); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 02ba4bfb9cc3..06e272a25ed7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1536,6 +1536,7 @@ struct super_block { #ifdef CONFIG_SB_NOTIFICATIONS struct watch_list *s_watchers; #endif + atomic_t s_notify_counter; } __randomize_layout; /* Helper functions so that in most cases filesystems will diff --git a/include/uapi/linux/fsinfo.h b/include/uapi/linux/fsinfo.h index 7247088332c2..b4c9446305bb 100644 --- a/include/uapi/linux/fsinfo.h +++ b/include/uapi/linux/fsinfo.h @@ -39,6 +39,7 @@ enum fsinfo_attribute { FSINFO_ATTR_SERVER_NAME = 21, /* Name of the Nth server (string) */ FSINFO_ATTR_SERVER_ADDRESS = 22, /* Mth address of the Nth server */ FSINFO_ATTR_CELL_NAME = 23, /* Cell name (string) */ + FSINFO_ATTR_SB_NOTIFICATIONS = 24, /* sb_notify() information */ FSINFO_ATTR__NR }; @@ -308,4 +309,13 @@ struct fsinfo_server_address { struct __kernel_sockaddr_storage address; }; +/* + * Information struct for fsinfo(FSINFO_ATTR_SB_NOTIFICATIONS). + */ +struct fsinfo_sb_notifications { + __u64 watch_id; /* Watch ID for superblock. */ + __u32 notify_counter; /* Number of notifications. */ + __u32 __reserved[1]; +}; + #endif /* _UAPI_LINUX_FSINFO_H */ diff --git a/include/uapi/linux/watch_queue.h b/include/uapi/linux/watch_queue.h index 66b0da7cf888..aeffcfd7a742 100644 --- a/include/uapi/linux/watch_queue.h +++ b/include/uapi/linux/watch_queue.h @@ -146,7 +146,7 @@ enum superblock_notification_type { */ struct superblock_notification { struct watch_notification watch; /* WATCH_TYPE_SB_NOTIFY */ - __u64 sb_id; /* 64-bit superblock ID [fsinfo_ids::f_sb_id] */ + __u64 sb_id; /* 64-bit superblock ID [fsinfo_sb_notifications::watch_id] */ }; struct superblock_error_notification { diff --git a/samples/vfs/test-fsinfo.c b/samples/vfs/test-fsinfo.c index af29da74559e..0f8f9ded0925 100644 --- a/samples/vfs/test-fsinfo.c +++ b/samples/vfs/test-fsinfo.c @@ -90,6 +90,7 @@ static const struct fsinfo_attr_info fsinfo_buffer_info[FSINFO_ATTR__NR] = { FSINFO_STRING_N (SERVER_NAME, server_name), FSINFO_STRUCT_NM (SERVER_ADDRESS, server_address), FSINFO_STRING (CELL_NAME, cell_name), + FSINFO_STRUCT (SB_NOTIFICATIONS, sb_notifications), }; #define FSINFO_NAME(X,Y) [FSINFO_ATTR_##X] = #Y @@ -118,6 +119,7 @@ static const char *fsinfo_attr_names[FSINFO_ATTR__NR] = { FSINFO_NAME (SERVER_NAME, server_name), FSINFO_NAME (SERVER_ADDRESS, server_address), FSINFO_NAME (CELL_NAME, cell_name), + FSINFO_NAME (SB_NOTIFICATIONS, sb_notifications), }; union reply { @@ -133,6 +135,7 @@ union reply { struct fsinfo_mount_info mount_info; struct fsinfo_mount_child mount_children[1]; struct fsinfo_server_address srv_addr; + struct fsinfo_sb_notifications sb_notifications; }; static void dump_hex(unsigned int *data, int from, int to) @@ -377,6 +380,15 @@ static void dump_attr_MOUNT_CHILDREN(union reply *r, int size) printf("\t[%u] %8x %8x\n", i++, f->mnt_id, f->notify_counter); } +static void dump_attr_SB_NOTIFICATIONS(union reply *r, int size) +{ + struct fsinfo_sb_notifications *f = &r->sb_notifications; + + printf("\n"); + printf("\twatch_id: %llx\n", (unsigned long long)f->watch_id); + printf("\tnotifs : %llx\n", (unsigned long long)f->notify_counter); +} + /* * */ @@ -395,6 +407,7 @@ static const dumper_t fsinfo_attr_dumper[FSINFO_ATTR__NR] = { FSINFO_DUMPER(MOUNT_INFO), FSINFO_DUMPER(MOUNT_CHILDREN), FSINFO_DUMPER(SERVER_ADDRESS), + FSINFO_DUMPER(SB_NOTIFICATIONS), }; static void dump_fsinfo(enum fsinfo_attribute attr,
WARNING: multiple messages have this Message-ID (diff)
From: David Howells <dhowells@redhat.com> To: viro@zeniv.linux.org.uk Cc: dhowells@redhat.com, raven@themaw.net, linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org, linux-block@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/10] fsinfo: Export superblock notification counter [ver #3] Date: Thu, 06 Jun 2019 09:42:57 +0000 [thread overview] Message-ID: <155981417717.17513.456246833950321215.stgit@warthog.procyon.org.uk> (raw) In-Reply-To: <155981411940.17513.7137844619951358374.stgit@warthog.procyon.org.uk> Provide an fsinfo attribute to export the superblock notification counter so that it can be polled in the case of a notification buffer overrun. This is accessed with: struct fsinfo_params params = { .request = FSINFO_ATTR_SB_NOTIFICATIONS, }; and returns a structure that looks like: struct fsinfo_sb_notifications { __u64 watch_id; __u32 notify_counter; __u32 __reserved[1]; }; Where watch_id is a number uniquely identifying the superblock in notification records and notify_counter is incremented for each superblock notification posted. Signed-off-by: David Howells <dhowells@redhat.com> --- fs/fsinfo.c | 12 ++++++++++++ fs/super.c | 1 + include/linux/fs.h | 1 + include/uapi/linux/fsinfo.h | 10 ++++++++++ include/uapi/linux/watch_queue.h | 2 +- samples/vfs/test-fsinfo.c | 13 +++++++++++++ 6 files changed, 38 insertions(+), 1 deletion(-) diff --git a/fs/fsinfo.c b/fs/fsinfo.c index 3ec64d3cba08..1456e26d2f7c 100644 --- a/fs/fsinfo.c +++ b/fs/fsinfo.c @@ -284,6 +284,16 @@ static int fsinfo_generic_param_enum(struct file_system_type *f, return sizeof(*p); } +static int fsinfo_generic_sb_notifications(struct path *path, + struct fsinfo_sb_notifications *p) +{ + struct super_block *sb = path->dentry->d_sb; + + p->watch_id = sb->s_unique_id; + p->notify_counter = atomic_read(&sb->s_notify_counter); + return sizeof(*p); +} + static void fsinfo_insert_sb_flag_parameters(struct path *path, struct fsinfo_kparams *params) { @@ -331,6 +341,7 @@ int generic_fsinfo(struct path *path, struct fsinfo_kparams *params) case _genp(MOUNT_DEVNAME, mount_devname); case _genp(MOUNT_CHILDREN, mount_children); case _genp(MOUNT_SUBMOUNT, mount_submount); + case _gen(SB_NOTIFICATIONS, sb_notifications); default: return -EOPNOTSUPP; } @@ -606,6 +617,7 @@ static const struct fsinfo_attr_info fsinfo_buffer_info[FSINFO_ATTR__NR] = { FSINFO_STRING_N (SERVER_NAME, server_name), FSINFO_STRUCT_NM (SERVER_ADDRESS, server_address), FSINFO_STRING (CELL_NAME, cell_name), + FSINFO_STRUCT (SB_NOTIFICATIONS, sb_notifications), }; /** diff --git a/fs/super.c b/fs/super.c index cddf23f1d648..da428702e725 100644 --- a/fs/super.c +++ b/fs/super.c @@ -1823,6 +1823,7 @@ EXPORT_SYMBOL(thaw_super); */ void post_sb_notification(struct super_block *s, struct superblock_notification *n) { + atomic_inc(&s->s_notify_counter); post_watch_notification(s->s_watchers, &n->watch, current_cred(), s->s_unique_id); } diff --git a/include/linux/fs.h b/include/linux/fs.h index 02ba4bfb9cc3..06e272a25ed7 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1536,6 +1536,7 @@ struct super_block { #ifdef CONFIG_SB_NOTIFICATIONS struct watch_list *s_watchers; #endif + atomic_t s_notify_counter; } __randomize_layout; /* Helper functions so that in most cases filesystems will diff --git a/include/uapi/linux/fsinfo.h b/include/uapi/linux/fsinfo.h index 7247088332c2..b4c9446305bb 100644 --- a/include/uapi/linux/fsinfo.h +++ b/include/uapi/linux/fsinfo.h @@ -39,6 +39,7 @@ enum fsinfo_attribute { FSINFO_ATTR_SERVER_NAME = 21, /* Name of the Nth server (string) */ FSINFO_ATTR_SERVER_ADDRESS = 22, /* Mth address of the Nth server */ FSINFO_ATTR_CELL_NAME = 23, /* Cell name (string) */ + FSINFO_ATTR_SB_NOTIFICATIONS = 24, /* sb_notify() information */ FSINFO_ATTR__NR }; @@ -308,4 +309,13 @@ struct fsinfo_server_address { struct __kernel_sockaddr_storage address; }; +/* + * Information struct for fsinfo(FSINFO_ATTR_SB_NOTIFICATIONS). + */ +struct fsinfo_sb_notifications { + __u64 watch_id; /* Watch ID for superblock. */ + __u32 notify_counter; /* Number of notifications. */ + __u32 __reserved[1]; +}; + #endif /* _UAPI_LINUX_FSINFO_H */ diff --git a/include/uapi/linux/watch_queue.h b/include/uapi/linux/watch_queue.h index 66b0da7cf888..aeffcfd7a742 100644 --- a/include/uapi/linux/watch_queue.h +++ b/include/uapi/linux/watch_queue.h @@ -146,7 +146,7 @@ enum superblock_notification_type { */ struct superblock_notification { struct watch_notification watch; /* WATCH_TYPE_SB_NOTIFY */ - __u64 sb_id; /* 64-bit superblock ID [fsinfo_ids::f_sb_id] */ + __u64 sb_id; /* 64-bit superblock ID [fsinfo_sb_notifications::watch_id] */ }; struct superblock_error_notification { diff --git a/samples/vfs/test-fsinfo.c b/samples/vfs/test-fsinfo.c index af29da74559e..0f8f9ded0925 100644 --- a/samples/vfs/test-fsinfo.c +++ b/samples/vfs/test-fsinfo.c @@ -90,6 +90,7 @@ static const struct fsinfo_attr_info fsinfo_buffer_info[FSINFO_ATTR__NR] = { FSINFO_STRING_N (SERVER_NAME, server_name), FSINFO_STRUCT_NM (SERVER_ADDRESS, server_address), FSINFO_STRING (CELL_NAME, cell_name), + FSINFO_STRUCT (SB_NOTIFICATIONS, sb_notifications), }; #define FSINFO_NAME(X,Y) [FSINFO_ATTR_##X] = #Y @@ -118,6 +119,7 @@ static const char *fsinfo_attr_names[FSINFO_ATTR__NR] = { FSINFO_NAME (SERVER_NAME, server_name), FSINFO_NAME (SERVER_ADDRESS, server_address), FSINFO_NAME (CELL_NAME, cell_name), + FSINFO_NAME (SB_NOTIFICATIONS, sb_notifications), }; union reply { @@ -133,6 +135,7 @@ union reply { struct fsinfo_mount_info mount_info; struct fsinfo_mount_child mount_children[1]; struct fsinfo_server_address srv_addr; + struct fsinfo_sb_notifications sb_notifications; }; static void dump_hex(unsigned int *data, int from, int to) @@ -377,6 +380,15 @@ static void dump_attr_MOUNT_CHILDREN(union reply *r, int size) printf("\t[%u] %8x %8x\n", i++, f->mnt_id, f->notify_counter); } +static void dump_attr_SB_NOTIFICATIONS(union reply *r, int size) +{ + struct fsinfo_sb_notifications *f = &r->sb_notifications; + + printf("\n"); + printf("\twatch_id: %llx\n", (unsigned long long)f->watch_id); + printf("\tnotifs : %llx\n", (unsigned long long)f->notify_counter); +} + /* * */ @@ -395,6 +407,7 @@ static const dumper_t fsinfo_attr_dumper[FSINFO_ATTR__NR] = { FSINFO_DUMPER(MOUNT_INFO), FSINFO_DUMPER(MOUNT_CHILDREN), FSINFO_DUMPER(SERVER_ADDRESS), + FSINFO_DUMPER(SB_NOTIFICATIONS), }; static void dump_fsinfo(enum fsinfo_attribute attr,
next prev parent reply other threads:[~2019-06-06 9:43 UTC|newest] Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-06-06 9:41 [RFC][PATCH 00/10] Mount, FS, Block and Keyrings notifications [ver #3] David Howells 2019-06-06 9:41 ` David Howells 2019-06-06 9:42 ` [PATCH 01/10] security: Override creds in __fput() with last fputter's creds " David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 14:57 ` Andy Lutomirski 2019-06-06 14:57 ` Andy Lutomirski 2019-06-06 15:06 ` David Howells 2019-06-06 15:06 ` David Howells 2019-06-06 17:18 ` Andy Lutomirski 2019-06-06 17:18 ` Andy Lutomirski 2019-06-06 19:09 ` Casey Schaufler 2019-06-06 19:09 ` Casey Schaufler 2019-06-06 19:34 ` Andy Lutomirski 2019-06-06 19:34 ` Andy Lutomirski 2019-06-06 9:42 ` [PATCH 02/10] General notification queue with user mmap()'able ring buffer " David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 9:42 ` [PATCH 03/10] keys: Add a notification facility " David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 9:42 ` [PATCH 04/10] vfs: Add a mount-notification " David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 9:42 ` [PATCH 05/10] vfs: Add superblock notifications " David Howells 2019-06-06 9:42 ` David Howells 2019-06-06 9:42 ` David Howells [this message] 2019-06-06 9:42 ` [PATCH 06/10] fsinfo: Export superblock notification counter " David Howells 2019-06-06 9:43 ` [PATCH 07/10] Add a general, global device notification watch list " David Howells 2019-06-06 9:43 ` David Howells 2019-06-06 9:43 ` [PATCH 08/10] block: Add block layer notifications " David Howells 2019-06-06 9:43 ` David Howells 2019-06-06 9:43 ` [PATCH 09/10] usb: Add USB subsystem " David Howells 2019-06-06 9:43 ` David Howells 2019-06-06 14:24 ` Alan Stern 2019-06-06 14:24 ` Alan Stern 2019-06-06 14:24 ` Alan Stern 2019-06-06 14:33 ` Greg Kroah-Hartman 2019-06-06 14:33 ` Greg Kroah-Hartman 2019-06-06 14:55 ` Alan Stern 2019-06-06 14:55 ` Alan Stern 2019-06-06 14:55 ` Alan Stern 2019-06-06 15:31 ` Greg Kroah-Hartman 2019-06-06 15:31 ` Greg Kroah-Hartman 2019-06-07 6:40 ` Felipe Balbi 2019-06-07 6:40 ` Felipe Balbi 2019-06-07 14:01 ` Alan Stern 2019-06-07 14:01 ` Alan Stern 2019-06-07 14:01 ` Alan Stern 2019-06-11 6:28 ` Felipe Balbi 2019-06-11 6:28 ` Felipe Balbi 2019-06-11 13:53 ` Alan Stern 2019-06-11 13:53 ` Alan Stern 2019-06-11 13:53 ` Alan Stern 2019-06-12 6:58 ` Felipe Balbi 2019-06-12 6:58 ` Felipe Balbi 2019-06-06 9:43 ` [PATCH 10/10] Add sample notification program " David Howells 2019-06-06 9:43 ` David Howells 2019-06-06 21:21 ` Eugeniu Rosca 2019-06-06 21:21 ` Eugeniu Rosca 2019-06-06 21:21 ` Eugeniu Rosca 2019-06-06 22:52 ` David Howells 2019-06-06 22:52 ` David Howells 2019-06-07 14:37 ` David Howells 2019-06-07 14:37 ` David Howells 2019-06-06 12:32 ` [RFC][PATCH 00/10] Mount, FS, Block and Keyrings notifications " Stephen Smalley 2019-06-06 12:32 ` Stephen Smalley 2019-06-06 13:16 ` David Howells 2019-06-06 13:16 ` David Howells 2019-06-06 14:05 ` Stephen Smalley 2019-06-06 14:05 ` Stephen Smalley 2019-06-06 16:43 ` Casey Schaufler 2019-06-06 16:43 ` Casey Schaufler 2019-06-06 17:11 ` Andy Lutomirski 2019-06-06 17:11 ` Andy Lutomirski 2019-06-06 18:33 ` Casey Schaufler 2019-06-06 18:33 ` Casey Schaufler 2019-06-06 18:51 ` Andy Lutomirski 2019-06-06 18:51 ` Andy Lutomirski 2019-06-06 17:16 ` Stephen Smalley 2019-06-06 17:16 ` Stephen Smalley 2019-06-06 18:56 ` Casey Schaufler 2019-06-06 18:56 ` Casey Schaufler 2019-06-06 19:54 ` Andy Lutomirski 2019-06-06 19:54 ` Andy Lutomirski 2019-06-06 21:17 ` David Howells 2019-06-06 21:17 ` David Howells 2019-06-06 21:54 ` Andy Lutomirski 2019-06-06 21:54 ` Andy Lutomirski 2019-06-06 22:38 ` David Howells 2019-06-06 22:38 ` David Howells 2019-06-06 22:42 ` Andy Lutomirski 2019-06-06 22:42 ` Andy Lutomirski 2019-06-06 22:50 ` David Howells 2019-06-06 22:50 ` David Howells 2019-06-06 14:34 ` Christian Brauner 2019-06-06 14:34 ` Christian Brauner
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=155981417717.17513.456246833950321215.stgit@warthog.procyon.org.uk \ --to=dhowells@redhat.com \ --cc=keyrings@vger.kernel.org \ --cc=linux-api@vger.kernel.org \ --cc=linux-block@vger.kernel.org \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-security-module@vger.kernel.org \ --cc=raven@themaw.net \ --cc=viro@zeniv.linux.org.uk \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.