aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/super.c
diff options
context:
space:
mode:
authorLi Zefan <lizf@cn.fujitsu.com>2010-12-17 01:21:50 -0500
committerLi Zefan <lizf@cn.fujitsu.com>2010-12-22 10:15:45 -0500
commit261507a02ccba9afda919852263b6bc1581ce1ef (patch)
treec16bc657ff4e29a87042ceb379487f24dff01035 /fs/btrfs/super.c
parent4b72029dc3fd6ba7dc45ccd1cf0aa0ebfa209bd3 (diff)
btrfs: Allow to add new compression algorithm
Make the code aware of compression type, instead of always assuming zlib compression. Also make the zlib workspace function as common code for all compression types. Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Diffstat (limited to 'fs/btrfs/super.c')
-rw-r--r--fs/btrfs/super.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 61bd79abb805..f348f2b93164 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -69,9 +69,9 @@ enum {
69 Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum, 69 Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum,
70 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd, 70 Opt_nodatacow, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, Opt_ssd,
71 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress, 71 Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, Opt_compress,
72 Opt_compress_force, Opt_notreelog, Opt_ratio, Opt_flushoncommit, 72 Opt_compress_type, Opt_compress_force, Opt_compress_force_type,
73 Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_err, 73 Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard,
74 Opt_user_subvol_rm_allowed, 74 Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed, Opt_err,
75}; 75};
76 76
77static match_table_t tokens = { 77static match_table_t tokens = {
@@ -86,7 +86,9 @@ static match_table_t tokens = {
86 {Opt_alloc_start, "alloc_start=%s"}, 86 {Opt_alloc_start, "alloc_start=%s"},
87 {Opt_thread_pool, "thread_pool=%d"}, 87 {Opt_thread_pool, "thread_pool=%d"},
88 {Opt_compress, "compress"}, 88 {Opt_compress, "compress"},
89 {Opt_compress_type, "compress=%s"},
89 {Opt_compress_force, "compress-force"}, 90 {Opt_compress_force, "compress-force"},
91 {Opt_compress_force_type, "compress-force=%s"},
90 {Opt_ssd, "ssd"}, 92 {Opt_ssd, "ssd"},
91 {Opt_ssd_spread, "ssd_spread"}, 93 {Opt_ssd_spread, "ssd_spread"},
92 {Opt_nossd, "nossd"}, 94 {Opt_nossd, "nossd"},
@@ -112,6 +114,8 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
112 char *p, *num, *orig; 114 char *p, *num, *orig;
113 int intarg; 115 int intarg;
114 int ret = 0; 116 int ret = 0;
117 char *compress_type;
118 bool compress_force = false;
115 119
116 if (!options) 120 if (!options)
117 return 0; 121 return 0;
@@ -154,14 +158,29 @@ int btrfs_parse_options(struct btrfs_root *root, char *options)
154 btrfs_set_opt(info->mount_opt, NODATACOW); 158 btrfs_set_opt(info->mount_opt, NODATACOW);
155 btrfs_set_opt(info->mount_opt, NODATASUM); 159 btrfs_set_opt(info->mount_opt, NODATASUM);
156 break; 160 break;
157 case Opt_compress:
158 printk(KERN_INFO "btrfs: use compression\n");
159 btrfs_set_opt(info->mount_opt, COMPRESS);
160 break;
161 case Opt_compress_force: 161 case Opt_compress_force:
162 printk(KERN_INFO "btrfs: forcing compression\n"); 162 case Opt_compress_force_type:
163 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS); 163 compress_force = true;
164 case Opt_compress:
165 case Opt_compress_type:
166 if (token == Opt_compress ||
167 token == Opt_compress_force ||
168 strcmp(args[0].from, "zlib") == 0) {
169 compress_type = "zlib";
170 info->compress_type = BTRFS_COMPRESS_ZLIB;
171 } else {
172 ret = -EINVAL;
173 goto out;
174 }
175
164 btrfs_set_opt(info->mount_opt, COMPRESS); 176 btrfs_set_opt(info->mount_opt, COMPRESS);
177 if (compress_force) {
178 btrfs_set_opt(info->mount_opt, FORCE_COMPRESS);
179 pr_info("btrfs: force %s compression\n",
180 compress_type);
181 } else
182 pr_info("btrfs: use %s compression\n",
183 compress_type);
165 break; 184 break;
166 case Opt_ssd: 185 case Opt_ssd:
167 printk(KERN_INFO "btrfs: use ssd allocation scheme\n"); 186 printk(KERN_INFO "btrfs: use ssd allocation scheme\n");
@@ -898,10 +917,14 @@ static int __init init_btrfs_fs(void)
898 if (err) 917 if (err)
899 return err; 918 return err;
900 919
901 err = btrfs_init_cachep(); 920 err = btrfs_init_compress();
902 if (err) 921 if (err)
903 goto free_sysfs; 922 goto free_sysfs;
904 923
924 err = btrfs_init_cachep();
925 if (err)
926 goto free_compress;
927
905 err = extent_io_init(); 928 err = extent_io_init();
906 if (err) 929 if (err)
907 goto free_cachep; 930 goto free_cachep;
@@ -929,6 +952,8 @@ free_extent_io:
929 extent_io_exit(); 952 extent_io_exit();
930free_cachep: 953free_cachep:
931 btrfs_destroy_cachep(); 954 btrfs_destroy_cachep();
955free_compress:
956 btrfs_exit_compress();
932free_sysfs: 957free_sysfs:
933 btrfs_exit_sysfs(); 958 btrfs_exit_sysfs();
934 return err; 959 return err;
@@ -943,7 +968,7 @@ static void __exit exit_btrfs_fs(void)
943 unregister_filesystem(&btrfs_fs_type); 968 unregister_filesystem(&btrfs_fs_type);
944 btrfs_exit_sysfs(); 969 btrfs_exit_sysfs();
945 btrfs_cleanup_fs_uuids(); 970 btrfs_cleanup_fs_uuids();
946 btrfs_zlib_exit(); 971 btrfs_exit_compress();
947} 972}
948 973
949module_init(init_btrfs_fs) 974module_init(init_btrfs_fs)