diff --git a/include/spdk/nbd.h b/include/spdk/nbd.h index 15e905a9c..584dd0652 100644 --- a/include/spdk/nbd.h +++ b/include/spdk/nbd.h @@ -44,6 +44,8 @@ extern "C" { struct spdk_bdev; struct spdk_nbd_disk; +struct spdk_json_write_ctx; +struct spdk_event; /** * Initialize the network block device layer. @@ -75,6 +77,14 @@ struct spdk_nbd_disk *spdk_nbd_start(const char *bdev_name, const char *nbd_path */ void spdk_nbd_stop(struct spdk_nbd_disk *nbd); +/** + * Write NBD subsystem configuration into provided JSON context. + * + * \param w JSON write context + * \param done_ev call this event when done. + */ +void spdk_nbd_write_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev); + #ifdef __cplusplus } #endif diff --git a/lib/event/subsystems/nbd/nbd.c b/lib/event/subsystems/nbd/nbd.c index b82ae4f89..767364462 100644 --- a/lib/event/subsystems/nbd/nbd.c +++ b/lib/event/subsystems/nbd/nbd.c @@ -59,6 +59,7 @@ static struct spdk_subsystem g_spdk_subsystem_nbd = { .init = spdk_nbd_subsystem_init, .fini = spdk_nbd_subsystem_fini, .config = NULL, + .write_config_json = spdk_nbd_write_config_json, }; SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_nbd); diff --git a/lib/nbd/nbd.c b/lib/nbd/nbd.c index 19225788f..d476e8ece 100644 --- a/lib/nbd/nbd.c +++ b/lib/nbd/nbd.c @@ -44,6 +44,7 @@ #include "spdk/log.h" #include "spdk/util.h" #include "spdk/io_channel.h" +#include "spdk/event.h" #include "spdk_internal/log.h" #include "spdk/queue.h" @@ -211,6 +212,27 @@ spdk_nbd_disk_get_bdev_name(struct spdk_nbd_disk *nbd) return spdk_bdev_get_name(nbd->bdev); } +void +spdk_nbd_write_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev) +{ + struct spdk_nbd_disk *nbd; + + TAILQ_FOREACH(nbd, &g_spdk_nbd.disk_head, tailq) { + spdk_json_write_object_begin(w); + + spdk_json_write_named_string(w, "method", "start_nbd_disk"); + + spdk_json_write_named_object_begin(w, "params"); + spdk_json_write_named_string(w, "nbd_device", spdk_nbd_disk_get_nbd_path(nbd)); + spdk_json_write_named_string(w, "bdev_name", spdk_nbd_disk_get_bdev_name(nbd)); + spdk_json_write_object_end(w); + + spdk_json_write_object_end(w); + } + + spdk_event_call(done_ev); +} + void nbd_disconnect(struct spdk_nbd_disk *nbd) {