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, 2015, 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 if (cl_io_is_trunc(io)) {
101 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
103 new_size = lov_size_to_stripe(lsm, new_size, stripe);
104 io->u.ci_setattr.sa_attr.lvb_size = new_size;
108 case CIT_DATA_VERSION: {
109 io->u.ci_data_version.dv_data_version = 0;
110 io->u.ci_data_version.dv_flags =
111 parent->u.ci_data_version.dv_flags;
115 struct cl_object *obj = parent->ci_obj;
116 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
118 io->u.ci_fault = parent->u.ci_fault;
119 off = lov_size_to_stripe(lsm, off, stripe);
120 io->u.ci_fault.ft_index = cl_index(obj, off);
124 io->u.ci_fsync.fi_start = start;
125 io->u.ci_fsync.fi_end = end;
126 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
127 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
132 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
133 if (cl_io_is_append(parent)) {
134 io->u.ci_wr.wr_append = 1;
136 io->u.ci_rw.crw_pos = start;
137 io->u.ci_rw.crw_count = end - start;
146 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
147 struct lov_io_sub *sub)
149 struct lov_object *lov = lio->lis_object;
150 struct lov_device *ld = lu2lov_dev(lov2cl(lov)->co_lu.lo_dev);
151 struct cl_io *sub_io;
152 struct cl_object *sub_obj;
153 struct cl_io *io = lio->lis_cl.cis_io;
155 int stripe = sub->sub_stripe;
158 LASSERT(sub->sub_io == NULL);
159 LASSERT(sub->sub_env == NULL);
160 LASSERT(sub->sub_stripe < lio->lis_stripe_count);
163 if (unlikely(lov_r0(lov)->lo_sub[stripe] == NULL))
167 sub->sub_io_initialized = 0;
168 sub->sub_borrowed = 0;
170 if (lio->lis_mem_frozen) {
171 LASSERT(mutex_is_locked(&ld->ld_mutex));
172 sub->sub_io = &ld->ld_emrg[stripe]->emrg_subio;
173 sub->sub_env = ld->ld_emrg[stripe]->emrg_env;
174 sub->sub_borrowed = 1;
178 /* obtain new environment */
179 cookie = cl_env_reenter();
180 sub->sub_env = cl_env_get(&sub->sub_refcheck);
181 cl_env_reexit(cookie);
182 if (IS_ERR(sub->sub_env))
183 result = PTR_ERR(sub->sub_env);
187 * First sub-io. Use ->lis_single_subio to
188 * avoid dynamic allocation.
190 if (lio->lis_active_subios == 0) {
191 sub->sub_io = &lio->lis_single_subio;
192 lio->lis_single_subio_index = stripe;
194 OBD_ALLOC_PTR(sub->sub_io);
195 if (sub->sub_io == NULL)
202 sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
203 sub_io = sub->sub_io;
205 sub_io->ci_obj = sub_obj;
206 sub_io->ci_result = 0;
208 sub_io->ci_parent = io;
209 sub_io->ci_lockreq = io->ci_lockreq;
210 sub_io->ci_type = io->ci_type;
211 sub_io->ci_no_srvlock = io->ci_no_srvlock;
212 sub_io->ci_noatime = io->ci_noatime;
215 result = cl_io_sub_init(sub->sub_env, sub_io,
216 io->ci_type, sub_obj);
219 lio->lis_active_subios++;
220 sub->sub_io_initialized = 1;
225 lov_io_sub_fini(env, lio, sub);
229 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
230 struct lov_io *lio, int stripe)
233 struct lov_io_sub *sub = &lio->lis_subs[stripe];
235 LASSERT(stripe < lio->lis_stripe_count);
238 if (!sub->sub_io_initialized) {
239 sub->sub_stripe = stripe;
240 rc = lov_io_sub_init(env, lio, sub);
250 void lov_sub_put(struct lov_io_sub *sub)
255 /*****************************************************************************
261 int lov_page_stripe(const struct cl_page *page)
263 const struct cl_page_slice *slice;
266 slice = cl_page_at(page, &lov_device_type);
267 LASSERT(slice != NULL);
268 LASSERT(slice->cpl_obj != NULL);
270 RETURN(cl2lov_page(slice)->lps_stripe);
273 struct lov_io_sub *lov_page_subio(const struct lu_env *env, struct lov_io *lio,
274 const struct cl_page_slice *slice)
276 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
277 struct cl_page *page = slice->cpl_page;
280 LASSERT(lio->lis_cl.cis_io != NULL);
281 LASSERT(cl2lov(slice->cpl_obj) == lio->lis_object);
282 LASSERT(lsm != NULL);
283 LASSERT(lio->lis_nr_subios > 0);
286 stripe = lov_page_stripe(page);
287 RETURN(lov_sub_get(env, lio, stripe));
291 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
294 struct lov_stripe_md *lsm;
298 LASSERT(lio->lis_object != NULL);
299 lsm = lio->lis_object->lo_lsm;
302 * Need to be optimized, we can't afford to allocate a piece of memory
303 * when writing a page. -jay
305 OBD_ALLOC_LARGE(lio->lis_subs,
306 lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
307 if (lio->lis_subs != NULL) {
308 lio->lis_nr_subios = lio->lis_stripe_count;
309 lio->lis_single_subio_index = -1;
310 lio->lis_active_subios = 0;
317 static int lov_io_slice_init(struct lov_io *lio,
318 struct lov_object *obj, struct cl_io *io)
323 lio->lis_object = obj;
325 LASSERT(obj->lo_lsm != NULL);
326 lio->lis_stripe_count = obj->lo_lsm->lsm_stripe_count;
328 switch (io->ci_type) {
331 lio->lis_pos = io->u.ci_rw.crw_pos;
332 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
333 lio->lis_io_endpos = lio->lis_endpos;
334 if (cl_io_is_append(io)) {
335 LASSERT(io->ci_type == CIT_WRITE);
337 /* If there is LOV EA hole, then we may cannot locate
338 * the current file-tail exactly. */
339 if (unlikely(obj->lo_lsm->lsm_pattern &
344 lio->lis_endpos = OBD_OBJECT_EOF;
349 if (cl_io_is_trunc(io))
350 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
353 lio->lis_endpos = OBD_OBJECT_EOF;
356 case CIT_DATA_VERSION:
358 lio->lis_endpos = OBD_OBJECT_EOF;
362 pgoff_t index = io->u.ci_fault.ft_index;
363 lio->lis_pos = cl_offset(io->ci_obj, index);
364 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
369 lio->lis_pos = io->u.ci_fsync.fi_start;
370 lio->lis_endpos = io->u.ci_fsync.fi_end;
376 lio->lis_endpos = OBD_OBJECT_EOF;
386 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
388 struct lov_io *lio = cl2lov_io(env, ios);
389 struct lov_object *lov = cl2lov(ios->cis_obj);
393 if (lio->lis_subs != NULL) {
394 for (i = 0; i < lio->lis_nr_subios; i++)
395 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
396 OBD_FREE_LARGE(lio->lis_subs,
397 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
398 lio->lis_nr_subios = 0;
401 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
402 if (atomic_dec_and_test(&lov->lo_active_ios))
403 wake_up_all(&lov->lo_waitq);
407 static loff_t lov_offset_mod(loff_t val, int delta)
409 if (val != OBD_OBJECT_EOF)
414 static int lov_io_iter_init(const struct lu_env *env,
415 const struct cl_io_slice *ios)
417 struct lov_io *lio = cl2lov_io(env, ios);
418 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
419 struct lov_io_sub *sub;
427 endpos = lov_offset_mod(lio->lis_endpos, -1);
428 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
429 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
430 endpos, &start, &end))
433 if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
434 if (ios->cis_io->ci_type == CIT_READ ||
435 ios->cis_io->ci_type == CIT_WRITE ||
436 ios->cis_io->ci_type == CIT_FAULT)
442 end = lov_offset_mod(end, +1);
443 sub = lov_sub_get(env, lio, stripe);
449 lov_io_sub_inherit(sub->sub_io, lio, stripe, start, end);
450 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
452 cl_io_iter_fini(sub->sub_env, sub->sub_io);
457 CDEBUG(D_VFSTRACE, "shrink: %d ["LPU64", "LPU64")\n",
460 list_add_tail(&sub->sub_linkage, &lio->lis_active);
465 static int lov_io_rw_iter_init(const struct lu_env *env,
466 const struct cl_io_slice *ios)
468 struct lov_io *lio = cl2lov_io(env, ios);
469 struct cl_io *io = ios->cis_io;
470 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
471 loff_t start = io->u.ci_rw.crw_pos;
473 unsigned long ssize = lsm->lsm_stripe_size;
475 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
478 /* fast path for common case. */
479 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
481 lov_do_div64(start, ssize);
482 next = (start + 1) * ssize;
483 if (next <= start * ssize)
486 io->ci_continue = next < lio->lis_io_endpos;
487 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
488 next) - io->u.ci_rw.crw_pos;
489 lio->lis_pos = io->u.ci_rw.crw_pos;
490 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
491 CDEBUG(D_VFSTRACE, "stripe: "LPU64" chunk: ["LPU64", "LPU64") "
492 LPU64"\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
493 (__u64)lio->lis_io_endpos);
496 * XXX The following call should be optimized: we know, that
497 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
499 RETURN(lov_io_iter_init(env, ios));
502 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
503 int (*iofunc)(const struct lu_env *, struct cl_io *))
505 struct cl_io *parent = lio->lis_cl.cis_io;
506 struct lov_io_sub *sub;
510 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
512 rc = iofunc(sub->sub_env, sub->sub_io);
517 if (parent->ci_result == 0)
518 parent->ci_result = sub->sub_io->ci_result;
523 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
526 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
529 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
532 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
535 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
539 * It's possible that lov_io_start() wasn't called against this
540 * sub-io, either because previous sub-io failed, or upper layer
543 if (io->ci_state == CIS_IO_GOING)
546 io->ci_state = CIS_IO_FINISHED;
550 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
552 cl_io_iter_fini(env, io);
556 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
558 cl_io_unlock(env, io);
562 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
566 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
571 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
573 struct lov_io *lio = cl2lov_io(env, ios);
574 struct cl_io *parent = lio->lis_cl.cis_io;
575 struct lov_io_sub *sub;
578 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
579 lov_io_end_wrapper(env, sub->sub_io);
581 parent->u.ci_data_version.dv_data_version +=
582 sub->sub_io->u.ci_data_version.dv_data_version;
584 if (parent->ci_result == 0)
585 parent->ci_result = sub->sub_io->ci_result;
591 static void lov_io_iter_fini(const struct lu_env *env,
592 const struct cl_io_slice *ios)
594 struct lov_io *lio = cl2lov_io(env, ios);
598 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
600 while (!list_empty(&lio->lis_active))
601 list_del_init(lio->lis_active.next);
605 static void lov_io_unlock(const struct lu_env *env,
606 const struct cl_io_slice *ios)
611 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
616 static int lov_io_read_ahead(const struct lu_env *env,
617 const struct cl_io_slice *ios,
618 pgoff_t start, struct cl_read_ahead *ra)
620 struct lov_io *lio = cl2lov_io(env, ios);
621 struct lov_object *loo = lio->lis_object;
622 struct cl_object *obj = lov2cl(loo);
623 struct lov_layout_raid0 *r0 = lov_r0(loo);
624 struct lov_io_sub *sub;
627 unsigned int pps; /* pages per stripe */
632 stripe = lov_stripe_number(loo->lo_lsm, cl_offset(obj, start));
633 if (unlikely(r0->lo_sub[stripe] == NULL))
636 sub = lov_sub_get(env, lio, stripe);
638 lov_stripe_offset(loo->lo_lsm, cl_offset(obj, start), stripe, &suboff);
639 rc = cl_io_read_ahead(sub->sub_env, sub->sub_io,
640 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
644 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
645 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
650 * Adjust the stripe index by layout of raid0. ra->cra_end is the maximum
651 * page index covered by an underlying DLM lock.
652 * This function converts cra_end from stripe level to file level, and
653 * make sure it's not beyond stripe boundary.
655 if (r0->lo_nr == 1) /* single stripe file */
658 /* cra_end is stripe level, convert it into file level */
659 ra_end = ra->cra_end;
660 if (ra_end != CL_PAGE_EOF)
661 ra_end = lov_stripe_pgoff(loo->lo_lsm, ra_end, stripe);
663 pps = loo->lo_lsm->lsm_stripe_size >> PAGE_CACHE_SHIFT;
665 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, "
666 "stripe_size = %u, stripe no = %u, start index = %lu\n",
667 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps,
668 loo->lo_lsm->lsm_stripe_size, stripe, start);
670 /* never exceed the end of the stripe */
671 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
676 * lov implementation of cl_operations::cio_submit() method. It takes a list
677 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
678 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
681 * Major complication of this function is a need to handle memory cleansing:
682 * cl_io_submit() is called to write out pages as a part of VM memory
683 * reclamation, and hence it may not fail due to memory shortages (system
684 * dead-locks otherwise). To deal with this, some resources (sub-lists,
685 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
686 * not-memory cleansing context), and in case of memory shortage, these
687 * pre-allocated resources are used by lov_io_submit() under
688 * lov_device::ld_mutex mutex.
690 static int lov_io_submit(const struct lu_env *env,
691 const struct cl_io_slice *ios,
692 enum cl_req_type crt, struct cl_2queue *queue)
694 struct cl_page_list *qin = &queue->c2_qin;
695 struct lov_io *lio = cl2lov_io(env, ios);
696 struct lov_io_sub *sub;
697 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
698 struct cl_page *page;
703 if (lio->lis_active_subios == 1) {
704 int idx = lio->lis_single_subio_index;
706 LASSERT(idx < lio->lis_nr_subios);
707 sub = lov_sub_get(env, lio, idx);
708 LASSERT(!IS_ERR(sub));
709 LASSERT(sub->sub_io == &lio->lis_single_subio);
710 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
716 LASSERT(lio->lis_subs != NULL);
718 cl_page_list_init(plist);
719 while (qin->pl_nr > 0) {
720 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
722 cl_2queue_init(cl2q);
724 page = cl_page_list_first(qin);
725 cl_page_list_move(&cl2q->c2_qin, qin, page);
727 stripe = lov_page_stripe(page);
728 while (qin->pl_nr > 0) {
729 page = cl_page_list_first(qin);
730 if (stripe != lov_page_stripe(page))
733 cl_page_list_move(&cl2q->c2_qin, qin, page);
736 sub = lov_sub_get(env, lio, stripe);
738 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
745 cl_page_list_splice(&cl2q->c2_qin, plist);
746 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
747 cl_2queue_fini(env, cl2q);
753 cl_page_list_splice(plist, qin);
754 cl_page_list_fini(env, plist);
759 static int lov_io_commit_async(const struct lu_env *env,
760 const struct cl_io_slice *ios,
761 struct cl_page_list *queue, int from, int to,
764 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
765 struct lov_io *lio = cl2lov_io(env, ios);
766 struct lov_io_sub *sub;
767 struct cl_page *page;
771 if (lio->lis_active_subios == 1) {
772 int idx = lio->lis_single_subio_index;
774 LASSERT(idx < lio->lis_nr_subios);
775 sub = lov_sub_get(env, lio, idx);
776 LASSERT(!IS_ERR(sub));
777 LASSERT(sub->sub_io == &lio->lis_single_subio);
778 rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
784 LASSERT(lio->lis_subs != NULL);
786 cl_page_list_init(plist);
787 while (queue->pl_nr > 0) {
791 LASSERT(plist->pl_nr == 0);
792 page = cl_page_list_first(queue);
793 cl_page_list_move(plist, queue, page);
795 stripe = lov_page_stripe(page);
796 while (queue->pl_nr > 0) {
797 page = cl_page_list_first(queue);
798 if (stripe != lov_page_stripe(page))
801 cl_page_list_move(plist, queue, page);
804 if (queue->pl_nr > 0) /* still has more pages */
805 stripe_to = PAGE_SIZE;
807 sub = lov_sub_get(env, lio, stripe);
809 rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
810 plist, from, stripe_to, cb);
817 if (plist->pl_nr > 0) /* short write */
823 /* for error case, add the page back into the qin list */
824 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
825 while (plist->pl_nr > 0) {
826 /* error occurred, add the uncommitted pages back into queue */
827 page = cl_page_list_last(plist);
828 cl_page_list_move_head(queue, plist, page);
834 static int lov_io_fault_start(const struct lu_env *env,
835 const struct cl_io_slice *ios)
837 struct cl_fault_io *fio;
839 struct lov_io_sub *sub;
842 fio = &ios->cis_io->u.ci_fault;
843 lio = cl2lov_io(env, ios);
844 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
845 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
847 RETURN(lov_io_start(env, ios));
850 static void lov_io_fsync_end(const struct lu_env *env,
851 const struct cl_io_slice *ios)
853 struct lov_io *lio = cl2lov_io(env, ios);
854 struct lov_io_sub *sub;
855 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
859 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
860 struct cl_io *subio = sub->sub_io;
863 lov_io_end_wrapper(sub->sub_env, subio);
866 if (subio->ci_result == 0)
867 *written += subio->u.ci_fsync.fi_nr_written;
872 static const struct cl_io_operations lov_io_ops = {
875 .cio_fini = lov_io_fini,
876 .cio_iter_init = lov_io_rw_iter_init,
877 .cio_iter_fini = lov_io_iter_fini,
878 .cio_lock = lov_io_lock,
879 .cio_unlock = lov_io_unlock,
880 .cio_start = lov_io_start,
881 .cio_end = lov_io_end
884 .cio_fini = lov_io_fini,
885 .cio_iter_init = lov_io_rw_iter_init,
886 .cio_iter_fini = lov_io_iter_fini,
887 .cio_lock = lov_io_lock,
888 .cio_unlock = lov_io_unlock,
889 .cio_start = lov_io_start,
890 .cio_end = lov_io_end
893 .cio_fini = lov_io_fini,
894 .cio_iter_init = lov_io_iter_init,
895 .cio_iter_fini = lov_io_iter_fini,
896 .cio_lock = lov_io_lock,
897 .cio_unlock = lov_io_unlock,
898 .cio_start = lov_io_start,
899 .cio_end = lov_io_end
901 [CIT_DATA_VERSION] = {
902 .cio_fini = lov_io_fini,
903 .cio_iter_init = lov_io_iter_init,
904 .cio_iter_fini = lov_io_iter_fini,
905 .cio_lock = lov_io_lock,
906 .cio_unlock = lov_io_unlock,
907 .cio_start = lov_io_start,
908 .cio_end = lov_io_data_version_end,
911 .cio_fini = lov_io_fini,
912 .cio_iter_init = lov_io_iter_init,
913 .cio_iter_fini = lov_io_iter_fini,
914 .cio_lock = lov_io_lock,
915 .cio_unlock = lov_io_unlock,
916 .cio_start = lov_io_fault_start,
917 .cio_end = lov_io_end
920 .cio_fini = lov_io_fini,
921 .cio_iter_init = lov_io_iter_init,
922 .cio_iter_fini = lov_io_iter_fini,
923 .cio_lock = lov_io_lock,
924 .cio_unlock = lov_io_unlock,
925 .cio_start = lov_io_start,
926 .cio_end = lov_io_fsync_end
929 .cio_fini = lov_io_fini
932 .cio_read_ahead = lov_io_read_ahead,
933 .cio_submit = lov_io_submit,
934 .cio_commit_async = lov_io_commit_async,
937 /*****************************************************************************
939 * Empty lov io operations.
943 static void lov_empty_io_fini(const struct lu_env *env,
944 const struct cl_io_slice *ios)
946 struct lov_object *lov = cl2lov(ios->cis_obj);
949 if (atomic_dec_and_test(&lov->lo_active_ios))
950 wake_up_all(&lov->lo_waitq);
954 static int lov_empty_io_submit(const struct lu_env *env,
955 const struct cl_io_slice *ios,
956 enum cl_req_type crt, struct cl_2queue *queue)
961 static void lov_empty_impossible(const struct lu_env *env,
962 struct cl_io_slice *ios)
967 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
970 * An io operation vector for files without stripes.
972 static const struct cl_io_operations lov_empty_io_ops = {
975 .cio_fini = lov_empty_io_fini,
977 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
978 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
979 .cio_start = LOV_EMPTY_IMPOSSIBLE,
980 .cio_end = LOV_EMPTY_IMPOSSIBLE
984 .cio_fini = lov_empty_io_fini,
985 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
986 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
987 .cio_start = LOV_EMPTY_IMPOSSIBLE,
988 .cio_end = LOV_EMPTY_IMPOSSIBLE
991 .cio_fini = lov_empty_io_fini,
992 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
993 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
994 .cio_start = LOV_EMPTY_IMPOSSIBLE,
995 .cio_end = LOV_EMPTY_IMPOSSIBLE
998 .cio_fini = lov_empty_io_fini,
999 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1000 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1001 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1002 .cio_end = LOV_EMPTY_IMPOSSIBLE
1005 .cio_fini = lov_empty_io_fini
1008 .cio_fini = lov_empty_io_fini
1011 .cio_submit = lov_empty_io_submit,
1012 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
1015 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
1018 struct lov_io *lio = lov_env_io(env);
1019 struct lov_object *lov = cl2lov(obj);
1022 INIT_LIST_HEAD(&lio->lis_active);
1023 io->ci_result = lov_io_slice_init(lio, lov, io);
1024 if (io->ci_result != 0)
1025 RETURN(io->ci_result);
1027 if (io->ci_result == 0) {
1028 io->ci_result = lov_io_subio_init(env, lio, io);
1029 if (io->ci_result == 0) {
1030 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
1031 atomic_inc(&lov->lo_active_ios);
1034 RETURN(io->ci_result);
1037 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
1040 struct lov_object *lov = cl2lov(obj);
1041 struct lov_io *lio = lov_env_io(env);
1045 lio->lis_object = lov;
1046 switch (io->ci_type) {
1055 case CIT_DATA_VERSION:
1063 CERROR("Page fault on a file without stripes: "DFID"\n",
1064 PFID(lu_object_fid(&obj->co_lu)));
1068 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1069 atomic_inc(&lov->lo_active_ios);
1072 io->ci_result = result < 0 ? result : 0;
1076 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1079 struct lov_object *lov = cl2lov(obj);
1080 struct lov_io *lio = lov_env_io(env);
1084 LASSERT(lov->lo_lsm != NULL);
1085 lio->lis_object = lov;
1087 switch (io->ci_type) {
1089 LASSERTF(0, "invalid type %d\n", io->ci_type);
1092 case CIT_DATA_VERSION:
1096 /* the truncate to 0 is managed by MDT:
1097 * - in open, for open O_TRUNC
1098 * - in setattr, for truncate
1100 /* the truncate is for size > 0 so triggers a restore */
1101 if (cl_io_is_trunc(io)) {
1102 io->ci_restore_needed = 1;
1110 io->ci_restore_needed = 1;
1115 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1116 atomic_inc(&lov->lo_active_ios);
1119 io->ci_result = result < 0 ? result : 0;