blobstore: separate deserializing xattrs to common function
Signed-off-by: Piotr Pelplinski <piotr.pelplinski@intel.com> Change-Id: Icba20351c9ca76397393064b41013c527084853e Reviewed-on: https://review.gerrithub.io/396385 Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com> Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
1dab20c225
commit
79457c51db
@ -232,6 +232,47 @@ _spdk_blob_mark_clean(struct spdk_blob_data *blob)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
_spdk_blob_deserialize_xattr(struct spdk_blob_data *blob,
|
||||
struct spdk_blob_md_descriptor_xattr *desc_xattr)
|
||||
{
|
||||
struct spdk_xattr *xattr;
|
||||
|
||||
if (desc_xattr->length != sizeof(desc_xattr->name_length) +
|
||||
sizeof(desc_xattr->value_length) +
|
||||
desc_xattr->name_length + desc_xattr->value_length) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
xattr = calloc(1, sizeof(*xattr));
|
||||
if (xattr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
xattr->name = malloc(desc_xattr->name_length + 1);
|
||||
if (xattr->name == NULL) {
|
||||
free(xattr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
strncpy(xattr->name, desc_xattr->name, desc_xattr->name_length);
|
||||
xattr->name[desc_xattr->name_length] = '\0';
|
||||
|
||||
xattr->value = malloc(desc_xattr->value_length);
|
||||
if (xattr->value == NULL) {
|
||||
free(xattr->name);
|
||||
free(xattr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
xattr->value_len = desc_xattr->value_length;
|
||||
memcpy(xattr->value,
|
||||
(void *)((uintptr_t)desc_xattr->name + desc_xattr->name_length),
|
||||
desc_xattr->value_length);
|
||||
|
||||
TAILQ_INSERT_TAIL(&blob->xattrs, xattr, link);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
_spdk_blob_parse_page(const struct spdk_blob_md_page *page, struct spdk_blob_data *blob)
|
||||
{
|
||||
@ -326,42 +367,12 @@ _spdk_blob_parse_page(const struct spdk_blob_md_page *page, struct spdk_blob_dat
|
||||
}
|
||||
|
||||
} else if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_XATTR) {
|
||||
struct spdk_blob_md_descriptor_xattr *desc_xattr;
|
||||
struct spdk_xattr *xattr;
|
||||
int rc;
|
||||
|
||||
desc_xattr = (struct spdk_blob_md_descriptor_xattr *)desc;
|
||||
|
||||
if (desc_xattr->length != sizeof(desc_xattr->name_length) +
|
||||
sizeof(desc_xattr->value_length) +
|
||||
desc_xattr->name_length + desc_xattr->value_length) {
|
||||
return -EINVAL;
|
||||
rc = _spdk_blob_deserialize_xattr(blob, (struct spdk_blob_md_descriptor_xattr *) desc);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
xattr = calloc(1, sizeof(*xattr));
|
||||
if (xattr == NULL) {
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
xattr->name = malloc(desc_xattr->name_length + 1);
|
||||
if (xattr->name == NULL) {
|
||||
free(xattr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
strncpy(xattr->name, desc_xattr->name, desc_xattr->name_length);
|
||||
xattr->name[desc_xattr->name_length] = '\0';
|
||||
|
||||
xattr->value = malloc(desc_xattr->value_length);
|
||||
if (xattr->value == NULL) {
|
||||
free(xattr->name);
|
||||
free(xattr);
|
||||
return -ENOMEM;
|
||||
}
|
||||
xattr->value_len = desc_xattr->value_length;
|
||||
memcpy(xattr->value,
|
||||
(void *)((uintptr_t)desc_xattr->name + desc_xattr->name_length),
|
||||
desc_xattr->value_length);
|
||||
|
||||
TAILQ_INSERT_TAIL(&blob->xattrs, xattr, link);
|
||||
} else {
|
||||
/* Unrecognized descriptor type. Do not fail - just continue to the
|
||||
* next descriptor. If this descriptor is associated with some feature
|
||||
|
Loading…
Reference in New Issue
Block a user