| From 2ed1d2a0a5bf09ab741f5c3d6d10021c0702be08 Mon Sep 17 00:00:00 2001 | 
 | From: David Howells <dhowells@redhat.com> | 
 | Date: Fri, 5 Jul 2019 11:10:10 +0100 | 
 | Subject: [PATCH 1/3] fsinfo: Introduce a non-repeating system-unique | 
 |  superblock ID | 
 |  | 
 | 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@redhat.com> | 
 | --- | 
 |  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 a7cd0f64faa4a..1b7460f055a3b 100644 | 
 | --- a/fs/internal.h | 
 | +++ b/fs/internal.h | 
 | @@ -112,6 +112,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 98bb0629ee108..31fadb7189d27 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 8bde32cf97115..e1325dec4fa86 100644 | 
 | --- a/include/linux/fs.h | 
 | +++ b/include/linux/fs.h | 
 | @@ -1547,6 +1547,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 | 
 | --  | 
 | 2.25.1 | 
 |  |