From 7caa514f3ce2386ea1413bce55c37d2c854f8daf Mon Sep 17 00:00:00 2001 From: Mike Gerdts Date: Mon, 20 Dec 2021 14:42:44 +0000 Subject: [PATCH] blob: blobcli should dump XATTR_INTERNAL Refactor the code that dumps XATTR into a function. Call this function for XATTR and XATTR_INTERNAL. Signed-off-by: Mike Gerdts Change-Id: Ic0cb32b14f7a34e030a48e1ea468ec63172e2bf1 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11256 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Paul Luse --- lib/blob/blobstore.c | 77 ++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 31 deletions(-) diff --git a/lib/blob/blobstore.c b/lib/blob/blobstore.c index 17a2a60a4..e39aa12ca 100644 --- a/lib/blob/blobstore.c +++ b/lib/blob/blobstore.c @@ -4548,6 +4548,50 @@ bs_dump_finish(spdk_bs_sequence_t *seq, struct spdk_bs_load_ctx *ctx, int bserrn free(ctx); } +static void +bs_dump_print_xattr(struct spdk_bs_load_ctx *ctx, struct spdk_blob_md_descriptor *desc) +{ + struct spdk_blob_md_descriptor_xattr *desc_xattr; + uint32_t i; + const char *type; + + 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) { + } + + memcpy(ctx->xattr_name, desc_xattr->name, desc_xattr->name_length); + ctx->xattr_name[desc_xattr->name_length] = '\0'; + if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_XATTR) { + type = "XATTR"; + } else if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_XATTR_INTERNAL) { + type = "XATTR_INTERNAL"; + } else { + assert(false); + type = "XATTR_?"; + } + fprintf(ctx->fp, "%s: name = \"%s\"\n", type, ctx->xattr_name); + fprintf(ctx->fp, " value = \""); + ctx->print_xattr_fn(ctx->fp, ctx->super->bstype.bstype, ctx->xattr_name, + (void *)((uintptr_t)desc_xattr->name + desc_xattr->name_length), + desc_xattr->value_length); + fprintf(ctx->fp, "\"\n"); + for (i = 0; i < desc_xattr->value_length; i++) { + if (i % 16 == 0) { + fprintf(ctx->fp, " "); + } + fprintf(ctx->fp, "%02" PRIx8 " ", *((uint8_t *)desc_xattr->name + desc_xattr->name_length + i)); + if ((i + 1) % 16 == 0) { + fprintf(ctx->fp, "\n"); + } + } + if (i % 16 != 0) { + fprintf(ctx->fp, "\n"); + } +} + static void bs_dump_print_md_page(struct spdk_bs_load_ctx *ctx) { @@ -4617,38 +4661,9 @@ bs_dump_print_md_page(struct spdk_bs_load_ctx *ctx) fprintf(ctx->fp, "\n"); } } else if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_XATTR) { - struct spdk_blob_md_descriptor_xattr *desc_xattr; - uint32_t i; - - 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) { - } - - memcpy(ctx->xattr_name, desc_xattr->name, desc_xattr->name_length); - ctx->xattr_name[desc_xattr->name_length] = '\0'; - fprintf(ctx->fp, "XATTR: name = \"%s\"\n", ctx->xattr_name); - fprintf(ctx->fp, " value = \""); - ctx->print_xattr_fn(ctx->fp, ctx->super->bstype.bstype, ctx->xattr_name, - (void *)((uintptr_t)desc_xattr->name + desc_xattr->name_length), - desc_xattr->value_length); - fprintf(ctx->fp, "\"\n"); - for (i = 0; i < desc_xattr->value_length; i++) { - if (i % 16 == 0) { - fprintf(ctx->fp, " "); - } - fprintf(ctx->fp, "%02" PRIx8 " ", *((uint8_t *)desc_xattr->name + desc_xattr->name_length + i)); - if ((i + 1) % 16 == 0) { - fprintf(ctx->fp, "\n"); - } - } - if (i % 16 != 0) { - fprintf(ctx->fp, "\n"); - } + bs_dump_print_xattr(ctx, desc); } else if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_XATTR_INTERNAL) { - /* TODO */ + bs_dump_print_xattr(ctx, desc); } else if (desc->type == SPDK_MD_DESCRIPTOR_TYPE_FLAGS) { /* TODO */ } else {