Skip to content

Commit 5058a62

Browse files
calebsanderaxboe
authored andcommitted
ublk: check for unprivileged daemon on each I/O fetch
Commit ab03a61 ("ublk: have a per-io daemon instead of a per-queue daemon") allowed each ublk I/O to have an independent daemon task. However, nr_privileged_daemon is only computed based on whether the last I/O fetched in each ublk queue has an unprivileged daemon task. Fix this by checking whether every fetched I/O's daemon is privileged. Change nr_privileged_daemon from a count of queues to a boolean indicating whether any I/Os have an unprivileged daemon. Signed-off-by: Caleb Sander Mateos <[email protected]> Fixes: ab03a61 ("ublk: have a per-io daemon instead of a per-queue daemon") Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 212c928 commit 5058a62

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

drivers/block/ublk_drv.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ struct ublk_device {
235235

236236
struct completion completion;
237237
unsigned int nr_queues_ready;
238-
unsigned int nr_privileged_daemon;
238+
bool unprivileged_daemons;
239239
struct mutex cancel_mutex;
240240
bool canceling;
241241
pid_t ublksrv_tgid;
@@ -1551,7 +1551,7 @@ static void ublk_reset_ch_dev(struct ublk_device *ub)
15511551
/* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */
15521552
ub->mm = NULL;
15531553
ub->nr_queues_ready = 0;
1554-
ub->nr_privileged_daemon = 0;
1554+
ub->unprivileged_daemons = false;
15551555
ub->ublksrv_tgid = -1;
15561556
}
15571557

@@ -1978,12 +1978,10 @@ static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq)
19781978
__must_hold(&ub->mutex)
19791979
{
19801980
ubq->nr_io_ready++;
1981-
if (ublk_queue_ready(ubq)) {
1981+
if (ublk_queue_ready(ubq))
19821982
ub->nr_queues_ready++;
1983-
1984-
if (capable(CAP_SYS_ADMIN))
1985-
ub->nr_privileged_daemon++;
1986-
}
1983+
if (!ub->unprivileged_daemons && !capable(CAP_SYS_ADMIN))
1984+
ub->unprivileged_daemons = true;
19871985

19881986
if (ub->nr_queues_ready == ub->dev_info.nr_hw_queues) {
19891987
/* now we are ready for handling ublk io request */
@@ -2878,8 +2876,8 @@ static int ublk_ctrl_start_dev(struct ublk_device *ub,
28782876

28792877
ublk_apply_params(ub);
28802878

2881-
/* don't probe partitions if any one ubq daemon is un-trusted */
2882-
if (ub->nr_privileged_daemon != ub->nr_queues_ready)
2879+
/* don't probe partitions if any daemon task is un-trusted */
2880+
if (ub->unprivileged_daemons)
28832881
set_bit(GD_SUPPRESS_PART_SCAN, &disk->state);
28842882

28852883
ublk_get_device(ub);

0 commit comments

Comments
 (0)