Commit be90ea6e authored by Artur Paszkiewicz's avatar Artur Paszkiewicz Committed by Jim Harris
Browse files

FTL: Add bdev_ftl_create and delete rpc definitions



Signed-off-by: default avatarKozlowski Mateusz <mateusz.kozlowski@intel.com>
Signed-off-by: default avatarArtur Paszkiewicz <artur.paszkiewicz@intel.com>
Change-Id: I0837028fbe349e8df7f05fb3c9db1f4682f04679
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13301


Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent 6db3ac3a
Loading
Loading
Loading
Loading
+105 −11
Original line number Diff line number Diff line
@@ -465,7 +465,9 @@ Example response:
    "bdev_malloc_delete",
    "bdev_malloc_create",
    "bdev_ftl_delete",
    "bdev_ftl_unload",
    "bdev_ftl_create",
    "bdev_ftl_load",
    "bdev_lvol_get_lvstores",
    "bdev_lvol_delete",
    "bdev_lvol_resize",
@@ -4564,11 +4566,11 @@ This RPC is subject to change.
Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name
trtype                  | Required | string      | Transport type
traddr                  | Required | string      | NVMe target address
punits                  | Required | string      | Parallel unit range in the form of start-end e.g 4-8
base_bdev               | Required | string      | Name of the base device
cache                   | Required | string      | Name of the cache device
uuid                    | Optional | string      | UUID of restored bdev (not applicable when creating new instance)
cache                   | Optional | string      | Name of the bdev to be used as a write buffer cache
core_mask               | Optional | string      | CPU core(s) possible for placement of the ftl core thread, application main thread by default
overprovisioning        | Optional | int         | Percentage of base device used for relocation, 20% by default

#### Result

@@ -4581,11 +4583,12 @@ Example request:
~~~json
{
  "params": {
    "name": "nvme0"
    "trtype" "pcie"
    "traddr": "0000:00:04.0"
    "punits": "0-3"
    "uuid": "4a7481ce-786f-41a0-9b86-8f7465c8f4d3"
    "name": "ftl0",
    "base_bdev": "nvme0n1",
    "cache": "nvme1n1",
    "uuid": "4a7481ce-786f-41a0-9b86-8f7465c8f4d3",
    "core_mask": "[0]",
    "overprovisioning": 10
  },
  "jsonrpc": "2.0",
  "method": "bdev_ftl_create",
@@ -4600,7 +4603,61 @@ Example response:
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
      "name" : "nvme0"
      "name" : "ftl0"
      "uuid" : "4a7481ce-786f-41a0-9b86-8f7465c8f4d3"
  }
}
~~~

### bdev_ftl_load {#rpc_bdev_ftl_load}

Loads FTL bdev.

This RPC is subject to change.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name
base_bdev               | Required | string      | Name of the base device
cache                   | Required | string      | Name of the cache device
uuid                    | Required | string      | UUID of restored bdev
core_mask               | Optional | string      | CPU core(s) possible for placement of the ftl core thread, application main thread by default
overprovisioning        | Optional | int         | Percentage of base device used for relocation, 20% by default

#### Result

Name of loaded bdev.

#### Example

Example request:

~~~json
{
  "params": {
    "name": "ftl0",
    "base_bdev": "nvme0n1",
    "cache": "nvme1n1",
    "uuid": "4a7481ce-786f-41a0-9b86-8f7465c8f4d3",
    "core_mask": "[0]",
    "overprovisioning": 10
  },
  "jsonrpc": "2.0",
  "method": "bdev_ftl_load",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
      "name" : "ftl0"
      "uuid" : "4a7481ce-786f-41a0-9b86-8f7465c8f4d3"
  }
}
@@ -4625,7 +4682,7 @@ Example request:
~~~json
{
  "params": {
    "name": "nvme0"
    "name": "ftl0"
  },
  "jsonrpc": "2.0",
  "method": "bdev_ftl_delete",
@@ -4643,6 +4700,43 @@ Example response:
}
~~~

### bdev_ftl_unload {#rpc_bdev_ftl_unload}

Unloads FTL bdev.

This RPC is subject to change.

#### Parameters

Name                    | Optional | Type        | Description
----------------------- | -------- | ----------- | -----------
name                    | Required | string      | Bdev name

#### Example

Example request:

~~~json
{
  "params": {
    "name": "ftl0"
  },
  "jsonrpc": "2.0",
  "method": "bdev_ftl_unload",
  "id": 1
}
~~~

Example response:

~~~json
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": true
}
~~~

### bdev_pmem_create_pool {#rpc_bdev_pmem_create_pool}

Create a @ref bdev_config_pmem blk pool file. It is equivalent of following `pmempool create` command:
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ endif

# module/bdev
ifeq ($(OS),Linux)
DEPDIRS-bdev_ftl := bdev json log util ftl
DEPDIRS-bdev_ftl := $(BDEV_DEPS) ftl
endif
DEPDIRS-bdev_gpt := bdev json log thread util

+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@ ifdef SPDK_FTL_VSS_EMU
CFLAGS += -DSPDK_FTL_VSS_EMU
endif

C_SRCS += bdev_ftl.c
C_SRCS += bdev_ftl.c bdev_ftl_rpc.c
LIBNAME = bdev_ftl

SPDK_MAP_FILE = $(SPDK_ROOT_DIR)/mk/spdk_blank.map
+161 −0
Original line number Diff line number Diff line
/*   SPDX-License-Identifier: BSD-3-Clause
 *   Copyright (c) Intel Corporation.
 *   All rights reserved.
 */

#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/bdev_module.h"
#include "spdk/string.h"
#include "spdk/log.h"

#include "bdev_ftl.h"

static int
rpc_bdev_ftl_decode_uuid(const struct spdk_json_val *val, void *out)
{
	char *uuid_str;
	int ret;

	uuid_str = spdk_json_strdup(val);
	if (!uuid_str) {
		return -ENOMEM;
	}

	ret = spdk_uuid_parse(out, uuid_str);

	free(uuid_str);
	return ret;
}

static const struct spdk_json_object_decoder rpc_bdev_ftl_create_decoders[] = {
	{"name", offsetof(struct spdk_ftl_conf, name), spdk_json_decode_string},
	{"base_bdev", offsetof(struct spdk_ftl_conf, base_bdev), spdk_json_decode_string},
	{"uuid", offsetof(struct spdk_ftl_conf, uuid), rpc_bdev_ftl_decode_uuid, true},
	{"cache", offsetof(struct spdk_ftl_conf, cache_bdev), spdk_json_decode_string},
	{
		"overprovisioning", offsetof(struct spdk_ftl_conf, overprovisioning),
		spdk_json_decode_uint64, true
	},
	{
		"core_mask", offsetof(struct spdk_ftl_conf, core_mask),
		spdk_json_decode_string, true
	},
};

static void
rpc_bdev_ftl_create_cb(const struct ftl_bdev_info *bdev_info, void *ctx, int status)
{
	struct spdk_jsonrpc_request *request = ctx;
	char bdev_uuid[SPDK_UUID_STRING_LEN];
	struct spdk_json_write_ctx *w;

	if (status) {
		spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
						     "Failed to create FTL bdev: %s",
						     spdk_strerror(-status));
		return;
	}

	w = spdk_jsonrpc_begin_result(request);
	spdk_uuid_fmt_lower(bdev_uuid, sizeof(bdev_uuid), &bdev_info->uuid);
	spdk_json_write_object_begin(w);
	spdk_json_write_named_string(w, "name", bdev_info->name);
	spdk_json_write_named_string(w, "uuid", bdev_uuid);
	spdk_json_write_object_end(w);
	spdk_jsonrpc_end_result(request, w);
}

static void
rpc_bdev_ftl_create(struct spdk_jsonrpc_request *request,
		    const struct spdk_json_val *params)
{
	struct spdk_ftl_conf conf = {};
	struct spdk_json_write_ctx *w;
	int rc;

	spdk_ftl_get_default_conf(&conf);

	if (spdk_json_decode_object(params, rpc_bdev_ftl_create_decoders,
				    SPDK_COUNTOF(rpc_bdev_ftl_create_decoders),
				    &conf)) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
						 "Invalid parameters");
		goto out;
	}

	if (spdk_mem_all_zero(&conf.uuid, sizeof(conf.uuid))) {
		conf.mode |= SPDK_FTL_MODE_CREATE;
	}

	rc = bdev_ftl_create_bdev(&conf, rpc_bdev_ftl_create_cb, request);
	if (rc == -ENODEV) {
		rc = bdev_ftl_defer_init(&conf);
		if (rc == 0) {
			w = spdk_jsonrpc_begin_result(request);
			spdk_json_write_string_fmt(w, "FTL bdev: %s creation deferred", conf.name);
			spdk_jsonrpc_end_result(request, w);
		}
	}

	if (rc) {
		spdk_jsonrpc_send_error_response_fmt(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
						     "Failed to create FTL bdev: %s",
						     spdk_strerror(-rc));
	}
out:
	spdk_ftl_conf_deinit(&conf);
}
SPDK_RPC_REGISTER("bdev_ftl_create", rpc_bdev_ftl_create, SPDK_RPC_RUNTIME)

static void
rpc_bdev_ftl_load(struct spdk_jsonrpc_request *request,
		  const struct spdk_json_val *params)
{
	rpc_bdev_ftl_create(request, params);
}
SPDK_RPC_REGISTER("bdev_ftl_load", rpc_bdev_ftl_load, SPDK_RPC_RUNTIME)

struct rpc_delete_ftl {
	char *name;
};

static const struct spdk_json_object_decoder rpc_delete_ftl_decoders[] = {
	{"name", offsetof(struct rpc_delete_ftl, name), spdk_json_decode_string},
};

static void
rpc_bdev_ftl_delete_cb(void *cb_arg, int bdeverrno)
{
	struct spdk_jsonrpc_request *request = cb_arg;

	spdk_jsonrpc_send_bool_response(request, bdeverrno == 0);
}

static void
rpc_bdev_ftl_delete(struct spdk_jsonrpc_request *request,
		    const struct spdk_json_val *params)
{
	struct rpc_delete_ftl attrs = {};

	if (spdk_json_decode_object(params, rpc_delete_ftl_decoders,
				    SPDK_COUNTOF(rpc_delete_ftl_decoders),
				    &attrs)) {
		spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
						 "Invalid parameters");
		goto invalid;
	}

	bdev_ftl_delete_bdev(attrs.name, rpc_bdev_ftl_delete_cb, request);
invalid:
	free(attrs.name);
}
SPDK_RPC_REGISTER("bdev_ftl_delete", rpc_bdev_ftl_delete, SPDK_RPC_RUNTIME)

static void
rpc_bdev_ftl_unload(struct spdk_jsonrpc_request *request,
		    const struct spdk_json_val *params)
{
	rpc_bdev_ftl_delete(request, params);
}
SPDK_RPC_REGISTER("bdev_ftl_unload", rpc_bdev_ftl_unload, SPDK_RPC_RUNTIME)
+28 −0
Original line number Diff line number Diff line
@@ -1347,6 +1347,34 @@ def bdev_ftl_create(client, name, base_bdev, **kwargs):
    return client.call('bdev_ftl_create', params)


def bdev_ftl_load(client, name, base_bdev, **kwargs):
    """Load FTL bdev

    Args:
        name: name of the bdev
        base_bdev: name of the base bdev
        kwargs: optional parameters
    """
    params = {'name': name,
              'base_bdev': base_bdev}
    for key, value in kwargs.items():
        if value is not None:
            params[key] = value

    return client.call('bdev_ftl_load', params)


def bdev_ftl_unload(client, name):
    """Unload FTL bdev

    Args:
        name: name of the bdev
    """
    params = {'name': name}

    return client.call('bdev_ftl_unload', params)


def bdev_ftl_delete(client, name):
    """Delete FTL bdev

Loading