Lorenz Brun | 5999e92 | 2021-01-27 18:53:54 +0100 | [diff] [blame^] | 1 | From 2ed1d2a0a5bf09ab741f5c3d6d10021c0702be08 Mon Sep 17 00:00:00 2001 |
| 2 | From: David Howells <dhowells@redhat.com> |
| 3 | Date: Fri, 5 Jul 2019 11:10:10 +0100 |
| 4 | Subject: [PATCH 1/3] fsinfo: Introduce a non-repeating system-unique |
| 5 | superblock ID |
| 6 | |
| 7 | Introduce an (effectively) non-repeating system-unique superblock ID that |
| 8 | can be used to determine that two objects are in the same superblock |
| 9 | without needing to worry about the ID changing in the meantime (as is |
| 10 | possible with device IDs). |
| 11 | |
| 12 | The counter could also be used to tag other features, such as mount |
| 13 | objects. |
| 14 | |
| 15 | Signed-off-by: David Howells <dhowells@redhat.com> |
| 16 | --- |
| 17 | fs/internal.h | 1 + |
| 18 | fs/super.c | 2 ++ |
| 19 | include/linux/fs.h | 3 +++ |
| 20 | 3 files changed, 6 insertions(+) |
| 21 | |
| 22 | diff --git a/fs/internal.h b/fs/internal.h |
| 23 | index a7cd0f64faa4a..1b7460f055a3b 100644 |
| 24 | --- a/fs/internal.h |
| 25 | +++ b/fs/internal.h |
| 26 | @@ -112,6 +112,7 @@ extern struct file *alloc_empty_file_noaccount(int, const struct cred *); |
| 27 | /* |
| 28 | * super.c |
| 29 | */ |
| 30 | +extern atomic64_t vfs_unique_counter; |
| 31 | extern int reconfigure_super(struct fs_context *); |
| 32 | extern bool trylock_super(struct super_block *sb); |
| 33 | extern struct super_block *user_get_super(dev_t); |
| 34 | diff --git a/fs/super.c b/fs/super.c |
| 35 | index 98bb0629ee108..31fadb7189d27 100644 |
| 36 | --- a/fs/super.c |
| 37 | +++ b/fs/super.c |
| 38 | @@ -44,6 +44,7 @@ static int thaw_super_locked(struct super_block *sb); |
| 39 | |
| 40 | static LIST_HEAD(super_blocks); |
| 41 | static DEFINE_SPINLOCK(sb_lock); |
| 42 | +atomic64_t vfs_unique_counter; /* Unique identifier counter */ |
| 43 | |
| 44 | static char *sb_writers_name[SB_FREEZE_LEVELS] = { |
| 45 | "sb_writers", |
| 46 | @@ -273,6 +274,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags, |
| 47 | goto fail; |
| 48 | if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink)) |
| 49 | goto fail; |
| 50 | + s->s_unique_id = atomic64_inc_return(&vfs_unique_counter); |
| 51 | return s; |
| 52 | |
| 53 | fail: |
| 54 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
| 55 | index 8bde32cf97115..e1325dec4fa86 100644 |
| 56 | --- a/include/linux/fs.h |
| 57 | +++ b/include/linux/fs.h |
| 58 | @@ -1547,6 +1547,9 @@ struct super_block { |
| 59 | |
| 60 | spinlock_t s_inode_wblist_lock; |
| 61 | struct list_head s_inodes_wb; /* writeback inodes */ |
| 62 | + |
| 63 | + /* Superblock information */ |
| 64 | + u64 s_unique_id; |
| 65 | } __randomize_layout; |
| 66 | |
| 67 | /* Helper functions so that in most cases filesystems will |
| 68 | -- |
| 69 | 2.25.1 |
| 70 | |