diff mbox

[v3,1/1] Btrfs: Check INCOMPAT flags on remount and add helper function

Message ID 1342822601-18340-2-git-send-email-mitch.harder@sabayonlinux.org (mailing list archive)
State New, archived
Headers show

Commit Message

Mitch Harder July 20, 2012, 10:16 p.m. UTC
In support of the recently added capability to remount with lzo
compression, provide a helper function to check the compression
INCOMPAT flags when remounting with lzo compression, and set
the flags if necessary.

Also, implement the new helper function when defragmenting with
explicit lzo compression.

Signed-off-by: Mitch Harder <mitch.harder@sabayonlinux.org>
---

v1->v2
- Remove extraneous formatting change.
v2->v3
- Consolidate into a single patch
- Convert helper function to a static inline function.

 fs/btrfs/ctree.h |   13 +++++++++++++
 fs/btrfs/ioctl.c |    7 +------
 fs/btrfs/super.c |    1 +
 3 files changed, 15 insertions(+), 6 deletions(-)

Comments

Zefan Li July 23, 2012, 1:15 a.m. UTC | #1
> diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h

> index a0ee2f8..3a1a700 100644
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3103,6 +3103,19 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
>  			       struct btrfs_root *root, const char *function,
>  			       unsigned int line, int errno);
>  
> +static inline void btrfs_chk_lzo_incompat(struct btrfs_root *root)


Isn't btrfs_set_lzo_incompat() is a better name?

> +{
> +	struct btrfs_super_block *disk_super;
> +	u64 features;
> +
> +	disk_super = root->fs_info->super_copy;
> +	features = btrfs_super_incompat_flags(disk_super);
> +	if (!(features & BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)) {
> +		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
> +		btrfs_set_super_incompat_flags(disk_super, features);
> +	}
> +}
> +


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba July 24, 2012, 12:11 p.m. UTC | #2
We don't need a helper for every incompatibility bit, let's do it in a
more generic way as suggested below [modulo syntax errors]:

On Fri, Jul 20, 2012 at 05:16:41PM -0500, Mitch Harder wrote:
> --- a/fs/btrfs/ctree.h
> +++ b/fs/btrfs/ctree.h
> @@ -3103,6 +3103,19 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
>  			       struct btrfs_root *root, const char *function,
>  			       unsigned int line, int errno);
>  
> +static inline void btrfs_chk_lzo_incompat(struct btrfs_root *root)
> +{

btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag) {

> +	struct btrfs_super_block *disk_super;
> +	u64 features;
> +
> +	disk_super = root->fs_info->super_copy;

   	disk_super = fs_info->super_copy;

> +	features = btrfs_super_incompat_flags(disk_super);
> +	if (!(features & BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)) {
> +		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;

	if (!(features & flag)) {
		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;

> +		btrfs_set_super_incompat_flags(disk_super, features);
> +	}
> +}
> +
>  #define btrfs_abort_transaction(trans, root, errno)		\
>  do {								\
>  	__btrfs_abort_transaction(trans, root, __func__,	\
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 17facea..d5fd69e 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1042,11 +1042,9 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
>  		      u64 newer_than, unsigned long max_to_defrag)
>  {
>  	struct btrfs_root *root = BTRFS_I(inode)->root;
> -	struct btrfs_super_block *disk_super;
>  	struct file_ra_state *ra = NULL;
>  	unsigned long last_index;
>  	u64 isize = i_size_read(inode);
> -	u64 features;
>  	u64 last_len = 0;
>  	u64 skip = 0;
>  	u64 defrag_end = 0;
> @@ -1233,11 +1231,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
>  		mutex_unlock(&inode->i_mutex);
>  	}
>  
> -	disk_super = root->fs_info->super_copy;
> -	features = btrfs_super_incompat_flags(disk_super);
>  	if (range->compress_type == BTRFS_COMPRESS_LZO) {
> -		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
> -		btrfs_set_super_incompat_flags(disk_super, features);
> +		btrfs_chk_lzo_incompat(root);

		btrfs_set_fs_incompat(fs_info, BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO);

>  	}
>  
>  	ret = defrag_count;
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 26da344..32c2bd9 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -401,6 +401,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
>  				compress_type = "lzo";
>  				info->compress_type = BTRFS_COMPRESS_LZO;
>  				btrfs_set_opt(info->mount_opt, COMPRESS);
> +				btrfs_chk_lzo_incompat(root);

				btrfs_set_fs_incompat(fs_info, BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO);

>  			} else if (strncmp(args[0].from, "no", 2) == 0) {
>  				compress_type = "no";
>  				info->compress_type = BTRFS_COMPRESS_NONE;
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index a0ee2f8..3a1a700 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3103,6 +3103,19 @@  void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
 			       struct btrfs_root *root, const char *function,
 			       unsigned int line, int errno);
 
+static inline void btrfs_chk_lzo_incompat(struct btrfs_root *root)
+{
+	struct btrfs_super_block *disk_super;
+	u64 features;
+
+	disk_super = root->fs_info->super_copy;
+	features = btrfs_super_incompat_flags(disk_super);
+	if (!(features & BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO)) {
+		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
+		btrfs_set_super_incompat_flags(disk_super, features);
+	}
+}
+
 #define btrfs_abort_transaction(trans, root, errno)		\
 do {								\
 	__btrfs_abort_transaction(trans, root, __func__,	\
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 17facea..d5fd69e 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1042,11 +1042,9 @@  int btrfs_defrag_file(struct inode *inode, struct file *file,
 		      u64 newer_than, unsigned long max_to_defrag)
 {
 	struct btrfs_root *root = BTRFS_I(inode)->root;
-	struct btrfs_super_block *disk_super;
 	struct file_ra_state *ra = NULL;
 	unsigned long last_index;
 	u64 isize = i_size_read(inode);
-	u64 features;
 	u64 last_len = 0;
 	u64 skip = 0;
 	u64 defrag_end = 0;
@@ -1233,11 +1231,8 @@  int btrfs_defrag_file(struct inode *inode, struct file *file,
 		mutex_unlock(&inode->i_mutex);
 	}
 
-	disk_super = root->fs_info->super_copy;
-	features = btrfs_super_incompat_flags(disk_super);
 	if (range->compress_type == BTRFS_COMPRESS_LZO) {
-		features |= BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO;
-		btrfs_set_super_incompat_flags(disk_super, features);
+		btrfs_chk_lzo_incompat(root);
 	}
 
 	ret = defrag_count;
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 26da344..32c2bd9 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -401,6 +401,7 @@  int btrfs_parse_options(struct btrfs_root *root, char *options)
 				compress_type = "lzo";
 				info->compress_type = BTRFS_COMPRESS_LZO;
 				btrfs_set_opt(info->mount_opt, COMPRESS);
+				btrfs_chk_lzo_incompat(root);
 			} else if (strncmp(args[0].from, "no", 2) == 0) {
 				compress_type = "no";
 				info->compress_type = BTRFS_COMPRESS_NONE;