Skip to content

Commit 28d7a37

Browse files
Ming Leiaxboe
authored andcommitted
ublk: add helper of __ublk_fetch()
Add helper __ublk_fetch() for refactoring ublk_fetch(). Meantime move ublk_config_io_buf() out of __ublk_fetch() to make the code structure cleaner. Reviewed-by: Caleb Sander Mateos <csander@purestorage.com> Signed-off-by: Ming Lei <ming.lei@redhat.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3443bab commit 28d7a37

1 file changed

Lines changed: 24 additions & 22 deletions

File tree

drivers/block/ublk_drv.c

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,39 +2234,41 @@ static int ublk_check_fetch_buf(const struct ublk_device *ub, __u64 buf_addr)
22342234
return 0;
22352235
}
22362236

2237-
static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
2238-
struct ublk_io *io, __u64 buf_addr)
2237+
static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
2238+
struct ublk_io *io)
22392239
{
2240-
int ret = 0;
2241-
2242-
/*
2243-
* When handling FETCH command for setting up ublk uring queue,
2244-
* ub->mutex is the innermost lock, and we won't block for handling
2245-
* FETCH, so it is fine even for IO_URING_F_NONBLOCK.
2246-
*/
2247-
mutex_lock(&ub->mutex);
22482240
/* UBLK_IO_FETCH_REQ is only allowed before dev is setup */
2249-
if (ublk_dev_ready(ub)) {
2250-
ret = -EBUSY;
2251-
goto out;
2252-
}
2241+
if (ublk_dev_ready(ub))
2242+
return -EBUSY;
22532243

22542244
/* allow each command to be FETCHed at most once */
2255-
if (io->flags & UBLK_IO_FLAG_ACTIVE) {
2256-
ret = -EINVAL;
2257-
goto out;
2258-
}
2245+
if (io->flags & UBLK_IO_FLAG_ACTIVE)
2246+
return -EINVAL;
22592247

22602248
WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV);
22612249

22622250
ublk_fill_io_cmd(io, cmd);
2263-
ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL);
2264-
if (ret)
2265-
goto out;
22662251

22672252
WRITE_ONCE(io->task, get_task_struct(current));
22682253
ublk_mark_io_ready(ub);
2269-
out:
2254+
2255+
return 0;
2256+
}
2257+
2258+
static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub,
2259+
struct ublk_io *io, __u64 buf_addr)
2260+
{
2261+
int ret;
2262+
2263+
/*
2264+
* When handling FETCH command for setting up ublk uring queue,
2265+
* ub->mutex is the innermost lock, and we won't block for handling
2266+
* FETCH, so it is fine even for IO_URING_F_NONBLOCK.
2267+
*/
2268+
mutex_lock(&ub->mutex);
2269+
ret = __ublk_fetch(cmd, ub, io);
2270+
if (!ret)
2271+
ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL);
22702272
mutex_unlock(&ub->mutex);
22712273
return ret;
22722274
}

0 commit comments

Comments
 (0)