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);
155 sub->sub_io_initialized = 0;
156 sub->sub_borrowed = 0;
158 if (lio->lis_mem_frozen) {
159 LASSERT(mutex_is_locked(&ld->ld_mutex));
160 sub->sub_io = &ld->ld_emrg[stripe]->emrg_subio;
161 sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
162 sub->sub_borrowed = 1;
166 /* obtain new environment */
167 cookie = cl_env_reenter();
168 sub->sub_env = cl_env_get(&sub->sub_refcheck);
169 cl_env_reexit(cookie);
170 if (IS_ERR(sub->sub_env))
171 result = PTR_ERR(sub->sub_env);
175 * First sub-io. Use ->lis_single_subio to
176 * avoid dynamic allocation.
178 if (lio->lis_active_subios == 0) {
179 sub->sub_io = &lio->lis_single_subio;
180 lio->lis_single_subio_index = stripe;
182 OBD_ALLOC_PTR(sub->sub_io);
183 if (sub->sub_io == NULL)
190 sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
191 sub_io = sub->sub_io;
193 sub_io->ci_obj = sub_obj;
194 sub_io->ci_result = 0;
196 sub_io->ci_parent = io;
197 sub_io->ci_lockreq = io->ci_lockreq;
198 sub_io->ci_type = io->ci_type;
199 sub_io->ci_no_srvlock = io->ci_no_srvlock;
200 sub_io->ci_noatime = io->ci_noatime;
203 result = cl_io_sub_init(sub->sub_env, sub_io,
204 io->ci_type, sub_obj);
207 lio->lis_active_subios++;
208 sub->sub_io_initialized = 1;
213 lov_io_sub_fini(env, lio, sub);
217 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
218 struct lov_io *lio, int stripe)
221 struct lov_io_sub *sub = &lio->lis_subs[stripe];
223 LASSERT(stripe < lio->lis_stripe_count);
226 if (!sub->sub_io_initialized) {
227 sub->sub_stripe = stripe;
228 rc = lov_io_sub_init(env, lio, sub);
238 void lov_sub_put(struct lov_io_sub *sub)
243 /*****************************************************************************
249 static int lov_page_stripe(const struct cl_page *page)
251 struct lovsub_object *subobj;
255 lu_object_locate(page->cp_child->cp_obj->co_lu.lo_header,
256 &lovsub_device_type));
257 LASSERT(subobj != NULL);
258 RETURN(subobj->lso_index);
261 struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
262 const struct cl_page_slice *slice)
264 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
265 struct cl_page *page = slice->cpl_page;
268 LASSERT(lio->lis_cl.cis_io != NULL);
269 LASSERT(cl2lov(slice->cpl_obj) == lio->lis_object);
270 LASSERT(lsm != NULL);
271 LASSERT(lio->lis_nr_subios > 0);
274 stripe = lov_page_stripe(page);
275 RETURN(lov_sub_get(env, lio, stripe));
279 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
282 struct lov_stripe_md *lsm;
286 LASSERT(lio->lis_object != NULL);
287 lsm = lio->lis_object->lo_lsm;
290 * Need to be optimized, we can't afford to allocate a piece of memory
291 * when writing a page. -jay
293 OBD_ALLOC_LARGE(lio->lis_subs,
294 lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
295 if (lio->lis_subs != NULL) {
296 lio->lis_nr_subios = lio->lis_stripe_count;
297 lio->lis_single_subio_index = -1;
298 lio->lis_active_subios = 0;
305 static void lov_io_slice_init(struct lov_io *lio,
306 struct lov_object *obj, struct cl_io *io)
311 lio->lis_object = obj;
313 LASSERT(obj->lo_lsm != NULL);
314 lio->lis_stripe_count = obj->lo_lsm->lsm_stripe_count;
316 switch (io->ci_type) {
319 lio->lis_pos = io->u.ci_rw.crw_pos;
320 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
321 lio->lis_io_endpos = lio->lis_endpos;
322 if (cl_io_is_append(io)) {
323 LASSERT(io->ci_type == CIT_WRITE);
325 lio->lis_endpos = OBD_OBJECT_EOF;
330 if (cl_io_is_trunc(io))
331 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
334 lio->lis_endpos = OBD_OBJECT_EOF;
338 pgoff_t index = io->u.ci_fault.ft_index;
339 lio->lis_pos = cl_offset(io->ci_obj, index);
340 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
345 lio->lis_pos = io->u.ci_fsync.fi_start;
346 lio->lis_endpos = io->u.ci_fsync.fi_end;
352 lio->lis_endpos = OBD_OBJECT_EOF;
362 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
364 struct lov_io *lio = cl2lov_io(env, ios);
365 struct lov_object *lov = cl2lov(ios->cis_obj);
369 if (lio->lis_subs != NULL) {
370 for (i = 0; i < lio->lis_nr_subios; i++)
371 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
372 OBD_FREE_LARGE(lio->lis_subs,
373 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
374 lio->lis_nr_subios = 0;
377 LASSERT(cfs_atomic_read(&lov->lo_active_ios) > 0);
378 if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
379 wake_up_all(&lov->lo_waitq);
383 static obd_off lov_offset_mod(obd_off val, int delta)
385 if (val != OBD_OBJECT_EOF)
390 static int lov_io_iter_init(const struct lu_env *env,
391 const struct cl_io_slice *ios)
393 struct lov_io *lio = cl2lov_io(env, ios);
394 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
395 struct lov_io_sub *sub;
403 endpos = lov_offset_mod(lio->lis_endpos, -1);
404 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
405 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
406 endpos, &start, &end))
409 end = lov_offset_mod(end, +1);
410 sub = lov_sub_get(env, lio, stripe);
412 lov_io_sub_inherit(sub->sub_io, lio, stripe,
414 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
416 CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
422 cfs_list_add_tail(&sub->sub_linkage, &lio->lis_active);
429 static int lov_io_rw_iter_init(const struct lu_env *env,
430 const struct cl_io_slice *ios)
432 struct lov_io *lio = cl2lov_io(env, ios);
433 struct cl_io *io = ios->cis_io;
434 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
435 loff_t start = io->u.ci_rw.crw_pos;
437 unsigned long ssize = lsm->lsm_stripe_size;
439 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
442 /* fast path for common case. */
443 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
445 lov_do_div64(start, ssize);
446 next = (start + 1) * ssize;
447 if (next <= start * ssize)
450 io->ci_continue = next < lio->lis_io_endpos;
451 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
452 next) - io->u.ci_rw.crw_pos;
453 lio->lis_pos = io->u.ci_rw.crw_pos;
454 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
455 CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
456 LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
457 (__u64)lio->lis_io_endpos);
460 * XXX The following call should be optimized: we know, that
461 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
463 RETURN(lov_io_iter_init(env, ios));
466 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
467 int (*iofunc)(const struct lu_env *, struct cl_io *))
469 struct cl_io *parent = lio->lis_cl.cis_io;
470 struct lov_io_sub *sub;
474 cfs_list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
476 rc = iofunc(sub->sub_env, sub->sub_io);
481 if (parent->ci_result == 0)
482 parent->ci_result = sub->sub_io->ci_result;
487 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
490 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
493 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
496 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
499 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
503 * It's possible that lov_io_start() wasn't called against this
504 * sub-io, either because previous sub-io failed, or upper layer
507 if (io->ci_state == CIS_IO_GOING)
510 io->ci_state = CIS_IO_FINISHED;
514 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
516 cl_io_iter_fini(env, io);
520 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
522 cl_io_unlock(env, io);
526 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
530 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
534 static void lov_io_iter_fini(const struct lu_env *env,
535 const struct cl_io_slice *ios)
537 struct lov_io *lio = cl2lov_io(env, ios);
541 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
543 while (!cfs_list_empty(&lio->lis_active))
544 cfs_list_del_init(lio->lis_active.next);
548 static void lov_io_unlock(const struct lu_env *env,
549 const struct cl_io_slice *ios)
554 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
560 static struct cl_page_list *lov_io_submit_qin(struct lov_device *ld,
561 struct cl_page_list *qin,
564 return alloc ? &qin[idx] : &ld->ld_emrg[idx]->emrg_page_list;
568 * lov implementation of cl_operations::cio_submit() method. It takes a list
569 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
570 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
573 * Major complication of this function is a need to handle memory cleansing:
574 * cl_io_submit() is called to write out pages as a part of VM memory
575 * reclamation, and hence it may not fail due to memory shortages (system
576 * dead-locks otherwise). To deal with this, some resources (sub-lists,
577 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
578 * not-memory cleansing context), and in case of memory shortage, these
579 * pre-allocated resources are used by lov_io_submit() under
580 * lov_device::ld_mutex mutex.
582 static int lov_io_submit(const struct lu_env *env,
583 const struct cl_io_slice *ios,
584 enum cl_req_type crt, struct cl_2queue *queue)
586 struct lov_io *lio = cl2lov_io(env, ios);
587 struct lov_object *obj = lio->lis_object;
588 struct lov_device *ld = lu2lov_dev(lov2cl(obj)->co_lu.lo_dev);
589 struct cl_page_list *qin = &queue->c2_qin;
590 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
591 struct cl_page_list *stripes_qin = NULL;
592 struct cl_page *page;
596 #define QIN(stripe) lov_io_submit_qin(ld, stripes_qin, stripe, alloc)
600 #if defined(__KERNEL__) && defined(__linux__)
601 !(current->flags & PF_MEMALLOC);
606 if (lio->lis_active_subios == 1) {
607 int idx = lio->lis_single_subio_index;
608 struct lov_io_sub *sub;
610 LASSERT(idx < lio->lis_nr_subios);
611 sub = lov_sub_get(env, lio, idx);
612 LASSERT(!IS_ERR(sub));
613 LASSERT(sub->sub_io == &lio->lis_single_subio);
614 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
620 LASSERT(lio->lis_subs != NULL);
622 OBD_ALLOC_LARGE(stripes_qin,
623 sizeof(*stripes_qin) * lio->lis_nr_subios);
624 if (stripes_qin == NULL)
627 for (stripe = 0; stripe < lio->lis_nr_subios; stripe++)
628 cl_page_list_init(&stripes_qin[stripe]);
631 * If we get here, it means pageout & swap doesn't help.
632 * In order to not make things worse, even don't try to
633 * allocate the memory with __GFP_NOWARN. -jay
635 mutex_lock(&ld->ld_mutex);
636 lio->lis_mem_frozen = 1;
639 cl_2queue_init(cl2q);
640 cl_page_list_for_each_safe(page, tmp, qin) {
641 stripe = lov_page_stripe(page);
642 cl_page_list_move(QIN(stripe), qin, page);
645 for (stripe = 0; stripe < lio->lis_nr_subios; stripe++) {
646 struct lov_io_sub *sub;
647 struct cl_page_list *sub_qin = QIN(stripe);
649 if (cfs_list_empty(&sub_qin->pl_pages))
652 cl_page_list_splice(sub_qin, &cl2q->c2_qin);
653 sub = lov_sub_get(env, lio, stripe);
655 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
660 cl_page_list_splice(&cl2q->c2_qin, &queue->c2_qin);
661 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
666 for (stripe = 0; stripe < lio->lis_nr_subios; stripe++) {
667 struct cl_page_list *sub_qin = QIN(stripe);
669 if (cfs_list_empty(&sub_qin->pl_pages))
672 cl_page_list_splice(sub_qin, qin);
676 OBD_FREE_LARGE(stripes_qin,
677 sizeof(*stripes_qin) * lio->lis_nr_subios);
681 for (i = 0; i < lio->lis_nr_subios; i++) {
682 struct cl_io *cio = lio->lis_subs[i].sub_io;
684 if (cio && cio == &ld->ld_emrg[i]->emrg_subio)
685 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
687 lio->lis_mem_frozen = 0;
688 mutex_unlock(&ld->ld_mutex);
695 static int lov_io_prepare_write(const struct lu_env *env,
696 const struct cl_io_slice *ios,
697 const struct cl_page_slice *slice,
698 unsigned from, unsigned to)
700 struct lov_io *lio = cl2lov_io(env, ios);
701 struct cl_page *sub_page = lov_sub_page(slice);
702 struct lov_io_sub *sub;
706 sub = lov_page_subio(env, lio, slice);
708 result = cl_io_prepare_write(sub->sub_env, sub->sub_io,
712 result = PTR_ERR(sub);
716 static int lov_io_commit_write(const struct lu_env *env,
717 const struct cl_io_slice *ios,
718 const struct cl_page_slice *slice,
719 unsigned from, unsigned to)
721 struct lov_io *lio = cl2lov_io(env, ios);
722 struct cl_page *sub_page = lov_sub_page(slice);
723 struct lov_io_sub *sub;
727 sub = lov_page_subio(env, lio, slice);
729 result = cl_io_commit_write(sub->sub_env, sub->sub_io,
733 result = PTR_ERR(sub);
737 static int lov_io_fault_start(const struct lu_env *env,
738 const struct cl_io_slice *ios)
740 struct cl_fault_io *fio;
742 struct lov_io_sub *sub;
745 fio = &ios->cis_io->u.ci_fault;
746 lio = cl2lov_io(env, ios);
747 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
748 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
750 RETURN(lov_io_start(env, ios));
753 static void lov_io_fsync_end(const struct lu_env *env,
754 const struct cl_io_slice *ios)
756 struct lov_io *lio = cl2lov_io(env, ios);
757 struct lov_io_sub *sub;
758 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
762 cfs_list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
763 struct cl_io *subio = sub->sub_io;
766 lov_io_end_wrapper(sub->sub_env, subio);
769 if (subio->ci_result == 0)
770 *written += subio->u.ci_fsync.fi_nr_written;
775 static const struct cl_io_operations lov_io_ops = {
778 .cio_fini = lov_io_fini,
779 .cio_iter_init = lov_io_rw_iter_init,
780 .cio_iter_fini = lov_io_iter_fini,
781 .cio_lock = lov_io_lock,
782 .cio_unlock = lov_io_unlock,
783 .cio_start = lov_io_start,
784 .cio_end = lov_io_end
787 .cio_fini = lov_io_fini,
788 .cio_iter_init = lov_io_rw_iter_init,
789 .cio_iter_fini = lov_io_iter_fini,
790 .cio_lock = lov_io_lock,
791 .cio_unlock = lov_io_unlock,
792 .cio_start = lov_io_start,
793 .cio_end = lov_io_end
796 .cio_fini = lov_io_fini,
797 .cio_iter_init = lov_io_iter_init,
798 .cio_iter_fini = lov_io_iter_fini,
799 .cio_lock = lov_io_lock,
800 .cio_unlock = lov_io_unlock,
801 .cio_start = lov_io_start,
802 .cio_end = lov_io_end
805 .cio_fini = lov_io_fini,
806 .cio_iter_init = lov_io_iter_init,
807 .cio_iter_fini = lov_io_iter_fini,
808 .cio_lock = lov_io_lock,
809 .cio_unlock = lov_io_unlock,
810 .cio_start = lov_io_fault_start,
811 .cio_end = lov_io_end
814 .cio_fini = lov_io_fini,
815 .cio_iter_init = lov_io_iter_init,
816 .cio_iter_fini = lov_io_iter_fini,
817 .cio_lock = lov_io_lock,
818 .cio_unlock = lov_io_unlock,
819 .cio_start = lov_io_start,
820 .cio_end = lov_io_fsync_end
823 .cio_fini = lov_io_fini
828 .cio_submit = lov_io_submit
831 .cio_submit = lov_io_submit
834 .cio_prepare_write = lov_io_prepare_write,
835 .cio_commit_write = lov_io_commit_write
838 /*****************************************************************************
840 * Empty lov io operations.
844 static void lov_empty_io_fini(const struct lu_env *env,
845 const struct cl_io_slice *ios)
847 struct lov_object *lov = cl2lov(ios->cis_obj);
850 if (cfs_atomic_dec_and_test(&lov->lo_active_ios))
851 wake_up_all(&lov->lo_waitq);
855 static void lov_empty_impossible(const struct lu_env *env,
856 struct cl_io_slice *ios)
861 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
864 * An io operation vector for files without stripes.
866 static const struct cl_io_operations lov_empty_io_ops = {
869 .cio_fini = lov_empty_io_fini,
871 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
872 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
873 .cio_start = LOV_EMPTY_IMPOSSIBLE,
874 .cio_end = LOV_EMPTY_IMPOSSIBLE
878 .cio_fini = lov_empty_io_fini,
879 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
880 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
881 .cio_start = LOV_EMPTY_IMPOSSIBLE,
882 .cio_end = LOV_EMPTY_IMPOSSIBLE
885 .cio_fini = lov_empty_io_fini,
886 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
887 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
888 .cio_start = LOV_EMPTY_IMPOSSIBLE,
889 .cio_end = LOV_EMPTY_IMPOSSIBLE
892 .cio_fini = lov_empty_io_fini,
893 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
894 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
895 .cio_start = LOV_EMPTY_IMPOSSIBLE,
896 .cio_end = LOV_EMPTY_IMPOSSIBLE
899 .cio_fini = lov_empty_io_fini
902 .cio_fini = lov_empty_io_fini
907 .cio_submit = LOV_EMPTY_IMPOSSIBLE
910 .cio_submit = LOV_EMPTY_IMPOSSIBLE
913 .cio_commit_write = LOV_EMPTY_IMPOSSIBLE
916 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
919 struct lov_io *lio = lov_env_io(env);
920 struct lov_object *lov = cl2lov(obj);
923 CFS_INIT_LIST_HEAD(&lio->lis_active);
924 lov_io_slice_init(lio, lov, io);
925 if (io->ci_result == 0) {
926 io->ci_result = lov_io_subio_init(env, lio, io);
927 if (io->ci_result == 0) {
928 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
929 cfs_atomic_inc(&lov->lo_active_ios);
932 RETURN(io->ci_result);
935 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
938 struct lov_object *lov = cl2lov(obj);
939 struct lov_io *lio = lov_env_io(env);
943 lio->lis_object = lov;
944 switch (io->ci_type) {
960 CERROR("Page fault on a file without stripes: "DFID"\n",
961 PFID(lu_object_fid(&obj->co_lu)));
965 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
966 cfs_atomic_inc(&lov->lo_active_ios);
969 io->ci_result = result < 0 ? result : 0;
973 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
976 struct lov_object *lov = cl2lov(obj);
977 struct lov_io *lio = lov_env_io(env);
981 LASSERT(lov->lo_lsm != NULL);
982 lio->lis_object = lov;
984 switch (io->ci_type) {
986 LASSERTF(0, "invalid type %d\n", io->ci_type);
992 /* the truncate to 0 is managed by MDT:
993 * - in open, for open O_TRUNC
994 * - in setattr, for truncate
996 /* the truncate is for size > 0 so triggers a restore */
997 if (cl_io_is_trunc(io))
998 io->ci_restore_needed = 1;
1004 io->ci_restore_needed = 1;
1009 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1010 cfs_atomic_inc(&lov->lo_active_ios);
1013 io->ci_result = result < 0 ? result : 0;
1014 RETURN(result != 0);