bdev/lvol: add UUID to lvols

In addition to the lvolstore uuid, add a per-lvol uuid for bdev
identification.

The lvol uuid is stored as an xattr for each lvol blob; if an lvol blob
without a uuid xattr is encountered, the lvol bdev will not report a
uuid for now (it will be set to all zeroes, which will be treated as
no uuid available by the generic bdev layer).

Change-Id: If00221383a12d62234fc085d56e257dd48053103
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/402973
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Tomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Daniel Verkamp 2018-03-06 16:54:38 -07:00 committed by Jim Harris
parent 364d4fdfe0
commit 8887697f8c
3 changed files with 21 additions and 4 deletions

View File

@ -98,6 +98,8 @@ struct spdk_lvol {
spdk_blob_id blob_id; spdk_blob_id blob_id;
char *unique_id; char *unique_id;
char name[SPDK_LVOL_NAME_MAX]; char name[SPDK_LVOL_NAME_MAX];
struct spdk_uuid uuid;
char uuid_str[SPDK_UUID_STRING_LEN];
bool close_only; bool close_only;
bool thin_provision; bool thin_provision;
struct spdk_bdev *bdev; struct spdk_bdev *bdev;

View File

@ -749,6 +749,7 @@ _create_lvol_disk(struct spdk_lvol *lvol)
total_size = lvol->num_clusters * spdk_bs_get_cluster_size(lvol->lvol_store->blobstore); total_size = lvol->num_clusters * spdk_bs_get_cluster_size(lvol->lvol_store->blobstore);
assert((total_size % bdev->blocklen) == 0); assert((total_size % bdev->blocklen) == 0);
bdev->blockcnt = total_size / bdev->blocklen; bdev->blockcnt = total_size / bdev->blocklen;
bdev->uuid = lvol->uuid;
bdev->ctxt = lvol; bdev->ctxt = lvol;
bdev->fn_table = &vbdev_lvol_fn_table; bdev->fn_table = &vbdev_lvol_fn_table;

View File

@ -36,6 +36,7 @@
#include "spdk/string.h" #include "spdk/string.h"
#include "spdk/io_channel.h" #include "spdk/io_channel.h"
#include "spdk/blob_bdev.h" #include "spdk/blob_bdev.h"
#include "spdk/util.h"
/* Default blob channel opts for lvol */ /* Default blob channel opts for lvol */
#define SPDK_LVOL_BLOB_OPTS_CHANNEL_OPS 512 #define SPDK_LVOL_BLOB_OPTS_CHANNEL_OPS 512
@ -213,11 +214,19 @@ _spdk_load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
strncpy(lvol->name, attr, SPDK_LVOL_NAME_MAX); strncpy(lvol->name, attr, SPDK_LVOL_NAME_MAX);
rc = spdk_blob_get_xattr_value(blob, "uuid", (const void **)&attr, &value_len);
if (rc != 0 || value_len != SPDK_UUID_STRING_LEN || attr[SPDK_UUID_STRING_LEN - 1] != '\0' ||
spdk_uuid_parse(&lvol->uuid, attr) != 0) {
SPDK_INFOLOG(SPDK_LOG_LVOL, "Missing or corrupt lvol uuid\n");
memset(&lvol->uuid, 0, sizeof(lvol->uuid));
}
spdk_uuid_fmt_lower(lvol->uuid_str, sizeof(lvol->uuid_str), &lvol->uuid);
TAILQ_INSERT_TAIL(&lvs->lvols, lvol, link); TAILQ_INSERT_TAIL(&lvs->lvols, lvol, link);
lvs->lvol_count++; lvs->lvol_count++;
SPDK_INFOLOG(SPDK_LOG_LVOL, "added lvol %s\n", lvol->unique_id); SPDK_INFOLOG(SPDK_LOG_LVOL, "added lvol %s (%s)\n", lvol->unique_id, lvol->uuid_str);
spdk_bs_iter_next(bs, blob, _spdk_load_next_lvol, req); spdk_bs_iter_next(bs, blob, _spdk_load_next_lvol, req);
@ -904,6 +913,9 @@ spdk_lvol_get_xattr_value(void *xattr_ctx, const char *name,
if (!strcmp(LVOL_NAME, name)) { if (!strcmp(LVOL_NAME, name)) {
*value = lvol->name; *value = lvol->name;
*value_len = SPDK_LVOL_NAME_MAX; *value_len = SPDK_LVOL_NAME_MAX;
} else if (!strcmp("uuid", name)) {
*value = lvol->uuid_str;
*value_len = sizeof(lvol->uuid_str);
} }
} }
@ -916,7 +928,7 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
struct spdk_lvol *lvol, *tmp; struct spdk_lvol *lvol, *tmp;
struct spdk_blob_opts opts; struct spdk_blob_opts opts;
uint64_t num_clusters; uint64_t num_clusters;
char *xattr_name = LVOL_NAME; char *xattr_names[] = {LVOL_NAME, "uuid"};
if (lvs == NULL) { if (lvs == NULL) {
SPDK_ERRLOG("lvol store does not exist\n"); SPDK_ERRLOG("lvol store does not exist\n");
@ -963,13 +975,15 @@ spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
lvol->close_only = false; lvol->close_only = false;
lvol->thin_provision = thin_provision; lvol->thin_provision = thin_provision;
strncpy(lvol->name, name, SPDK_LVS_NAME_MAX); strncpy(lvol->name, name, SPDK_LVS_NAME_MAX);
spdk_uuid_generate(&lvol->uuid);
spdk_uuid_fmt_lower(lvol->uuid_str, sizeof(lvol->uuid_str), &lvol->uuid);
req->lvol = lvol; req->lvol = lvol;
spdk_blob_opts_init(&opts); spdk_blob_opts_init(&opts);
opts.thin_provision = thin_provision; opts.thin_provision = thin_provision;
opts.num_clusters = num_clusters; opts.num_clusters = num_clusters;
opts.xattrs.count = 1; opts.xattrs.count = SPDK_COUNTOF(xattr_names);
opts.xattrs.names = &xattr_name; opts.xattrs.names = xattr_names;
opts.xattrs.ctx = lvol; opts.xattrs.ctx = lvol;
opts.xattrs.get_value = spdk_lvol_get_xattr_value; opts.xattrs.get_value = spdk_lvol_get_xattr_value;