Jeff Mahoney 6c14ee
From: Jeff Mahoney <jeffm@suse.com>
Jeff Mahoney 6c14ee
Subject: vfs: add super_operations->get_inode_dev
Michal Kubecek 6a3065
Patch-mainline: Never, upstream submissions have been met with a request to use per-subvolume superblocks, which is unworkable in practice
Michal Kubecek b493de
References: bsc#927455
Jeff Mahoney 6c14ee
Jeff Mahoney 6c14ee
There are many places where a dev_t:ino_t pair are passed to userspace
Jeff Mahoney 6c14ee
to uniquely describe an inode.  Some file systems, like btrfs, have
Jeff Mahoney 6c14ee
multiple inode namespace internally and use a separate dev_t to make the
Jeff Mahoney 6c14ee
distinction between them.
Jeff Mahoney 6c14ee
Jeff Mahoney 6c14ee
This patch adds a super_operations->get_inode_dev operation to allow
Jeff Mahoney 6c14ee
the file system to export those dev_ts to callers within the kernel
Jeff Mahoney 6c14ee
for further export to userspace.
Jeff Mahoney 6c14ee
Jeff Mahoney 6c14ee
Without this patch, things like audit and some perf and trace events
Jeff Mahoney 6c14ee
will not distinguish between subvolumes within a single btrfs filesystem.
Jeff Mahoney 6c14ee
Jeff Mahoney 6c14ee
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Jeff Mahoney 6c14ee
---
Michal Kubecek c02e2a
 fs/eventpoll.c                   |  2 +-
Michal Kubecek c02e2a
 fs/iomap/trace.h                 |  8 ++++----
Michal Kubecek c02e2a
 fs/locks.c                       | 12 +++++++-----
Michal Kubecek c02e2a
 fs/nfsd/nfs3xdr.c                |  2 +-
Michal Kubecek c02e2a
 fs/nfsd/nfs4state.c              |  5 +++--
Michal Kubecek c02e2a
 fs/nfsd/vfs.c                    |  4 ++--
Michal Kubecek c02e2a
 fs/notify/fdinfo.c               |  4 ++--
Michal Kubecek c02e2a
 fs/proc/nommu.c                  |  2 +-
Michal Kubecek c02e2a
 fs/proc/task_mmu.c               |  2 +-
Michal Kubecek c02e2a
 fs/proc/task_nommu.c             |  2 +-
Michal Kubecek c02e2a
 fs/proc_namespace.c              |  3 ++-
Michal Kubecek c02e2a
 fs/stat.c                        |  2 +-
Michal Kubecek c02e2a
 include/linux/fs.h               |  9 +++++++++
Michal Kubecek c02e2a
 include/trace/events/filelock.h  |  8 ++++----
Michal Kubecek c02e2a
 include/trace/events/filemap.h   |  6 +++---
Michal Kubecek c02e2a
 include/trace/events/writeback.h |  2 +-
Michal Kubecek c02e2a
 init/do_mounts.c                 |  2 +-
Michal Kubecek c02e2a
 kernel/audit_fsnotify.c          |  2 +-
Michal Kubecek c02e2a
 kernel/audit_watch.c             |  6 +++---
Michal Kubecek c02e2a
 kernel/auditsc.c                 |  6 +++---
Michal Kubecek c02e2a
 kernel/events/core.c             |  2 +-
Michal Kubecek c02e2a
 mm/memory-failure.c              |  2 +-
Michal Kubecek c02e2a
 net/unix/diag.c                  |  2 +-
Michal Kubecek c02e2a
 security/tomoyo/condition.c      |  2 +-
Michal Kubecek c02e2a
 security/tomoyo/realpath.c       |  1 +
Michal Kubecek c02e2a
 25 files changed, 56 insertions(+), 42 deletions(-)
Jeff Mahoney 6c14ee
Michal Kubecek c02e2a
--- a/fs/eventpoll.c
Michal Kubecek c02e2a
+++ b/fs/eventpoll.c
Michal Kubecek 769d7a
@@ -879,7 +879,7 @@ static void ep_show_fdinfo(struct seq_file *m, struct file *f)
Michal Kubecek c02e2a
 			   epi->ffd.fd, epi->event.events,
Michal Kubecek c02e2a
 			   (long long)epi->event.data,
Michal Kubecek c02e2a
 			   (long long)epi->ffd.file->f_pos,
Michal Kubecek c02e2a
-			   inode->i_ino, inode->i_sb->s_dev);
Michal Kubecek c02e2a
+			   inode->i_ino, inode_get_dev(inode));
Michal Kubecek c02e2a
 		if (seq_has_overflowed(m))
Michal Kubecek c02e2a
 			break;
Michal Kubecek c02e2a
 	}
Michal Kubecek c02e2a
--- a/fs/iomap/trace.h
Michal Kubecek c02e2a
+++ b/fs/iomap/trace.h
Michal Kubecek c02e2a
@@ -33,7 +33,7 @@ DECLARE_EVENT_CLASS(iomap_readpage_class,
Michal Kubecek c02e2a
 		__field(int, nr_pages)
Michal Kubecek c02e2a
 	),
Michal Kubecek c02e2a
 	TP_fast_assign(
Michal Kubecek c02e2a
-		__entry->dev = inode->i_sb->s_dev;
Michal Kubecek c02e2a
+		__entry->dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 		__entry->ino = inode->i_ino;
Michal Kubecek c02e2a
 		__entry->nr_pages = nr_pages;
Michal Kubecek c02e2a
 	),
Michal Kubecek c02e2a
@@ -61,7 +61,7 @@ DECLARE_EVENT_CLASS(iomap_range_class,
Michal Kubecek c02e2a
 		__field(u64, length)
Michal Kubecek c02e2a
 	),
Michal Kubecek c02e2a
 	TP_fast_assign(
Michal Kubecek c02e2a
-		__entry->dev = inode->i_sb->s_dev;
Michal Kubecek c02e2a
+		__entry->dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 		__entry->ino = inode->i_ino;
Michal Kubecek c02e2a
 		__entry->size = i_size_read(inode);
Michal Kubecek c02e2a
 		__entry->offset = off;
Michal Kubecek c02e2a
@@ -121,7 +121,7 @@ DECLARE_EVENT_CLASS(iomap_class,
Michal Kubecek c02e2a
 		__field(dev_t, bdev)
Michal Kubecek c02e2a
 	),
Michal Kubecek c02e2a
 	TP_fast_assign(
Michal Kubecek c02e2a
-		__entry->dev = inode->i_sb->s_dev;
Michal Kubecek c02e2a
+		__entry->dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 		__entry->ino = inode->i_ino;
Michal Kubecek c02e2a
 		__entry->addr = iomap->addr;
Michal Kubecek c02e2a
 		__entry->offset = iomap->offset;
Michal Kubecek 769d7a
@@ -164,7 +164,7 @@ TRACE_EVENT(iomap_iter,
Michal Kubecek c02e2a
 		__field(unsigned long, caller)
Michal Kubecek c02e2a
 	),
Michal Kubecek c02e2a
 	TP_fast_assign(
Michal Kubecek c02e2a
-		__entry->dev = iter->inode->i_sb->s_dev;
Michal Kubecek c02e2a
+		__entry->dev = inode_get_dev(iter->inode);
Michal Kubecek c02e2a
 		__entry->ino = iter->inode->i_ino;
Michal Kubecek c02e2a
 		__entry->pos = iter->pos;
Michal Kubecek c02e2a
 		__entry->length = iomap_length(iter);
Jeff Mahoney 6c14ee
--- a/fs/locks.c
Jeff Mahoney 6c14ee
+++ b/fs/locks.c
Michal Kubecek e499f1
@@ -215,12 +215,13 @@ static void
Michal Kubecek c02e2a
 locks_check_ctx_lists(struct inode *inode)
Michal Kubecek c02e2a
 {
Michal Kubecek c02e2a
 	struct file_lock_context *ctx = inode->i_flctx;
Michal Kubecek c02e2a
+	dev_t dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 
Michal Kubecek c02e2a
 	if (unlikely(!list_empty(&ctx->flc_flock) ||
Michal Kubecek c02e2a
 		     !list_empty(&ctx->flc_posix) ||
Michal Kubecek c02e2a
 		     !list_empty(&ctx->flc_lease))) {
Michal Kubecek c02e2a
 		pr_warn("Leaked locks on dev=0x%x:0x%x ino=0x%lx:\n",
Michal Kubecek c02e2a
-			MAJOR(inode->i_sb->s_dev), MINOR(inode->i_sb->s_dev),
Michal Kubecek c02e2a
+			MAJOR(dev), MINOR(dev),
Michal Kubecek c02e2a
 			inode->i_ino);
Michal Kubecek c02e2a
 		locks_dump_ctx_list(&ctx->flc_flock, "FLOCK");
Michal Kubecek c02e2a
 		locks_dump_ctx_list(&ctx->flc_posix, "POSIX");
Michal Kubecek e499f1
@@ -234,13 +235,14 @@ locks_check_ctx_file_list(struct file *filp, struct list_head *list,
Michal Kubecek c02e2a
 {
Michal Kubecek c02e2a
 	struct file_lock *fl;
Michal Kubecek c02e2a
 	struct inode *inode = locks_inode(filp);
Michal Kubecek c02e2a
+	dev_t dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 
Michal Kubecek c02e2a
 	list_for_each_entry(fl, list, fl_list)
Michal Kubecek c02e2a
 		if (fl->fl_file == filp)
Michal Kubecek c02e2a
 			pr_warn("Leaked %s lock on dev=0x%x:0x%x ino=0x%lx "
Michal Kubecek c02e2a
 				" fl_owner=%p fl_flags=0x%x fl_type=0x%x fl_pid=%u\n",
Michal Kubecek c02e2a
-				list_type, MAJOR(inode->i_sb->s_dev),
Michal Kubecek c02e2a
-				MINOR(inode->i_sb->s_dev), inode->i_ino,
Michal Kubecek c02e2a
+				list_type, MAJOR(dev),
Michal Kubecek c02e2a
+				MINOR(dev), inode->i_ino,
Michal Kubecek c02e2a
 				fl->fl_owner, fl->fl_flags, fl->fl_type, fl->fl_pid);
Michal Kubecek c02e2a
 }
Michal Kubecek c02e2a
 
Michal Kubecek 769d7a
@@ -2761,8 +2763,8 @@ static void lock_get_status(struct seq_file *f, struct file_lock *fl,
Jeff Mahoney 6c14ee
 	if (inode) {
Jeff Mahoney 6c14ee
 		/* userspace relies on this representation of dev_t */
Michal Kubecek 7e31c5
 		seq_printf(f, "%d %02x:%02x:%lu ", fl_pid,
Jeff Mahoney 6c14ee
-				MAJOR(inode->i_sb->s_dev),
Jeff Mahoney 6c14ee
-				MINOR(inode->i_sb->s_dev), inode->i_ino);
Jeff Mahoney 6c14ee
+				MAJOR(inode_get_dev(inode)),
Jeff Mahoney 6c14ee
+				MINOR(inode_get_dev(inode)), inode->i_ino);
Jeff Mahoney 6c14ee
 	} else {
Jeff Mahoney 6c14ee
 		seq_printf(f, "%d <none>:0 ", fl_pid);
Jeff Mahoney 6c14ee
 	}
Jeff Mahoney 6c14ee
--- a/fs/nfsd/nfs3xdr.c
Jeff Mahoney 6c14ee
+++ b/fs/nfsd/nfs3xdr.c
Michal Kubecek 0ba08a
@@ -372,7 +372,7 @@ svcxdr_encode_fattr3(struct svc_rqst *rqstp, struct xdr_stream *xdr,
Michal Kubecek 0ba08a
 		fsid ^= ((u64 *)fhp->fh_export->ex_uuid)[1];
Jeff Mahoney 6c14ee
 		break;
Michal Kubecek 0ba08a
 	default:
Michal Kubecek 0ba08a
-		fsid = (u64)huge_encode_dev(fhp->fh_dentry->d_sb->s_dev);
Michal Kubecek 0ba08a
+		fsid = (u64)huge_encode_dev(inode_get_dev(d_inode(fhp->fh_dentry)));
Michal Kubecek 0ba08a
 	}
Michal Kubecek 0ba08a
 	p = xdr_encode_hyper(p, fsid);
Michal Kubecek 0ba08a
 
Michal Kubecek c02e2a
--- a/fs/nfsd/nfs4state.c
Michal Kubecek c02e2a
+++ b/fs/nfsd/nfs4state.c
Michal Kubecek 769d7a
@@ -2595,10 +2595,11 @@ static void nfs4_show_fname(struct seq_file *s, struct nfsd_file *f)
Michal Kubecek c02e2a
 static void nfs4_show_superblock(struct seq_file *s, struct nfsd_file *f)
Michal Kubecek c02e2a
 {
Michal Kubecek c35dc3
 	struct inode *inode = file_inode(f->nf_file);
Michal Kubecek c02e2a
+	dev_t dev = inode_get_dev(inode);
Michal Kubecek c02e2a
 
Michal Kubecek c02e2a
 	seq_printf(s, "superblock: \"%02x:%02x:%ld\"",
Michal Kubecek c02e2a
-					MAJOR(inode->i_sb->s_dev),
Michal Kubecek c02e2a
-					 MINOR(inode->i_sb->s_dev),
Michal Kubecek c02e2a
+					MAJOR(dev),
Michal Kubecek c02e2a
+					 MINOR(dev),
Michal Kubecek c02e2a
 					 inode->i_ino);
Michal Kubecek c02e2a
 }
Michal Kubecek c02e2a
 
Jeff Mahoney 6c14ee
--- a/fs/nfsd/vfs.c
Jeff Mahoney 6c14ee
+++ b/fs/nfsd/vfs.c
Michal Kubecek 769d7a
@@ -1033,7 +1033,7 @@ static int wait_for_concurrent_writes(struct file *file)
Jeff Mahoney 6c14ee
 	int err = 0;
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 	if (atomic_read(&inode->i_writecount) > 1
Jeff Mahoney 6c14ee
-	    || (last_ino == inode->i_ino && last_dev == inode->i_sb->s_dev)) {
Jeff Mahoney 6c14ee
+	    || (last_ino == inode->i_ino && last_dev == inode_get_dev(inode))) {
Jeff Mahoney 6c14ee
 		dprintk("nfsd: write defer %d\n", task_pid_nr(current));
Jeff Mahoney 6c14ee
 		msleep(10);
Jeff Mahoney 6c14ee
 		dprintk("nfsd: write resume %d\n", task_pid_nr(current));
Michal Kubecek 769d7a
@@ -1044,7 +1044,7 @@ static int wait_for_concurrent_writes(struct file *file)
Jeff Mahoney 6c14ee
 		err = vfs_fsync(file, 0);
Jeff Mahoney 6c14ee
 	}
Jeff Mahoney 6c14ee
 	last_ino = inode->i_ino;
Jeff Mahoney 6c14ee
-	last_dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+	last_dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 	return err;
Jeff Mahoney 6c14ee
 }
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
--- a/fs/notify/fdinfo.c
Jeff Mahoney 6c14ee
+++ b/fs/notify/fdinfo.c
Michal Kubecek 515f42
@@ -85,7 +85,7 @@ static void inotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
Michal Kubecek 515f42
 	inode = igrab(fsnotify_conn_inode(mark->connector));
Michal Kubecek 515f42
 	if (inode) {
Michal Kubecek 515f42
 		seq_printf(m, "inotify wd:%x ino:%lx sdev:%x mask:%x ignored_mask:0 ",
Jeff Mahoney 6c14ee
-			   inode_mark->wd, inode->i_ino, inode->i_sb->s_dev,
Jeff Mahoney 6c14ee
+			   inode_mark->wd, inode->i_ino, inode_get_dev(inode),
Michal Kubecek 515f42
 			   inotify_mark_user_mask(mark));
Jeff Mahoney 6c14ee
 		show_mark_fhandle(m, inode);
Jeff Mahoney 6c14ee
 		seq_putc(m, '\n');
Michal Kubecek 515f42
@@ -112,7 +112,7 @@ static void fanotify_fdinfo(struct seq_file *m, struct fsnotify_mark *mark)
Jeff Mahoney 6c14ee
 		if (!inode)
Jeff Mahoney 6c14ee
 			return;
Jeff Mahoney 6c14ee
 		seq_printf(m, "fanotify ino:%lx sdev:%x mflags:%x mask:%x ignored_mask:%x ",
Jeff Mahoney 6c14ee
-			   inode->i_ino, inode->i_sb->s_dev,
Jeff Mahoney 6c14ee
+			   inode->i_ino, inode_get_dev(inode),
Michal Kubecek c35dc3
 			   mflags, mark->mask, mark->ignore_mask);
Jeff Mahoney 6c14ee
 		show_mark_fhandle(m, inode);
Jeff Mahoney 6c14ee
 		seq_putc(m, '\n');
Jeff Mahoney 6c14ee
--- a/fs/proc/nommu.c
Jeff Mahoney 6c14ee
+++ b/fs/proc/nommu.c
Michal Kubecek c35dc3
@@ -40,7 +40,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 	if (file) {
Jeff Mahoney 6c14ee
 		struct inode *inode = file_inode(region->vm_file);
Jeff Mahoney 6c14ee
-		dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+		dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 		ino = inode->i_ino;
Jeff Mahoney 6c14ee
 	}
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
--- a/fs/proc/task_mmu.c
Jeff Mahoney 6c14ee
+++ b/fs/proc/task_mmu.c
Michal Kubecek 769d7a
@@ -286,7 +286,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 	if (file) {
Jeff Mahoney 6c14ee
 		struct inode *inode = file_inode(vma->vm_file);
Jeff Mahoney 6c14ee
-		dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+		dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 		ino = inode->i_ino;
Jeff Mahoney 6c14ee
 		pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
Jeff Mahoney 6c14ee
 	}
Jeff Mahoney 6c14ee
--- a/fs/proc/task_nommu.c
Jeff Mahoney 6c14ee
+++ b/fs/proc/task_nommu.c
Michal Kubecek 769d7a
@@ -151,7 +151,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 	if (file) {
Jeff Mahoney 6c14ee
 		struct inode *inode = file_inode(vma->vm_file);
Jeff Mahoney 6c14ee
-		dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+		dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 		ino = inode->i_ino;
Jeff Mahoney 6c14ee
 		pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT;
Jeff Mahoney 6c14ee
 	}
Michal Kubecek c02e2a
--- a/fs/proc_namespace.c
Michal Kubecek c02e2a
+++ b/fs/proc_namespace.c
Michal Kubecek c02e2a
@@ -137,11 +137,12 @@ static int show_mountinfo(struct seq_file *m, struct vfsmount *mnt)
Michal Kubecek c02e2a
 	struct proc_mounts *p = m->private;
Michal Kubecek c02e2a
 	struct mount *r = real_mount(mnt);
Michal Kubecek c02e2a
 	struct super_block *sb = mnt->mnt_sb;
Michal Kubecek c02e2a
+	dev_t dev = inode_get_dev(d_inode(mnt->mnt_root));
Michal Kubecek c02e2a
 	struct path mnt_path = { .dentry = mnt->mnt_root, .mnt = mnt };
Michal Kubecek c02e2a
 	int err;
Michal Kubecek c02e2a
 
Michal Kubecek c02e2a
 	seq_printf(m, "%i %i %u:%u ", r->mnt_id, r->mnt_parent->mnt_id,
Michal Kubecek c02e2a
-		   MAJOR(sb->s_dev), MINOR(sb->s_dev));
Michal Kubecek c02e2a
+		   MAJOR(dev), MINOR(dev));
Michal Kubecek c02e2a
 	if (sb->s_op->show_path) {
Michal Kubecek c02e2a
 		err = sb->s_op->show_path(m, mnt->mnt_root);
Michal Kubecek c02e2a
 		if (err)
Jeff Mahoney 6c14ee
--- a/fs/stat.c
Jeff Mahoney 6c14ee
+++ b/fs/stat.c
Michal Kubecek 769d7a
@@ -47,7 +47,7 @@ void generic_fillattr(struct user_namespace *mnt_userns, struct inode *inode,
Michal Kubecek 769d7a
 	vfsuid_t vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
Michal Kubecek 769d7a
 	vfsgid_t vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
Michal Kubecek 769d7a
 
Jeff Mahoney 6c14ee
-	stat->dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+	stat->dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 	stat->ino = inode->i_ino;
Jeff Mahoney 6c14ee
 	stat->mode = inode->i_mode;
Jeff Mahoney 6c14ee
 	stat->nlink = inode->i_nlink;
Jeff Mahoney 6c14ee
--- a/include/linux/fs.h
Jeff Mahoney 6c14ee
+++ b/include/linux/fs.h
Michal Kubecek 769d7a
@@ -2250,6 +2250,7 @@ struct super_operations {
Jeff Mahoney 6c14ee
 				  struct shrink_control *);
Jeff Mahoney 6c14ee
 	long (*free_cached_objects)(struct super_block *,
Jeff Mahoney 6c14ee
 				    struct shrink_control *);
Jeff Mahoney 6c14ee
+	dev_t (*get_inode_dev)(const struct inode *);
Jeff Mahoney 6c14ee
 };
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 /*
Michal Kubecek 769d7a
@@ -3610,4 +3611,12 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len,
Michal Kubecek e499f1
 extern int generic_fadvise(struct file *file, loff_t offset, loff_t len,
Michal Kubecek e499f1
 			   int advice);
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
+static inline dev_t inode_get_dev(const struct inode *inode)
Jeff Mahoney 6c14ee
+{
Jeff Mahoney 6c14ee
+	if (inode->i_sb->s_op->get_inode_dev)
Jeff Mahoney 6c14ee
+		return inode->i_sb->s_op->get_inode_dev(inode);
Jeff Mahoney 6c14ee
+
Jeff Mahoney 6c14ee
+	return inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+}
Jeff Mahoney 6c14ee
+
Jeff Mahoney 6c14ee
 #endif /* _LINUX_FS_H */
Jeff Mahoney fa0111
--- a/include/trace/events/filelock.h
Jeff Mahoney fa0111
+++ b/include/trace/events/filelock.h
Michal Kubecek 549a5b
@@ -48,7 +48,7 @@ TRACE_EVENT(locks_get_lock_context,
Jeff Mahoney fa0111
 	),
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 	TP_fast_assign(
Jeff Mahoney fa0111
-		__entry->s_dev = inode->i_sb->s_dev;
Jeff Mahoney fa0111
+		__entry->s_dev = inode_get_dev(inode);
Jeff Mahoney fa0111
 		__entry->i_ino = inode->i_ino;
Jeff Mahoney fa0111
 		__entry->type = type;
Jeff Mahoney fa0111
 		__entry->ctx = ctx;
Michal Kubecek 549a5b
@@ -80,7 +80,7 @@ DECLARE_EVENT_CLASS(filelock_lock,
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 	TP_fast_assign(
Jeff Mahoney fa0111
 		__entry->fl = fl ? fl : NULL;
Jeff Mahoney fa0111
-		__entry->s_dev = inode->i_sb->s_dev;
Jeff Mahoney fa0111
+		__entry->s_dev = inode_get_dev(inode);
Jeff Mahoney fa0111
 		__entry->i_ino = inode->i_ino;
Michal Kubecek 6a4cea
 		__entry->fl_blocker = fl ? fl->fl_blocker : NULL;
Jeff Mahoney fa0111
 		__entry->fl_owner = fl ? fl->fl_owner : NULL;
Michal Kubecek d3995d
@@ -135,7 +135,7 @@ DECLARE_EVENT_CLASS(filelock_lease,
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 	TP_fast_assign(
Jeff Mahoney fa0111
 		__entry->fl = fl ? fl : NULL;
Jeff Mahoney fa0111
-		__entry->s_dev = inode->i_sb->s_dev;
Jeff Mahoney fa0111
+		__entry->s_dev = inode_get_dev(inode);
Jeff Mahoney fa0111
 		__entry->i_ino = inode->i_ino;
Michal Kubecek 6a4cea
 		__entry->fl_blocker = fl ? fl->fl_blocker : NULL;
Jeff Mahoney fa0111
 		__entry->fl_owner = fl ? fl->fl_owner : NULL;
Michal Kubecek d3995d
@@ -185,7 +185,7 @@ TRACE_EVENT(generic_add_lease,
Jeff Mahoney fa0111
 	),
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 	TP_fast_assign(
Jeff Mahoney fa0111
-		__entry->s_dev = inode->i_sb->s_dev;
Jeff Mahoney fa0111
+		__entry->s_dev = inode_get_dev(inode);
Jeff Mahoney fa0111
 		__entry->i_ino = inode->i_ino;
Jeff Mahoney fa0111
 		__entry->wcount = atomic_read(&inode->i_writecount);
Michal Kubecek 059916
 		__entry->rcount = atomic_read(&inode->i_readcount);
Jeff Mahoney 6c14ee
--- a/include/trace/events/filemap.h
Jeff Mahoney 6c14ee
+++ b/include/trace/events/filemap.h
Michal Kubecek 8751a9
@@ -32,7 +32,7 @@ DECLARE_EVENT_CLASS(mm_filemap_op_page_cache,
Michal Kubecek 8751a9
 		__entry->i_ino = folio->mapping->host->i_ino;
Michal Kubecek 8751a9
 		__entry->index = folio->index;
Michal Kubecek 8751a9
 		if (folio->mapping->host->i_sb)
Michal Kubecek 8751a9
-			__entry->s_dev = folio->mapping->host->i_sb->s_dev;
Michal Kubecek 8751a9
+			__entry->s_dev = inode_get_dev(folio->mapping->host);
Jeff Mahoney 6c14ee
 		else
Michal Kubecek 8751a9
 			__entry->s_dev = folio->mapping->host->i_rdev;
Michal Kubecek 8751a9
 		__entry->order = folio_order(folio);
Michal Kubecek 8751a9
@@ -71,7 +71,7 @@ TRACE_EVENT(filemap_set_wb_err,
Michal Kubecek c02e2a
 			__entry->i_ino = mapping->host->i_ino;
Michal Kubecek c02e2a
 			__entry->errseq = eseq;
Michal Kubecek c02e2a
 			if (mapping->host->i_sb)
Michal Kubecek c02e2a
-				__entry->s_dev = mapping->host->i_sb->s_dev;
Michal Kubecek c02e2a
+				__entry->s_dev = inode_get_dev(mapping->host);
Michal Kubecek c02e2a
 			else
Michal Kubecek c02e2a
 				__entry->s_dev = mapping->host->i_rdev;
Michal Kubecek c02e2a
 		),
Michal Kubecek 8751a9
@@ -99,7 +99,7 @@ TRACE_EVENT(file_check_and_advance_wb_err,
Michal Kubecek c02e2a
 			__entry->i_ino = file->f_mapping->host->i_ino;
Michal Kubecek c02e2a
 			if (file->f_mapping->host->i_sb)
Michal Kubecek c02e2a
 				__entry->s_dev =
Michal Kubecek c02e2a
-					file->f_mapping->host->i_sb->s_dev;
Michal Kubecek c02e2a
+					inode_get_dev(file->f_mapping->host);
Michal Kubecek c02e2a
 			else
Michal Kubecek c02e2a
 				__entry->s_dev =
Michal Kubecek c02e2a
 					file->f_mapping->host->i_rdev;
Jeff Mahoney fa0111
--- a/include/trace/events/writeback.h
Jeff Mahoney fa0111
+++ b/include/trace/events/writeback.h
Michal Kubecek e499f1
@@ -809,7 +809,7 @@ DECLARE_EVENT_CLASS(writeback_inode_template,
Jeff Mahoney fa0111
 	),
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 	TP_fast_assign(
Jeff Mahoney fa0111
-		__entry->dev	= inode->i_sb->s_dev;
Jeff Mahoney fa0111
+		__entry->dev	= inode_get_dev(inode);
Jeff Mahoney fa0111
 		__entry->ino	= inode->i_ino;
Jeff Mahoney fa0111
 		__entry->state	= inode->i_state;
Jeff Mahoney fa0111
 		__entry->mode	= inode->i_mode;
Michal Kubecek c02e2a
--- a/init/do_mounts.c
Michal Kubecek c02e2a
+++ b/init/do_mounts.c
Michal Kubecek e499f1
@@ -378,7 +378,7 @@ static int __init do_mount_root(const char *name, const char *fs,
Michal Kubecek c02e2a
 
Michal Kubecek c02e2a
 	init_chdir("/root");
Michal Kubecek c02e2a
 	s = current->fs->pwd.dentry->d_sb;
Michal Kubecek c02e2a
-	ROOT_DEV = s->s_dev;
Michal Kubecek c02e2a
+	ROOT_DEV = inode_get_dev(d_inode(current->fs->pwd.dentry));
Michal Kubecek c02e2a
 	printk(KERN_INFO
Michal Kubecek c02e2a
 	       "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
Michal Kubecek c02e2a
 	       s->s_type->name,
Jeff Mahoney fa0111
--- a/kernel/audit_fsnotify.c
Jeff Mahoney fa0111
+++ b/kernel/audit_fsnotify.c
Michal Kubecek 0a6d0d
@@ -67,7 +67,7 @@ int audit_mark_compare(struct audit_fsnotify_mark *mark, unsigned long ino, dev_
Jeff Mahoney fa0111
 static void audit_update_mark(struct audit_fsnotify_mark *audit_mark,
Jeff Mahoney c901e2
 			     const struct inode *inode)
Jeff Mahoney fa0111
 {
Jeff Mahoney fa0111
-	audit_mark->dev = inode ? inode->i_sb->s_dev : AUDIT_DEV_UNSET;
Jeff Mahoney fa0111
+	audit_mark->dev = inode ? inode_get_dev(inode) : AUDIT_DEV_UNSET;
Jeff Mahoney fa0111
 	audit_mark->ino = inode ? inode->i_ino : AUDIT_INO_UNSET;
Jeff Mahoney fa0111
 }
Jeff Mahoney fa0111
 
Jeff Mahoney 6c14ee
--- a/kernel/audit_watch.c
Jeff Mahoney 6c14ee
+++ b/kernel/audit_watch.c
Michal Kubecek c02e2a
@@ -352,7 +352,7 @@ static int audit_get_nd(struct audit_watch *watch, struct path *parent)
Michal Kubecek 97aef1
 		return PTR_ERR(d);
Jeff Mahoney 6c14ee
 	if (d_is_positive(d)) {
Jeff Mahoney 6c14ee
 		/* update watch filter fields */
Jeff Mahoney 7dd255
-		watch->dev = d->d_sb->s_dev;
Jeff Mahoney 6c14ee
+		watch->dev = inode_get_dev(d_backing_inode(d));
Jeff Mahoney 6c14ee
 		watch->ino = d_backing_inode(d)->i_ino;
Jeff Mahoney 6c14ee
 	}
Michal Kubecek 97aef1
 	inode_unlock(d_backing_inode(parent->dentry));
Michal Kubecek 6a3065
@@ -477,7 +477,7 @@ static int audit_watch_handle_event(struct fsnotify_mark *inode_mark, u32 mask,
Michal Kubecek 6a3065
 		return 0;
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
 	if (mask & (FS_CREATE|FS_MOVED_TO) && inode)
Jeff Mahoney 6c14ee
-		audit_update_watch(parent, dname, inode->i_sb->s_dev, inode->i_ino, 0);
Jeff Mahoney 6c14ee
+		audit_update_watch(parent, dname, inode_get_dev(inode), inode->i_ino, 0);
Jeff Mahoney 6c14ee
 	else if (mask & (FS_DELETE|FS_MOVED_FROM))
Jeff Mahoney 6c14ee
 		audit_update_watch(parent, dname, AUDIT_DEV_UNSET, AUDIT_INO_UNSET, 1);
Jeff Mahoney 6c14ee
 	else if (mask & (FS_DELETE_SELF|FS_UNMOUNT|FS_MOVE_SELF))
Michal Kubecek 6a3065
@@ -531,7 +531,7 @@ int audit_exe_compare(struct task_struct *tsk, struct audit_fsnotify_mark *mark)
Jeff Mahoney a0ab92
 	if (!exe_file)
Jeff Mahoney a0ab92
 		return 0;
Jeff Mahoney c901e2
 	ino = file_inode(exe_file)->i_ino;
Jeff Mahoney c901e2
-	dev = file_inode(exe_file)->i_sb->s_dev;
Jeff Mahoney c901e2
+	dev = inode_get_dev(file_inode(exe_file));
Jeff Mahoney a0ab92
 	fput(exe_file);
Jeff Mahoney fa0111
 	return audit_mark_compare(mark, ino, dev);
Jeff Mahoney fa0111
 }
Jeff Mahoney fa0111
--- a/kernel/auditsc.c
Jeff Mahoney fa0111
+++ b/kernel/auditsc.c
Michal Kubecek 769d7a
@@ -2272,7 +2272,7 @@ static void audit_copy_inode(struct audit_names *name,
Michal Kubecek c8b110
 			     struct inode *inode, unsigned int flags)
Michal Kubecek b493de
 {
Michal Kubecek b493de
 	name->ino   = inode->i_ino;
Michal Kubecek b493de
-	name->dev   = inode->i_sb->s_dev;
Michal Kubecek b493de
+	name->dev   = inode_get_dev(inode);
Michal Kubecek b493de
 	name->mode  = inode->i_mode;
Michal Kubecek b493de
 	name->uid   = inode->i_uid;
Michal Kubecek b493de
 	name->gid   = inode->i_gid;
Michal Kubecek 769d7a
@@ -2344,7 +2344,7 @@ void __audit_inode(struct filename *name, const struct dentry *dentry,
Jeff Mahoney fa0111
 		if (n->ino) {
Jeff Mahoney fa0111
 			/* valid inode number, use that for the comparison */
Jeff Mahoney fa0111
 			if (n->ino != inode->i_ino ||
Jeff Mahoney fa0111
-			    n->dev != inode->i_sb->s_dev)
Jeff Mahoney fa0111
+			    n->dev != inode_get_dev(inode))
Jeff Mahoney fa0111
 				continue;
Jeff Mahoney fa0111
 		} else if (n->name) {
Jeff Mahoney fa0111
 			/* inode number has not been set, check the name */
Michal Kubecek 769d7a
@@ -2449,7 +2449,7 @@ void __audit_inode_child(struct inode *parent,
Jeff Mahoney fa0111
 		     n->type != AUDIT_TYPE_UNKNOWN))
Jeff Mahoney fa0111
 			continue;
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
-		if (n->ino == parent->i_ino && n->dev == parent->i_sb->s_dev &&
Jeff Mahoney fa0111
+		if (n->ino == parent->i_ino && n->dev == inode_get_dev(parent) &&
Jeff Mahoney fa0111
 		    !audit_compare_dname_path(dname,
Jeff Mahoney fa0111
 					      n->name->name, n->name_len)) {
Jeff Mahoney fa0111
 			if (n->type == AUDIT_TYPE_UNKNOWN)
Jeff Mahoney 6c14ee
--- a/kernel/events/core.c
Jeff Mahoney 6c14ee
+++ b/kernel/events/core.c
Michal Kubecek 769d7a
@@ -8654,7 +8654,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
Jeff Mahoney 6c14ee
 			goto cpy_name;
Jeff Mahoney 6c14ee
 		}
Jeff Mahoney 6c14ee
 		inode = file_inode(vma->vm_file);
Jeff Mahoney 6c14ee
-		dev = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+		dev = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 		ino = inode->i_ino;
Jeff Mahoney 6c14ee
 		gen = inode->i_generation;
Jeff Mahoney 6c14ee
 		maj = MAJOR(dev);
Jeff Mahoney 6c14ee
--- a/mm/memory-failure.c
Jeff Mahoney 6c14ee
+++ b/mm/memory-failure.c
Michal Kubecek 769d7a
@@ -159,7 +159,7 @@ static int hwpoison_filter_dev(struct page *p)
Jeff Mahoney 6c14ee
 	if (mapping == NULL || mapping->host == NULL)
Jeff Mahoney 6c14ee
 		return -EINVAL;
Jeff Mahoney 6c14ee
 
Jeff Mahoney 6c14ee
-	dev = mapping->host->i_sb->s_dev;
Jeff Mahoney 6c14ee
+	dev = inode_get_dev(mapping->host);
Jeff Mahoney 6c14ee
 	if (hwpoison_filter_dev_major != ~0U &&
Jeff Mahoney 6c14ee
 	    hwpoison_filter_dev_major != MAJOR(dev))
Jeff Mahoney 6c14ee
 		return -EINVAL;
Jeff Mahoney fa0111
--- a/net/unix/diag.c
Jeff Mahoney fa0111
+++ b/net/unix/diag.c
Michal Kubecek 8751a9
@@ -31,7 +31,7 @@ static int sk_diag_dump_vfs(struct sock *sk, struct sk_buff *nlskb)
Jeff Mahoney fa0111
 	if (dentry) {
Jeff Mahoney fa0111
 		struct unix_diag_vfs uv = {
Jeff Mahoney fa0111
 			.udiag_vfs_ino = d_backing_inode(dentry)->i_ino,
Jeff Mahoney fa0111
-			.udiag_vfs_dev = dentry->d_sb->s_dev,
Jeff Mahoney fa0111
+			.udiag_vfs_dev = inode_get_dev(d_backing_inode(dentry)),
Jeff Mahoney fa0111
 		};
Jeff Mahoney fa0111
 
Jeff Mahoney fa0111
 		return nla_put(nlskb, UNIX_DIAG_VFS, sizeof(uv), &uv;;
Jeff Mahoney 6c14ee
--- a/security/tomoyo/condition.c
Jeff Mahoney 6c14ee
+++ b/security/tomoyo/condition.c
Michal Kubecek b493de
@@ -743,7 +743,7 @@ void tomoyo_get_attributes(struct tomoyo_obj_info *obj)
Jeff Mahoney 6c14ee
 			stat->gid  = inode->i_gid;
Jeff Mahoney 6c14ee
 			stat->ino  = inode->i_ino;
Jeff Mahoney 6c14ee
 			stat->mode = inode->i_mode;
Jeff Mahoney 6c14ee
-			stat->dev  = inode->i_sb->s_dev;
Jeff Mahoney 6c14ee
+			stat->dev  = inode_get_dev(inode);
Jeff Mahoney 6c14ee
 			stat->rdev = inode->i_rdev;
Jeff Mahoney 6c14ee
 			obj->stat_valid[i] = true;
Jeff Mahoney 6c14ee
 		}
Michal Kubecek c02e2a
--- a/security/tomoyo/realpath.c
Michal Kubecek c02e2a
+++ b/security/tomoyo/realpath.c
Michal Kubecek c02e2a
@@ -174,6 +174,7 @@ static char *tomoyo_get_local_path(struct dentry *dentry, char * const buffer,
Michal Kubecek c02e2a
 		goto prepend_filesystem_name;
Michal Kubecek c02e2a
 	}
Michal Kubecek c02e2a
 	/* Use filesystem name for unnamed devices. */
Michal Kubecek c02e2a
+	/* NOTE: This will fail with the btrfs get_inode_dev patches */
Michal Kubecek c02e2a
 	if (!MAJOR(sb->s_dev))
Michal Kubecek c02e2a
 		goto prepend_filesystem_name;
Michal Kubecek c02e2a
 	{