Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ublk: consolidate nr_io_ready and nr_queues_ready

ublk_mark_io_ready() tracks whether all the ublk_device's I/Os have been
fetched by incrementing ublk_queue's nr_io_ready count and incrementing
ublk_device's nr_queues_ready count if the whole queue is ready.
Simplify the logic by just tracking the total number of fetched I/Os on
each ublk_device. When this count reaches nr_hw_queues * queue_depth,
the ublk_device is ready to receive I/O.

Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
Reviewed-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Caleb Sander Mateos and committed by
Jens Axboe
97e8ba31 e0ed2bca

+12 -16
+12 -16
drivers/block/ublk_drv.c
··· 201 201 bool force_abort; 202 202 bool canceling; 203 203 bool fail_io; /* copy of dev->state == UBLK_S_DEV_FAIL_IO */ 204 - unsigned short nr_io_ready; /* how many ios setup */ 205 204 spinlock_t cancel_lock; 206 205 struct ublk_device *dev; 207 206 struct ublk_io ios[]; ··· 233 234 struct ublk_params params; 234 235 235 236 struct completion completion; 236 - unsigned int nr_queues_ready; 237 + u32 nr_io_ready; 237 238 bool unprivileged_daemons; 238 239 struct mutex cancel_mutex; 239 240 bool canceling; ··· 1498 1499 { 1499 1500 int i; 1500 1501 1501 - /* All old ioucmds have to be completed */ 1502 - ubq->nr_io_ready = 0; 1503 - 1504 1502 for (i = 0; i < ubq->q_depth; i++) { 1505 1503 struct ublk_io *io = &ubq->ios[i]; 1506 1504 ··· 1546 1550 1547 1551 /* set to NULL, otherwise new tasks cannot mmap io_cmd_buf */ 1548 1552 ub->mm = NULL; 1549 - ub->nr_queues_ready = 0; 1553 + ub->nr_io_ready = 0; 1550 1554 ub->unprivileged_daemons = false; 1551 1555 ub->ublksrv_tgid = -1; 1552 1556 } ··· 1844 1848 ublk_cancel_cmd(ubq, pdu->tag, issue_flags); 1845 1849 } 1846 1850 1847 - static inline bool ublk_queue_ready(struct ublk_queue *ubq) 1851 + static inline bool ublk_dev_ready(const struct ublk_device *ub) 1848 1852 { 1849 - return ubq->nr_io_ready == ubq->q_depth; 1853 + u32 total = (u32)ub->dev_info.nr_hw_queues * ub->dev_info.queue_depth; 1854 + 1855 + return ub->nr_io_ready == total; 1850 1856 } 1851 1857 1852 1858 static void ublk_cancel_queue(struct ublk_queue *ubq) ··· 1972 1974 } 1973 1975 1974 1976 /* device can only be started after all IOs are ready */ 1975 - static void ublk_mark_io_ready(struct ublk_device *ub, struct ublk_queue *ubq) 1977 + static void ublk_mark_io_ready(struct ublk_device *ub) 1976 1978 __must_hold(&ub->mutex) 1977 1979 { 1978 - ubq->nr_io_ready++; 1979 - if (ublk_queue_ready(ubq)) 1980 - ub->nr_queues_ready++; 1981 1980 if (!ub->unprivileged_daemons && !capable(CAP_SYS_ADMIN)) 1982 1981 ub->unprivileged_daemons = true; 1983 1982 1984 - if (ub->nr_queues_ready == ub->dev_info.nr_hw_queues) { 1983 + ub->nr_io_ready++; 1984 + if (ublk_dev_ready(ub)) { 1985 1985 /* now we are ready for handling ublk io request */ 1986 1986 ublk_reset_io_flags(ub); 1987 1987 complete_all(&ub->completion); ··· 2185 2189 * FETCH, so it is fine even for IO_URING_F_NONBLOCK. 2186 2190 */ 2187 2191 mutex_lock(&ub->mutex); 2188 - /* UBLK_IO_FETCH_REQ is only allowed before queue is setup */ 2189 - if (ublk_queue_ready(ubq)) { 2192 + /* UBLK_IO_FETCH_REQ is only allowed before dev is setup */ 2193 + if (ublk_dev_ready(ub)) { 2190 2194 ret = -EBUSY; 2191 2195 goto out; 2192 2196 } ··· 2205 2209 goto out; 2206 2210 2207 2211 WRITE_ONCE(io->task, get_task_struct(current)); 2208 - ublk_mark_io_ready(ub, ubq); 2212 + ublk_mark_io_ready(ub); 2209 2213 out: 2210 2214 mutex_unlock(&ub->mutex); 2211 2215 return ret;