+ if (ll_i2sbi(inode)->ll_flags & LL_SBI_PIO)
+ io->ci_pio = !io->u.ci_rw.rw_append;
+ else
+ io->ci_pio = 0;
+}
+
+static int ll_file_io_ptask(struct cfs_ptask *ptask)
+{
+ struct cl_io_pt *pt = ptask->pt_cbdata;
+ struct file *file = pt->cip_file;
+ struct lu_env *env;
+ struct cl_io *io;
+ loff_t pos = pt->cip_pos;
+ int rc;
+ __u16 refcheck;
+ ENTRY;
+
+ env = cl_env_get(&refcheck);
+ if (IS_ERR(env))
+ RETURN(PTR_ERR(env));
+
+ CDEBUG(D_VFSTRACE, "%s: %s range: [%llu, %llu)\n",
+ file_dentry(file)->d_name.name,
+ pt->cip_iot == CIT_READ ? "read" : "write",
+ pos, pos + pt->cip_count);
+
+restart:
+ io = vvp_env_thread_io(env);
+ ll_io_init(io, file, pt->cip_iot);
+ io->u.ci_rw.rw_iter = pt->cip_iter;
+ io->u.ci_rw.rw_iocb = pt->cip_iocb;
+ io->ci_pio = 0; /* It's already in parallel task */
+
+ rc = cl_io_rw_init(env, io, pt->cip_iot, pos,
+ pt->cip_count - pt->cip_result);
+ if (!rc) {
+ struct vvp_io *vio = vvp_env_io(env);
+
+ vio->vui_io_subtype = IO_NORMAL;
+ vio->vui_fd = LUSTRE_FPRIVATE(file);
+
+ ll_cl_add(file, env, io, LCC_RW);
+ rc = cl_io_loop(env, io);
+ ll_cl_remove(file, env);
+ } else {
+ /* cl_io_rw_init() handled IO */
+ rc = io->ci_result;
+ }
+
+ if (OBD_FAIL_CHECK_RESET(OBD_FAIL_LLITE_PTASK_IO_FAIL, 0)) {
+ if (io->ci_nob > 0)
+ io->ci_nob /= 2;
+ rc = -EIO;
+ }
+
+ if (io->ci_nob > 0) {
+ pt->cip_result += io->ci_nob;
+ iov_iter_advance(&pt->cip_iter, io->ci_nob);
+ pos += io->ci_nob;
+ pt->cip_iocb.ki_pos = pos;
+#ifdef HAVE_KIOCB_KI_LEFT
+ pt->cip_iocb.ki_left = pt->cip_count - pt->cip_result;
+#elif defined(HAVE_KI_NBYTES)
+ pt->cip_iocb.ki_nbytes = pt->cip_count - pt->cip_result;
+#endif
+ }
+
+ cl_io_fini(env, io);
+
+ if ((rc == 0 || rc == -ENODATA) &&
+ pt->cip_result < pt->cip_count &&
+ io->ci_need_restart) {
+ CDEBUG(D_VFSTRACE,
+ "%s: restart %s range: [%llu, %llu) ret: %zd, rc: %d\n",
+ file_dentry(file)->d_name.name,
+ pt->cip_iot == CIT_READ ? "read" : "write",
+ pos, pos + pt->cip_count - pt->cip_result,
+ pt->cip_result, rc);
+ goto restart;
+ }
+
+ CDEBUG(D_VFSTRACE, "%s: %s ret: %zd, rc: %d\n",
+ file_dentry(file)->d_name.name,
+ pt->cip_iot == CIT_READ ? "read" : "write",
+ pt->cip_result, rc);
+
+ cl_env_put(env, &refcheck);
+ RETURN(pt->cip_result > 0 ? 0 : rc);