From patchwork Mon Apr 23 15:00:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902983 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="oqhsV18d"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40V8jg6DWdz9ry1 for ; Tue, 24 Apr 2018 00:58:47 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755440AbeDWO6r (ORCPT ); Mon, 23 Apr 2018 10:58:47 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33546 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755419AbeDWO6p (ORCPT ); Mon, 23 Apr 2018 10:58:45 -0400 Received: by mail-pf0-f195.google.com with SMTP id f15so9528387pfn.0 for ; Mon, 23 Apr 2018 07:58:45 -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=nUkY3RHKqnNjAOVjYnquN/LOlIP2iSESsx+RKUYkAKY=; b=oqhsV18dbKJXLQ8lUCdJTYxT8Mgm/CSzupyAWJGZGAvMnKu9jLOXQXF2XeWK4EY+KV evDIbOSOU9Akd8JoBV/ZUbwQ5mWFqgwjoK2TQoMx/hPgup3tsLaH+Q0LCj/cSo9PuKFX +tfN4b15vcFlKGBNh+3cWXqW/o86VC+rOwBvs8efVcvs4uBATaBisdEY46XsJnEZl82U UBYzdcV/D+IJ3UEaxGa/vcWMNlyrmgOZmmkn5iuU/wQxeqE1lmYUGh8ZFikYBIpW/jMW UDaS3mBhG1qmEhluG1NgPtGC+BygJ9Ae1Xaujz0v+HfBxEwdy4saC7xLw0ORCidrnyPZ VWlA== 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=nUkY3RHKqnNjAOVjYnquN/LOlIP2iSESsx+RKUYkAKY=; b=qIrU+Ud8h5NUb9yTWN+gm95f5Bb7vBwAV5BAb/U6N0RSmSkFB/Z/jCcdD2SBxCDC5W XABUJnwZ3/w63m4qafxS+/6GCLfrzFIQs5tPy5WXCt/PiRxMY7WoFg5nEeHanN7HULtf DzaEZR0HlkygleKBieNPWQIhCYzGNslOHE8aZZBgmxDk7k9TzdIS9b6r6CV/QN/jjCPS R4GR1azEkfT5byUEpQsTdkGLays7vk+Affs86i9OZjvaZMAFPSZfZNSFVDGdn+aNHBFh 3MtoQ4aJjdWuRoGR6+Wuis9/dsPPwnXRGfXgPnISZApzpL3aaVH7+bJFzRHs3kBkpgOI wmtA== X-Gm-Message-State: ALQs6tCfRE5tfaRN2VDabzgjMttS8dqIGjDzx4fFsI5T6Owm5SLP7izp GzrZFSxULvdtDJV/uQTuSYnMgw== X-Google-Smtp-Source: AIpwx48KtoU5zRrxfNO1S2V+qqXQk0fNt4nQxnIenBzSUtxFz8Ym+876UrEKq0g14pTxkWpHQaBH4g== X-Received: by 10.99.116.76 with SMTP id e12mr17217172pgn.270.1524495525450; Mon, 23 Apr 2018 07:58:45 -0700 (PDT) Received: from amir-VirtualBox.event.rightround.com ([198.233.165.212]) by smtp.gmail.com with ESMTPSA id o66sm23873923pfg.90.2018.04.23.07.58.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Apr 2018 07:58:44 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v3 1/3] vfs: add the sb_start_intwrite_trylock() helper Date: Mon, 23 Apr 2018 09:00:06 -0600 Message-Id: <1524495608-14086-2-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524495608-14086-1-git-send-email-amir73il@gmail.com> References: <1524495608-14086-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. Reviewed-by: Jan Kara Signed-off-by: Amir Goldstein --- 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 15:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902984 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="LI1WapWy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40V8jj2X7dz9rxx for ; Tue, 24 Apr 2018 00:58:49 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755447AbeDWO6s (ORCPT ); Mon, 23 Apr 2018 10:58:48 -0400 Received: from mail-pf0-f195.google.com ([209.85.192.195]:33549 "EHLO mail-pf0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755435AbeDWO6r (ORCPT ); Mon, 23 Apr 2018 10:58:47 -0400 Received: by mail-pf0-f195.google.com with SMTP id f15so9528429pfn.0 for ; Mon, 23 Apr 2018 07:58:46 -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=mlK91y9bhGprfudMfn/5cBWX3JxHjqgvIveNZlnRmEs=; b=LI1WapWy/qGJD0f+Qtnjbj3WSuCRl92JGMdBLpeklNBuCHms9wfIug1+5bMMCx7XcX LFmnG6VmRklEX0KV4D0XkUqnaxHQE32fWa9667fDkxoUnlOi1skOM4RvDicDau9+27FO EuKxlFmwoA0HuE6Ps5oGzozBCDx67NE6/dLq9wBFmDgAHOaO5wUZcB9LtXYvSEmmrTgh OdmWu7dQs2hCrFD9vDB6LOoCFV5I9RPoN16xlb3/kZNClK8SN4ieL0i/SIYGgY5RjTO1 CgIrtUSncNhewFi/PX1KD9Hw6EAxm71WVUqvmB7oRPxTupI/rrCeWA4a9zww9oODes43 /hFg== 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=mlK91y9bhGprfudMfn/5cBWX3JxHjqgvIveNZlnRmEs=; b=lRkRckX+5G+bWVeJx4s7mL6ofRS6fX9zb7qFnXCpxbhj/SNf16okr5aFpgYk8tdAOc D21C6Lfkcg/C/DJrnrsVYDLTxVS3/hVcSeawvQWZDMuqSRBUfFQy5hc5qVvT9EjAPZO3 MmKlFcgh+NvxsovzRjAfNldmI6jFtEfXlAZt63gpxFy0C47vfOdPanfSxh+Y2Y6KI/sj RMrgSCkl5Fz2Es9ejkmgeszGEHy4/dSR3KLMfH5oSz6Kjt30FBFWPY/cZD1HrEca3hos 2yepwrq6uU9fsywERO/1WCRPH5IjLMCfJU8xsCBIUL1VSIhpmqtEGC7eoV9eroaibyMy C+zg== X-Gm-Message-State: ALQs6tAXV3tWfWAK7HDiO6VDj/egq+XTuNkmtCasHYTD9qQBYlGL6KrQ uBfQTTgEjDppbIHpNVe6MN8= X-Google-Smtp-Source: AIpwx48fd3D2W3jFes/AAJRYBkV5IISeN9hCl0XlJ4ehP5EKt8tTZqB1KWnEaK/dDNGGQjlQ9Q/XXA== X-Received: by 2002:a17:902:8d96:: with SMTP id v22-v6mr20980814plo.373.1524495526496; Mon, 23 Apr 2018 07:58:46 -0700 (PDT) Received: from amir-VirtualBox.event.rightround.com ([198.233.165.212]) by smtp.gmail.com with ESMTPSA id o66sm23873923pfg.90.2018.04.23.07.58.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Apr 2018 07:58:45 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v3 2/3] ext4: factor out helper ext4_sample_last_mounted() Date: Mon, 23 Apr 2018 09:00:07 -0600 Message-Id: <1524495608-14086-3-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524495608-14086-1-git-send-email-amir73il@gmail.com> References: <1524495608-14086-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 Reviewed-by: Jan Kara Signed-off-by: Amir Goldstein --- 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 15:00:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 902985 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="t/O0S3Vw"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40V8jl4PHgz9rx7 for ; Tue, 24 Apr 2018 00:58:51 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755448AbeDWO6u (ORCPT ); Mon, 23 Apr 2018 10:58:50 -0400 Received: from mail-pg0-f65.google.com ([74.125.83.65]:44200 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755419AbeDWO6s (ORCPT ); Mon, 23 Apr 2018 10:58:48 -0400 Received: by mail-pg0-f65.google.com with SMTP id l12so8575505pgp.11 for ; Mon, 23 Apr 2018 07:58:47 -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=8+by8V5EyT6gpCTBZlaZaSiFahBZOO3uBFnFsl19Ab0=; b=t/O0S3Vw1mhTDro0s/NQ6Ttinw0F6mS2HOUkzne6qiG+kyUnhR8Jogxcnj5eD5aapL bsHmKUHZp4GG5lN2fzPetmR6iN07elrvW+z2OMcJwwLkHRW2l6/wO5j2WSvB7zLQ8LII MhUjFN3Ena56Y0//PMZXI1KpIQkimEMgib9fOVyLymcESRjDmA5o+H7ZHjzgmIrw9vNJ eu9brpkqSF1PBzLzu4qumK399M6cSs+gtemRejhKuQwtK2G6J6TYHOiDMvgMs+vSuabg XCstFV+/EFUxvRoizHPeXQdnMkWLVjMazWHnGesERrnqkLXGNtzb7JvUpaOt1VMyYqGj vEuw== 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=8+by8V5EyT6gpCTBZlaZaSiFahBZOO3uBFnFsl19Ab0=; b=selK6RCZIVNnyNGGxwg5wjYnoRfHJYMGVj+XSzZBQM6Bt7/xU6oVy2ldZRajArRzZb UcKG7uL2LytuWSgrXYb4k4ywp1rZwEUpsBccuqmE7lr0oC7U78K+OgCLX25+rnihl4Id BpAUhKuMbqcTSAK5sf4DgsRb1hU5Rs8JEuHCoNrkNYE/YZSgvmluRslP2y0PCKU8y/TA A4BZ57/it+GQag7nH5Yo7G3hD9Es+1ivMYZBmKaWCxm1gXe7n5DvVOhHLCMcc3GZSyFi LTaHCSwGbkUQZYjYKyxP9rW+NaH/v+F0whmBppvxQzS0N90nTxaAuLZcC8g7BXRQ7q9H MCvA== X-Gm-Message-State: ALQs6tBfLzs9ogpkn3zRvfWozL1YB/oCh/fGQsuI+ojH8bMAOTsHJMsc Jtv9FgpkJ6ior194la44oqU= X-Google-Smtp-Source: AIpwx49TYswxlmCwLkgy4/brZwOhPJHemycX2FHzLT9jPMQiNQOjaxMjrYJ1kBBeMygMbmEkyVepXw== X-Received: by 2002:a17:902:b105:: with SMTP id q5-v6mr21678144plr.173.1524495527506; Mon, 23 Apr 2018 07:58:47 -0700 (PDT) Received: from amir-VirtualBox.event.rightround.com ([198.233.165.212]) by smtp.gmail.com with ESMTPSA id o66sm23873923pfg.90.2018.04.23.07.58.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 23 Apr 2018 07:58:46 -0700 (PDT) From: Amir Goldstein To: Theodore Tso Cc: Jan Kara , linux-ext4@vger.kernel.org Subject: [PATCH v3 3/3] ext4: do not update s_last_mounted of a frozen fs Date: Mon, 23 Apr 2018 09:00:08 -0600 Message-Id: <1524495608-14086-4-git-send-email-amir73il@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524495608-14086-1-git-send-email-amir73il@gmail.com> References: <1524495608-14086-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: Reviewed-by: Jan Kara Signed-off-by: Amir Goldstein --- fs/ext4/file.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 065e95bb7186..918a59b6bc1a 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,21 +406,25 @@ 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; handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1); + err = PTR_ERR(handle); if (IS_ERR(handle)) - return PTR_ERR(handle); + goto out; BUFFER_TRACE(sbi->s_sbh, "get_write_access"); err = ext4_journal_get_write_access(handle, sbi->s_sbh); if (err) - goto out; + goto out_journal; strlcpy(sbi->s_es->s_last_mounted, cp, sizeof(sbi->s_es->s_last_mounted)); ext4_handle_dirty_super(handle, sb); -out: +out_journal: ext4_journal_stop(handle); +out: + sb_end_intwrite(sb); return err; }