Commit c287b5b4 authored by Piotr Pelplinski's avatar Piotr Pelplinski Committed by Ben Walker
Browse files

blobstore: move xattrs parameters passed as options to separate structure



This change will allow reusing this structure for both internal
and external xattrs as well as in functions having optional xattr,
but missing other options (i.e. snapshot, clone implemented in next patches)

Signed-off-by: default avatarPiotr Pelplinski <piotr.pelplinski@intel.com>
Change-Id: Ia6619a75efa0a100168a6f8317be274823af04ab
Reviewed-on: https://review.gerrithub.io/396417


Reviewed-by: default avatarSeth Howell <seth.howell5141@gmail.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 79457c51
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -206,20 +206,24 @@ uint64_t spdk_blob_get_num_pages(struct spdk_blob *blob);
/* Return the number of clusters allocated to the blob */
uint64_t spdk_blob_get_num_clusters(struct spdk_blob *blob);

struct spdk_blob_opts {
	uint64_t  num_clusters;
	bool	thin_provision;
struct spdk_blob_xattr_opts {
	/* Number of attributes */
	size_t	xattr_count;
	size_t	count;
	/* Array of attribute names. Caller should free this array after use. */
	char	**xattr_names;
	char	**names;
	/* User context passed to get_xattr_value function */
	void	*xattr_ctx;
	void	*ctx;
	/* Callback that will return value for each attribute name. */
	void	(*get_xattr_value)(void *xattr_ctx, const char *name,
	void	(*get_value)(void *xattr_ctx, const char *name,
			     const void **value, size_t *value_len);
};

struct spdk_blob_opts {
	uint64_t  num_clusters;
	bool	thin_provision;
	struct spdk_blob_xattr_opts xattrs;
};

/* Initialize an spdk_blob_opts structure to the default blob option values. */
void spdk_blob_opts_init(struct spdk_blob_opts *opts);

+11 −10
Original line number Diff line number Diff line
@@ -131,10 +131,10 @@ spdk_blob_opts_init(struct spdk_blob_opts *opts)
{
	opts->num_clusters = 0;
	opts->thin_provision = false;
	opts->xattr_count = 0;
	opts->xattr_names = NULL;
	opts->xattr_ctx = NULL;
	opts->get_xattr_value = NULL;
	opts->xattrs.count = 0;
	opts->xattrs.names = NULL;
	opts->xattrs.ctx = NULL;
	opts->xattrs.get_value = NULL;
}

static struct spdk_blob_data *
@@ -3144,21 +3144,21 @@ _spdk_bs_create_blob_cpl(spdk_bs_sequence_t *seq, void *cb_arg, int bserrno)
}

static int
_spdk_blob_set_xattrs(struct spdk_blob	*blob, const struct spdk_blob_opts *opts)
_spdk_blob_set_xattrs(struct spdk_blob	*blob, const struct spdk_blob_xattr_opts *xattrs)
{
	uint64_t i;
	size_t value_len = 0;
	int rc;
	const void *value = NULL;
	if (opts->xattr_count > 0 && opts->get_xattr_value == NULL) {
	if (xattrs->count > 0 && xattrs->get_value == NULL) {
		return -EINVAL;
	}
	for (i = 0; i < opts->xattr_count; i++) {
		opts->get_xattr_value(opts->xattr_ctx, opts->xattr_names[i], &value, &value_len);
	for (i = 0; i < xattrs->count; i++) {
		xattrs->get_value(xattrs->ctx, xattrs->names[i], &value, &value_len);
		if (value == NULL || value_len == 0) {
			return -EINVAL;
		}
		rc = spdk_blob_set_xattr(blob, opts->xattr_names[i], value, value_len);
		rc = spdk_blob_set_xattr(blob, xattrs->names[i], value, value_len);
		if (rc < 0) {
			return rc;
		}
@@ -3206,7 +3206,8 @@ void spdk_bs_create_blob_ext(struct spdk_blob_store *bs, const struct spdk_blob_
		spdk_blob_opts_init(&opts_default);
		opts = &opts_default;
	}
	rc = _spdk_blob_set_xattrs(__data_to_blob(blob), opts);

	rc = _spdk_blob_set_xattrs(__data_to_blob(blob), &opts->xattrs);
	if (rc < 0) {
		_spdk_blob_free(blob);
		cb_fn(cb_arg, 0, rc);
+4 −4
Original line number Diff line number Diff line
@@ -971,10 +971,10 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
	spdk_blob_opts_init(&opts);
	opts.thin_provision = thin_provision;
	opts.num_clusters = num_clusters;
	opts.xattr_count = 1;
	opts.xattr_names = &xattr_name;
	opts.xattr_ctx = lvol;
	opts.get_xattr_value = spdk_lvol_get_xattr_value;
	opts.xattrs.count = 1;
	opts.xattrs.names = &xattr_name;
	opts.xattrs.ctx = lvol;
	opts.xattrs.get_value = spdk_lvol_get_xattr_value;

	spdk_bs_create_blob_ext(lvs->blobstore, &opts, _spdk_lvol_create_cb, req);

+12 −12
Original line number Diff line number Diff line
@@ -2628,10 +2628,10 @@ blob_set_xattrs(void)
	/* Create blob with extra attributes */
	spdk_blob_opts_init(&opts);

	opts.xattr_names = g_xattr_names;
	opts.get_xattr_value = _get_xattr_value;
	opts.xattr_count = 3;
	opts.xattr_ctx = &g_ctx;
	opts.xattrs.names = g_xattr_names;
	opts.xattrs.get_value = _get_xattr_value;
	opts.xattrs.count = 3;
	opts.xattrs.ctx = &g_ctx;

	spdk_bs_create_blob_ext(bs, &opts, blob_op_with_id_complete, NULL);
	CU_ASSERT(g_bserrno == 0);
@@ -2677,10 +2677,10 @@ blob_set_xattrs(void)

	/* NULL callback */
	spdk_blob_opts_init(&opts);
	opts.xattr_names = g_xattr_names;
	opts.get_xattr_value = NULL;
	opts.xattr_count = 1;
	opts.xattr_ctx = &g_ctx;
	opts.xattrs.names = g_xattr_names;
	opts.xattrs.get_value = NULL;
	opts.xattrs.count = 1;
	opts.xattrs.ctx = &g_ctx;

	spdk_bs_create_blob_ext(bs, &opts, blob_op_with_id_complete, NULL);
	CU_ASSERT(g_bserrno == -EINVAL);
@@ -2688,10 +2688,10 @@ blob_set_xattrs(void)

	/* NULL values */
	spdk_blob_opts_init(&opts);
	opts.xattr_names = g_xattr_names;
	opts.get_xattr_value = _get_xattr_value_null;
	opts.xattr_count = 1;
	opts.xattr_ctx = NULL;
	opts.xattrs.names = g_xattr_names;
	opts.xattrs.get_value = _get_xattr_value_null;
	opts.xattrs.count = 1;
	opts.xattrs.ctx = NULL;

	spdk_bs_create_blob_ext(bs, &opts, blob_op_with_id_complete, NULL);
	CU_ASSERT(g_bserrno == -EINVAL);
+4 −4
Original line number Diff line number Diff line
@@ -365,10 +365,10 @@ spdk_blob_opts_init(struct spdk_blob_opts *opts)
{
	opts->num_clusters = 0;
	opts->thin_provision = false;
	opts->xattr_count = 0;
	opts->xattr_names = NULL;
	opts->xattr_ctx = NULL;
	opts->get_xattr_value = NULL;
	opts->xattrs.count = 0;
	opts->xattrs.names = NULL;
	opts->xattrs.ctx = NULL;
	opts->xattrs.get_value = NULL;
}

void