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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Implementation of cl_io for LOV layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
39 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
42 #define DEBUG_SUBSYSTEM S_LOV
44 #include "lov_cl_internal.h"
50 static inline void lov_sub_enter(struct lov_io_sub *sub)
54 static inline void lov_sub_exit(struct lov_io_sub *sub)
59 static void lov_io_sub_fini(const struct lu_env *env, struct lov_io *lio,
60 struct lov_io_sub *sub)
63 if (sub->sub_io != NULL) {
64 if (sub->sub_io_initialized) {
66 cl_io_fini(sub->sub_env, sub->sub_io);
68 sub->sub_io_initialized = 0;
69 lio->lis_active_subios--;
71 if (sub->sub_stripe == lio->lis_single_subio_index)
72 lio->lis_single_subio_index = -1;
73 else if (!sub->sub_borrowed)
74 OBD_FREE_PTR(sub->sub_io);
77 if (sub->sub_env != NULL && !IS_ERR(sub->sub_env)) {
78 if (!sub->sub_borrowed)
79 cl_env_put(sub->sub_env, &sub->sub_refcheck);
85 static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
86 int stripe, loff_t start, loff_t end)
88 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
89 struct cl_io *parent = lio->lis_cl.cis_io;
93 io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
94 io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
95 io->u.ci_setattr.sa_capa = parent->u.ci_setattr.sa_capa;
96 if (cl_io_is_trunc(io)) {
97 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
99 new_size = lov_size_to_stripe(lsm, new_size, stripe);
100 io->u.ci_setattr.sa_attr.lvb_size = new_size;
105 struct cl_object *obj = parent->ci_obj;
106 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
108 io->u.ci_fault = parent->u.ci_fault;
109 off = lov_size_to_stripe(lsm, off, stripe);
110 io->u.ci_fault.ft_index = cl_index(obj, off);
114 io->u.ci_fsync.fi_start = start;
115 io->u.ci_fsync.fi_end = end;
116 io->u.ci_fsync.fi_capa = parent->u.ci_fsync.fi_capa;
117 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
118 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
123 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
124 if (cl_io_is_append(parent)) {
125 io->u.ci_wr.wr_append = 1;
127 io->u.ci_rw.crw_pos = start;
128 io->u.ci_rw.crw_count = end - start;
137 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
138 struct lov_io_sub *sub)
140 struct lov_object *lov = lio->lis_object;
141 struct lov_device *ld = lu2lov_dev(lov2cl(lov)->co_lu.lo_dev);
142 struct cl_io *sub_io;
143 struct cl_object *sub_obj;
144 struct cl_io *io = lio->lis_cl.cis_io;
146 int stripe = sub->sub_stripe;
149 LASSERT(sub->sub_io == NULL);
150 LASSERT(sub->sub_env == NULL);
151 LASSERT(sub->sub_stripe < lio->lis_stripe_count);
154 if (unlikely(lov_r0(lov)->lo_sub[stripe] == NULL))
158 sub->sub_io_initialized = 0;
159 sub->sub_borrowed = 0;
161 if (lio->lis_mem_frozen) {
162 LASSERT(mutex_is_locked(&ld->ld_mutex));
163 sub->sub_io = &ld->ld_emrg[stripe]->emrg_subio;
164 sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
165 sub->sub_borrowed = 1;
169 /* obtain new environment */
170 cookie = cl_env_reenter();
171 sub->sub_env = cl_env_get(&sub->sub_refcheck);
172 cl_env_reexit(cookie);
173 if (IS_ERR(sub->sub_env))
174 result = PTR_ERR(sub->sub_env);
178 * First sub-io. Use ->lis_single_subio to
179 * avoid dynamic allocation.
181 if (lio->lis_active_subios == 0) {
182 sub->sub_io = &lio->lis_single_subio;
183 lio->lis_single_subio_index = stripe;
185 OBD_ALLOC_PTR(sub->sub_io);
186 if (sub->sub_io == NULL)
193 sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
194 sub_io = sub->sub_io;
196 sub_io->ci_obj = sub_obj;
197 sub_io->ci_result = 0;
199 sub_io->ci_parent = io;
200 sub_io->ci_lockreq = io->ci_lockreq;
201 sub_io->ci_type = io->ci_type;
202 sub_io->ci_no_srvlock = io->ci_no_srvlock;
203 sub_io->ci_noatime = io->ci_noatime;
206 result = cl_io_sub_init(sub->sub_env, sub_io,
207 io->ci_type, sub_obj);
210 lio->lis_active_subios++;
211 sub->sub_io_initialized = 1;
216 lov_io_sub_fini(env, lio, sub);
220 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
221 struct lov_io *lio, int stripe)
224 struct lov_io_sub *sub = &lio->lis_subs[stripe];
226 LASSERT(stripe < lio->lis_stripe_count);
229 if (!sub->sub_io_initialized) {
230 sub->sub_stripe = stripe;
231 rc = lov_io_sub_init(env, lio, sub);
241 void lov_sub_put(struct lov_io_sub *sub)
246 /*****************************************************************************
252 int lov_page_stripe(const struct cl_page *page)
254 struct lovsub_object *subobj;
255 const struct cl_page_slice *slice;
258 slice = cl_page_at(page, &lovsub_device_type);
259 LASSERT(slice != NULL);
260 LASSERT(slice->cpl_obj != NULL);
262 subobj = cl2lovsub(slice->cpl_obj);
263 RETURN(subobj->lso_index);
266 struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
267 const struct cl_page_slice *slice)
269 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
270 struct cl_page *page = slice->cpl_page;
273 LASSERT(lio->lis_cl.cis_io != NULL);
274 LASSERT(cl2lov(slice->cpl_obj) == lio->lis_object);
275 LASSERT(lsm != NULL);
276 LASSERT(lio->lis_nr_subios > 0);
279 stripe = lov_page_stripe(page);
280 RETURN(lov_sub_get(env, lio, stripe));
284 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
287 struct lov_stripe_md *lsm;
291 LASSERT(lio->lis_object != NULL);
292 lsm = lio->lis_object->lo_lsm;
295 * Need to be optimized, we can't afford to allocate a piece of memory
296 * when writing a page. -jay
298 OBD_ALLOC_LARGE(lio->lis_subs,
299 lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
300 if (lio->lis_subs != NULL) {
301 lio->lis_nr_subios = lio->lis_stripe_count;
302 lio->lis_single_subio_index = -1;
303 lio->lis_active_subios = 0;
310 static int lov_io_slice_init(struct lov_io *lio,
311 struct lov_object *obj, struct cl_io *io)
316 lio->lis_object = obj;
318 LASSERT(obj->lo_lsm != NULL);
319 lio->lis_stripe_count = obj->lo_lsm->lsm_stripe_count;
321 switch (io->ci_type) {
324 lio->lis_pos = io->u.ci_rw.crw_pos;
325 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
326 lio->lis_io_endpos = lio->lis_endpos;
327 if (cl_io_is_append(io)) {
328 LASSERT(io->ci_type == CIT_WRITE);
330 /* If there is LOV EA hole, then we may cannot locate
331 * the current file-tail exactly. */
332 if (unlikely(obj->lo_lsm->lsm_pattern &
337 lio->lis_endpos = OBD_OBJECT_EOF;
342 if (cl_io_is_trunc(io))
343 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
346 lio->lis_endpos = OBD_OBJECT_EOF;
350 pgoff_t index = io->u.ci_fault.ft_index;
351 lio->lis_pos = cl_offset(io->ci_obj, index);
352 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
357 lio->lis_pos = io->u.ci_fsync.fi_start;
358 lio->lis_endpos = io->u.ci_fsync.fi_end;
364 lio->lis_endpos = OBD_OBJECT_EOF;
374 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
376 struct lov_io *lio = cl2lov_io(env, ios);
377 struct lov_object *lov = cl2lov(ios->cis_obj);
381 if (lio->lis_subs != NULL) {
382 for (i = 0; i < lio->lis_nr_subios; i++)
383 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
384 OBD_FREE_LARGE(lio->lis_subs,
385 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
386 lio->lis_nr_subios = 0;
389 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
390 if (atomic_dec_and_test(&lov->lo_active_ios))
391 wake_up_all(&lov->lo_waitq);
395 static obd_off lov_offset_mod(obd_off val, int delta)
397 if (val != OBD_OBJECT_EOF)
402 static int lov_io_iter_init(const struct lu_env *env,
403 const struct cl_io_slice *ios)
405 struct lov_io *lio = cl2lov_io(env, ios);
406 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
407 struct lov_io_sub *sub;
415 endpos = lov_offset_mod(lio->lis_endpos, -1);
416 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
417 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
418 endpos, &start, &end))
421 if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
422 if (ios->cis_io->ci_type == CIT_READ ||
423 ios->cis_io->ci_type == CIT_WRITE ||
424 ios->cis_io->ci_type == CIT_FAULT)
430 end = lov_offset_mod(end, +1);
431 sub = lov_sub_get(env, lio, stripe);
433 lov_io_sub_inherit(sub->sub_io, lio, stripe,
435 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
437 CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
443 list_add_tail(&sub->sub_linkage, &lio->lis_active);
450 static int lov_io_rw_iter_init(const struct lu_env *env,
451 const struct cl_io_slice *ios)
453 struct lov_io *lio = cl2lov_io(env, ios);
454 struct cl_io *io = ios->cis_io;
455 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
456 loff_t start = io->u.ci_rw.crw_pos;
458 unsigned long ssize = lsm->lsm_stripe_size;
460 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
463 /* fast path for common case. */
464 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
466 lov_do_div64(start, ssize);
467 next = (start + 1) * ssize;
468 if (next <= start * ssize)
471 io->ci_continue = next < lio->lis_io_endpos;
472 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
473 next) - io->u.ci_rw.crw_pos;
474 lio->lis_pos = io->u.ci_rw.crw_pos;
475 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
476 CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
477 LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
478 (__u64)lio->lis_io_endpos);
481 * XXX The following call should be optimized: we know, that
482 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
484 RETURN(lov_io_iter_init(env, ios));
487 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
488 int (*iofunc)(const struct lu_env *, struct cl_io *))
490 struct cl_io *parent = lio->lis_cl.cis_io;
491 struct lov_io_sub *sub;
495 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
497 rc = iofunc(sub->sub_env, sub->sub_io);
502 if (parent->ci_result == 0)
503 parent->ci_result = sub->sub_io->ci_result;
508 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
511 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
514 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
517 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
520 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
524 * It's possible that lov_io_start() wasn't called against this
525 * sub-io, either because previous sub-io failed, or upper layer
528 if (io->ci_state == CIS_IO_GOING)
531 io->ci_state = CIS_IO_FINISHED;
535 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
537 cl_io_iter_fini(env, io);
541 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
543 cl_io_unlock(env, io);
547 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
551 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
555 static void lov_io_iter_fini(const struct lu_env *env,
556 const struct cl_io_slice *ios)
558 struct lov_io *lio = cl2lov_io(env, ios);
562 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
564 while (!list_empty(&lio->lis_active))
565 list_del_init(lio->lis_active.next);
569 static void lov_io_unlock(const struct lu_env *env,
570 const struct cl_io_slice *ios)
575 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
581 * lov implementation of cl_operations::cio_submit() method. It takes a list
582 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
583 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
586 * Major complication of this function is a need to handle memory cleansing:
587 * cl_io_submit() is called to write out pages as a part of VM memory
588 * reclamation, and hence it may not fail due to memory shortages (system
589 * dead-locks otherwise). To deal with this, some resources (sub-lists,
590 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
591 * not-memory cleansing context), and in case of memory shortage, these
592 * pre-allocated resources are used by lov_io_submit() under
593 * lov_device::ld_mutex mutex.
595 static int lov_io_submit(const struct lu_env *env,
596 const struct cl_io_slice *ios,
597 enum cl_req_type crt, struct cl_2queue *queue)
599 struct cl_page_list *qin = &queue->c2_qin;
600 struct lov_io *lio = cl2lov_io(env, ios);
601 struct lov_io_sub *sub;
602 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
603 struct cl_page *page;
608 if (lio->lis_active_subios == 1) {
609 int idx = lio->lis_single_subio_index;
611 LASSERT(idx < lio->lis_nr_subios);
612 sub = lov_sub_get(env, lio, idx);
613 LASSERT(!IS_ERR(sub));
614 LASSERT(sub->sub_io == &lio->lis_single_subio);
615 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
621 LASSERT(lio->lis_subs != NULL);
623 cl_page_list_init(plist);
624 while (qin->pl_nr > 0) {
625 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
627 cl_2queue_init(cl2q);
629 page = cl_page_list_first(qin);
630 cl_page_list_move(&cl2q->c2_qin, qin, page);
632 stripe = lov_page_stripe(page);
633 while (qin->pl_nr > 0) {
634 page = cl_page_list_first(qin);
635 if (stripe != lov_page_stripe(page))
638 cl_page_list_move(&cl2q->c2_qin, qin, page);
641 sub = lov_sub_get(env, lio, stripe);
643 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
650 cl_page_list_splice(&cl2q->c2_qin, plist);
651 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
652 cl_2queue_fini(env, cl2q);
658 cl_page_list_splice(plist, qin);
659 cl_page_list_fini(env, plist);
664 static int lov_io_commit_async(const struct lu_env *env,
665 const struct cl_io_slice *ios,
666 struct cl_page_list *queue, int from, int to,
669 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
670 struct lov_io *lio = cl2lov_io(env, ios);
671 struct lov_io_sub *sub;
672 struct cl_page *page;
676 if (lio->lis_active_subios == 1) {
677 int idx = lio->lis_single_subio_index;
679 LASSERT(idx < lio->lis_nr_subios);
680 sub = lov_sub_get(env, lio, idx);
681 LASSERT(!IS_ERR(sub));
682 LASSERT(sub->sub_io == &lio->lis_single_subio);
683 rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
689 LASSERT(lio->lis_subs != NULL);
691 cl_page_list_init(plist);
692 while (queue->pl_nr > 0) {
696 LASSERT(plist->pl_nr == 0);
697 page = cl_page_list_first(queue);
698 cl_page_list_move(plist, queue, page);
700 stripe = lov_page_stripe(page);
701 while (queue->pl_nr > 0) {
702 page = cl_page_list_first(queue);
703 if (stripe != lov_page_stripe(page))
706 cl_page_list_move(plist, queue, page);
709 if (queue->pl_nr > 0) /* still has more pages */
710 stripe_to = PAGE_SIZE;
712 sub = lov_sub_get(env, lio, stripe);
714 rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
715 plist, from, stripe_to, cb);
722 if (plist->pl_nr > 0) /* short write */
728 /* for error case, add the page back into the qin list */
729 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
730 while (plist->pl_nr > 0) {
731 /* error occurred, add the uncommitted pages back into queue */
732 page = cl_page_list_last(plist);
733 cl_page_list_move_head(queue, plist, page);
739 static int lov_io_fault_start(const struct lu_env *env,
740 const struct cl_io_slice *ios)
742 struct cl_fault_io *fio;
744 struct lov_io_sub *sub;
747 fio = &ios->cis_io->u.ci_fault;
748 lio = cl2lov_io(env, ios);
749 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
750 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
752 RETURN(lov_io_start(env, ios));
755 static void lov_io_fsync_end(const struct lu_env *env,
756 const struct cl_io_slice *ios)
758 struct lov_io *lio = cl2lov_io(env, ios);
759 struct lov_io_sub *sub;
760 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
764 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
765 struct cl_io *subio = sub->sub_io;
768 lov_io_end_wrapper(sub->sub_env, subio);
771 if (subio->ci_result == 0)
772 *written += subio->u.ci_fsync.fi_nr_written;
777 static const struct cl_io_operations lov_io_ops = {
780 .cio_fini = lov_io_fini,
781 .cio_iter_init = lov_io_rw_iter_init,
782 .cio_iter_fini = lov_io_iter_fini,
783 .cio_lock = lov_io_lock,
784 .cio_unlock = lov_io_unlock,
785 .cio_start = lov_io_start,
786 .cio_end = lov_io_end
789 .cio_fini = lov_io_fini,
790 .cio_iter_init = lov_io_rw_iter_init,
791 .cio_iter_fini = lov_io_iter_fini,
792 .cio_lock = lov_io_lock,
793 .cio_unlock = lov_io_unlock,
794 .cio_start = lov_io_start,
795 .cio_end = lov_io_end
798 .cio_fini = lov_io_fini,
799 .cio_iter_init = lov_io_iter_init,
800 .cio_iter_fini = lov_io_iter_fini,
801 .cio_lock = lov_io_lock,
802 .cio_unlock = lov_io_unlock,
803 .cio_start = lov_io_start,
804 .cio_end = lov_io_end
807 .cio_fini = lov_io_fini,
808 .cio_iter_init = lov_io_iter_init,
809 .cio_iter_fini = lov_io_iter_fini,
810 .cio_lock = lov_io_lock,
811 .cio_unlock = lov_io_unlock,
812 .cio_start = lov_io_fault_start,
813 .cio_end = lov_io_end
816 .cio_fini = lov_io_fini,
817 .cio_iter_init = lov_io_iter_init,
818 .cio_iter_fini = lov_io_iter_fini,
819 .cio_lock = lov_io_lock,
820 .cio_unlock = lov_io_unlock,
821 .cio_start = lov_io_start,
822 .cio_end = lov_io_fsync_end
825 .cio_fini = lov_io_fini
828 .cio_submit = lov_io_submit,
829 .cio_commit_async = lov_io_commit_async,
832 /*****************************************************************************
834 * Empty lov io operations.
838 static void lov_empty_io_fini(const struct lu_env *env,
839 const struct cl_io_slice *ios)
841 struct lov_object *lov = cl2lov(ios->cis_obj);
844 if (atomic_dec_and_test(&lov->lo_active_ios))
845 wake_up_all(&lov->lo_waitq);
849 static void lov_empty_impossible(const struct lu_env *env,
850 struct cl_io_slice *ios)
855 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
858 * An io operation vector for files without stripes.
860 static const struct cl_io_operations lov_empty_io_ops = {
863 .cio_fini = lov_empty_io_fini,
865 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
866 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
867 .cio_start = LOV_EMPTY_IMPOSSIBLE,
868 .cio_end = LOV_EMPTY_IMPOSSIBLE
872 .cio_fini = lov_empty_io_fini,
873 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
874 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
875 .cio_start = LOV_EMPTY_IMPOSSIBLE,
876 .cio_end = LOV_EMPTY_IMPOSSIBLE
879 .cio_fini = lov_empty_io_fini,
880 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
881 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
882 .cio_start = LOV_EMPTY_IMPOSSIBLE,
883 .cio_end = LOV_EMPTY_IMPOSSIBLE
886 .cio_fini = lov_empty_io_fini,
887 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
888 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
889 .cio_start = LOV_EMPTY_IMPOSSIBLE,
890 .cio_end = LOV_EMPTY_IMPOSSIBLE
893 .cio_fini = lov_empty_io_fini
896 .cio_fini = lov_empty_io_fini
899 .cio_submit = LOV_EMPTY_IMPOSSIBLE,
900 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
903 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
906 struct lov_io *lio = lov_env_io(env);
907 struct lov_object *lov = cl2lov(obj);
910 INIT_LIST_HEAD(&lio->lis_active);
911 io->ci_result = lov_io_slice_init(lio, lov, io);
912 if (io->ci_result != 0)
913 RETURN(io->ci_result);
915 if (io->ci_result == 0) {
916 io->ci_result = lov_io_subio_init(env, lio, io);
917 if (io->ci_result == 0) {
918 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
919 atomic_inc(&lov->lo_active_ios);
922 RETURN(io->ci_result);
925 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
928 struct lov_object *lov = cl2lov(obj);
929 struct lov_io *lio = lov_env_io(env);
933 lio->lis_object = lov;
934 switch (io->ci_type) {
950 CERROR("Page fault on a file without stripes: "DFID"\n",
951 PFID(lu_object_fid(&obj->co_lu)));
955 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
956 atomic_inc(&lov->lo_active_ios);
959 io->ci_result = result < 0 ? result : 0;
963 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
966 struct lov_object *lov = cl2lov(obj);
967 struct lov_io *lio = lov_env_io(env);
971 LASSERT(lov->lo_lsm != NULL);
972 lio->lis_object = lov;
974 switch (io->ci_type) {
976 LASSERTF(0, "invalid type %d\n", io->ci_type);
982 /* the truncate to 0 is managed by MDT:
983 * - in open, for open O_TRUNC
984 * - in setattr, for truncate
986 /* the truncate is for size > 0 so triggers a restore */
987 if (cl_io_is_trunc(io))
988 io->ci_restore_needed = 1;
994 io->ci_restore_needed = 1;
999 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1000 atomic_inc(&lov->lo_active_ios);
1003 io->ci_result = result < 0 ? result : 0;
1004 RETURN(result != 0);