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 = {