From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Subject: [PATCH v5 8/8] btrfs-progs: property: add a dedup property
Date: Fri, 5 Feb 2016 09:23:04 +0800 [thread overview]
Message-ID: <1454635384-10106-9-git-send-email-quwenruo@cn.fujitsu.com> (raw)
In-Reply-To: <1454635384-10106-1-git-send-email-quwenruo@cn.fujitsu.com>
From: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
Normally if we enable online dedup for a fs, it's filesystem wide
de-duplication. With this property, we can explicitly disable data
de-duplication for specified files.
Signed-off-by: Wang Xiaoguang <wangxg.fnst@cn.fujitsu.com>
---
Documentation/btrfs-property.asciidoc | 2 +
props.c | 73 +++++++++++++++++++++++++++++++++++
2 files changed, 75 insertions(+)
diff --git a/Documentation/btrfs-property.asciidoc b/Documentation/btrfs-property.asciidoc
index 8b9b7f0..2fbecf6 100644
--- a/Documentation/btrfs-property.asciidoc
+++ b/Documentation/btrfs-property.asciidoc
@@ -44,6 +44,8 @@ label::::
label of device
compression::::
compression setting for an inode: lzo, zlib, or "" (empty string)
+dedup::::
+online dedup setting for an inode: disable or "" (empty string)
*list* [-t <type>] <object>::
Lists available properties with their descriptions for the given object.
diff --git a/props.c b/props.c
index 5b74932..f27eb8b 100644
--- a/props.c
+++ b/props.c
@@ -187,6 +187,77 @@ out:
return ret;
}
+static int prop_dedup(enum prop_object_type type, const char *object,
+ const char *name, const char *value)
+{
+ int ret;
+ ssize_t sret;
+ int fd = -1;
+ DIR *dirstream = NULL;
+ char *buf = NULL;
+ char *xattr_name = NULL;
+ int open_flags = value ? O_RDWR : O_RDONLY;
+
+ fd = open_file_or_dir3(object, &dirstream, open_flags);
+ if (fd == -1) {
+ ret = -errno;
+ fprintf(stderr, "ERROR: open %s failed. %s\n",
+ object, strerror(-ret));
+ goto out;
+ }
+
+ xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
+ if (!xattr_name) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ memcpy(xattr_name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN);
+ memcpy(xattr_name + XATTR_BTRFS_PREFIX_LEN, name, strlen(name));
+ xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';
+
+ if (value)
+ sret = fsetxattr(fd, xattr_name, value, strlen(value), 0);
+ else
+ sret = fgetxattr(fd, xattr_name, NULL, 0);
+ if (sret < 0) {
+ ret = -errno;
+ if (ret != -ENOATTR)
+ fprintf(stderr,
+ "ERROR: failed to %s dedup for %s. %s\n",
+ value ? "set" : "get", object, strerror(-ret));
+ else
+ ret = 0;
+ goto out;
+ }
+ if (!value) {
+ size_t len = sret;
+
+ buf = malloc(len);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto out;
+ }
+ sret = fgetxattr(fd, xattr_name, buf, len);
+ if (sret < 0) {
+ ret = -errno;
+ fprintf(stderr,
+ "ERROR: failed to get dedup for %s. %s\n",
+ object, strerror(-ret));
+ goto out;
+ }
+ fprintf(stdout, "dedup=%.*s\n", (int)len, buf);
+ }
+
+ ret = 0;
+out:
+ free(xattr_name);
+ free(buf);
+ if (fd >= 0)
+ close_file_or_dir(fd, dirstream);
+
+ return ret;
+}
+
const struct prop_handler prop_handlers[] = {
{"ro", "Set/get read-only flag of subvolume.", 0, prop_object_subvol,
prop_read_only},
@@ -194,5 +265,7 @@ const struct prop_handler prop_handlers[] = {
prop_object_dev | prop_object_root, prop_label},
{"compression", "Set/get compression for a file or directory", 0,
prop_object_inode, prop_compression},
+ {"dedup", "Set/get dedup for a file or directory", 0,
+ prop_object_inode, prop_dedup},
{NULL, NULL, 0, 0, NULL}
};
--
2.7.0
prev parent reply other threads:[~2016-02-05 1:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-05 1:22 [PATCH v5 0/8] btrfs-progs: Support in-band de-duplication Qu Wenruo
2016-02-05 1:22 ` [PATCH v5 1/8] btrfs-progs: Basic framework for dedup command group Qu Wenruo
2016-02-05 1:22 ` [PATCH v5 2/8] btrfs-progs: dedup: Add enable command " Qu Wenruo
2016-02-05 1:22 ` [PATCH v5 3/8] btrfs-progs: dedup: Add disable support for inband deduplication Qu Wenruo
2016-02-05 1:23 ` [PATCH v5 4/8] btrfs-progs: dedup: Add status subcommand Qu Wenruo
2016-02-05 1:23 ` [PATCH v5 5/8] btrfs-progs: Add dedup feature for mkfs and convert Qu Wenruo
2016-02-05 1:23 ` [PATCH v5 6/8] btrfs-progs: Add show-super support for new DEDUP flag Qu Wenruo
2016-02-05 1:23 ` [PATCH v5 7/8] btrfs-progs: debug-tree: Add dedup tree support Qu Wenruo
2016-02-05 1:23 ` Qu Wenruo [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1454635384-10106-9-git-send-email-quwenruo@cn.fujitsu.com \
--to=quwenruo@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=wangxg.fnst@cn.fujitsu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).