Skip to content

Commit

Permalink
block: freeze the queue in queue_attr_store
Browse files Browse the repository at this point in the history
queue_attr_store updates attributes used to control generating I/O, and
can cause malformed bios if changed with I/O in flight.  Freeze the queue
in common code instead of adding it to almost every attribute.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Bart Van Assche <[email protected]>
Reviewed-by: Damien Le Moal <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Reviewed-by: Chaitanya Kulkarni <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jun 19, 2024
1 parent 6b37778 commit af28141
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 3 additions & 2 deletions block/blk-mq.c
Original file line number Diff line number Diff line change
Expand Up @@ -4631,13 +4631,15 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
int ret;
unsigned long i;

if (WARN_ON_ONCE(!q->mq_freeze_depth))
return -EINVAL;

if (!set)
return -EINVAL;

if (q->nr_requests == nr)
return 0;

blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);

ret = 0;
Expand Down Expand Up @@ -4671,7 +4673,6 @@ int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr)
}

blk_mq_unquiesce_queue(q);
blk_mq_unfreeze_queue(q);

return ret;
}
Expand Down
9 changes: 2 additions & 7 deletions block/blk-sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,9 @@ static ssize_t queue_discard_max_store(struct request_queue *q,
if ((max_discard_bytes >> SECTOR_SHIFT) > UINT_MAX)
return -EINVAL;

blk_mq_freeze_queue(q);
lim = queue_limits_start_update(q);
lim.max_user_discard_sectors = max_discard_bytes >> SECTOR_SHIFT;
err = queue_limits_commit_update(q, &lim);
blk_mq_unfreeze_queue(q);

if (err)
return err;
return ret;
Expand Down Expand Up @@ -241,11 +238,9 @@ queue_max_sectors_store(struct request_queue *q, const char *page, size_t count)
if (ret < 0)
return ret;

blk_mq_freeze_queue(q);
lim = queue_limits_start_update(q);
lim.max_user_sectors = max_sectors_kb << 1;
err = queue_limits_commit_update(q, &lim);
blk_mq_unfreeze_queue(q);
if (err)
return err;
return ret;
Expand Down Expand Up @@ -585,13 +580,11 @@ static ssize_t queue_wb_lat_store(struct request_queue *q, const char *page,
* ends up either enabling or disabling wbt completely. We can't
* have IO inflight if that happens.
*/
blk_mq_freeze_queue(q);
blk_mq_quiesce_queue(q);

wbt_set_min_lat(q, val);

blk_mq_unquiesce_queue(q);
blk_mq_unfreeze_queue(q);

return count;
}
Expand Down Expand Up @@ -722,9 +715,11 @@ queue_attr_store(struct kobject *kobj, struct attribute *attr,
if (!entry->store)
return -EIO;

blk_mq_freeze_queue(q);
mutex_lock(&q->sysfs_lock);
res = entry->store(q, page, length);
mutex_unlock(&q->sysfs_lock);
blk_mq_unfreeze_queue(q);
return res;
}

Expand Down

0 comments on commit af28141

Please sign in to comment.