Skip to content

Commit 13fe8e6

Browse files
Ming Leiaxboe
authored andcommitted
ublk: add UBLK_CMD_DEL_DEV_ASYNC
The current command UBLK_CMD_DEL_DEV won't return until the device is released, this way looks more reliable, but makes userspace more difficult to implement, especially about orders: unmap command buffer(which holds one ublkc reference), ublkc close, io_uring_file_unregister, ublkb close. Add UBLK_CMD_DEL_DEV_ASYNC so that device deletion won't wait release, then userspace needn't worry about the above order. Actually both loop and nbd is deleted in this async way. Signed-off-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 1221b9e commit 13fe8e6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

drivers/block/ublk_drv.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,7 @@ static inline bool ublk_idr_freed(int id)
24682468
return ptr == NULL;
24692469
}
24702470

2471-
static int ublk_ctrl_del_dev(struct ublk_device **p_ub)
2471+
static int ublk_ctrl_del_dev(struct ublk_device **p_ub, bool wait)
24722472
{
24732473
struct ublk_device *ub = *p_ub;
24742474
int idx = ub->ub_number;
@@ -2502,7 +2502,7 @@ static int ublk_ctrl_del_dev(struct ublk_device **p_ub)
25022502
* - the device number is freed already, we will not find this
25032503
* device via ublk_get_device_from_id()
25042504
*/
2505-
if (wait_event_interruptible(ublk_idr_wq, ublk_idr_freed(idx)))
2505+
if (wait && wait_event_interruptible(ublk_idr_wq, ublk_idr_freed(idx)))
25062506
return -EINTR;
25072507
return 0;
25082508
}
@@ -2901,7 +2901,10 @@ static int ublk_ctrl_uring_cmd(struct io_uring_cmd *cmd,
29012901
ret = ublk_ctrl_add_dev(cmd);
29022902
break;
29032903
case UBLK_CMD_DEL_DEV:
2904-
ret = ublk_ctrl_del_dev(&ub);
2904+
ret = ublk_ctrl_del_dev(&ub, true);
2905+
break;
2906+
case UBLK_U_CMD_DEL_DEV_ASYNC:
2907+
ret = ublk_ctrl_del_dev(&ub, false);
29052908
break;
29062909
case UBLK_CMD_GET_QUEUE_AFFINITY:
29072910
ret = ublk_ctrl_get_queue_affinity(ub, cmd);

include/uapi/linux/ublk_cmd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
_IOR('u', UBLK_CMD_GET_DEV_INFO2, struct ublksrv_ctrl_cmd)
5050
#define UBLK_U_CMD_GET_FEATURES \
5151
_IOR('u', 0x13, struct ublksrv_ctrl_cmd)
52+
#define UBLK_U_CMD_DEL_DEV_ASYNC \
53+
_IOR('u', 0x14, struct ublksrv_ctrl_cmd)
5254

5355
/*
5456
* 64bits are enough now, and it should be easy to extend in case of

0 commit comments

Comments
 (0)