Skip to content

Commit

Permalink
libublksrv: add UBLK_U_CMD_DEL_DEV_ASYNC
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ming1 committed Jul 25, 2024
1 parent b8bc26c commit be42deb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/ublk_cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions include/ublksrv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
12 changes: 12 additions & 0 deletions lib/ublksrv_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down

0 comments on commit be42deb

Please sign in to comment.