Re: [PATCH v2] Btrfs-progs: add dedup subcommand

2013-09-02 Thread David Sterba
On Mon, Aug 12, 2013 at 10:45:55AM +0800, Liu Bo wrote:
 On Fri, Aug 09, 2013 at 02:51:35PM +0200, David Sterba wrote:
  I'm not sure that calling it register/unregister is the right thing, IMO
  it's more enable/disable as you write in the documentation under each
  respective command.
  
 
 Both of them are easy to be understood, but let's keep it consistent
 with the docs as you suggest :)

I'm now adding the dedup patch into integration so more people can play
with it (though the kernel part is not in btrfs-next yet). I've
committed a separate patch to do the rename, but feel free to fold it
into further revisions of your progs dedup patch, I'll drop mine then.

david
--
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 v2] Btrfs-progs: add dedup subcommand

2013-08-11 Thread Liu Bo
On Fri, Aug 09, 2013 at 02:51:35PM +0200, David Sterba wrote:
 On Thu, Aug 08, 2013 at 04:35:46PM +0800, Liu Bo wrote:
  This aims to add deduplication subcommand, 'btrfs dedup command path',
  ie. register/unregister'.
 
 I'm not sure that calling it register/unregister is the right thing, IMO
 it's more enable/disable as you write in the documentation under each
 respective command.
 

Both of them are easy to be understood, but let's keep it consistent
with the docs as you suggest :)

 Please post a list of the other commands if there are any, and the
 expected usage.
 

So far only these two commands are needed, thanks for reviewing this.

-liubo

 thanks,
 david
 
  +\fBbtrfs dedup register\fP \fIpath\fP
  +Enable data deduplication support for a filesystem.
^
 
  +.TP
  +
  +\fBbtrfs dedup unregister\fP \fIpath\fP
  +Disable data deduplication support for a filesystem.
^^^
--
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 v2] Btrfs-progs: add dedup subcommand

2013-08-09 Thread David Sterba
On Thu, Aug 08, 2013 at 04:35:46PM +0800, Liu Bo wrote:
 This aims to add deduplication subcommand, 'btrfs dedup command path',
 ie. register/unregister'.

I'm not sure that calling it register/unregister is the right thing, IMO
it's more enable/disable as you write in the documentation under each
respective command.

Please post a list of the other commands if there are any, and the
expected usage.

thanks,
david

 +\fBbtrfs dedup register\fP \fIpath\fP
 +Enable data deduplication support for a filesystem.
   ^

 +.TP
 +
 +\fBbtrfs dedup unregister\fP \fIpath\fP
 +Disable data deduplication support for a filesystem.
   ^^^
--
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


[PATCH v2] Btrfs-progs: add dedup subcommand

2013-08-08 Thread Liu Bo
This aims to add deduplication subcommand, 'btrfs dedup command path',
ie. register/unregister'.

It can be used to enable or disable dedup support for a filesystem.

Signed-off-by: Liu Bo bo.li@oracle.com
---
v2: add manpage

 Makefile   |2 +-
 btrfs.c|1 +
 cmds-dedup.c   |  101 
 commands.h |2 +
 ctree.h|2 +
 ioctl.h|5 +++
 man/btrfs.8.in |   12 +++
 7 files changed, 124 insertions(+), 1 deletions(-)
 create mode 100644 cmds-dedup.c

diff --git a/Makefile b/Makefile
index da7438e..5b4a07d 100644
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ objects = ctree.o disk-io.o radix-tree.o extent-tree.o 
print-tree.o \
 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-restore.o cmds-dedup.o
 libbtrfs_objects = send-stream.o send-utils.o rbtree.o btrfs-list.o crc32c.o
 libbtrfs_headers = send-stream.h send-utils.h send.h rbtree.h btrfs-list.h \
   crc32c.h list.h kerncompat.h radix-tree.h extent-cache.h \
diff --git a/btrfs.c b/btrfs.c
index 691adef..956905c 100644
--- a/btrfs.c
+++ b/btrfs.c
@@ -254,6 +254,7 @@ 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 },
{ 0, 0, 0, 0, 0 }
diff --git a/cmds-dedup.c b/cmds-dedup.c
new file mode 100644
index 000..a977585
--- /dev/null
+++ b/cmds-dedup.c
@@ -0,0 +1,101 @@
+/*
+ * 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 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(int cmd, int argc, char **argv)
+{
+   int ret = 0;
+   int fd;
+   int e;
+   char *path = argv[1];
+
+   if (check_argc_exact(argc, 2))
+   return -1;
+
+   fd = open_file_or_dir(path);
+   if (fd  0) {
+   fprintf(stderr, ERROR: can't access '%s'\n, path);
+   return -EACCES;
+   }
+
+   ret = ioctl(fd, BTRFS_IOC_DEDUP_CTL, cmd);
+   e = errno;
+   close(fd);
+   if (ret  0) {
+   fprintf(stderr, ERROR: dedup command failed: %s\n,
+   strerror(e));
+   if (cmd == BTRFS_DEDUP_CTL_UNREG)
+   fprintf(stderr, please refer to 'dmesg | tail' for 
more info\n);
+   return -EINVAL;
+   }
+   return 0;
+}
+
+static const char * const cmd_dedup_reg_usage[] = {
+   btrfs dedup register path,
+   Enable data deduplication support for a filesystem.,
+   NULL
+};
+
+static int cmd_dedup_reg(int argc, char **argv)
+{
+   int ret = dedup_ctl(BTRFS_DEDUP_CTL_REG, argc, argv);
+   if (ret  0)
+   usage(cmd_dedup_reg_usage);
+   return ret;
+}
+
+static const char * const cmd_dedup_unreg_usage[] = {
+   btrfs dedup unregister path,
+   Disable data deduplication support for a filesystem.,
+   NULL
+};
+
+static int cmd_dedup_unreg(int argc, char **argv)
+{
+   int ret = dedup_ctl(BTRFS_DEDUP_CTL_UNREG, argc, argv);
+   if (ret  0)
+   usage(cmd_dedup_unreg_usage);
+   return ret;
+}
+
+const struct cmd_group dedup_cmd_group = {
+   dedup_cmd_group_usage, NULL, {
+   { register, cmd_dedup_reg, cmd_dedup_reg_usage, NULL, 0 },
+   { unregister, cmd_dedup_unreg, cmd_dedup_unreg_usage, 0, 0 },
+   { 0, 0, 0, 0, 0 }
+   }
+};
+
+int cmd_dedup(int argc, char **argv)
+{
+   return handle_command_group(dedup_cmd_group, argc, argv);
+}
diff --git a/commands.h b/commands.h
index 15c616d..d31afa4 100644
--- a/commands.h
+++ b/commands.h
@@