* [PATCH] Btrfs: add autodefrag inode flag
@ 2015-06-19 2:10 Omar Sandoval
2015-06-30 16:18 ` David Sterba
0 siblings, 1 reply; 3+ messages in thread
From: Omar Sandoval @ 2015-06-19 2:10 UTC (permalink / raw)
To: linux-btrfs; +Cc: Omar Sandoval
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 <osandov@fb.com>
---
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 */
--
1.8.5.6
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Btrfs: add autodefrag inode flag
2015-06-19 2:10 [PATCH] Btrfs: add autodefrag inode flag Omar Sandoval
@ 2015-06-30 16:18 ` David Sterba
2015-06-30 16:24 ` Omar Sandoval
0 siblings, 1 reply; 3+ messages in thread
From: David Sterba @ 2015-06-30 16:18 UTC (permalink / raw)
To: Omar Sandoval; +Cc: linux-btrfs
On Thu, Jun 18, 2015 at 07:10:47PM -0700, Omar Sandoval wrote:
> 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.
While I think all sorts of inode flags can be useful, the autodefrag is
a good example, please note that you're touching a public interface
header
> include/uapi/linux/fs.h | 1 +
so this should be discussed at fsdevel.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Btrfs: add autodefrag inode flag
2015-06-30 16:18 ` David Sterba
@ 2015-06-30 16:24 ` Omar Sandoval
0 siblings, 0 replies; 3+ messages in thread
From: Omar Sandoval @ 2015-06-30 16:24 UTC (permalink / raw)
To: dsterba, Omar Sandoval, linux-btrfs
On 06/30/2015 09:18 AM, David Sterba wrote:
> On Thu, Jun 18, 2015 at 07:10:47PM -0700, Omar Sandoval wrote:
>> 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.
>
> While I think all sorts of inode flags can be useful, the autodefrag is
> a good example, please note that you're touching a public interface
> header
>
>> include/uapi/linux/fs.h | 1 +
>
> so this should be discussed at fsdevel.
Ah, right, definitely. I'll resend the patch and CC fsdevel.
Thanks,
--
Omar
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-06-30 16:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-19 2:10 [PATCH] Btrfs: add autodefrag inode flag Omar Sandoval
2015-06-30 16:18 ` David Sterba
2015-06-30 16:24 ` Omar Sandoval
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox