Skip to content

Commit

Permalink
Trash RBD image on namespace deletion.
Browse files Browse the repository at this point in the history
Fixes ceph#953

Signed-off-by: Gil Bregman <[email protected]>
  • Loading branch information
gbregman committed Jan 13, 2025
1 parent e7153ce commit 0c9bd9d
Show file tree
Hide file tree
Showing 9 changed files with 441 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ jobs:
strategy:
fail-fast: false
matrix:
test: ["cli", "cli_change_lb", "cli_change_keys", "cli_change_ns_visibility", "state", "multi_gateway", "server", "grpc", "omap_lock", "log_files", "nsid", "psk", "dhchap", "subsys_grp_name_append"]
test: ["cli", "cli_change_lb", "cli_change_keys", "cli_change_ns_visibility", "cli_trash_rbd", "state", "multi_gateway", "server", "grpc", "omap_lock", "log_files", "nsid", "psk", "dhchap", "subsys_grp_name_append"]
runs-on: ubuntu-latest
env:
HUGEPAGES: 512 # for multi gateway test, approx 256 per gateway instance
Expand Down
1 change: 1 addition & 0 deletions ceph-nvmeof.conf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ timeout = 60.0

# Example value: {"max_queue_depth" : 16, "max_io_size" : 4194304, "io_unit_size" : 1048576, "zcopy" : false}
transport_tcp_options = {"in_capsule_data_size" : 8192, "max_io_qpairs_per_ctrlr" : 7}
#iobuf_options = {"small_pool_count" : 8192, "large_pool_count" : 1024, "small_bufsize" : 8192, "large_bufsize" : 135168}

[monitor]
#timeout = 1.0
Expand Down
26 changes: 24 additions & 2 deletions control/cephutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ def get_number_created_gateways(self, pool, group, caching=True):
self.rebalance_supported = True
self.rebalance_ana_group = data.get("rebalance_ana_group", None)
self.num_gws = data.get("num gws", None)
self.logger.info(f"Rebalance ana_group: {self.rebalance_ana_group},\
num-gws: {self.num_gws} ")
self.logger.info(f"Rebalance ana_group: {self.rebalance_ana_group}, "
f"num-gws: {self.num_gws}")
else:
self.rebalance_supported = False
pos = conv_str.find("[")
Expand Down Expand Up @@ -191,6 +191,28 @@ def create_image(self, pool_name, image_name, size) -> bool:

return True

def delete_image(self, pool_name, image_name) -> bool:
if not pool_name and not image_name:
return True

if not self.pool_exists(pool_name):
self.logger.warning(f"Pool {pool_name} doesn't exist, can't delete RBD image")
return True

with rados.Rados(conffile=self.ceph_conf, rados_id=self.rados_id) as cluster:
with cluster.open_ioctx(pool_name) as ioctx:
rbd_inst = rbd.RBD()
try:
rbd_inst.remove(ioctx, image_name)
except rbd.ImageNotFound:
self.logger.warning(f"Image {pool_name}/{image_name} is not found")
return True
except (rbd.ImageBusy, rbd.ImageHasSnapshots):
self.logger.exception(f"Can't delete image {pool_name}/{image_name}")
return False

return True

def get_image_size(self, pool_name, image_name) -> int:
image_size = 0
if not self.pool_exists(pool_name):
Expand Down
28 changes: 21 additions & 7 deletions control/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,10 @@ def ns_add(self, args):
self.cli.parser.error("--size argument is not allowed for add command when "
"RBD image creation is disabled")

if args.rbd_trash_image_on_delete and not args.rbd_create_image:
self.cli.parser.error("Can't trash associated RBD image on delete if it wasn't "
"created automatically by the gateway")

req = pb2.namespace_add_req(rbd_pool_name=args.rbd_pool,
rbd_image_name=args.rbd_image,
subsystem_nqn=args.subsystem,
Expand All @@ -1736,7 +1740,8 @@ def ns_add(self, args):
create_image=args.rbd_create_image,
size=img_size,
force=args.force,
no_auto_visible=args.no_auto_visible)
no_auto_visible=args.no_auto_visible,
trash_image=args.rbd_trash_image_on_delete)
try:
ret = self.stub.namespace_add(req)
except Exception as ex:
Expand Down Expand Up @@ -1776,7 +1781,7 @@ def ns_del(self, args):

try:
ret = self.stub.namespace_delete(pb2.namespace_delete_req(
subsystem_nqn=args.subsystem, nsid=args.nsid))
subsystem_nqn=args.subsystem, nsid=args.nsid, are_you_sure=args.are_you_sure))
except Exception as ex:
ret = pb2.req_status(status=errno.EINVAL,
error_message=f"Failure deleting namespace:\n{ex}")
Expand Down Expand Up @@ -1925,15 +1930,15 @@ def ns_list(self, args):
namespaces_list = []
for ns in namespaces_info.namespaces:
if args.subsystem == GatewayUtils.ALL_SUBSYSTEMS:
if not ns.subsystem_nqn:
if not ns.ns_subsystem_nqn:
err_func(f"Got namespace with ID {ns.nsid} on an unknown subsystem")
subsys_nqn = "<n/a>"
else:
subsys_nqn = ns.subsystem_nqn
subsys_nqn = ns.ns_subsystem_nqn
else:
if ns.subsystem_nqn and ns.subsystem_nqn != args.subsystem:
if ns.ns_subsystem_nqn and ns.ns_subsystem_nqn != args.subsystem:
err_func(f"Got a namespace with ID {ns.nsid} in subsystem "
f"{ns.subsystem_nqn} which is different than the "
f"{ns.ns_subsystem_nqn} which is different than the "
f"requested one {args.subsystem}")
return errno.ENODEV
subsys_nqn = namespaces_info.subsystem_nqn
Expand All @@ -1960,10 +1965,11 @@ def ns_list(self, args):
else:
visibility = "Restrictive"

trash_msg = "\n(trash on deletion)" if ns.trash_image else ""
namespaces_list.append([subsys_nqn,
ns.nsid,
break_string(ns.bdev_name, "-", 2),
f"{ns.rbd_pool_name}/{ns.rbd_image_name}",
f"{ns.rbd_pool_name}/{ns.rbd_image_name}{trash_msg}",
self.format_size(ns.rbd_image_size),
self.format_size(ns.block_size),
break_string(ns.uuid, "-", 3),
Expand Down Expand Up @@ -2454,12 +2460,20 @@ def ns_change_visibility(self, args):
help="Make the namespace visible only to specific hosts",
action='store_true',
required=False),
argument("--rbd-trash-image-on-delete",
help="When deleting the namespace, trash associated RBD image. "
"Only applies to images created automatically by the gateway",
action='store_true',
required=False),
]
ns_del_args_list = ns_common_args + [
argument("--nsid",
help="Namespace ID",
type=int,
required=True),
argument("--are-you-sure",
help="If you choose to delete the associated RBD image, set this to \"yes\"",
required=False),
]
ns_resize_args_list = ns_common_args + [
argument("--nsid",
Expand Down
Loading

0 comments on commit 0c9bd9d

Please sign in to comment.