Skip to content

Commit

Permalink
Make bdev name optional
Browse files Browse the repository at this point in the history
Signed-off-by: Sandy Kaur <[email protected]>
  • Loading branch information
sskaur committed Nov 29, 2022
1 parent 5c1d529 commit 8299c64
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 15 deletions.
10 changes: 5 additions & 5 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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}")

Expand Down
16 changes: 9 additions & 7 deletions control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}")
Expand All @@ -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
Expand All @@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions control/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
11 changes: 8 additions & 3 deletions proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8299c64

Please sign in to comment.