From 8299c64e861d63cb90024728b7af154cca39d4b0 Mon Sep 17 00:00:00 2001 From: Sandy Kaur Date: Tue, 29 Nov 2022 10:14:38 -0500 Subject: [PATCH] Make bdev name optional Signed-off-by: Sandy Kaur --- control/cli.py | 10 +++++----- control/grpc.py | 16 +++++++++------- control/state.py | 3 +++ proto/gateway.proto | 11 ++++++++--- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/control/cli.py b/control/cli.py index 6fdadd09..4b6bedc5 100644 --- a/control/cli.py +++ b/control/cli.py @@ -127,8 +127,8 @@ def connect(self, config): @cli.cmd([ argument("-i", "--image", help="RBD image name", required=True), - argument("-p", "--pool", help="Ceph pool name", required=True), - argument("-b", "--bdev", help="Bdev name", required=True), + argument("-p", "--pool", help="RBD pool name", required=True), + argument("-b", "--bdev", help="Bdev name"), argument("-s", "--block-size", help="Block size", @@ -140,13 +140,13 @@ def create_bdev(self, args): try: req = pb2.create_bdev_req( - ceph_pool_name=args.pool, - rbd_name=args.image, + rbd_pool_name=args.pool, + rbd_image_name=args.image, block_size=args.block_size, bdev_name=args.bdev, ) ret = self.stub.create_bdev(req) - self.logger.info(f"Created bdev {args.bdev}: {ret.status}") + self.logger.info(f"Created bdev {ret.bdev_name}: {ret.status}") except Exception as error: self.logger.error(f"Failed to create bdev: \n {error}") diff --git a/control/grpc.py b/control/grpc.py index 5500142f..4931a36e 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -10,6 +10,7 @@ import socket import grpc import json +import uuid import logging from google.protobuf import json_format from .generated import gateway_pb2 as pb2 @@ -45,16 +46,17 @@ def __init__(self, config, gateway_state, spdk_rpc, spdk_rpc_client): def create_bdev(self, request, context=None): """Creates a bdev from an RBD image.""" + name = str(uuid.uuid4()) if not request.bdev_name else request.bdev_name self.logger.info( - f"Received request to create bdev {request.bdev_name} from" - f" {request.ceph_pool_name}/{request.rbd_name}" + f"Received request to create bdev {name} from" + f" {request.rbd_pool_name}/{request.rbd_image_name}" f" with block size {request.block_size}") try: bdev_name = self.spdk_rpc.bdev.bdev_rbd_create( self.spdk_rpc_client, - name=request.bdev_name, - pool_name=request.ceph_pool_name, - rbd_name=request.rbd_name, + name=name, + pool_name=request.rbd_pool_name, + rbd_name=request.rbd_image_name, block_size=request.block_size, ) self.logger.info(f"create_bdev: {bdev_name}") @@ -63,7 +65,7 @@ def create_bdev(self, request, context=None): if context: context.set_code(grpc.StatusCode.INTERNAL) context.set_details(f"{ex}") - return pb2.req_status() + return pb2.bdev() if context: # Update gateway state @@ -76,7 +78,7 @@ def create_bdev(self, request, context=None): f"Error persisting create_bdev {bdev_name}: {ex}") raise - return pb2.req_status(status=True) + return pb2.bdev(bdev_name=bdev_name, status=True) def delete_bdev(self, request, context=None): """Deletes a bdev.""" diff --git a/control/state.py b/control/state.py index ac59ac0b..5f0d33df 100644 --- a/control/state.py +++ b/control/state.py @@ -178,7 +178,10 @@ def _restore_bdevs(self, omap_dict, callback): for (key, val) in omap_dict.items(): if key.startswith(self.BDEV_PREFIX): + # Get bdev_name from end of key + bdev_name = key.split("_", 1)[1] req = json_format.Parse(val, pb2.create_bdev_req()) + req.bdev_name = bdev_name callback(req) def add_namespace(self, subsystem_nqn: str, nsid: str, val: str): diff --git a/proto/gateway.proto b/proto/gateway.proto index c63d8d59..e8670e62 100644 --- a/proto/gateway.proto +++ b/proto/gateway.proto @@ -12,7 +12,7 @@ syntax = "proto3"; service Gateway { // Creates a bdev from an RBD image - rpc create_bdev(create_bdev_req) returns (req_status) {} + rpc create_bdev(create_bdev_req) returns (bdev) {} // Deletes a bdev rpc delete_bdev(delete_bdev_req) returns (req_status) {} @@ -49,8 +49,8 @@ service Gateway { message create_bdev_req { string bdev_name = 1; - string ceph_pool_name = 2; - string rbd_name = 3; + string rbd_pool_name = 2; + string rbd_image_name = 3; int32 block_size = 4; } @@ -111,6 +111,11 @@ message get_subsystems_req { // Return messages +message bdev { + string bdev_name = 1; + bool status = 2; +} + message req_status { bool status = 1; }