2017-09-14 14:53:36 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
|
|
|
* Copyright (c) Intel Corporation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* * Neither the name of Intel Corporation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/rpc.h"
|
|
|
|
#include "spdk/bdev.h"
|
|
|
|
#include "spdk/util.h"
|
|
|
|
#include "vbdev_lvol.h"
|
|
|
|
#include "spdk/string.h"
|
|
|
|
#include "spdk_internal/log.h"
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_LOG_REGISTER_COMPONENT("lvolrpc", SPDK_LOG_LVOL_RPC)
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
struct rpc_construct_lvol_store {
|
2017-10-27 13:12:38 +00:00
|
|
|
char *lvs_name;
|
|
|
|
char *bdev_name;
|
2017-09-29 07:46:50 +00:00
|
|
|
uint32_t cluster_sz;
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
static int
|
|
|
|
vbdev_get_lvol_store_by_uuid_xor_name(const char *uuid, const char *lvs_name,
|
|
|
|
struct spdk_lvol_store **lvs)
|
|
|
|
{
|
|
|
|
if ((uuid == NULL && lvs_name == NULL)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "lvs UUID nor lvs name specified\n");
|
2017-10-27 13:12:38 +00:00
|
|
|
return -EINVAL;
|
|
|
|
} else if ((uuid && lvs_name)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "both lvs UUID '%s' and lvs name '%s' specified\n", uuid,
|
2017-10-27 13:12:38 +00:00
|
|
|
lvs_name);
|
|
|
|
return -EINVAL;
|
|
|
|
} else if (uuid) {
|
2017-11-30 18:16:37 +00:00
|
|
|
*lvs = vbdev_get_lvol_store_by_uuid(uuid);
|
2017-10-27 13:12:38 +00:00
|
|
|
|
|
|
|
if (*lvs == NULL) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "blobstore with UUID '%s' not found\n", uuid);
|
2017-10-27 13:12:38 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
} else if (lvs_name) {
|
|
|
|
|
|
|
|
*lvs = vbdev_get_lvol_store_by_name(lvs_name);
|
|
|
|
|
|
|
|
if (*lvs == NULL) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "blobstore with name '%s' not found\n", lvs_name);
|
2017-10-27 13:12:38 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-14 14:53:36 +00:00
|
|
|
static void
|
|
|
|
free_rpc_construct_lvol_store(struct rpc_construct_lvol_store *req)
|
|
|
|
{
|
2017-10-27 13:12:38 +00:00
|
|
|
free(req->bdev_name);
|
|
|
|
free(req->lvs_name);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_construct_lvol_store_decoders[] = {
|
2017-10-27 13:12:38 +00:00
|
|
|
{"bdev_name", offsetof(struct rpc_construct_lvol_store, bdev_name), spdk_json_decode_string},
|
2017-09-29 07:46:50 +00:00
|
|
|
{"cluster_sz", offsetof(struct rpc_construct_lvol_store, cluster_sz), spdk_json_decode_uint32, true},
|
2017-10-27 13:12:38 +00:00
|
|
|
{"lvs_name", offsetof(struct rpc_construct_lvol_store, lvs_name), spdk_json_decode_string},
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_rpc_lvol_store_construct_cb(void *cb_arg, struct spdk_lvol_store *lvol_store, int lvserrno)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
2017-09-18 08:49:22 +00:00
|
|
|
char lvol_store_uuid[UUID_STRING_LEN];
|
2017-09-14 14:53:36 +00:00
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
uuid_unparse(lvol_store->uuid, lvol_store_uuid);
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_begin(w);
|
|
|
|
spdk_json_write_string(w, lvol_store_uuid);
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-lvserrno));
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_construct_lvol_store(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_construct_lvol_store req = {};
|
|
|
|
struct spdk_bdev *bdev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_construct_lvol_store_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_construct_lvol_store_decoders),
|
|
|
|
&req)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "spdk_json_decode_object failed\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
if (req.bdev_name == NULL) {
|
|
|
|
SPDK_ERRLOG("missing bdev_name param\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
if (req.lvs_name == NULL) {
|
|
|
|
SPDK_ERRLOG("missing lvs_name param\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
bdev = spdk_bdev_get_by_name(req.bdev_name);
|
2017-09-14 14:53:36 +00:00
|
|
|
if (bdev == NULL) {
|
2017-10-27 13:12:38 +00:00
|
|
|
SPDK_ERRLOG("bdev '%s' does not exist\n", req.bdev_name);
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
rc = vbdev_lvs_create(bdev, req.lvs_name, req.cluster_sz, _spdk_rpc_lvol_store_construct_cb,
|
|
|
|
request);
|
2017-09-14 14:53:36 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
free_rpc_construct_lvol_store(&req);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-09-14 14:53:36 +00:00
|
|
|
free_rpc_construct_lvol_store(&req);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("construct_lvol_store", spdk_rpc_construct_lvol_store)
|
|
|
|
|
|
|
|
struct rpc_destroy_lvol_store {
|
2017-10-27 13:12:38 +00:00
|
|
|
char *uuid;
|
|
|
|
char *lvs_name;
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_destroy_lvol_store(struct rpc_destroy_lvol_store *req)
|
|
|
|
{
|
2017-10-27 13:12:38 +00:00
|
|
|
free(req->uuid);
|
|
|
|
free(req->lvs_name);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_destroy_lvol_store_decoders[] = {
|
2017-10-27 13:12:38 +00:00
|
|
|
{"uuid", offsetof(struct rpc_destroy_lvol_store, uuid), spdk_json_decode_string, true},
|
|
|
|
{"lvs_name", offsetof(struct rpc_destroy_lvol_store, lvs_name), spdk_json_decode_string, true},
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_rpc_lvol_store_destroy_cb(void *cb_arg, int lvserrno)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
|
|
|
if (lvserrno != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-lvserrno));
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_destroy_lvol_store(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_destroy_lvol_store req = {};
|
2017-10-27 13:12:38 +00:00
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
2017-09-14 14:53:36 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_destroy_lvol_store_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_destroy_lvol_store_decoders),
|
|
|
|
&req)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "spdk_json_decode_object failed\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
rc = vbdev_get_lvol_store_by_uuid_xor_name(req.uuid, req.lvs_name, &lvs);
|
|
|
|
if (rc != 0) {
|
2017-09-14 14:53:36 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
vbdev_lvs_destruct(lvs, _spdk_rpc_lvol_store_destroy_cb, request);
|
|
|
|
|
|
|
|
free_rpc_destroy_lvol_store(&req);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-09-14 14:53:36 +00:00
|
|
|
free_rpc_destroy_lvol_store(&req);
|
|
|
|
}
|
|
|
|
SPDK_RPC_REGISTER("destroy_lvol_store", spdk_rpc_destroy_lvol_store)
|
|
|
|
|
|
|
|
struct rpc_construct_lvol_bdev {
|
2017-10-27 13:12:38 +00:00
|
|
|
char *uuid;
|
|
|
|
char *lvs_name;
|
|
|
|
char *lvol_name;
|
2017-09-14 14:53:36 +00:00
|
|
|
uint64_t size;
|
2018-01-26 13:33:27 +00:00
|
|
|
bool thin_provision;
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_construct_lvol_bdev(struct rpc_construct_lvol_bdev *req)
|
|
|
|
{
|
2017-10-27 13:12:38 +00:00
|
|
|
free(req->uuid);
|
|
|
|
free(req->lvs_name);
|
|
|
|
free(req->lvol_name);
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_construct_lvol_bdev_decoders[] = {
|
2017-10-27 13:12:38 +00:00
|
|
|
{"uuid", offsetof(struct rpc_construct_lvol_bdev, uuid), spdk_json_decode_string, true},
|
|
|
|
{"lvs_name", offsetof(struct rpc_construct_lvol_bdev, lvs_name), spdk_json_decode_string, true},
|
|
|
|
{"lvol_name", offsetof(struct rpc_construct_lvol_bdev, lvol_name), spdk_json_decode_string, true},
|
2017-09-14 14:53:36 +00:00
|
|
|
{"size", offsetof(struct rpc_construct_lvol_bdev, size), spdk_json_decode_uint64},
|
2018-01-26 13:33:27 +00:00
|
|
|
{"thin_provision", offsetof(struct rpc_construct_lvol_bdev, thin_provision), spdk_json_decode_bool, true},
|
2017-09-14 14:53:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_rpc_construct_lvol_bdev_cb(void *cb_arg, struct spdk_lvol *lvol, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_array_begin(w);
|
2017-10-27 13:12:38 +00:00
|
|
|
spdk_json_write_string(w, lvol->bdev->name);
|
2017-09-14 14:53:36 +00:00
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-lvolerrno));
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_construct_lvol_bdev(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_construct_lvol_bdev req = {};
|
|
|
|
size_t sz;
|
|
|
|
int rc;
|
2017-10-27 13:12:38 +00:00
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
2017-09-14 14:53:36 +00:00
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "Creating blob\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_construct_lvol_bdev_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_construct_lvol_bdev_decoders),
|
|
|
|
&req)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "spdk_json_decode_object failed\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
2017-10-27 13:12:38 +00:00
|
|
|
rc = vbdev_get_lvol_store_by_uuid_xor_name(req.uuid, req.lvs_name, &lvs);
|
|
|
|
if (rc != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.lvol_name == NULL) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "no bdev name\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = (size_t)req.size;
|
|
|
|
|
2018-01-26 13:33:27 +00:00
|
|
|
rc = vbdev_lvol_create(lvs, req.lvol_name, sz, req.thin_provision,
|
|
|
|
_spdk_rpc_construct_lvol_bdev_cb, request);
|
2017-09-14 14:53:36 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_construct_lvol_bdev(&req);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-09-14 14:53:36 +00:00
|
|
|
free_rpc_construct_lvol_bdev(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_RPC_REGISTER("construct_lvol_bdev", spdk_rpc_construct_lvol_bdev)
|
|
|
|
|
|
|
|
struct rpc_resize_lvol_bdev {
|
|
|
|
char *name;
|
|
|
|
uint64_t size;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_resize_lvol_bdev(struct rpc_resize_lvol_bdev *req)
|
|
|
|
{
|
|
|
|
free(req->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_resize_lvol_bdev_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_resize_lvol_bdev, name), spdk_json_decode_string},
|
|
|
|
{"size", offsetof(struct rpc_resize_lvol_bdev, size), spdk_json_decode_uint64},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
_spdk_rpc_resize_lvol_bdev_cb(void *cb_arg, int lvolerrno)
|
|
|
|
{
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
|
|
|
if (lvolerrno != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spdk_json_write_bool(w, true);
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-lvolerrno));
|
2017-09-14 14:53:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-02 08:17:13 +00:00
|
|
|
static void __attribute__((unused))
|
2017-09-14 14:53:36 +00:00
|
|
|
spdk_rpc_resize_lvol_bdev(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_resize_lvol_bdev req = {};
|
|
|
|
int rc = 0;
|
|
|
|
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "Resizing lvol\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_resize_lvol_bdev_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_resize_lvol_bdev_decoders),
|
|
|
|
&req)) {
|
2017-08-30 18:06:33 +00:00
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "spdk_json_decode_object failed\n");
|
2017-09-14 14:53:36 +00:00
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req.name == NULL) {
|
|
|
|
SPDK_ERRLOG("missing name param\n");
|
2017-10-13 13:32:59 +00:00
|
|
|
rc = -EINVAL;
|
2017-09-14 14:53:36 +00:00
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = vbdev_lvol_resize(req.name, (size_t)req.size, _spdk_rpc_resize_lvol_bdev_cb, request);
|
|
|
|
if (rc < 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
free_rpc_resize_lvol_bdev(&req);
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
2017-11-07 12:56:52 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
2017-09-14 14:53:36 +00:00
|
|
|
free_rpc_resize_lvol_bdev(&req);
|
|
|
|
}
|
|
|
|
|
2017-10-02 08:17:13 +00:00
|
|
|
/* Logical volume resize feature is disabled, as it is currently work in progress
|
|
|
|
SPDK_RPC_REGISTER("resize_lvol_bdev", spdk_rpc_resize_lvol_bdev) */
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
struct rpc_get_lvol_stores {
|
|
|
|
char *uuid;
|
|
|
|
char *lvs_name;
|
|
|
|
};
|
|
|
|
|
2017-09-18 08:49:22 +00:00
|
|
|
static void
|
2018-01-29 07:09:35 +00:00
|
|
|
free_rpc_get_lvol_stores(struct rpc_get_lvol_stores *req)
|
|
|
|
{
|
|
|
|
free(req->uuid);
|
|
|
|
free(req->lvs_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_get_lvol_stores_decoders[] = {
|
|
|
|
{"uuid", offsetof(struct rpc_get_lvol_stores, uuid), spdk_json_decode_string, true},
|
|
|
|
{"lvs_name", offsetof(struct rpc_get_lvol_stores, lvs_name), spdk_json_decode_string, true},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
spdk_rpc_dump_lvol_store_info(struct spdk_json_write_ctx *w, struct lvol_store_bdev *lvs_bdev)
|
2017-09-18 08:49:22 +00:00
|
|
|
{
|
2017-10-03 10:54:06 +00:00
|
|
|
struct spdk_blob_store *bs;
|
2017-11-03 13:09:40 +00:00
|
|
|
uint64_t cluster_size, block_size;
|
2017-09-18 08:49:22 +00:00
|
|
|
char uuid[UUID_STRING_LEN];
|
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
bs = lvs_bdev->lvs->blobstore;
|
|
|
|
cluster_size = spdk_bs_get_cluster_size(bs);
|
|
|
|
/* Block size of lvols is always size of blob store page */
|
|
|
|
block_size = spdk_bs_get_page_size(bs);
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_object_begin(w);
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
uuid_unparse(lvs_bdev->lvs->uuid, uuid);
|
|
|
|
spdk_json_write_name(w, "uuid");
|
|
|
|
spdk_json_write_string(w, uuid);
|
|
|
|
|
|
|
|
spdk_json_write_name(w, "name");
|
|
|
|
spdk_json_write_string(w, lvs_bdev->lvs->name);
|
|
|
|
|
|
|
|
spdk_json_write_name(w, "base_bdev");
|
|
|
|
spdk_json_write_string(w, spdk_bdev_get_name(lvs_bdev->bdev));
|
|
|
|
|
|
|
|
spdk_json_write_name(w, "total_data_clusters");
|
|
|
|
spdk_json_write_uint64(w, spdk_bs_total_data_cluster_count(bs));
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_name(w, "free_clusters");
|
|
|
|
spdk_json_write_uint64(w, spdk_bs_free_cluster_count(bs));
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_name(w, "block_size");
|
|
|
|
spdk_json_write_uint64(w, block_size);
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_name(w, "cluster_size");
|
|
|
|
spdk_json_write_uint64(w, cluster_size);
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_object_end(w);
|
|
|
|
}
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
static void
|
|
|
|
spdk_rpc_get_lvol_stores(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
|
|
|
{
|
|
|
|
struct rpc_get_lvol_stores req = {};
|
|
|
|
struct spdk_json_write_ctx *w;
|
|
|
|
struct lvol_store_bdev *lvs_bdev = NULL;
|
|
|
|
struct spdk_lvol_store *lvs = NULL;
|
|
|
|
int rc;
|
2017-10-27 13:12:38 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
if (params != NULL) {
|
|
|
|
if (spdk_json_decode_object(params, rpc_get_lvol_stores_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_get_lvol_stores_decoders),
|
|
|
|
&req)) {
|
|
|
|
SPDK_INFOLOG(SPDK_LOG_LVOL_RPC, "spdk_json_decode_object failed\n");
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto invalid;
|
|
|
|
}
|
2017-09-18 08:49:22 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
rc = vbdev_get_lvol_store_by_uuid_xor_name(req.uuid, req.lvs_name, &lvs);
|
|
|
|
if (rc != 0) {
|
|
|
|
goto invalid;
|
|
|
|
}
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
lvs_bdev = vbdev_get_lvs_bdev_by_lvs(lvs);
|
|
|
|
if (lvs_bdev == NULL) {
|
|
|
|
rc = -ENODEV;
|
|
|
|
goto invalid;
|
|
|
|
}
|
|
|
|
}
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
|
|
|
if (w == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
spdk_json_write_array_begin(w);
|
2017-10-03 10:54:06 +00:00
|
|
|
|
2018-01-29 07:09:35 +00:00
|
|
|
if (lvs_bdev != NULL) {
|
|
|
|
spdk_rpc_dump_lvol_store_info(w, lvs_bdev);
|
|
|
|
} else {
|
|
|
|
for (lvs_bdev = vbdev_lvol_store_first(); lvs_bdev != NULL;
|
|
|
|
lvs_bdev = vbdev_lvol_store_next(lvs_bdev)) {
|
|
|
|
spdk_rpc_dump_lvol_store_info(w, lvs_bdev);
|
|
|
|
}
|
2017-09-18 08:49:22 +00:00
|
|
|
}
|
|
|
|
spdk_json_write_array_end(w);
|
|
|
|
|
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2018-01-29 07:09:35 +00:00
|
|
|
|
|
|
|
free_rpc_get_lvol_stores(&req);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
invalid:
|
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
|
|
|
|
spdk_strerror(-rc));
|
|
|
|
free_rpc_get_lvol_stores(&req);
|
2017-09-18 08:49:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SPDK_RPC_REGISTER("get_lvol_stores", spdk_rpc_get_lvol_stores)
|