Lines Matching full:req
76 static ssize_t nvmet_file_submit_bvec(struct nvmet_req *req, loff_t pos, in nvmet_file_submit_bvec() argument
79 struct kiocb *iocb = &req->f.iocb; in nvmet_file_submit_bvec()
84 if (req->cmd->rw.opcode == nvme_cmd_write) { in nvmet_file_submit_bvec()
85 if (req->cmd->rw.control & cpu_to_le16(NVME_RW_FUA)) in nvmet_file_submit_bvec()
87 call_iter = req->ns->file->f_op->write_iter; in nvmet_file_submit_bvec()
90 call_iter = req->ns->file->f_op->read_iter; in nvmet_file_submit_bvec()
94 iov_iter_bvec(&iter, rw, req->f.bvec, nr_segs, count); in nvmet_file_submit_bvec()
97 iocb->ki_filp = req->ns->file; in nvmet_file_submit_bvec()
105 struct nvmet_req *req = container_of(iocb, struct nvmet_req, f.iocb); in nvmet_file_io_done() local
108 if (req->f.bvec != req->inline_bvec) { in nvmet_file_io_done()
109 if (likely(req->f.mpool_alloc == false)) in nvmet_file_io_done()
110 kfree(req->f.bvec); in nvmet_file_io_done()
112 mempool_free(req->f.bvec, req->ns->bvec_pool); in nvmet_file_io_done()
115 if (unlikely(ret != req->transfer_len)) in nvmet_file_io_done()
116 status = errno_to_nvme_status(req, ret); in nvmet_file_io_done()
117 nvmet_req_complete(req, status); in nvmet_file_io_done()
120 static bool nvmet_file_execute_io(struct nvmet_req *req, int ki_flags) in nvmet_file_execute_io() argument
122 ssize_t nr_bvec = req->sg_cnt; in nvmet_file_execute_io()
131 if (req->f.mpool_alloc && nr_bvec > NVMET_MAX_MPOOL_BVEC) in nvmet_file_execute_io()
134 pos = le64_to_cpu(req->cmd->rw.slba) << req->ns->blksize_shift; in nvmet_file_execute_io()
135 if (unlikely(pos + req->transfer_len > req->ns->size)) { in nvmet_file_execute_io()
136 nvmet_req_complete(req, errno_to_nvme_status(req, -ENOSPC)); in nvmet_file_execute_io()
140 memset(&req->f.iocb, 0, sizeof(struct kiocb)); in nvmet_file_execute_io()
141 for_each_sg(req->sg, sg, req->sg_cnt, i) { in nvmet_file_execute_io()
142 bvec_set_page(&req->f.bvec[bv_cnt], sg_page(sg), sg->length, in nvmet_file_execute_io()
144 len += req->f.bvec[bv_cnt].bv_len; in nvmet_file_execute_io()
145 total_len += req->f.bvec[bv_cnt].bv_len; in nvmet_file_execute_io()
152 ret = nvmet_file_submit_bvec(req, pos, bv_cnt, len, 0); in nvmet_file_execute_io()
163 if (WARN_ON_ONCE(total_len != req->transfer_len)) { in nvmet_file_execute_io()
178 req->f.iocb.ki_complete = nvmet_file_io_done; in nvmet_file_execute_io()
180 ret = nvmet_file_submit_bvec(req, pos, bv_cnt, total_len, ki_flags); in nvmet_file_execute_io()
201 nvmet_file_io_done(&req->f.iocb, ret); in nvmet_file_execute_io()
207 struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); in nvmet_file_buffered_io_work() local
209 nvmet_file_execute_io(req, 0); in nvmet_file_buffered_io_work()
212 static void nvmet_file_submit_buffered_io(struct nvmet_req *req) in nvmet_file_submit_buffered_io() argument
214 INIT_WORK(&req->f.work, nvmet_file_buffered_io_work); in nvmet_file_submit_buffered_io()
215 queue_work(buffered_io_wq, &req->f.work); in nvmet_file_submit_buffered_io()
218 static void nvmet_file_execute_rw(struct nvmet_req *req) in nvmet_file_execute_rw() argument
220 ssize_t nr_bvec = req->sg_cnt; in nvmet_file_execute_rw()
222 if (!nvmet_check_transfer_len(req, nvmet_rw_data_len(req))) in nvmet_file_execute_rw()
225 if (!req->sg_cnt || !nr_bvec) { in nvmet_file_execute_rw()
226 nvmet_req_complete(req, 0); in nvmet_file_execute_rw()
231 req->f.bvec = kmalloc_array(nr_bvec, sizeof(struct bio_vec), in nvmet_file_execute_rw()
234 req->f.bvec = req->inline_bvec; in nvmet_file_execute_rw()
236 if (unlikely(!req->f.bvec)) { in nvmet_file_execute_rw()
238 req->f.bvec = mempool_alloc(req->ns->bvec_pool, GFP_KERNEL); in nvmet_file_execute_rw()
239 req->f.mpool_alloc = true; in nvmet_file_execute_rw()
241 req->f.mpool_alloc = false; in nvmet_file_execute_rw()
243 if (req->ns->buffered_io) { in nvmet_file_execute_rw()
244 if (likely(!req->f.mpool_alloc) && in nvmet_file_execute_rw()
245 (req->ns->file->f_mode & FMODE_NOWAIT) && in nvmet_file_execute_rw()
246 nvmet_file_execute_io(req, IOCB_NOWAIT)) in nvmet_file_execute_rw()
248 nvmet_file_submit_buffered_io(req); in nvmet_file_execute_rw()
250 nvmet_file_execute_io(req, 0); in nvmet_file_execute_rw()
253 u16 nvmet_file_flush(struct nvmet_req *req) in nvmet_file_flush() argument
255 return errno_to_nvme_status(req, vfs_fsync(req->ns->file, 1)); in nvmet_file_flush()
260 struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); in nvmet_file_flush_work() local
262 nvmet_req_complete(req, nvmet_file_flush(req)); in nvmet_file_flush_work()
265 static void nvmet_file_execute_flush(struct nvmet_req *req) in nvmet_file_execute_flush() argument
267 if (!nvmet_check_transfer_len(req, 0)) in nvmet_file_execute_flush()
269 INIT_WORK(&req->f.work, nvmet_file_flush_work); in nvmet_file_execute_flush()
270 queue_work(nvmet_wq, &req->f.work); in nvmet_file_execute_flush()
273 static void nvmet_file_execute_discard(struct nvmet_req *req) in nvmet_file_execute_discard() argument
282 for (i = 0; i <= le32_to_cpu(req->cmd->dsm.nr); i++) { in nvmet_file_execute_discard()
283 status = nvmet_copy_from_sgl(req, i * sizeof(range), &range, in nvmet_file_execute_discard()
288 offset = le64_to_cpu(range.slba) << req->ns->blksize_shift; in nvmet_file_execute_discard()
290 len <<= req->ns->blksize_shift; in nvmet_file_execute_discard()
291 if (offset + len > req->ns->size) { in nvmet_file_execute_discard()
292 req->error_slba = le64_to_cpu(range.slba); in nvmet_file_execute_discard()
293 status = errno_to_nvme_status(req, -ENOSPC); in nvmet_file_execute_discard()
297 ret = vfs_fallocate(req->ns->file, mode, offset, len); in nvmet_file_execute_discard()
299 req->error_slba = le64_to_cpu(range.slba); in nvmet_file_execute_discard()
300 status = errno_to_nvme_status(req, ret); in nvmet_file_execute_discard()
305 nvmet_req_complete(req, status); in nvmet_file_execute_discard()
310 struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); in nvmet_file_dsm_work() local
312 switch (le32_to_cpu(req->cmd->dsm.attributes)) { in nvmet_file_dsm_work()
314 nvmet_file_execute_discard(req); in nvmet_file_dsm_work()
320 nvmet_req_complete(req, 0); in nvmet_file_dsm_work()
325 static void nvmet_file_execute_dsm(struct nvmet_req *req) in nvmet_file_execute_dsm() argument
327 if (!nvmet_check_data_len_lte(req, nvmet_dsm_len(req))) in nvmet_file_execute_dsm()
329 INIT_WORK(&req->f.work, nvmet_file_dsm_work); in nvmet_file_execute_dsm()
330 queue_work(nvmet_wq, &req->f.work); in nvmet_file_execute_dsm()
335 struct nvmet_req *req = container_of(w, struct nvmet_req, f.work); in nvmet_file_write_zeroes_work() local
336 struct nvme_write_zeroes_cmd *write_zeroes = &req->cmd->write_zeroes; in nvmet_file_write_zeroes_work()
342 offset = le64_to_cpu(write_zeroes->slba) << req->ns->blksize_shift; in nvmet_file_write_zeroes_work()
344 req->ns->blksize_shift); in nvmet_file_write_zeroes_work()
346 if (unlikely(offset + len > req->ns->size)) { in nvmet_file_write_zeroes_work()
347 nvmet_req_complete(req, errno_to_nvme_status(req, -ENOSPC)); in nvmet_file_write_zeroes_work()
351 ret = vfs_fallocate(req->ns->file, mode, offset, len); in nvmet_file_write_zeroes_work()
352 nvmet_req_complete(req, ret < 0 ? errno_to_nvme_status(req, ret) : 0); in nvmet_file_write_zeroes_work()
355 static void nvmet_file_execute_write_zeroes(struct nvmet_req *req) in nvmet_file_execute_write_zeroes() argument
357 if (!nvmet_check_transfer_len(req, 0)) in nvmet_file_execute_write_zeroes()
359 INIT_WORK(&req->f.work, nvmet_file_write_zeroes_work); in nvmet_file_execute_write_zeroes()
360 queue_work(nvmet_wq, &req->f.work); in nvmet_file_execute_write_zeroes()
363 u16 nvmet_file_parse_io_cmd(struct nvmet_req *req) in nvmet_file_parse_io_cmd() argument
365 switch (req->cmd->common.opcode) { in nvmet_file_parse_io_cmd()
368 req->execute = nvmet_file_execute_rw; in nvmet_file_parse_io_cmd()
371 req->execute = nvmet_file_execute_flush; in nvmet_file_parse_io_cmd()
374 req->execute = nvmet_file_execute_dsm; in nvmet_file_parse_io_cmd()
377 req->execute = nvmet_file_execute_write_zeroes; in nvmet_file_parse_io_cmd()
380 return nvmet_report_invalid_opcode(req); in nvmet_file_parse_io_cmd()