Commit 5b424282 authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Daniel Verkamp
Browse files

nbd: add JSON config dump

parent a77cd3f7
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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);
+22 −0
Original line number Diff line number Diff line
@@ -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)
{