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: 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>

authored by

Ming Lei and committed by
Jens Axboe
28d7a371 3443bab2

+25 -23
+25 -23
drivers/block/ublk_drv.c
··· 2234 2234 return 0; 2235 2235 } 2236 2236 2237 + static int __ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub, 2238 + struct ublk_io *io) 2239 + { 2240 + /* UBLK_IO_FETCH_REQ is only allowed before dev is setup */ 2241 + if (ublk_dev_ready(ub)) 2242 + return -EBUSY; 2243 + 2244 + /* allow each command to be FETCHed at most once */ 2245 + if (io->flags & UBLK_IO_FLAG_ACTIVE) 2246 + return -EINVAL; 2247 + 2248 + WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV); 2249 + 2250 + ublk_fill_io_cmd(io, cmd); 2251 + 2252 + WRITE_ONCE(io->task, get_task_struct(current)); 2253 + ublk_mark_io_ready(ub); 2254 + 2255 + return 0; 2256 + } 2257 + 2237 2258 static int ublk_fetch(struct io_uring_cmd *cmd, struct ublk_device *ub, 2238 2259 struct ublk_io *io, __u64 buf_addr) 2239 2260 { 2240 - int ret = 0; 2261 + int ret; 2241 2262 2242 2263 /* 2243 2264 * When handling FETCH command for setting up ublk uring queue, ··· 2266 2245 * FETCH, so it is fine even for IO_URING_F_NONBLOCK. 2267 2246 */ 2268 2247 mutex_lock(&ub->mutex); 2269 - /* UBLK_IO_FETCH_REQ is only allowed before dev is setup */ 2270 - if (ublk_dev_ready(ub)) { 2271 - ret = -EBUSY; 2272 - goto out; 2273 - } 2274 - 2275 - /* allow each command to be FETCHed at most once */ 2276 - if (io->flags & UBLK_IO_FLAG_ACTIVE) { 2277 - ret = -EINVAL; 2278 - goto out; 2279 - } 2280 - 2281 - WARN_ON_ONCE(io->flags & UBLK_IO_FLAG_OWNED_BY_SRV); 2282 - 2283 - ublk_fill_io_cmd(io, cmd); 2284 - ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL); 2285 - if (ret) 2286 - goto out; 2287 - 2288 - WRITE_ONCE(io->task, get_task_struct(current)); 2289 - ublk_mark_io_ready(ub); 2290 - out: 2248 + ret = __ublk_fetch(cmd, ub, io); 2249 + if (!ret) 2250 + ret = ublk_config_io_buf(ub, io, cmd, buf_addr, NULL); 2291 2251 mutex_unlock(&ub->mutex); 2292 2252 return ret; 2293 2253 }