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, 2016, 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_entries[0]->lsme_stripe_count *
256 sizeof lio->lis_subs[0]);
257 if (lio->lis_subs != NULL) {
258 lio->lis_nr_subios = lio->lis_stripe_count;
259 lio->lis_single_subio_index = -1;
260 lio->lis_active_subios = 0;
268 static int lov_io_slice_init(struct lov_io *lio,
269 struct lov_object *obj, struct cl_io *io)
274 lio->lis_object = obj;
276 LASSERT(obj->lo_lsm != NULL);
277 lio->lis_stripe_count = obj->lo_lsm->lsm_entries[0]->lsme_stripe_count;
279 switch (io->ci_type) {
282 lio->lis_pos = io->u.ci_rw.crw_pos;
283 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
284 lio->lis_io_endpos = lio->lis_endpos;
285 if (cl_io_is_append(io)) {
286 LASSERT(io->ci_type == CIT_WRITE);
288 /* If there is LOV EA hole, then we may cannot locate
289 * the current file-tail exactly. */
290 if (unlikely(obj->lo_lsm->lsm_entries[0]->lsme_pattern &
295 lio->lis_endpos = OBD_OBJECT_EOF;
300 if (cl_io_is_trunc(io))
301 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
304 lio->lis_endpos = OBD_OBJECT_EOF;
307 case CIT_DATA_VERSION:
309 lio->lis_endpos = OBD_OBJECT_EOF;
313 pgoff_t index = io->u.ci_fault.ft_index;
314 lio->lis_pos = cl_offset(io->ci_obj, index);
315 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
320 lio->lis_pos = io->u.ci_fsync.fi_start;
321 lio->lis_endpos = io->u.ci_fsync.fi_end;
326 lio->lis_pos = io->u.ci_ladvise.li_start;
327 lio->lis_endpos = io->u.ci_ladvise.li_end;
333 lio->lis_endpos = OBD_OBJECT_EOF;
343 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
345 struct lov_io *lio = cl2lov_io(env, ios);
346 struct lov_object *lov = cl2lov(ios->cis_obj);
350 if (lio->lis_subs != NULL) {
351 for (i = 0; i < lio->lis_nr_subios; i++)
352 lov_io_sub_fini(env, lio, &lio->lis_subs[i]);
353 OBD_FREE_LARGE(lio->lis_subs,
354 lio->lis_nr_subios * sizeof lio->lis_subs[0]);
355 lio->lis_nr_subios = 0;
358 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
359 if (atomic_dec_and_test(&lov->lo_active_ios))
360 wake_up_all(&lov->lo_waitq);
364 static loff_t lov_offset_mod(loff_t val, int delta)
366 if (val != OBD_OBJECT_EOF)
371 static int lov_io_iter_init(const struct lu_env *env,
372 const struct cl_io_slice *ios)
374 struct lov_io *lio = cl2lov_io(env, ios);
375 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
376 struct lov_io_sub *sub;
384 endpos = lov_offset_mod(lio->lis_endpos, -1);
385 for (stripe = 0; stripe < lio->lis_stripe_count; stripe++) {
386 if (!lov_stripe_intersects(lsm, stripe, lio->lis_pos,
387 endpos, &start, &end))
390 if (unlikely(lov_r0(lio->lis_object)->lo_sub[stripe] == NULL)) {
391 if (ios->cis_io->ci_type == CIT_READ ||
392 ios->cis_io->ci_type == CIT_WRITE ||
393 ios->cis_io->ci_type == CIT_FAULT)
399 end = lov_offset_mod(end, +1);
400 sub = lov_sub_get(env, lio, stripe);
406 lov_io_sub_inherit(sub->sub_io, lio, stripe, start, end);
407 rc = cl_io_iter_init(sub->sub_env, sub->sub_io);
409 cl_io_iter_fini(sub->sub_env, sub->sub_io);
413 CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
416 list_add_tail(&sub->sub_linkage, &lio->lis_active);
421 static int lov_io_rw_iter_init(const struct lu_env *env,
422 const struct cl_io_slice *ios)
424 struct lov_io *lio = cl2lov_io(env, ios);
425 struct cl_io *io = ios->cis_io;
426 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
427 loff_t start = io->u.ci_rw.crw_pos;
429 unsigned long ssize = lsm->lsm_entries[0]->lsme_stripe_size;
431 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
434 /* fast path for common case. */
435 if (lio->lis_nr_subios != 1 && !cl_io_is_append(io)) {
437 lov_do_div64(start, ssize);
438 next = (start + 1) * ssize;
439 if (next <= start * ssize)
442 io->ci_continue = next < lio->lis_io_endpos;
443 io->u.ci_rw.crw_count = min_t(loff_t, lio->lis_io_endpos,
444 next) - io->u.ci_rw.crw_pos;
445 lio->lis_pos = io->u.ci_rw.crw_pos;
446 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
447 CDEBUG(D_VFSTRACE, "stripe: %llu chunk: [%llu, %llu) "
448 "%llu\n", (__u64)start, lio->lis_pos, lio->lis_endpos,
449 (__u64)lio->lis_io_endpos);
452 * XXX The following call should be optimized: we know, that
453 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
455 RETURN(lov_io_iter_init(env, ios));
458 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
459 int (*iofunc)(const struct lu_env *, struct cl_io *))
461 struct cl_io *parent = lio->lis_cl.cis_io;
462 struct lov_io_sub *sub;
466 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
467 rc = iofunc(sub->sub_env, sub->sub_io);
471 if (parent->ci_result == 0)
472 parent->ci_result = sub->sub_io->ci_result;
477 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
480 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
483 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
486 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
489 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
493 * It's possible that lov_io_start() wasn't called against this
494 * sub-io, either because previous sub-io failed, or upper layer
497 if (io->ci_state == CIS_IO_GOING)
500 io->ci_state = CIS_IO_FINISHED;
504 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
506 cl_io_iter_fini(env, io);
510 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
512 cl_io_unlock(env, io);
516 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
520 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
525 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
527 struct lov_io *lio = cl2lov_io(env, ios);
528 struct cl_io *parent = lio->lis_cl.cis_io;
529 struct lov_io_sub *sub;
532 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
533 lov_io_end_wrapper(env, sub->sub_io);
535 parent->u.ci_data_version.dv_data_version +=
536 sub->sub_io->u.ci_data_version.dv_data_version;
538 if (parent->ci_result == 0)
539 parent->ci_result = sub->sub_io->ci_result;
545 static void lov_io_iter_fini(const struct lu_env *env,
546 const struct cl_io_slice *ios)
548 struct lov_io *lio = cl2lov_io(env, ios);
552 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
554 while (!list_empty(&lio->lis_active))
555 list_del_init(lio->lis_active.next);
559 static void lov_io_unlock(const struct lu_env *env,
560 const struct cl_io_slice *ios)
565 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
570 static int lov_io_read_ahead(const struct lu_env *env,
571 const struct cl_io_slice *ios,
572 pgoff_t start, struct cl_read_ahead *ra)
574 struct lov_io *lio = cl2lov_io(env, ios);
575 struct lov_object *loo = lio->lis_object;
576 struct cl_object *obj = lov2cl(loo);
577 struct lov_layout_raid0 *r0 = lov_r0(loo);
578 struct lov_io_sub *sub;
581 unsigned int pps; /* pages per stripe */
586 stripe = lov_stripe_number(loo->lo_lsm, cl_offset(obj, start));
587 if (unlikely(r0->lo_sub[stripe] == NULL))
590 sub = lov_sub_get(env, lio, stripe);
594 lov_stripe_offset(loo->lo_lsm, cl_offset(obj, start), stripe, &suboff);
595 rc = cl_io_read_ahead(sub->sub_env, sub->sub_io,
596 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
599 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
600 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
605 * Adjust the stripe index by layout of raid0. ra->cra_end is the maximum
606 * page index covered by an underlying DLM lock.
607 * This function converts cra_end from stripe level to file level, and
608 * make sure it's not beyond stripe boundary.
610 if (r0->lo_nr == 1) /* single stripe file */
613 /* cra_end is stripe level, convert it into file level */
614 ra_end = ra->cra_end;
615 if (ra_end != CL_PAGE_EOF)
616 ra_end = lov_stripe_pgoff(loo->lo_lsm, ra_end, stripe);
618 pps = loo->lo_lsm->lsm_entries[0]->lsme_stripe_size >> PAGE_SHIFT;
620 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, "
621 "stripe_size = %u, stripe no = %u, start index = %lu\n",
622 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps,
623 loo->lo_lsm->lsm_entries[0]->lsme_stripe_size, stripe, start);
625 /* never exceed the end of the stripe */
626 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
631 * lov implementation of cl_operations::cio_submit() method. It takes a list
632 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
633 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
636 * Major complication of this function is a need to handle memory cleansing:
637 * cl_io_submit() is called to write out pages as a part of VM memory
638 * reclamation, and hence it may not fail due to memory shortages (system
639 * dead-locks otherwise). To deal with this, some resources (sub-lists,
640 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
641 * not-memory cleansing context), and in case of memory shortage, these
642 * pre-allocated resources are used by lov_io_submit() under
643 * lov_device::ld_mutex mutex.
645 static int lov_io_submit(const struct lu_env *env,
646 const struct cl_io_slice *ios,
647 enum cl_req_type crt, struct cl_2queue *queue)
649 struct cl_page_list *qin = &queue->c2_qin;
650 struct lov_io *lio = cl2lov_io(env, ios);
651 struct lov_io_sub *sub;
652 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
653 struct cl_page *page;
658 if (lio->lis_active_subios == 1) {
659 int idx = lio->lis_single_subio_index;
661 LASSERT(idx < lio->lis_nr_subios);
662 sub = lov_sub_get(env, lio, idx);
663 LASSERT(!IS_ERR(sub));
664 LASSERT(sub->sub_io == &lio->lis_single_subio);
665 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
670 LASSERT(lio->lis_subs != NULL);
672 cl_page_list_init(plist);
673 while (qin->pl_nr > 0) {
674 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
676 cl_2queue_init(cl2q);
678 page = cl_page_list_first(qin);
679 cl_page_list_move(&cl2q->c2_qin, qin, page);
681 stripe = lov_page_stripe(page);
682 while (qin->pl_nr > 0) {
683 page = cl_page_list_first(qin);
684 if (stripe != lov_page_stripe(page))
687 cl_page_list_move(&cl2q->c2_qin, qin, page);
690 sub = lov_sub_get(env, lio, stripe);
692 rc = cl_io_submit_rw(sub->sub_env, sub->sub_io,
698 cl_page_list_splice(&cl2q->c2_qin, plist);
699 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
700 cl_2queue_fini(env, cl2q);
706 cl_page_list_splice(plist, qin);
707 cl_page_list_fini(env, plist);
712 static int lov_io_commit_async(const struct lu_env *env,
713 const struct cl_io_slice *ios,
714 struct cl_page_list *queue, int from, int to,
717 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
718 struct lov_io *lio = cl2lov_io(env, ios);
719 struct lov_io_sub *sub;
720 struct cl_page *page;
724 if (lio->lis_active_subios == 1) {
725 int idx = lio->lis_single_subio_index;
727 LASSERT(idx < lio->lis_nr_subios);
728 sub = lov_sub_get(env, lio, idx);
729 LASSERT(!IS_ERR(sub));
730 LASSERT(sub->sub_io == &lio->lis_single_subio);
731 rc = cl_io_commit_async(sub->sub_env, sub->sub_io, queue,
736 LASSERT(lio->lis_subs != NULL);
738 cl_page_list_init(plist);
739 while (queue->pl_nr > 0) {
743 LASSERT(plist->pl_nr == 0);
744 page = cl_page_list_first(queue);
745 cl_page_list_move(plist, queue, page);
747 stripe = lov_page_stripe(page);
748 while (queue->pl_nr > 0) {
749 page = cl_page_list_first(queue);
750 if (stripe != lov_page_stripe(page))
753 cl_page_list_move(plist, queue, page);
756 if (queue->pl_nr > 0) /* still has more pages */
757 stripe_to = PAGE_SIZE;
759 sub = lov_sub_get(env, lio, stripe);
761 rc = cl_io_commit_async(sub->sub_env, sub->sub_io,
762 plist, from, stripe_to, cb);
768 if (plist->pl_nr > 0) /* short write */
774 /* for error case, add the page back into the qin list */
775 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
776 while (plist->pl_nr > 0) {
777 /* error occurred, add the uncommitted pages back into queue */
778 page = cl_page_list_last(plist);
779 cl_page_list_move_head(queue, plist, page);
785 static int lov_io_fault_start(const struct lu_env *env,
786 const struct cl_io_slice *ios)
788 struct cl_fault_io *fio;
790 struct lov_io_sub *sub;
793 fio = &ios->cis_io->u.ci_fault;
794 lio = cl2lov_io(env, ios);
795 sub = lov_sub_get(env, lio, lov_page_stripe(fio->ft_page));
796 sub->sub_io->u.ci_fault.ft_nob = fio->ft_nob;
797 RETURN(lov_io_start(env, ios));
800 static void lov_io_fsync_end(const struct lu_env *env,
801 const struct cl_io_slice *ios)
803 struct lov_io *lio = cl2lov_io(env, ios);
804 struct lov_io_sub *sub;
805 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
809 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
810 struct cl_io *subio = sub->sub_io;
812 lov_io_end_wrapper(sub->sub_env, subio);
814 if (subio->ci_result == 0)
815 *written += subio->u.ci_fsync.fi_nr_written;
820 static const struct cl_io_operations lov_io_ops = {
823 .cio_fini = lov_io_fini,
824 .cio_iter_init = lov_io_rw_iter_init,
825 .cio_iter_fini = lov_io_iter_fini,
826 .cio_lock = lov_io_lock,
827 .cio_unlock = lov_io_unlock,
828 .cio_start = lov_io_start,
829 .cio_end = lov_io_end
832 .cio_fini = lov_io_fini,
833 .cio_iter_init = lov_io_rw_iter_init,
834 .cio_iter_fini = lov_io_iter_fini,
835 .cio_lock = lov_io_lock,
836 .cio_unlock = lov_io_unlock,
837 .cio_start = lov_io_start,
838 .cio_end = lov_io_end
841 .cio_fini = lov_io_fini,
842 .cio_iter_init = lov_io_iter_init,
843 .cio_iter_fini = lov_io_iter_fini,
844 .cio_lock = lov_io_lock,
845 .cio_unlock = lov_io_unlock,
846 .cio_start = lov_io_start,
847 .cio_end = lov_io_end
849 [CIT_DATA_VERSION] = {
850 .cio_fini = lov_io_fini,
851 .cio_iter_init = lov_io_iter_init,
852 .cio_iter_fini = lov_io_iter_fini,
853 .cio_lock = lov_io_lock,
854 .cio_unlock = lov_io_unlock,
855 .cio_start = lov_io_start,
856 .cio_end = lov_io_data_version_end,
859 .cio_fini = lov_io_fini,
860 .cio_iter_init = lov_io_iter_init,
861 .cio_iter_fini = lov_io_iter_fini,
862 .cio_lock = lov_io_lock,
863 .cio_unlock = lov_io_unlock,
864 .cio_start = lov_io_fault_start,
865 .cio_end = lov_io_end
868 .cio_fini = lov_io_fini,
869 .cio_iter_init = lov_io_iter_init,
870 .cio_iter_fini = lov_io_iter_fini,
871 .cio_lock = lov_io_lock,
872 .cio_unlock = lov_io_unlock,
873 .cio_start = lov_io_start,
874 .cio_end = lov_io_fsync_end
877 .cio_fini = lov_io_fini,
878 .cio_iter_init = lov_io_iter_init,
879 .cio_iter_fini = lov_io_iter_fini,
880 .cio_lock = lov_io_lock,
881 .cio_unlock = lov_io_unlock,
882 .cio_start = lov_io_start,
883 .cio_end = lov_io_end
886 .cio_fini = lov_io_fini
889 .cio_read_ahead = lov_io_read_ahead,
890 .cio_submit = lov_io_submit,
891 .cio_commit_async = lov_io_commit_async,
894 /*****************************************************************************
896 * Empty lov io operations.
900 static void lov_empty_io_fini(const struct lu_env *env,
901 const struct cl_io_slice *ios)
903 struct lov_object *lov = cl2lov(ios->cis_obj);
906 if (atomic_dec_and_test(&lov->lo_active_ios))
907 wake_up_all(&lov->lo_waitq);
911 static int lov_empty_io_submit(const struct lu_env *env,
912 const struct cl_io_slice *ios,
913 enum cl_req_type crt, struct cl_2queue *queue)
918 static void lov_empty_impossible(const struct lu_env *env,
919 struct cl_io_slice *ios)
924 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
927 * An io operation vector for files without stripes.
929 static const struct cl_io_operations lov_empty_io_ops = {
932 .cio_fini = lov_empty_io_fini,
934 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
935 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
936 .cio_start = LOV_EMPTY_IMPOSSIBLE,
937 .cio_end = LOV_EMPTY_IMPOSSIBLE
941 .cio_fini = lov_empty_io_fini,
942 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
943 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
944 .cio_start = LOV_EMPTY_IMPOSSIBLE,
945 .cio_end = LOV_EMPTY_IMPOSSIBLE
948 .cio_fini = lov_empty_io_fini,
949 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
950 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
951 .cio_start = LOV_EMPTY_IMPOSSIBLE,
952 .cio_end = LOV_EMPTY_IMPOSSIBLE
955 .cio_fini = lov_empty_io_fini,
956 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
957 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
958 .cio_start = LOV_EMPTY_IMPOSSIBLE,
959 .cio_end = LOV_EMPTY_IMPOSSIBLE
962 .cio_fini = lov_empty_io_fini
965 .cio_fini = lov_empty_io_fini
968 .cio_fini = lov_empty_io_fini
971 .cio_submit = lov_empty_io_submit,
972 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
975 int lov_io_init_raid0(const struct lu_env *env, struct cl_object *obj,
978 struct lov_io *lio = lov_env_io(env);
979 struct lov_object *lov = cl2lov(obj);
982 INIT_LIST_HEAD(&lio->lis_active);
983 io->ci_result = lov_io_slice_init(lio, lov, io);
984 if (io->ci_result != 0)
985 RETURN(io->ci_result);
987 if (io->ci_result == 0) {
988 io->ci_result = lov_io_subio_init(env, lio, io);
989 if (io->ci_result == 0) {
990 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
991 atomic_inc(&lov->lo_active_ios);
994 RETURN(io->ci_result);
997 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
1000 struct lov_object *lov = cl2lov(obj);
1001 struct lov_io *lio = lov_env_io(env);
1005 lio->lis_object = lov;
1006 switch (io->ci_type) {
1016 case CIT_DATA_VERSION:
1024 CERROR("Page fault on a file without stripes: "DFID"\n",
1025 PFID(lu_object_fid(&obj->co_lu)));
1029 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1030 atomic_inc(&lov->lo_active_ios);
1033 io->ci_result = result < 0 ? result : 0;
1037 int lov_io_init_released(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 LASSERT(lov->lo_lsm != NULL);
1046 lio->lis_object = lov;
1048 switch (io->ci_type) {
1050 LASSERTF(0, "invalid type %d\n", io->ci_type);
1051 result = -EOPNOTSUPP;
1056 case CIT_DATA_VERSION:
1060 /* the truncate to 0 is managed by MDT:
1061 * - in open, for open O_TRUNC
1062 * - in setattr, for truncate
1064 /* the truncate is for size > 0 so triggers a restore */
1065 if (cl_io_is_trunc(io)) {
1066 io->ci_restore_needed = 1;
1074 io->ci_restore_needed = 1;
1080 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1081 atomic_inc(&lov->lo_active_ios);
1084 io->ci_result = result < 0 ? result : 0;