Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3313927imu; Sun, 11 Nov 2018 12:10:20 -0800 (PST) X-Google-Smtp-Source: AJdET5crVqA03F4FXrj0cP1f1gyrT0WmVHImcORVjG54MxNHK3t7/cobgiK9NfeV6bAxCEiuwcu4 X-Received: by 2002:a17:902:4683:: with SMTP id p3-v6mr17560168pld.215.1541967020871; Sun, 11 Nov 2018 12:10:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541967020; cv=none; d=google.com; s=arc-20160816; b=LGP1VsJu6F1TNDvOICttwdcyoJ4t8OvAnHorD4rOULT/pkwexI68/UkLkZYmLc7ZV9 5KeLZMDcV5IaBc0DaETFYLoEZH2COlCZfUqYlee9Ea4luPcIKTuQOG55maUQsPbi8nCN OwMi36R4LCgipAWWFcYqMgcKM9YRc2CyS55ABuxes1Qo2S33+Riwjn1DP+yPX9Js/fsN chwH7pKZ2YKT7Xr5SL7cqP1kKTZ82xbkoqq7QDn2YyYkcEErx57glqji3lQzCDN3eEkF 56psQi6X74Bv32vQAQim9rcFSklP5ld5mJ33v8dpLbFVdwRIPcOlJOFKb/+op6F1AawK g6fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=8jG/ccBQDY5HHGFDNpohI2nhF7Jsxqw2pJIcI7oj5uw=; b=OtdXjwi+dQIQek3pNGR2kpp9aXPp65n2ewVysGxQTXBO64411vUug870EcoTAdpSQn i9EuMfEYu0XJGCK9TRzhUKMDfGtgfJwFhC3ma6L6Ft5GHqGgbJlOI3SshzazdvtzSM6N 87eEGn5y59n2QzQ1O64RGtr+y+p3b4x0PAvN7Q99wOhetMadSwP8Id8M6azMPDBKvrjM TSc6x1+t5C1EM1+cRYPVrOoxOyQTsTBsFhrjqN2cQCCyTdT1CQVC5Al0hqjqMfuaSX85 EjcWjinT8YdqdjvbSzNUhEa0uFlXcaz5SFzYXAXHh8Yb5T4J0Eaj209DYgMfhhhdujfR c1SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e32-v6si13673796pgl.129.2018.11.11.12.10.05; Sun, 11 Nov 2018 12:10:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731512AbeKLF5H (ORCPT + 99 others); Mon, 12 Nov 2018 00:57:07 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:52166 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727204AbeKLF5H (ORCPT ); Mon, 12 Nov 2018 00:57:07 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvtB-0000oJ-RG; Sun, 11 Nov 2018 19:59:21 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsO-0001Pa-N3; Sun, 11 Nov 2018 19:58:32 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Jan Kara" , "Theodore Ts'o" , "Amir Goldstein" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 044/366] ext4: factor out helper ext4_sample_last_mounted() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Amir Goldstein commit 833a950882d33a7dfc319d5e152fdf35028936eb upstream. Signed-off-by: Amir Goldstein Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara [bwh: Backported to 3.16: - Move up declaration of ret in ext4_file_open() - Adjust context] Signed-off-by: Ben Hutchings --- fs/ext4/file.c | 82 ++++++++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 36 deletions(-) --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -208,52 +208,64 @@ static int ext4_file_mmap(struct file *f 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->s_flags & MS_RDONLY) + 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; + + ret = ext4_sample_last_mounted(inode->i_sb, filp->f_path.mnt); + if (ret) + return ret; - if (unlikely(!(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED) && - !(sb->s_flags & MS_RDONLY))) { - 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); - } - } /* * Set up the jbd2_inode if we are opening the inode for * writing and the journal is present */ if (filp->f_mode & FMODE_WRITE) { - int ret = ext4_inode_attach_jinode(inode); + ret = ext4_inode_attach_jinode(inode); if (ret < 0) return ret; }