From 7c624c36c9c725f8e641815433dd14eaf6a43116 Mon Sep 17 00:00:00 2001 From: Gil Bregman Date: Tue, 28 May 2024 16:54:22 +0300 Subject: [PATCH] Use size in MiBs, not bytes, in namespace_resize gRRPC call Fixes: #685 Signed-off-by: Gil Bregman --- control/cli.py | 3 ++- control/grpc.py | 11 +++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/control/cli.py b/control/cli.py index e2167f7a..d82f385b 100644 --- a/control/cli.py +++ b/control/cli.py @@ -1381,6 +1381,7 @@ def ns_resize(self, args): mib = 1024 * 1024 if ns_size % mib: self.cli.parser.error("size value must be aligned to MiBs") + ns_size //= mib try: ret = self.stub.namespace_resize(pb2.namespace_resize_req(subsystem_nqn=args.subsystem, nsid=args.nsid, @@ -1396,7 +1397,7 @@ def ns_resize(self, args): ns_id_str = f"with UUID {args.uuid}" else: assert False - sz_str = self.format_size(ns_size) + sz_str = self.format_size(ns_size * mib) out_func(f"Resizing namespace {ns_id_str} in {args.subsystem} to {sz_str}: Successful") else: err_func(f"{ret.error_message}") diff --git a/control/grpc.py b/control/grpc.py index 78f500de..f94c0c22 100644 --- a/control/grpc.py +++ b/control/grpc.py @@ -353,7 +353,7 @@ def create_bdev(self, anagrp: int, name, uuid, rbd_pool_name, rbd_image_name, bl def resize_bdev(self, bdev_name, new_size, peer_msg = ""): """Resizes a bdev.""" - self.logger.info(f"Received request to resize bdev {bdev_name} to {new_size} bytes{peer_msg}") + self.logger.info(f"Received request to resize bdev {bdev_name} to {new_size} MiB{peer_msg}") rbd_pool_name = None rbd_image_name = None bdev_info = self.get_bdev_info(bdev_name, True) @@ -372,16 +372,15 @@ def resize_bdev(self, bdev_name, new_size, peer_msg = ""): if rbd_pool_name and rbd_image_name: try: current_size = self.ceph_utils.get_image_size(rbd_pool_name, rbd_image_name) - if current_size > new_size: + if current_size > new_size * 1024 * 1024: return pb2.req_status(status=errno.EINVAL, - error_message=f"new size {new_size} bytes is smaller than current size {current_size} bytes") + error_message=f"new size {new_size * 1024 * 1024} bytes is smaller than current size {current_size} bytes") except Exception as ex: self.logger.warning(f"Error trying to get the size of image {rbd_pool_name}/{rbd_image_name}, won't check size for shrinkage:\n{ex}") pass with self.rpc_lock: try: - new_size //= (1024 * 1024) # spdk wants the size in MiBs ret = rpc_bdev.bdev_rbd_resize( self.spdk_rpc_client, name=bdev_name, @@ -1573,10 +1572,6 @@ def namespace_resize(self, request, context=None): return pb2.req_status(status=errno.EINVAL, error_message=f"Failure resizing namespace {nsid_msg}on {request.subsystem_nqn}: New size must be positive") - if request.new_size % (1024 * 1024): - return pb2.req_status(status=errno.EINVAL, - error_message=f"Failure resizing namespace {nsid_msg}on {request.subsystem_nqn}: new size must be aligned to MiBs") - find_ret = self.find_namespace_and_bdev_name(request.subsystem_nqn, request.nsid, request.uuid, True, "Failure resizing namespace") if not find_ret[0]: errmsg = f"Failure resizing namespace {nsid_msg}on {request.subsystem_nqn}: Can't find namespace"