[PATCH 01/18] fsinfo: Introduce a non-repeating system-unique superblock ID [ver #21]

From: David Howells
Date: Mon Aug 03 2020 - 09:36:52 EST


Introduce an (effectively) non-repeating system-unique superblock ID that
can be used to determine that two objects are in the same superblock
without needing to worry about the ID changing in the meantime (as is
possible with device IDs).

The counter could also be used to tag other features, such as mount
objects.

Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

fs/internal.h | 1 +
fs/super.c | 2 ++
include/linux/fs.h | 3 +++
3 files changed, 6 insertions(+)

diff --git a/fs/internal.h b/fs/internal.h
index 9b863a7bd708..ea60d864a8cb 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -103,6 +103,7 @@ extern struct file *alloc_empty_file_noaccount(int, const struct cred *);
/*
* super.c
*/
+extern atomic64_t vfs_unique_counter;
extern int reconfigure_super(struct fs_context *);
extern bool trylock_super(struct super_block *sb);
extern struct super_block *user_get_super(dev_t);
diff --git a/fs/super.c b/fs/super.c
index 904459b35119..21ae8afeba3a 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -44,6 +44,7 @@ static int thaw_super_locked(struct super_block *sb);

static LIST_HEAD(super_blocks);
static DEFINE_SPINLOCK(sb_lock);
+atomic64_t vfs_unique_counter; /* Unique identifier counter */

static char *sb_writers_name[SB_FREEZE_LEVELS] = {
"sb_writers",
@@ -273,6 +274,7 @@ static struct super_block *alloc_super(struct file_system_type *type, int flags,
goto fail;
if (list_lru_init_memcg(&s->s_inode_lru, &s->s_shrink))
goto fail;
+ s->s_unique_id = atomic64_inc_return(&vfs_unique_counter);
return s;

fail:
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f5abba86107d..28a29356eace 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1564,6 +1564,9 @@ struct super_block {

spinlock_t s_inode_wblist_lock;
struct list_head s_inodes_wb; /* writeback inodes */
+
+ /* Superblock information */
+ u64 s_unique_id;
} __randomize_layout;

/* Helper functions so that in most cases filesystems will