From patchwork Tue Nov 25 05:34:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 5371641 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6F1579F319 for ; Tue, 25 Nov 2014 05:35:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 40E012015D for ; Tue, 25 Nov 2014 05:35:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2EF0620136 for ; Tue, 25 Nov 2014 05:35:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751944AbaKYFfI (ORCPT ); Tue, 25 Nov 2014 00:35:08 -0500 Received: from imap.thunk.org ([74.207.234.97]:49134 "EHLO imap.thunk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751822AbaKYFeu (ORCPT ); Tue, 25 Nov 2014 00:34:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=thunk.org; s=ef5046eb; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=I4zahLjQOKqKiyZBYmUn7vbsUAdNG8hSFQDB/hsNcfQ=; b=S/YBEMqwNm874JcQllt2I6pBT+bVWa+oQqUUvwVqaSXgC6zgcAGWZUhldESI9SpQLO8spv+1kTtADJn1++xaENO2FEhbrOWkxudi2+pc7RYDTGTgHyUXBZezPt7dr4pWQwzEtM1NrKljJtyuoNh+pScfjAUrv5YFnih78ktX+HI=; Received: from root (helo=closure.thunk.org) by imap.thunk.org with local-esmtp (Exim 4.80) (envelope-from ) id 1Xt8m0-0005eg-48; Tue, 25 Nov 2014 05:34:48 +0000 Received: by closure.thunk.org (Postfix, from userid 15806) id 696AE5802D0; Tue, 25 Nov 2014 00:34:45 -0500 (EST) From: Theodore Ts'o To: Linux Filesystem Development List Cc: Ext4 Developers List , Linux btrfs Developers List , XFS Developers , Theodore Ts'o Subject: [PATCH-v3 6/6] btrfs: add an is_readonly() so btrfs can use common code for update_time() Date: Tue, 25 Nov 2014 00:34:34 -0500 Message-Id: <1416893674-419-7-git-send-email-tytso@mit.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1416893674-419-1-git-send-email-tytso@mit.edu> References: <1416893674-419-1-git-send-email-tytso@mit.edu> X-SA-Exim-Connect-IP: X-SA-Exim-Mail-From: tytso@thunk.org X-SA-Exim-Scanned: No (on imap.thunk.org); SAEximRunCond expanded to false Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,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 The only reason btrfs cloned code from the VFS layer was so it could add a check to see if a subvolume is read-ony. Instead of doing that, let's add a new inode operation which allows a file system to return an error if the inode is read-only, and use that in update_time(). There may be other places where the VFS layer may want to know that btrfs would want to treat an inode is read-only. With this commit, there are no remaining users of update_time() in the inode operations structure, so we can remove it and simply things further. Signed-off-by: Theodore Ts'o Cc: linux-btrfs@vger.kernel.org Reviewed-by: David Sterba --- fs/btrfs/inode.c | 26 ++++++-------------------- fs/inode.c | 22 +++++++++++----------- include/linux/fs.h | 2 +- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index a5e0d0d..0bfe3a4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5554,26 +5554,12 @@ static int btrfs_dirty_inode(struct inode *inode) return ret; } -/* - * This is a copy of file_update_time. We need this so we can return error on - * ENOSPC for updating the inode in the case of file write and mmap writes. - */ -static int btrfs_update_time(struct inode *inode, struct timespec *now, - int flags) +static int btrfs_is_readonly(struct inode *inode) { struct btrfs_root *root = BTRFS_I(inode)->root; if (btrfs_root_readonly(root)) return -EROFS; - - if (flags & S_VERSION) - inode_inc_iversion(inode); - if (flags & S_CTIME) - inode->i_ctime = *now; - if (flags & S_MTIME) - inode->i_mtime = *now; - if (flags & S_ATIME) - inode->i_atime = *now; return 0; } @@ -9466,8 +9452,8 @@ static const struct inode_operations btrfs_dir_inode_operations = { .permission = btrfs_permission, .get_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, - .update_time = btrfs_update_time, .write_time = btrfs_write_time, + .is_readonly = btrfs_is_readonly, .tmpfile = btrfs_tmpfile, }; static const struct inode_operations btrfs_dir_ro_inode_operations = { @@ -9475,8 +9461,8 @@ static const struct inode_operations btrfs_dir_ro_inode_operations = { .permission = btrfs_permission, .get_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, - .update_time = btrfs_update_time, .write_time = btrfs_write_time, + .is_readonly = btrfs_is_readonly, }; static const struct file_operations btrfs_dir_file_operations = { @@ -9546,8 +9532,8 @@ static const struct inode_operations btrfs_file_inode_operations = { .fiemap = btrfs_fiemap, .get_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, - .update_time = btrfs_update_time, .write_time = btrfs_write_time, + .is_readonly = btrfs_is_readonly, }; static const struct inode_operations btrfs_special_inode_operations = { .getattr = btrfs_getattr, @@ -9559,8 +9545,8 @@ static const struct inode_operations btrfs_special_inode_operations = { .removexattr = btrfs_removexattr, .get_acl = btrfs_get_acl, .set_acl = btrfs_set_acl, - .update_time = btrfs_update_time, .write_time = btrfs_write_time, + .is_readonly = btrfs_is_readonly, }; static const struct inode_operations btrfs_symlink_inode_operations = { .readlink = generic_readlink, @@ -9573,8 +9559,8 @@ static const struct inode_operations btrfs_symlink_inode_operations = { .getxattr = btrfs_getxattr, .listxattr = btrfs_listxattr, .removexattr = btrfs_removexattr, - .update_time = btrfs_update_time, .write_time = btrfs_write_time, + .is_readonly = btrfs_is_readonly, }; const struct dentry_operations btrfs_dentry_operations = { diff --git a/fs/inode.c b/fs/inode.c index 1f90591..e83c6d2 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -1555,20 +1555,20 @@ static int update_time(struct inode *inode, struct timespec *time, int flags) unsigned short daycode; int ret; - if (inode->i_op->update_time) { - ret = inode->i_op->update_time(inode, time, flags); + if (inode->i_op->is_readonly) { + ret = inode->i_op->is_readonly(inode); if (ret) return ret; - } else { - if (flags & S_ATIME) - inode->i_atime = *time; - if (flags & S_VERSION) - inode_inc_iversion(inode); - if (flags & S_CTIME) - inode->i_ctime = *time; - if (flags & S_MTIME) - inode->i_mtime = *time; } + if (flags & S_ATIME) + inode->i_atime = *time; + if (flags & S_VERSION) + inode_inc_iversion(inode); + if (flags & S_CTIME) + inode->i_ctime = *time; + if (flags & S_MTIME) + inode->i_mtime = *time; + /* * If i_ts_dirty_day is zero, then either we have not deferred * timestamp updates, or the system has been up for less than diff --git a/include/linux/fs.h b/include/linux/fs.h index dbbd642..70711c8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1545,8 +1545,8 @@ struct inode_operations { int (*removexattr) (struct dentry *, const char *); int (*fiemap)(struct inode *, struct fiemap_extent_info *, u64 start, u64 len); - int (*update_time)(struct inode *, struct timespec *, int); int (*write_time)(struct inode *); + int (*is_readonly)(struct inode *); int (*atomic_open)(struct inode *, struct dentry *, struct file *, unsigned open_flag, umode_t create_mode, int *opened);