Commit 199080cf authored by Vitaliy Mysak's avatar Vitaliy Mysak Committed by Jim Harris
Browse files

OCF: rpc: add get_ocf_bdevs method



Add new RPC method for OCF bdev: get_ocf_bdevs
It is useful in respect to not registered OCF bdevs
  which do not appear in standard get_bdevs call

Change-Id: I8a5fc86a880b04c47d5f139aa5fa4d07ca39c853
Signed-off-by: default avatarVitaliy Mysak <vitaliy.mysak@intel.com>
Reviewed-on: https://review.gerrithub.io/c/441655


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarDarek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 27e0190b
Loading
Loading
Loading
Loading
+47 −0
Original line number Diff line number Diff line
@@ -1076,6 +1076,53 @@ Example response:
}
~~~

## get_ocf_bdevs {#rpc_get_ocf_bdevs}

Get list of OCF devices including unregistered ones.

### Parameters

This method has no parameters.

### Response

Array of OCF devices with their current status, along with core and cache bdevs.

### Example

Example request:

~~~
{
  "jsonrpc": "2.0",
  "method": "get_ocf_bdevs",
  "id": 1
}
~~~

Example response:

~~~
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": [
    {
      "name": "PartCache",
      "started": false,
      "cache": {
        "name": "Malloc0",
        "attached": true
      },
      "core": {
        "name": "Malloc1",
        "attached": false
      }
    }
  ]
}
~~~

## construct_malloc_bdev {#rpc_construct_malloc_bdev}

Construct @ref bdev_config_malloc
+15 −0
Original line number Diff line number Diff line
@@ -228,6 +228,21 @@ vbdev_ocf_get_base_by_name(const char *name)
	return NULL;
}

/* Execute fn for each OCF device that is online or waits for base devices */
void
vbdev_ocf_foreach(vbdev_ocf_foreach_fn fn, void *ctx)
{
	struct vbdev_ocf *vbdev;

	assert(fn != NULL);

	TAILQ_FOREACH(vbdev, &g_ocf_vbdev_head, tailq) {
		if (!vbdev->state.doing_finish) {
			fn(vbdev, ctx);
		}
	}
}

/* Called from OCF when SPDK_IO is completed */
static void
vbdev_ocf_io_submit_cb(struct ocf_io *io, int error)
+5 −0
Original line number Diff line number Diff line
@@ -154,4 +154,9 @@ struct vbdev_ocf_base *vbdev_ocf_get_base_by_name(const char *name);
/* Stop OCF cache and unregister SPDK bdev */
int vbdev_ocf_delete(struct vbdev_ocf *vbdev);

typedef void (*vbdev_ocf_foreach_fn)(struct vbdev_ocf *, void *);

/* Execute fn for each OCF device that is online or waits for base devices */
void vbdev_ocf_foreach(vbdev_ocf_foreach_fn fn, void *ctx);

#endif
+40 −0
Original line number Diff line number Diff line
@@ -218,3 +218,43 @@ end:
	free_rpc_get_ocf_stats(&req);
}
SPDK_RPC_REGISTER("get_ocf_stats", spdk_rpc_get_ocf_stats, SPDK_RPC_RUNTIME)

static void
get_bdevs_fn(struct vbdev_ocf *vbdev, void *ctx)
{
	struct spdk_json_write_ctx *w = ctx;

	spdk_json_write_object_begin(w);
	spdk_json_write_named_string(w, "name", vbdev->name);
	spdk_json_write_named_bool(w, "started", vbdev->state.started);

	spdk_json_write_named_object_begin(w, "cache");
	spdk_json_write_named_string(w, "name", vbdev->cache.name);
	spdk_json_write_named_bool(w, "attached", vbdev->cache.attached);
	spdk_json_write_object_end(w);

	spdk_json_write_named_object_begin(w, "core");
	spdk_json_write_named_string(w, "name", vbdev->core.name);
	spdk_json_write_named_bool(w, "attached", vbdev->core.attached);
	spdk_json_write_object_end(w);

	spdk_json_write_object_end(w);
}

static void
spdk_rpc_get_ocf_bdevs(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
	struct spdk_json_write_ctx *w;

	w = spdk_jsonrpc_begin_result(request);
	if (w == NULL) {
		return;
	}

	spdk_json_write_array_begin(w);
	vbdev_ocf_foreach(get_bdevs_fn, w);
	spdk_json_write_array_end(w);

	spdk_jsonrpc_end_result(request, w);
}
SPDK_RPC_REGISTER("get_ocf_bdevs", spdk_rpc_get_ocf_bdevs, SPDK_RPC_RUNTIME)
+6 −0
Original line number Diff line number Diff line
@@ -175,6 +175,12 @@ if __name__ == "__main__":
    p.add_argument('name', help='Name of OCF bdev')
    p.set_defaults(func=get_ocf_stats)

    def get_ocf_bdevs(args):
        print_dict(rpc.bdev.get_ocf_bdevs(args.client))
    p = subparsers.add_parser('get_ocf_bdevs',
                              help='Get list of OCF devices including unregistered ones')
    p.set_defaults(func=get_ocf_bdevs)

    def construct_malloc_bdev(args):
        num_blocks = (args.total_size * 1024 * 1024) // args.block_size
        print(rpc.bdev.construct_malloc_bdev(args.client,
Loading