1 ext4: factor out helper ext4_sample_last_mounted()
3 From: Amir Goldstein <amir73il@gmail.com>
5 Signed-off-by: Amir Goldstein <amir73il@gmail.com>
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 Reviewed-by: Jan Kara <jack@suse.cz>
9 fs/ext4/file.c | 82 ++++++++++++++++++++++++++++++++--------------------------
10 1 file changed, 46 insertions(+), 36 deletions(-)
12 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
13 index fb6f023622fe..065e95bb7186 100644
16 @@ -380,50 +380,60 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma)
20 -static int ext4_file_open(struct inode * inode, struct file * filp)
21 +static int ext4_sample_last_mounted(struct super_block *sb,
22 + struct vfsmount *mnt)
24 - struct super_block *sb = inode->i_sb;
25 - struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
26 - struct vfsmount *mnt = filp->f_path.mnt;
27 + struct ext4_sb_info *sbi = EXT4_SB(sb);
33 + if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED))
39 + sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
41 + * Sample where the filesystem has been mounted and
42 + * store it in the superblock for sysadmin convenience
43 + * when trying to sort through large numbers of block
44 + * devices or filesystem images.
46 + memset(buf, 0, sizeof(buf));
48 + path.dentry = mnt->mnt_root;
49 + cp = d_path(&path, buf, sizeof(buf));
53 + handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
55 + return PTR_ERR(handle);
56 + BUFFER_TRACE(sbi->s_sbh, "get_write_access");
57 + err = ext4_journal_get_write_access(handle, sbi->s_sbh);
60 + strlcpy(sbi->s_es->s_last_mounted, cp,
61 + sizeof(sbi->s_es->s_last_mounted));
62 + ext4_handle_dirty_super(handle, sb);
64 + ext4_journal_stop(handle);
68 +static int ext4_file_open(struct inode * inode, struct file * filp)
72 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
75 - if (unlikely(!(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED) &&
77 - sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
79 - * Sample where the filesystem has been mounted and
80 - * store it in the superblock for sysadmin convenience
81 - * when trying to sort through large numbers of block
82 - * devices or filesystem images.
84 - memset(buf, 0, sizeof(buf));
86 - path.dentry = mnt->mnt_root;
87 - cp = d_path(&path, buf, sizeof(buf));
92 - handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
94 - return PTR_ERR(handle);
95 - BUFFER_TRACE(sbi->s_sbh, "get_write_access");
96 - err = ext4_journal_get_write_access(handle, sbi->s_sbh);
98 - ext4_journal_stop(handle);
101 - strlcpy(sbi->s_es->s_last_mounted, cp,
102 - sizeof(sbi->s_es->s_last_mounted));
103 - ext4_handle_dirty_super(handle, sb);
104 - ext4_journal_stop(handle);
107 + ret = ext4_sample_last_mounted(inode->i_sb, filp->f_path.mnt);
111 ret = fscrypt_file_open(inode, filp);