From patchwork Fri Jun 19 02:10:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 6642051 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BCE2E9F326 for ; Fri, 19 Jun 2015 02:12:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BC344200D6 for ; Fri, 19 Jun 2015 02:12:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 95546204E3 for ; Fri, 19 Jun 2015 02:12:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752345AbbFSCLi (ORCPT ); Thu, 18 Jun 2015 22:11:38 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:26283 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752228AbbFSCLg (ORCPT ); Thu, 18 Jun 2015 22:11:36 -0400 Received: from pps.filterd (m0004060 [127.0.0.1]) by mx0b-00082601.pphosted.com (8.14.5/8.14.5) with SMTP id t5J2Bajx021089 for ; Thu, 18 Jun 2015 19:11:36 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=DMFex5SWL8w+2nZAcTDsIzdx+ZJ1CECRs+8PhBuXpps=; b=ixLB57uESK8uP8UGTTSjy5rkfl37QSZdeuXVZvA2NLPbvH5okmRRtXTwZz+TPxkHGlg3 czyw9MWCCYJgnBkureSmRs1aZxNWWnWgTfj3w6FtNegkw37KRtKyJaHfNatud68siMnM LBpL++m7HTYVjIF0BdtQjUDIfNTzXe/Lrr8= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0b-00082601.pphosted.com with ESMTP id 1v47jm8gp6-1 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT) for ; Thu, 18 Jun 2015 19:11:36 -0700 Received: from huxley.thefacebook.com (192.168.52.123) by mail.thefacebook.com (192.168.16.16) with Microsoft SMTP Server (TLS) id 14.3.195.1; Thu, 18 Jun 2015 19:10:58 -0700 From: Omar Sandoval To: CC: Omar Sandoval Subject: [PATCH] Btrfs: add autodefrag inode flag Date: Thu, 18 Jun 2015 19:10:47 -0700 Message-ID: <49b5df0f2a140a18386d794447aae87e165e6559.1434679740.git.osandov@fb.com> X-Mailer: git-send-email 2.4.4 MIME-Version: 1.0 X-Originating-IP: [192.168.52.123] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.14.151, 1.0.33, 0.0.0000 definitions=2015-06-18_06:2015-06-18, 2015-06-18, 1970-01-01 signatures=0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 In some cases, we may not want to enable automatic defragmentation for the whole filesystem with the "autodefrag" mount option but we still want to defragment specific files or directories. Add an inode flag which allows us to do specify that. Signed-off-by: Omar Sandoval --- fs/btrfs/ctree.h | 1 + fs/btrfs/file.c | 18 ++++++++++-------- fs/btrfs/ioctl.c | 13 +++++++++++-- include/uapi/linux/fs.h | 1 + 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 6f364e1d8d3d..e898bb2822ef 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2234,6 +2234,7 @@ do { \ #define BTRFS_INODE_NOATIME (1 << 9) #define BTRFS_INODE_DIRSYNC (1 << 10) #define BTRFS_INODE_COMPRESS (1 << 11) +#define BTRFS_INODE_AUTODEFRAG (1 << 12) #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31) diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index b072e17479aa..33bead79da7a 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -129,15 +129,17 @@ static int __btrfs_add_inode_defrag(struct inode *inode, return 0; } -static inline int __need_auto_defrag(struct btrfs_root *root) +static inline int __need_auto_defrag(struct btrfs_root *root, + struct inode *inode) { - if (!btrfs_test_opt(root, AUTO_DEFRAG)) - return 0; - if (btrfs_fs_closing(root->fs_info)) return 0; - return 1; + if (btrfs_test_opt(root, AUTO_DEFRAG)) + return 1; + if (BTRFS_I(inode)->flags & BTRFS_INODE_AUTODEFRAG) + return 1; + return 0; } /* @@ -152,7 +154,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, u64 transid; int ret; - if (!__need_auto_defrag(root)) + if (!__need_auto_defrag(root, inode)) return 0; if (test_bit(BTRFS_INODE_IN_DEFRAG, &BTRFS_I(inode)->runtime_flags)) @@ -199,7 +201,7 @@ static void btrfs_requeue_inode_defrag(struct inode *inode, struct btrfs_root *root = BTRFS_I(inode)->root; int ret; - if (!__need_auto_defrag(root)) + if (!__need_auto_defrag(root, inode)) goto out; /* @@ -372,7 +374,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info) &fs_info->fs_state)) break; - if (!__need_auto_defrag(fs_info->tree_root)) + if (btrfs_fs_closing(fs_info)) break; /* find an inode to defrag */ diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 1c22c6518504..c1a45d507613 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -121,6 +121,8 @@ static unsigned int btrfs_flags_to_ioctl(unsigned int flags) iflags |= FS_DIRSYNC_FL; if (flags & BTRFS_INODE_NODATACOW) iflags |= FS_NOCOW_FL; + if (flags & BTRFS_INODE_AUTODEFRAG) + iflags |= FS_AUTODEFRAG_FL; if ((flags & BTRFS_INODE_COMPRESS) && !(flags & BTRFS_INODE_NOCOMPRESS)) iflags |= FS_COMPR_FL; @@ -157,7 +159,7 @@ void btrfs_update_iflags(struct inode *inode) /* * Inherit flags from the parent inode. * - * Currently only the compression flags and the cow flags are inherited. + * Currently only the compression, cow, and autodefrag flags are inherited. */ void btrfs_inherit_iflags(struct inode *inode, struct inode *dir) { @@ -182,6 +184,9 @@ void btrfs_inherit_iflags(struct inode *inode, struct inode *dir) BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM; } + if (flags & BTRFS_INODE_AUTODEFRAG) + BTRFS_I(inode)->flags |= BTRFS_INODE_AUTODEFRAG; + btrfs_update_iflags(inode); } @@ -201,7 +206,7 @@ static int check_flags(unsigned int flags) FS_NOATIME_FL | FS_NODUMP_FL | \ FS_SYNC_FL | FS_DIRSYNC_FL | \ FS_NOCOMP_FL | FS_COMPR_FL | - FS_NOCOW_FL)) + FS_NOCOW_FL | FS_AUTODEFRAG_FL)) return -EOPNOTSUPP; if ((flags & FS_NOCOMP_FL) && (flags & FS_COMPR_FL)) @@ -278,6 +283,10 @@ static int btrfs_ioctl_setflags(struct file *file, void __user *arg) ip->flags |= BTRFS_INODE_DIRSYNC; else ip->flags &= ~BTRFS_INODE_DIRSYNC; + if (flags & FS_AUTODEFRAG_FL) + ip->flags |= BTRFS_INODE_AUTODEFRAG; + else + ip->flags &= ~BTRFS_INODE_AUTODEFRAG; if (flags & FS_NOCOW_FL) { if (S_ISREG(mode)) { /* diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 9b964a5920af..8c7e8c7a0236 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -197,6 +197,7 @@ struct inodes_stat_t { #define FS_EXTENT_FL 0x00080000 /* Extents */ #define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ #define FS_NOCOW_FL 0x00800000 /* Do not cow file */ +#define FS_AUTODEFRAG_FL 0x01000000 /* Auto-defragment file */ #define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ #define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */