LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Alexey Dobriyan <adobriyan@gmail.com>
To: Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Linux Kernel <linux-kernel@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	swhiteho@redhat.com, cluster-devel@redhat.com
Subject: [PATCH v3] fs: record task name which froze superblock
Date: Sat, 28 Feb 2015 17:25:57 +0300	[thread overview]
Message-ID: <20150228142557.GB19552@p183.telecom.by> (raw)
In-Reply-To: <20150228142235.GA19552@p183.telecom.by>

Freezing and thawing are separate system calls, task which is supposed
to thaw filesystem/superblock can disappear due to crash or not thaw
due to a bug. At least record task name (we can't take task_struct
reference) to make support engineer's life easier.

Hopefully 16 bytes per superblock isn't much.

TASK_COMM_LEN definition (which is userspace ABI, see prctl(PR_SET_NAME)) is
moved to userspace exported header to not drag sched.h into every fs.h inclusion.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 fs/block_dev.c             |   12 ++++++++----
 fs/ioctl.c                 |   22 ++++++++++++++++------
 fs/super.c                 |    2 ++
 include/linux/fs.h         |    6 ++++++
 include/linux/sched.h      |    3 ---
 include/uapi/linux/sched.h |    3 +++
 6 files changed, 35 insertions(+), 13 deletions(-)

--- a/fs/block_dev.c
+++ b/fs/block_dev.c
@@ -227,9 +227,11 @@ struct super_block *freeze_bdev(struct block_device *bdev)
 	sb = get_active_super(bdev);
 	if (!sb)
 		goto out;
-	if (sb->s_op->freeze_super)
+	if (sb->s_op->freeze_super) {
 		error = sb->s_op->freeze_super(sb);
-	else
+		if (error == 0)
+			get_task_comm(sb->s_writers.freeze_comm, current);
+	} else
 		error = freeze_super(sb);
 	if (error) {
 		deactivate_super(sb);
@@ -267,9 +269,11 @@ int thaw_bdev(struct block_device *bdev, struct super_block *sb)
 	if (!sb)
 		goto out;
 
-	if (sb->s_op->thaw_super)
+	if (sb->s_op->thaw_super) {
 		error = sb->s_op->thaw_super(sb);
-	else
+		if (error == 0)
+			memset(sb->s_writers.freeze_comm, 0, TASK_COMM_LEN);
+	} else
 		error = thaw_super(sb);
 	if (error) {
 		bdev->bd_fsfreeze_count++;
--- a/fs/ioctl.c
+++ b/fs/ioctl.c
@@ -518,6 +518,7 @@ static int ioctl_fioasync(unsigned int fd, struct file *filp,
 static int ioctl_fsfreeze(struct file *filp)
 {
 	struct super_block *sb = file_inode(filp)->i_sb;
+	int rv;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
@@ -527,22 +528,31 @@ static int ioctl_fsfreeze(struct file *filp)
 		return -EOPNOTSUPP;
 
 	/* Freeze */
-	if (sb->s_op->freeze_super)
-		return sb->s_op->freeze_super(sb);
-	return freeze_super(sb);
+	if (sb->s_op->freeze_super) {
+		rv = sb->s_op->freeze_super(sb);
+		if (rv == 0)
+			get_task_comm(sb->s_writers.freeze_comm, current);
+	} else
+		rv = freeze_super(sb);
+	return rv;
 }
 
 static int ioctl_fsthaw(struct file *filp)
 {
 	struct super_block *sb = file_inode(filp)->i_sb;
+	int rv;
 
 	if (!capable(CAP_SYS_ADMIN))
 		return -EPERM;
 
 	/* Thaw */
-	if (sb->s_op->thaw_super)
-		return sb->s_op->thaw_super(sb);
-	return thaw_super(sb);
+	if (sb->s_op->thaw_super) {
+		rv = sb->s_op->thaw_super(sb);
+		if (rv == 0)
+			memset(sb->s_writers.freeze_comm, 0, TASK_COMM_LEN);
+	} else
+		rv = thaw_super(sb);
+	return rv;
 }
 
 /*
--- a/fs/super.c
+++ b/fs/super.c
@@ -1351,6 +1351,7 @@ int freeze_super(struct super_block *sb)
 	 * sees write activity when frozen is set to SB_FREEZE_COMPLETE.
 	 */
 	sb->s_writers.frozen = SB_FREEZE_COMPLETE;
+	get_task_comm(sb->s_writers.freeze_comm, current);
 	up_write(&sb->s_umount);
 	return 0;
 }
@@ -1387,6 +1388,7 @@ int thaw_super(struct super_block *sb)
 
 out:
 	sb->s_writers.frozen = SB_UNFROZEN;
+	memset(sb->s_writers.freeze_comm, 0, TASK_COMM_LEN);
 	smp_wmb();
 	wake_up(&sb->s_writers.wait_unfrozen);
 	deactivate_locked_super(sb);
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -33,6 +33,7 @@
 
 #include <asm/byteorder.h>
 #include <uapi/linux/fs.h>
+#include <uapi/linux/sched.h>
 
 struct backing_dev_info;
 struct export_operations;
@@ -1217,6 +1218,11 @@ struct sb_writers {
 	int			frozen;		/* Is sb frozen? */
 	wait_queue_head_t	wait_unfrozen;	/* queue for waiting for
 						   sb to be thawed */
+	/*
+	 * who froze superblock
+	 * write-only field for traces in crashdump
+	 */
+	char			freeze_comm[TASK_COMM_LEN];
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 	struct lockdep_map	lock_map[SB_FREEZE_LEVELS];
 #endif
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -303,9 +303,6 @@ extern char ___assert_task_state[1 - 2*!!(
 
 #endif
 
-/* Task command name length */
-#define TASK_COMM_LEN 16
-
 #include <linux/spinlock.h>
 
 /*
--- a/include/uapi/linux/sched.h
+++ b/include/uapi/linux/sched.h
@@ -49,4 +49,7 @@
  */
 #define SCHED_FLAG_RESET_ON_FORK	0x01
 
+/* Task command name length */
+#define TASK_COMM_LEN 16
+
 #endif /* _UAPI_LINUX_SCHED_H */

  reply	other threads:[~2015-02-28 14:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-14 18:55 [PATCH] " Alexey Dobriyan
2015-02-16  9:38 ` Jan Kara
2015-02-18  7:34   ` Alexey Dobriyan
2015-02-18  7:36     ` [PATCH v2] " Alexey Dobriyan
2015-02-18  9:13     ` [PATCH] " Jan Kara
2015-02-18 10:18       ` Steven Whitehouse
2015-02-20 11:42       ` Alexey Dobriyan
2015-02-20 12:15         ` Jan Kara
2015-02-28 14:22           ` Alexey Dobriyan
2015-02-28 14:25             ` Alexey Dobriyan [this message]
2015-02-28 21:31               ` [PATCH v3] " Dave Chinner
2015-03-02  4:38                 ` Mateusz Guzik
2015-03-02  4:46                   ` Mateusz Guzik
2015-03-09 15:14                     ` Alexey Dobriyan
2015-03-02 21:33                   ` Dave Chinner
2015-03-04 15:14                   ` Alexey Dobriyan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150228142557.GB19552@p183.telecom.by \
    --to=adobriyan@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cluster-devel@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=swhiteho@redhat.com \
    --cc=viro@zeniv.linux.org.uk \
    --subject='Re: [PATCH v3] fs: record task name which froze superblock' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).