From be42deba59260fdc4626004e16f15dd3343c201f Mon Sep 17 00:00:00 2001 From: Ming Lei Date: Thu, 25 Jul 2024 12:46:23 +0000 Subject: [PATCH] libublksrv: add UBLK_U_CMD_DEL_DEV_ASYNC Add UBLK_U_CMD_DEL_DEV_ASYNC, so that devices can be deleted in async. This command is useful for removing stackable devices, especially one ublk device is over another ublk device. With async delete, user needn't to figure out the exact dependency between ublk devices any more for removing them. Signed-off-by: Ming Lei --- include/ublk_cmd.h | 2 ++ include/ublksrv.h | 7 +++++++ lib/ublksrv_cmd.c | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/include/ublk_cmd.h b/include/ublk_cmd.h index 3a579a19..4abddfdc 100644 --- a/include/ublk_cmd.h +++ b/include/ublk_cmd.h @@ -49,6 +49,8 @@ _IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd) #define UBLK_U_CMD_GET_FEATURES \ _IOR('u', 0x13, struct ublksrv_ctrl_cmd) +#define UBLK_U_CMD_DEL_DEV_ASYNC \ + _IOR('u', 0x14, struct ublksrv_ctrl_cmd) /* * 64bit are enough now, and it should be easy to extend in case of diff --git a/include/ublksrv.h b/include/ublksrv.h index bf14ee2a..405df600 100644 --- a/include/ublksrv.h +++ b/include/ublksrv.h @@ -424,6 +424,13 @@ extern int ublksrv_ctrl_add_dev(struct ublksrv_ctrl_dev *dev); */ extern int ublksrv_ctrl_del_dev(struct ublksrv_ctrl_dev *dev); +/** + * Delete this ublk device asynchronously by sending command to ublk driver + * + * @param dev the ublksrv control device instance + */ +extern int ublksrv_ctrl_del_dev_async(struct ublksrv_ctrl_dev *dev); + /** * Retrieve ublk device info by sending command to ublk control device * diff --git a/lib/ublksrv_cmd.c b/lib/ublksrv_cmd.c index b2e0d155..b9781f49 100644 --- a/lib/ublksrv_cmd.c +++ b/lib/ublksrv_cmd.c @@ -289,6 +289,18 @@ int ublksrv_ctrl_add_dev(struct ublksrv_ctrl_dev *dev) return ret; } +int ublksrv_ctrl_del_dev_async(struct ublksrv_ctrl_dev *dev) +{ + struct ublksrv_ctrl_cmd_data data = { + .cmd_op = UBLK_U_CMD_DEL_DEV_ASYNC, + .flags = CTRL_CMD_NO_TRANS, + }; + + ublk_un_privileged_prep_data(dev, data); + + return __ublksrv_ctrl_cmd(dev, &data); +} + int ublksrv_ctrl_del_dev(struct ublksrv_ctrl_dev *dev) { struct ublksrv_ctrl_cmd_data data = {