Re: [PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-04-05 Thread liubo
On 04/04/2011 05:31 PM, Konstantinos Skarlatos wrote:
 Hello,
 I would like to ask about the status of this feature/patch, is it
 accepted into btrfs code, and how can I use it?
 

Yes, it is now in the latest 2.6.39-rc1.

 I am interested in enabling compression in a specific
 folder(force-compress would be ideal) of a large btrfs volume, and
 disabling it for the rest.
 

hmm, I'm making the tool's patch, and will come soon. :)

 
 On 21/3/2011 10:57 πμ, liubo wrote:
 Data compression and data cow are controlled across the entire FS by
 mount
 options right now.  ioctls are needed to set this on a per file or per
 directory basis.  This has been proposed previously, but VFS developers
 wanted us to use generic ioctls rather than btrfs-specific ones.

 According to chris's comment, there should be just one true compression
 method(probably LZO) stored in the super.  However, before this, we would
 wait for that one method is stable enough to be adopted into the super.
 So I list it as a long term goal, and just store it in ram today.

 After applying this patch, we can use the generic FS_IOC_SETFLAGS
 ioctl to
 control file and directory's datacow and compression attribute.

 NOTE:
   - The compression type is selected by such rules:
 If we mount btrfs with compress options, ie, zlib/lzo, the type is
 it.
 Otherwise, we'll use the default compress type (zlib today).

 v1-v2:
 Rebase the patch with the latest btrfs.

 Signed-off-by: Liu Boliubo2...@cn.fujitsu.com
 ---
   fs/btrfs/ctree.h   |1 +
   fs/btrfs/disk-io.c |6 ++
   fs/btrfs/inode.c   |   32 
   fs/btrfs/ioctl.c   |   41 +
   4 files changed, 72 insertions(+), 8 deletions(-)

 diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
 index 8b4b9d1..b77d1a5 100644
 --- a/fs/btrfs/ctree.h
 +++ b/fs/btrfs/ctree.h
 @@ -1283,6 +1283,7 @@ struct btrfs_root {
   #define BTRFS_INODE_NODUMP(1  8)
   #define BTRFS_INODE_NOATIME(1  9)
   #define BTRFS_INODE_DIRSYNC(1  10)
 +#define BTRFS_INODE_COMPRESS(1  11)

   /* some macros to generate set/get funcs for the struct fields.  This
* assumes there is a lefoo_to_cpu for every type, so lets make a
 simple
 diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
 index 3e1ea3e..a894c12 100644
 --- a/fs/btrfs/disk-io.c
 +++ b/fs/btrfs/disk-io.c
 @@ -1762,6 +1762,12 @@ struct btrfs_root *open_ctree(struct
 super_block *sb,

   btrfs_check_super_valid(fs_info, sb-s_flags  MS_RDONLY);

 +/*
 + * In the long term, we'll store the compression type in the super
 + * block, and it'll be used for per file compression control.
 + */
 +fs_info-compress_type = BTRFS_COMPRESS_ZLIB;
 +
   ret = btrfs_parse_options(tree_root, options);
   if (ret) {
   err = ret;
 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
 index db67821..e687bb9 100644
 --- a/fs/btrfs/inode.c
 +++ b/fs/btrfs/inode.c
 @@ -381,7 +381,8 @@ again:
*/
   if (!(BTRFS_I(inode)-flags  BTRFS_INODE_NOCOMPRESS)
   (btrfs_test_opt(root, COMPRESS) ||
 - (BTRFS_I(inode)-force_compress))) {
 + (BTRFS_I(inode)-force_compress) ||
 + (BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))) {
   WARN_ON(pages);
   pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);

 @@ -1253,7 +1254,8 @@ static int run_delalloc_range(struct inode
 *inode, struct page *locked_page,
   ret = run_delalloc_nocow(inode, locked_page, start, end,
page_started, 0, nr_written);
   else if (!btrfs_test_opt(root, COMPRESS)
 - !(BTRFS_I(inode)-force_compress))
 + !(BTRFS_I(inode)-force_compress)
 + !(BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))
   ret = cow_file_range(inode, locked_page, start, end,
 page_started, nr_written, 1);
   else
 @@ -4581,8 +4583,6 @@ static struct inode *btrfs_new_inode(struct
 btrfs_trans_handle *trans,
   location-offset = 0;
   btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);

 -btrfs_inherit_iflags(inode, dir);
 -
   if ((mode  S_IFREG)) {
   if (btrfs_test_opt(root, NODATASUM))
   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
 @@ -4590,6 +4590,8 @@ static struct inode *btrfs_new_inode(struct
 btrfs_trans_handle *trans,
   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
   }

 +btrfs_inherit_iflags(inode, dir);
 +
   insert_inode_hash(inode);
   inode_tree_add(inode);
   return inode;
 @@ -6803,6 +6805,26 @@ static int btrfs_getattr(struct vfsmount *mnt,
   return 0;
   }

 +/*
 + * If a file is moved, it will inherit the cow and compression flags
 of the new
 + * directory.
 + */
 +static void fixup_inode_flags(struct inode *dir, struct inode *inode)
 +{
 +struct btrfs_inode *b_dir = BTRFS_I(dir);
 +struct btrfs_inode *b_inode = BTRFS_I(inode);
 +
 +if (b_dir-flags  

Re: [PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-04-05 Thread Li Zefan
liubo wrote:
 On 04/04/2011 05:31 PM, Konstantinos Skarlatos wrote:
 Hello,
 I would like to ask about the status of this feature/patch, is it
 accepted into btrfs code, and how can I use it?

 
 Yes, it is now in the latest 2.6.39-rc1.
 
 I am interested in enabling compression in a specific
 folder(force-compress would be ideal) of a large btrfs volume, and
 disabling it for the rest.

 
 hmm, I'm making the tool's patch, and will come soon. :)
 

What's wrong with this?

# chattr -c -R /btrfs/folder

(But force-compress is not implemented in the kernel)

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-04-04 Thread Konstantinos Skarlatos

Hello,
I would like to ask about the status of this feature/patch, is it 
accepted into btrfs code, and how can I use it?


I am interested in enabling compression in a specific 
folder(force-compress would be ideal) of a large btrfs volume, and 
disabling it for the rest.



On 21/3/2011 10:57 πμ, liubo wrote:

Data compression and data cow are controlled across the entire FS by mount
options right now.  ioctls are needed to set this on a per file or per
directory basis.  This has been proposed previously, but VFS developers
wanted us to use generic ioctls rather than btrfs-specific ones.

According to chris's comment, there should be just one true compression
method(probably LZO) stored in the super.  However, before this, we would
wait for that one method is stable enough to be adopted into the super.
So I list it as a long term goal, and just store it in ram today.

After applying this patch, we can use the generic FS_IOC_SETFLAGS ioctl to
control file and directory's datacow and compression attribute.

NOTE:
  - The compression type is selected by such rules:
If we mount btrfs with compress options, ie, zlib/lzo, the type is it.
Otherwise, we'll use the default compress type (zlib today).

v1-v2:
Rebase the patch with the latest btrfs.

Signed-off-by: Liu Boliubo2...@cn.fujitsu.com
---
  fs/btrfs/ctree.h   |1 +
  fs/btrfs/disk-io.c |6 ++
  fs/btrfs/inode.c   |   32 
  fs/btrfs/ioctl.c   |   41 +
  4 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8b4b9d1..b77d1a5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1283,6 +1283,7 @@ struct btrfs_root {
  #define BTRFS_INODE_NODUMP(1  8)
  #define BTRFS_INODE_NOATIME   (1  9)
  #define BTRFS_INODE_DIRSYNC   (1  10)
+#define BTRFS_INODE_COMPRESS   (1  11)

  /* some macros to generate set/get funcs for the struct fields.  This
   * assumes there is a lefoo_to_cpu for every type, so lets make a simple
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3e1ea3e..a894c12 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1762,6 +1762,12 @@ struct btrfs_root *open_ctree(struct super_block *sb,

btrfs_check_super_valid(fs_info, sb-s_flags  MS_RDONLY);

+   /*
+* In the long term, we'll store the compression type in the super
+* block, and it'll be used for per file compression control.
+*/
+   fs_info-compress_type = BTRFS_COMPRESS_ZLIB;
+
ret = btrfs_parse_options(tree_root, options);
if (ret) {
err = ret;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index db67821..e687bb9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -381,7 +381,8 @@ again:
 */
if (!(BTRFS_I(inode)-flags  BTRFS_INODE_NOCOMPRESS)
(btrfs_test_opt(root, COMPRESS) ||
-(BTRFS_I(inode)-force_compress))) {
+(BTRFS_I(inode)-force_compress) ||
+(BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))) {
WARN_ON(pages);
pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);

@@ -1253,7 +1254,8 @@ static int run_delalloc_range(struct inode *inode, struct 
page *locked_page,
ret = run_delalloc_nocow(inode, locked_page, start, end,
 page_started, 0, nr_written);
else if (!btrfs_test_opt(root, COMPRESS)
-!(BTRFS_I(inode)-force_compress))
+!(BTRFS_I(inode)-force_compress)
+!(BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))
ret = cow_file_range(inode, locked_page, start, end,
  page_started, nr_written, 1);
else
@@ -4581,8 +4583,6 @@ static struct inode *btrfs_new_inode(struct 
btrfs_trans_handle *trans,
location-offset = 0;
btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);

-   btrfs_inherit_iflags(inode, dir);
-
if ((mode  S_IFREG)) {
if (btrfs_test_opt(root, NODATASUM))
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
@@ -4590,6 +4590,8 @@ static struct inode *btrfs_new_inode(struct 
btrfs_trans_handle *trans,
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
}

+   btrfs_inherit_iflags(inode, dir);
+
insert_inode_hash(inode);
inode_tree_add(inode);
return inode;
@@ -6803,6 +6805,26 @@ static int btrfs_getattr(struct vfsmount *mnt,
return 0;
  }

+/*
+ * If a file is moved, it will inherit the cow and compression flags of the new
+ * directory.
+ */
+static void fixup_inode_flags(struct inode *dir, struct inode *inode)
+{
+   struct btrfs_inode *b_dir = BTRFS_I(dir);
+   struct btrfs_inode *b_inode = BTRFS_I(inode);
+
+   if (b_dir-flags  BTRFS_INODE_NODATACOW)
+   b_inode-flags |= BTRFS_INODE_NODATACOW;
+  

[PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-03-21 Thread liubo

Data compression and data cow are controlled across the entire FS by mount
options right now.  ioctls are needed to set this on a per file or per
directory basis.  This has been proposed previously, but VFS developers
wanted us to use generic ioctls rather than btrfs-specific ones.

According to chris's comment, there should be just one true compression
method(probably LZO) stored in the super.  However, before this, we would
wait for that one method is stable enough to be adopted into the super.
So I list it as a long term goal, and just store it in ram today.

After applying this patch, we can use the generic FS_IOC_SETFLAGS ioctl to
control file and directory's datacow and compression attribute.

NOTE:
 - The compression type is selected by such rules:
   If we mount btrfs with compress options, ie, zlib/lzo, the type is it.
   Otherwise, we'll use the default compress type (zlib today).

v1-v2:
Rebase the patch with the latest btrfs.

Signed-off-by: Liu Bo liubo2...@cn.fujitsu.com
---
 fs/btrfs/ctree.h   |1 +
 fs/btrfs/disk-io.c |6 ++
 fs/btrfs/inode.c   |   32 
 fs/btrfs/ioctl.c   |   41 +
 4 files changed, 72 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 8b4b9d1..b77d1a5 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1283,6 +1283,7 @@ struct btrfs_root {
 #define BTRFS_INODE_NODUMP (1  8)
 #define BTRFS_INODE_NOATIME(1  9)
 #define BTRFS_INODE_DIRSYNC(1  10)
+#define BTRFS_INODE_COMPRESS   (1  11)
 
 /* some macros to generate set/get funcs for the struct fields.  This
  * assumes there is a lefoo_to_cpu for every type, so lets make a simple
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 3e1ea3e..a894c12 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1762,6 +1762,12 @@ struct btrfs_root *open_ctree(struct super_block *sb,
 
btrfs_check_super_valid(fs_info, sb-s_flags  MS_RDONLY);
 
+   /*
+* In the long term, we'll store the compression type in the super
+* block, and it'll be used for per file compression control.
+*/
+   fs_info-compress_type = BTRFS_COMPRESS_ZLIB;
+
ret = btrfs_parse_options(tree_root, options);
if (ret) {
err = ret;
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index db67821..e687bb9 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -381,7 +381,8 @@ again:
 */
if (!(BTRFS_I(inode)-flags  BTRFS_INODE_NOCOMPRESS) 
(btrfs_test_opt(root, COMPRESS) ||
-(BTRFS_I(inode)-force_compress))) {
+(BTRFS_I(inode)-force_compress) ||
+(BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))) {
WARN_ON(pages);
pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS);
 
@@ -1253,7 +1254,8 @@ static int run_delalloc_range(struct inode *inode, struct 
page *locked_page,
ret = run_delalloc_nocow(inode, locked_page, start, end,
 page_started, 0, nr_written);
else if (!btrfs_test_opt(root, COMPRESS) 
-!(BTRFS_I(inode)-force_compress))
+!(BTRFS_I(inode)-force_compress) 
+!(BTRFS_I(inode)-flags  BTRFS_INODE_COMPRESS))
ret = cow_file_range(inode, locked_page, start, end,
  page_started, nr_written, 1);
else
@@ -4581,8 +4583,6 @@ static struct inode *btrfs_new_inode(struct 
btrfs_trans_handle *trans,
location-offset = 0;
btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
 
-   btrfs_inherit_iflags(inode, dir);
-
if ((mode  S_IFREG)) {
if (btrfs_test_opt(root, NODATASUM))
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
@@ -4590,6 +4590,8 @@ static struct inode *btrfs_new_inode(struct 
btrfs_trans_handle *trans,
BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
}
 
+   btrfs_inherit_iflags(inode, dir);
+
insert_inode_hash(inode);
inode_tree_add(inode);
return inode;
@@ -6803,6 +6805,26 @@ static int btrfs_getattr(struct vfsmount *mnt,
return 0;
 }
 
+/*
+ * If a file is moved, it will inherit the cow and compression flags of the new
+ * directory.
+ */
+static void fixup_inode_flags(struct inode *dir, struct inode *inode)
+{
+   struct btrfs_inode *b_dir = BTRFS_I(dir);
+   struct btrfs_inode *b_inode = BTRFS_I(inode);
+
+   if (b_dir-flags  BTRFS_INODE_NODATACOW)
+   b_inode-flags |= BTRFS_INODE_NODATACOW;
+   else
+   b_inode-flags = ~BTRFS_INODE_NODATACOW;
+
+   if (b_dir-flags  BTRFS_INODE_COMPRESS)
+   b_inode-flags |= BTRFS_INODE_COMPRESS;
+   else
+   b_inode-flags = ~BTRFS_INODE_COMPRESS;
+}
+
 static int btrfs_rename(struct inode *old_dir, struct dentry 

Re: [PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-03-21 Thread Johann Lombardi
On Mon, Mar 21, 2011 at 04:57:13PM +0800, liubo wrote:
 @@ -4581,8 +4583,6 @@ static struct inode *btrfs_new_inode(struct 
 btrfs_trans_handle *trans,
   location-offset = 0;
   btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
  
 - btrfs_inherit_iflags(inode, dir);
 -
   if ((mode  S_IFREG)) {
   if (btrfs_test_opt(root, NODATASUM))
   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
 @@ -4590,6 +4590,8 @@ static struct inode *btrfs_new_inode(struct 
 btrfs_trans_handle *trans,
   BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
   }
  
 + btrfs_inherit_iflags(inode, dir);

The problem is that btrfs_inherit_iflags() overwrites BTRFS_I(inode)-flags 
with the parent's flags, so you lose BTRFS_INODE_NODATA{SUM|COW}.

Johann
--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2 v2] Btrfs: Per file/directory controls for COW and compression

2011-03-21 Thread liubo
On 03/22/2011 01:43 AM, Johann Lombardi wrote:
 On Mon, Mar 21, 2011 at 04:57:13PM +0800, liubo wrote:
 @@ -4581,8 +4583,6 @@ static struct inode *btrfs_new_inode(struct 
 btrfs_trans_handle *trans,
  location-offset = 0;
  btrfs_set_key_type(location, BTRFS_INODE_ITEM_KEY);
  
 -btrfs_inherit_iflags(inode, dir);
 -
  if ((mode  S_IFREG)) {
  if (btrfs_test_opt(root, NODATASUM))
  BTRFS_I(inode)-flags |= BTRFS_INODE_NODATASUM;
 @@ -4590,6 +4590,8 @@ static struct inode *btrfs_new_inode(struct 
 btrfs_trans_handle *trans,
  BTRFS_I(inode)-flags |= BTRFS_INODE_NODATACOW;
  }
  
 +btrfs_inherit_iflags(inode, dir);
 
 The problem is that btrfs_inherit_iflags() overwrites BTRFS_I(inode)-flags 
 with the parent's flags, so you lose BTRFS_INODE_NODATA{SUM|COW}.
 

Thanks for pointing this, will fix it.

thanks,
liubo

 Johann
 

--
To unsubscribe from this list: send the line unsubscribe linux-btrfs in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html