[PATCH v5] Btrfs-progs: add dedup subcommand
This adds deduplication subcommands, 'btrfs dedup command path', including enable/disable/on/off. - btrfs dedup enable Create the dedup tree, and it's the very first step when you're going to use the dedup feature. - btrfs dedup disable Delete the dedup tree, after this we're not able to use dedup any more unless you enable it again. - btrfs dedup on [-b] Switch on the dedup feature temporarily, and it's the second step of applying dedup with writes. Option '-b' is used to set dedup blocksize. The default blocksize is 8192(no special reason, you may argue), and the current limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the upper limit of btrfs's compression. - btrfs dedup off Switch off the dedup feature temporarily, but the dedup tree remains. - Usage: Step 1: btrfs dedup enable /btrfs Step 2: btrfs dedup on /btrfs or btrfs dedup on -b 4K /btrfs Step 3: now we have dedup, run your test. Step 4: btrfs dedup off /btrfs Step 5: btrfs dedup disable /btrfs - Signed-off-by: Liu Bo bo.li@oracle.com --- v4: rebase and reserve spare space in btrfs_ioctl_dedup_args struct. v3: add commands 'btrfs dedup on/off' v2: add manpage Makefile | 2 +- btrfs.c| 1 + cmds-dedup.c | 178 + commands.h | 2 + ctree.h| 2 + ioctl.h| 12 man/btrfs.8.in | 31 +- 7 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 cmds-dedup.c diff --git a/Makefile b/Makefile index da05197..369df6c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,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-property.o cmds-dedup.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ diff --git a/btrfs.c b/btrfs.c index 98ff6f5..16458ef 100644 --- a/btrfs.c +++ b/btrfs.c @@ -256,6 +256,7 @@ static const struct cmd_group btrfs_cmd_group = { { quota, cmd_quota, NULL, quota_cmd_group, 0 }, { qgroup, cmd_qgroup, NULL, qgroup_cmd_group, 0 }, { replace, cmd_replace, NULL, replace_cmd_group, 0 }, + { dedup, cmd_dedup, NULL, dedup_cmd_group, 0 }, { help, cmd_help, cmd_help_usage, NULL, 0 }, { version, cmd_version, cmd_version_usage, NULL, 0 }, NULL_CMD_STRUCT diff --git a/cmds-dedup.c b/cmds-dedup.c new file mode 100644 index 000..b959349 --- /dev/null +++ b/cmds-dedup.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2013 Oracle. 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. + */ + +#include sys/ioctl.h +#include unistd.h +#include getopt.h + +#include ctree.h +#include ioctl.h + +#include commands.h +#include utils.h + +static const char * const dedup_cmd_group_usage[] = { + btrfs dedup command [options] path, + NULL +}; + +int dedup_ctl(char *path, struct btrfs_ioctl_dedup_args *args) +{ + int ret = 0; + int fd; + int e; + DIR *dirstream = NULL; + + fd = open_file_or_dir(path, dirstream); + if (fd 0) { + fprintf(stderr, ERROR: can't access '%s'\n, path); + return -EACCES; + } + + ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, args); + e = errno; + close_file_or_dir(fd, dirstream); + if (ret 0) { + fprintf(stderr, ERROR: dedup command failed: %s\n, + strerror(e)); + if (args-cmd == BTRFS_DEDUP_CTL_DISABLE || + args-cmd == BTRFS_DEDUP_CTL_SET_BS) + fprintf(stderr, please refer to 'dmesg | tail' for more info\n); + return -EINVAL; + } + return 0; +} + +static const char * const cmd_dedup_enable_usage[] = { + btrfs dedup enable path, + Enable data deduplication support for a filesystem., +
Re: [PATCH v5] Btrfs-progs: add dedup subcommand
On Wed, Apr 09, 2014 at 06:10:40PM +0800, Liu Bo wrote: This adds deduplication subcommands, 'btrfs dedup command path', including enable/disable/on/off. - btrfs dedup enable Create the dedup tree, and it's the very first step when you're going to use the dedup feature. - btrfs dedup disable Delete the dedup tree, after this we're not able to use dedup any more unless you enable it again. - btrfs dedup on [-b] Switch on the dedup feature temporarily, and it's the second step of applying dedup with writes. Option '-b' is used to set dedup blocksize. The default blocksize is 8192(no special reason, you may argue), and the current limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the upper limit of btrfs's compression. - btrfs dedup off Switch off the dedup feature temporarily, but the dedup tree remains. - Usage: Step 1: btrfs dedup enable /btrfs Step 2: btrfs dedup on /btrfs or btrfs dedup on -b 4K /btrfs Step 3: now we have dedup, run your test. Step 4: btrfs dedup off /btrfs Step 5: btrfs dedup disable /btrfs - Signed-off-by: Liu Bo bo.li@oracle.com --- v5: rebase onto the latest btrfs-progs v3.14. -liubo v4: rebase and reserve spare space in btrfs_ioctl_dedup_args struct. v3: add commands 'btrfs dedup on/off' v2: add manpage Makefile | 2 +- btrfs.c| 1 + cmds-dedup.c | 178 + commands.h | 2 + ctree.h| 2 + ioctl.h| 12 man/btrfs.8.in | 31 +- 7 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 cmds-dedup.c diff --git a/Makefile b/Makefile index da05197..369df6c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,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-property.o cmds-dedup.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ diff --git a/btrfs.c b/btrfs.c index 98ff6f5..16458ef 100644 --- a/btrfs.c +++ b/btrfs.c @@ -256,6 +256,7 @@ static const struct cmd_group btrfs_cmd_group = { { quota, cmd_quota, NULL, quota_cmd_group, 0 }, { qgroup, cmd_qgroup, NULL, qgroup_cmd_group, 0 }, { replace, cmd_replace, NULL, replace_cmd_group, 0 }, + { dedup, cmd_dedup, NULL, dedup_cmd_group, 0 }, { help, cmd_help, cmd_help_usage, NULL, 0 }, { version, cmd_version, cmd_version_usage, NULL, 0 }, NULL_CMD_STRUCT diff --git a/cmds-dedup.c b/cmds-dedup.c new file mode 100644 index 000..b959349 --- /dev/null +++ b/cmds-dedup.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2013 Oracle. 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. + */ + +#include sys/ioctl.h +#include unistd.h +#include getopt.h + +#include ctree.h +#include ioctl.h + +#include commands.h +#include utils.h + +static const char * const dedup_cmd_group_usage[] = { + btrfs dedup command [options] path, + NULL +}; + +int dedup_ctl(char *path, struct btrfs_ioctl_dedup_args *args) +{ + int ret = 0; + int fd; + int e; + DIR *dirstream = NULL; + + fd = open_file_or_dir(path, dirstream); + if (fd 0) { + fprintf(stderr, ERROR: can't access '%s'\n, path); + return -EACCES; + } + + ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, args); + e = errno; + close_file_or_dir(fd, dirstream); + if (ret 0) { + fprintf(stderr, ERROR: dedup command failed: %s\n, + strerror(e)); + if (args-cmd == BTRFS_DEDUP_CTL_DISABLE || + args-cmd == BTRFS_DEDUP_CTL_SET_BS) + fprintf(stderr, please refer to 'dmesg | tail' for more info\n); + return -EINVAL;
[PATCH v5] Btrfs-progs: add dedup subcommand
This adds deduplication subcommands, 'btrfs dedup command path', including enable/disable/on/off. - btrfs dedup enable Create the dedup tree, and it's the very first step when you're going to use the dedup feature. - btrfs dedup disable Delete the dedup tree, after this we're not able to use dedup any more unless you enable it again. - btrfs dedup on [-b] Switch on the dedup feature temporarily, and it's the second step of applying dedup with writes. Option '-b' is used to set dedup blocksize. The default blocksize is 8192(no special reason, you may argue), and the current limit is [4096, 128 * 1024], because 4K is the generic page size and 128K is the upper limit of btrfs's compression. - btrfs dedup off Switch off the dedup feature temporarily, but the dedup tree remains. - Usage: Step 1: btrfs dedup enable /btrfs Step 2: btrfs dedup on /btrfs or btrfs dedup on -b 4K /btrfs Step 3: now we have dedup, run your test. Step 4: btrfs dedup off /btrfs Step 5: btrfs dedup disable /btrfs - Signed-off-by: Liu Bo bo.li@oracle.com --- v5: rebase onto the latest btrfs-progs v3.14. v4: rebase and reserve spare space in btrfs_ioctl_dedup_args struct. v3: add commands 'btrfs dedup on/off' v2: add manpage Makefile | 2 +- btrfs.c| 1 + cmds-dedup.c | 178 + commands.h | 2 + ctree.h| 2 + ioctl.h| 12 man/btrfs.8.in | 31 +- 7 files changed, 224 insertions(+), 4 deletions(-) create mode 100644 cmds-dedup.c diff --git a/Makefile b/Makefile index da05197..369df6c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,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-property.o cmds-dedup.o libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o \ uuid-tree.o libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \ diff --git a/btrfs.c b/btrfs.c index 98ff6f5..16458ef 100644 --- a/btrfs.c +++ b/btrfs.c @@ -256,6 +256,7 @@ static const struct cmd_group btrfs_cmd_group = { { quota, cmd_quota, NULL, quota_cmd_group, 0 }, { qgroup, cmd_qgroup, NULL, qgroup_cmd_group, 0 }, { replace, cmd_replace, NULL, replace_cmd_group, 0 }, + { dedup, cmd_dedup, NULL, dedup_cmd_group, 0 }, { help, cmd_help, cmd_help_usage, NULL, 0 }, { version, cmd_version, cmd_version_usage, NULL, 0 }, NULL_CMD_STRUCT diff --git a/cmds-dedup.c b/cmds-dedup.c new file mode 100644 index 000..b959349 --- /dev/null +++ b/cmds-dedup.c @@ -0,0 +1,178 @@ +/* + * Copyright (C) 2013 Oracle. 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. + */ + +#include sys/ioctl.h +#include unistd.h +#include getopt.h + +#include ctree.h +#include ioctl.h + +#include commands.h +#include utils.h + +static const char * const dedup_cmd_group_usage[] = { + btrfs dedup command [options] path, + NULL +}; + +int dedup_ctl(char *path, struct btrfs_ioctl_dedup_args *args) +{ + int ret = 0; + int fd; + int e; + DIR *dirstream = NULL; + + fd = open_file_or_dir(path, dirstream); + if (fd 0) { + fprintf(stderr, ERROR: can't access '%s'\n, path); + return -EACCES; + } + + ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, args); + e = errno; + close_file_or_dir(fd, dirstream); + if (ret 0) { + fprintf(stderr, ERROR: dedup command failed: %s\n, + strerror(e)); + if (args-cmd == BTRFS_DEDUP_CTL_DISABLE || + args-cmd == BTRFS_DEDUP_CTL_SET_BS) + fprintf(stderr, please refer to 'dmesg | tail' for more info\n); + return -EINVAL; + } + return 0; +} + +static const char * const cmd_dedup_enable_usage[] = { + btrfs dedup enable path, + Enable data