2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation.
|
2017-09-14 14:53:36 +00:00
|
|
|
* All rights reserved.
|
2023-01-26 21:52:52 +00:00
|
|
|
* Copyright (c) 2022-2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2017-09-14 14:53:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/blob_bdev.h"
|
|
|
|
#include "spdk/rpc.h"
|
2018-05-23 21:01:03 +00:00
|
|
|
#include "spdk/bdev_module.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2017-10-19 15:30:32 +00:00
|
|
|
#include "spdk/string.h"
|
2018-03-02 00:59:50 +00:00
|
|
|
#include "spdk/uuid.h"
|
2022-10-10 21:31:31 +00:00
|
|
|
#include "spdk/blob.h"
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
#include "vbdev_lvol.h"
|
|
|
|
|
2022-01-31 12:10:53 +00:00
|
|
|
struct vbdev_lvol_io {
|
|
|
|
struct spdk_blob_ext_io_opts ext_io_opts;
|
|
|
|
};
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static TAILQ_HEAD(, lvol_store_bdev) g_spdk_lvol_pairs = TAILQ_HEAD_INITIALIZER(
|
|
|
|
g_spdk_lvol_pairs);
|
|
|
|
|
2018-03-06 18:52:46 +00:00
|
|
|
static int vbdev_lvs_init(void);
|
2021-08-05 10:14:54 +00:00
|
|
|
static void vbdev_lvs_fini_start(void);
|
2018-03-06 18:52:46 +00:00
|
|
|
static int vbdev_lvs_get_ctx_size(void);
|
2023-01-30 18:13:06 +00:00
|
|
|
static void vbdev_lvs_examine_config(struct spdk_bdev *bdev);
|
|
|
|
static void vbdev_lvs_examine_disk(struct spdk_bdev *bdev);
|
2021-08-05 10:14:54 +00:00
|
|
|
static bool g_shutdown_started = false;
|
2018-03-06 18:52:46 +00:00
|
|
|
|
2023-01-26 21:52:52 +00:00
|
|
|
struct spdk_bdev_module g_lvol_if = {
|
2018-03-06 18:52:46 +00:00
|
|
|
.name = "lvol",
|
|
|
|
.module_init = vbdev_lvs_init,
|
2021-08-05 10:14:54 +00:00
|
|
|
.fini_start = vbdev_lvs_fini_start,
|
2021-08-04 12:56:37 +00:00
|
|
|
.async_fini_start = true,
|
2023-01-30 18:13:06 +00:00
|
|
|
.examine_config = vbdev_lvs_examine_config,
|
|
|
|
.examine_disk = vbdev_lvs_examine_disk,
|
2018-03-06 18:52:46 +00:00
|
|
|
.get_ctx_size = vbdev_lvs_get_ctx_size,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2019-02-05 10:46:48 +00:00
|
|
|
SPDK_BDEV_MODULE_REGISTER(lvol, &g_lvol_if)
|
2018-03-06 18:52:46 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
struct lvol_store_bdev *
|
2017-11-30 18:30:55 +00:00
|
|
|
vbdev_get_lvs_bdev_by_lvs(struct spdk_lvol_store *lvs_orig)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
|
|
|
struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first();
|
|
|
|
|
|
|
|
while (lvs_bdev != NULL) {
|
|
|
|
lvs = lvs_bdev->lvs;
|
|
|
|
if (lvs == lvs_orig) {
|
|
|
|
if (lvs_bdev->req != NULL) {
|
|
|
|
/* We do not allow access to lvs that are being destroyed */
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return lvs_bdev;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
|
|
|
}
|
2017-11-24 13:23:45 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:02:27 +00:00
|
|
|
static int
|
|
|
|
_vbdev_lvol_change_bdev_alias(struct spdk_lvol *lvol, const char *new_lvol_name)
|
|
|
|
{
|
|
|
|
struct spdk_bdev_alias *tmp;
|
|
|
|
char *old_alias;
|
|
|
|
char *alias;
|
|
|
|
int rc;
|
|
|
|
int alias_number = 0;
|
|
|
|
|
|
|
|
/* bdev representing lvols have only one alias,
|
|
|
|
* while we changed lvs name earlier, we have to iterate alias list to get one,
|
|
|
|
* and check if there is only one alias */
|
|
|
|
|
2021-05-11 07:16:14 +00:00
|
|
|
TAILQ_FOREACH(tmp, spdk_bdev_get_aliases(lvol->bdev), tailq) {
|
2018-01-10 10:02:27 +00:00
|
|
|
if (++alias_number > 1) {
|
|
|
|
SPDK_ERRLOG("There is more than 1 alias in bdev %s\n", lvol->bdev->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-05-11 07:16:14 +00:00
|
|
|
old_alias = tmp->alias.name;
|
2018-01-10 10:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (alias_number == 0) {
|
|
|
|
SPDK_ERRLOG("There are no aliases in bdev %s\n", lvol->bdev->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
alias = spdk_sprintf_alloc("%s/%s", lvol->lvol_store->name, new_lvol_name);
|
|
|
|
if (alias == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for alias\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_bdev_alias_add(lvol->bdev, alias);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("cannot add alias '%s'\n", alias);
|
|
|
|
free(alias);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
free(alias);
|
|
|
|
|
|
|
|
rc = spdk_bdev_alias_del(lvol->bdev, old_alias);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("cannot remove alias '%s'\n", old_alias);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-11-24 13:23:45 +00:00
|
|
|
static struct lvol_store_bdev *
|
|
|
|
vbdev_get_lvs_bdev_by_bdev(struct spdk_bdev *bdev_orig)
|
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first();
|
|
|
|
|
|
|
|
while (lvs_bdev != NULL) {
|
|
|
|
if (lvs_bdev->bdev == bdev_orig) {
|
2017-12-04 10:38:24 +00:00
|
|
|
if (lvs_bdev->req != NULL) {
|
|
|
|
/* We do not allow access to lvs that are being destroyed */
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return lvs_bdev;
|
|
|
|
}
|
2017-11-24 13:23:45 +00:00
|
|
|
}
|
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:30:55 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-20 13:46:11 +00:00
|
|
|
static void
|
2020-10-14 16:34:23 +00:00
|
|
|
vbdev_lvs_hotremove_cb(struct spdk_bdev *bdev)
|
2017-09-20 13:46:11 +00:00
|
|
|
{
|
2017-11-24 13:23:45 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
2017-09-20 13:46:11 +00:00
|
|
|
|
2017-11-24 13:23:45 +00:00
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_bdev(bdev);
|
|
|
|
if (lvs_bdev != NULL) {
|
2022-10-06 22:25:48 +00:00
|
|
|
SPDK_NOTICELOG("bdev %s being removed: closing lvstore %s\n",
|
|
|
|
spdk_bdev_get_name(bdev), lvs_bdev->lvs->name);
|
2017-11-24 13:23:45 +00:00
|
|
|
vbdev_lvs_unload(lvs_bdev->lvs, NULL, NULL);
|
2017-09-20 13:46:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-14 16:34:23 +00:00
|
|
|
static void
|
|
|
|
vbdev_lvs_base_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
|
|
|
|
void *event_ctx)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case SPDK_BDEV_EVENT_REMOVE:
|
|
|
|
vbdev_lvs_hotremove_cb(bdev);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
SPDK_NOTICELOG("Unsupported bdev event: type %d\n", type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_create_cb(void *cb_arg, struct spdk_lvol_store *lvs, int lvserrno)
|
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_with_handle_req *req = cb_arg;
|
2017-09-14 14:53:36 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_bdev *bdev = req->base_bdev;
|
2017-10-04 15:06:46 +00:00
|
|
|
struct spdk_bs_dev *bs_dev = req->bs_dev;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
assert(lvs == NULL);
|
2019-09-04 08:43:01 +00:00
|
|
|
SPDK_ERRLOG("Cannot create lvol store bdev\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:52:46 +00:00
|
|
|
lvserrno = spdk_bs_bdev_claim(bs_dev, &g_lvol_if);
|
2017-10-04 15:06:46 +00:00
|
|
|
if (lvserrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store base bdev already claimed by another bdev\n");
|
2017-10-04 15:06:46 +00:00
|
|
|
req->bs_dev->destroy(req->bs_dev);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
assert(lvs != NULL);
|
|
|
|
|
|
|
|
lvs_bdev = calloc(1, sizeof(*lvs_bdev));
|
|
|
|
if (!lvs_bdev) {
|
|
|
|
lvserrno = -ENOMEM;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
lvs_bdev->lvs = lvs;
|
|
|
|
lvs_bdev->bdev = bdev;
|
2017-10-26 08:41:00 +00:00
|
|
|
lvs_bdev->req = NULL;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store bdev inserted\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
end:
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvs, lvserrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(req);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2020-10-14 19:34:25 +00:00
|
|
|
vbdev_lvs_create(const char *base_bdev_name, const char *name, uint32_t cluster_sz,
|
2022-04-10 05:56:26 +00:00
|
|
|
enum lvs_clear_method clear_method, uint32_t num_md_pages_per_cluster_ratio,
|
|
|
|
spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_bs_dev *bs_dev;
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvs_with_handle_req *lvs_req;
|
2017-10-18 19:40:28 +00:00
|
|
|
struct spdk_lvs_opts opts;
|
2017-09-14 14:53:36 +00:00
|
|
|
int rc;
|
2017-10-27 13:12:38 +00:00
|
|
|
int len;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2020-10-14 19:34:25 +00:00
|
|
|
if (base_bdev_name == NULL) {
|
|
|
|
SPDK_ERRLOG("missing base_bdev_name param\n");
|
|
|
|
return -EINVAL;
|
2017-09-29 07:46:50 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 19:40:28 +00:00
|
|
|
spdk_lvs_opts_init(&opts);
|
2017-09-29 07:46:50 +00:00
|
|
|
if (cluster_sz != 0) {
|
2017-10-18 19:40:28 +00:00
|
|
|
opts.cluster_sz = cluster_sz;
|
2017-09-29 07:46:50 +00:00
|
|
|
}
|
|
|
|
|
2019-02-28 09:57:19 +00:00
|
|
|
if (clear_method != 0) {
|
|
|
|
opts.clear_method = clear_method;
|
|
|
|
}
|
|
|
|
|
2022-04-10 05:56:26 +00:00
|
|
|
if (num_md_pages_per_cluster_ratio != 0) {
|
|
|
|
opts.num_md_pages_per_cluster_ratio = num_md_pages_per_cluster_ratio;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
if (name == NULL) {
|
|
|
|
SPDK_ERRLOG("missing name param\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = strnlen(name, SPDK_LVS_NAME_MAX);
|
|
|
|
|
|
|
|
if (len == 0 || len == SPDK_LVS_NAME_MAX) {
|
|
|
|
SPDK_ERRLOG("name must be between 1 and %d characters\n", SPDK_LVS_NAME_MAX - 1);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-04-09 23:05:26 +00:00
|
|
|
snprintf(opts.name, sizeof(opts.name), "%s", name);
|
2023-01-26 21:52:52 +00:00
|
|
|
opts.esnap_bs_dev_create = vbdev_lvol_esnap_dev_create;
|
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) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-10-14 19:34:25 +00:00
|
|
|
rc = spdk_bdev_create_bs_dev_ext(base_bdev_name, vbdev_lvs_base_bdev_event_cb,
|
2020-10-14 16:34:23 +00:00
|
|
|
NULL, &bs_dev);
|
|
|
|
if (rc < 0) {
|
2017-09-14 14:53:36 +00:00
|
|
|
SPDK_ERRLOG("Cannot create blobstore device\n");
|
|
|
|
free(lvs_req);
|
2020-10-14 16:34:23 +00:00
|
|
|
return rc;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2017-09-19 14:09:43 +00:00
|
|
|
lvs_req->bs_dev = bs_dev;
|
2020-10-14 19:34:25 +00:00
|
|
|
lvs_req->base_bdev = bs_dev->get_base_bdev(bs_dev);
|
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-10-18 19:40:28 +00:00
|
|
|
rc = spdk_lvs_init(bs_dev, &opts, _vbdev_lvs_create_cb, lvs_req);
|
2017-09-14 14:53:36 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
free(lvs_req);
|
|
|
|
bs_dev->destroy(bs_dev);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:03:39 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_rename_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *tmp;
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store rename failed\n");
|
2018-01-10 10:03:39 +00:00
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH(tmp, &req->lvol_store->lvols, link) {
|
|
|
|
/* We have to pass current lvol name, since only lvs name changed */
|
|
|
|
_vbdev_lvol_change_bdev_alias(tmp, tmp->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvserrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvs_rename(struct spdk_lvol_store *lvs, const char *new_lvs_name,
|
|
|
|
spdk_lvs_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
|
|
|
|
struct spdk_lvs_req *req;
|
|
|
|
|
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvs);
|
|
|
|
if (!lvs_bdev) {
|
|
|
|
SPDK_ERRLOG("No such lvol store found\n");
|
|
|
|
cb_fn(cb_arg, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->lvol_store = lvs;
|
|
|
|
|
|
|
|
spdk_lvs_rename(lvs, new_lvs_name, _vbdev_lvs_rename_cb, req);
|
|
|
|
}
|
|
|
|
|
2017-10-21 01:23:54 +00:00
|
|
|
static void
|
2017-10-26 06:42:11 +00:00
|
|
|
_vbdev_lvs_remove_cb(void *cb_arg, int lvserrno)
|
2017-10-21 01:23:54 +00:00
|
|
|
{
|
2017-10-26 08:41:00 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev = cb_arg;
|
|
|
|
struct spdk_lvs_req *req = lvs_bdev->req;
|
2017-10-21 01:23:54 +00:00
|
|
|
|
2017-10-26 08:41:00 +00:00
|
|
|
if (lvserrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store removed with error: %d.\n", lvserrno);
|
2017-10-26 08:41:00 +00:00
|
|
|
}
|
2017-10-21 01:23:54 +00:00
|
|
|
|
2019-01-17 09:14:59 +00:00
|
|
|
TAILQ_REMOVE(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
|
|
|
free(lvs_bdev);
|
|
|
|
|
2017-12-07 23:23:48 +00:00
|
|
|
if (req->cb_fn != NULL) {
|
2017-10-21 01:23:54 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvserrno);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-10-21 01:23:54 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_remove_lvol_cb(void *cb_arg, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = lvs_bdev->lvs;
|
|
|
|
struct spdk_lvol *lvol;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vbdev_lvol, "Lvol removed with errno %d\n", lvolerrno);
|
2018-07-23 13:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (TAILQ_EMPTY(&lvs->lvols)) {
|
2018-07-24 08:42:23 +00:00
|
|
|
spdk_lvs_destroy(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
|
2018-07-23 13:57:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvol = TAILQ_FIRST(&lvs->lvols);
|
|
|
|
while (lvol != NULL) {
|
|
|
|
if (spdk_lvol_deletable(lvol)) {
|
|
|
|
vbdev_lvol_destroy(lvol, _vbdev_lvs_remove_lvol_cb, lvs_bdev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lvol = TAILQ_NEXT(lvol, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no lvol is deletable, that means there is circular dependency. */
|
|
|
|
SPDK_ERRLOG("Lvols left in lvs, but unable to delete.\n");
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
2021-08-05 09:07:05 +00:00
|
|
|
static bool
|
|
|
|
_vbdev_lvs_are_lvols_closed(struct spdk_lvol_store *lvs)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol;
|
|
|
|
|
|
|
|
TAILQ_FOREACH(lvol, &lvs->lvols, link) {
|
|
|
|
if (lvol->ref_count != 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
static void
|
2018-07-24 08:42:23 +00:00
|
|
|
_vbdev_lvs_remove_bdev_unregistered_cb(void *cb_arg, int bdeverrno)
|
2018-07-23 13:57:02 +00:00
|
|
|
{
|
2018-07-24 08:42:23 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = lvs_bdev->lvs;
|
|
|
|
|
|
|
|
if (bdeverrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(vbdev_lvol, "Lvol unregistered with errno %d\n", bdeverrno);
|
2018-07-24 08:42:23 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 09:07:05 +00:00
|
|
|
/* Lvol store can be unloaded once all lvols are closed. */
|
|
|
|
if (_vbdev_lvs_are_lvols_closed(lvs)) {
|
|
|
|
spdk_lvs_unload(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
|
2018-07-24 08:42:23 +00:00
|
|
|
}
|
2018-07-23 13:57:02 +00:00
|
|
|
}
|
|
|
|
|
2017-10-26 06:42:11 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_remove(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg,
|
|
|
|
bool destroy)
|
2017-10-21 01:23:54 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvs_req *req;
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
struct spdk_lvol *lvol, *tmp;
|
|
|
|
|
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvs);
|
2017-10-26 06:42:11 +00:00
|
|
|
if (!lvs_bdev) {
|
|
|
|
SPDK_ERRLOG("No such lvol store found\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
if (cb_fn != NULL) {
|
2017-10-26 06:42:11 +00:00
|
|
|
cb_fn(cb_arg, -ENODEV);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-10-21 01:23:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-04 15:06:46 +00:00
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
2017-12-07 23:23:48 +00:00
|
|
|
if (cb_fn != NULL) {
|
2017-10-04 15:06:46 +00:00
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
2017-12-07 23:23:48 +00:00
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-10-04 15:06:46 +00:00
|
|
|
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
2017-10-26 08:41:00 +00:00
|
|
|
lvs_bdev->req = req;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2021-08-05 09:07:05 +00:00
|
|
|
if (_vbdev_lvs_are_lvols_closed(lvs)) {
|
2017-10-26 06:42:11 +00:00
|
|
|
if (destroy) {
|
2017-12-04 18:05:49 +00:00
|
|
|
spdk_lvs_destroy(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
|
2023-04-09 13:48:25 +00:00
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
2023-04-09 13:48:25 +00:00
|
|
|
spdk_lvs_unload(lvs, _vbdev_lvs_remove_cb, lvs_bdev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (destroy) {
|
|
|
|
_vbdev_lvs_remove_lvol_cb(lvs_bdev, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
2022-10-10 21:31:31 +00:00
|
|
|
if (lvol->bdev == NULL) {
|
|
|
|
spdk_lvol_close(lvol, _vbdev_lvs_remove_bdev_unregistered_cb, lvs_bdev);
|
|
|
|
continue;
|
|
|
|
}
|
2023-04-09 13:48:25 +00:00
|
|
|
spdk_bdev_unregister(lvol->bdev, _vbdev_lvs_remove_bdev_unregistered_cb, lvs_bdev);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 06:42:11 +00:00
|
|
|
void
|
|
|
|
vbdev_lvs_unload(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
_vbdev_lvs_remove(lvs, cb_fn, cb_arg, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvs_destruct(struct spdk_lvol_store *lvs, spdk_lvs_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
_vbdev_lvs_remove(lvs, cb_fn, cb_arg, true);
|
|
|
|
}
|
|
|
|
|
2017-09-18 08:49:22 +00:00
|
|
|
struct lvol_store_bdev *
|
|
|
|
vbdev_lvol_store_first(void)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
|
|
|
|
lvs_bdev = TAILQ_FIRST(&g_spdk_lvol_pairs);
|
|
|
|
if (lvs_bdev) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Starting lvolstore iteration at %p\n", lvs_bdev->lvs);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lvs_bdev;
|
|
|
|
}
|
|
|
|
|
2017-09-18 08:49:22 +00:00
|
|
|
struct lvol_store_bdev *
|
|
|
|
vbdev_lvol_store_next(struct lvol_store_bdev *prev)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
|
2017-11-24 13:19:36 +00:00
|
|
|
if (prev == NULL) {
|
|
|
|
SPDK_ERRLOG("prev argument cannot be NULL\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs_bdev = TAILQ_NEXT(prev, lvol_stores);
|
|
|
|
if (lvs_bdev) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Continuing lvolstore iteration at %p\n", lvs_bdev->lvs);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return lvs_bdev;
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:16:37 +00:00
|
|
|
static struct spdk_lvol_store *
|
2018-03-02 00:59:50 +00:00
|
|
|
_vbdev_get_lvol_store_by_uuid(const struct spdk_uuid *uuid)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
2017-09-18 08:49:22 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first();
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
while (lvs_bdev != NULL) {
|
|
|
|
lvs = lvs_bdev->lvs;
|
2018-03-02 00:59:50 +00:00
|
|
|
if (spdk_uuid_compare(&lvs->uuid, uuid) == 0) {
|
2017-09-14 14:53:36 +00:00
|
|
|
return lvs;
|
|
|
|
}
|
2017-09-18 08:49:22 +00:00
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:16:37 +00:00
|
|
|
struct spdk_lvol_store *
|
|
|
|
vbdev_get_lvol_store_by_uuid(const char *uuid_str)
|
|
|
|
{
|
2018-03-02 00:59:50 +00:00
|
|
|
struct spdk_uuid uuid;
|
2017-11-30 18:16:37 +00:00
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
if (spdk_uuid_parse(&uuid, uuid_str)) {
|
2017-11-30 18:16:37 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
return _vbdev_get_lvol_store_by_uuid(&uuid);
|
2017-11-30 18:16:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
struct spdk_lvol_store *
|
|
|
|
vbdev_get_lvol_store_by_name(const char *name)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
|
|
|
struct lvol_store_bdev *lvs_bdev = vbdev_lvol_store_first();
|
|
|
|
|
|
|
|
while (lvs_bdev != NULL) {
|
|
|
|
lvs = lvs_bdev->lvs;
|
|
|
|
if (strncmp(lvs->name, name, sizeof(lvs->name)) == 0) {
|
|
|
|
return lvs;
|
|
|
|
}
|
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
struct vbdev_lvol_destroy_ctx {
|
|
|
|
struct spdk_lvol *lvol;
|
|
|
|
spdk_lvol_op_complete cb_fn;
|
|
|
|
void *cb_arg;
|
|
|
|
};
|
2017-10-20 09:43:07 +00:00
|
|
|
|
2021-08-05 10:14:54 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvol_unregister_unload_lvs(void *cb_arg, int lvserrno)
|
|
|
|
{
|
|
|
|
struct lvol_bdev *lvol_bdev = cb_arg;
|
|
|
|
struct lvol_store_bdev *lvs_bdev = lvol_bdev->lvs_bdev;
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store removed with error: %d.\n", lvserrno);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
|
|
|
free(lvs_bdev);
|
|
|
|
|
|
|
|
spdk_bdev_destruct_done(&lvol_bdev->bdev, lvserrno);
|
|
|
|
free(lvol_bdev);
|
|
|
|
}
|
|
|
|
|
2017-10-20 09:43:07 +00:00
|
|
|
static void
|
2018-07-23 13:57:02 +00:00
|
|
|
_vbdev_lvol_unregister_cb(void *ctx, int lvolerrno)
|
2017-10-20 09:43:07 +00:00
|
|
|
{
|
2021-08-11 06:57:23 +00:00
|
|
|
struct lvol_bdev *lvol_bdev = ctx;
|
2021-08-05 10:14:54 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev = lvol_bdev->lvs_bdev;
|
|
|
|
|
|
|
|
if (g_shutdown_started && _vbdev_lvs_are_lvols_closed(lvs_bdev->lvs)) {
|
|
|
|
spdk_lvs_unload(lvs_bdev->lvs, _vbdev_lvol_unregister_unload_lvs, lvol_bdev);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-25 09:11:59 +00:00
|
|
|
|
2021-08-11 06:57:23 +00:00
|
|
|
spdk_bdev_destruct_done(&lvol_bdev->bdev, lvolerrno);
|
|
|
|
free(lvol_bdev);
|
2017-10-20 09:43:07 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static int
|
2018-07-23 13:57:02 +00:00
|
|
|
vbdev_lvol_unregister(void *ctx)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = ctx;
|
2021-08-18 14:35:47 +00:00
|
|
|
struct lvol_bdev *lvol_bdev;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
assert(lvol != NULL);
|
2021-08-18 14:35:47 +00:00
|
|
|
lvol_bdev = SPDK_CONTAINEROF(lvol->bdev, struct lvol_bdev, bdev);
|
2017-10-25 09:11:59 +00:00
|
|
|
|
2018-08-14 08:39:27 +00:00
|
|
|
spdk_bdev_alias_del_all(lvol->bdev);
|
2021-08-11 06:57:23 +00:00
|
|
|
spdk_lvol_close(lvol, _vbdev_lvol_unregister_cb, lvol_bdev);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-10-25 09:11:59 +00:00
|
|
|
/* return 1 to indicate we have an operation that must finish asynchronously before the
|
|
|
|
* lvol is closed
|
|
|
|
*/
|
|
|
|
return 1;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvol_destroy_cb(void *cb_arg, int bdeverrno)
|
|
|
|
{
|
|
|
|
struct vbdev_lvol_destroy_ctx *ctx = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = ctx->lvol;
|
|
|
|
|
|
|
|
if (bdeverrno < 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Could not unregister bdev during lvol (%s) destroy\n",
|
2018-07-23 13:57:02 +00:00
|
|
|
lvol->unique_id);
|
|
|
|
ctx->cb_fn(ctx->cb_arg, bdeverrno);
|
|
|
|
free(ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_lvol_destroy(lvol, ctx->cb_fn, ctx->cb_arg);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2018-04-11 22:12:13 +00:00
|
|
|
void
|
|
|
|
vbdev_lvol_destroy(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
2018-07-23 13:57:02 +00:00
|
|
|
struct vbdev_lvol_destroy_ctx *ctx;
|
2019-05-21 07:19:03 +00:00
|
|
|
size_t count;
|
2018-07-23 13:57:02 +00:00
|
|
|
|
|
|
|
assert(lvol != NULL);
|
|
|
|
assert(cb_fn != NULL);
|
|
|
|
|
|
|
|
/* Check if it is possible to delete lvol */
|
2019-05-21 07:19:03 +00:00
|
|
|
spdk_blob_get_clones(lvol->lvol_store->blobstore, lvol->blob_id, NULL, &count);
|
|
|
|
if (count > 1) {
|
2018-07-23 13:57:02 +00:00
|
|
|
/* throw an error */
|
|
|
|
SPDK_ERRLOG("Cannot delete lvol\n");
|
|
|
|
cb_fn(cb_arg, -EPERM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx = calloc(1, sizeof(*ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->lvol = lvol;
|
|
|
|
ctx->cb_fn = cb_fn;
|
|
|
|
ctx->cb_arg = cb_arg;
|
|
|
|
|
2023-04-11 17:21:21 +00:00
|
|
|
if (spdk_blob_is_degraded(lvol->blob)) {
|
|
|
|
spdk_lvol_close(lvol, _vbdev_lvol_destroy_cb, ctx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-23 13:57:02 +00:00
|
|
|
spdk_bdev_unregister(lvol->bdev, _vbdev_lvol_destroy_cb, ctx);
|
2018-04-11 22:12:13 +00:00
|
|
|
}
|
|
|
|
|
2018-03-19 11:30:51 +00:00
|
|
|
static char *
|
|
|
|
vbdev_lvol_find_name(struct spdk_lvol *lvol, spdk_blob_id blob_id)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs;
|
|
|
|
struct spdk_lvol *_lvol;
|
|
|
|
|
|
|
|
assert(lvol != NULL);
|
|
|
|
|
|
|
|
lvs = lvol->lvol_store;
|
|
|
|
|
|
|
|
assert(lvs);
|
|
|
|
|
|
|
|
TAILQ_FOREACH(_lvol, &lvs->lvols, link) {
|
|
|
|
if (_lvol->blob_id == blob_id) {
|
|
|
|
return _lvol->name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static int
|
2018-02-22 12:48:13 +00:00
|
|
|
vbdev_lvol_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = ctx;
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
struct spdk_bdev *bdev;
|
2018-03-19 11:30:51 +00:00
|
|
|
struct spdk_blob *blob;
|
2018-03-02 00:59:50 +00:00
|
|
|
char lvol_store_uuid[SPDK_UUID_STRING_LEN];
|
2018-03-19 11:30:51 +00:00
|
|
|
spdk_blob_id *ids = NULL;
|
|
|
|
size_t count, i;
|
|
|
|
char *name;
|
|
|
|
int rc = 0;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_object_begin(w, "lvol");
|
2017-10-13 23:11:17 +00:00
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvol->lvol_store);
|
2018-04-20 21:48:24 +00:00
|
|
|
if (!lvs_bdev) {
|
|
|
|
SPDK_ERRLOG("No such lvol store found\n");
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
bdev = lvs_bdev->bdev;
|
|
|
|
|
2018-03-02 00:59:50 +00:00
|
|
|
spdk_uuid_fmt_lower(lvol_store_uuid, sizeof(lvol_store_uuid), &lvol->lvol_store->uuid);
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_string(w, "lvol_store_uuid", lvol_store_uuid);
|
2017-10-13 23:23:04 +00:00
|
|
|
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_string(w, "base_bdev", spdk_bdev_get_name(bdev));
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-03-19 11:30:51 +00:00
|
|
|
blob = lvol->blob;
|
|
|
|
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_bool(w, "thin_provision", spdk_blob_is_thin_provisioned(blob));
|
2018-03-19 11:30:51 +00:00
|
|
|
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_bool(w, "snapshot", spdk_blob_is_snapshot(blob));
|
2018-01-31 16:55:54 +00:00
|
|
|
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_bool(w, "clone", spdk_blob_is_clone(blob));
|
2018-03-19 11:30:51 +00:00
|
|
|
|
|
|
|
if (spdk_blob_is_clone(blob)) {
|
|
|
|
spdk_blob_id snapshotid = spdk_blob_get_parent_snapshot(lvol->lvol_store->blobstore, lvol->blob_id);
|
|
|
|
if (snapshotid != SPDK_BLOBID_INVALID) {
|
|
|
|
name = vbdev_lvol_find_name(lvol, snapshotid);
|
|
|
|
if (name != NULL) {
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_string(w, "base_snapshot", name);
|
2018-03-19 11:30:51 +00:00
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Cannot obtain snapshots name\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_blob_is_snapshot(blob)) {
|
|
|
|
/* Take a number of clones */
|
|
|
|
rc = spdk_blob_get_clones(lvol->lvol_store->blobstore, lvol->blob_id, NULL, &count);
|
|
|
|
if (rc == -ENOMEM && count > 0) {
|
|
|
|
ids = malloc(sizeof(spdk_blob_id) * count);
|
|
|
|
if (ids == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot allocate memory\n");
|
|
|
|
rc = -ENOMEM;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_blob_get_clones(lvol->lvol_store->blobstore, lvol->blob_id, ids, &count);
|
|
|
|
if (rc == 0) {
|
2019-02-01 05:34:45 +00:00
|
|
|
spdk_json_write_named_array_begin(w, "clones");
|
2018-03-19 11:30:51 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
name = vbdev_lvol_find_name(lvol, ids[i]);
|
|
|
|
if (name != NULL) {
|
|
|
|
spdk_json_write_string(w, name);
|
|
|
|
} else {
|
|
|
|
SPDK_ERRLOG("Cannot obtain clone name\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
}
|
|
|
|
free(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-01-17 16:12:48 +00:00
|
|
|
spdk_json_write_named_bool(w, "esnap_clone", spdk_blob_is_esnap_clone(blob));
|
|
|
|
|
|
|
|
if (spdk_blob_is_esnap_clone(blob)) {
|
|
|
|
const char *name;
|
|
|
|
size_t name_len;
|
|
|
|
|
|
|
|
rc = spdk_blob_get_esnap_id(blob, (const void **)&name, &name_len);
|
|
|
|
if (rc == 0 && name != NULL && strnlen(name, name_len) + 1 == name_len) {
|
|
|
|
spdk_json_write_named_string(w, "external_snapshot_name", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-19 11:30:51 +00:00
|
|
|
end:
|
2017-10-13 23:11:17 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
|
2018-03-19 11:30:51 +00:00
|
|
|
return rc;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 15:28:47 +00:00
|
|
|
static void
|
|
|
|
vbdev_lvol_write_config_json(struct spdk_bdev *bdev, struct spdk_json_write_ctx *w)
|
|
|
|
{
|
|
|
|
/* Nothing to dump as lvol configuration is saved on physical device. */
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static struct spdk_io_channel *
|
|
|
|
vbdev_lvol_get_io_channel(void *ctx)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = ctx;
|
|
|
|
|
|
|
|
return spdk_lvol_get_io_channel(lvol);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
vbdev_lvol_io_type_supported(void *ctx, enum spdk_bdev_io_type io_type)
|
|
|
|
{
|
2018-04-20 12:24:00 +00:00
|
|
|
struct spdk_lvol *lvol = ctx;
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
switch (io_type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
2018-04-20 12:24:00 +00:00
|
|
|
return !spdk_blob_is_read_only(lvol->blob);
|
2018-02-22 12:29:49 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
2022-09-05 13:22:18 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_SEEK_DATA:
|
|
|
|
case SPDK_BDEV_IO_TYPE_SEEK_HOLE:
|
2017-11-15 14:54:28 +00:00
|
|
|
return true;
|
2017-09-14 14:53:36 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lvol_op_comp(void *cb_arg, int bserrno)
|
|
|
|
{
|
2020-04-22 09:48:18 +00:00
|
|
|
struct spdk_bdev_io *bdev_io = cb_arg;
|
2020-04-10 10:46:13 +00:00
|
|
|
enum spdk_bdev_io_status status = SPDK_BDEV_IO_STATUS_SUCCESS;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (bserrno != 0) {
|
2017-12-28 07:02:21 +00:00
|
|
|
if (bserrno == -ENOMEM) {
|
2020-04-10 10:46:13 +00:00
|
|
|
status = SPDK_BDEV_IO_STATUS_NOMEM;
|
2017-12-28 07:02:21 +00:00
|
|
|
} else {
|
2020-04-10 10:46:13 +00:00
|
|
|
status = SPDK_BDEV_IO_STATUS_FAILED;
|
2017-12-28 07:02:21 +00:00
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 10:46:13 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, status);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2017-11-15 14:54:28 +00:00
|
|
|
static void
|
|
|
|
lvol_unmap(struct spdk_lvol *lvol, struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
uint64_t start_page, num_pages;
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
|
|
|
|
|
|
|
start_page = bdev_io->u.bdev.offset_blocks;
|
|
|
|
num_pages = bdev_io->u.bdev.num_blocks;
|
|
|
|
|
2020-04-22 09:48:18 +00:00
|
|
|
spdk_blob_io_unmap(blob, ch, start_page, num_pages, lvol_op_comp, bdev_io);
|
2017-11-15 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
2022-09-05 13:22:18 +00:00
|
|
|
static void
|
|
|
|
lvol_seek_data(struct spdk_lvol *lvol, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
bdev_io->u.bdev.seek.offset = spdk_blob_get_next_allocated_io_unit(lvol->blob,
|
|
|
|
bdev_io->u.bdev.offset_blocks);
|
|
|
|
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lvol_seek_hole(struct spdk_lvol *lvol, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
bdev_io->u.bdev.seek.offset = spdk_blob_get_next_unallocated_io_unit(lvol->blob,
|
|
|
|
bdev_io->u.bdev.offset_blocks);
|
|
|
|
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2017-11-15 14:54:28 +00:00
|
|
|
static void
|
|
|
|
lvol_write_zeroes(struct spdk_lvol *lvol, struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
uint64_t start_page, num_pages;
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
|
|
|
|
|
|
|
start_page = bdev_io->u.bdev.offset_blocks;
|
|
|
|
num_pages = bdev_io->u.bdev.num_blocks;
|
|
|
|
|
2020-04-22 09:48:18 +00:00
|
|
|
spdk_blob_io_write_zeroes(blob, ch, start_page, num_pages, lvol_op_comp, bdev_io);
|
2017-11-15 14:54:28 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
lvol_read(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
uint64_t start_page, num_pages;
|
|
|
|
struct spdk_lvol *lvol = bdev_io->bdev->ctxt;
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
struct vbdev_lvol_io *lvol_io = (struct vbdev_lvol_io *)bdev_io->driver_ctx;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-09-20 13:10:17 +00:00
|
|
|
start_page = bdev_io->u.bdev.offset_blocks;
|
|
|
|
num_pages = bdev_io->u.bdev.num_blocks;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
lvol_io->ext_io_opts.size = sizeof(lvol_io->ext_io_opts);
|
|
|
|
lvol_io->ext_io_opts.memory_domain = bdev_io->u.bdev.memory_domain;
|
|
|
|
lvol_io->ext_io_opts.memory_domain_ctx = bdev_io->u.bdev.memory_domain_ctx;
|
2022-01-31 12:10:53 +00:00
|
|
|
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
spdk_blob_io_readv_ext(blob, ch, bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, start_page,
|
|
|
|
num_pages, lvol_op_comp, bdev_io, &lvol_io->ext_io_opts);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
lvol_write(struct spdk_lvol *lvol, struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
uint64_t start_page, num_pages;
|
|
|
|
struct spdk_blob *blob = lvol->blob;
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
struct vbdev_lvol_io *lvol_io = (struct vbdev_lvol_io *)bdev_io->driver_ctx;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-09-20 13:10:17 +00:00
|
|
|
start_page = bdev_io->u.bdev.offset_blocks;
|
|
|
|
num_pages = bdev_io->u.bdev.num_blocks;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
lvol_io->ext_io_opts.size = sizeof(lvol_io->ext_io_opts);
|
|
|
|
lvol_io->ext_io_opts.memory_domain = bdev_io->u.bdev.memory_domain;
|
|
|
|
lvol_io->ext_io_opts.memory_domain_ctx = bdev_io->u.bdev.memory_domain_ctx;
|
2022-01-31 12:10:53 +00:00
|
|
|
|
bdev: remove spdk_bdev_ext_io_opts from spdk_bdev_io
The spdk_bdev_ext_io_opts structure is used to pass extra options when
submitting a bdev IO request, without having to modify/add functions to
handle new options. Additionally, the structure has a size field to
allow adding new fields without breaking the ABI (and thus having to
bump up the major version of a library).
It is also a part of spdk_bdev_io and there are several reasons for
removing it from that structure:
1. The size field only makes sense in structures that are passed
through pointers. And spdk_bdev_ext_io_opts is indeed passed as a
pointer to spdk_bdev_{readv,writev}_blocks_ext(), however it is
also embedded in spdk_bdev_io (internal.ext_opts_copy), which is
also part of the API. It means that each time a new field is added
to spdk_bdev_ext_io_opts, the size of spdk_bdev_io will also
change, so we will need to bump the major version of libspdk_bdev
anyway, thus making spdk_bdev_ext_io_opts.size useless.
2. The size field also makes internal.ext_opts cumbersome to use, as
each time one of its fields is accessed, we need to check the size.
Currently the code doesn't do that, because all of the existing
spdk_bdev_ext_io_opts fields were present when this structure was
initially introduced, but we'd need to do check the size before
accessing any new fields.
3. spdk_bdev_ext_io_opts has a metadata field, while spdk_bdev_io
already has u.bdev.md_buf, which means that we store the same thing
in several different places in spdk_bdev_io (u.bdev.md_buf,
u.bdev.ext_opts->metadata, internal.ext_opts->metadata).
Therefore, this patch removes all references to spdk_bdev_ext_io_opts
from spdk_bdev_io and replaces them with fields (memory_domain,
memory_domain_ctx) that were missing in spdk_bdev_io. Unfortunately,
this change breaks the API and requires changes in bdev modules that
supported spdk_bdev_io.u.bdev.ext_opts.
Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I49b7524eb84d1d4d7f12b7ab025fec36da1ee01f
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16773
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
2023-02-10 15:22:51 +00:00
|
|
|
spdk_blob_io_writev_ext(blob, ch, bdev_io->u.bdev.iovs, bdev_io->u.bdev.iovcnt, start_page,
|
|
|
|
num_pages, lvol_op_comp, bdev_io, &lvol_io->ext_io_opts);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
lvol_reset(struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
bdev: Not assert but pass completion status to spdk_bdev_io_get_buf_cb
When the specified buffer size to spdk_bdev_io_get_buf() is greater
than the permitted maximum, spdk_bdev_io_get_buf() asserts simply and
doesn't call the specified callback function.
SPDK SCSI library doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
Bdev perf tool also doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
When we support DIF insert and strip in iSCSI target, the read
buffer size iSCSI initiator requests and the read buffer size iSCSI target
requests will become different.
Even after that, iSCSI initiator and iSCSI target will negotiate correctly
not to cause buffer overflow in spdk_bdev_io_get_buf(), but if iSCSI
initiator ignores the result of negotiation, iSCSI initiator can request
read buffer size larger than the permitted maximum, and can cause
failure in iSCSI target. This is very flagile and should be avoided.
This patch do the following
- Add the completion status of spdk_bdev_io_get_buf() to
spdk_bdev_io_get_buf_cb(),
- spdk_bdev_io_get_buf() calls spdk_bdev_io_get_buf_cb() by setting
success to false, and return.
- spdk_bdev_io_get_buf_cb() in each bdev module calls assert if success
is false.
Subsequent patches will process the case that success is false
in spdk_bdev_io_get_buf_cb().
Change-Id: I76429a86e18a69aa085a353ac94743296d270b82
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/446045
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
2019-02-25 00:34:28 +00:00
|
|
|
static void
|
|
|
|
lvol_get_buf_cb(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io, bool success)
|
|
|
|
{
|
2019-02-25 01:43:13 +00:00
|
|
|
if (!success) {
|
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
bdev: Not assert but pass completion status to spdk_bdev_io_get_buf_cb
When the specified buffer size to spdk_bdev_io_get_buf() is greater
than the permitted maximum, spdk_bdev_io_get_buf() asserts simply and
doesn't call the specified callback function.
SPDK SCSI library doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
Bdev perf tool also doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
When we support DIF insert and strip in iSCSI target, the read
buffer size iSCSI initiator requests and the read buffer size iSCSI target
requests will become different.
Even after that, iSCSI initiator and iSCSI target will negotiate correctly
not to cause buffer overflow in spdk_bdev_io_get_buf(), but if iSCSI
initiator ignores the result of negotiation, iSCSI initiator can request
read buffer size larger than the permitted maximum, and can cause
failure in iSCSI target. This is very flagile and should be avoided.
This patch do the following
- Add the completion status of spdk_bdev_io_get_buf() to
spdk_bdev_io_get_buf_cb(),
- spdk_bdev_io_get_buf() calls spdk_bdev_io_get_buf_cb() by setting
success to false, and return.
- spdk_bdev_io_get_buf_cb() in each bdev module calls assert if success
is false.
Subsequent patches will process the case that success is false
in spdk_bdev_io_get_buf_cb().
Change-Id: I76429a86e18a69aa085a353ac94743296d270b82
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/446045
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
2019-02-25 00:34:28 +00:00
|
|
|
|
|
|
|
lvol_read(ch, bdev_io);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
vbdev_lvol_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = bdev_io->bdev->ctxt;
|
|
|
|
|
|
|
|
switch (bdev_io->type) {
|
|
|
|
case SPDK_BDEV_IO_TYPE_READ:
|
bdev: Not assert but pass completion status to spdk_bdev_io_get_buf_cb
When the specified buffer size to spdk_bdev_io_get_buf() is greater
than the permitted maximum, spdk_bdev_io_get_buf() asserts simply and
doesn't call the specified callback function.
SPDK SCSI library doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
Bdev perf tool also doesn't allocate read buffer and specifies
expected read buffer size, and expects that it is allocated by
spdk_bdev_io_get_buf().
When we support DIF insert and strip in iSCSI target, the read
buffer size iSCSI initiator requests and the read buffer size iSCSI target
requests will become different.
Even after that, iSCSI initiator and iSCSI target will negotiate correctly
not to cause buffer overflow in spdk_bdev_io_get_buf(), but if iSCSI
initiator ignores the result of negotiation, iSCSI initiator can request
read buffer size larger than the permitted maximum, and can cause
failure in iSCSI target. This is very flagile and should be avoided.
This patch do the following
- Add the completion status of spdk_bdev_io_get_buf() to
spdk_bdev_io_get_buf_cb(),
- spdk_bdev_io_get_buf() calls spdk_bdev_io_get_buf_cb() by setting
success to false, and return.
- spdk_bdev_io_get_buf_cb() in each bdev module calls assert if success
is false.
Subsequent patches will process the case that success is false
in spdk_bdev_io_get_buf_cb().
Change-Id: I76429a86e18a69aa085a353ac94743296d270b82
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/446045
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
2019-02-25 00:34:28 +00:00
|
|
|
spdk_bdev_io_get_buf(bdev_io, lvol_get_buf_cb,
|
2017-09-22 20:59:55 +00:00
|
|
|
bdev_io->u.bdev.num_blocks * bdev_io->bdev->blocklen);
|
2017-09-14 14:53:36 +00:00
|
|
|
break;
|
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE:
|
|
|
|
lvol_write(lvol, ch, bdev_io);
|
|
|
|
break;
|
|
|
|
case SPDK_BDEV_IO_TYPE_RESET:
|
|
|
|
lvol_reset(bdev_io);
|
|
|
|
break;
|
|
|
|
case SPDK_BDEV_IO_TYPE_UNMAP:
|
2017-11-15 14:54:28 +00:00
|
|
|
lvol_unmap(lvol, ch, bdev_io);
|
|
|
|
break;
|
2017-09-14 14:53:36 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_WRITE_ZEROES:
|
2017-11-15 14:54:28 +00:00
|
|
|
lvol_write_zeroes(lvol, ch, bdev_io);
|
|
|
|
break;
|
2022-09-05 13:22:18 +00:00
|
|
|
case SPDK_BDEV_IO_TYPE_SEEK_DATA:
|
|
|
|
lvol_seek_data(lvol, bdev_io);
|
|
|
|
break;
|
|
|
|
case SPDK_BDEV_IO_TYPE_SEEK_HOLE:
|
|
|
|
lvol_seek_hole(lvol, bdev_io);
|
|
|
|
break;
|
2017-09-14 14:53:36 +00:00
|
|
|
default:
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "lvol: unsupported I/O type %d\n", bdev_io->type);
|
2017-09-14 14:53:36 +00:00
|
|
|
spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-31 12:44:03 +00:00
|
|
|
static int
|
|
|
|
vbdev_lvol_get_memory_domains(void *ctx, struct spdk_memory_domain **domains, int array_size)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = ctx;
|
|
|
|
struct spdk_bdev *base_bdev;
|
|
|
|
|
|
|
|
base_bdev = lvol->lvol_store->bs_dev->get_base_bdev(lvol->lvol_store->bs_dev);
|
|
|
|
|
|
|
|
return spdk_bdev_get_memory_domains(base_bdev, domains, array_size);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static struct spdk_bdev_fn_table vbdev_lvol_fn_table = {
|
2018-07-23 13:57:02 +00:00
|
|
|
.destruct = vbdev_lvol_unregister,
|
2017-09-14 14:53:36 +00:00
|
|
|
.io_type_supported = vbdev_lvol_io_type_supported,
|
|
|
|
.submit_request = vbdev_lvol_submit_request,
|
|
|
|
.get_io_channel = vbdev_lvol_get_io_channel,
|
2018-02-22 12:48:13 +00:00
|
|
|
.dump_info_json = vbdev_lvol_dump_info_json,
|
2018-04-16 15:28:47 +00:00
|
|
|
.write_config_json = vbdev_lvol_write_config_json,
|
2022-01-31 12:44:03 +00:00
|
|
|
.get_memory_domains = vbdev_lvol_get_memory_domains,
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
2018-08-13 08:42:50 +00:00
|
|
|
static void
|
2020-05-15 16:29:10 +00:00
|
|
|
lvol_destroy_cb(void *cb_arg, int bdeverrno)
|
2018-08-13 08:42:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_create_lvol_disk_destroy_cb(void *cb_arg, int bdeverrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = cb_arg;
|
|
|
|
|
|
|
|
if (bdeverrno < 0) {
|
|
|
|
SPDK_ERRLOG("Could not unregister bdev for lvol %s\n",
|
|
|
|
lvol->unique_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-05-15 16:29:10 +00:00
|
|
|
spdk_lvol_destroy(lvol, lvol_destroy_cb, NULL);
|
2018-08-13 08:42:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_create_lvol_disk_unload_cb(void *cb_arg, int bdeverrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvol *lvol = cb_arg;
|
|
|
|
|
|
|
|
if (bdeverrno < 0) {
|
|
|
|
SPDK_ERRLOG("Could not unregister bdev for lvol %s\n",
|
|
|
|
lvol->unique_id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&lvol->lvol_store->lvols, lvol, link);
|
|
|
|
free(lvol);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_create_lvol_disk(struct spdk_lvol *lvol, bool destroy)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
|
|
|
struct spdk_bdev *bdev;
|
2021-08-11 06:57:23 +00:00
|
|
|
struct lvol_bdev *lvol_bdev;
|
2017-09-14 14:53:36 +00:00
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
2017-09-27 11:18:50 +00:00
|
|
|
uint64_t total_size;
|
2018-01-10 10:02:27 +00:00
|
|
|
unsigned char *alias;
|
2017-11-20 09:31:39 +00:00
|
|
|
int rc;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2022-10-10 21:31:31 +00:00
|
|
|
if (spdk_blob_is_degraded(lvol->blob)) {
|
|
|
|
SPDK_NOTICELOG("lvol %s: blob is degraded: deferring bdev creation\n",
|
|
|
|
lvol->unique_id);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvol->lvol_store);
|
|
|
|
if (lvs_bdev == NULL) {
|
2017-12-21 09:50:52 +00:00
|
|
|
SPDK_ERRLOG("No spdk lvs-bdev pair found for lvol %s\n", lvol->unique_id);
|
2018-08-13 08:42:50 +00:00
|
|
|
return -ENODEV;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:57:23 +00:00
|
|
|
lvol_bdev = calloc(1, sizeof(struct lvol_bdev));
|
|
|
|
if (!lvol_bdev) {
|
2017-09-14 14:53:36 +00:00
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvol bdev\n");
|
2018-08-13 08:42:50 +00:00
|
|
|
return -ENOMEM;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 06:57:23 +00:00
|
|
|
lvol_bdev->lvol = lvol;
|
2021-08-05 10:14:54 +00:00
|
|
|
lvol_bdev->lvs_bdev = lvs_bdev;
|
2021-08-11 06:57:23 +00:00
|
|
|
|
|
|
|
bdev = &lvol_bdev->bdev;
|
2018-08-02 22:51:33 +00:00
|
|
|
bdev->name = lvol->unique_id;
|
2017-09-14 14:53:36 +00:00
|
|
|
bdev->product_name = "Logical Volume";
|
2018-09-12 07:54:32 +00:00
|
|
|
bdev->blocklen = spdk_bs_get_io_unit_size(lvol->lvol_store->blobstore);
|
2018-03-20 23:24:47 +00:00
|
|
|
total_size = spdk_blob_get_num_clusters(lvol->blob) *
|
|
|
|
spdk_bs_get_cluster_size(lvol->lvol_store->blobstore);
|
2017-09-27 11:18:50 +00:00
|
|
|
assert((total_size % bdev->blocklen) == 0);
|
|
|
|
bdev->blockcnt = total_size / bdev->blocklen;
|
2018-03-06 23:54:38 +00:00
|
|
|
bdev->uuid = lvol->uuid;
|
2018-10-24 07:02:31 +00:00
|
|
|
bdev->required_alignment = lvs_bdev->bdev->required_alignment;
|
2018-10-04 14:59:54 +00:00
|
|
|
bdev->split_on_optimal_io_boundary = true;
|
|
|
|
bdev->optimal_io_boundary = spdk_bs_get_cluster_size(lvol->lvol_store->blobstore) / bdev->blocklen;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
bdev->ctxt = lvol;
|
|
|
|
bdev->fn_table = &vbdev_lvol_fn_table;
|
2018-03-06 18:52:46 +00:00
|
|
|
bdev->module = &g_lvol_if;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2022-09-14 09:57:03 +00:00
|
|
|
/* Set default bdev reset waiting time. This value indicates how much
|
|
|
|
* time a reset should wait before forcing a reset down to the underlying
|
|
|
|
* bdev module.
|
|
|
|
* Setting this parameter is mainly to avoid "empty" resets to a shared
|
|
|
|
* bdev that may be used by multiple lvols. */
|
2022-11-14 04:28:38 +00:00
|
|
|
bdev->reset_io_drain_timeout = SPDK_BDEV_RESET_IO_DRAIN_RECOMMENDED_VALUE;
|
2022-09-14 09:57:03 +00:00
|
|
|
|
2019-04-03 12:59:05 +00:00
|
|
|
rc = spdk_bdev_register(bdev);
|
2017-11-20 09:31:39 +00:00
|
|
|
if (rc) {
|
2021-08-11 06:57:23 +00:00
|
|
|
free(lvol_bdev);
|
2018-08-13 08:42:50 +00:00
|
|
|
return rc;
|
2017-11-20 09:31:39 +00:00
|
|
|
}
|
2018-08-13 08:42:50 +00:00
|
|
|
lvol->bdev = bdev;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-01-10 10:02:27 +00:00
|
|
|
alias = spdk_sprintf_alloc("%s/%s", lvs_bdev->lvs->name, lvol->name);
|
|
|
|
if (alias == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for alias\n");
|
2018-08-13 08:42:50 +00:00
|
|
|
spdk_bdev_unregister(lvol->bdev, (destroy ? _create_lvol_disk_destroy_cb :
|
|
|
|
_create_lvol_disk_unload_cb), lvol);
|
|
|
|
return -ENOMEM;
|
2018-01-10 10:02:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_bdev_alias_add(bdev, alias);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Cannot add alias to lvol bdev\n");
|
2018-08-13 08:42:50 +00:00
|
|
|
spdk_bdev_unregister(lvol->bdev, (destroy ? _create_lvol_disk_destroy_cb :
|
|
|
|
_create_lvol_disk_unload_cb), lvol);
|
2018-01-10 10:02:27 +00:00
|
|
|
}
|
|
|
|
free(alias);
|
|
|
|
|
2018-08-13 08:42:50 +00:00
|
|
|
return rc;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_vbdev_lvol_create_cb(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
|
|
|
|
{
|
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
|
|
|
|
|
|
|
if (lvolerrno < 0) {
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:42:50 +00:00
|
|
|
lvolerrno = _create_lvol_disk(lvol, true);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
end:
|
2017-09-19 14:09:43 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvol, lvolerrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2018-04-09 20:29:34 +00:00
|
|
|
vbdev_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)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_with_handle_req *req;
|
2017-09-14 14:53:36 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
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
|
|
|
|
2019-01-22 08:47:24 +00:00
|
|
|
rc = spdk_lvol_create(lvs, name, sz, thin_provision, clear_method,
|
|
|
|
_vbdev_lvol_create_cb, req);
|
2017-09-21 11:19:22 +00:00
|
|
|
if (rc != 0) {
|
|
|
|
free(req);
|
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2018-02-22 12:29:49 +00:00
|
|
|
void
|
|
|
|
vbdev_lvol_create_snapshot(struct spdk_lvol *lvol, const char *snapshot_name,
|
|
|
|
spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_lvol_create_snapshot(lvol, snapshot_name, _vbdev_lvol_create_cb, req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvol_create_clone(struct spdk_lvol *lvol, const char *clone_name,
|
|
|
|
spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_lvol_create_clone(lvol, clone_name, _vbdev_lvol_create_cb, req);
|
|
|
|
}
|
|
|
|
|
2023-01-27 04:49:19 +00:00
|
|
|
static void
|
|
|
|
ignore_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev, void *ctx)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2022-01-24 05:15:09 +00:00
|
|
|
vbdev_lvol_create_bdev_clone(const char *esnap_name,
|
2023-01-27 04:49:19 +00:00
|
|
|
struct spdk_lvol_store *lvs, const char *clone_name,
|
|
|
|
spdk_lvol_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_with_handle_req *req;
|
|
|
|
struct spdk_bdev_desc *desc;
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
char bdev_uuid[SPDK_UUID_STRING_LEN];
|
|
|
|
uint64_t sz;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (lvs == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol store not specified\n");
|
|
|
|
cb_fn(cb_arg, NULL, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-24 05:15:09 +00:00
|
|
|
rc = spdk_bdev_open_ext(esnap_name, false, ignore_bdev_event_cb, NULL, &desc);
|
2023-01-27 04:49:19 +00:00
|
|
|
if (rc != 0) {
|
2022-01-24 05:15:09 +00:00
|
|
|
SPDK_ERRLOG("bdev '%s' could not be opened: error %d\n", esnap_name, rc);
|
2023-01-27 04:49:19 +00:00
|
|
|
cb_fn(cb_arg, NULL, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bdev = spdk_bdev_desc_get_bdev(desc);
|
|
|
|
|
|
|
|
rc = spdk_uuid_fmt_lower(bdev_uuid, sizeof(bdev_uuid), spdk_bdev_get_uuid(bdev));
|
|
|
|
if (rc != 0) {
|
|
|
|
spdk_bdev_close(desc);
|
2022-01-24 05:15:09 +00:00
|
|
|
SPDK_ERRLOG("bdev %s: unable to parse UUID\n", esnap_name);
|
2023-01-27 04:49:19 +00:00
|
|
|
assert(false);
|
|
|
|
cb_fn(cb_arg, NULL, -ENODEV);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
spdk_bdev_close(desc);
|
|
|
|
cb_fn(cb_arg, NULL, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
sz = spdk_bdev_get_num_blocks(bdev) * spdk_bdev_get_block_size(bdev);
|
|
|
|
rc = spdk_lvol_create_esnap_clone(bdev_uuid, sizeof(bdev_uuid), sz, lvs, clone_name,
|
|
|
|
_vbdev_lvol_create_cb, req);
|
|
|
|
spdk_bdev_close(desc);
|
|
|
|
if (rc != 0) {
|
|
|
|
cb_fn(cb_arg, NULL, rc);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-10 10:02:27 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvol_rename_cb(void *cb_arg, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("Renaming lvol failed\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvol_rename(struct spdk_lvol *lvol, const char *new_lvol_name,
|
|
|
|
spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = _vbdev_lvol_change_bdev_alias(lvol, new_lvol_name);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("renaming lvol to '%s' does not succeed\n", new_lvol_name);
|
|
|
|
cb_fn(cb_arg, rc);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
|
|
|
|
spdk_lvol_rename(lvol, new_lvol_name, _vbdev_lvol_rename_cb, req);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvol_resize_cb(void *cb_arg, int lvolerrno)
|
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
2018-02-07 10:02:09 +00:00
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
|
|
|
uint64_t total_size;
|
2018-03-19 21:05:44 +00:00
|
|
|
|
2018-02-07 10:02:09 +00:00
|
|
|
/* change bdev size */
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("CB function for bdev lvol %s receive error no: %d.\n", lvol->name, lvolerrno);
|
|
|
|
goto finish;
|
2018-03-19 21:05:44 +00:00
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-02-07 10:02:09 +00:00
|
|
|
total_size = spdk_blob_get_num_clusters(lvol->blob) *
|
|
|
|
spdk_bs_get_cluster_size(lvol->lvol_store->blobstore);
|
|
|
|
assert((total_size % lvol->bdev->blocklen) == 0);
|
|
|
|
|
|
|
|
lvolerrno = spdk_bdev_notify_blockcnt_change(lvol->bdev, total_size / lvol->bdev->blocklen);
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("Could not change num blocks for bdev lvol %s with error no: %d.\n",
|
|
|
|
lvol->name, lvolerrno);
|
|
|
|
}
|
|
|
|
|
|
|
|
finish:
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
2017-09-14 14:53:36 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
2018-02-07 10:02:09 +00:00
|
|
|
void
|
2018-04-09 20:29:34 +00:00
|
|
|
vbdev_lvol_resize(struct spdk_lvol *lvol, uint64_t sz, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2017-09-19 14:09:43 +00:00
|
|
|
struct spdk_lvol_req *req;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (lvol == NULL) {
|
2018-02-07 10:02:09 +00:00
|
|
|
SPDK_ERRLOG("lvol does not exist\n");
|
|
|
|
cb_fn(cb_arg, -EINVAL);
|
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 10:02:09 +00:00
|
|
|
assert(lvol->bdev != NULL);
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
2018-02-07 10:02:09 +00:00
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
2018-02-07 10:02:09 +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->sz = sz;
|
|
|
|
req->lvol = lvol;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2018-02-07 10:02:09 +00:00
|
|
|
spdk_lvol_resize(req->lvol, req->sz, _vbdev_lvol_resize_cb, req);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2019-01-15 15:31:05 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvol_set_read_only_cb(void *cb_arg, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req = cb_arg;
|
|
|
|
struct spdk_lvol *lvol = req->lvol;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("Could not set bdev lvol %s as read only due to error: %d.\n", lvol->name, lvolerrno);
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn(req->cb_arg, lvolerrno);
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvol_set_read_only(struct spdk_lvol *lvol, spdk_lvol_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_req *req;
|
|
|
|
|
|
|
|
if (lvol == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol does not exist\n");
|
|
|
|
cb_fn(cb_arg, -EINVAL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(lvol->bdev != NULL);
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
|
|
|
req->lvol = lvol;
|
|
|
|
|
|
|
|
spdk_lvol_set_read_only(lvol, _vbdev_lvol_set_read_only_cb, req);
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static int
|
|
|
|
vbdev_lvs_init(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-08-04 12:56:37 +00:00
|
|
|
static void vbdev_lvs_fini_start_iter(struct lvol_store_bdev *lvs_bdev);
|
|
|
|
|
|
|
|
static void
|
|
|
|
vbdev_lvs_fini_start_unload_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev = cb_arg;
|
|
|
|
struct lvol_store_bdev *next_lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store removed with error: %d.\n", lvserrno);
|
|
|
|
}
|
|
|
|
|
|
|
|
TAILQ_REMOVE(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
|
|
|
free(lvs_bdev);
|
|
|
|
|
|
|
|
vbdev_lvs_fini_start_iter(next_lvs_bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vbdev_lvs_fini_start_iter(struct lvol_store_bdev *lvs_bdev)
|
|
|
|
{
|
|
|
|
struct spdk_lvol_store *lvs;
|
|
|
|
|
|
|
|
while (lvs_bdev != NULL) {
|
|
|
|
lvs = lvs_bdev->lvs;
|
|
|
|
|
|
|
|
if (_vbdev_lvs_are_lvols_closed(lvs)) {
|
|
|
|
spdk_lvs_unload(lvs, vbdev_lvs_fini_start_unload_cb, lvs_bdev);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_bdev_module_fini_start_done();
|
|
|
|
}
|
|
|
|
|
2021-08-05 10:14:54 +00:00
|
|
|
static void
|
|
|
|
vbdev_lvs_fini_start(void)
|
|
|
|
{
|
|
|
|
g_shutdown_started = true;
|
2021-08-04 12:56:37 +00:00
|
|
|
vbdev_lvs_fini_start_iter(vbdev_lvol_store_first());
|
2021-08-05 10:14:54 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static int
|
|
|
|
vbdev_lvs_get_ctx_size(void)
|
|
|
|
{
|
2022-01-31 12:10:53 +00:00
|
|
|
return sizeof(struct vbdev_lvol_io);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_examine_done(struct spdk_lvs_req *req, int lvserrno)
|
|
|
|
{
|
|
|
|
req->cb_fn(req->cb_arg, lvserrno);
|
|
|
|
}
|
|
|
|
|
2018-07-18 11:07:33 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_examine_failed(void *cb_arg, int lvserrno)
|
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
|
|
|
|
_vbdev_lvs_examine_done(req, req->lvserrno);
|
2018-07-18 11:07:33 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
2017-10-19 15:30:32 +00:00
|
|
|
_vbdev_lvs_examine_finish(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
|
2017-09-14 14:53:36 +00:00
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_req *req = cb_arg;
|
|
|
|
struct spdk_lvol_store *lvs = req->lvol_store;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
TAILQ_REMOVE(&lvs->lvols, lvol, link);
|
2023-02-21 15:30:17 +00:00
|
|
|
if (lvolerrno == -ENOMEM) {
|
|
|
|
TAILQ_INSERT_TAIL(&lvs->retry_open_lvols, lvol, link);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SPDK_ERRLOG("Error opening lvol %s\n", lvol->unique_id);
|
2017-10-19 15:30:32 +00:00
|
|
|
lvs->lvol_count--;
|
|
|
|
free(lvol);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2018-08-13 08:42:50 +00:00
|
|
|
if (_create_lvol_disk(lvol, false)) {
|
2017-12-21 09:50:52 +00:00
|
|
|
SPDK_ERRLOG("Cannot create bdev for lvol %s\n", lvol->unique_id);
|
2017-10-19 15:30:32 +00:00
|
|
|
lvs->lvol_count--;
|
2023-02-22 12:38:41 +00:00
|
|
|
goto end;
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lvs->lvols_opened++;
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Opening lvol %s succeeded\n", lvol->unique_id);
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
end:
|
2023-02-21 15:30:17 +00:00
|
|
|
if (!TAILQ_EMPTY(&lvs->retry_open_lvols)) {
|
|
|
|
lvol = TAILQ_FIRST(&lvs->retry_open_lvols);
|
|
|
|
TAILQ_REMOVE(&lvs->retry_open_lvols, lvol, link);
|
|
|
|
TAILQ_INSERT_HEAD(&lvs->lvols, lvol, link);
|
|
|
|
spdk_lvol_open(lvol, _vbdev_lvs_examine_finish, req);
|
|
|
|
return;
|
|
|
|
}
|
2017-10-19 15:30:32 +00:00
|
|
|
if (lvs->lvols_opened >= lvs->lvol_count) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Opening lvols finished\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(req, 0);
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2023-01-30 18:13:06 +00:00
|
|
|
/* Walks a tree of clones that are no longer degraded to create bdevs. */
|
|
|
|
static int
|
|
|
|
create_esnap_clone_lvol_disks(void *ctx, struct spdk_lvol *lvol)
|
|
|
|
{
|
|
|
|
struct spdk_bdev *bdev = ctx;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = _create_lvol_disk(lvol, false);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("lvol %s: failed to create bdev after esnap hotplug of %s: %d\n",
|
|
|
|
lvol->unique_id, spdk_bdev_get_name(bdev), rc);
|
|
|
|
/* Do not prevent creation of other clones in case of one failure. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return spdk_lvol_iter_immediate_clones(lvol, create_esnap_clone_lvol_disks, ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vbdev_lvs_hotplug(void *ctx, struct spdk_lvol *lvol, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct spdk_bdev *esnap_clone_bdev = ctx;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
SPDK_ERRLOG("lvol %s: during examine of bdev %s: not creating clone bdev due to "
|
|
|
|
"error %d\n", lvol->unique_id, spdk_bdev_get_name(esnap_clone_bdev),
|
|
|
|
lvolerrno);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
create_esnap_clone_lvol_disks(esnap_clone_bdev, lvol);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vbdev_lvs_examine_config(struct spdk_bdev *bdev)
|
|
|
|
{
|
|
|
|
char uuid_str[SPDK_UUID_STRING_LEN];
|
|
|
|
|
|
|
|
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &bdev->uuid);
|
|
|
|
|
|
|
|
if (spdk_lvs_notify_hotplug(uuid_str, sizeof(uuid_str), vbdev_lvs_hotplug, bdev)) {
|
|
|
|
SPDK_INFOLOG(vbdev_lvol, "bdev %s: claimed by one ore more esnap clones\n",
|
|
|
|
uuid_str);
|
|
|
|
}
|
|
|
|
spdk_bdev_module_examine_done(&g_lvol_if);
|
|
|
|
}
|
|
|
|
|
2017-10-19 15:30:32 +00:00
|
|
|
static void
|
|
|
|
_vbdev_lvs_examine_cb(void *arg, struct spdk_lvol_store *lvol_store, int lvserrno)
|
|
|
|
{
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
struct spdk_lvs_with_handle_req *req = (struct spdk_lvs_with_handle_req *)arg;
|
|
|
|
struct spdk_lvol *lvol, *tmp;
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_req *ori_req = req->cb_arg;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2017-10-27 13:47:34 +00:00
|
|
|
if (lvserrno == -EEXIST) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol,
|
2017-10-27 13:47:34 +00:00
|
|
|
"Name for lvolstore on device %s conflicts with name for already loaded lvs\n",
|
|
|
|
req->base_bdev->name);
|
2018-07-18 11:07:33 +00:00
|
|
|
/* On error blobstore destroys bs_dev itself */
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(ori_req, lvserrno);
|
2017-10-27 13:47:34 +00:00
|
|
|
goto end;
|
|
|
|
} else if (lvserrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store not found on %s\n", req->base_bdev->name);
|
2018-07-18 11:07:33 +00:00
|
|
|
/* On error blobstore destroys bs_dev itself */
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(ori_req, lvserrno);
|
2017-10-19 15:30:32 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2018-03-06 18:52:46 +00:00
|
|
|
lvserrno = spdk_bs_bdev_claim(lvol_store->bs_dev, &g_lvol_if);
|
2017-10-19 15:30:32 +00:00
|
|
|
if (lvserrno != 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store base bdev already claimed by another bdev\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
ori_req->lvserrno = lvserrno;
|
|
|
|
spdk_lvs_unload(lvol_store, _vbdev_lvs_examine_failed, ori_req);
|
2017-10-19 15:30:32 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs_bdev = calloc(1, sizeof(*lvs_bdev));
|
|
|
|
if (!lvs_bdev) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for lvs_bdev\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
ori_req->lvserrno = lvserrno;
|
|
|
|
spdk_lvs_unload(lvol_store, _vbdev_lvs_examine_failed, ori_req);
|
2017-10-19 15:30:32 +00:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs_bdev->lvs = lvol_store;
|
|
|
|
lvs_bdev->bdev = req->base_bdev;
|
|
|
|
|
|
|
|
TAILQ_INSERT_TAIL(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store found on %s - begin parsing\n",
|
2017-10-19 15:30:32 +00:00
|
|
|
req->base_bdev->name);
|
|
|
|
|
|
|
|
lvol_store->lvols_opened = 0;
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
ori_req->lvol_store = lvol_store;
|
|
|
|
|
2017-11-21 11:19:33 +00:00
|
|
|
if (TAILQ_EMPTY(&lvol_store->lvols)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Lvol store examination done\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(ori_req, 0);
|
2017-11-21 11:19:33 +00:00
|
|
|
} else {
|
|
|
|
/* Open all lvols */
|
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvol_store->lvols, link, tmp) {
|
2023-02-23 12:12:48 +00:00
|
|
|
spdk_lvol_open(lvol, _vbdev_lvs_examine_finish, ori_req);
|
2017-11-21 11:19:33 +00:00
|
|
|
}
|
2017-10-19 15:30:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine(struct spdk_bdev *bdev, struct spdk_lvs_req *ori_req,
|
|
|
|
void (*action)(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg))
|
2017-10-19 15:30:32 +00:00
|
|
|
{
|
|
|
|
struct spdk_bs_dev *bs_dev;
|
|
|
|
struct spdk_lvs_with_handle_req *req;
|
2020-10-14 16:34:23 +00:00
|
|
|
int rc;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(ori_req, -ENOMEM);
|
2017-10-19 15:30:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-14 16:34:23 +00:00
|
|
|
rc = spdk_bdev_create_bs_dev_ext(bdev->name, vbdev_lvs_base_bdev_event_cb,
|
|
|
|
NULL, &bs_dev);
|
|
|
|
if (rc < 0) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Cannot create bs dev on %s\n", bdev->name);
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_examine_done(ori_req, rc);
|
2017-10-19 15:30:32 +00:00
|
|
|
free(req);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->base_bdev = bdev;
|
2023-02-23 12:12:48 +00:00
|
|
|
req->cb_arg = ori_req;
|
2017-10-19 15:30:32 +00:00
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
action(bs_dev, _vbdev_lvs_examine_cb, req);
|
2018-02-02 10:23:39 +00:00
|
|
|
}
|
|
|
|
|
2021-10-05 03:28:38 +00:00
|
|
|
static void
|
2023-02-23 12:12:48 +00:00
|
|
|
vbdev_lvs_examine_done(void *arg, int lvserrno)
|
2021-10-05 03:28:38 +00:00
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_req *req = arg;
|
|
|
|
|
|
|
|
spdk_bdev_module_examine_done(&g_lvol_if);
|
2021-10-05 03:28:38 +00:00
|
|
|
free(req);
|
|
|
|
}
|
|
|
|
|
2023-01-26 21:52:52 +00:00
|
|
|
static void
|
|
|
|
vbdev_lvs_load(struct spdk_bs_dev *bs_dev, spdk_lvs_op_with_handle_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_opts lvs_opts;
|
|
|
|
|
|
|
|
spdk_lvs_opts_init(&lvs_opts);
|
|
|
|
lvs_opts.esnap_bs_dev_create = vbdev_lvol_esnap_dev_create;
|
|
|
|
spdk_lvs_load_ext(bs_dev, &lvs_opts, cb_fn, cb_arg);
|
|
|
|
}
|
|
|
|
|
2021-10-05 03:28:38 +00:00
|
|
|
static void
|
2023-01-30 18:13:06 +00:00
|
|
|
vbdev_lvs_examine_disk(struct spdk_bdev *bdev)
|
2021-10-05 03:28:38 +00:00
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_req *req;
|
2021-10-05 03:28:38 +00:00
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
if (spdk_bdev_get_md_size(bdev) != 0) {
|
|
|
|
SPDK_INFOLOG(vbdev_lvol, "Cannot create bs dev on %s\n which is formatted with metadata",
|
|
|
|
bdev->name);
|
|
|
|
spdk_bdev_module_examine_done(&g_lvol_if);
|
|
|
|
return;
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (req == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
|
|
|
spdk_bdev_module_examine_done(&g_lvol_if);
|
|
|
|
return;
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
req->cb_fn = vbdev_lvs_examine_done;
|
|
|
|
req->cb_arg = req;
|
2021-10-05 03:28:38 +00:00
|
|
|
|
2023-01-26 21:52:52 +00:00
|
|
|
_vbdev_lvs_examine(bdev, req, vbdev_lvs_load);
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvol *
|
|
|
|
vbdev_lvol_get_from_bdev(struct spdk_bdev *bdev)
|
2021-10-05 03:28:38 +00:00
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
if (!bdev || bdev->module != &g_lvol_if) {
|
|
|
|
return NULL;
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
if (bdev->ctxt == NULL) {
|
|
|
|
SPDK_ERRLOG("No lvol ctx assigned to bdev %s\n", bdev->name);
|
|
|
|
return NULL;
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
return (struct spdk_lvol *)bdev->ctxt;
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_grow_finish(void *arg, int lvserrno)
|
2021-10-05 03:28:38 +00:00
|
|
|
{
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvs_grow_req *req = arg;
|
2021-10-05 03:28:38 +00:00
|
|
|
|
2023-02-23 12:12:48 +00:00
|
|
|
req->cb_fn(req->cb_arg, lvserrno);
|
|
|
|
free(req);
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_vbdev_lvs_grow_unload_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_grow_req *req = cb_arg;
|
|
|
|
struct lvol_store_bdev *lvs_bdev;
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_grow_finish(req, lvserrno);
|
2021-10-05 03:28:38 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
lvs_bdev = req->lvs_bdev;
|
|
|
|
bdev = lvs_bdev->bdev;
|
|
|
|
TAILQ_REMOVE(&g_spdk_lvol_pairs, lvs_bdev, lvol_stores);
|
2023-02-23 12:12:48 +00:00
|
|
|
req->base.cb_fn = _vbdev_lvs_grow_finish;
|
|
|
|
req->base.cb_arg = req;
|
|
|
|
_vbdev_lvs_examine(bdev, &req->base, spdk_lvs_grow);
|
2021-10-05 03:28:38 +00:00
|
|
|
free(lvs_bdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_vbdev_lvs_grow_remove_bdev_unregistered_cb(void *cb_arg, int bdeverrno)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_grow_req *req = cb_arg;
|
2023-02-23 12:12:48 +00:00
|
|
|
struct spdk_lvol_store *lvs = req->base.lvol_store;
|
2021-10-05 03:28:38 +00:00
|
|
|
|
|
|
|
if (bdeverrno != 0) {
|
|
|
|
SPDK_DEBUGLOG(vbdev_lvol, "Lvol unregistered with errno %d\n", bdeverrno);
|
|
|
|
}
|
|
|
|
|
|
|
|
req->lvol_cnt--;
|
|
|
|
|
|
|
|
if (req->lvol_cnt == 0) {
|
|
|
|
/* Lvol store can be unloaded once all lvols are closed. */
|
|
|
|
if (_vbdev_lvs_are_lvols_closed(lvs)) {
|
|
|
|
spdk_lvs_unload(lvs, _vbdev_lvs_grow_unload_cb, req);
|
|
|
|
} else {
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_grow_finish(req, -EINVAL);
|
2021-10-05 03:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
vbdev_lvs_grow(struct spdk_lvol_store *lvs,
|
|
|
|
spdk_lvs_op_complete cb_fn, void *cb_arg)
|
|
|
|
{
|
|
|
|
struct spdk_lvs_grow_req *req;
|
|
|
|
struct spdk_lvol *lvol, *tmp;
|
|
|
|
|
|
|
|
req = calloc(1, sizeof(*req));
|
|
|
|
if (!req) {
|
|
|
|
SPDK_ERRLOG("Cannot alloc memory for vbdev lvol store request pointer\n");
|
|
|
|
cb_fn(cb_arg, -ENOMEM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req->cb_fn = cb_fn;
|
|
|
|
req->cb_arg = cb_arg;
|
2023-02-23 12:12:48 +00:00
|
|
|
req->base.lvol_store = lvs;
|
2021-10-05 03:28:38 +00:00
|
|
|
req->lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvs);
|
2022-11-29 02:39:28 +00:00
|
|
|
if (req->lvs_bdev == NULL) {
|
|
|
|
SPDK_ERRLOG("Cannot get valid lvs_bdev\n");
|
2023-02-23 12:12:48 +00:00
|
|
|
_vbdev_lvs_grow_finish(req, -EINVAL);
|
2022-11-29 02:39:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-10-05 03:28:38 +00:00
|
|
|
|
|
|
|
if (_vbdev_lvs_are_lvols_closed(lvs)) {
|
|
|
|
spdk_lvs_unload(lvs, _vbdev_lvs_grow_unload_cb, req);
|
|
|
|
} else {
|
|
|
|
TAILQ_FOREACH_SAFE(lvol, &lvs->lvols, link, tmp) {
|
|
|
|
req->lvol_cnt++;
|
|
|
|
spdk_bdev_unregister(lvol->bdev, _vbdev_lvs_grow_remove_bdev_unregistered_cb, req);
|
|
|
|
}
|
|
|
|
assert(req->lvol_cnt > 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-10 21:31:31 +00:00
|
|
|
/* Begin degraded blobstore device */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When an external snapshot is missing, an instance of bs_dev_degraded is used as the blob's
|
|
|
|
* back_bs_dev. No bdev is registered, so there should be no IO nor requests for channels. The main
|
|
|
|
* purposes of this device are to prevent blobstore from hitting fatal runtime errors and to
|
|
|
|
* indicate that the blob is degraded via the is_degraded() callback.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
bs_dev_degraded_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
|
|
|
|
uint64_t lba, uint32_t lba_count, struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bs_dev_degraded_readv(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bs_dev_degraded_readv_ext(struct spdk_bs_dev *dev, struct spdk_io_channel *channel,
|
|
|
|
struct iovec *iov, int iovcnt, uint64_t lba, uint32_t lba_count,
|
|
|
|
struct spdk_bs_dev_cb_args *cb_args,
|
|
|
|
struct spdk_blob_ext_io_opts *io_opts)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, -EIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
bs_dev_degraded_is_zeroes(struct spdk_bs_dev *dev, uint64_t lba, uint64_t lba_count)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_io_channel *
|
|
|
|
bs_dev_degraded_create_channel(struct spdk_bs_dev *bs_dev)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bs_dev_degraded_destroy_channel(struct spdk_bs_dev *bs_dev, struct spdk_io_channel *channel)
|
|
|
|
{
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bs_dev_degraded_destroy(struct spdk_bs_dev *bs_dev)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
bs_dev_degraded_is_degraded(struct spdk_bs_dev *bs_dev)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct spdk_bs_dev bs_dev_degraded = {
|
|
|
|
.create_channel = bs_dev_degraded_create_channel,
|
|
|
|
.destroy_channel = bs_dev_degraded_destroy_channel,
|
|
|
|
.destroy = bs_dev_degraded_destroy,
|
|
|
|
.read = bs_dev_degraded_read,
|
|
|
|
.readv = bs_dev_degraded_readv,
|
|
|
|
.readv_ext = bs_dev_degraded_readv_ext,
|
|
|
|
.is_zeroes = bs_dev_degraded_is_zeroes,
|
|
|
|
.is_degraded = bs_dev_degraded_is_degraded,
|
|
|
|
/* Make the device as large as possible without risk of uint64 overflow. */
|
|
|
|
.blockcnt = UINT64_MAX / 512,
|
|
|
|
/* Prevent divide by zero errors calculating LBAs that will never be read. */
|
|
|
|
.blocklen = 512,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* End degraded blobstore device */
|
|
|
|
|
2023-01-26 21:52:52 +00:00
|
|
|
/* Begin external snapshot support */
|
|
|
|
|
|
|
|
static void
|
|
|
|
vbdev_lvol_esnap_bdev_event_cb(enum spdk_bdev_event_type type, struct spdk_bdev *bdev,
|
|
|
|
void *event_ctx)
|
|
|
|
{
|
|
|
|
SPDK_NOTICELOG("bdev name (%s) received unsupported event type %d\n",
|
|
|
|
spdk_bdev_get_name(bdev), type);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
vbdev_lvol_esnap_dev_create(void *bs_ctx, void *blob_ctx, struct spdk_blob *blob,
|
|
|
|
const void *esnap_id, uint32_t id_len,
|
|
|
|
struct spdk_bs_dev **_bs_dev)
|
|
|
|
{
|
2022-10-10 21:31:31 +00:00
|
|
|
struct spdk_lvol_store *lvs = bs_ctx;
|
2023-01-26 21:52:52 +00:00
|
|
|
struct spdk_lvol *lvol = blob_ctx;
|
|
|
|
struct spdk_bs_dev *bs_dev = NULL;
|
|
|
|
struct spdk_uuid uuid;
|
|
|
|
int rc;
|
|
|
|
char uuid_str[SPDK_UUID_STRING_LEN] = { 0 };
|
|
|
|
|
|
|
|
if (esnap_id == NULL) {
|
|
|
|
SPDK_ERRLOG("lvol %s: NULL esnap ID\n", lvol->unique_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Guard against arbitrary names and unterminated UUID strings */
|
|
|
|
if (id_len != SPDK_UUID_STRING_LEN) {
|
|
|
|
SPDK_ERRLOG("lvol %s: Invalid esnap ID length (%u)\n", lvol->unique_id, id_len);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (spdk_uuid_parse(&uuid, esnap_id)) {
|
|
|
|
SPDK_ERRLOG("lvol %s: Invalid esnap ID: not a UUID\n", lvol->unique_id);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Format the UUID the same as it is in the bdev names tree. */
|
|
|
|
spdk_uuid_fmt_lower(uuid_str, sizeof(uuid_str), &uuid);
|
|
|
|
if (strcmp(uuid_str, esnap_id) != 0) {
|
|
|
|
SPDK_WARNLOG("lvol %s: esnap_id '%*s' does not match parsed uuid '%s'\n",
|
|
|
|
lvol->unique_id, SPDK_UUID_STRING_LEN, (const char *)esnap_id,
|
|
|
|
uuid_str);
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = spdk_bdev_create_bs_dev(uuid_str, false, NULL, 0,
|
|
|
|
vbdev_lvol_esnap_bdev_event_cb, NULL, &bs_dev);
|
|
|
|
if (rc != 0) {
|
2022-10-10 21:31:31 +00:00
|
|
|
goto fail;
|
2023-01-26 21:52:52 +00:00
|
|
|
}
|
2022-10-10 21:31:31 +00:00
|
|
|
|
2023-01-26 21:52:52 +00:00
|
|
|
rc = spdk_bs_bdev_claim(bs_dev, &g_lvol_if);
|
|
|
|
if (rc != 0) {
|
2022-10-10 21:31:31 +00:00
|
|
|
SPDK_ERRLOG("lvol %s: unable to claim esnap bdev '%s': %d\n", lvol->unique_id,
|
|
|
|
uuid_str, rc);
|
2023-01-26 21:52:52 +00:00
|
|
|
bs_dev->destroy(bs_dev);
|
2022-10-10 21:31:31 +00:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
*_bs_dev = bs_dev;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
/* Unable to open or claim the bdev. This lvol is degraded. */
|
|
|
|
bs_dev = &bs_dev_degraded;
|
|
|
|
SPDK_NOTICELOG("lvol %s: bdev %s not available: lvol is degraded\n", lvol->unique_id,
|
|
|
|
uuid_str);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Be sure not to call spdk_lvs_missing_add() on an lvol that is already degraded. This can
|
|
|
|
* lead to a cycle in the degraded_lvols tailq.
|
|
|
|
*/
|
|
|
|
if (lvol->degraded_set == NULL) {
|
|
|
|
rc = spdk_lvs_esnap_missing_add(lvs, lvol, uuid_str, sizeof(uuid_str));
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_NOTICELOG("lvol %s: unable to register missing esnap device %s: "
|
|
|
|
"it will not be hotplugged if added later\n",
|
|
|
|
lvol->unique_id, uuid_str);
|
|
|
|
}
|
2023-01-26 21:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*_bs_dev = bs_dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* End external snapshot support */
|
|
|
|
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT(vbdev_lvol)
|