bdev/nvme: Factor out each RPC config from config_json()

Factor out each RPC configuration from bdev_nvme_config_json() and
bdev_ocssd_namespace_config_json() into a helper function, respectively.

These changes will make us easier to introduce subsystem into the
NVMe bdev module.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I297f3fb47893d45463e742834c58d2b1213a4b01
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/5468
Community-CI: Broadcom CI
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: <dongx.yi@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
This commit is contained in:
Shuhei Matsumoto 2020-12-08 03:46:51 +09:00 committed by Tomasz Zawadzki
parent 17afd268df
commit 4dc86079b7
2 changed files with 85 additions and 56 deletions

View File

@ -2769,13 +2769,10 @@ nvme_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *n
g_config_json_namespace_fn[nvme_ns->type](w, nvme_ns); g_config_json_namespace_fn[nvme_ns->type](w, nvme_ns);
} }
static int static void
bdev_nvme_config_json(struct spdk_json_write_ctx *w) bdev_nvme_opts_config_json(struct spdk_json_write_ctx *w)
{ {
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; const char *action;
struct spdk_nvme_transport_id *trid;
const char *action;
uint32_t nsid;
if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET) { if (g_opts.action_on_timeout == SPDK_BDEV_NVME_TIMEOUT_ACTION_RESET) {
action = "reset"; action = "reset";
@ -2805,26 +2802,59 @@ bdev_nvme_config_json(struct spdk_json_write_ctx *w)
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
}
static void
nvme_bdev_ctrlr_config_json(struct spdk_json_write_ctx *w,
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr)
{
struct spdk_nvme_transport_id *trid;
trid = nvme_bdev_ctrlr->connected_trid;
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_nvme_attach_controller");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
nvme_bdev_dump_trid_json(trid, w);
spdk_json_write_named_bool(w, "prchk_reftag",
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_REFTAG) != 0);
spdk_json_write_named_bool(w, "prchk_guard",
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) != 0);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
static void
bdev_nvme_hotplug_config_json(struct spdk_json_write_ctx *w)
{
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_nvme_set_hotplug");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_uint64(w, "period_us", g_nvme_hotplug_poll_period_us);
spdk_json_write_named_bool(w, "enable", g_nvme_hotplug_enabled);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
static int
bdev_nvme_config_json(struct spdk_json_write_ctx *w)
{
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
uint32_t nsid;
bdev_nvme_opts_config_json(w);
pthread_mutex_lock(&g_bdev_nvme_mutex); pthread_mutex_lock(&g_bdev_nvme_mutex);
TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) { TAILQ_FOREACH(nvme_bdev_ctrlr, &g_nvme_bdev_ctrlrs, tailq) {
trid = nvme_bdev_ctrlr->connected_trid; nvme_bdev_ctrlr_config_json(w, nvme_bdev_ctrlr);
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_nvme_attach_controller");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "name", nvme_bdev_ctrlr->name);
nvme_bdev_dump_trid_json(trid, w);
spdk_json_write_named_bool(w, "prchk_reftag",
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_REFTAG) != 0);
spdk_json_write_named_bool(w, "prchk_guard",
(nvme_bdev_ctrlr->prchk_flags & SPDK_NVME_IO_FLAGS_PRCHK_GUARD) != 0);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
for (nsid = 0; nsid < nvme_bdev_ctrlr->num_ns; ++nsid) { for (nsid = 0; nsid < nvme_bdev_ctrlr->num_ns; ++nsid) {
if (!nvme_bdev_ctrlr->namespaces[nsid]->populated) { if (!nvme_bdev_ctrlr->namespaces[nsid]->populated) {
@ -2838,15 +2868,7 @@ bdev_nvme_config_json(struct spdk_json_write_ctx *w)
/* Dump as last parameter to give all NVMe bdevs chance to be constructed /* Dump as last parameter to give all NVMe bdevs chance to be constructed
* before enabling hotplug poller. * before enabling hotplug poller.
*/ */
spdk_json_write_object_begin(w); bdev_nvme_hotplug_config_json(w);
spdk_json_write_named_string(w, "method", "bdev_nvme_set_hotplug");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_uint64(w, "period_us", g_nvme_hotplug_poll_period_us);
spdk_json_write_named_bool(w, "enable", g_nvme_hotplug_enabled);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
pthread_mutex_unlock(&g_bdev_nvme_mutex); pthread_mutex_unlock(&g_bdev_nvme_mutex);
return 0; return 0;

View File

@ -129,37 +129,44 @@ bdev_ocssd_config_json(struct spdk_json_write_ctx *w)
return 0; return 0;
} }
void static void
bdev_ocssd_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *nvme_ns) ocssd_bdev_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev *nvme_bdev)
{ {
struct nvme_bdev_ctrlr *nvme_bdev_ctrlr; struct nvme_bdev_ctrlr *nvme_bdev_ctrlr;
struct nvme_bdev *nvme_bdev;
struct ocssd_bdev *ocssd_bdev; struct ocssd_bdev *ocssd_bdev;
char range_buf[128]; char range_buf[128];
int rc; int rc;
nvme_bdev_ctrlr = nvme_bdev->nvme_ns->ctrlr;
ocssd_bdev = SPDK_CONTAINEROF(nvme_bdev, struct ocssd_bdev, nvme_bdev);
rc = snprintf(range_buf, sizeof(range_buf), "%"PRIu64"-%"PRIu64,
ocssd_bdev->range.begin, ocssd_bdev->range.end);
if (rc < 0 || rc >= (int)sizeof(range_buf)) {
SPDK_ERRLOG("Failed to convert parallel unit range\n");
return;
}
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_ocssd_create");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr_name", nvme_bdev_ctrlr->name);
spdk_json_write_named_string(w, "bdev_name", nvme_bdev->disk.name);
spdk_json_write_named_uint32(w, "nsid", nvme_bdev->nvme_ns->id);
spdk_json_write_named_string(w, "range", range_buf);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
}
void
bdev_ocssd_namespace_config_json(struct spdk_json_write_ctx *w, struct nvme_bdev_ns *nvme_ns)
{
struct nvme_bdev *nvme_bdev;
TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) { TAILQ_FOREACH(nvme_bdev, &nvme_ns->bdevs, tailq) {
nvme_bdev_ctrlr = nvme_bdev->nvme_ns->ctrlr; ocssd_bdev_config_json(w, nvme_bdev);
ocssd_bdev = SPDK_CONTAINEROF(nvme_bdev, struct ocssd_bdev, nvme_bdev);
rc = snprintf(range_buf, sizeof(range_buf), "%"PRIu64"-%"PRIu64,
ocssd_bdev->range.begin, ocssd_bdev->range.end);
if (rc < 0 || rc >= (int)sizeof(range_buf)) {
SPDK_ERRLOG("Failed to convert parallel unit range\n");
continue;
}
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "method", "bdev_ocssd_create");
spdk_json_write_named_object_begin(w, "params");
spdk_json_write_named_string(w, "ctrlr_name", nvme_bdev_ctrlr->name);
spdk_json_write_named_string(w, "bdev_name", nvme_bdev->disk.name);
spdk_json_write_named_uint32(w, "nsid", nvme_bdev->nvme_ns->id);
spdk_json_write_named_string(w, "range", range_buf);
spdk_json_write_object_end(w);
spdk_json_write_object_end(w);
} }
} }