btrfs-progs: Support for in-band de-duplication
Subsystems (3)
v2 cover btrfs-progs: Support for in-band de-duplication
Preparation patchset for in-coming (aimed for 4.6) kernel in-band de-duplication patchset.
New kernel dedup will has 2 different dedup backends and a ioctl interface to enable/disable dedup.
The ioctl interface and on-disk format (mostly) is determined, so submit this patchset first before de-duplication first.
v2:
Better objectid/offset format for dedup hash items Output hash for dedup hash items
Qu Wenruo (7):
btrfs-progs: Basic framework for dedup command group
btrfs-progs: dedup: Add enable command for dedup command group
btrfs-progs: dedup: Add disable support for inban deduplication
btrfs-progs: dedup: Add status subcommand
btrfs-progs: Add dedup feature for mkfs and convert
btrfs: dedup: Add show-super support for new DEDUP flag
btrfs-progs: dedup-tree: Add dedup tree support
Documentation/btrfs-dedup.asciidoc | 105 ++++++++++++++ Documentation/mkfs.btrfs.asciidoc | 9 ++ Makefile.in | 2 +- btrfs-convert.c | 19 ++- btrfs-debug-tree.c | 4 + btrfs-show-super.c | 17 +++ btrfs.c | 1 + cmds-dedup.c | 282 +++++++++++++++++++++++++++++++++++++ commands.h | 2 + ctree.h | 41 +++++- dedup.h | 39 +++++ ioctl.h | 23 +++ kerncompat.h | 5 + mkfs.c | 8 +- print-tree.c | 75 ++++++++++ utils.c | 38 +++-- utils.h | 7 +- 17 files changed, 653 insertions(+), 24 deletions(-) create mode 100644 Documentation/btrfs-dedup.asciidoc create mode 100644 cmds-dedup.c create mode 100644 dedup.h
Signature · 1 line
2.6.4
PATCH v2 1/7 btrfs-progs: Basic framework for dedup command group
Add basic ioctl header and command group framework for later use. Alone with basic man page doc.
--- Documentation/btrfs-dedup.asciidoc | 37 +++++++++++++++++++++++++++++ Makefile.in | 2 +- btrfs.c | 1 + cmds-dedup.c | 48 ++++++++++++++++++++++++++++++++++++++ commands.h | 2 ++ ctree.h | 34 ++++++++++++++++++++++++++- dedup.h | 39 +++++++++++++++++++++++++++++++ ioctl.h | 21 +++++++++++++++++ 8 files changed, 182 insertions(+), 2 deletions(-) create mode 100644 Documentation/btrfs-dedup.asciidoc create mode 100644 cmds-dedup.c create mode 100644 dedup.h
Documentation/btrfs-dedup.asciidoc new file +37 -0
@@ -0,0 +1,37 @@ +btrfs-dedup(8) +============== + +NAME +---- +btrfs-dedup - manage in-band (write time) de-duplication of a btrfs filesystem + +SYNOPSIS +-------- +*btrfs dedup* <subcommand> <args> + +DESCRIPTION +----------- +*btrfs dedup* is used to enable/disable or show current in-band de-duplication +status of a btrfs filesystem. + +WARNING: In-band de-duplication is still a experimental feautre of btrfs, +use with caution. + +SUBCOMMAND +---------- +Nothing yet + +EXIT STATUS +----------- +*btrfs dedup* returns a zero exit status if it succeeds. Non zero is +returned in case of failure. + +AVAILABILITY +------------ +*btrfs* is part of btrfs-progs. +Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for +further details. + +SEE ALSO +-------- +`mkfs.btrfs`(8),
Makefile.in +1 -1
@@ -74,7 +74,7 @@ cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \ cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \ cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \ cmds-restore.o cmds-rescue.o chunk-recover.o super-recover.o \ - cmds-property.o cmds-fi-usage.o + cmds-property.o cmds-fi-usage.o cmds-dedup.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o utils-lib.o rbtree-utils.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
btrfs.c +1 -0
@@ -208,6 +208,7 @@ static const struct cmd_group btrfs_cmd_group = { { "receive", cmd_receive, cmd_receive_usage, NULL, 0 }, { "quota", cmd_quota, NULL, "a_cmd_group, 0 }, { "qgroup", cmd_qgroup, NULL, &qgroup_cmd_group, 0 }, + { "dedup", cmd_dedup, NULL, &dedup_cmd_group, 0 }, { "replace", cmd_replace, NULL, &replace_cmd_group, 0 }, { "help", cmd_help, cmd_help_usage, NULL, 0 }, { "version", cmd_version, cmd_version_usage, NULL, 0 },
cmds-dedup.c new file +48 -0
48 lines not on this page · raw message
commands.h +2 -0
@@ -93,6 +93,7 @@ extern const struct cmd_group inspect_cmd_group;extern const struct cmd_group property_cmd_group;extern const struct cmd_group quota_cmd_group;extern const struct cmd_group qgroup_cmd_group; +extern const struct cmd_group dedup_cmd_group;extern const struct cmd_group replace_cmd_group;extern const struct cmd_group rescue_cmd_group;
@@ -118,6 +119,7 @@ int cmd_send(int argc, char **argv);int cmd_receive (int argc,char **argv);int cmd_quota (int argc,char **argv);int cmd_qgroup (int argc,char **argv); +int cmd_dedup (int argc,char **argv);int cmd_replace (int argc,char **argv);int cmd_restore (int argc,char **argv);int cmd_select_super (int argc,char **argv);
ctree.h +33 -1
@@ -476,9 +476,11 @@ struct btrfs_super_block {#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8)#define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) +#define BTRFS_FEATURE_COMPAT_RO_DEDUP (1ULL << 0)#define BTRFS_FEATURE_COMPAT_SUPP 0ULL -#define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL +#define BTRFS_FEATURE_COMPAT_RO_SUPP \ + (BTRFS_FEATURE_COMPAT_RO_DEDUP)#define BTRFS_FEATURE_INCOMPAT_SUPP \ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL | \
@@ -828,6 +830,23 @@ struct btrfs_csum_item {u8 csum; } __attribute__ ((__packed__)); +struct btrfs_dedup_status_item { +__le64 blocksize; +__le64 limit_nr; +__le16 hash_type; +__le16 backend; +} __attribute__ ((__packed__ )); + +struct btrfs_dedup_hash_item { +/* on disk length of dedup range */ +__le64 len; + +/* Spare space */ +u8 __unused[16 ]; + +/* Hash follows */ +} __attribute__ ((__packed__ )); +/* * We don't want to overwrite 1M at the beginning of device, even though * there is our 1st superblock at 64k. Some possible reasons:
@@ -2032,6 +2051,19 @@ static inline unsigned long btrfs_leaf_data(struct extent_buffer *l)return offsetof(struct btrfs_leaf , items); } +/* btrfs_dedup_status */ +BTRFS_SETGET_FUNCS(dedup_status_blocksize, struct btrfs_dedup_status_item, + blocksize,64 ); +BTRFS_SETGET_FUNCS(dedup_status_limit, struct btrfs_dedup_status_item, + limit_nr,64 ); +BTRFS_SETGET_FUNCS(dedup_status_hash_type, struct btrfs_dedup_status_item, + hash_type,16 ); +BTRFS_SETGET_FUNCS(dedup_status_backend, struct btrfs_dedup_status_item, + backend,16 ); + +/* btrfs_dedup_hash_item */ +BTRFS_SETGET_FUNCS(dedup_hash_len, struct btrfs_dedup_hash_item, len, 64); +/* struct btrfs_file_extent_item */ BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type, 8);
dedup.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (C) 2015 Fujitsu. All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License v2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA. +*/ + +#ifndef __BTRFS_DEDUP__ +#define __BTRFS_DEDUP__ + +/* +* Dedup storage backend +* On disk is persist storage but overhead is large +* In memory is fast but will lose all its hash on umount +*/ +#define BTRFS_DEDUP_BACKEND_INMEMORY 0 +#define BTRFS_DEDUP_BACKEND_ONDISK 1 +#define BTRFS_DEDUP_BACKEND_LAST 2 + +/* Dedup block size limit and default value */ +#define BTRFS_DEDUP_BLOCKSIZE_MAX (128 * 1024) +#define BTRFS_DEDUP_BLOCKSIZE_MIN (16 * 1024) +#define BTRFS_DEDUP_BLOCKSIZE_DEFAULT (32 * 1024) + +/* Hash algorithm, only support SHA256 yet */ +#define BTRFS_DEDUP_HASH_SHA256 0 + +#endif
ioctl.h +21 -0
@@ -466,6 +466,27 @@ struct btrfs_ioctl_get_dev_stats {__u64 unused[128 -2 -BTRFS_DEV_STAT_VALUES_MAX ];/* pad to 1k */ }; +/* +* de-duplication control modes +* For re-config, re-enable will handle it +* TODO: Add support to disable per-file/dir dedup operation +*/ +#define BTRFS_DEDUP_CTL_ENABLE 1 +#define BTRFS_DEDUP_CTL_DISABLE 2 +#define BTRFS_DEDUP_CTL_STATUS 3 +#define BTRFS_DEDUP_CTL_LAST 4 +struct btrfs_ioctl_dedup_args { +__u16 cmd;/* In: command(see above macro) */ +__u64 blocksize;/* In/Out: For enable/status */ +__u64 limit_nr;/* In/Out: For enable/status */ +__u64 current_nr;/* Out: For status output */ +__u16 backend;/* In/Out: For enable/status */ +__u16 hash_type;/* In/Out: For enable/status */ +u8 status;/* Out: For status output */ +/* pad to 512 bytes */ +u8 __unused[489 ]; +}; +/* BTRFS_IOC_SNAP_CREATE is no longer used by the btrfs command */ #define BTRFS_QUOTA_CTL_ENABLE 1#define BTRFS_QUOTA_CTL_DISABLE 2
Signature · 1 line
2.6.4
PATCH v2 2/7 btrfs-progs: dedup: Add enable command for dedup command group
In reply to Qu WenruoAdd enable subcommand for dedup commmand group.
--- Documentation/btrfs-dedup.asciidoc | 62 ++++++++++++++++++- cmds-dedup.c | 120 +++++++++++++++++++++++++++++++++++++ ioctl.h | 2 + kerncompat.h | 5 ++ 4 files changed, 188 insertions(+), 1 deletion(-)
Documentation/btrfs-dedup.asciidoc +61 -1
@@ -19,7 +19,67 @@ use with caution. SUBCOMMAND ---------- -Nothing yet +*enable* [options] <path>:: +Enable in-band de-duplication for a filesystem. ++ +`Options` ++ +-s|--storage-backend <BACKEND>:::: +Specify de-duplication hash storage backend. +Supported backends are 'ondisk' and 'inmemory' +If not specified, default value is 'inmemory'. ++ +Refer to *BACKENDS* sector for more information. + +-b|--blocksize <BLOCKSIZE>:::: +Specify dedup block size. +Supported values are power of 2 from '16K' to '128K'. +Default value is the larger of page size and '32K'. ++ +Refer to *BLOCKSIZE* sector for more information. + +-a|--hash-algorithm <HASH>:::: +Specify hash algorithm. +Only 'sha256' is supported yet. + +-l|--limit <LIMIT>:::: +Specify limit of hash number. +Only works for 'inmemory' backend. +If *LIMIT* is zero, there will be no limit at all. Use with caution as it can +use up all the memory for dedup hash. +Default value is 4096 if using 'inmemory' backend. + +BACKENDS +-------- +Btrfs in-band de-duplication support two different backends with their own +features. + +In-memory backend:: +Designed for speed, in-memory backend will keep all dedup hash into memory. +And it has a limit of number of hash kept in-memory. +Hashes over the limit will be dropped following last recent use behavior. +So this backend has a consistent overhead for given limit but can't ensure +any all duplicated data will be de-duplicated. ++ +After umount and mount, in-memory backend need to refill its hash table. + +On-disk backend:: +Designed for de-duplication rate, on-disk backend will keep dedup hash on disk. +This behavior may cause extra disk IO for de-duplication, but will have a much +higher dedup rate. ++ +After umount and mount, on-disk backend still has its hash on disk, no need to +refill its dedup hash table. + +BLOCKSIZE +--------- +Block in-band de-duplication is done at block size unit. +Any data smaller than dedup block size won't go through the dedup backends. + +Smaller block size will cause more fragments and lower performance, but a +higher dedup rate. +Larger block size will cause less fragments and higher performance, but a +lower dedup rate. EXIT STATUS -----------
cmds-dedup.c +120 -0
128 lines not on this page · raw message
ioctl.h +2 -0
@@ -698,6 +698,8 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_dev_replace_args)#define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \ struct btrfs_ioctl_same_args) +#define BTRFS_IOC_DEDUP_CTL _IOWR(BTRFS_IOCTL_MAGIC, 55, \ + struct btrfs_ioctl_dedup_args)#define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ struct btrfs_ioctl_feature_flags)#define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
kerncompat.h +5 -0
@@ -310,6 +310,11 @@ static inline long IS_ERR(const void *ptr)#define __bitwise#endif +static inline int is_power_of_2 (unsigned long n) +{ +return (n !=0 && ((n & (n -1 )) ==0 )); +} +typedef u16 __bitwise __le16 ;typedef u16 __bitwise __be16 ;typedef u32 __bitwise __le32 ;
Signature · 1 line
2.6.4
PATCH v2 3/7 btrfs-progs: dedup: Add disable support for inban deduplication
In reply to Qu WenruoAdd disable subcommand for dedup command group.
--- Documentation/btrfs-dedup.asciidoc | 5 +++++ cmds-dedup.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+)
Documentation/btrfs-dedup.asciidoc +5 -0
@@ -19,6 +19,11 @@ use with caution. SUBCOMMAND ---------- +*disable* <path>:: +Disable in-band de-duplication for a filesystem. ++ +This will trash all stored dedup hash. ++ *enable* [options] <path>:: Enable in-band de-duplication for a filesystem. +
cmds-dedup.c +42 -0
51 lines not on this page · raw message
Signature · 1 line
2.6.4
PATCH v2 4/7 btrfs-progs: dedup: Add status subcommand
In reply to Qu WenruoAdd status subcommand for dedup command group.
--- Documentation/btrfs-dedup.asciidoc | 3 ++ cmds-dedup.c | 72 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+)
Documentation/btrfs-dedup.asciidoc +3 -0
@@ -54,6 +54,9 @@ If *LIMIT* is zero, there will be no limit at all. Use with caution as it can use up all the memory for dedup hash. Default value is 4096 if using 'inmemory' backend. +*status* <path>:: +Show current in-band de-duplication status of a filesystem. + BACKENDS -------- Btrfs in-band de-duplication support two different backends with their own
cmds-dedup.c +72 -0
83 lines not on this page · raw message
Signature · 1 line
2.6.4
PATCH v2 5/7 btrfs-progs: Add dedup feature for mkfs and convert
In reply to Qu WenruoAdd new DEDUP ro compat flag and corresponding mkfs/convert flag 'dedup'.
Since dedup tree is completely isolated from fs tree, so even old kernel could do read mount.
So add it to RO compat flag instead of common incompat flags
--- Documentation/mkfs.btrfs.asciidoc | 9 +++++++++ btrfs-convert.c | 19 +++++++++++++------ mkfs.c | 8 ++++++-- utils.c | 38 +++++++++++++++++++++++++++----------- utils.h | 7 ++++--- 5 files changed, 59 insertions(+), 22 deletions(-)
Documentation/mkfs.btrfs.asciidoc +9 -0
@@ -207,6 +207,15 @@ reduced-size metadata for extent references, saves a few percent of metadata improved representation of file extents where holes are not explicitly stored as an extent, saves a few percent of metadata if sparse files are used +*dedup*:: +allow btrfs to use new on-disk format designed for in-band(write time) +de-duplication. ++ +on-disk storage backend and persist de-duplication status needs this feature. ++ +unlike other features, this is an RO compat flag, means old kernel can still +mount fs read-only. + BLOCK GROUPS, CHUNKS, RAID --------------------------
btrfs-convert.c +13 -6
@@ -2288,7 +2288,7 @@ err:static int do_convert (const char *devname,int datacsum,int packing,int noxattr,u32 nodesize,int copylabel,const char *fslabel,int progress, -u64 features) +u64 features,u64 ro_features) {int i, ret, blocks_per_node;int fd =-1 ;
@@ -2343,8 +2343,9 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxattfprintf (stderr,"unable to open %s\n" , devname); goto fail; } -btrfs_parse_features_to_string (features_buf, features); -if (features ==BTRFS_MKFS_DEFAULT_FEATURES ) +btrfs_parse_features_to_string (features_buf, features, ro_features); +if (features ==BTRFS_MKFS_DEFAULT_FEATURES && + ro_features ==0 )strcat (features_buf," (default)" );printf ("create btrfs filesystem:\n" );
@@ -2360,6 +2361,7 @@ static int do_convert(const char *devname, int datacsum, int packing, int noxatt mkfs_cfg.sectorsize = blocksize; mkfs_cfg.stripesize = blocksize; mkfs_cfg.features = features; + mkfs_cfg.ro_features = ro_features; ret =make_btrfs (fd, &mkfs_cfg);if (ret) {
@@ -2898,6 +2900,7 @@ int main(int argc, char *argv[])char *file;char fslabel[BTRFS_LABEL_SIZE ];u64 features =BTRFS_MKFS_DEFAULT_FEATURES ; +u64 ro_features =0 ;while (1 ) {enum {GETOPT_VAL_NO_PROGRESS =256 };
@@ -2956,7 +2959,8 @@ int main(int argc, char *argv[])char *orig =strdup (optarg);char *tmp = orig; - tmp =btrfs_parse_fs_features (tmp, &features); + tmp =btrfs_parse_fs_features (tmp, &features, + &ro_features);if (tmp) { fprintf(stderr, "Unrecognized filesystem feature '%s'\n",
@@ -2974,7 +2978,9 @@ int main(int argc, char *argv[])char buf[64 ];btrfs_parse_features_to_string (buf, - features & ~BTRFS_CONVERT_ALLOWED_FEATURES ); + features & + ~BTRFS_CONVERT_ALLOWED_FEATURES , + ro_features);fprintf (stderr,"ERROR: features not allowed for convert: %s\n" , buf);
@@ -3025,7 +3031,8 @@ int main(int argc, char *argv[]) ret =do_rollback (file); }else { ret =do_convert (file, datacsum, packing, noxattr, nodesize, - copylabel, fslabel, progress, features); + copylabel, fslabel, progress, features, + ro_features); }if (ret)return 1 ;
mkfs.c +6 -2
@@ -1372,6 +1372,7 @@ int main(int ac, char **av)int saved_optind;char fs_uuid[BTRFS_UUID_UNPARSED_SIZE ] = {0 };u64 features =BTRFS_MKFS_DEFAULT_FEATURES ; +u64 ro_features =0 ;struct mkfs_allocation allocation = {0 };struct btrfs_mkfs_config mkfs_cfg;
@@ -1434,7 +1435,8 @@ int main(int ac, char **av)char *orig =strdup (optarg);char *tmp = orig; - tmp =btrfs_parse_fs_features (tmp, &features); + tmp =btrfs_parse_fs_features (tmp, &features, + &ro_features);if (tmp) { fprintf(stderr, "Unrecognized filesystem feature '%s'\n",
@@ -1677,6 +1679,7 @@ int main(int ac, char **av) mkfs_cfg.sectorsize = sectorsize; mkfs_cfg.stripesize = stripesize; mkfs_cfg.features = features; + mkfs_cfg.ro_features = ro_features; ret =make_btrfs (fd, &mkfs_cfg);if (ret) {
@@ -1831,7 +1834,8 @@ raid_groups:btrfs_group_profile_str (metadata_profile), pretty_size(allocation.system));printf ("SSD detected: %s\n" , ssd ?"yes" :"no" ); -btrfs_parse_features_to_string (features_buf, features); +btrfs_parse_features_to_string (features_buf, features, + ro_features);printf ("Incompat features: %s" , features_buf);printf ("\n" );
utils.c +27 -11
@@ -250,6 +250,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)btrfs_set_super_chunk_root_generation (&super,1 );btrfs_set_super_cache_generation (&super,-1 );btrfs_set_super_incompat_flags (&super, cfg->features); +btrfs_set_super_compat_ro_flags (&super, cfg->ro_features);if (cfg->label)strncpy (super.label, cfg->label,BTRFS_LABEL_SIZE -1 );
@@ -572,23 +573,26 @@ out:static const struct btrfs_fs_feature {const char *name;u64 flag; +u64 ro_flag;const char *desc; } mkfs_features[] = { - {"mixed-bg" ,BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS , + {"mixed-bg" ,BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS ,0 ,"mixed data and metadata block groups" }, - {"extref" ,BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF , + {"extref" ,BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF ,0 ,"increased hardlink limit per file to 65536" }, - {"raid56" ,BTRFS_FEATURE_INCOMPAT_RAID56 , + {"raid56" ,BTRFS_FEATURE_INCOMPAT_RAID56 ,0 ,"raid56 extended format" }, - {"skinny-metadata" ,BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA , + {"skinny-metadata" ,BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA ,0 ,"reduced-size metadata extent refs" }, - {"no-holes" ,BTRFS_FEATURE_INCOMPAT_NO_HOLES , + {"no-holes" ,BTRFS_FEATURE_INCOMPAT_NO_HOLES ,0 ,"no explicit hole extents for files" }, + {"dedup" ,0 ,BTRFS_FEATURE_COMPAT_RO_DEDUP , +"support on-disk dedup backend and persist dedup status" },/* Keep this one last */ - {"list-all" ,BTRFS_FEATURE_LIST_ALL ,NULL } + {"list-all" ,BTRFS_FEATURE_LIST_ALL ,0 ,NULL } }; -static int parse_one_fs_feature (const char *name,u64 *flags) +static int parse_one_fs_feature (const char *name,u64 *flags,u64 *ro_flags) {int i;int found =0 ;
@@ -597,9 +601,11 @@ static int parse_one_fs_feature(const char *name, u64 *flags)if (name[0 ] =='^' && !strcmp (mkfs_features[i].name, name +1 )) { *flags &= ~ mkfs_features[i].flag; + *ro_flags &= ~mkfs_features[i].ro_flag; found =1 ; }else if (!strcmp (mkfs_features[i].name, name)) { *flags |= mkfs_features[i].flag; + *ro_flags |= mkfs_features[i].ro_flag; found =1 ; } }
@@ -607,7 +613,7 @@ static int parse_one_fs_feature(const char *name, u64 *flags)return !found; } -void btrfs_parse_features_to_string (char *buf,u64 flags) +void btrfs_parse_features_to_string (char *buf,u64 flags,u64 ro_flags) {int i;
@@ -619,10 +625,15 @@ void btrfs_parse_features_to_string(char *buf, u64 flags)strcat (buf,", " );strcat (buf, mkfs_features[i].name); } +if (ro_flags & mkfs_features[i].ro_flag) { +if (*buf) +strcat (buf,", " ); +strcat (buf, mkfs_features[i].name); + } } } -void btrfs_process_fs_features (u64 flags) +void btrfs_process_fs_features (u64 flags,u64 ro_flags) {int i;
@@ -632,6 +643,11 @@ void btrfs_process_fs_features(u64 flags) mkfs_features[i].name, mkfs_features[i].desc); } +if (ro_flags & mkfs_features[i].ro_flag) { +printf ("Turning ON RO compat features '%s': %s\n" , + mkfs_features[i].name, + mkfs_features[i].desc); + } } }
@@ -659,7 +675,7 @@ void btrfs_list_all_fs_features(u64 mask_disallowed)* Return NULL if all features were parsed fine, otherwise return the name of * the first unparsed. */ -char *btrfs_parse_fs_features (char *namelist,u64 *flags) +char *btrfs_parse_fs_features (char *namelist,u64 *flags,u64 *ro_flags) {char *this_char;char *save_ptr =NULL ;/* Satisfy static checkers */
@@ -667,7 +683,7 @@ char* btrfs_parse_fs_features(char *namelist, u64 *flags)for (this_char =strtok_r (namelist,"," , &save_ptr); this_char !=NULL ; this_char =strtok_r (NULL ,"," , &save_ptr)) { -if (parse_one_fs_feature (this_char, flags)) +if (parse_one_fs_feature (this_char, flags, ro_flags))return this_char; }
utils.h +4 -3
@@ -102,9 +102,9 @@ void units_set_mode(unsigned *units, unsigned mode);void units_set_base (unsigned *units,unsigned base);void btrfs_list_all_fs_features (u64 mask_disallowed); -char *btrfs_parse_fs_features (char *namelist,u64 *flags); -void btrfs_process_fs_features (u64 flags); -void btrfs_parse_features_to_string (char *buf,u64 flags); +char *btrfs_parse_fs_features (char *namelist,u64 *flags,u64 *ro_flags); +void btrfs_process_fs_features (u64 flags,u64 ro_flags); +void btrfs_parse_features_to_string (char *buf,u64 flags,u64 ro_flags);struct btrfs_mkfs_config {char *label;
@@ -115,6 +115,7 @@ struct btrfs_mkfs_config {u32 sectorsize;u32 stripesize;u64 features; +u64 ro_features; };int make_btrfs (int fd,struct btrfs_mkfs_config *cfg);
Signature · 1 line
2.6.4
PATCH v2 6/7 btrfs: dedup: Add show-super support for new DEDUP flag
In reply to Qu WenruoNow btrfs-show-super can handle DEDUP ro compat flag.
--- btrfs-show-super.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
btrfs-show-super.c +17 -0
@@ -291,6 +291,15 @@ struct readable_flag_entry {u64 bit;char *output; }; +#define DEF_RO_COMPAT_FLAG_ENTRY (bit_name) \ + {BTRFS_FEATURE_COMPAT_RO_##bit_name, #bit_name} + +struct readable_flag_entry ro_compat_flags_array[] = { +DEF_RO_COMPAT_FLAG_ENTRY (DEDUP ) +}; + +static const int ro_compat_flags_num =sizeof (ro_compat_flags_array) / +sizeof (struct readable_flag_entry );#define DEF_INCOMPAT_FLAG_ENTRY (bit_name) \ {BTRFS_FEATURE_INCOMPAT_##bit_name, #bit_name}
@@ -363,6 +372,13 @@ static void __print_readable_flag(u64 flag, struct readable_flag_entry *array,printf (")\n" ); } +static void print_readable_ro_compat_flag (u64 ro_flag) +{ +return __print_readable_flag (ro_flag, ro_compat_flags_array, + ro_compat_flags_num, +BTRFS_FEATURE_COMPAT_RO_SUPP ); +} +static void print_readable_incompat_flag (u64 flag) { return __print_readable_flag(flag, incompat_flags_array,
@@ -454,6 +470,7 @@ static void dump_superblock(struct btrfs_super_block *sb, int full) (unsigned long long)btrfs_super_compat_flags(sb));printf ("compat_ro_flags\t\t0x%llx\n" , (unsigned long long )btrfs_super_compat_ro_flags (sb)); +print_readable_ro_compat_flag (btrfs_super_compat_ro_flags (sb));printf ("incompat_flags\t\t0x%llx\n" , (unsigned long long )btrfs_super_incompat_flags (sb));print_readable_incompat_flag (btrfs_super_incompat_flags (sb));
Signature · 1 line
2.6.4
PATCH v2 7/7 btrfs-progs: dedup-tree: Add dedup tree support
In reply to Qu WenruoAdd dedup tree support for btrfs-debug-tree.
---
v2:
Add support to print hex objectid/offset for dedup hash. Add support to print hex hash.
--- btrfs-debug-tree.c | 4 +++ ctree.h | 7 +++++ print-tree.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+)
btrfs-debug-tree.c +4 -0
@@ -381,6 +381,10 @@ again:printf ("multiple" ); }break ; +case BTRFS_DEDUP_TREE_OBJECTID : +if (!skip) +printf ("dedup" ); +break ;default :if (!skip) {printf ("file" );
ctree.h +7 -0
@@ -76,6 +76,9 @@ struct btrfs_free_space_ctl;/* for storing items that use the BTRFS_UUID_KEY* */ #define BTRFS_UUID_TREE_OBJECTID 9ULL +/* on-disk dedup tree (EXPERIMENTAL) */ +#define BTRFS_DEDUP_TREE_OBJECTID 10ULL +/* for storing balance parameters in the root tree */ #define BTRFS_BALANCE_OBJECTID -4ULL
@@ -1180,6 +1183,10 @@ struct btrfs_root {#define BTRFS_DEV_ITEM_KEY 216#define BTRFS_CHUNK_ITEM_KEY 228 +#define BTRFS_DEDUP_STATUS_ITEM_KEY 230 +#define BTRFS_DEDUP_HASH_ITEM_KEY 231 +#define BTRFS_DEDUP_BYTENR_ITEM_KEY 232 +#define BTRFS_BALANCE_ITEM_KEY 248/*
print-tree.c +75 -0
123 lines not on this page · raw message
Signature · 1 line
2.6.4