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, 2015, 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 LOV layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
35 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_LOV
40 #include "lov_cl_internal.h"
46 static void lov_io_sub_fini(const struct lu_env *env, struct lov_io *lio,
47 struct lov_io_sub *sub)
50 if (sub->sub_io != NULL) {
51 if (sub->sub_io_initialized) {
52 cl_io_fini(sub->sub_env, sub->sub_io);
53 sub->sub_io_initialized = 0;
54 lio->lis_active_subios--;
56 if (sub->sub_stripe == lio->lis_single_subio_index)
57 lio->lis_single_subio_index = -1;
58 else if (!sub->sub_borrowed)
59 OBD_FREE_PTR(sub->sub_io);
62 if (sub->sub_env != NULL && !IS_ERR(sub->sub_env)) {
63 if (!sub->sub_borrowed)
64 cl_env_put(sub->sub_env, &sub->sub_refcheck);
70 static void lov_io_sub_inherit(struct cl_io *io, struct lov_io *lio,
71 int stripe, loff_t start, loff_t end)
73 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
74 struct cl_io *parent = lio->lis_cl.cis_io;
76 switch (io->ci_type) {
78 io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
79 io->u.ci_setattr.sa_attr_flags =
80 parent->u.ci_setattr.sa_attr_flags;
81 io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
82 io->u.ci_setattr.sa_stripe_index = stripe;
83 io->u.ci_setattr.sa_parent_fid =
84 parent->u.ci_setattr.sa_parent_fid;
85 if (cl_io_is_trunc(io)) {
86 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
88 new_size = lov_size_to_stripe(lsm, new_size, stripe);
89 io->u.ci_setattr.sa_attr.lvb_size = new_size;
93 case CIT_DATA_VERSION: {
94 io->u.ci_data_version.dv_data_version = 0;
95 io->u.ci_data_version.dv_flags =
96 parent->u.ci_data_version.dv_flags;
100 struct cl_object *obj = parent->ci_obj;
101 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
103 io->u.ci_fault = parent->u.ci_fault;
104 off = lov_size_to_stripe(lsm, off, stripe);
105 io->u.ci_fault.ft_index = cl_index(obj, off);
109 io->u.ci_fsync.fi_start = start;
110 io->u.ci_fsync.fi_end = end;
111 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
112 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
117 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
118 if (cl_io_is_append(parent)) {
119 io->u.ci_wr.wr_append = 1;
121 io->u.ci_rw.crw_pos = start;
122 io->u.ci_rw.crw_count = end - start;
127 io->u.ci_ladvise.li_start = start;
128 io->u.ci_ladvise.li_end = end;
129 io->u.ci_ladvise.li_fid = parent->u.ci_ladvise.li_fid;
130 io->u.ci_ladvise.li_advice = parent->u.ci_ladvise.li_advice;
131 io->u.ci_ladvise.li_flags = parent->u.ci_ladvise.li_flags;
139 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
140 struct lov_io_sub *sub)
142 struct lov_object *lov = lio->lis_object;
143 struct cl_io *sub_io;
144 struct cl_object *sub_obj;
145 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))
157 sub->sub_io_initialized = 0;
158 sub->sub_borrowed = 0;
160 /* obtain new environment */
161 sub->sub_env = cl_env_get(&sub->sub_refcheck);
162 if (IS_ERR(sub->sub_env))
163 GOTO(fini_lov_io, rc = PTR_ERR(sub->sub_env));
166 * First sub-io. Use ->lis_single_subio to
167 * avoid dynamic allocation.
169 if (lio->lis_active_subios == 0) {
170 sub->sub_io = &lio->lis_single_subio;
171 lio->lis_single_subio_index = stripe;
173 OBD_ALLOC_PTR(sub->sub_io);
174 if (sub->sub_io == NULL)
175 GOTO(fini_lov_io, rc = -ENOMEM);
178 sub_obj = lovsub2cl(lov_r0(lov)->lo_sub[stripe]);
179 sub_io = sub->sub_io;
181 sub_io->ci_obj = sub_obj;
182 sub_io->ci_result = 0;
183 sub_io->ci_parent = io;
184 sub_io->ci_lockreq = io->ci_lockreq;
185 sub_io->ci_type = io->ci_type;
186 sub_io->ci_no_srvlock = io->ci_no_srvlock;
187 sub_io->ci_noatime = io->ci_noatime;
189 rc = cl_io_sub_init(sub->sub_env, sub_io, io->ci_type, sub_obj);
191 lio->lis_active_subios++;
192 sub->sub_io_initialized = 1;
197 lov_io_sub_fini(env, lio, sub);
201 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
202 struct lov_io *lio, int stripe)
205 struct lov_io_sub *sub = &lio->lis_subs[stripe];
207 LASSERT(stripe < lio->lis_stripe_count);
210 if (!sub->sub_io_initialized) {
211 sub->sub_stripe = stripe;
212 rc = lov_io_sub_init(env, lio, sub);
222 /*****************************************************************************
228 int lov_page_stripe(const struct cl_page *page)
230 const struct cl_page_slice *slice;
233 slice = cl_page_at(page, &lov_device_type);
234 LASSERT(slice != NULL);
235 LASSERT(slice->cpl_obj != NULL);
237 RETURN(cl2lov_page(slice)->lps_stripe);
240 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
243 struct lov_stripe_md *lsm;
247 LASSERT(lio->lis_object != NULL);
248 lsm = lio->lis_object->lo_lsm;
251 * Need to be optimized, we can't afford to allocate a piece of memory
252 * when writing a page. -jay
254 OBD_ALLOC_LARGE(lio->lis_subs,
255 lsm->lsm_stripe_count * sizeof lio->lis_subs[0]);
256 if (lio->lis_subs != NULL) {
257 lio->lis_nr_subios = lio->lis_stripe_count;
258 lio->lis_single_subio_index = -1;
259 lio->lis_active_subios = 0;
267 static int lov_io_slice_init(struct lov_io *lio,
268 struct lov_object *obj, struct cl_io *io)
273 lio->lis_object = obj;
275 LASSERT(obj->lo_lsm != NULL);
276 lio->lis_stripe_count = obj->lo_lsm->lsm_stripe_count;
278 switch (io->ci_type) {
281 lio->lis_pos = io->u.ci_rw.crw_pos;
282 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
283 lio->lis_io_endpos = lio->lis_endpos;
284 if (cl_io_is_append(io)) {
285 LASSERT(io->ci_type == CIT_WRITE);
287 /* If there is LOV EA hole, then we may cannot locate
288 * the current file-tail exactly. */
289 if (unlikely(obj->lo_lsm->lsm_pattern &
294 lio->lis_endpos = OBD_OBJECT_EOF;
299 if (cl_io_is_trunc(io))
300 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
303 lio->lis_endpos = OBD_OBJECT_EOF;
306 case CIT_DATA_VERSION:
308 lio->lis_endpos = OBD_OBJECT_EOF;
312 pgoff_t index = io->u.ci_fault.ft_index;
313 lio->lis_pos = cl_offset(io->ci_obj, index);
314 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
319 lio->lis_pos = io->u.ci_fsync.fi_start;
320 lio->lis_endpos = io->u.ci_fsync.fi_end;
325 lio->lis_pos = io->u.ci_ladvise.li_start;
326 lio->lis_endpos = io->u.ci_ladvise.li_end;
332 lio->lis_endpos = OBD_OBJECT_EOF;
342 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
344 struct lov_io *lio = cl2lov_io(env, ios);
345 struct lov_object *lov = cl2lov(ios->cis_obj);
349 if (lio->lis_subs != NULL) {
350 for (i = 0; i < lio->lis_nr_subios; i++)
351 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
352 OBD_FREE_LARGE(lio->lis_subs,
353 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
354 lio->lis_nr_subios = 0;
357 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
358 if (atomic_dec_and_test(&lov->lo_active_ios))
359 wake_up_all(&lov->lo_waitq);
363 static loff_t lov_offset_mod(loff_t val, int delta)
365 if (val != OBD_OBJECT_EOF)
370 static int lov_io_iter_init(const struct lu_env *env,
371 const struct cl_io_slice *ios)
373 struct lov_io *lio = cl2lov_io(env, ios);
374 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
375 struct lov_io_sub *sub;
383 endpos = lov_offset_mod(lio->lis_endpos, -1);
384 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
385 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
386 endpos, &start, &end))
389 if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
390 if (ios->cis_io->ci_type == CIT_READ ||
391 ios->cis_io->ci_type == CIT_WRITE ||
392 ios->cis_io->ci_type == CIT_FAULT)
398 end = lov_offset_mod(end, +1);
399 sub = lov_sub_get(env, lio, stripe);
405 lov_io_sub_inherit(sub->sub_io, lio, stripe, start, end);
406 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
408 cl_io_iter_fini(sub->sub_env, sub->sub_io);
412 CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
415 list_add_tail(&sub->sub_linkage, &lio->lis_active);
420 static int lov_io_rw_iter_init(const struct lu_env *env,
421 const struct cl_io_slice *ios)
423 struct lov_io *lio = cl2lov_io(env, ios);
424 struct cl_io *io = ios->cis_io;
425 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
426 loff_t start = io->u.ci_rw.crw_pos;
428 unsigned long ssize = lsm->lsm_stripe_size;
430 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
433 /* fast path for common case. */
434 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
436 lov_do_div64(start, ssize);
437 next = (start + 1) * ssize;
438 if (next <= start * ssize)
441 io->ci_continue = next < lio->lis_io_endpos;
442 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
443 next) - io->u.ci_rw.crw_pos;
444 lio->lis_pos = io->u.ci_rw.crw_pos;
445 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
446 CDEBUG(D_VFSTRACE, "stripe: %llu chunk: [%llu, %llu) "
447 "%llu\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
448 (__u64)lio->lis_io_endpos);
451 * XXX The following call should be optimized: we know, that
452 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
454 RETURN(lov_io_iter_init(env, ios));
457 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
458 int (*iofunc)(const struct lu_env *, struct cl_io *))
460 struct cl_io *parent = lio->lis_cl.cis_io;
461 struct lov_io_sub *sub;
465 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
466 rc = iofunc(sub->sub_env, sub->sub_io);
470 if (parent->ci_result == 0)
471 parent->ci_result = sub->sub_io->ci_result;
476 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
479 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
482 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
485 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
488 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
492 * It's possible that lov_io_start() wasn't called against this
493 * sub-io, either because previous sub-io failed, or upper layer
496 if (io->ci_state == CIS_IO_GOING)
499 io->ci_state = CIS_IO_FINISHED;
503 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
505 cl_io_iter_fini(env, io);
509 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
511 cl_io_unlock(env, io);
515 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
519 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
524 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
526 struct lov_io *lio = cl2lov_io(env, ios);
527 struct cl_io *parent = lio->lis_cl.cis_io;
528 struct lov_io_sub *sub;
531 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
532 lov_io_end_wrapper(env, sub->sub_io);
534 parent->u.ci_data_version.dv_data_version +=
535 sub->sub_io->u.ci_data_version.dv_data_version;
537 if (parent->ci_result == 0)
538 parent->ci_result = sub->sub_io->ci_result;
544 static void lov_io_iter_fini(const struct lu_env *env,
545 const struct cl_io_slice *ios)
547 struct lov_io *lio = cl2lov_io(env, ios);
551 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
553 while (!list_empty(&lio->lis_active))
554 list_del_init(lio->lis_active.next);
558 static void lov_io_unlock(const struct lu_env *env,
559 const struct cl_io_slice *ios)
564 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
569 static int lov_io_read_ahead(const struct lu_env *env,
570 const struct cl_io_slice *ios,
571 pgoff_t start, struct cl_read_ahead *ra)
573 struct lov_io *lio = cl2lov_io(env, ios);
574 struct lov_object *loo = lio->lis_object;
575 struct cl_object *obj = lov2cl(loo);
576 struct lov_layout_raid0 *r0 = lov_r0(loo);
577 struct lov_io_sub *sub;
580 unsigned int pps; /* pages per stripe */
585 stripe = lov_stripe_number(loo->lo_lsm, cl_offset(obj, start));
586 if (unlikely(r0->lo_sub[stripe] == NULL))
589 sub = lov_sub_get(env, lio, stripe);
591 lov_stripe_offset(loo->lo_lsm, cl_offset(obj, start), stripe, &suboff);
592 rc = cl_io_read_ahead(sub->sub_env, sub->sub_io,
593 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
596 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
597 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
602 * Adjust the stripe index by layout of raid0. ra->cra_end is the maximum
603 * page index covered by an underlying DLM lock.
604 * This function converts cra_end from stripe level to file level, and
605 * make sure it's not beyond stripe boundary.
607 if (r0->lo_nr == 1) /* single stripe file */
610 /* cra_end is stripe level, convert it into file level */
611 ra_end = ra->cra_end;
612 if (ra_end != CL_PAGE_EOF)
613 ra_end = lov_stripe_pgoff(loo->lo_lsm, ra_end, stripe);
615 pps = loo->lo_lsm->lsm_stripe_size >> PAGE_SHIFT;
617 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, "
618 "stripe_size = %u, stripe no = %u, start index = %lu\n",
619 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps,
620 loo->lo_lsm->lsm_stripe_size, stripe, start);
622 /* never exceed the end of the stripe */
623 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
628 * lov implementation of cl_operations::cio_submit() method. It takes a list
629 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
630 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
633 * Major complication of this function is a need to handle memory cleansing:
634 * cl_io_submit() is called to write out pages as a part of VM memory
635 * reclamation, and hence it may not fail due to memory shortages (system
636 * dead-locks otherwise). To deal with this, some resources (sub-lists,
637 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
638 * not-memory cleansing context), and in case of memory shortage, these
639 * pre-allocated resources are used by lov_io_submit() under
640 * lov_device::ld_mutex mutex.
642 static int lov_io_submit(const struct lu_env *env,
643 const struct cl_io_slice *ios,
644 enum cl_req_type crt, struct cl_2queue *queue)
646 struct cl_page_list *qin = &queue->c2_qin;
647 struct lov_io *lio = cl2lov_io(env, ios);
648 struct lov_io_sub *sub;
649 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
650 struct cl_page *page;
655 if (lio->lis_active_subios == 1) {
656 int idx = lio->lis_single_subio_index;
658 LASSERT(idx < lio->lis_nr_subios);
659 sub = lov_sub_get(env, lio, idx);
660 LASSERT(!IS_ERR(sub));
661 LASSERT(sub->sub_io == &lio->lis_single_subio);
662 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
667 LASSERT(lio->lis_subs != NULL);
669 cl_page_list_init(plist);
670 while (qin->pl_nr > 0) {
671 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
673 cl_2queue_init(cl2q);
675 page = cl_page_list_first(qin);
676 cl_page_list_move(&cl2q->c2_qin, qin, page);
678 stripe = lov_page_stripe(page);
679 while (qin->pl_nr > 0) {
680 page = cl_page_list_first(qin);
681 if (stripe != lov_page_stripe(page))
684 cl_page_list_move(&cl2q->c2_qin, qin, page);
687 sub = lov_sub_get(env, lio, stripe);
689 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
695 cl_page_list_splice(&cl2q->c2_qin, plist);
696 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
697 cl_2queue_fini(env, cl2q);
703 cl_page_list_splice(plist, qin);
704 cl_page_list_fini(env, plist);
709 static int lov_io_commit_async(const struct lu_env *env,
710 const struct cl_io_slice *ios,
711 struct cl_page_list *queue, int from, int to,
714 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
715 struct lov_io *lio = cl2lov_io(env, ios);
716 struct lov_io_sub *sub;
717 struct cl_page *page;
721 if (lio->lis_active_subios == 1) {
722 int idx = lio->lis_single_subio_index;
724 LASSERT(idx < lio->lis_nr_subios);
725 sub = lov_sub_get(env, lio, idx);
726 LASSERT(!IS_ERR(sub));
727 LASSERT(sub->sub_io == &lio->lis_single_subio);
728 rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
733 LASSERT(lio->lis_subs != NULL);
735 cl_page_list_init(plist);
736 while (queue->pl_nr > 0) {
740 LASSERT(plist->pl_nr == 0);
741 page = cl_page_list_first(queue);
742 cl_page_list_move(plist, queue, page);
744 stripe = lov_page_stripe(page);
745 while (queue->pl_nr > 0) {
746 page = cl_page_list_first(queue);
747 if (stripe != lov_page_stripe(page))
750 cl_page_list_move(plist, queue, page);
753 if (queue->pl_nr > 0) /* still has more pages */
754 stripe_to = PAGE_SIZE;
756 sub = lov_sub_get(env, lio, stripe);
758 rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
759 plist, from, stripe_to, cb);
765 if (plist->pl_nr > 0) /* short write */
771 /* for error case, add the page back into the qin list */
772 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
773 while (plist->pl_nr > 0) {
774 /* error occurred, add the uncommitted pages back into queue */
775 page = cl_page_list_last(plist);
776 cl_page_list_move_head(queue, plist, page);
782 static int lov_io_fault_start(const struct lu_env *env,
783 const struct cl_io_slice *ios)
785 struct cl_fault_io *fio;
787 struct lov_io_sub *sub;
790 fio = &ios->cis_io->u.ci_fault;
791 lio = cl2lov_io(env, ios);
792 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
793 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
794 RETURN(lov_io_start(env, ios));
797 static void lov_io_fsync_end(const struct lu_env *env,
798 const struct cl_io_slice *ios)
800 struct lov_io *lio = cl2lov_io(env, ios);
801 struct lov_io_sub *sub;
802 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
806 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
807 struct cl_io *subio = sub->sub_io;
809 lov_io_end_wrapper(sub->sub_env, subio);
811 if (subio->ci_result == 0)
812 *written += subio->u.ci_fsync.fi_nr_written;
817 static const struct cl_io_operations lov_io_ops = {
820 .cio_fini = lov_io_fini,
821 .cio_iter_init = lov_io_rw_iter_init,
822 .cio_iter_fini = lov_io_iter_fini,
823 .cio_lock = lov_io_lock,
824 .cio_unlock = lov_io_unlock,
825 .cio_start = lov_io_start,
826 .cio_end = lov_io_end
829 .cio_fini = lov_io_fini,
830 .cio_iter_init = lov_io_rw_iter_init,
831 .cio_iter_fini = lov_io_iter_fini,
832 .cio_lock = lov_io_lock,
833 .cio_unlock = lov_io_unlock,
834 .cio_start = lov_io_start,
835 .cio_end = lov_io_end
838 .cio_fini = lov_io_fini,
839 .cio_iter_init = lov_io_iter_init,
840 .cio_iter_fini = lov_io_iter_fini,
841 .cio_lock = lov_io_lock,
842 .cio_unlock = lov_io_unlock,
843 .cio_start = lov_io_start,
844 .cio_end = lov_io_end
846 [CIT_DATA_VERSION] = {
847 .cio_fini = lov_io_fini,
848 .cio_iter_init = lov_io_iter_init,
849 .cio_iter_fini = lov_io_iter_fini,
850 .cio_lock = lov_io_lock,
851 .cio_unlock = lov_io_unlock,
852 .cio_start = lov_io_start,
853 .cio_end = lov_io_data_version_end,
856 .cio_fini = lov_io_fini,
857 .cio_iter_init = lov_io_iter_init,
858 .cio_iter_fini = lov_io_iter_fini,
859 .cio_lock = lov_io_lock,
860 .cio_unlock = lov_io_unlock,
861 .cio_start = lov_io_fault_start,
862 .cio_end = lov_io_end
865 .cio_fini = lov_io_fini,
866 .cio_iter_init = lov_io_iter_init,
867 .cio_iter_fini = lov_io_iter_fini,
868 .cio_lock = lov_io_lock,
869 .cio_unlock = lov_io_unlock,
870 .cio_start = lov_io_start,
871 .cio_end = lov_io_fsync_end
874 .cio_fini = lov_io_fini,
875 .cio_iter_init = lov_io_iter_init,
876 .cio_iter_fini = lov_io_iter_fini,
877 .cio_lock = lov_io_lock,
878 .cio_unlock = lov_io_unlock,
879 .cio_start = lov_io_start,
880 .cio_end = lov_io_end
883 .cio_fini = lov_io_fini
886 .cio_read_ahead = lov_io_read_ahead,
887 .cio_submit = lov_io_submit,
888 .cio_commit_async = lov_io_commit_async,
891 /*****************************************************************************
893 * Empty lov io operations.
897 static void lov_empty_io_fini(const struct lu_env *env,
898 const struct cl_io_slice *ios)
900 struct lov_object *lov = cl2lov(ios->cis_obj);
903 if (atomic_dec_and_test(&lov->lo_active_ios))
904 wake_up_all(&lov->lo_waitq);
908 static int lov_empty_io_submit(const struct lu_env *env,
909 const struct cl_io_slice *ios,
910 enum cl_req_type crt, struct cl_2queue *queue)
915 static void lov_empty_impossible(const struct lu_env *env,
916 struct cl_io_slice *ios)
921 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
924 * An io operation vector for files without stripes.
926 static const struct cl_io_operations lov_empty_io_ops = {
929 .cio_fini = lov_empty_io_fini,
931 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
932 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
933 .cio_start = LOV_EMPTY_IMPOSSIBLE,
934 .cio_end = LOV_EMPTY_IMPOSSIBLE
938 .cio_fini = lov_empty_io_fini,
939 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
940 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
941 .cio_start = LOV_EMPTY_IMPOSSIBLE,
942 .cio_end = LOV_EMPTY_IMPOSSIBLE
945 .cio_fini = lov_empty_io_fini,
946 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
947 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
948 .cio_start = LOV_EMPTY_IMPOSSIBLE,
949 .cio_end = LOV_EMPTY_IMPOSSIBLE
952 .cio_fini = lov_empty_io_fini,
953 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
954 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
955 .cio_start = LOV_EMPTY_IMPOSSIBLE,
956 .cio_end = LOV_EMPTY_IMPOSSIBLE
959 .cio_fini = lov_empty_io_fini
962 .cio_fini = lov_empty_io_fini
965 .cio_fini = lov_empty_io_fini
968 .cio_submit = lov_empty_io_submit,
969 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
972 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
975 struct lov_io *lio = lov_env_io(env);
976 struct lov_object *lov = cl2lov(obj);
979 INIT_LIST_HEAD(&lio->lis_active);
980 io->ci_result = lov_io_slice_init(lio, lov, io);
981 if (io->ci_result != 0)
982 RETURN(io->ci_result);
984 if (io->ci_result == 0) {
985 io->ci_result = lov_io_subio_init(env, lio, io);
986 if (io->ci_result == 0) {
987 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
988 atomic_inc(&lov->lo_active_ios);
991 RETURN(io->ci_result);
994 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
997 struct lov_object *lov = cl2lov(obj);
998 struct lov_io *lio = lov_env_io(env);
1002 lio->lis_object = lov;
1003 switch (io->ci_type) {
1013 case CIT_DATA_VERSION:
1021 CERROR("Page fault on a file without stripes: "DFID"\n",
1022 PFID(lu_object_fid(&obj->co_lu)));
1026 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1027 atomic_inc(&lov->lo_active_ios);
1030 io->ci_result = result < 0 ? result : 0;
1034 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1037 struct lov_object *lov = cl2lov(obj);
1038 struct lov_io *lio = lov_env_io(env);
1042 LASSERT(lov->lo_lsm != NULL);
1043 lio->lis_object = lov;
1045 switch (io->ci_type) {
1047 LASSERTF(0, "invalid type %d\n", io->ci_type);
1048 result = -EOPNOTSUPP;
1053 case CIT_DATA_VERSION:
1057 /* the truncate to 0 is managed by MDT:
1058 * - in open, for open O_TRUNC
1059 * - in setattr, for truncate
1061 /* the truncate is for size > 0 so triggers a restore */
1062 if (cl_io_is_trunc(io)) {
1063 io->ci_restore_needed = 1;
1071 io->ci_restore_needed = 1;
1077 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1078 atomic_inc(&lov->lo_active_ios);
1081 io->ci_result = result < 0 ? result : 0;