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

vhost: add JSON config dump




Change-Id: If6c9ea6f9959b6c34ef90b8e382ceba9889040ee
Signed-off-by: default avatarPawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/404373


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
parent e3263286
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
#include "spdk/stdinc.h"

#include "spdk/event.h"
#include "spdk/json.h"

#ifdef __cplusplus
extern "C" {
@@ -77,6 +78,15 @@ int spdk_vhost_init(void);
 */
void spdk_vhost_fini(spdk_vhost_fini_cb fini_cb);


/**
 * Write vhost subsystem configuration into provided JSON context.
 *
 * \param w JSON write context
 * \param done_ev call this event when done.
 */
void spdk_vhost_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev);

/**
 * Deinit vhost application. This is called once by SPDK app layer.
 */
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ static struct spdk_subsystem g_spdk_subsystem_vhost = {
	.init = spdk_vhost_subsystem_init,
	.fini = spdk_vhost_subsystem_fini,
	.config = NULL,
	.write_config_json = spdk_vhost_config_json,
};

SPDK_SUBSYSTEM_REGISTER(g_spdk_subsystem_vhost);
+37 −4
Original line number Diff line number Diff line
@@ -1158,11 +1158,10 @@ session_shutdown(void *arg)
}

void
spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev,
			    struct spdk_json_write_ctx *w)
spdk_vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
	assert(vdev->backend->dump_config_json != NULL);
	vdev->backend->dump_config_json(vdev, w);
	assert(vdev->backend->dump_info_json != NULL);
	vdev->backend->dump_info_json(vdev, w);
}

int
@@ -1368,5 +1367,39 @@ spdk_vhost_fini(spdk_vhost_fini_cb fini_cb)
	pthread_detach(tid);
}

struct spdk_vhost_write_config_json_ctx {
	struct spdk_json_write_ctx *w;
	struct spdk_event *done_ev;
};

static int
spdk_vhost_config_json_cb(struct spdk_vhost_dev *vdev, void *arg)
{
	struct spdk_vhost_write_config_json_ctx *ctx = arg;

	if (vdev == NULL) {
		spdk_json_write_array_end(ctx->w);
		spdk_event_call(ctx->done_ev);
		free(ctx);
		return 0;
	}

	vdev->backend->write_config_json(vdev, ctx->w);
	return 0;
}

void
spdk_vhost_config_json(struct spdk_json_write_ctx *w, struct spdk_event *done_ev)
{
	struct spdk_vhost_write_config_json_ctx *ctx = calloc(1, sizeof(*ctx));

	ctx->w = w;
	ctx->done_ev = done_ev;

	spdk_json_write_array_begin(w);

	spdk_vhost_call_external_event_foreach(spdk_vhost_config_json_cb, ctx);
}

SPDK_LOG_REGISTER_COMPONENT("vhost", SPDK_LOG_VHOST)
SPDK_LOG_REGISTER_COMPONENT("vhost_ring", SPDK_LOG_VHOST_RING)
+25 −2
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ err:
}

static void
spdk_vhost_blk_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
spdk_vhost_blk_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
	struct spdk_bdev *bdev = spdk_vhost_blk_get_dev(vdev);
	struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);
@@ -617,6 +617,28 @@ spdk_vhost_blk_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_wr
	spdk_json_write_object_end(w);
}

static void
spdk_vhost_blk_write_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w)
{
	struct spdk_vhost_blk_dev *bvdev = to_blk_dev(vdev);

	if (!bvdev->bdev) {
		return;
	}

	spdk_json_write_object_begin(w);
	spdk_json_write_named_string(w, "method", "construct_vhost_blk_controller");

	spdk_json_write_named_object_begin(w, "params");
	spdk_json_write_named_string(w, "ctrlr", vdev->name);
	spdk_json_write_named_string(w, "dev_name", spdk_bdev_get_name(bvdev->bdev));
	spdk_json_write_named_string(w, "cpumask", spdk_cpuset_fmt(vdev->cpumask));
	spdk_json_write_named_bool(w, "readonly", bvdev->readonly);
	spdk_json_write_object_end(w);

	spdk_json_write_object_end(w);
}

static int spdk_vhost_blk_destroy(struct spdk_vhost_dev *dev);

static int
@@ -672,7 +694,8 @@ static const struct spdk_vhost_dev_backend vhost_blk_device_backend = {
	.start_device =  spdk_vhost_blk_start,
	.stop_device = spdk_vhost_blk_stop,
	.vhost_get_config = spdk_vhost_blk_get_config,
	.dump_config_json = spdk_vhost_blk_dump_config_json,
	.dump_info_json = spdk_vhost_blk_dump_info_json,
	.write_config_json = spdk_vhost_blk_write_config_json,
	.remove_device = spdk_vhost_blk_destroy,
};

+3 −2
Original line number Diff line number Diff line
@@ -128,7 +128,8 @@ struct spdk_vhost_dev_backend {
	int (*vhost_set_config)(struct spdk_vhost_dev *vdev, uint8_t *config,
				uint32_t offset, uint32_t size, uint32_t flags);

	void (*dump_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
	void (*dump_info_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
	void (*write_config_json)(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
	int (*remove_device)(struct spdk_vhost_dev *vdev);
};

@@ -248,7 +249,7 @@ int spdk_vhost_dev_unregister(struct spdk_vhost_dev *vdev);

int spdk_vhost_scsi_controller_construct(void);
int spdk_vhost_blk_controller_construct(void);
void spdk_vhost_dump_config_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
void spdk_vhost_dump_info_json(struct spdk_vhost_dev *vdev, struct spdk_json_write_ctx *w);
void spdk_vhost_dev_backend_event_done(void *event_ctx, int response);
void spdk_vhost_lock(void);
void spdk_vhost_unlock(void);
Loading