Skip to contentSkip to conversation

btrfs: add mount umount logs

PATCH In review Anand Jain 3 participants 5 messages May 16, 2017 – May 18, 2017 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

PATCH 1/1 btrfs: add mount umount logs

By looking at the logs we should be able to know when the FS was mounted and unmounted and the options used, so to help forensic investigations.

---
 fs/btrfs/super.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
fs/btrfs/super.c +17 -0
index 827a8305da50..a123bc46b521 100644
@@ -1408,6 +1408,17 @@ static char *setup_root_args(char *args)
 	return buf;
 }
 
+static void print_mount_info(struct btrfs_fs_info *info, int flag, char *opt,
+		char *prefix)
+{
+	char f[10] = {0};
+
+	if (flag & MS_RDONLY)
+		strcpy(f, "rdonly");
+
+	btrfs_notice(info, "%s: flags:%s opt:%s\n", prefix, f, opt);
+}
+
 static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
 				   int flags, const char *device_name,
 				   char *data)
@@ -1502,6 +1513,8 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
 			dput(root);
 			root = ERR_PTR(ret);
 			deactivate_locked_super(s);
+		} else {
+			print_mount_info(fs_info, flags, data, "mount");
 		}
 	}
 
@@ -1882,6 +1895,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
 out:
 	wake_up_process(fs_info->transaction_kthread);
 	btrfs_remount_cleanup(fs_info, old_opts);
+
+	print_mount_info(fs_info, *flags, data, "remount");
+
 	return 0;
 
 restore:
@@ -2212,6 +2228,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
 static void btrfs_kill_super(struct super_block *sb)
 {
 	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+	btrfs_notice(fs_info, "%s\n", "unmount");
 	kill_anon_super(sb);
 	free_fs_info(fs_info);
 }
Signature · 1 line
2.10.0
#1 lore raw

Yes, this is indeed a nice feature.

But what about only outputting this info when BTRFS_DEBUG is selected?
I'm sure there will be some guys not liking such kernel message flooding everywhere when doing testing.

Thanks,
Qu

Quoted 14 lines · Anand Jain

By looking at the logs we should be able to know when the FS was mounted and unmounted and the options used, so to help forensic investigations.

---
  fs/btrfs/super.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
fs/btrfs/super.c +0 -0
index 827a8305da50..a123bc46b521 100644

fs/btrfs/super.c static char *setup_root_args(char *args) · line 1417

Quoted 10 lines
fs/btrfs/super.c +7 -0
@@ -1408,6 +1408,17 @@ static char *setup_root_args(char *args)
  	return buf;
  }
 
+static void print_mount_info(struct btrfs_fs_info *info, int flag, char *opt,
+		char *prefix)
+{
+	char f[10] = {0};
+
+	if (flag & MS_RDONLY)
+		strcpy(f, "rdonly");

Isn't "ro" more common?

Thanks,
Qu

Quoted 35 lines
fs/btrfs/super.c +10 -0
+
+	btrfs_notice(info, "%s: flags:%s opt:%s\n", prefix, f, opt);
+}
+
  static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
  				   int flags, const char *device_name,
  				   char *data)
@@ -1502,6 +1513,8 @@ static struct dentry *mount_subvol(const char *subvol_name, u64 subvol_objectid,
  			dput(root);
  			root = ERR_PTR(ret);
  			deactivate_locked_super(s);
+		} else {
+			print_mount_info(fs_info, flags, data, "mount");
  		}
  	}
 
@@ -1882,6 +1895,9 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
  out:
  	wake_up_process(fs_info->transaction_kthread);
  	btrfs_remount_cleanup(fs_info, old_opts);
+
+	print_mount_info(fs_info, *flags, data, "remount");
+
  	return 0;
 
  restore:
@@ -2212,6 +2228,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)
  static void btrfs_kill_super(struct super_block *sb)
  {
  	struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+	btrfs_notice(fs_info, "%s\n", "unmount");
  	kill_anon_super(sb);
  	free_fs_info(fs_info);
  }
#3 lore raw
In reply to Anand Jain
Quoted 3 lines · Anand Jain

By looking at the logs we should be able to know when the FS was mounted and unmounted and the options used, so to help forensic investigations.

Could be a useful feature, but you're adding it to the wrong layer.

author
#2 lore raw
In reply to Qu Wenruo
Quoted 5 lines · Qu Wenruo

Yes, this is indeed a nice feature.

But what about only outputting this info when BTRFS_DEBUG is selected? I'm sure there will be some guys not liking such kernel message flooding everywhere when doing testing.

Thanks. Will keep in mind to make that changes if received confirmed
objection.

Thanks. Anand

Quoted 77 lines

Thanks,
Qu

Quoted 14 lines · Anand Jain

By looking at the logs we should be able to know when the FS was mounted and unmounted and the options used, so to help forensic investigations.

---
  fs/btrfs/super.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)
fs/btrfs/super.c +0 -0
index 827a8305da50..a123bc46b521 100644

fs/btrfs/super.c static char *setup_root_args(char *args) · line 1417

Quoted 10 lines
fs/btrfs/super.c +6 -0
@@ -1408,6 +1408,17 @@ static char *setup_root_args(char *args)
      return buf;
  }
  +static void print_mount_info(struct btrfs_fs_info *info, int flag,
 char *opt,
+        char *prefix)
+{
+    char f[10] = {0};
+
+    if (flag & MS_RDONLY)
+        strcpy(f, "rdonly");

Isn't "ro" more common?

Thanks,
Qu

Quoted 35 lines
fs/btrfs/super.c +6 -0
+
+    btrfs_notice(info, "%s: flags:%s opt:%s\n", prefix, f, opt);
+}
+
  static struct dentry *mount_subvol(const char *subvol_name, u64
 subvol_objectid,
                     int flags, const char *device_name,
                     char *data)
@@ -1502,6 +1513,8 @@ static struct dentry *mount_subvol(const char
 *subvol_name, u64 subvol_objectid,
              dput(root);
              root = ERR_PTR(ret);
              deactivate_locked_super(s);
+        } else {
+            print_mount_info(fs_info, flags, data, "mount");
          }
      }

@@ -1882,6 +1895,9 @@ static int btrfs_remount(struct super_block
*sb, int *flags, char *data)
out:

      wake_up_process(fs_info->transaction_kthread);
      btrfs_remount_cleanup(fs_info, old_opts);
fs/btrfs/super.c +4 -0
+
+    print_mount_info(fs_info, *flags, data, "remount");
+
      return 0;
    restore:
@@ -2212,6 +2228,7 @@ static int btrfs_statfs(struct dentry *dentry,
 struct kstatfs *buf)
  static void btrfs_kill_super(struct super_block *sb)
  {
      struct btrfs_fs_info *fs_info = btrfs_sb(sb);
+    btrfs_notice(fs_info, "%s\n", "unmount");
      kill_anon_super(sb);
      free_fs_info(fs_info);
Quoted 2 lines
  }

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#4 lore raw
In reply to David Sterba
Quoted 6 lines · David Sterba
Quoted 3 lines · Anand Jain

By looking at the logs we should be able to know when the FS was mounted and unmounted and the options used, so to help forensic investigations.

Could be a useful feature, but you're adding it to the wrong layer.

Ok proposing to be added to the vfs layer.

Thanks, Anand

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html