From patchwork Sat Feb 28 14:25:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 5905501 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6F4559F373 for ; Sat, 28 Feb 2015 14:26:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72EEF2034B for ; Sat, 28 Feb 2015 14:26:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5BD3C201D3 for ; Sat, 28 Feb 2015 14:26:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751615AbbB1O0F (ORCPT ); Sat, 28 Feb 2015 09:26:05 -0500 Received: from mail-wi0-f180.google.com ([209.85.212.180]:43002 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751460AbbB1O0E (ORCPT ); Sat, 28 Feb 2015 09:26:04 -0500 Received: by wiwh11 with SMTP id h11so5909147wiw.1; Sat, 28 Feb 2015 06:26:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=HRe5F53cX07gc3VDXuCDYwI4IL5N7w0Jia+eEFd/uIU=; b=avfCIqDTZy9u24dyiWtBll8S7vJqrAx302SqQwu+ki36hypU2by4h927G4nL6ZF5HZ hdJ4suVCvBPlelVHYQylK949YMQla2rbv07B556wbCOirruiUFlv1SyKN3gUclqdNu/T UWNIlEXXx7h1E4fwLtOEgBnlHXEB/envMS/PtIuRVu2mUVXe2pS/KhSotfUFYajkmgsb ZP0wtaEt4YKmrU9YhigbIk40x4Atk36GlPxeeo4QhVXWXoceOTK/62KX+fc6fqE+2Adz 2G7tYedVg8AoPl9hb15xQSTgle3gZ7zFhA4v+XyyWG2buQpEB8AocGZyojiXepB13Do1 oLEg== X-Received: by 10.194.179.194 with SMTP id di2mr38627612wjc.4.1425133562298; Sat, 28 Feb 2015 06:26:02 -0800 (PST) Received: from p183.telecom.by (nat4-minsk-pool-46-53-177-222.telecom.by. [46.53.177.222]) by mx.google.com with ESMTPSA id dm6sm7212969wib.22.2015.02.28.06.26.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Feb 2015 06:26:01 -0800 (PST) Date: Sat, 28 Feb 2015 17:25:57 +0300 From: Alexey Dobriyan To: Jan Kara Cc: Andrew Morton , Al Viro , Linux Kernel , linux-fsdevel , swhiteho@redhat.com, cluster-devel@redhat.com Subject: [PATCH v3] fs: record task name which froze superblock Message-ID: <20150228142557.GB19552@p183.telecom.by> References: <20150214185524.GA16579@p183.telecom.by> <20150216093852.GB4749@quack.suse.cz> <20150218073455.GA1752@p183.telecom.by> <20150218091323.GA4614@quack.suse.cz> <20150220121522.GC6293@quack.suse.cz> <20150228142235.GA19552@p183.telecom.by> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20150228142235.GA19552@p183.telecom.by> User-Agent: Mutt/1.5.22 (2013-10-16) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_WEB, T_DKIM_INVALID, T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 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 #include +#include 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 /* --- 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 */