linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2 RESEND Rebased] btrfs-progs: add helper to create xattr name
Date: Wed, 26 Jun 2019 16:37:22 +0800	[thread overview]
Message-ID: <20190626083723.2094-1-anand.jain@oracle.com> (raw)
In-Reply-To: <20190626083402.1895-1-anand.jain@oracle.com>

This is a preparatory patch to add more xattr attributes, care a helper
function to alloc xattr name.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 props.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/props.c b/props.c
index efa11180d4c5..3a498bd9e904 100644
--- a/props.c
+++ b/props.c
@@ -94,6 +94,21 @@ static int prop_label(enum prop_object_type type,
 	return ret;
 }
 
+static char *alloc_xattr_name(const char *name)
+{
+	char *xattr_name;
+
+	xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
+	if (!xattr_name)
+		ERR_PTR(-ENOMEM);
+
+	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';
+
+	return xattr_name;
+}
+
 static int prop_compression(enum prop_object_type type,
 			    const char *object,
 			    const char *name,
@@ -114,14 +129,11 @@ static int prop_compression(enum prop_object_type type,
 		goto out;
 	}
 
-	xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
-	if (!xattr_name) {
-		ret = -ENOMEM;
-		goto out;
+	xattr_name = alloc_xattr_name(name);
+	if (IS_ERR(xattr_name)) {
+		error("failed to alloc xattr_name %s: %m", object);
+		return PTR_ERR(xattr_name);
 	}
-	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) {
 		if (strcmp(value, "no") == 0 || strcmp(value, "none") == 0)
-- 
1.8.3.1


  parent reply	other threads:[~2019-06-26  8:37 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26  8:33 [PATCH 0/3 RESEND Rebased] readmirror feature Anand Jain
2019-06-26  8:34 ` [PATCH 1/3 RESEND Rebased] btrfs: add inode pointer to prop_handler::validate() Anand Jain
2019-06-26  8:34 ` [PATCH 2/3 RESEND Rebased] btrfs: add readmirror property framework Anand Jain
2019-07-23 14:57   ` David Sterba
2019-07-24  2:42     ` Anand Jain
2019-06-26  8:34 ` [PATCH 3/3 RESEND Rebased] btrfs: add readmirror devid property Anand Jain
2019-07-23 14:55   ` David Sterba
2019-07-23 15:25     ` David Sterba
2019-06-26  8:37 ` Anand Jain [this message]
2019-06-26  8:37   ` [PATCH 2/2 RESEND Rebased] btrfs-progs: add readmirror policy Anand Jain
2019-07-23 13:53     ` David Sterba
2019-07-24  3:11       ` Anand Jain
2019-07-23 13:55     ` David Sterba
2019-07-02  8:09 ` [PATCH 0/3 RESEND Rebased] readmirror feature Anand Jain
2019-07-24  0:20 ` Qu Wenruo
2019-07-24  2:26   ` Anand Jain
2019-07-24  3:05     ` Qu Wenruo

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=20190626083723.2094-1-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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).