From patchwork Mon Apr 23 01:10:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902718 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PnwJmt7L"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40TpK13LS2z9s15 for ; Mon, 23 Apr 2018 11:09:41 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753824AbeDWBJk (ORCPT ); Sun, 22 Apr 2018 21:09:40 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:33332 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753821AbeDWBJj (ORCPT ); Sun, 22 Apr 2018 21:09:39 -0400 Received: by mail-pf0-f193.google.com with SMTP id f15so7824667pfn.0 for ; Sun, 22 Apr 2018 18:09:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Au93NtItWHwPvH+FpdK7nU/j5343GVm1nq0CO8E0qUY=; b=PnwJmt7LjSZDFqH3AIg5M44iNnt0vCe9zgFki0pIOix57+Ww/GlGiwdS4JNpIL/d7b Ck6Fv5DAuAeUjGFzpALS2JIwIxraCGVmrM4FPzovje9CZiEUK642WeoOOrwb9FF7fJcY CxxpaMmQCrFbDBhYWjvCPxJRWGcTVSrqlW+rYBJD3gOOiQZ5BJF4mGDtGxQd62oY42d4 fBSBMvUaxEQdyIOTt0II3dMmIMZ7Dvdd0TN+C33cMoON+eOoZEmJzKkj2PFmLdhlo4fc vEN6hW/Gge8y4l6yIiywbJQdw+GYezOJM2X+5Y7YgrB7rHIoPNEJVrBBiRJ17HersfOI 68GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Au93NtItWHwPvH+FpdK7nU/j5343GVm1nq0CO8E0qUY=; b=udnTwN+bc2OUrNOBXTPM2afzGF+h9yro4BUYsNGRVnyMH+2dS8/hGnAixgMMw0mjfd c04nI+cgJ1ACn9qYTolhPqyboIE5w4XQd0FVH/9Nv1H+Q4qqgWI759c8N4ooTUqy/LIT slmoa9OBMjQd0IHIMSzMdU3xSIcILea8dCMmecfvE1siAqi64nZvVwDjPABNBeTvWIz6 B3cA2I6I0DVhaDUBF1QY6K6pVnPtiJP0cN7drjqw9DosGE4aoqlxpY+mbTm+GT2b7Fs6 5LY7zHIYRfvJDwQPyBKMtZwQZC061l3SUBxzG1ZO7cYYNFOZRerppftjyj5/Y4u6U/Ir TDow== X-Gm-Message-State: ALQs6tAVonAbGeAghddFGe8Lc95YvkahaxfNvnIWDF6us57oj9mgz8CA dwNyO17p3B/AK41sqZput9WNQw== X-Google-Smtp-Source: AIpwx49uFcpZqJ5HbFmdPLc48REKSadldpvzkjYMAajVR5+azFRrzFNzAENWOPmAXetYIF6U+O9VfQ== X-Received: by 10.98.246.25 with SMTP id x25mr18086644pfh.138.1524445779072; Sun, 22 Apr 2018 18:09:39 -0700 (PDT) Received: from localhost.localdomain ([216.9.110.2]) by smtp.gmail.com with ESMTPSA id y15sm19435930pfb.37.2018.04.22.18.09.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 18:09:38 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v2 1/3] vfs: add the sb_start_intwrite_trylock() helper Date: Sun, 22 Apr 2018 18:10:57 -0700 Message-Id: <1524445859-26970-2-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524445859-26970-1-git-send-email-amir73il@gmail.com> References: <1524445859-26970-1-git-send-email-amir73il@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Needed by ext4 to test frozen fs before updating s_last_mounted. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- include/linux/fs.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 760d8da1b6c7..cac41f1bad05 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1597,6 +1597,11 @@ static inline void sb_start_intwrite(struct super_block *sb) __sb_start_write(sb, SB_FREEZE_FS, true); } +static inline int sb_start_intwrite_trylock(struct super_block *sb) +{ + return __sb_start_write(sb, SB_FREEZE_FS, false); +} + extern bool inode_owner_or_capable(const struct inode *inode); From patchwork Mon Apr 23 01:10:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902719 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TPsIo8WF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40TpK26pFtz9s1B for ; Mon, 23 Apr 2018 11:09:42 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753833AbeDWBJm (ORCPT ); Sun, 22 Apr 2018 21:09:42 -0400 Received: from mail-pg0-f68.google.com ([74.125.83.68]:38999 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753755AbeDWBJk (ORCPT ); Sun, 22 Apr 2018 21:09:40 -0400 Received: by mail-pg0-f68.google.com with SMTP id b9so7193028pgf.6 for ; Sun, 22 Apr 2018 18:09:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X7KNWE6NA4RR2qsXOKPpcaIJosVVrWDfooe+NyfDqwM=; b=TPsIo8WFv+gTTc/HntC8DdghWlRbva/krcb0d8x8CxKu3uKn45r1PpSfsq1M8pg3YG Np+igOkjfiKym0MVDtve1xfybbSAlETfsk5U2A0VYwQp/8CKPRZ30LX5s4ctX0aW1yWc X/EIaR79yKhLT86AX/ndp61UvyIU8FC765VYZ0Be6/LAtJF8Nuh4jwFlZgVzceKumcrX iet79csEsZzR90Wlo5NtZRcNHciWMdgGmhK5rLbPDbpoXZA2PXLCnVzAZkpeuVvGpUes voFnGDMYsleLUlzZT8+75Waz83pajTSsm+8VLpOdo++WTrpKx/0jxYPavuTLwrXjgCfP zvKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X7KNWE6NA4RR2qsXOKPpcaIJosVVrWDfooe+NyfDqwM=; b=DVsbqrV7/8gCOIsvFLhfFKaGtJJH7Kspp/nSLPVC17sk68pPyS8+/d+At+pcjlBrcy uqabCErgGFEeNeNHzuqV8GgiACXIzo+e89NN9HNkDTDPdT2FPbf8SKjE6jwxEKQYelA9 XJrPba4LIdphtnpOPANkSXIlw24yzQweWqlwsPYbj1Ni9nOtsvQZYJqLMKq3bMMA88+K dvAM26aTbZBa+oXC1GBjpmRv+h/Lu0ZO0SpcMrhx4jgxXXONomhElRaEwRvOnIuTyVvu uXrot+B/k5htVXn6UjeGX1BXVdoUjq7xnz8YGv6ztF0UA7b1TGU2Oobe7icS4MVB0wXl IOrA== X-Gm-Message-State: ALQs6tBEM4a8clJd2a77mxWfZCH2VmtGWiomITYz3xMrp36QqeXc68JQ YC96yGApbgCW+C4Pzu26VjE= X-Google-Smtp-Source: AIpwx496KrDqW0Kakcu8Oj4cuavUwWCe79zlqAIeqLI8kAkvkITY/h8gTzM6+UITCjx3gOsq1h28fg== X-Received: by 2002:a17:902:7084:: with SMTP id z4-v6mr18813815plk.364.1524445780174; Sun, 22 Apr 2018 18:09:40 -0700 (PDT) Received: from localhost.localdomain ([216.9.110.2]) by smtp.gmail.com with ESMTPSA id y15sm19435930pfb.37.2018.04.22.18.09.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 18:09:39 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v2 2/3] ext4: factor out helper ext4_sample_last_mounted() Date: Sun, 22 Apr 2018 18:10:58 -0700 Message-Id: <1524445859-26970-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524445859-26970-1-git-send-email-amir73il@gmail.com> References: <1524445859-26970-1-git-send-email-amir73il@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- fs/ext4/file.c | 82 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 36 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index fb6f023622fe..065e95bb7186 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -380,50 +380,60 @@ static int ext4_file_mmap(struct file *file, struct vm_area_struct *vma) return 0; } -static int ext4_file_open(struct inode * inode, struct file * filp) +static int ext4_sample_last_mounted(struct super_block *sb, + struct vfsmount *mnt) { - struct super_block *sb = inode->i_sb; - struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); - struct vfsmount *mnt = filp->f_path.mnt; + struct ext4_sb_info *sbi = EXT4_SB(sb); struct path path; char buf[64], *cp; + handle_t *handle; + int err; + + if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED)) + return 0; + + if (sb_rdonly(sb)) + return 0; + + sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED; + /* + * Sample where the filesystem has been mounted and + * store it in the superblock for sysadmin convenience + * when trying to sort through large numbers of block + * devices or filesystem images. + */ + memset(buf, 0, sizeof(buf)); + path.mnt = mnt; + path.dentry = mnt->mnt_root; + cp = d_path(&path, buf, sizeof(buf)); + if (IS_ERR(cp)) + return 0; + + handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); + if (IS_ERR(handle)) + return PTR_ERR(handle); + BUFFER_TRACE(sbi->s_sbh, "get_write_access"); + err = ext4_journal_get_write_access(handle, sbi->s_sbh); + if (err) + goto out; + strlcpy(sbi->s_es->s_last_mounted, cp, + sizeof(sbi->s_es->s_last_mounted)); + ext4_handle_dirty_super(handle, sb); +out: + ext4_journal_stop(handle); + return err; +} + +static int ext4_file_open(struct inode * inode, struct file * filp) +{ int ret; if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) return -EIO; - if (unlikely(!(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED) && - !sb_rdonly(sb))) { - sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED; - /* - * Sample where the filesystem has been mounted and - * store it in the superblock for sysadmin convenience - * when trying to sort through large numbers of block - * devices or filesystem images. - */ - memset(buf, 0, sizeof(buf)); - path.mnt = mnt; - path.dentry = mnt->mnt_root; - cp = d_path(&path, buf, sizeof(buf)); - if (!IS_ERR(cp)) { - handle_t *handle; - int err; - - handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); - if (IS_ERR(handle)) - return PTR_ERR(handle); - BUFFER_TRACE(sbi->s_sbh, "get_write_access"); - err = ext4_journal_get_write_access(handle, sbi->s_sbh); - if (err) { - ext4_journal_stop(handle); - return err; - } - strlcpy(sbi->s_es->s_last_mounted, cp, - sizeof(sbi->s_es->s_last_mounted)); - ext4_handle_dirty_super(handle, sb); - ext4_journal_stop(handle); - } - } + ret = ext4_sample_last_mounted(inode->i_sb, filp->f_path.mnt); + if (ret) + return ret; ret = fscrypt_file_open(inode, filp); if (ret) From patchwork Mon Apr 23 01:10:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902720 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GjhYAGbQ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40TpK43LTyz9s1P for ; Mon, 23 Apr 2018 11:09:44 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753821AbeDWBJn (ORCPT ); Sun, 22 Apr 2018 21:09:43 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:43584 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753825AbeDWBJm (ORCPT ); Sun, 22 Apr 2018 21:09:42 -0400 Received: by mail-pg0-f66.google.com with SMTP id f132so7183835pgc.10 for ; Sun, 22 Apr 2018 18:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zNfnkEjwG+aSZh5MeBLSWLAWR6LNpqi0geEjhfQXGn0=; b=GjhYAGbQuIv6q+Pn770KHbC1kt/p5HzHKmAymDQM+gbwFebIAKMOg+Q7Jy6zh3ulFK OFQ3+7NczFtrrhMMhQx8AqiHPQuPE0xUque0YPUy6ty2LnMyyMA3dJ5Q/Z9QtRGcBaCG BvrBmGwkvK/APCq49nhHpSnh9ktph2sLzLNHf8Dk3gmzqxx6ZLAgPNxfW9Jv2VsAYCh5 e7wRK0DJYq1vJa/ekD2W54R3AG/Kv22P9r42839eBhHcwPvNr5PM9Uw0jssodjRSvqE0 WGG3KXRLW4JprZTRI/C+2kE4lLCGigyqk2isbn7bmiVEIDd1CfWdc38Q62B+CoTrl1Ok YDtw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zNfnkEjwG+aSZh5MeBLSWLAWR6LNpqi0geEjhfQXGn0=; b=cbrtmgRnKQQW/rgpsaL4PZIcpARhf3Gy5XnDmvNg2I4k4suwnGl9nW8/Le6qFSFV7S YLFkKEJx+qXkH9LN0ZB45K0xuvVU/ddVIkkSAe0x0Bq8jFKqemGRV8QNuWlTPPy+FuSy pdNr/7SszpZnBvWdW99GG33IUvWNvBIZhtvGF8WZFUH+cRrlBXnEbxW3YIShh8JGXS9l QQxjSxwOiew1DMosj13rA7CGmz1e1aUnC40nZKivTqnHOAnY8hnX+Wam9qeFvWRjJQPu xVMDCkSTqvkdAXZIJ09CagGz65u+iJg9YfDHSu5C2EFNheJ3OI+jeOeMzPykLqsqPp/W co7w== X-Gm-Message-State: ALQs6tBCSw+5GzpfguoS0tIZf7nJaHl9TpiSh3WVSsFMgO4A0TvwUJNE 5kX5lHCkOqLF/ciNPNQ+GIQ= X-Google-Smtp-Source: AIpwx4940mgOE/aqG00j0uVBO+9cO5g87CSfR+2N+MLXnEOPC3iSbfumLbcNKvp2bNXZ+R6r7Bjpqw== X-Received: by 10.98.228.13 with SMTP id r13mr18055798pfh.51.1524445781566; Sun, 22 Apr 2018 18:09:41 -0700 (PDT) Received: from localhost.localdomain ([216.9.110.2]) by smtp.gmail.com with ESMTPSA id y15sm19435930pfb.37.2018.04.22.18.09.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Apr 2018 18:09:40 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v2 3/3] ext4: do not update s_last_mounted of a frozen fs Date: Sun, 22 Apr 2018 18:10:59 -0700 Message-Id: <1524445859-26970-4-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524445859-26970-1-git-send-email-amir73il@gmail.com> References: <1524445859-26970-1-git-send-email-amir73il@gmail.com> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If fs is frozen after mount and before the first file open, the update of s_last_mounted bypasses freeze protection and prints out a WARNING splat: $ mount /vdf $ fsfreeze -f /vdf $ cat /vdf/foo [ 31.578555] WARNING: CPU: 1 PID: 1415 at fs/ext4/ext4_jbd2.c:53 ext4_journal_check_start+0x48/0x82 [ 31.614016] Call Trace: [ 31.614997] __ext4_journal_start_sb+0xe4/0x1a4 [ 31.616771] ? ext4_file_open+0xb6/0x189 [ 31.618094] ext4_file_open+0xb6/0x189 If fs is frozen, skip s_last_mounted update. [backport hint: to apply to stable tree, need to apply also patches vfs: add the sb_start_intwrite_trylock() helper ext4: factor out helper ext4_sample_last_mounted()] Fixes: bc0b0d6d69ee ("ext4: update the s_last_mounted field in the superblock") Cc: Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- fs/ext4/file.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 065e95bb7186..f097a76ee54e 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -392,7 +392,7 @@ static int ext4_sample_last_mounted(struct super_block *sb, if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED)) return 0; - if (sb_rdonly(sb)) + if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb)) return 0; sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED; @@ -406,12 +406,14 @@ static int ext4_sample_last_mounted(struct super_block *sb, path.mnt = mnt; path.dentry = mnt->mnt_root; cp = d_path(&path, buf, sizeof(buf)); + err = 0; if (IS_ERR(cp)) - return 0; + goto out_intwrite; handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); + err = PTR_ERR(handle); if (IS_ERR(handle)) - return PTR_ERR(handle); + goto out_intwrite; BUFFER_TRACE(sbi->s_sbh, "get_write_access"); err = ext4_journal_get_write_access(handle, sbi->s_sbh); if (err) @@ -421,6 +423,8 @@ static int ext4_sample_last_mounted(struct super_block *sb, ext4_handle_dirty_super(handle, sb); out: ext4_journal_stop(handle); +out_intwrite: + sb_end_intwrite(sb); return err; }