Skip to content

Commit

Permalink
Merge pull request #318 from gbregman/devel
Browse files Browse the repository at this point in the history
Add a bdev resize CLI command
  • Loading branch information
gbregman authored Nov 14, 2023
2 parents 41a88dc + 844e25a commit d0b684d
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 56 deletions.
24 changes: 19 additions & 5 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ def create_bdev(self, args):
ret = self.stub.create_bdev(req)
self.logger.info(f"Created bdev {ret.bdev_name}: {ret.status}")

@cli.cmd([
argument("-b", "--bdev", help="Bdev name", required=True),
argument("-s", "--size", help="New size in MiB", type=int, required=True),
])
def resize_bdev(self, args):
"""Resizes a bdev."""
req = pb2.resize_bdev_req(
bdev_name=args.bdev,
new_size=args.size,
)
ret = self.stub.resize_bdev(req)
self.logger.info(f"Resized bdev {args.bdev}: {ret.status}")

@cli.cmd([
argument("-b", "--bdev", help="Bdev name", required=True),
argument("-f", "--force", help="Delete any namespace using this bdev before deleting bdev", action='store_true', required=False),
Expand Down Expand Up @@ -287,16 +300,17 @@ def remove_host(self, args):
])
def create_listener(self, args):
"""Creates a listener for a subsystem at a given IP/Port."""
traddr = GatewayConfig.escape_address_if_ipv6(args.traddr)
req = pb2.create_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=args.trtype,
adrfam=args.adrfam,
traddr=args.traddr,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.create_listener(req)
self.logger.info(f"Created {args.subnqn} listener: {ret.status}")
self.logger.info(f"Created {args.subnqn} listener at {traddr}:{args.trsvcid}: {ret.status}")

@cli.cmd([
argument("-n", "--subnqn", help="Subsystem NQN", required=True),
Expand All @@ -308,17 +322,17 @@ def create_listener(self, args):
])
def delete_listener(self, args):
"""Deletes a listener from a subsystem at a given IP/Port."""
traddr = GatewayConfig.escape_address_if_ipv6(args.traddr)
req = pb2.delete_listener_req(
nqn=args.subnqn,
gateway_name=args.gateway_name,
trtype=args.trtype,
adrfam=args.adrfam,
traddr=args.traddr,
traddr=traddr,
trsvcid=args.trsvcid,
)
ret = self.stub.delete_listener(req)
self.logger.info(
f"Deleted {args.traddr} from {args.subnqn}: {ret.status}")
self.logger.info(f"Deleted {traddr}:{args.trsvcid} from {args.subnqn}: {ret.status}")

@cli.cmd()
def get_subsystems(self, args):
Expand Down
23 changes: 22 additions & 1 deletion control/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,27 @@ def create_bdev_safe(self, request, context=None):
def create_bdev(self, request, context=None):
return self.execute_grpc_function(self.create_bdev_safe, request, context)

def resize_bdev_safe(self, request):
"""Resizes a bdev."""

self.logger.info(f"Received request to resize bdev {request.bdev_name} to size {request.new_size} MiB")
try:
ret = rpc_bdev.bdev_rbd_resize(
self.spdk_rpc_client,
name=request.bdev_name,
new_size=request.new_size,
)
self.logger.info(f"resize_bdev: {request.bdev_name}: {ret}")
except Exception as ex:
self.logger.error(f"resize_bdev failed with: \n {ex}")
return pb2.req_status()

return pb2.req_status(status=ret)

def resize_bdev(self, request, context=None):
with self.rpc_lock:
return self.resize_bdev_safe(request)

def get_bdev_namespaces(self, bdev_name) -> list:
ns_list = []
local_state_dict = self.gateway_state.local.get_state()
Expand Down Expand Up @@ -619,7 +640,7 @@ def create_listener_safe(self, request, context=None):
ret = True
traddr = GatewayConfig.escape_address_if_ipv6(request.traddr)
self.logger.info(f"Received request to create {request.gateway_name}"
f" {request.trtype} listener for {request.nqn} at"
f" {request.trtype} {request.adrfam} listener for {request.nqn} at"
f" {traddr}:{request.trsvcid}., context: {context}")

if self.is_discovery_nqn(request.nqn):
Expand Down
8 changes: 8 additions & 0 deletions control/proto/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ service Gateway {
// Creates a bdev from an RBD image
rpc create_bdev(create_bdev_req) returns (bdev) {}

// Resizes a bdev
rpc resize_bdev(resize_bdev_req) returns (req_status) {}

// Deletes a bdev
rpc delete_bdev(delete_bdev_req) returns (req_status) {}

Expand Down Expand Up @@ -64,6 +67,11 @@ message create_bdev_req {
optional string uuid = 5;
}

message resize_bdev_req {
string bdev_name = 1;
int32 new_size = 2;
}

message delete_bdev_req {
string bdev_name = 1;
bool force = 2;
Expand Down
Loading

0 comments on commit d0b684d

Please sign in to comment.