2017-09-14 14:53:36 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk_internal/lvolstore.h"
|
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
#include "spdk/string.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2017-10-19 15:30:32 +00:00
|
|
|
#include "spdk/blob_bdev.h"
|
2018-03-06 23:54:38 +00:00
|
|
|
#include "spdk/util.h"
|
2017-09-14 14:53:36 +00:00
|
|
|
|
lvol, blob: make channel operations number configurable for blob.
We need to make the channel operations numbers configurable for blob.
Reason: for iSCSI tests, if there is one CPU core, there will be only
one channel, thus read stress tests would
fail since we need more operations for blob channel.
Select a value equal to the small buffer size(8192) for
bdev layer, thus we can solve the iSCSI read issue
correctly. Since for bdev read, we currently only
allow 8192 active bdev I/o requests, so this solution should
work.
PS: Current solution is still not perfect, I think the very
precise fix is that we need to restrict sending I/Os
to the blob, if there is no channel operations. Though
current code, we have retry I/O in bdev , but it still fails
the iSCSI high pressure test.
Change-Id: I211f7a89d144af2c96ad4cc1bd7ac8e94adc72e7
Signed-off-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/393115
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-12-28 03:07:45 +00:00
|
|
|
/* Default blob channel opts for lvol */
|
2018-01-11 11:52:44 +00:00
|
|
|
#define SPDK_LVOL_BLOB_OPTS_CHANNEL_OPS 512
|
lvol, blob: make channel operations number configurable for blob.
We need to make the channel operations numbers configurable for blob.
Reason: for iSCSI tests, if there is one CPU core, there will be only
one channel, thus read stress tests would
fail since we need more operations for blob channel.
Select a value equal to the small buffer size(8192) for
bdev layer, thus we can solve the iSCSI read issue
correctly. Since for bdev read, we currently only
allow 8192 active bdev I/o requests, so this solution should
work.
PS: Current solution is still not perfect, I think the very
precise fix is that we need to restrict sending I/Os
to the blob, if there is no channel operations. Though
current code, we have retry I/O in bdev , but it still fails
the iSCSI high pressure test.
Change-Id: I211f7a89d144af2c96ad4cc1bd7ac8e94adc72e7
Signed-off-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/393115
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2017-12-28 03:07:45 +00:00
|
|
|
|
2018-01-30 12:48:21 +00:00
|
|
|
#define LVOL_NAME "name"
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("lvol", SPDK_LOG_LVOL)
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-10-18 18:05:41 +00:00
|
|
|
static TAILQ_HEAD(, spdk_lvol_store) g_lvol_stores = TAILQ_HEAD_INITIALIZER(g_lvol_stores);
|
|
|
|
static pthread_mutex_t g_lvol_stores_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
static int
|
2020-05-15 01:06:20 +00:00
|
|
|
add_lvs_to_list(struct spdk_lvol_store *lvs)
|
2017-10-18 18:05:41 +00:00
|
|
|
{
|
2017-08-29 17:37:41 +00:00
|
|
|
struct spdk_lvol_store *tmp;
|
|
|
|
bool name_conflict = false;
|
|
|
|
|
2017-10-18 18:05:41 +00:00
|
|
|
pthread_mutex_lock(&g_lvol_stores_mutex);
|
2017-08-29 17:37:41 +00:00
|
|
|
TAILQ_FOREACH(tmp, &g_lvol_stores, link) {
|
|
|
|
if (!strncmp(lvs->name, tmp->name, SPDK_LVS_NAME_MAX)) {
|
|
|
|
name_conflict = true;
|
2018-09-12 01:02:06 +00:00
|
|
|
break;
|
2017-08-29 17:37:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!name_conflict) {
|
|
|
|
lvs->on_list = true;
|
|
|
|
TAILQ_INSERT_TAIL(&g_lvol_stores, lvs, link);
|
|
|
|
}
|
2017-10-18 18:05:41 +00:00
|
|
|
pthread_mutex_unlock(&g_lvol_stores_mutex);
|
|
|
|
|
2017-08-29 17:37:41 +00:00
|
|
|
return name_conflict ? -1 : 0;
|
2017-10-18 18:05:41 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 18:15:56 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(struct spdk_lvol_store *lvs)
|
2017-10-18 18:15:56 +00:00
|
|
|
{
|
2018-09-20 02:01:20 +00:00
|
|
|
pthread_mutex_lock(&g_lvol_stores_mutex);
|
2017-10-18 18:05:41 +00:00
|
|
|
if (lvs->on_list) {
|
|
|
|
TAILQ_REMOVE(&g_lvol_stores, lvs, link);
|
|
|
|
}
|
2018-09-20 02:01:20 +00:00
|
|
|
pthread_mutex_unlock(&g_lvol_stores_mutex);
|
|
|
|
|
2017-10-18 18:15:56 +00:00
|
|
|
free(lvs);
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_free(struct spdk_lvol *lvol)
|
2018-07-23 13:57:02 +00:00
|
|
|
{
|
|
|
|
free(lvol);
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
2017-12-21 09:50:52 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Failed to open lvol %s\n", lvol->unique_id);
|
2017-10-19 15:30:32 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2017-10-20 14:07:10 +00:00
|
|
|
lvol->ref_count++;
|
2017-10-19 15:30:32 +00:00
|
|
|
lvol->blob = blob;
|
|
|
|
end:
|
|
|
|
req->cb_fn(req->cb_arg, lvol, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_open(struct spdk_lvol *lvol, spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
2019-01-22 08:47:24 +00:00
|
|
|
struct spdk_blob_open_opts opts;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol does not exist\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-25 08:15:02 +00:00
|
|
|
if (lvol->action_in_progress == true) {
|
|
|
|
SPDK_ERRLOG("Cannot open lvol - operations on lvol pending\n");
|
|
|
|
cb_fn(cb_arg, lvol, -EBUSY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-20 14:07:10 +00:00
|
|
|
if (lvol->ref_count > 0) {
|
|
|
|
lvol->ref_count++;
|
|
|
|
cb_fn(cb_arg, lvol, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for request structure\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->lvol = lvol;
|
|
|
|
|
2019-01-22 08:47:24 +00:00
|
|
|
spdk_blob_open_opts_init(&opts);
|
|
|
|
opts.clear_method = lvol->clear_method;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_open_blob_ext(lvol->lvol_store->blobstore, lvol->blob_id, &opts, lvol_open_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 19:37:25 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
bs_unload_with_error_cb(void *cb_arg, int lvolerrno)
|
2017-11-06 19:37:25 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, NULL, req->lvserrno);
|
|
|
|
free(req);
|
|
|
|
}
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
load_next_lvol(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs = lvs->blobstore;
|
|
|
|
struct spdk_lvol *lvol, *tmp;
|
|
|
|
spdk_blob_id blob_id;
|
2017-11-02 12:57:58 +00:00
|
|
|
const char *attr;
|
|
|
|
size_t value_len;
|
|
|
|
int rc;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
if (lvolerrno == -ENOENT) {
|
|
|
|
/* Finished iterating */
|
|
|
|
req->cb_fn(req->cb_arg, lvs, 0);
|
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
} else if (lvolerrno < 0) {
|
|
|
|
SPDK_ERRLOG("Failed to fetch blobs list\n");
|
2017-11-06 19:37:25 +00:00
|
|
|
req->lvserrno = lvolerrno;
|
|
|
|
goto invalid;
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
blob_id = spdk_blob_get_id(blob);
|
|
|
|
|
|
|
|
if (blob_id == lvs->super_blob_id) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "found superblob %"PRIu64"\n", (uint64_t)blob_id);
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_iter_next(bs, blob, load_next_lvol, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvol = calloc(1, sizeof(*lvol));
|
|
|
|
if (!lvol) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol base pointer\n");
|
2017-11-06 19:37:25 +00:00
|
|
|
req->lvserrno = -ENOMEM;
|
|
|
|
goto invalid;
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lvol->blob = blob;
|
|
|
|
lvol->blob_id = blob_id;
|
|
|
|
lvol->lvol_store = lvs;
|
2020-05-15 02:17:57 +00:00
|
|
|
lvol->thin_provision = spdk_blob_is_thin_provisioned(blob);
|
2018-03-15 20:50:06 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-03-15 20:57:51 +00:00
|
|
|
if (!spdk_mem_all_zero(&lvol->uuid, sizeof(lvol->uuid))) {
|
2019-01-18 10:47:46 +00:00
|
|
|
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", lvol->uuid_str);
|
2018-03-15 20:57:51 +00:00
|
|
|
} else {
|
2019-01-18 10:47:46 +00:00
|
|
|
spdk_uuid_fmt_lower(lvol->unique_id, sizeof(lvol->unique_id), &lvol->lvol_store->uuid);
|
|
|
|
value_len = strlen(lvol->unique_id);
|
|
|
|
snprintf(lvol->unique_id + value_len, sizeof(lvol->unique_id) - value_len, "_%"PRIu64,
|
|
|
|
(uint64_t)blob_id);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2017-12-08 16:38:33 +00:00
|
|
|
rc = spdk_blob_get_xattr_value(blob, "name", (const void **)&attr, &value_len);
|
2017-11-02 12:57:58 +00:00
|
|
|
if (rc != 0 || value_len > SPDK_LVOL_NAME_MAX) {
|
|
|
|
SPDK_ERRLOG("Cannot assign lvol name\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_free(lvol);
|
2017-11-06 19:37:25 +00:00
|
|
|
req->lvserrno = -EINVAL;
|
|
|
|
goto invalid;
|
2017-11-02 12:57:58 +00:00
|
|
|
}
|
|
|
|
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(lvol->name, sizeof(lvol->name), "%s", attr);
|
2017-11-02 12:57:58 +00:00
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lvs->lvols, lvol, link);
|
|
|
|
|
|
|
|
lvs->lvol_count++;
|
|
|
|
|
2018-03-06 23:54:38 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "added lvol %s (%s)\n", lvol->unique_id, lvol->uuid_str);
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_iter_next(bs, blob, load_next_lvol, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2017-11-06 19:37:25 +00:00
|
|
|
return;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2017-11-06 19:37:25 +00:00
|
|
|
invalid:
|
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
|
|
|
free(lvol);
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
close_super_cb(void *cb_arg, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs = lvs->blobstore;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Could not close super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -ENODEV;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start loading lvols */
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_iter_first(lvs->blobstore, load_next_lvol, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
close_super_blob_with_error_cb(void *cb_arg, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs = lvs->blobstore;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_read_uuid(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs = lvs->blobstore;
|
|
|
|
const char *attr;
|
|
|
|
size_t value_len;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Could not open super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -ENODEV;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 16:38:33 +00:00
|
|
|
rc = spdk_blob_get_xattr_value(blob, "uuid", (const void **)&attr, &value_len);
|
2018-03-02 00:59:50 +00:00
|
|
|
if (rc != 0 || value_len != SPDK_UUID_STRING_LEN || attr[SPDK_UUID_STRING_LEN - 1] != '\0') {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "missing or incorrect UUID\n");
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -EINVAL;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, close_super_blob_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
if (spdk_uuid_parse(&lvs->uuid, attr)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "incorrect UUID '%s'\n", attr);
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -EINVAL;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, close_super_blob_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-08 16:38:33 +00:00
|
|
|
rc = spdk_blob_get_xattr_value(blob, "name", (const void **)&attr, &value_len);
|
2017-08-29 17:37:41 +00:00
|
|
|
if (rc != 0 || value_len > SPDK_LVS_NAME_MAX) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "missing or invalid name\n");
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -EINVAL;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, close_super_blob_with_error_cb, req);
|
2017-08-29 17:37:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(lvs->name, sizeof(lvs->name), "%s", attr);
|
2017-08-29 17:37:41 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
rc = add_lvs_to_list(lvs);
|
2017-08-29 17:37:41 +00:00
|
|
|
if (rc) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "lvolstore with name %s already exists\n", lvs->name);
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -EEXIST;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, close_super_blob_with_error_cb, req);
|
2017-08-29 17:37:41 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-18 18:05:41 +00:00
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
lvs->super_blob_id = spdk_blob_get_id(blob);
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, close_super_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_open_super(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs = lvs->blobstore;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Super blob not found\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-27 13:47:34 +00:00
|
|
|
req->lvserrno = -ENODEV;
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_open_blob(bs, blobid, lvs_read_uuid, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_load_cb(void *cb_arg, struct spdk_blob_store *bs, int lvolerrno)
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs = calloc(1, sizeof(*lvs));
|
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol store\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_unload(bs, bs_unload_with_error_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs->blobstore = bs;
|
|
|
|
lvs->bs_dev = req->bs_dev;
|
|
|
|
TAILQ_INIT(&lvs->lvols);
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_INIT(&lvs->pending_lvols);
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
req->lvol_store = lvs;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_get_super(bs, lvs_open_super, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2018-01-05 03:16:37 +00:00
|
|
|
static void
|
2020-05-10 23:18:51 +00:00
|
|
|
lvs_bs_opts_init(struct spdk_bs_opts *opts)
|
2018-01-05 03:16:37 +00:00
|
|
|
{
|
|
|
|
spdk_bs_opts_init(opts);
|
|
|
|
opts->max_channel_ops = SPDK_LVOL_BLOB_OPTS_CHANNEL_OPS;
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
void
|
|
|
|
spdk_lvs_load(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req;
|
|
|
|
struct spdk_bs_opts opts = {};
|
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
|
|
|
if (bs_dev == NULL) {
|
|
|
|
SPDK_ERRLOG("Blobstore device does not exist\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for request structure\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->bs_dev = bs_dev;
|
|
|
|
|
2020-05-10 23:18:51 +00:00
|
|
|
lvs_bs_opts_init(&opts);
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(opts.bstype.bstype, sizeof(opts.bstype.bstype), "LVOLSTORE");
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_load(bs_dev, &opts, lvs_load_cb, req);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
2019-09-04 09:11:24 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
remove_bs_on_error_cb(void *cb_arg, int bserrno)
|
2019-09-04 09:11:24 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
super_create_close_cb(void *cb_arg, int lvolerrno)
|
2017-09-22 12:13:56 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not close super blob\n");
|
2017-10-13 21:27:22 +00:00
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, remove_bs_on_error_cb, NULL);
|
|
|
|
lvs_free(lvs);
|
2017-10-13 21:27:22 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
2017-09-22 12:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvs, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
super_blob_set_cb(void *cb_arg, int lvolerrno)
|
2017-09-22 12:13:56 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob *blob = lvs->super_blob;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not set uuid for super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, remove_bs_on_error_cb, NULL);
|
|
|
|
lvs_free(lvs);
|
2017-09-22 12:13:56 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, super_create_close_cb, req);
|
2017-09-22 12:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
super_blob_init_cb(void *cb_arg, int lvolerrno)
|
2017-09-22 12:13:56 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob *blob = lvs->super_blob;
|
2018-03-02 00:59:50 +00:00
|
|
|
char uuid[SPDK_UUID_STRING_LEN];
|
2017-09-22 12:13:56 +00:00
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not set super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, remove_bs_on_error_cb, NULL);
|
|
|
|
lvs_free(lvs);
|
2017-09-22 12:13:56 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
spdk_uuid_fmt_lower(uuid, sizeof(uuid), &lvs->uuid);
|
2017-09-22 12:13:56 +00:00
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
spdk_blob_set_xattr(blob, "uuid", uuid, sizeof(uuid));
|
2017-12-08 16:38:33 +00:00
|
|
|
spdk_blob_set_xattr(blob, "name", lvs->name, strnlen(lvs->name, SPDK_LVS_NAME_MAX) + 1);
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_sync_md(blob, super_blob_set_cb, req);
|
2017-09-22 12:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
super_blob_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2017-09-22 12:13:56 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not open super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, remove_bs_on_error_cb, NULL);
|
|
|
|
lvs_free(lvs);
|
2017-09-22 12:13:56 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs->super_blob = blob;
|
|
|
|
lvs->super_blob_id = spdk_blob_get_id(blob);
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_set_super(lvs->blobstore, lvs->super_blob_id, super_blob_init_cb, req);
|
2017-09-22 12:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
super_blob_create_cb(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
|
2017-09-22 12:13:56 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
|
|
|
struct spdk_blob_store *bs;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not create super blob\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, remove_bs_on_error_cb, NULL);
|
|
|
|
lvs_free(lvs);
|
2017-09-22 12:13:56 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bs = req->lvol_store->blobstore;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_open_blob(bs, blobid, super_blob_create_open_cb, req);
|
2017-09-22 12:13:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_init_cb(void *cb_arg, struct spdk_blob_store *bs, int lvserrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_with_handle_req *lvs_req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = lvs_req->lvol_store;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
assert(bs == NULL);
|
2017-09-22 12:13:56 +00:00
|
|
|
lvs_req->cb_fn(lvs_req->cb_arg, NULL, lvserrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
SPDK_ERRLOG("Lvol store init failed: could not initialize blobstore\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-09-22 12:13:56 +00:00
|
|
|
free(lvs_req);
|
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
2017-09-22 12:13:56 +00:00
|
|
|
|
|
|
|
assert(bs != NULL);
|
|
|
|
lvs->blobstore = bs;
|
|
|
|
TAILQ_INIT(&lvs->lvols);
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_INIT(&lvs->pending_lvols);
|
2017-09-22 12:13:56 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol store initialized\n");
|
2017-09-22 12:13:56 +00:00
|
|
|
|
|
|
|
/* create super blob */
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_create_blob(lvs->blobstore, super_blob_create_cb, lvs_req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 19:40:28 +00:00
|
|
|
void
|
|
|
|
spdk_lvs_opts_init(struct spdk_lvs_opts *o)
|
|
|
|
{
|
|
|
|
o->cluster_sz = SPDK_LVS_OPTS_CLUSTER_SZ;
|
2019-02-28 09:57:19 +00:00
|
|
|
o->clear_method = LVS_CLEAR_WITH_UNMAP;
|
2017-08-29 17:37:41 +00:00
|
|
|
memset(o->name, 0, sizeof(o->name));
|
2017-10-18 19:40:28 +00:00
|
|
|
}
|
|
|
|
|
2017-09-29 07:46:50 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
setup_lvs_opts(struct spdk_bs_opts *bs_opts, struct spdk_lvs_opts *o)
|
2017-09-29 07:46:50 +00:00
|
|
|
{
|
2017-10-18 19:40:28 +00:00
|
|
|
assert(o != NULL);
|
2020-05-10 23:18:51 +00:00
|
|
|
lvs_bs_opts_init(bs_opts);
|
2017-10-18 19:40:28 +00:00
|
|
|
bs_opts->cluster_sz = o->cluster_sz;
|
2019-02-28 09:57:19 +00:00
|
|
|
bs_opts->clear_method = (enum bs_clear_method)o->clear_method;
|
2017-09-29 07:46:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
int
|
2017-09-29 07:46:50 +00:00
|
|
|
spdk_lvs_init(struct spdk_bs_dev *bs_dev, struct spdk_lvs_opts *o,
|
|
|
|
spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs;
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_with_handle_req *lvs_req;
|
2017-10-19 15:30:32 +00:00
|
|
|
struct spdk_bs_opts opts = {};
|
2017-08-29 17:37:41 +00:00
|
|
|
int rc;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (bs_dev == NULL) {
|
|
|
|
SPDK_ERRLOG("Blobstore device does not exist\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2017-10-18 19:40:28 +00:00
|
|
|
if (o == NULL) {
|
|
|
|
SPDK_ERRLOG("spdk_lvs_opts not specified\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
setup_lvs_opts(&opts, o);
|
2017-09-29 07:46:50 +00:00
|
|
|
|
2017-08-29 17:37:41 +00:00
|
|
|
if (strnlen(o->name, SPDK_LVS_NAME_MAX) == SPDK_LVS_NAME_MAX) {
|
|
|
|
SPDK_ERRLOG("Name has no null terminator.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strnlen(o->name, SPDK_LVS_NAME_MAX) == 0) {
|
|
|
|
SPDK_ERRLOG("No name specified.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs = calloc(1, sizeof(*lvs));
|
|
|
|
if (!lvs) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol store base pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
spdk_uuid_generate(&lvs->uuid);
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(lvs->name, sizeof(lvs->name), "%s", o->name);
|
2017-08-29 17:37:41 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
rc = add_lvs_to_list(lvs);
|
2017-08-29 17:37:41 +00:00
|
|
|
if (rc) {
|
|
|
|
SPDK_ERRLOG("lvolstore with name %s already exists\n", lvs->name);
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-27 13:47:34 +00:00
|
|
|
return -EEXIST;
|
2017-08-29 17:37:41 +00:00
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
lvs_req = calloc(1, sizeof(*lvs_req));
|
|
|
|
if (!lvs_req) {
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-09-14 14:53:36 +00:00
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol store request pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-09-22 12:13:56 +00:00
|
|
|
assert(cb_fn != NULL);
|
2017-09-19 14:09:43 +00:00
|
|
|
lvs_req->cb_fn = cb_fn;
|
|
|
|
lvs_req->cb_arg = cb_arg;
|
|
|
|
lvs_req->lvol_store = lvs;
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs->bs_dev = bs_dev;
|
2017-10-21 01:23:54 +00:00
|
|
|
lvs->destruct = false;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(opts.bstype.bstype, sizeof(opts.bstype.bstype), "LVOLSTORE");
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Initializing lvol store\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_init(bs_dev, &opts, lvs_init_cb, lvs_req);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:03:39 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_rename_cb(void *cb_arg, int lvolerrno)
|
2018-01-10 10:03:39 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
req->lvserrno = lvolerrno;
|
|
|
|
}
|
|
|
|
if (req->lvserrno != 0) {
|
|
|
|
SPDK_ERRLOG("Lvol store rename operation failed\n");
|
|
|
|
/* Lvs renaming failed, so we should 'clear' new_name.
|
|
|
|
* Otherwise it could cause a failure on the next attepmt to change the name to 'new_name' */
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(req->lvol_store->new_name,
|
|
|
|
sizeof(req->lvol_store->new_name),
|
|
|
|
"%s", req->lvol_store->name);
|
2018-01-10 10:03:39 +00:00
|
|
|
} else {
|
|
|
|
/* Update lvs name with new_name */
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(req->lvol_store->name,
|
|
|
|
sizeof(req->lvol_store->name),
|
|
|
|
"%s", req->lvol_store->new_name);
|
2018-01-10 10:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, req->lvserrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_rename_sync_cb(void *cb_arg, int lvolerrno)
|
2018-01-10 10:03:39 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
struct spdk_blob *blob = req->lvol_store->super_blob;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
req->lvserrno = lvolerrno;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(blob, lvs_rename_cb, req);
|
2018-01-10 10:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_rename_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2018-01-10 10:03:39 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_rename_cb(cb_arg, lvolerrno);
|
2018-01-10 10:03:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_blob_set_xattr(blob, "name", req->lvol_store->new_name,
|
|
|
|
strlen(req->lvol_store->new_name) + 1);
|
|
|
|
if (rc < 0) {
|
|
|
|
req->lvserrno = rc;
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_rename_sync_cb(req, rc);
|
2018-01-10 10:03:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->lvol_store->super_blob = blob;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_sync_md(blob, lvs_rename_sync_cb, req);
|
2018-01-10 10:03:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvs_rename(struct spdk_lvol_store *lvs, const char *new_name,
|
|
|
|
spdk_lvs_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req;
|
|
|
|
struct spdk_lvol_store *tmp;
|
|
|
|
|
|
|
|
/* Check if new name is current lvs name.
|
|
|
|
* If so, return success immediately */
|
|
|
|
if (strncmp(lvs->name, new_name, SPDK_LVS_NAME_MAX) == 0) {
|
|
|
|
cb_fn(cb_arg, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if new or new_name is already used in other lvs */
|
2018-09-20 02:01:20 +00:00
|
|
|
pthread_mutex_lock(&g_lvol_stores_mutex);
|
2018-01-10 10:03:39 +00:00
|
|
|
TAILQ_FOREACH(tmp, &g_lvol_stores, link) {
|
|
|
|
if (!strncmp(new_name, tmp->name, SPDK_LVS_NAME_MAX) ||
|
|
|
|
!strncmp(new_name, tmp->new_name, SPDK_LVS_NAME_MAX)) {
|
2018-09-20 02:01:20 +00:00
|
|
|
pthread_mutex_unlock(&g_lvol_stores_mutex);
|
2018-01-10 10:03:39 +00:00
|
|
|
cb_fn(cb_arg, -EEXIST);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 02:01:20 +00:00
|
|
|
pthread_mutex_unlock(&g_lvol_stores_mutex);
|
2018-01-10 10:03:39 +00:00
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(lvs->new_name, sizeof(lvs->new_name), "%s", new_name);
|
2018-01-10 10:03:39 +00:00
|
|
|
req->lvol_store = lvs;
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_open_blob(lvs->blobstore, lvs->super_blob_id, lvs_rename_open_cb, req);
|
2018-01-10 10:03:39 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
_lvs_unload_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_req *lvs_req = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol store unloaded\n");
|
2017-09-19 14:09:43 +00:00
|
|
|
assert(lvs_req->cb_fn != NULL);
|
|
|
|
lvs_req->cb_fn(lvs_req->cb_arg, lvserrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(lvs_req);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
|
|
|
|
void *cb_arg)
|
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_req *lvs_req;
|
2017-10-20 08:34:22 +00:00
|
|
|
struct spdk_lvol *lvol, *tmp;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("Lvol store is NULL\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2017-10-20 08:34:22 +00:00
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
2017-10-25 08:15:02 +00:00
|
|
|
if (lvol->action_in_progress == true) {
|
|
|
|
SPDK_ERRLOG("Cannot unload lvol store - operations on lvols pending\n");
|
|
|
|
cb_fn(cb_arg, -EBUSY);
|
|
|
|
return -EBUSY;
|
|
|
|
} else if (lvol->ref_count != 0) {
|
2017-10-20 08:34:22 +00:00
|
|
|
SPDK_ERRLOG("Lvols still open on lvol store\n");
|
2017-10-25 08:15:02 +00:00
|
|
|
cb_fn(cb_arg, -EBUSY);
|
2017-10-20 08:34:22 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
|
|
|
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_free(lvol);
|
2017-10-12 07:47:41 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs_req = calloc(1, sizeof(*lvs_req));
|
|
|
|
if (!lvs_req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol store request pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2017-09-19 14:09:43 +00:00
|
|
|
lvs_req->cb_fn = cb_fn;
|
|
|
|
lvs_req->cb_arg = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Unloading lvol store\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
spdk_bs_unload(lvs->blobstore, _lvs_unload_cb, lvs_req);
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-10-20 13:44:30 +00:00
|
|
|
static void
|
|
|
|
_lvs_destroy_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
2017-10-20 22:22:11 +00:00
|
|
|
struct spdk_lvs_destroy_req *lvs_req = cb_arg;
|
2017-10-20 13:44:30 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol store destroyed\n");
|
2017-10-20 13:44:30 +00:00
|
|
|
assert(lvs_req->cb_fn != NULL);
|
|
|
|
lvs_req->cb_fn(lvs_req->cb_arg, lvserrno);
|
|
|
|
free(lvs_req);
|
|
|
|
}
|
|
|
|
|
2017-10-20 22:22:11 +00:00
|
|
|
static void
|
|
|
|
_lvs_destroy_super_cb(void *cb_arg, int bserrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_destroy_req *lvs_req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = lvs_req->lvs;
|
|
|
|
|
|
|
|
assert(lvs != NULL);
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Destroying lvol store\n");
|
2017-12-04 18:05:49 +00:00
|
|
|
spdk_bs_destroy(lvs->blobstore, _lvs_destroy_cb, lvs_req);
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_free(lvs);
|
2017-10-20 22:22:11 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 13:44:30 +00:00
|
|
|
int
|
2017-12-04 18:05:49 +00:00
|
|
|
spdk_lvs_destroy(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn,
|
2017-10-20 13:44:30 +00:00
|
|
|
void *cb_arg)
|
|
|
|
{
|
2017-10-20 22:22:11 +00:00
|
|
|
struct spdk_lvs_destroy_req *lvs_req;
|
2017-10-20 13:44:30 +00:00
|
|
|
struct spdk_lvol *iter_lvol, *tmp;
|
|
|
|
|
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("Lvol store is NULL\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(iter_lvol, &lvs->lvols, link, tmp) {
|
2017-10-25 08:15:02 +00:00
|
|
|
if (iter_lvol->action_in_progress == true) {
|
|
|
|
SPDK_ERRLOG("Cannot destroy lvol store - operations on lvols pending\n");
|
|
|
|
cb_fn(cb_arg, -EBUSY);
|
|
|
|
return -EBUSY;
|
|
|
|
} else if (iter_lvol->ref_count != 0) {
|
2017-10-20 13:44:30 +00:00
|
|
|
SPDK_ERRLOG("Lvols still open on lvol store\n");
|
2017-10-25 08:15:02 +00:00
|
|
|
cb_fn(cb_arg, -EBUSY);
|
2017-10-20 13:44:30 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH_SAFE(iter_lvol, &lvs->lvols, link, tmp) {
|
|
|
|
free(iter_lvol);
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs_req = calloc(1, sizeof(*lvs_req));
|
|
|
|
if (!lvs_req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol store request pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs_req->cb_fn = cb_fn;
|
|
|
|
lvs_req->cb_arg = cb_arg;
|
2017-10-20 22:22:11 +00:00
|
|
|
lvs_req->lvs = lvs;
|
2017-10-20 13:44:30 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Deleting super blob\n");
|
2017-12-08 21:09:12 +00:00
|
|
|
spdk_bs_delete_blob(lvs->blobstore, lvs->super_blob_id, _lvs_destroy_super_cb, lvs_req);
|
2017-10-20 13:44:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_close_blob_cb(void *cb_arg, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-10-20 09:43:07 +00:00
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
SPDK_ERRLOG("Could not close blob on lvol\n");
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_free(lvol);
|
2017-10-20 09:43:07 +00:00
|
|
|
goto end;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 08:34:22 +00:00
|
|
|
lvol->ref_count--;
|
2017-10-25 08:15:02 +00:00
|
|
|
lvol->action_in_progress = false;
|
2017-12-21 09:50:52 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol %s closed\n", lvol->unique_id);
|
2017-10-20 09:43:07 +00:00
|
|
|
|
|
|
|
end:
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
bool
|
|
|
|
spdk_lvol_deletable(struct spdk_lvol *lvol)
|
|
|
|
{
|
|
|
|
size_t count;
|
|
|
|
|
|
|
|
spdk_blob_get_clones(lvol->lvol_store->blobstore, lvol->blob_id, NULL, &count);
|
|
|
|
return (count == 0);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_delete_blob_cb(void *cb_arg, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2018-01-29 13:28:23 +00:00
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
2017-10-20 09:43:07 +00:00
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
2019-03-01 13:48:13 +00:00
|
|
|
SPDK_ERRLOG("Could not remove blob on lvol gracefully - forced removal\n");
|
|
|
|
} else {
|
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol %s deleted\n", lvol->unique_id);
|
2017-10-20 09:43:07 +00:00
|
|
|
}
|
|
|
|
|
2017-10-21 01:23:54 +00:00
|
|
|
TAILQ_REMOVE(&lvol->lvol_store->lvols, lvol, link);
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_free(lvol);
|
2018-01-29 13:28:23 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
2017-10-20 09:43:07 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_create_open_cb(void *cb_arg, struct spdk_blob *blob, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_with_handle_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_REMOVE(&req->lvol->lvol_store->pending_lvols, req->lvol, link);
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
if (lvolerrno < 0) {
|
|
|
|
free(lvol);
|
2018-01-29 13:28:23 +00:00
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lvol->blob = blob;
|
2020-03-31 13:19:14 +00:00
|
|
|
lvol->blob_id = spdk_blob_get_id(blob);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-01-29 13:28:23 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lvol->lvol_store->lvols, lvol, link);
|
|
|
|
|
2019-01-18 10:47:46 +00:00
|
|
|
snprintf(lvol->unique_id, sizeof(lvol->unique_id), "%s", lvol->uuid_str);
|
2018-01-30 12:48:21 +00:00
|
|
|
lvol->ref_count++;
|
2017-10-24 02:51:49 +00:00
|
|
|
|
2018-01-30 12:48:21 +00:00
|
|
|
assert(req->cb_fn != NULL);
|
|
|
|
req->cb_fn(req->cb_arg, req->lvol, lvolerrno);
|
|
|
|
free(req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_create_cb(void *cb_arg, spdk_blob_id blobid, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_with_handle_req *req = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
struct spdk_blob_store *bs;
|
2019-01-22 08:47:24 +00:00
|
|
|
struct spdk_blob_open_opts opts;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_REMOVE(&req->lvol->lvol_store->pending_lvols, req->lvol, link);
|
2017-09-19 14:09:43 +00:00
|
|
|
free(req->lvol);
|
|
|
|
assert(req->cb_fn != NULL);
|
|
|
|
req->cb_fn(req->cb_arg, NULL, lvolerrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-01-22 08:47:24 +00:00
|
|
|
spdk_blob_open_opts_init(&opts);
|
|
|
|
opts.clear_method = req->lvol->clear_method;
|
2017-09-19 14:09:43 +00:00
|
|
|
bs = req->lvol->lvol_store->blobstore;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_open_blob_ext(bs, blobid, &opts, lvol_create_open_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 12:48:21 +00:00
|
|
|
static void
|
2020-05-10 23:18:51 +00:00
|
|
|
lvol_get_xattr_value(void *xattr_ctx, const char *name,
|
|
|
|
const void **value, size_t *value_len)
|
2018-01-30 12:48:21 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = xattr_ctx;
|
|
|
|
|
|
|
|
if (!strcmp(LVOL_NAME, name)) {
|
|
|
|
*value = lvol->name;
|
|
|
|
*value_len = SPDK_LVOL_NAME_MAX;
|
2018-03-06 23:54:38 +00:00
|
|
|
} else if (!strcmp("uuid", name)) {
|
|
|
|
*value = lvol->uuid_str;
|
|
|
|
*value_len = sizeof(lvol->uuid_str);
|
2018-01-30 12:48:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:20:32 +00:00
|
|
|
static int
|
2020-05-15 01:06:20 +00:00
|
|
|
lvs_verify_lvol_name(struct spdk_lvol_store *lvs, const char *name)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2018-04-06 10:20:32 +00:00
|
|
|
struct spdk_lvol *tmp;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-04-06 10:20:32 +00:00
|
|
|
if (name == NULL || strnlen(name, SPDK_LVOL_NAME_MAX) == 0) {
|
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "lvol name not provided.\n");
|
2017-10-24 02:51:49 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strnlen(name, SPDK_LVOL_NAME_MAX) == SPDK_LVOL_NAME_MAX) {
|
|
|
|
SPDK_ERRLOG("Name has no null terminator.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_FOREACH(tmp, &lvs->lvols, link) {
|
|
|
|
if (!strncmp(name, tmp->name, SPDK_LVOL_NAME_MAX)) {
|
|
|
|
SPDK_ERRLOG("lvol with name %s already exists\n", name);
|
2018-04-06 10:20:32 +00:00
|
|
|
return -EEXIST;
|
2017-10-24 02:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_FOREACH(tmp, &lvs->pending_lvols, link) {
|
|
|
|
if (!strncmp(name, tmp->name, SPDK_LVOL_NAME_MAX)) {
|
|
|
|
SPDK_ERRLOG("lvol with name %s is being already created\n", name);
|
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-06 10:20:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
spdk_lvol_create(struct spdk_lvol_store *lvs, const char *name, uint64_t sz,
|
2019-01-22 08:47:24 +00:00
|
|
|
bool thin_provision, enum lvol_clear_method clear_method, spdk_lvol_op_with_handle_complete cb_fn,
|
|
|
|
void *cb_arg)
|
2018-04-06 10:20:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
struct spdk_blob_store *bs;
|
|
|
|
struct spdk_lvol *lvol;
|
|
|
|
struct spdk_blob_opts opts;
|
|
|
|
uint64_t num_clusters;
|
2019-10-04 01:03:11 +00:00
|
|
|
char *xattr_names[] = {LVOL_NAME, "uuid"};
|
2018-04-06 10:20:32 +00:00
|
|
|
int rc;
|
|
|
|
|
2018-09-04 16:44:51 +00:00
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol store does not exist\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
rc = lvs_verify_lvol_name(lvs, name);
|
2018-04-06 10:20:32 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-09-27 11:18:50 +00:00
|
|
|
bs = lvs->blobstore;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
lvol = calloc(1, sizeof(*lvol));
|
|
|
|
if (!lvol) {
|
|
|
|
free(req);
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol base pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
lvol->lvol_store = lvs;
|
2018-12-18 09:46:35 +00:00
|
|
|
num_clusters = spdk_divide_round_up(sz, spdk_bs_get_cluster_size(bs));
|
2018-01-31 16:55:54 +00:00
|
|
|
lvol->thin_provision = thin_provision;
|
2019-01-22 08:47:24 +00:00
|
|
|
lvol->clear_method = (enum blob_clear_method)clear_method;
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(lvol->name, sizeof(lvol->name), "%s", name);
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_INSERT_TAIL(&lvol->lvol_store->pending_lvols, lvol, link);
|
2018-03-06 23:54:38 +00:00
|
|
|
spdk_uuid_generate(&lvol->uuid);
|
|
|
|
spdk_uuid_fmt_lower(lvol->uuid_str, sizeof(lvol->uuid_str), &lvol->uuid);
|
2017-09-19 14:09:43 +00:00
|
|
|
req->lvol = lvol;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-01-26 13:33:27 +00:00
|
|
|
spdk_blob_opts_init(&opts);
|
|
|
|
opts.thin_provision = thin_provision;
|
2018-01-30 12:48:21 +00:00
|
|
|
opts.num_clusters = num_clusters;
|
2019-10-23 17:34:49 +00:00
|
|
|
opts.clear_method = lvol->clear_method;
|
2018-03-06 23:54:38 +00:00
|
|
|
opts.xattrs.count = SPDK_COUNTOF(xattr_names);
|
|
|
|
opts.xattrs.names = xattr_names;
|
2018-01-29 09:25:43 +00:00
|
|
|
opts.xattrs.ctx = lvol;
|
2020-05-10 23:18:51 +00:00
|
|
|
opts.xattrs.get_value = lvol_get_xattr_value;
|
2018-01-26 13:33:27 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_create_blob_ext(lvs->blobstore, &opts, lvol_create_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-22 12:29:49 +00:00
|
|
|
void
|
|
|
|
spdk_lvol_create_snapshot(struct spdk_lvol *origlvol, const char *snapshot_name,
|
|
|
|
spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs;
|
|
|
|
struct spdk_lvol *newlvol;
|
|
|
|
struct spdk_blob *origblob;
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
struct spdk_blob_xattr_opts snapshot_xattrs;
|
2018-04-11 12:27:03 +00:00
|
|
|
char *xattr_names[] = {LVOL_NAME, "uuid"};
|
2018-02-22 12:29:49 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (origlvol == NULL) {
|
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol not provided.\n");
|
|
|
|
cb_fn(cb_arg, NULL, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
origblob = origlvol->blob;
|
|
|
|
lvs = origlvol->lvol_store;
|
2018-09-04 16:44:51 +00:00
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol store does not exist\n");
|
|
|
|
cb_fn(cb_arg, NULL, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
rc = lvs_verify_lvol_name(lvs, snapshot_name);
|
2018-02-22 12:29:49 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
cb_fn(cb_arg, NULL, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newlvol = calloc(1, sizeof(*newlvol));
|
|
|
|
if (!newlvol) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol base pointer\n");
|
|
|
|
free(req);
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newlvol->lvol_store = origlvol->lvol_store;
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(newlvol->name, sizeof(newlvol->name), "%s", snapshot_name);
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_INSERT_TAIL(&newlvol->lvol_store->pending_lvols, newlvol, link);
|
2018-04-11 12:27:03 +00:00
|
|
|
spdk_uuid_generate(&newlvol->uuid);
|
|
|
|
spdk_uuid_fmt_lower(newlvol->uuid_str, sizeof(newlvol->uuid_str), &newlvol->uuid);
|
|
|
|
snapshot_xattrs.count = SPDK_COUNTOF(xattr_names);
|
2018-02-22 12:29:49 +00:00
|
|
|
snapshot_xattrs.ctx = newlvol;
|
2018-04-11 12:27:03 +00:00
|
|
|
snapshot_xattrs.names = xattr_names;
|
2020-05-10 23:18:51 +00:00
|
|
|
snapshot_xattrs.get_value = lvol_get_xattr_value;
|
2018-02-22 12:29:49 +00:00
|
|
|
req->lvol = newlvol;
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_bs_create_snapshot(lvs->blobstore, spdk_blob_get_id(origblob), &snapshot_xattrs,
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_create_cb, req);
|
2018-02-22 12:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_create_clone(struct spdk_lvol *origlvol, const char *clone_name,
|
|
|
|
spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *newlvol;
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
struct spdk_lvol_store *lvs;
|
|
|
|
struct spdk_blob *origblob;
|
|
|
|
struct spdk_blob_xattr_opts clone_xattrs;
|
2018-04-11 12:27:03 +00:00
|
|
|
char *xattr_names[] = {LVOL_NAME, "uuid"};
|
2018-02-22 12:29:49 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (origlvol == NULL) {
|
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL, "Lvol not provided.\n");
|
|
|
|
cb_fn(cb_arg, NULL, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
origblob = origlvol->blob;
|
|
|
|
lvs = origlvol->lvol_store;
|
2018-09-04 16:44:51 +00:00
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol store does not exist\n");
|
|
|
|
cb_fn(cb_arg, NULL, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
rc = lvs_verify_lvol_name(lvs, clone_name);
|
2018-02-22 12:29:49 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
cb_fn(cb_arg, NULL, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newlvol = calloc(1, sizeof(*newlvol));
|
|
|
|
if (!newlvol) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol base pointer\n");
|
|
|
|
free(req);
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
newlvol->lvol_store = lvs;
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(newlvol->name, sizeof(newlvol->name), "%s", clone_name);
|
2018-04-12 08:10:49 +00:00
|
|
|
TAILQ_INSERT_TAIL(&newlvol->lvol_store->pending_lvols, newlvol, link);
|
2018-04-11 12:27:03 +00:00
|
|
|
spdk_uuid_generate(&newlvol->uuid);
|
|
|
|
spdk_uuid_fmt_lower(newlvol->uuid_str, sizeof(newlvol->uuid_str), &newlvol->uuid);
|
|
|
|
clone_xattrs.count = SPDK_COUNTOF(xattr_names);
|
2018-02-22 12:29:49 +00:00
|
|
|
clone_xattrs.ctx = newlvol;
|
2018-04-11 12:27:03 +00:00
|
|
|
clone_xattrs.names = xattr_names;
|
2020-05-10 23:18:51 +00:00
|
|
|
clone_xattrs.get_value = lvol_get_xattr_value;
|
2018-02-22 12:29:49 +00:00
|
|
|
req->lvol = newlvol;
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_bs_create_clone(lvs->blobstore, spdk_blob_get_id(origblob), &clone_xattrs,
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_create_cb,
|
2018-02-22 12:29:49 +00:00
|
|
|
req);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_resize_done(void *cb_arg, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
2018-03-19 21:05:44 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_blob_resize_cb(void *cb_arg, int bserrno)
|
2018-03-19 21:05:44 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
|
|
|
|
|
|
|
if (bserrno != 0) {
|
|
|
|
req->cb_fn(req->cb_arg, bserrno);
|
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_sync_md(lvol->blob, lvol_resize_done, req);
|
2018-03-19 21:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-09-14 14:53:36 +00:00
|
|
|
spdk_lvol_resize(struct spdk_lvol *lvol, uint64_t sz,
|
|
|
|
spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
|
|
|
struct spdk_lvol_store *lvs = lvol->lvol_store;
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_req *req;
|
2018-12-18 09:46:35 +00:00
|
|
|
uint64_t new_clusters = spdk_divide_round_up(sz, spdk_bs_get_cluster_size(lvs->blobstore));
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
2018-03-19 21:05:44 +00:00
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
2018-03-19 21:05:44 +00:00
|
|
|
req->lvol = lvol;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_resize(blob, new_clusters, lvol_blob_resize_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 15:31:05 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_set_read_only_cb(void *cb_arg, int lvolerrno)
|
2019-01-15 15:31:05 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_blob_set_read_only(lvol->blob);
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_sync_md(lvol->blob, lvol_set_read_only_cb, req);
|
2019-01-15 15:31:05 +00:00
|
|
|
}
|
|
|
|
|
2018-01-10 10:02:27 +00:00
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_rename_cb(void *cb_arg, int lvolerrno)
|
2018-01-10 10:02:27 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("Lvol rename operation failed\n");
|
|
|
|
} else {
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(req->lvol->name, sizeof(req->lvol->name), "%s", req->name);
|
2018-01-10 10:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_rename(struct spdk_lvol *lvol, const char *new_name,
|
|
|
|
spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *tmp;
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
|
|
|
struct spdk_lvol_req *req;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Check if new name is current lvol name.
|
|
|
|
* If so, return success immediately */
|
|
|
|
if (strncmp(lvol->name, new_name, SPDK_LVOL_NAME_MAX) == 0) {
|
|
|
|
cb_fn(cb_arg, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if lvol with 'new_name' already exists in lvolstore */
|
|
|
|
TAILQ_FOREACH(tmp, &lvol->lvol_store->lvols, link) {
|
|
|
|
if (strncmp(tmp->name, new_name, SPDK_LVOL_NAME_MAX) == 0) {
|
|
|
|
SPDK_ERRLOG("Lvol %s already exists in lvol store %s\n", new_name, lvol->lvol_store->name);
|
|
|
|
cb_fn(cb_arg, -EEXIST);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->lvol = lvol;
|
2018-04-09 23:08:34 +00:00
|
|
|
snprintf(req->name, sizeof(req->name), "%s", new_name);
|
2018-01-10 10:02:27 +00:00
|
|
|
|
|
|
|
rc = spdk_blob_set_xattr(blob, "name", new_name, strlen(new_name) + 1);
|
|
|
|
if (rc < 0) {
|
|
|
|
free(req);
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_sync_md(blob, lvol_rename_cb, req);
|
2018-01-10 10:02:27 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
void
|
2017-10-20 09:43:07 +00:00
|
|
|
spdk_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2018-01-29 13:28:23 +00:00
|
|
|
struct spdk_lvol_req *req;
|
2019-01-05 08:11:12 +00:00
|
|
|
struct spdk_blob_store *bs;
|
2017-10-20 09:43:07 +00:00
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol does not exist\n");
|
2017-10-20 09:43:07 +00:00
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-20 08:34:22 +00:00
|
|
|
if (lvol->ref_count != 0) {
|
2017-12-21 09:50:52 +00:00
|
|
|
SPDK_ERRLOG("Cannot destroy lvol %s because it is still open\n", lvol->unique_id);
|
2017-10-20 08:34:22 +00:00
|
|
|
cb_fn(cb_arg, -EBUSY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-25 08:15:02 +00:00
|
|
|
lvol->action_in_progress = true;
|
|
|
|
|
2017-10-20 09:43:07 +00:00
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-29 13:28:23 +00:00
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
2017-10-20 09:43:07 +00:00
|
|
|
req->lvol = lvol;
|
2019-01-05 08:11:12 +00:00
|
|
|
bs = lvol->lvol_store->blobstore;
|
2017-10-20 09:43:07 +00:00
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_delete_blob(bs, lvol->blob_id, lvol_delete_blob_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-10-20 09:43:07 +00:00
|
|
|
spdk_lvol_close(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-10-20 09:43:07 +00:00
|
|
|
struct spdk_lvol_req *req;
|
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol does not exist\n");
|
2017-10-20 09:43:07 +00:00
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-20 14:07:10 +00:00
|
|
|
if (lvol->ref_count > 1) {
|
|
|
|
lvol->ref_count--;
|
|
|
|
cb_fn(cb_arg, 0);
|
|
|
|
return;
|
|
|
|
} else if (lvol->ref_count == 0) {
|
|
|
|
cb_fn(cb_arg, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-25 08:15:02 +00:00
|
|
|
lvol->action_in_progress = true;
|
|
|
|
|
2017-10-20 09:43:07 +00:00
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
2017-09-14 14:53:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-20 09:43:07 +00:00
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->lvol = lvol;
|
|
|
|
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_blob_close(lvol->blob, lvol_close_blob_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct spdk_io_channel *
|
|
|
|
spdk_lvol_get_io_channel(struct spdk_lvol *lvol)
|
|
|
|
{
|
|
|
|
return spdk_bs_alloc_io_channel(lvol->lvol_store->blobstore);
|
|
|
|
}
|
2018-04-23 12:30:16 +00:00
|
|
|
|
|
|
|
static void
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_inflate_cb(void *cb_arg, int lvolerrno)
|
2018-04-23 12:30:16 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
|
|
|
|
spdk_bs_free_io_channel(req->channel);
|
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
SPDK_ERRLOG("Could not inflate lvol\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_inflate(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req;
|
2018-11-19 13:39:16 +00:00
|
|
|
spdk_blob_id blob_id;
|
2018-04-23 12:30:16 +00:00
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("Lvol does not exist\n");
|
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->channel = spdk_bs_alloc_io_channel(lvol->lvol_store->blobstore);
|
|
|
|
if (req->channel == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc io channel for lvol inflate request\n");
|
|
|
|
free(req);
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-19 13:39:16 +00:00
|
|
|
blob_id = spdk_blob_get_id(lvol->blob);
|
2020-05-15 01:06:20 +00:00
|
|
|
spdk_bs_inflate_blob(lvol->lvol_store->blobstore, req->channel, blob_id, lvol_inflate_cb,
|
2018-04-23 12:30:16 +00:00
|
|
|
req);
|
|
|
|
}
|
2018-05-10 10:01:29 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
spdk_lvol_decouple_parent(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req;
|
2018-11-19 13:39:16 +00:00
|
|
|
spdk_blob_id blob_id;
|
2018-05-10 10:01:29 +00:00
|
|
|
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("Lvol does not exist\n");
|
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->channel = spdk_bs_alloc_io_channel(lvol->lvol_store->blobstore);
|
|
|
|
if (req->channel == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc io channel for lvol inflate request\n");
|
|
|
|
free(req);
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-19 13:39:16 +00:00
|
|
|
blob_id = spdk_blob_get_id(lvol->blob);
|
2018-05-10 10:01:29 +00:00
|
|
|
spdk_bs_blob_decouple_parent(lvol->lvol_store->blobstore, req->channel, blob_id,
|
2020-05-15 01:06:20 +00:00
|
|
|
lvol_inflate_cb, req);
|
2018-05-10 10:01:29 +00:00
|
|
|
}
|