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, 2014, 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;
91 switch (io->ci_type) {
93 io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
94 io->u.ci_setattr.sa_attr_flags =
95 parent->u.ci_setattr.sa_attr_flags;
96 io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
97 io->u.ci_setattr.sa_stripe_index = stripe;
98 io->u.ci_setattr.sa_parent_fid =
99 parent->u.ci_setattr.sa_parent_fid;
100 io->u.ci_setattr.sa_capa = parent->u.ci_setattr.sa_capa;
101 if (cl_io_is_trunc(io)) {
102 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
104 new_size = lov_size_to_stripe(lsm, new_size, stripe);
105 io->u.ci_setattr.sa_attr.lvb_size = new_size;
110 struct cl_object *obj = parent->ci_obj;
111 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
113 io->u.ci_fault = parent->u.ci_fault;
114 off = lov_size_to_stripe(lsm, off, stripe);
115 io->u.ci_fault.ft_index = cl_index(obj, off);
119 io->u.ci_fsync.fi_start = start;
120 io->u.ci_fsync.fi_end = end;
121 io->u.ci_fsync.fi_capa = parent->u.ci_fsync.fi_capa;
122 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
123 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
128 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
129 if (cl_io_is_append(parent)) {
130 io->u.ci_wr.wr_append = 1;
132 io->u.ci_rw.crw_pos = start;
133 io->u.ci_rw.crw_count = end - start;
142 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
143 struct lov_io_sub *sub)
145 struct lov_object *lov = lio->lis_object;
146 struct lov_device *ld = lu2lov_dev(lov2cl(lov)->co_lu.lo_dev);
147 struct cl_io *sub_io;
148 struct cl_object *sub_obj;
149 struct cl_io *io = lio->lis_cl.cis_io;
151 int stripe = sub->sub_stripe;
154 LASSERT(sub->sub_io == NULL);
155 LASSERT(sub->sub_env == NULL);
156 LASSERT(sub->sub_stripe < lio->lis_stripe_count);
159 if (unlikely(lov_r0(lov)->lo_sub[stripe] == NULL))
163 sub->sub_io_initialized = 0;
164 sub->sub_borrowed = 0;
166 if (lio->lis_mem_frozen) {
167 LASSERT(mutex_is_locked(&ld->ld_mutex));
168 sub->sub_io = &ld->ld_emrg[stripe]->emrg_subio;
169 sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
170 sub->sub_borrowed = 1;
174 /* obtain new environment */
175 cookie = cl_env_reenter();
176 sub->sub_env = cl_env_get(&sub->sub_refcheck);
177 cl_env_reexit(cookie);
178 if (IS_ERR(sub->sub_env))
179 result = PTR_ERR(sub->sub_env);
183 * First sub-io. Use ->lis_single_subio to
184 * avoid dynamic allocation.
186 if (lio->lis_active_subios == 0) {
187 sub->sub_io = &lio->lis_single_subio;
188 lio->lis_single_subio_index = stripe;
190 OBD_ALLOC_PTR(sub->sub_io);
191 if (sub->sub_io == NULL)
198 sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
199 sub_io = sub->sub_io;
201 sub_io->ci_obj = sub_obj;
202 sub_io->ci_result = 0;
204 sub_io->ci_parent = io;
205 sub_io->ci_lockreq = io->ci_lockreq;
206 sub_io->ci_type = io->ci_type;
207 sub_io->ci_no_srvlock = io->ci_no_srvlock;
208 sub_io->ci_noatime = io->ci_noatime;
211 result = cl_io_sub_init(sub->sub_env, sub_io,
212 io->ci_type, sub_obj);
215 lio->lis_active_subios++;
216 sub->sub_io_initialized = 1;
221 lov_io_sub_fini(env, lio, sub);
225 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
226 struct lov_io *lio, int stripe)
229 struct lov_io_sub *sub = &lio->lis_subs[stripe];
231 LASSERT(stripe < lio->lis_stripe_count);
234 if (!sub->sub_io_initialized) {
235 sub->sub_stripe = stripe;
236 rc = lov_io_sub_init(env, lio, sub);
246 void lov_sub_put(struct lov_io_sub *sub)
251 /*****************************************************************************
257 int lov_page_stripe(const struct cl_page *page)
259 const struct cl_page_slice *slice;
262 slice = cl_page_at(page, &lov_device_type);
263 LASSERT(slice != NULL);
264 LASSERT(slice->cpl_obj != NULL);
266 RETURN(cl2lov_page(slice)->lps_stripe);
269 struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
270 const struct cl_page_slice *slice)
272 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
273 struct cl_page *page = slice->cpl_page;
276 LASSERT(lio->lis_cl.cis_io != NULL);
277 LASSERT(cl2lov(slice->cpl_obj) == lio->lis_object);
278 LASSERT(lsm != NULL);
279 LASSERT(lio->lis_nr_subios > 0);
282 stripe = lov_page_stripe(page);
283 RETURN(lov_sub_get(env, lio, stripe));
287 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
290 struct lov_stripe_md *lsm;
294 LASSERT(lio->lis_object != NULL);
295 lsm = lio->lis_object->lo_lsm;
298 * Need to be optimized, we can't afford to allocate a piece of memory
299 * when writing a page. -jay
301 OBD_ALLOC_LARGE(lio->lis_subs,
302 lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
303 if (lio->lis_subs != NULL) {
304 lio->lis_nr_subios = lio->lis_stripe_count;
305 lio->lis_single_subio_index = -1;
306 lio->lis_active_subios = 0;
313 static int lov_io_slice_init(struct lov_io *lio,
314 struct lov_object *obj, struct cl_io *io)
319 lio->lis_object = obj;
321 LASSERT(obj->lo_lsm != NULL);
322 lio->lis_stripe_count = obj->lo_lsm->lsm_stripe_count;
324 switch (io->ci_type) {
327 lio->lis_pos = io->u.ci_rw.crw_pos;
328 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
329 lio->lis_io_endpos = lio->lis_endpos;
330 if (cl_io_is_append(io)) {
331 LASSERT(io->ci_type == CIT_WRITE);
333 /* If there is LOV EA hole, then we may cannot locate
334 * the current file-tail exactly. */
335 if (unlikely(obj->lo_lsm->lsm_pattern &
340 lio->lis_endpos = OBD_OBJECT_EOF;
345 if (cl_io_is_trunc(io))
346 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
349 lio->lis_endpos = OBD_OBJECT_EOF;
353 pgoff_t index = io->u.ci_fault.ft_index;
354 lio->lis_pos = cl_offset(io->ci_obj, index);
355 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
360 lio->lis_pos = io->u.ci_fsync.fi_start;
361 lio->lis_endpos = io->u.ci_fsync.fi_end;
367 lio->lis_endpos = OBD_OBJECT_EOF;
377 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
379 struct lov_io *lio = cl2lov_io(env, ios);
380 struct lov_object *lov = cl2lov(ios->cis_obj);
384 if (lio->lis_subs != NULL) {
385 for (i = 0; i < lio->lis_nr_subios; i++)
386 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
387 OBD_FREE_LARGE(lio->lis_subs,
388 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
389 lio->lis_nr_subios = 0;
392 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
393 if (atomic_dec_and_test(&lov->lo_active_ios))
394 wake_up_all(&lov->lo_waitq);
398 static loff_t lov_offset_mod(loff_t val, int delta)
400 if (val != OBD_OBJECT_EOF)
405 static int lov_io_iter_init(const struct lu_env *env,
406 const struct cl_io_slice *ios)
408 struct lov_io *lio = cl2lov_io(env, ios);
409 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
410 struct lov_io_sub *sub;
418 endpos = lov_offset_mod(lio->lis_endpos, -1);
419 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
420 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
421 endpos, &start, &end))
424 if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
425 if (ios->cis_io->ci_type == CIT_READ ||
426 ios->cis_io->ci_type == CIT_WRITE ||
427 ios->cis_io->ci_type == CIT_FAULT)
433 end = lov_offset_mod(end, +1);
434 sub = lov_sub_get(env, lio, stripe);
436 lov_io_sub_inherit(sub->sub_io, lio, stripe,
438 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
440 CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
446 list_add_tail(&sub->sub_linkage, &lio->lis_active);
453 static int lov_io_rw_iter_init(const struct lu_env *env,
454 const struct cl_io_slice *ios)
456 struct lov_io *lio = cl2lov_io(env, ios);
457 struct cl_io *io = ios->cis_io;
458 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
459 loff_t start = io->u.ci_rw.crw_pos;
461 unsigned long ssize = lsm->lsm_stripe_size;
463 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
466 /* fast path for common case. */
467 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
469 lov_do_div64(start, ssize);
470 next = (start + 1) * ssize;
471 if (next <= start * ssize)
474 io->ci_continue = next < lio->lis_io_endpos;
475 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
476 next) - io->u.ci_rw.crw_pos;
477 lio->lis_pos = io->u.ci_rw.crw_pos;
478 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
479 CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
480 LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
481 (__u64)lio->lis_io_endpos);
484 * XXX The following call should be optimized: we know, that
485 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
487 RETURN(lov_io_iter_init(env, ios));
490 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
491 int (*iofunc)(const struct lu_env *, struct cl_io *))
493 struct cl_io *parent = lio->lis_cl.cis_io;
494 struct lov_io_sub *sub;
498 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
500 rc = iofunc(sub->sub_env, sub->sub_io);
505 if (parent->ci_result == 0)
506 parent->ci_result = sub->sub_io->ci_result;
511 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
514 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
517 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
520 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
523 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
527 * It's possible that lov_io_start() wasn't called against this
528 * sub-io, either because previous sub-io failed, or upper layer
531 if (io->ci_state == CIS_IO_GOING)
534 io->ci_state = CIS_IO_FINISHED;
538 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
540 cl_io_iter_fini(env, io);
544 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
546 cl_io_unlock(env, io);
550 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
554 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
558 static void lov_io_iter_fini(const struct lu_env *env,
559 const struct cl_io_slice *ios)
561 struct lov_io *lio = cl2lov_io(env, ios);
565 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
567 while (!list_empty(&lio->lis_active))
568 list_del_init(lio->lis_active.next);
572 static void lov_io_unlock(const struct lu_env *env,
573 const struct cl_io_slice *ios)
578 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
583 static int lov_io_read_ahead(const struct lu_env *env,
584 const struct cl_io_slice *ios,
585 pgoff_t start, struct cl_read_ahead *ra)
587 struct lov_io *lio = cl2lov_io(env, ios);
588 struct lov_object *loo = lio->lis_object;
589 struct cl_object *obj = lov2cl(loo);
590 struct lov_layout_raid0 *r0 = lov_r0(loo);
591 struct lov_io_sub *sub;
594 unsigned int pps; /* pages per stripe */
599 stripe = lov_stripe_number(loo->lo_lsm, cl_offset(obj, start));
600 if (unlikely(r0->lo_sub[stripe] == NULL))
603 sub = lov_sub_get(env, lio, stripe);
605 lov_stripe_offset(loo->lo_lsm, cl_offset(obj, start), stripe, &suboff);
606 rc = cl_io_read_ahead(sub->sub_env, sub->sub_io,
607 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
611 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
612 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
617 * Adjust the stripe index by layout of raid0. ra->cra_end is the maximum
618 * page index covered by an underlying DLM lock.
619 * This function converts cra_end from stripe level to file level, and
620 * make sure it's not beyond stripe boundary.
622 if (r0->lo_nr == 1) /* single stripe file */
625 /* cra_end is stripe level, convert it into file level */
626 ra_end = ra->cra_end;
627 if (ra_end != CL_PAGE_EOF)
628 ra_end = lov_stripe_pgoff(loo->lo_lsm, ra_end, stripe);
630 pps = loo->lo_lsm->lsm_stripe_size >> PAGE_CACHE_SHIFT;
632 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, "
633 "stripe_size = %u, stripe no = %u, start index = %lu\n",
634 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps,
635 loo->lo_lsm->lsm_stripe_size, stripe, start);
637 /* never exceed the end of the stripe */
638 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
643 * lov implementation of cl_operations::cio_submit() method. It takes a list
644 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
645 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
648 * Major complication of this function is a need to handle memory cleansing:
649 * cl_io_submit() is called to write out pages as a part of VM memory
650 * reclamation, and hence it may not fail due to memory shortages (system
651 * dead-locks otherwise). To deal with this, some resources (sub-lists,
652 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
653 * not-memory cleansing context), and in case of memory shortage, these
654 * pre-allocated resources are used by lov_io_submit() under
655 * lov_device::ld_mutex mutex.
657 static int lov_io_submit(const struct lu_env *env,
658 const struct cl_io_slice *ios,
659 enum cl_req_type crt, struct cl_2queue *queue)
661 struct cl_page_list *qin = &queue->c2_qin;
662 struct lov_io *lio = cl2lov_io(env, ios);
663 struct lov_io_sub *sub;
664 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
665 struct cl_page *page;
670 if (lio->lis_active_subios == 1) {
671 int idx = lio->lis_single_subio_index;
673 LASSERT(idx < lio->lis_nr_subios);
674 sub = lov_sub_get(env, lio, idx);
675 LASSERT(!IS_ERR(sub));
676 LASSERT(sub->sub_io == &lio->lis_single_subio);
677 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
683 LASSERT(lio->lis_subs != NULL);
685 cl_page_list_init(plist);
686 while (qin->pl_nr > 0) {
687 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
689 cl_2queue_init(cl2q);
691 page = cl_page_list_first(qin);
692 cl_page_list_move(&cl2q->c2_qin, qin, page);
694 stripe = lov_page_stripe(page);
695 while (qin->pl_nr > 0) {
696 page = cl_page_list_first(qin);
697 if (stripe != lov_page_stripe(page))
700 cl_page_list_move(&cl2q->c2_qin, qin, page);
703 sub = lov_sub_get(env, lio, stripe);
705 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
712 cl_page_list_splice(&cl2q->c2_qin, plist);
713 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
714 cl_2queue_fini(env, cl2q);
720 cl_page_list_splice(plist, qin);
721 cl_page_list_fini(env, plist);
726 static int lov_io_commit_async(const struct lu_env *env,
727 const struct cl_io_slice *ios,
728 struct cl_page_list *queue, int from, int to,
731 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
732 struct lov_io *lio = cl2lov_io(env, ios);
733 struct lov_io_sub *sub;
734 struct cl_page *page;
738 if (lio->lis_active_subios == 1) {
739 int idx = lio->lis_single_subio_index;
741 LASSERT(idx < lio->lis_nr_subios);
742 sub = lov_sub_get(env, lio, idx);
743 LASSERT(!IS_ERR(sub));
744 LASSERT(sub->sub_io == &lio->lis_single_subio);
745 rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
751 LASSERT(lio->lis_subs != NULL);
753 cl_page_list_init(plist);
754 while (queue->pl_nr > 0) {
758 LASSERT(plist->pl_nr == 0);
759 page = cl_page_list_first(queue);
760 cl_page_list_move(plist, queue, page);
762 stripe = lov_page_stripe(page);
763 while (queue->pl_nr > 0) {
764 page = cl_page_list_first(queue);
765 if (stripe != lov_page_stripe(page))
768 cl_page_list_move(plist, queue, page);
771 if (queue->pl_nr > 0) /* still has more pages */
772 stripe_to = PAGE_SIZE;
774 sub = lov_sub_get(env, lio, stripe);
776 rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
777 plist, from, stripe_to, cb);
784 if (plist->pl_nr > 0) /* short write */
790 /* for error case, add the page back into the qin list */
791 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
792 while (plist->pl_nr > 0) {
793 /* error occurred, add the uncommitted pages back into queue */
794 page = cl_page_list_last(plist);
795 cl_page_list_move_head(queue, plist, page);
801 static int lov_io_fault_start(const struct lu_env *env,
802 const struct cl_io_slice *ios)
804 struct cl_fault_io *fio;
806 struct lov_io_sub *sub;
809 fio = &ios->cis_io->u.ci_fault;
810 lio = cl2lov_io(env, ios);
811 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
812 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
814 RETURN(lov_io_start(env, ios));
817 static void lov_io_fsync_end(const struct lu_env *env,
818 const struct cl_io_slice *ios)
820 struct lov_io *lio = cl2lov_io(env, ios);
821 struct lov_io_sub *sub;
822 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
826 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
827 struct cl_io *subio = sub->sub_io;
830 lov_io_end_wrapper(sub->sub_env, subio);
833 if (subio->ci_result == 0)
834 *written += subio->u.ci_fsync.fi_nr_written;
839 static const struct cl_io_operations lov_io_ops = {
842 .cio_fini = lov_io_fini,
843 .cio_iter_init = lov_io_rw_iter_init,
844 .cio_iter_fini = lov_io_iter_fini,
845 .cio_lock = lov_io_lock,
846 .cio_unlock = lov_io_unlock,
847 .cio_start = lov_io_start,
848 .cio_end = lov_io_end
851 .cio_fini = lov_io_fini,
852 .cio_iter_init = lov_io_rw_iter_init,
853 .cio_iter_fini = lov_io_iter_fini,
854 .cio_lock = lov_io_lock,
855 .cio_unlock = lov_io_unlock,
856 .cio_start = lov_io_start,
857 .cio_end = lov_io_end
860 .cio_fini = lov_io_fini,
861 .cio_iter_init = lov_io_iter_init,
862 .cio_iter_fini = lov_io_iter_fini,
863 .cio_lock = lov_io_lock,
864 .cio_unlock = lov_io_unlock,
865 .cio_start = lov_io_start,
866 .cio_end = lov_io_end
869 .cio_fini = lov_io_fini,
870 .cio_iter_init = lov_io_iter_init,
871 .cio_iter_fini = lov_io_iter_fini,
872 .cio_lock = lov_io_lock,
873 .cio_unlock = lov_io_unlock,
874 .cio_start = lov_io_fault_start,
875 .cio_end = lov_io_end
878 .cio_fini = lov_io_fini,
879 .cio_iter_init = lov_io_iter_init,
880 .cio_iter_fini = lov_io_iter_fini,
881 .cio_lock = lov_io_lock,
882 .cio_unlock = lov_io_unlock,
883 .cio_start = lov_io_start,
884 .cio_end = lov_io_fsync_end
887 .cio_fini = lov_io_fini
890 .cio_read_ahead = lov_io_read_ahead,
891 .cio_submit = lov_io_submit,
892 .cio_commit_async = lov_io_commit_async,
895 /*****************************************************************************
897 * Empty lov io operations.
901 static void lov_empty_io_fini(const struct lu_env *env,
902 const struct cl_io_slice *ios)
904 struct lov_object *lov = cl2lov(ios->cis_obj);
907 if (atomic_dec_and_test(&lov->lo_active_ios))
908 wake_up_all(&lov->lo_waitq);
912 static void lov_empty_impossible(const struct lu_env *env,
913 struct cl_io_slice *ios)
918 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
921 * An io operation vector for files without stripes.
923 static const struct cl_io_operations lov_empty_io_ops = {
926 .cio_fini = lov_empty_io_fini,
928 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
929 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
930 .cio_start = LOV_EMPTY_IMPOSSIBLE,
931 .cio_end = LOV_EMPTY_IMPOSSIBLE
935 .cio_fini = lov_empty_io_fini,
936 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
937 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
938 .cio_start = LOV_EMPTY_IMPOSSIBLE,
939 .cio_end = LOV_EMPTY_IMPOSSIBLE
942 .cio_fini = lov_empty_io_fini,
943 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
944 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
945 .cio_start = LOV_EMPTY_IMPOSSIBLE,
946 .cio_end = LOV_EMPTY_IMPOSSIBLE
949 .cio_fini = lov_empty_io_fini,
950 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
951 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
952 .cio_start = LOV_EMPTY_IMPOSSIBLE,
953 .cio_end = LOV_EMPTY_IMPOSSIBLE
956 .cio_fini = lov_empty_io_fini
959 .cio_fini = lov_empty_io_fini
962 .cio_submit = LOV_EMPTY_IMPOSSIBLE,
963 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
966 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
969 struct lov_io *lio = lov_env_io(env);
970 struct lov_object *lov = cl2lov(obj);
973 INIT_LIST_HEAD(&lio->lis_active);
974 io->ci_result = lov_io_slice_init(lio, lov, io);
975 if (io->ci_result != 0)
976 RETURN(io->ci_result);
978 if (io->ci_result == 0) {
979 io->ci_result = lov_io_subio_init(env, lio, io);
980 if (io->ci_result == 0) {
981 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
982 atomic_inc(&lov->lo_active_ios);
985 RETURN(io->ci_result);
988 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
991 struct lov_object *lov = cl2lov(obj);
992 struct lov_io *lio = lov_env_io(env);
996 lio->lis_object = lov;
997 switch (io->ci_type) {
1013 CERROR("Page fault on a file without stripes: "DFID"\n",
1014 PFID(lu_object_fid(&obj->co_lu)));
1018 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1019 atomic_inc(&lov->lo_active_ios);
1022 io->ci_result = result < 0 ? result : 0;
1023 RETURN(result != 0);
1026 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1029 struct lov_object *lov = cl2lov(obj);
1030 struct lov_io *lio = lov_env_io(env);
1034 LASSERT(lov->lo_lsm != NULL);
1035 lio->lis_object = lov;
1037 switch (io->ci_type) {
1039 LASSERTF(0, "invalid type %d\n", io->ci_type);
1045 /* the truncate to 0 is managed by MDT:
1046 * - in open, for open O_TRUNC
1047 * - in setattr, for truncate
1049 /* the truncate is for size > 0 so triggers a restore */
1050 if (cl_io_is_trunc(io))
1051 io->ci_restore_needed = 1;
1057 io->ci_restore_needed = 1;
1062 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1063 atomic_inc(&lov->lo_active_ios);
1066 io->ci_result = result < 0 ? result : 0;
1067 RETURN(result != 0);