4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * Implementation of cl_io for VVP layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
35 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_LLITE
41 #include <linux/pagevec.h>
42 #include <linux/memcontrol.h>
44 #include "llite_internal.h"
45 #include "vvp_internal.h"
46 #include <libcfs/linux/linux-misc.h>
48 static struct vvp_io *cl2vvp_io(const struct lu_env *env,
49 const struct cl_io_slice *slice)
53 vio = container_of(slice, struct vvp_io, vui_cl);
54 LASSERT(vio == vvp_env_io(env));
60 * True, if \a io is a normal io, False for splice_{read,write}
62 static int cl_is_normalio(const struct lu_env *env, const struct cl_io *io)
64 struct vvp_io *vio = vvp_env_io(env);
66 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
68 return vio->vui_io_subtype == IO_NORMAL;
72 * For swapping layout. The file's layout may have changed.
73 * To avoid populating pages to a wrong stripe, we have to verify the
74 * correctness of layout. It works because swapping layout processes
75 * have to acquire group lock.
77 static bool can_populate_pages(const struct lu_env *env, struct cl_io *io,
80 struct ll_inode_info *lli = ll_i2info(inode);
81 struct vvp_io *vio = vvp_env_io(env);
84 switch (io->ci_type) {
87 /* don't need lock here to check lli_layout_gen as we have held
88 * extent lock and GROUP lock has to hold to swap layout */
89 if (ll_layout_version_get(lli) != vio->vui_layout_gen ||
90 OBD_FAIL_CHECK_RESET(OBD_FAIL_LLITE_LOST_LAYOUT, 0)) {
91 io->ci_need_restart = 1;
92 /* this will cause a short read/write */
97 /* fault is okay because we've already had a page. */
105 static void vvp_object_size_lock(struct cl_object *obj)
107 struct inode *inode = vvp_object_inode(obj);
109 ll_inode_size_lock(inode);
110 cl_object_attr_lock(obj);
113 static void vvp_object_size_unlock(struct cl_object *obj)
115 struct inode *inode = vvp_object_inode(obj);
117 cl_object_attr_unlock(obj);
118 ll_inode_size_unlock(inode);
122 * Helper function that if necessary adjusts file size (inode->i_size), when
123 * position at the offset \a pos is accessed. File size can be arbitrary stale
124 * on a Lustre client, but client at least knows KMS. If accessed area is
125 * inside [0, KMS], set file size to KMS, otherwise glimpse file size.
127 * Locking: i_size_lock is used to serialize changes to inode size and to
128 * protect consistency between inode size and cl_object
129 * attributes. cl_object_size_lock() protects consistency between cl_attr's of
130 * top-object and sub-objects.
132 static int vvp_prep_size(const struct lu_env *env, struct cl_object *obj,
133 struct cl_io *io, loff_t start, size_t count,
136 struct cl_attr *attr = vvp_env_thread_attr(env);
137 struct inode *inode = vvp_object_inode(obj);
138 loff_t pos = start + count - 1;
143 * Consistency guarantees: following possibilities exist for the
144 * relation between region being accessed and real file size at this
147 * (A): the region is completely inside of the file;
149 * (B-x): x bytes of region are inside of the file, the rest is
152 * (C): the region is completely outside of the file.
154 * This classification is stable under DLM lock already acquired by
155 * the caller, because to change the class, other client has to take
156 * DLM lock conflicting with our lock. Also, any updates to ->i_size
157 * by other threads on this client are serialized by
158 * ll_inode_size_lock(). This guarantees that short reads are handled
159 * correctly in the face of concurrent writes and truncates.
161 vvp_object_size_lock(obj);
162 result = cl_object_attr_get(env, obj, attr);
167 * A glimpse is necessary to determine whether we
168 * return a short read (B) or some zeroes at the end
171 vvp_object_size_unlock(obj);
172 result = cl_glimpse_lock(env, io, inode, obj, 0);
173 if (result == 0 && exceed != NULL) {
174 /* If objective page index exceed end-of-file
175 * page index, return directly. Do not expect
176 * kernel will check such case correctly.
177 * linux-2.6.18-128.1.1 miss to do that.
179 loff_t size = i_size_read(inode);
180 unsigned long cur_index = start >>
183 if ((size == 0 && cur_index != 0) ||
184 (((size - 1) >> PAGE_SHIFT) <
192 * region is within kms and, hence, within real file
193 * size (A). We need to increase i_size to cover the
194 * read region so that generic_file_read() will do its
195 * job, but that doesn't mean the kms size is
196 * _correct_, it is only the _minimum_ size. If
197 * someone does a stat they will get the correct size
198 * which will always be >= the kms value here.
201 if (i_size_read(inode) < kms) {
202 i_size_write(inode, kms);
204 DFID" updating i_size %llu\n",
205 PFID(lu_object_fid(&obj->co_lu)),
206 (__u64)i_size_read(inode));
211 vvp_object_size_unlock(obj);
216 /*****************************************************************************
222 static int vvp_io_one_lock_index(const struct lu_env *env, struct cl_io *io,
223 __u32 enqflags, enum cl_lock_mode mode,
224 pgoff_t start, pgoff_t end)
226 struct vvp_io *vio = vvp_env_io(env);
227 struct cl_lock_descr *descr = &vio->vui_link.cill_descr;
228 struct cl_object *obj = io->ci_obj;
230 CLOBINVRNT(env, obj, vvp_object_invariant(obj));
233 CDEBUG(D_VFSTRACE, "lock: %d [%lu, %lu]\n", mode, start, end);
235 memset(&vio->vui_link, 0, sizeof vio->vui_link);
237 if (vio->vui_fd && (vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
238 descr->cld_mode = CLM_GROUP;
239 descr->cld_gid = vio->vui_fd->fd_grouplock.lg_gid;
240 enqflags |= CEF_LOCK_MATCH;
242 descr->cld_mode = mode;
245 descr->cld_obj = obj;
246 descr->cld_start = start;
247 descr->cld_end = end;
248 descr->cld_enq_flags = enqflags;
250 cl_io_lock_add(env, io, &vio->vui_link);
255 static int vvp_io_one_lock(const struct lu_env *env, struct cl_io *io,
256 __u32 enqflags, enum cl_lock_mode mode,
257 loff_t start, loff_t end)
259 struct cl_object *obj = io->ci_obj;
261 return vvp_io_one_lock_index(env, io, enqflags, mode,
262 cl_index(obj, start), cl_index(obj, end));
265 static int vvp_io_write_iter_init(const struct lu_env *env,
266 const struct cl_io_slice *ios)
268 struct vvp_io *vio = cl2vvp_io(env, ios);
270 cl_page_list_init(&vio->u.write.vui_queue);
271 vio->u.write.vui_written = 0;
272 vio->u.write.vui_from = 0;
273 vio->u.write.vui_to = PAGE_SIZE;
278 static void vvp_io_write_iter_fini(const struct lu_env *env,
279 const struct cl_io_slice *ios)
281 struct vvp_io *vio = cl2vvp_io(env, ios);
283 LASSERT(vio->u.write.vui_queue.pl_nr == 0);
286 static int vvp_io_fault_iter_init(const struct lu_env *env,
287 const struct cl_io_slice *ios)
289 struct vvp_io *vio = cl2vvp_io(env, ios);
290 struct inode *inode = vvp_object_inode(ios->cis_obj);
292 LASSERT(inode == file_inode(vio->vui_fd->fd_file));
297 static void vvp_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
299 struct cl_io *io = ios->cis_io;
300 struct cl_object *obj = io->ci_obj;
301 struct vvp_io *vio = cl2vvp_io(env, ios);
302 struct inode *inode = vvp_object_inode(obj);
307 CLOBINVRNT(env, obj, vvp_object_invariant(obj));
309 CDEBUG(D_VFSTRACE, DFID" ignore/verify layout %d/%d, layout version %d "
310 "need write layout %d, restore needed %d\n",
311 PFID(lu_object_fid(&obj->co_lu)),
312 io->ci_ignore_layout, io->ci_verify_layout,
313 vio->vui_layout_gen, io->ci_need_write_intent,
314 io->ci_restore_needed);
316 if (io->ci_restore_needed) {
317 /* file was detected release, we need to restore it
318 * before finishing the io
320 rc = ll_layout_restore(inode, 0, OBD_OBJECT_EOF);
321 /* if restore registration failed, no restart,
322 * we will return -ENODATA */
323 /* The layout will change after restore, so we need to
324 * block on layout lock held by the MDT
325 * as MDT will not send new layout in lvb (see LU-3124)
326 * we have to explicitly fetch it, all this will be done
327 * by ll_layout_refresh().
328 * Even if ll_layout_restore() returns zero, it doesn't mean
329 * that restore has been successful. Therefore it sets
330 * ci_verify_layout so that it will check layout at the end
334 io->ci_restore_needed = 1;
335 io->ci_need_restart = 0;
336 io->ci_verify_layout = 0;
341 io->ci_restore_needed = 0;
343 /* Even if ll_layout_restore() returns zero, it doesn't mean
344 * that restore has been successful. Therefore it should verify
345 * if there was layout change and restart I/O correspondingly.
347 ll_layout_refresh(inode, &gen);
348 io->ci_need_restart = vio->vui_layout_gen != gen;
349 if (io->ci_need_restart) {
351 DFID" layout changed from %d to %d.\n",
352 PFID(lu_object_fid(&obj->co_lu)),
353 vio->vui_layout_gen, gen);
354 /* today successful restore is the only possible
356 /* restore was done, clear restoring state */
357 ll_file_clear_flag(ll_i2info(vvp_object_inode(obj)),
358 LLIF_FILE_RESTORING);
364 * dynamic layout change needed, send layout intent
367 if (io->ci_need_write_intent) {
368 enum layout_intent_opc opc = LAYOUT_INTENT_WRITE;
370 io->ci_need_write_intent = 0;
372 LASSERT(io->ci_type == CIT_WRITE ||
373 cl_io_is_trunc(io) || cl_io_is_mkwrite(io));
375 CDEBUG(D_VFSTRACE, DFID" write layout, type %u "DEXT"\n",
376 PFID(lu_object_fid(&obj->co_lu)), io->ci_type,
377 PEXT(&io->ci_write_intent));
379 if (cl_io_is_trunc(io))
380 opc = LAYOUT_INTENT_TRUNC;
382 rc = ll_layout_write_intent(inode, opc, &io->ci_write_intent);
385 io->ci_need_restart = 1;
389 if (!io->ci_need_restart &&
390 !io->ci_ignore_layout && io->ci_verify_layout) {
391 /* check layout version */
392 ll_layout_refresh(inode, &gen);
393 io->ci_need_restart = vio->vui_layout_gen != gen;
394 if (io->ci_need_restart) {
396 DFID" layout changed from %d to %d.\n",
397 PFID(lu_object_fid(&obj->co_lu)),
398 vio->vui_layout_gen, gen);
406 static void vvp_io_fault_fini(const struct lu_env *env,
407 const struct cl_io_slice *ios)
409 struct cl_io *io = ios->cis_io;
410 struct cl_page *page = io->u.ci_fault.ft_page;
412 CLOBINVRNT(env, io->ci_obj, vvp_object_invariant(io->ci_obj));
415 lu_ref_del(&page->cp_reference, "fault", io);
416 cl_page_put(env, page);
417 io->u.ci_fault.ft_page = NULL;
419 vvp_io_fini(env, ios);
422 static enum cl_lock_mode vvp_mode_from_vma(struct vm_area_struct *vma)
425 * we only want to hold PW locks if the mmap() can generate
426 * writes back to the file and that only happens in shared
429 if ((vma->vm_flags & VM_SHARED) && (vma->vm_flags & VM_WRITE))
434 static int vvp_mmap_locks(const struct lu_env *env,
435 struct vvp_io *vio, struct cl_io *io)
437 struct vvp_thread_info *vti = vvp_env_info(env);
438 struct mm_struct *mm = current->mm;
439 struct vm_area_struct *vma;
440 struct cl_lock_descr *descr = &vti->vti_descr;
441 union ldlm_policy_data policy;
449 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
451 if (!cl_is_normalio(env, io))
454 /* nfs or loop back device write */
455 if (vio->vui_iter == NULL)
458 /* No MM (e.g. NFS)? No vmas too. */
462 if (!iter_is_iovec(vio->vui_iter) && !iov_iter_is_kvec(vio->vui_iter))
465 for (i = *vio->vui_iter;
467 iov_iter_advance(&i, iov.iov_len)) {
468 iov = iov_iter_iovec(&i);
469 addr = (unsigned long)iov.iov_base;
475 count += addr & ~PAGE_MASK;
478 down_read(&mm->mmap_sem);
479 while((vma = our_vma(mm, addr, count)) != NULL) {
480 struct dentry *de = file_dentry(vma->vm_file);
481 struct inode *inode = de->d_inode;
482 int flags = CEF_MUST;
484 if (ll_file_nolock(vma->vm_file)) {
486 * For no lock case is not allowed for mmap
493 * XXX: Required lock mode can be weakened: CIT_WRITE
494 * io only ever reads user level buffer, and CIT_READ
497 policy_from_vma(&policy, vma, addr, count);
498 descr->cld_mode = vvp_mode_from_vma(vma);
499 descr->cld_obj = ll_i2info(inode)->lli_clob;
500 descr->cld_start = cl_index(descr->cld_obj,
501 policy.l_extent.start);
502 descr->cld_end = cl_index(descr->cld_obj,
503 policy.l_extent.end);
504 descr->cld_enq_flags = flags;
505 result = cl_io_lock_alloc_add(env, io, descr);
507 CDEBUG(D_VFSTRACE, "lock: %d: [%lu, %lu]\n",
508 descr->cld_mode, descr->cld_start,
514 if (vma->vm_end - addr >= count)
517 count -= vma->vm_end - addr;
520 up_read(&mm->mmap_sem);
527 static void vvp_io_advance(const struct lu_env *env,
528 const struct cl_io_slice *ios,
531 struct vvp_io *vio = cl2vvp_io(env, ios);
532 struct cl_io *io = ios->cis_io;
533 struct cl_object *obj = ios->cis_io->ci_obj;
535 CLOBINVRNT(env, obj, vvp_object_invariant(obj));
537 if (!cl_is_normalio(env, io))
540 vio->vui_tot_count -= nob;
541 iov_iter_reexpand(vio->vui_iter, vio->vui_tot_count);
544 static void vvp_io_update_iov(const struct lu_env *env,
545 struct vvp_io *vio, struct cl_io *io)
547 size_t size = io->u.ci_rw.crw_count;
549 if (!cl_is_normalio(env, io) || vio->vui_iter == NULL)
552 iov_iter_truncate(vio->vui_iter, size);
555 static int vvp_io_rw_lock(const struct lu_env *env, struct cl_io *io,
556 enum cl_lock_mode mode, loff_t start, loff_t end)
558 struct vvp_io *vio = vvp_env_io(env);
562 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
565 vvp_io_update_iov(env, vio, io);
567 if (io->u.ci_rw.crw_nonblock)
568 ast_flags |= CEF_NONBLOCK;
569 if (io->ci_lock_no_expand)
570 ast_flags |= CEF_LOCK_NO_EXPAND;
572 /* Group lock held means no lockless any more */
573 if (vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)
574 io->ci_ignore_lockless = 1;
576 if (ll_file_nolock(vio->vui_fd->fd_file) ||
577 (vio->vui_fd->fd_flags & LL_FILE_LOCKLESS_IO &&
578 !io->ci_ignore_lockless))
579 ast_flags |= CEF_NEVER;
582 result = vvp_mmap_locks(env, vio, io);
584 result = vvp_io_one_lock(env, io, ast_flags, mode, start, end);
589 static int vvp_io_read_lock(const struct lu_env *env,
590 const struct cl_io_slice *ios)
592 struct cl_io *io = ios->cis_io;
593 struct cl_io_rw_common *rd = &io->u.ci_rd.rd;
597 result = vvp_io_rw_lock(env, io, CLM_READ, rd->crw_pos,
598 rd->crw_pos + rd->crw_count - 1);
602 static int vvp_io_fault_lock(const struct lu_env *env,
603 const struct cl_io_slice *ios)
605 struct cl_io *io = ios->cis_io;
606 struct vvp_io *vio = cl2vvp_io(env, ios);
608 * XXX LDLM_FL_CBPENDING
610 return vvp_io_one_lock_index(env,
612 vvp_mode_from_vma(vio->u.fault.ft_vma),
613 io->u.ci_fault.ft_index,
614 io->u.ci_fault.ft_index);
617 static int vvp_io_write_lock(const struct lu_env *env,
618 const struct cl_io_slice *ios)
620 struct cl_io *io = ios->cis_io;
624 if (io->u.ci_wr.wr_append) {
626 end = OBD_OBJECT_EOF;
628 start = io->u.ci_wr.wr.crw_pos;
629 end = start + io->u.ci_wr.wr.crw_count - 1;
632 RETURN(vvp_io_rw_lock(env, io, CLM_WRITE, start, end));
635 static int vvp_io_setattr_iter_init(const struct lu_env *env,
636 const struct cl_io_slice *ios)
643 * Implementation of cl_io_operations::cio_lock() method for CIT_SETATTR io.
645 * Handles "lockless io" mode when extent locking is done by server.
647 static int vvp_io_setattr_lock(const struct lu_env *env,
648 const struct cl_io_slice *ios)
650 struct cl_io *io = ios->cis_io;
651 __u64 lock_start = 0;
652 __u64 lock_end = OBD_OBJECT_EOF;
655 if (cl_io_is_trunc(io)) {
656 struct inode *inode = vvp_object_inode(io->ci_obj);
658 /* set enqueue flags to CEF_MUST in case of encrypted file,
659 * to prevent lockless truncate
661 if (S_ISREG(inode->i_mode) && IS_ENCRYPTED(inode))
663 else if (io->u.ci_setattr.sa_attr.lvb_size == 0)
664 enqflags = CEF_DISCARD_DATA;
665 } else if (cl_io_is_fallocate(io)) {
666 lock_start = io->u.ci_setattr.sa_falloc_offset;
667 lock_end = lock_start + io->u.ci_setattr.sa_attr.lvb_size;
669 unsigned int valid = io->u.ci_setattr.sa_avalid;
671 if (!(valid & TIMES_SET_FLAGS))
674 if ((!(valid & ATTR_MTIME) ||
675 io->u.ci_setattr.sa_attr.lvb_mtime >=
676 io->u.ci_setattr.sa_attr.lvb_ctime) &&
677 (!(valid & ATTR_ATIME) ||
678 io->u.ci_setattr.sa_attr.lvb_atime >=
679 io->u.ci_setattr.sa_attr.lvb_ctime))
683 return vvp_io_one_lock(env, io, enqflags, CLM_WRITE,
684 lock_start, lock_end);
687 static int vvp_do_vmtruncate(struct inode *inode, size_t size)
692 * Only ll_inode_size_lock is taken at this level.
694 ll_inode_size_lock(inode);
695 result = inode_newsize_ok(inode, size);
697 ll_inode_size_unlock(inode);
700 i_size_write(inode, size);
702 ll_truncate_pagecache(inode, size);
703 ll_inode_size_unlock(inode);
707 static int vvp_io_setattr_time(const struct lu_env *env,
708 const struct cl_io_slice *ios)
710 struct cl_io *io = ios->cis_io;
711 struct cl_object *obj = io->ci_obj;
712 struct cl_attr *attr = vvp_env_thread_attr(env);
714 unsigned valid = CAT_CTIME;
716 cl_object_attr_lock(obj);
717 attr->cat_ctime = io->u.ci_setattr.sa_attr.lvb_ctime;
718 if (io->u.ci_setattr.sa_avalid & ATTR_ATIME_SET) {
719 attr->cat_atime = io->u.ci_setattr.sa_attr.lvb_atime;
722 if (io->u.ci_setattr.sa_avalid & ATTR_MTIME_SET) {
723 attr->cat_mtime = io->u.ci_setattr.sa_attr.lvb_mtime;
726 result = cl_object_attr_update(env, obj, attr, valid);
727 cl_object_attr_unlock(obj);
732 static int vvp_io_setattr_start(const struct lu_env *env,
733 const struct cl_io_slice *ios)
735 struct cl_io *io = ios->cis_io;
736 struct inode *inode = vvp_object_inode(io->ci_obj);
737 struct ll_inode_info *lli = ll_i2info(inode);
739 if (cl_io_is_trunc(io)) {
740 trunc_sem_down_write(&lli->lli_trunc_sem);
741 mutex_lock(&lli->lli_setattr_mutex);
742 inode_dio_wait(inode);
743 } else if (cl_io_is_fallocate(io)) {
745 inode_dio_wait(inode);
747 mutex_lock(&lli->lli_setattr_mutex);
750 if (io->u.ci_setattr.sa_avalid & TIMES_SET_FLAGS)
751 return vvp_io_setattr_time(env, ios);
756 static void vvp_io_setattr_end(const struct lu_env *env,
757 const struct cl_io_slice *ios)
759 struct cl_io *io = ios->cis_io;
760 struct inode *inode = vvp_object_inode(io->ci_obj);
761 struct ll_inode_info *lli = ll_i2info(inode);
763 if (cl_io_is_trunc(io)) {
764 /* Truncate in memory pages - they must be clean pages
765 * because osc has already notified to destroy osc_extents. */
766 vvp_do_vmtruncate(inode, io->u.ci_setattr.sa_attr.lvb_size);
767 mutex_unlock(&lli->lli_setattr_mutex);
768 trunc_sem_up_write(&lli->lli_trunc_sem);
769 } else if (cl_io_is_fallocate(io)) {
772 mutex_unlock(&lli->lli_setattr_mutex);
776 static void vvp_io_setattr_fini(const struct lu_env *env,
777 const struct cl_io_slice *ios)
779 bool restore_needed = ios->cis_io->ci_restore_needed;
780 struct inode *inode = vvp_object_inode(ios->cis_obj);
782 vvp_io_fini(env, ios);
784 if (restore_needed && !ios->cis_io->ci_restore_needed) {
785 /* restore finished, set data modified flag for HSM */
786 ll_file_set_flag(ll_i2info(inode), LLIF_DATA_MODIFIED);
790 static int vvp_io_read_start(const struct lu_env *env,
791 const struct cl_io_slice *ios)
793 struct vvp_io *vio = cl2vvp_io(env, ios);
794 struct cl_io *io = ios->cis_io;
795 struct cl_object *obj = io->ci_obj;
796 struct inode *inode = vvp_object_inode(obj);
797 struct ll_inode_info *lli = ll_i2info(inode);
798 struct file *file = vio->vui_fd->fd_file;
799 loff_t pos = io->u.ci_rd.rd.crw_pos;
800 size_t cnt = io->u.ci_rd.rd.crw_count;
801 size_t tot = vio->vui_tot_count;
806 CLOBINVRNT(env, obj, vvp_object_invariant(obj));
808 CDEBUG(D_VFSTRACE, "%s: read [%llu, %llu)\n",
809 file_dentry(file)->d_name.name,
812 if (vio->vui_io_subtype == IO_NORMAL)
813 trunc_sem_down_read(&lli->lli_trunc_sem);
815 if (io->ci_async_readahead) {
820 if (!can_populate_pages(env, io, inode))
823 /* Unless this is reading a sparse file, otherwise the lock has already
824 * been acquired so vvp_prep_size() is an empty op. */
825 result = vvp_prep_size(env, obj, io, pos, cnt, &exceed);
828 else if (exceed != 0)
831 LU_OBJECT_HEADER(D_INODE, env, &obj->co_lu,
832 "Read ino %lu, %lu bytes, offset %lld, size %llu\n",
833 inode->i_ino, cnt, pos, i_size_read(inode));
835 /* turn off the kernel's read-ahead */
836 vio->vui_fd->fd_file->f_ra.ra_pages = 0;
838 /* initialize read-ahead window once per syscall */
839 if (!vio->vui_ra_valid) {
840 vio->vui_ra_valid = true;
841 vio->vui_ra_start_idx = cl_index(obj, pos);
842 vio->vui_ra_pages = cl_index(obj, tot + PAGE_SIZE - 1);
843 /* If both start and end are unaligned, we read one more page
844 * than the index math suggests. */
845 if ((pos & ~PAGE_MASK) != 0 && ((pos + tot) & ~PAGE_MASK) != 0)
848 CDEBUG(D_READA, "tot %zu, ra_start %lu, ra_count %lu\n",
849 tot, vio->vui_ra_start_idx, vio->vui_ra_pages);
854 switch (vio->vui_io_subtype) {
856 LASSERT(vio->vui_iocb->ki_pos == pos);
857 result = generic_file_read_iter(vio->vui_iocb, vio->vui_iter);
860 result = generic_file_splice_read(file, &pos,
861 vio->u.splice.vui_pipe, cnt,
862 vio->u.splice.vui_flags);
863 /* LU-1109: do splice read stripe by stripe otherwise if it
864 * may make nfsd stuck if this read occupied all internal pipe
869 CERROR("Wrong IO type %u\n", vio->vui_io_subtype);
878 io->ci_nob += result;
885 static int vvp_io_commit_sync(const struct lu_env *env, struct cl_io *io,
886 struct cl_page_list *plist, int from, int to)
888 struct cl_2queue *queue = &io->ci_queue;
889 struct cl_page *page;
890 unsigned int bytes = 0;
894 if (plist->pl_nr == 0)
897 if (from > 0 || to != PAGE_SIZE) {
898 page = cl_page_list_first(plist);
899 if (plist->pl_nr == 1) {
900 cl_page_clip(env, page, from, to);
903 cl_page_clip(env, page, from, PAGE_SIZE);
904 if (to != PAGE_SIZE) {
905 page = cl_page_list_last(plist);
906 cl_page_clip(env, page, 0, to);
911 cl_2queue_init(queue);
912 cl_page_list_splice(plist, &queue->c2_qin);
913 rc = cl_io_submit_sync(env, io, CRT_WRITE, queue, 0);
915 /* plist is not sorted any more */
916 cl_page_list_splice(&queue->c2_qin, plist);
917 cl_page_list_splice(&queue->c2_qout, plist);
918 cl_2queue_fini(env, queue);
921 /* calculate bytes */
922 bytes = plist->pl_nr << PAGE_SHIFT;
923 bytes -= from + PAGE_SIZE - to;
925 while (plist->pl_nr > 0) {
926 page = cl_page_list_first(plist);
927 cl_page_list_del(env, plist, page);
929 cl_page_clip(env, page, 0, PAGE_SIZE);
931 SetPageUptodate(cl_page_vmpage(page));
932 cl_page_disown(env, io, page);
934 /* held in ll_cl_init() */
935 lu_ref_del(&page->cp_reference, "cl_io", io);
936 cl_page_put(env, page);
940 RETURN(bytes > 0 ? bytes : rc);
944 * Kernels 4.2 - 4.5 pass memcg argument to account_page_dirtied()
945 * Kernel v5.2-5678-gac1c3e4 no longer exports account_page_dirtied
947 static inline void ll_account_page_dirtied(struct page *page,
948 struct address_space *mapping)
950 #ifdef HAVE_ACCOUNT_PAGE_DIRTIED_3ARGS
951 struct mem_cgroup *memcg = mem_cgroup_begin_page_stat(page);
953 account_page_dirtied(page, mapping, memcg);
954 mem_cgroup_end_page_stat(memcg);
955 #elif defined(HAVE_ACCOUNT_PAGE_DIRTIED_EXPORT)
956 account_page_dirtied(page, mapping);
958 vvp_account_page_dirtied(page, mapping);
963 * From kernel v4.19-rc5-248-g9b89a0355144 use XArrary
964 * Prior kernels use radix_tree for tags
966 static inline void ll_page_tag_dirty(struct page *page,
967 struct address_space *mapping)
969 #ifndef HAVE_RADIX_TREE_TAG_SET
970 __xa_set_mark(&mapping->i_pages, page_index(page), PAGECACHE_TAG_DIRTY);
972 radix_tree_tag_set(&mapping->page_tree, page_index(page),
973 PAGECACHE_TAG_DIRTY);
977 /* Taken from kernel set_page_dirty, __set_page_dirty_nobuffers
978 * Last change to this area: b93b016313b3ba8003c3b8bb71f569af91f19fc7
980 * Current with Linus tip of tree (7/13/2019):
981 * v5.2-rc4-224-ge01e060fe0
983 * Backwards compat for 3.x, 5.x kernels relating to memcg handling
984 * & rename of radix tree to xarray.
986 void vvp_set_pagevec_dirty(struct pagevec *pvec)
988 struct page *page = pvec->pages[0];
989 struct address_space *mapping = page->mapping;
991 int count = pagevec_count(pvec);
997 /* From set_page_dirty */
998 for (i = 0; i < count; i++)
999 ClearPageReclaim(pvec->pages[i]);
1001 LASSERTF(page->mapping,
1002 "mapping must be set. page %p, page->private (cl_page) %p\n",
1003 page, (void *) page->private);
1005 /* Rest of code derived from __set_page_dirty_nobuffers */
1006 ll_xa_lock_irqsave(&mapping->i_pages, flags);
1008 /* Notes on differences with __set_page_dirty_nobuffers:
1009 * 1. We don't need to call page_mapping because we know this is a page
1011 * 2. We have the pages locked, so there is no need for the careful
1012 * mapping/mapping2 dance.
1013 * 3. No mapping is impossible. (Race w/truncate mentioned in
1014 * dirty_nobuffers should be impossible because we hold the page lock.)
1015 * 4. All mappings are the same because i/o is only to one file.
1016 * 5. We invert the lock order on lock_page_memcg(page) and the mapping
1017 * xa_lock, but this is the only function that should use that pair of
1018 * locks and it can't race because Lustre locks pages throughout i/o.
1020 for (i = 0; i < count; i++) {
1021 page = pvec->pages[i];
1022 lock_page_memcg(page);
1023 if (TestSetPageDirty(page)) {
1024 unlock_page_memcg(page);
1027 LASSERTF(page->mapping == mapping,
1028 "all pages must have the same mapping. page %p, mapping %p, first mapping %p\n",
1029 page, page->mapping, mapping);
1030 WARN_ON_ONCE(!PagePrivate(page) && !PageUptodate(page));
1031 ll_account_page_dirtied(page, mapping);
1032 ll_page_tag_dirty(page, mapping);
1034 unlock_page_memcg(page);
1036 ll_xa_unlock_irqrestore(&mapping->i_pages, flags);
1038 CDEBUG(D_VFSTRACE, "mapping %p, count %d, dirtied %d\n", mapping,
1041 if (mapping->host && dirtied) {
1042 /* !PageAnon && !swapper_space */
1043 __mark_inode_dirty(mapping->host, I_DIRTY_PAGES);
1049 static void write_commit_callback(const struct lu_env *env, struct cl_io *io,
1050 struct pagevec *pvec)
1057 count = pagevec_count(pvec);
1060 for (i = 0; i < count; i++) {
1061 struct page *vmpage = pvec->pages[i];
1062 SetPageUptodate(vmpage);
1065 vvp_set_pagevec_dirty(pvec);
1067 for (i = 0; i < count; i++) {
1068 struct page *vmpage = pvec->pages[i];
1069 struct cl_page *page = (struct cl_page *) vmpage->private;
1070 cl_page_disown(env, io, page);
1071 lu_ref_del(&page->cp_reference, "cl_io", cl_io_top(io));
1072 cl_page_put(env, page);
1078 /* make sure the page list is contiguous */
1079 static bool page_list_sanity_check(struct cl_object *obj,
1080 struct cl_page_list *plist)
1082 struct cl_page *page;
1083 pgoff_t index = CL_PAGE_EOF;
1085 cl_page_list_for_each(page, plist) {
1086 struct vvp_page *vpg = cl_object_page_slice(obj, page);
1088 if (index == CL_PAGE_EOF) {
1089 index = vvp_index(vpg);
1094 if (index == vvp_index(vpg))
1102 /* Return how many bytes have queued or written */
1103 int vvp_io_write_commit(const struct lu_env *env, struct cl_io *io)
1105 struct cl_object *obj = io->ci_obj;
1106 struct inode *inode = vvp_object_inode(obj);
1107 struct vvp_io *vio = vvp_env_io(env);
1108 struct cl_page_list *queue = &vio->u.write.vui_queue;
1109 struct cl_page *page;
1112 unsigned int npages = vio->u.write.vui_queue.pl_nr;
1118 CDEBUG(D_VFSTRACE, "commit async pages: %d, from %d, to %d\n",
1119 npages, vio->u.write.vui_from, vio->u.write.vui_to);
1121 LASSERT(page_list_sanity_check(obj, queue));
1123 /* submit IO with async write */
1124 rc = cl_io_commit_async(env, io, queue,
1125 vio->u.write.vui_from, vio->u.write.vui_to,
1126 write_commit_callback);
1127 npages -= queue->pl_nr; /* already committed pages */
1129 /* calculate how many bytes were written */
1130 bytes = npages << PAGE_SHIFT;
1133 bytes -= vio->u.write.vui_from;
1134 if (queue->pl_nr == 0) /* last page */
1135 bytes -= PAGE_SIZE - vio->u.write.vui_to;
1136 LASSERTF(bytes > 0, "bytes = %d, pages = %d\n", bytes, npages);
1138 vio->u.write.vui_written += bytes;
1140 CDEBUG(D_VFSTRACE, "Committed %d pages %d bytes, tot: %ld\n",
1141 npages, bytes, vio->u.write.vui_written);
1143 /* the first page must have been written. */
1144 vio->u.write.vui_from = 0;
1146 LASSERT(page_list_sanity_check(obj, queue));
1147 LASSERT(ergo(rc == 0, queue->pl_nr == 0));
1149 /* out of quota, try sync write */
1150 if (rc == -EDQUOT && !cl_io_is_mkwrite(io)) {
1151 rc = vvp_io_commit_sync(env, io, queue,
1152 vio->u.write.vui_from,
1153 vio->u.write.vui_to);
1155 vio->u.write.vui_written += rc;
1160 /* update inode size */
1161 ll_merge_attr(env, inode);
1163 /* Now the pages in queue were failed to commit, discard them
1164 * unless they were dirtied before. */
1165 while (queue->pl_nr > 0) {
1166 page = cl_page_list_first(queue);
1167 cl_page_list_del(env, queue, page);
1169 if (!PageDirty(cl_page_vmpage(page)))
1170 cl_page_discard(env, io, page);
1172 cl_page_disown(env, io, page);
1174 /* held in ll_cl_init() */
1175 lu_ref_del(&page->cp_reference, "cl_io", io);
1176 cl_page_put(env, page);
1178 cl_page_list_fini(env, queue);
1183 static int vvp_io_write_start(const struct lu_env *env,
1184 const struct cl_io_slice *ios)
1186 struct vvp_io *vio = cl2vvp_io(env, ios);
1187 struct cl_io *io = ios->cis_io;
1188 struct cl_object *obj = io->ci_obj;
1189 struct inode *inode = vvp_object_inode(obj);
1190 struct ll_inode_info *lli = ll_i2info(inode);
1191 struct file *file = vio->vui_fd->fd_file;
1193 loff_t pos = io->u.ci_wr.wr.crw_pos;
1194 size_t cnt = io->u.ci_wr.wr.crw_count;
1195 bool lock_inode = !IS_NOSEC(inode);
1196 size_t nob = io->ci_nob;
1197 struct iov_iter iter;
1202 if (vio->vui_io_subtype == IO_NORMAL)
1203 trunc_sem_down_read(&lli->lli_trunc_sem);
1205 if (!can_populate_pages(env, io, inode))
1208 if (cl_io_is_append(io)) {
1210 * PARALLEL IO This has to be changed for parallel IO doing
1211 * out-of-order writes.
1213 ll_merge_attr(env, inode);
1214 pos = io->u.ci_wr.wr.crw_pos = i_size_read(inode);
1215 vio->vui_iocb->ki_pos = pos;
1217 LASSERTF(vio->vui_iocb->ki_pos == pos,
1218 "ki_pos %lld [%lld, %lld)\n",
1219 vio->vui_iocb->ki_pos,
1223 CDEBUG(D_VFSTRACE, "%s: write [%llu, %llu)\n",
1224 file_dentry(file)->d_name.name,
1227 /* The maximum Lustre file size is variable, based on the OST maximum
1228 * object size and number of stripes. This needs another check in
1229 * addition to the VFS checks earlier. */
1230 if (pos + cnt > ll_file_maxbytes(inode)) {
1232 "%s: file %s ("DFID") offset %llu > maxbytes %llu\n",
1233 ll_i2sbi(inode)->ll_fsname,
1234 file_dentry(file)->d_name.name,
1235 PFID(ll_inode2fid(inode)), pos + cnt,
1236 ll_file_maxbytes(inode));
1240 /* Tests to verify we take the i_mutex correctly */
1241 if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_IMUTEX_SEC) && !lock_inode)
1244 if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_IMUTEX_NOSEC) && lock_inode)
1247 if (vio->vui_iter == NULL) {
1248 /* from a temp io in ll_cl_init(). */
1252 * When using the locked AIO function (generic_file_aio_write())
1253 * testing has shown the inode mutex to be a limiting factor
1254 * with multi-threaded single shared file performance. To get
1255 * around this, we now use the lockless version. To maintain
1256 * consistency, proper locking to protect against writes,
1257 * trucates, etc. is handled in the higher layers of lustre.
1259 lock_inode = !IS_NOSEC(inode);
1260 iter = *vio->vui_iter;
1262 if (unlikely(lock_inode))
1264 result = __generic_file_write_iter(vio->vui_iocb,
1266 if (unlikely(lock_inode))
1267 inode_unlock(inode);
1271 #ifdef HAVE_GENERIC_WRITE_SYNC_2ARGS
1272 result = generic_write_sync(vio->vui_iocb, result);
1277 err = generic_write_sync(vio->vui_iocb->ki_filp, pos,
1279 if (err < 0 && result > 0)
1286 result = vvp_io_write_commit(env, io);
1287 /* Simulate short commit */
1288 if (CFS_FAULT_CHECK(OBD_FAIL_LLITE_SHORT_COMMIT)) {
1289 vio->u.write.vui_written >>= 1;
1290 if (vio->u.write.vui_written > 0)
1291 io->ci_need_restart = 1;
1293 if (vio->u.write.vui_written > 0) {
1294 result = vio->u.write.vui_written;
1295 CDEBUG(D_VFSTRACE, "%s: write nob %zd, result: %zd\n",
1296 file_dentry(file)->d_name.name,
1297 io->ci_nob, result);
1298 io->ci_nob += result;
1300 io->ci_continue = 0;
1303 if (vio->vui_iocb->ki_pos != (pos + io->ci_nob - nob)) {
1304 CDEBUG(D_VFSTRACE, "%s: write position mismatch: "
1305 "ki_pos %lld vs. pos %lld, written %ld, commit %ld "
1307 file_dentry(file)->d_name.name,
1308 vio->vui_iocb->ki_pos, pos + io->ci_nob - nob,
1309 written, io->ci_nob - nob, result);
1311 * Rewind ki_pos and vui_iter to where it has
1312 * successfully committed.
1314 vio->vui_iocb->ki_pos = pos + io->ci_nob - nob;
1315 iov_iter_advance(&iter, io->ci_nob - nob);
1316 vio->vui_iter->iov = iter.iov;
1317 vio->vui_iter->nr_segs = iter.nr_segs;
1318 vio->vui_iter->iov_offset = iter.iov_offset;
1319 vio->vui_iter->count = iter.count;
1321 if (result > 0 || result == -EIOCBQUEUED) {
1322 ll_file_set_flag(ll_i2info(inode), LLIF_DATA_MODIFIED);
1325 io->ci_continue = 0;
1333 static void vvp_io_rw_end(const struct lu_env *env,
1334 const struct cl_io_slice *ios)
1336 struct vvp_io *vio = cl2vvp_io(env, ios);
1337 struct inode *inode = vvp_object_inode(ios->cis_obj);
1338 struct ll_inode_info *lli = ll_i2info(inode);
1340 if (vio->vui_io_subtype == IO_NORMAL)
1341 trunc_sem_up_read(&lli->lli_trunc_sem);
1344 static int vvp_io_kernel_fault(struct vvp_fault_io *cfio)
1346 struct vm_fault *vmf = cfio->ft_vmf;
1348 cfio->ft_flags = ll_filemap_fault(cfio->ft_vma, vmf);
1349 cfio->ft_flags_valid = 1;
1352 LL_CDEBUG_PAGE(D_PAGE, vmf->page, "got addr %p type NOPAGE\n",
1353 get_vmf_address(vmf));
1354 if (unlikely(!(cfio->ft_flags & VM_FAULT_LOCKED))) {
1355 lock_page(vmf->page);
1356 cfio->ft_flags |= VM_FAULT_LOCKED;
1359 cfio->ft_vmpage = vmf->page;
1364 if (cfio->ft_flags & VM_FAULT_SIGBUS) {
1365 CDEBUG(D_PAGE, "got addr %p - SIGBUS\n", get_vmf_address(vmf));
1369 if (cfio->ft_flags & VM_FAULT_OOM) {
1370 CDEBUG(D_PAGE, "got addr %p - OOM\n", get_vmf_address(vmf));
1374 if (cfio->ft_flags & VM_FAULT_RETRY)
1377 CERROR("unknown error in page fault %d\n", cfio->ft_flags);
1382 static void mkwrite_commit_callback(const struct lu_env *env, struct cl_io *io,
1383 struct pagevec *pvec)
1385 vvp_set_pagevec_dirty(pvec);
1388 static int vvp_io_fault_start(const struct lu_env *env,
1389 const struct cl_io_slice *ios)
1391 struct vvp_io *vio = cl2vvp_io(env, ios);
1392 struct cl_io *io = ios->cis_io;
1393 struct cl_object *obj = io->ci_obj;
1394 struct inode *inode = vvp_object_inode(obj);
1395 struct ll_inode_info *lli = ll_i2info(inode);
1396 struct cl_fault_io *fio = &io->u.ci_fault;
1397 struct vvp_fault_io *cfio = &vio->u.fault;
1400 struct page *vmpage = NULL;
1401 struct cl_page *page;
1406 trunc_sem_down_read_nowait(&lli->lli_trunc_sem);
1408 /* offset of the last byte on the page */
1409 offset = cl_offset(obj, fio->ft_index + 1) - 1;
1410 LASSERT(cl_index(obj, offset) == fio->ft_index);
1411 result = vvp_prep_size(env, obj, io, 0, offset + 1, NULL);
1415 /* must return locked page */
1416 if (fio->ft_mkwrite) {
1417 LASSERT(cfio->ft_vmpage != NULL);
1418 lock_page(cfio->ft_vmpage);
1420 result = vvp_io_kernel_fault(cfio);
1425 vmpage = cfio->ft_vmpage;
1426 LASSERT(PageLocked(vmpage));
1428 if (OBD_FAIL_CHECK(OBD_FAIL_LLITE_FAULT_TRUNC_RACE))
1429 generic_error_remove_page(vmpage->mapping, vmpage);
1431 size = i_size_read(inode);
1432 /* Though we have already held a cl_lock upon this page, but
1433 * it still can be truncated locally. */
1434 if (unlikely((vmpage->mapping != inode->i_mapping) ||
1435 (page_offset(vmpage) > size))) {
1436 CDEBUG(D_PAGE, "llite: fault and truncate race happened!\n");
1438 /* return +1 to stop cl_io_loop() and ll_fault() will catch
1440 GOTO(out, result = +1);
1443 last_index = cl_index(obj, size - 1);
1445 if (fio->ft_mkwrite ) {
1447 * Capture the size while holding the lli_trunc_sem from above
1448 * we want to make sure that we complete the mkwrite action
1449 * while holding this lock. We need to make sure that we are
1450 * not past the end of the file.
1452 if (last_index < fio->ft_index) {
1454 "llite: mkwrite and truncate race happened: "
1455 "%p: 0x%lx 0x%lx\n",
1456 vmpage->mapping,fio->ft_index,last_index);
1458 * We need to return if we are
1459 * passed the end of the file. This will propagate
1460 * up the call stack to ll_page_mkwrite where
1461 * we will return VM_FAULT_NOPAGE. Any non-negative
1462 * value returned here will be silently
1463 * converted to 0. If the vmpage->mapping is null
1464 * the error code would be converted back to ENODATA
1465 * in ll_page_mkwrite0. Thus we return -ENODATA
1466 * to handle both cases
1468 GOTO(out, result = -ENODATA);
1472 page = cl_page_find(env, obj, fio->ft_index, vmpage, CPT_CACHEABLE);
1474 GOTO(out, result = PTR_ERR(page));
1476 /* if page is going to be written, we should add this page into cache
1478 if (fio->ft_mkwrite) {
1479 wait_on_page_writeback(vmpage);
1480 if (!PageDirty(vmpage)) {
1481 struct cl_page_list *plist = &vio->u.fault.ft_queue;
1482 struct vvp_page *vpg = cl_object_page_slice(obj, page);
1485 /* vvp_page_assume() calls wait_on_page_writeback(). */
1486 cl_page_assume(env, io, page);
1488 cl_page_list_init(plist);
1489 cl_page_list_add(plist, page);
1492 if (last_index == vvp_index(vpg))
1493 to = ((size - 1) & ~PAGE_MASK) + 1;
1495 /* Do not set Dirty bit here so that in case IO is
1496 * started before the page is really made dirty, we
1497 * still have chance to detect it. */
1498 result = cl_io_commit_async(env, io, plist, 0, to,
1499 mkwrite_commit_callback);
1500 /* Have overquota flag, trying sync write to check
1501 * whether indeed out of quota */
1502 if (result == -EDQUOT) {
1504 result = vvp_io_commit_sync(env, io,
1508 cl_page_own(env, io, page);
1509 cl_page_list_add(plist, page);
1510 lu_ref_add(&page->cp_reference,
1512 result = cl_io_commit_async(env, io,
1514 mkwrite_commit_callback);
1517 cl_page_put(env, page);
1521 LASSERT(cl_page_is_owned(page, io));
1522 cl_page_list_fini(env, plist);
1526 cl_page_discard(env, io, page);
1527 cl_page_disown(env, io, page);
1529 cl_page_put(env, page);
1531 /* we're in big trouble, what can we do now? */
1532 if (result == -EDQUOT)
1536 cl_page_disown(env, io, page);
1542 * The ft_index is only used in the case of
1543 * a mkwrite action. We need to check
1544 * our assertions are correct, since
1545 * we should have caught this above
1547 LASSERT(!fio->ft_mkwrite || fio->ft_index <= last_index);
1548 if (fio->ft_index == last_index)
1550 * Last page is mapped partially.
1552 fio->ft_nob = size - cl_offset(obj, fio->ft_index);
1554 fio->ft_nob = cl_page_size(obj);
1556 lu_ref_add(&page->cp_reference, "fault", io);
1557 fio->ft_page = page;
1561 /* return unlocked vmpage to avoid deadlocking */
1563 unlock_page(vmpage);
1565 cfio->ft_flags &= ~VM_FAULT_LOCKED;
1570 static void vvp_io_fault_end(const struct lu_env *env,
1571 const struct cl_io_slice *ios)
1573 struct inode *inode = vvp_object_inode(ios->cis_obj);
1574 struct ll_inode_info *lli = ll_i2info(inode);
1576 CLOBINVRNT(env, ios->cis_io->ci_obj,
1577 vvp_object_invariant(ios->cis_io->ci_obj));
1578 trunc_sem_up_read(&lli->lli_trunc_sem);
1581 static int vvp_io_fsync_start(const struct lu_env *env,
1582 const struct cl_io_slice *ios)
1584 /* we should mark TOWRITE bit to each dirty page in radix tree to
1585 * verify pages have been written, but this is difficult because of
1590 static int vvp_io_read_ahead(const struct lu_env *env,
1591 const struct cl_io_slice *ios,
1592 pgoff_t start, struct cl_read_ahead *ra)
1597 if (ios->cis_io->ci_type == CIT_READ ||
1598 ios->cis_io->ci_type == CIT_FAULT) {
1599 struct vvp_io *vio = cl2vvp_io(env, ios);
1601 if (unlikely(vio->vui_fd->fd_flags & LL_FILE_GROUP_LOCKED)) {
1602 ra->cra_end_idx = CL_PAGE_EOF;
1603 result = +1; /* no need to call down */
1610 static const struct cl_io_operations vvp_io_ops = {
1613 .cio_fini = vvp_io_fini,
1614 .cio_lock = vvp_io_read_lock,
1615 .cio_start = vvp_io_read_start,
1616 .cio_end = vvp_io_rw_end,
1617 .cio_advance = vvp_io_advance,
1620 .cio_fini = vvp_io_fini,
1621 .cio_iter_init = vvp_io_write_iter_init,
1622 .cio_iter_fini = vvp_io_write_iter_fini,
1623 .cio_lock = vvp_io_write_lock,
1624 .cio_start = vvp_io_write_start,
1625 .cio_end = vvp_io_rw_end,
1626 .cio_advance = vvp_io_advance,
1629 .cio_fini = vvp_io_setattr_fini,
1630 .cio_iter_init = vvp_io_setattr_iter_init,
1631 .cio_lock = vvp_io_setattr_lock,
1632 .cio_start = vvp_io_setattr_start,
1633 .cio_end = vvp_io_setattr_end
1636 .cio_fini = vvp_io_fault_fini,
1637 .cio_iter_init = vvp_io_fault_iter_init,
1638 .cio_lock = vvp_io_fault_lock,
1639 .cio_start = vvp_io_fault_start,
1640 .cio_end = vvp_io_fault_end,
1643 .cio_start = vvp_io_fsync_start,
1644 .cio_fini = vvp_io_fini
1647 .cio_fini = vvp_io_fini
1650 .cio_fini = vvp_io_fini
1653 .cio_fini = vvp_io_fini
1656 .cio_read_ahead = vvp_io_read_ahead
1659 int vvp_io_init(const struct lu_env *env, struct cl_object *obj,
1662 struct vvp_io *vio = vvp_env_io(env);
1663 struct inode *inode = vvp_object_inode(obj);
1666 CLOBINVRNT(env, obj, vvp_object_invariant(obj));
1669 CDEBUG(D_VFSTRACE, DFID" ignore/verify layout %d/%d, layout version %d "
1670 "restore needed %d\n",
1671 PFID(lu_object_fid(&obj->co_lu)),
1672 io->ci_ignore_layout, io->ci_verify_layout,
1673 vio->vui_layout_gen, io->ci_restore_needed);
1675 CL_IO_SLICE_CLEAN(vio, vui_cl);
1676 cl_io_slice_add(io, &vio->vui_cl, obj, &vvp_io_ops);
1677 vio->vui_ra_valid = false;
1679 if (io->ci_type == CIT_READ || io->ci_type == CIT_WRITE) {
1681 struct ll_inode_info *lli = ll_i2info(inode);
1683 count = io->u.ci_rw.crw_count;
1684 /* "If nbyte is 0, read() will return 0 and have no other
1685 * results." -- Single Unix Spec */
1689 vio->vui_tot_count = count;
1691 /* for read/write, we store the jobid in the inode, and
1692 * it'll be fetched by osc when building RPC.
1694 * it's not accurate if the file is shared by different
1697 lustre_get_jobid(lli->lli_jobid, sizeof(lli->lli_jobid));
1698 } else if (io->ci_type == CIT_SETATTR) {
1699 if (!cl_io_is_trunc(io))
1700 io->ci_lockreq = CILR_MANDATORY;
1703 /* Enqueue layout lock and get layout version. We need to do this
1704 * even for operations requiring to open file, such as read and write,
1705 * because it might not grant layout lock in IT_OPEN. */
1706 if (result == 0 && !io->ci_ignore_layout) {
1707 result = ll_layout_refresh(inode, &vio->vui_layout_gen);
1708 if (result == -ENOENT)
1709 /* If the inode on MDS has been removed, but the objects
1710 * on OSTs haven't been destroyed (async unlink), layout
1711 * fetch will return -ENOENT, we'd ingore this error
1712 * and continue with dirty flush. LU-3230. */
1715 CERROR("%s: refresh file layout " DFID " error %d.\n",
1716 ll_i2sbi(inode)->ll_fsname,
1717 PFID(lu_object_fid(&obj->co_lu)), result);
1720 io->ci_result = result < 0 ? result : 0;