static int do_rados_getxattrs(rados_ioctx_t io_ctx, const char *oid, const char **exkeys, const char **exvals) { rados_xattrs_iter_t iter; int nval = 0, i, nfound = 0, r = 0, ret = 1; for (i = 0; exvals[i]; ++i) { ++nval; } r = rados_getxattrs(io_ctx, oid, &iter); if (r) { printf("rados_getxattrs(%s) failed with error %d\n", oid, r); return 1; } while (1) { size_t len; const char *key, *val; r = rados_getxattrs_next(iter, &key, &val, &len); if (r) { printf("rados_getxattrs(%s): rados_getxattrs_next " "returned error %d\n", oid, r); goto out_err; } if (!key) break; for (i = 0; i < nval; ++i) { if (strcmp(exkeys[i], key)) continue; if ((len == strlen(exvals[i]) + 1) && (val != NULL) && (!strcmp(exvals[i], val))) { nfound++; break; } printf("rados_getxattrs(%s): got key %s, but the " "value was %s rather than %s.\n", oid, key, val, exvals[i]); goto out_err; } } if (nfound != nval) { printf("rados_getxattrs(%s): only found %d extended attributes. " "Expected %d\n", oid, nfound, nval); goto out_err; } ret = 0; printf("rados_getxattrs(%s)\n", oid); out_err: rados_getxattrs_end(iter); return ret; }
static bRC getXattr(bpContext *ctx, xattr_pkt *xp) { int status; size_t xattr_value_length; const char *xattr_name, *xattr_value; plugin_ctx *p_ctx = (plugin_ctx *)ctx->pContext; if (!p_ctx) { return bRC_Error; } /* * See if we need to open a new xattr iterator. */ if (!p_ctx->xattr_iterator) { status = rados_getxattrs(p_ctx->ioctx, p_ctx->object_name, &p_ctx->xattr_iterator); if (status < 0) { berrno be; Jmsg(ctx, M_ERROR, "rados_getxattrs(%s) failed: %s\n", p_ctx->object_name, be.bstrerror(-status)); goto bail_out; } } /* * Get the next xattr value. */ status = rados_getxattrs_next(p_ctx->xattr_iterator, &xattr_name, &xattr_value, &xattr_value_length); if (status < 0) { berrno be; Jmsg(ctx, M_ERROR, "rados_getxattrs_next(%s) failed: %s\n", p_ctx->object_name, be.bstrerror(-status)); goto bail_out; } /* * Got last xattr ? */ if (!xattr_name) { rados_getxattrs_end(p_ctx->xattr_iterator); p_ctx->xattr_iterator = NULL; return bRC_OK; } /* * Create a new xattr and return the data in allocated memory. * Caller will free this for us. */ xp->name = bstrdup(xattr_name); xp->name_length = strlen(xattr_name) + 1; xp->value = (char *)malloc(xattr_value_length); memcpy(xp->value, xattr_value, xattr_value_length); xp->value_length = xattr_value_length; return bRC_More; bail_out: return bRC_Error; }