Skip to content

Commit 5ac6024

Browse files
ps-ushankaraxboe
authored andcommitted
ublk: set_params: properly check if parameters can be applied
The parameters set by the set_params call are only applied to the block device in the start_dev call. So if a device has already been started, a subsequently issued set_params on that device will not have the desired effect, and should return an error. There is an existing check for this - set_params fails on devices in the LIVE state. But this check is not sufficient to cover the recovery case. In this case, the device will be in the QUIESCED or FAIL_IO states, so set_params will succeed. But this success is misleading, because the parameters will not be applied, since the device has already been started (by a previous ublk server). The bit UB_STATE_USED is set on completion of the start_dev; use it to detect and fail set_params commands which arrive too late to be applied (after start_dev). Signed-off-by: Uday Shankar <ushankar@purestorage.com> Fixes: 0aa7317 ("ublk_drv: add SET_PARAMS/GET_PARAMS control command") Reviewed-by: Ming Lei <ming.lei@redhat.com> Link: https://lore.kernel.org/r/20250304-set_params-v1-1-17b5e0887606@purestorage.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent b654f7a commit 5ac6024

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/block/ublk_drv.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,9 +2715,12 @@ static int ublk_ctrl_set_params(struct ublk_device *ub,
27152715
if (ph.len > sizeof(struct ublk_params))
27162716
ph.len = sizeof(struct ublk_params);
27172717

2718-
/* parameters can only be changed when device isn't live */
27192718
mutex_lock(&ub->mutex);
2720-
if (ub->dev_info.state == UBLK_S_DEV_LIVE) {
2719+
if (test_bit(UB_STATE_USED, &ub->state)) {
2720+
/*
2721+
* Parameters can only be changed when device hasn't
2722+
* been started yet
2723+
*/
27212724
ret = -EACCES;
27222725
} else if (copy_from_user(&ub->params, argp, ph.len)) {
27232726
ret = -EFAULT;

0 commit comments

Comments
 (0)