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 inline struct lov_io_sub *lov_sub_alloc(struct lov_io *lio, int index)
48 struct lov_io_sub *sub;
50 if (lio->lis_nr_subios == 0) {
51 LASSERT(lio->lis_single_subio_index == -1);
52 sub = &lio->lis_single_subio;
53 lio->lis_single_subio_index = index;
54 memset(sub, 0, sizeof(*sub));
60 INIT_LIST_HEAD(&sub->sub_list);
61 INIT_LIST_HEAD(&sub->sub_linkage);
62 sub->sub_subio_index = index;
68 static inline void lov_sub_free(struct lov_io *lio, struct lov_io_sub *sub)
70 if (sub->sub_subio_index == lio->lis_single_subio_index) {
71 LASSERT(sub == &lio->lis_single_subio);
72 lio->lis_single_subio_index = -1;
78 static void lov_io_sub_fini(const struct lu_env *env, struct lov_io *lio,
79 struct lov_io_sub *sub)
83 cl_io_fini(sub->sub_env, &sub->sub_io);
85 if (sub->sub_env != NULL && !IS_ERR(sub->sub_env)) {
86 cl_env_put(sub->sub_env, &sub->sub_refcheck);
92 static int lov_io_sub_init(const struct lu_env *env, struct lov_io *lio,
93 struct lov_io_sub *sub)
95 struct lov_object *lov = lio->lis_object;
97 struct cl_object *sub_obj;
98 struct cl_io *io = lio->lis_cl.cis_io;
99 int index = lov_comp_entry(sub->sub_subio_index);
100 int stripe = lov_comp_stripe(sub->sub_subio_index);
102 LASSERT(sub->sub_env == NULL);
105 if (unlikely(lov_r0(lov, index)->lo_sub[stripe] == NULL))
108 /* obtain new environment */
109 sub->sub_env = cl_env_get(&sub->sub_refcheck);
110 if (IS_ERR(sub->sub_env))
111 result = PTR_ERR(sub->sub_env);
113 sub_obj = lovsub2cl(lov_r0(lov, index)->lo_sub[stripe]);
114 sub_io = &sub->sub_io;
116 sub_io->ci_obj = sub_obj;
117 sub_io->ci_result = 0;
119 sub_io->ci_parent = io;
120 sub_io->ci_lockreq = io->ci_lockreq;
121 sub_io->ci_type = io->ci_type;
122 sub_io->ci_no_srvlock = io->ci_no_srvlock;
123 sub_io->ci_noatime = io->ci_noatime;
125 result = cl_io_sub_init(sub->sub_env, sub_io, io->ci_type, sub_obj);
128 lov_io_sub_fini(env, lio, sub);
133 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
134 struct lov_io *lio, int index)
136 struct lov_io_sub *sub;
141 list_for_each_entry(sub, &lio->lis_subios, sub_list) {
142 if (sub->sub_subio_index == index) {
149 sub = lov_sub_alloc(lio, index);
151 GOTO(out, rc = -ENOMEM);
153 rc = lov_io_sub_init(env, lio, sub);
155 lov_sub_free(lio, sub);
159 list_add_tail(&sub->sub_list, &lio->lis_subios);
160 lio->lis_nr_subios++;
168 /*****************************************************************************
174 int lov_page_index(const struct cl_page *page)
176 const struct cl_page_slice *slice;
179 slice = cl_page_at(page, &lov_device_type);
180 LASSERT(slice != NULL);
181 LASSERT(slice->cpl_obj != NULL);
183 RETURN(cl2lov_page(slice)->lps_index);
186 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
191 LASSERT(lio->lis_object != NULL);
193 INIT_LIST_HEAD(&lio->lis_subios);
194 lio->lis_single_subio_index = -1;
195 lio->lis_nr_subios = 0;
200 static int lov_io_slice_init(struct lov_io *lio,
201 struct lov_object *obj, struct cl_io *io)
206 lio->lis_object = obj;
208 LASSERT(obj->lo_lsm != NULL);
210 switch (io->ci_type) {
213 lio->lis_pos = io->u.ci_rw.crw_pos;
214 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
215 lio->lis_io_endpos = lio->lis_endpos;
216 if (cl_io_is_append(io)) {
217 LASSERT(io->ci_type == CIT_WRITE);
219 /* If there is LOV EA hole, then we may cannot locate
220 * the current file-tail exactly. */
221 if (unlikely(obj->lo_lsm->lsm_entries[0]->lsme_pattern &
226 lio->lis_endpos = OBD_OBJECT_EOF;
231 if (cl_io_is_trunc(io))
232 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
235 lio->lis_endpos = OBD_OBJECT_EOF;
238 case CIT_DATA_VERSION:
240 lio->lis_endpos = OBD_OBJECT_EOF;
244 pgoff_t index = io->u.ci_fault.ft_index;
245 lio->lis_pos = cl_offset(io->ci_obj, index);
246 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
251 lio->lis_pos = io->u.ci_fsync.fi_start;
252 lio->lis_endpos = io->u.ci_fsync.fi_end;
257 lio->lis_pos = io->u.ci_ladvise.li_start;
258 lio->lis_endpos = io->u.ci_ladvise.li_end;
264 lio->lis_endpos = OBD_OBJECT_EOF;
274 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
276 struct lov_io *lio = cl2lov_io(env, ios);
277 struct lov_object *lov = cl2lov(ios->cis_obj);
281 LASSERT(list_empty(&lio->lis_active));
283 while (!list_empty(&lio->lis_subios)) {
284 struct lov_io_sub *sub = list_entry(lio->lis_subios.next,
288 list_del_init(&sub->sub_list);
289 lio->lis_nr_subios--;
291 lov_io_sub_fini(env, lio, sub);
292 lov_sub_free(lio, sub);
294 LASSERT(lio->lis_nr_subios == 0);
296 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
297 if (atomic_dec_and_test(&lov->lo_active_ios))
298 wake_up_all(&lov->lo_waitq);
302 static void lov_io_sub_inherit(struct lov_io_sub *sub, struct lov_io *lio,
303 loff_t start, loff_t end)
305 struct cl_io *io = &sub->sub_io;
306 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
307 struct cl_io *parent = lio->lis_cl.cis_io;
308 int index = lov_comp_entry(sub->sub_subio_index);
309 int stripe = lov_comp_stripe(sub->sub_subio_index);
311 switch (io->ci_type) {
313 io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
314 io->u.ci_setattr.sa_attr_flags =
315 parent->u.ci_setattr.sa_attr_flags;
316 io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
317 io->u.ci_setattr.sa_stripe_index = stripe;
318 io->u.ci_setattr.sa_parent_fid =
319 parent->u.ci_setattr.sa_parent_fid;
320 if (cl_io_is_trunc(io)) {
321 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
323 new_size = lov_size_to_stripe(lsm, index, new_size,
325 io->u.ci_setattr.sa_attr.lvb_size = new_size;
327 lov_lsm2layout(lsm, lsm->lsm_entries[index],
328 &io->u.ci_setattr.sa_layout);
331 case CIT_DATA_VERSION: {
332 io->u.ci_data_version.dv_data_version = 0;
333 io->u.ci_data_version.dv_flags =
334 parent->u.ci_data_version.dv_flags;
338 struct cl_object *obj = parent->ci_obj;
339 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
341 io->u.ci_fault = parent->u.ci_fault;
342 off = lov_size_to_stripe(lsm, index, off, stripe);
343 io->u.ci_fault.ft_index = cl_index(obj, off);
347 io->u.ci_fsync.fi_start = start;
348 io->u.ci_fsync.fi_end = end;
349 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
350 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
355 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
356 if (cl_io_is_append(parent)) {
357 io->u.ci_wr.wr_append = 1;
359 io->u.ci_rw.crw_pos = start;
360 io->u.ci_rw.crw_count = end - start;
365 io->u.ci_ladvise.li_start = start;
366 io->u.ci_ladvise.li_end = end;
367 io->u.ci_ladvise.li_fid = parent->u.ci_ladvise.li_fid;
368 io->u.ci_ladvise.li_advice = parent->u.ci_ladvise.li_advice;
369 io->u.ci_ladvise.li_flags = parent->u.ci_ladvise.li_flags;
377 static loff_t lov_offset_mod(loff_t val, int delta)
379 if (val != OBD_OBJECT_EOF)
384 static int lov_io_iter_init(const struct lu_env *env,
385 const struct cl_io_slice *ios)
387 struct lov_io *lio = cl2lov_io(env, ios);
388 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
389 struct lov_io_sub *sub;
390 struct lov_layout_entry *le;
391 struct lu_extent ext;
397 ext.e_start = lio->lis_pos;
398 ext.e_end = lio->lis_endpos;
401 lov_foreach_layout_entry(lio->lis_object, le) {
402 struct lov_layout_raid0 *r0 = &le->lle_raid0;
407 CDEBUG(D_VFSTRACE, "component[%d] flags %#x\n",
408 index, lsm->lsm_entries[index]->lsme_flags);
409 if (!lsm_entry_inited(lsm, index))
413 if (!lu_extent_is_overlapped(&ext, &le->lle_extent))
416 for (stripe = 0; stripe < r0->lo_nr; stripe++) {
417 if (!lov_stripe_intersects(lsm, index - 1, stripe,
421 if (unlikely(r0->lo_sub[stripe] == NULL)) {
422 if (ios->cis_io->ci_type == CIT_READ ||
423 ios->cis_io->ci_type == CIT_WRITE ||
424 ios->cis_io->ci_type == CIT_FAULT)
430 end = lov_offset_mod(end, 1);
431 sub = lov_sub_get(env, lio,
432 lov_comp_index(index - 1, stripe));
438 lov_io_sub_inherit(sub, lio, start, end);
439 rc = cl_io_iter_init(sub->sub_env, &sub->sub_io);
441 cl_io_iter_fini(sub->sub_env, &sub->sub_io);
445 CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
448 list_add_tail(&sub->sub_linkage, &lio->lis_active);
456 static int lov_io_rw_iter_init(const struct lu_env *env,
457 const struct cl_io_slice *ios)
459 struct lov_io *lio = cl2lov_io(env, ios);
460 struct cl_io *io = ios->cis_io;
461 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
462 struct lov_stripe_md_entry *lse;
463 loff_t start = io->u.ci_rw.crw_pos;
468 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
471 if (cl_io_is_append(io))
472 RETURN(lov_io_iter_init(env, ios));
474 index = lov_lsm_entry(lsm, io->u.ci_rw.crw_pos);
475 if (index < 0) { /* non-existing layout component */
476 if (io->ci_type == CIT_READ) {
477 /* TODO: it needs to detect the next component and
478 * then set the next pos */
481 RETURN(lov_io_iter_init(env, ios));
487 lse = lov_lse(lio->lis_object, index);
489 ssize = lse->lsme_stripe_size;
490 lov_do_div64(start, ssize);
491 next = (start + 1) * ssize;
492 if (next <= start * ssize)
495 LASSERTF(io->u.ci_rw.crw_pos >= lse->lsme_extent.e_start,
496 "pos %lld, [%lld, %lld)\n", io->u.ci_rw.crw_pos,
497 lse->lsme_extent.e_start, lse->lsme_extent.e_end);
498 next = min_t(__u64, next, lse->lsme_extent.e_end);
499 next = min_t(loff_t, next, lio->lis_io_endpos);
501 io->ci_continue = next < lio->lis_io_endpos;
502 io->u.ci_rw.crw_count = next - io->u.ci_rw.crw_pos;
503 lio->lis_pos = io->u.ci_rw.crw_pos;
504 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
506 "stripe: %llu chunk: [%llu, %llu) %llu, %zd\n",
507 (__u64)start, lio->lis_pos, lio->lis_endpos,
508 (__u64)lio->lis_io_endpos, io->u.ci_rw.crw_count);
510 index = lov_lsm_entry(lsm, lio->lis_endpos - 1);
511 if (index > 0 && !lsm_entry_inited(lsm, index)) {
512 io->ci_need_write_intent = 1;
513 RETURN(io->ci_result = -ENODATA);
517 * XXX The following call should be optimized: we know, that
518 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
520 RETURN(lov_io_iter_init(env, ios));
523 static int lov_io_setattr_iter_init(const struct lu_env *env,
524 const struct cl_io_slice *ios)
526 struct lov_io *lio = cl2lov_io(env, ios);
527 struct cl_io *io = ios->cis_io;
528 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
532 if (cl_io_is_trunc(io) && lio->lis_pos) {
533 index = lov_lsm_entry(lsm, lio->lis_pos - 1);
534 if (index > 0 && !lsm_entry_inited(lsm, index)) {
535 io->ci_need_write_intent = 1;
536 RETURN(io->ci_result = -ENODATA);
540 RETURN(lov_io_iter_init(env, ios));
543 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
544 int (*iofunc)(const struct lu_env *, struct cl_io *))
546 struct cl_io *parent = lio->lis_cl.cis_io;
547 struct lov_io_sub *sub;
551 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
552 rc = iofunc(sub->sub_env, &sub->sub_io);
556 if (parent->ci_result == 0)
557 parent->ci_result = sub->sub_io.ci_result;
562 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
565 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
568 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
571 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
574 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
578 * It's possible that lov_io_start() wasn't called against this
579 * sub-io, either because previous sub-io failed, or upper layer
582 if (io->ci_state == CIS_IO_GOING)
585 io->ci_state = CIS_IO_FINISHED;
589 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
591 cl_io_iter_fini(env, io);
595 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
597 cl_io_unlock(env, io);
601 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
605 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
610 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
612 struct lov_io *lio = cl2lov_io(env, ios);
613 struct cl_io *parent = lio->lis_cl.cis_io;
614 struct lov_io_sub *sub;
617 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
618 lov_io_end_wrapper(env, &sub->sub_io);
620 parent->u.ci_data_version.dv_data_version +=
621 sub->sub_io.u.ci_data_version.dv_data_version;
623 if (parent->ci_result == 0)
624 parent->ci_result = sub->sub_io.ci_result;
630 static void lov_io_iter_fini(const struct lu_env *env,
631 const struct cl_io_slice *ios)
633 struct lov_io *lio = cl2lov_io(env, ios);
637 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
639 while (!list_empty(&lio->lis_active))
640 list_del_init(lio->lis_active.next);
644 static void lov_io_unlock(const struct lu_env *env,
645 const struct cl_io_slice *ios)
650 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
655 static int lov_io_read_ahead(const struct lu_env *env,
656 const struct cl_io_slice *ios,
657 pgoff_t start, struct cl_read_ahead *ra)
659 struct lov_io *lio = cl2lov_io(env, ios);
660 struct lov_object *loo = lio->lis_object;
661 struct cl_object *obj = lov2cl(loo);
662 struct lov_layout_raid0 *r0;
663 struct lov_io_sub *sub;
667 unsigned int pps; /* pages per stripe */
673 offset = cl_offset(obj, start);
674 index = lov_lsm_entry(loo->lo_lsm, offset);
675 if (index < 0 || !lsm_entry_inited(loo->lo_lsm, index))
678 stripe = lov_stripe_number(loo->lo_lsm, index, offset);
680 r0 = lov_r0(loo, index);
681 if (unlikely(r0->lo_sub[stripe] == NULL))
684 sub = lov_sub_get(env, lio, lov_comp_index(index, stripe));
686 RETURN(PTR_ERR(sub));
688 lov_stripe_offset(loo->lo_lsm, index, offset, stripe, &suboff);
689 rc = cl_io_read_ahead(sub->sub_env, &sub->sub_io,
690 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
693 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
694 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
699 * Adjust the stripe index by layout of raid0. ra->cra_end is the
700 * maximum page index covered by an underlying DLM lock.
701 * This function converts cra_end from stripe level to file level, and
702 * make sure it's not beyond stripe boundary.
704 if (r0->lo_nr == 1) /* single stripe file */
707 /* cra_end is stripe level, convert it into file level */
708 ra_end = ra->cra_end;
709 if (ra_end != CL_PAGE_EOF)
710 ra_end = lov_stripe_pgoff(loo->lo_lsm, index, ra_end, stripe);
712 pps = lov_lse(loo, index)->lsme_stripe_size >> PAGE_SHIFT;
714 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, index = %u, "
715 "stripe_size = %u, stripe no = %u, start index = %lu\n",
716 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps, index,
717 lov_lse(loo, index)->lsme_stripe_size, stripe, start);
719 /* never exceed the end of the stripe */
720 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
725 * lov implementation of cl_operations::cio_submit() method. It takes a list
726 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
727 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
730 * Major complication of this function is a need to handle memory cleansing:
731 * cl_io_submit() is called to write out pages as a part of VM memory
732 * reclamation, and hence it may not fail due to memory shortages (system
733 * dead-locks otherwise). To deal with this, some resources (sub-lists,
734 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
735 * not-memory cleansing context), and in case of memory shortage, these
736 * pre-allocated resources are used by lov_io_submit() under
737 * lov_device::ld_mutex mutex.
739 static int lov_io_submit(const struct lu_env *env,
740 const struct cl_io_slice *ios,
741 enum cl_req_type crt, struct cl_2queue *queue)
743 struct cl_page_list *qin = &queue->c2_qin;
744 struct lov_io *lio = cl2lov_io(env, ios);
745 struct lov_io_sub *sub;
746 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
747 struct cl_page *page;
752 if (lio->lis_nr_subios == 1) {
753 int idx = lio->lis_single_subio_index;
755 sub = lov_sub_get(env, lio, idx);
756 LASSERT(!IS_ERR(sub));
757 LASSERT(sub == &lio->lis_single_subio);
758 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
763 cl_page_list_init(plist);
764 while (qin->pl_nr > 0) {
765 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
767 cl_2queue_init(cl2q);
769 page = cl_page_list_first(qin);
770 cl_page_list_move(&cl2q->c2_qin, qin, page);
772 index = lov_page_index(page);
773 while (qin->pl_nr > 0) {
774 page = cl_page_list_first(qin);
775 if (index != lov_page_index(page))
778 cl_page_list_move(&cl2q->c2_qin, qin, page);
781 sub = lov_sub_get(env, lio, index);
783 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
789 cl_page_list_splice(&cl2q->c2_qin, plist);
790 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
791 cl_2queue_fini(env, cl2q);
797 cl_page_list_splice(plist, qin);
798 cl_page_list_fini(env, plist);
803 static int lov_io_commit_async(const struct lu_env *env,
804 const struct cl_io_slice *ios,
805 struct cl_page_list *queue, int from, int to,
808 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
809 struct lov_io *lio = cl2lov_io(env, ios);
810 struct lov_io_sub *sub;
811 struct cl_page *page;
815 if (lio->lis_nr_subios == 1) {
816 int idx = lio->lis_single_subio_index;
818 sub = lov_sub_get(env, lio, idx);
819 LASSERT(!IS_ERR(sub));
820 LASSERT(sub == &lio->lis_single_subio);
821 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io, queue,
826 cl_page_list_init(plist);
827 while (queue->pl_nr > 0) {
831 LASSERT(plist->pl_nr == 0);
832 page = cl_page_list_first(queue);
833 cl_page_list_move(plist, queue, page);
835 index = lov_page_index(page);
836 while (queue->pl_nr > 0) {
837 page = cl_page_list_first(queue);
838 if (index != lov_page_index(page))
841 cl_page_list_move(plist, queue, page);
844 if (queue->pl_nr > 0) /* still has more pages */
845 stripe_to = PAGE_SIZE;
847 sub = lov_sub_get(env, lio, index);
849 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io,
850 plist, from, stripe_to, cb);
856 if (plist->pl_nr > 0) /* short write */
862 /* for error case, add the page back into the qin list */
863 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
864 while (plist->pl_nr > 0) {
865 /* error occurred, add the uncommitted pages back into queue */
866 page = cl_page_list_last(plist);
867 cl_page_list_move_head(queue, plist, page);
873 static int lov_io_fault_start(const struct lu_env *env,
874 const struct cl_io_slice *ios)
876 struct cl_fault_io *fio;
878 struct lov_io_sub *sub;
882 fio = &ios->cis_io->u.ci_fault;
883 lio = cl2lov_io(env, ios);
884 sub = lov_sub_get(env, lio, lov_page_index(fio->ft_page));
885 sub->sub_io.u.ci_fault.ft_nob = fio->ft_nob;
887 RETURN(lov_io_start(env, ios));
890 static void lov_io_fsync_end(const struct lu_env *env,
891 const struct cl_io_slice *ios)
893 struct lov_io *lio = cl2lov_io(env, ios);
894 struct lov_io_sub *sub;
895 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
899 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
900 struct cl_io *subio = &sub->sub_io;
902 lov_io_end_wrapper(sub->sub_env, subio);
904 if (subio->ci_result == 0)
905 *written += subio->u.ci_fsync.fi_nr_written;
910 static const struct cl_io_operations lov_io_ops = {
913 .cio_fini = lov_io_fini,
914 .cio_iter_init = lov_io_rw_iter_init,
915 .cio_iter_fini = lov_io_iter_fini,
916 .cio_lock = lov_io_lock,
917 .cio_unlock = lov_io_unlock,
918 .cio_start = lov_io_start,
919 .cio_end = lov_io_end
922 .cio_fini = lov_io_fini,
923 .cio_iter_init = lov_io_rw_iter_init,
924 .cio_iter_fini = lov_io_iter_fini,
925 .cio_lock = lov_io_lock,
926 .cio_unlock = lov_io_unlock,
927 .cio_start = lov_io_start,
928 .cio_end = lov_io_end
931 .cio_fini = lov_io_fini,
932 .cio_iter_init = lov_io_setattr_iter_init,
933 .cio_iter_fini = lov_io_iter_fini,
934 .cio_lock = lov_io_lock,
935 .cio_unlock = lov_io_unlock,
936 .cio_start = lov_io_start,
937 .cio_end = lov_io_end
939 [CIT_DATA_VERSION] = {
940 .cio_fini = lov_io_fini,
941 .cio_iter_init = lov_io_iter_init,
942 .cio_iter_fini = lov_io_iter_fini,
943 .cio_lock = lov_io_lock,
944 .cio_unlock = lov_io_unlock,
945 .cio_start = lov_io_start,
946 .cio_end = lov_io_data_version_end,
949 .cio_fini = lov_io_fini,
950 .cio_iter_init = lov_io_iter_init,
951 .cio_iter_fini = lov_io_iter_fini,
952 .cio_lock = lov_io_lock,
953 .cio_unlock = lov_io_unlock,
954 .cio_start = lov_io_fault_start,
955 .cio_end = lov_io_end
958 .cio_fini = lov_io_fini,
959 .cio_iter_init = lov_io_iter_init,
960 .cio_iter_fini = lov_io_iter_fini,
961 .cio_lock = lov_io_lock,
962 .cio_unlock = lov_io_unlock,
963 .cio_start = lov_io_start,
964 .cio_end = lov_io_fsync_end
967 .cio_fini = lov_io_fini,
968 .cio_iter_init = lov_io_iter_init,
969 .cio_iter_fini = lov_io_iter_fini,
970 .cio_lock = lov_io_lock,
971 .cio_unlock = lov_io_unlock,
972 .cio_start = lov_io_start,
973 .cio_end = lov_io_end
976 .cio_fini = lov_io_fini
979 .cio_read_ahead = lov_io_read_ahead,
980 .cio_submit = lov_io_submit,
981 .cio_commit_async = lov_io_commit_async,
984 /*****************************************************************************
986 * Empty lov io operations.
990 static void lov_empty_io_fini(const struct lu_env *env,
991 const struct cl_io_slice *ios)
993 struct lov_object *lov = cl2lov(ios->cis_obj);
996 if (atomic_dec_and_test(&lov->lo_active_ios))
997 wake_up_all(&lov->lo_waitq);
1001 static int lov_empty_io_submit(const struct lu_env *env,
1002 const struct cl_io_slice *ios,
1003 enum cl_req_type crt, struct cl_2queue *queue)
1008 static void lov_empty_impossible(const struct lu_env *env,
1009 struct cl_io_slice *ios)
1014 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
1017 * An io operation vector for files without stripes.
1019 static const struct cl_io_operations lov_empty_io_ops = {
1022 .cio_fini = lov_empty_io_fini,
1024 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1025 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1026 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1027 .cio_end = LOV_EMPTY_IMPOSSIBLE
1031 .cio_fini = lov_empty_io_fini,
1032 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1033 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1034 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1035 .cio_end = LOV_EMPTY_IMPOSSIBLE
1038 .cio_fini = lov_empty_io_fini,
1039 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1040 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1041 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1042 .cio_end = LOV_EMPTY_IMPOSSIBLE
1045 .cio_fini = lov_empty_io_fini,
1046 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1047 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1048 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1049 .cio_end = LOV_EMPTY_IMPOSSIBLE
1052 .cio_fini = lov_empty_io_fini
1055 .cio_fini = lov_empty_io_fini
1058 .cio_fini = lov_empty_io_fini
1061 .cio_submit = lov_empty_io_submit,
1062 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
1065 int lov_io_init_composite(const struct lu_env *env, struct cl_object *obj,
1068 struct lov_io *lio = lov_env_io(env);
1069 struct lov_object *lov = cl2lov(obj);
1072 INIT_LIST_HEAD(&lio->lis_active);
1073 io->ci_result = lov_io_slice_init(lio, lov, io);
1074 if (io->ci_result != 0)
1075 RETURN(io->ci_result);
1077 if (io->ci_result == 0) {
1078 io->ci_result = lov_io_subio_init(env, lio, io);
1079 if (io->ci_result == 0) {
1080 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
1081 atomic_inc(&lov->lo_active_ios);
1084 RETURN(io->ci_result);
1087 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
1090 struct lov_object *lov = cl2lov(obj);
1091 struct lov_io *lio = lov_env_io(env);
1095 lio->lis_object = lov;
1096 switch (io->ci_type) {
1106 case CIT_DATA_VERSION:
1114 CERROR("Page fault on a file without stripes: "DFID"\n",
1115 PFID(lu_object_fid(&obj->co_lu)));
1119 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1120 atomic_inc(&lov->lo_active_ios);
1123 io->ci_result = result < 0 ? result : 0;
1127 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1130 struct lov_object *lov = cl2lov(obj);
1131 struct lov_io *lio = lov_env_io(env);
1135 LASSERT(lov->lo_lsm != NULL);
1136 lio->lis_object = lov;
1138 switch (io->ci_type) {
1140 LASSERTF(0, "invalid type %d\n", io->ci_type);
1141 result = -EOPNOTSUPP;
1146 case CIT_DATA_VERSION:
1150 /* the truncate to 0 is managed by MDT:
1151 * - in open, for open O_TRUNC
1152 * - in setattr, for truncate
1154 /* the truncate is for size > 0 so triggers a restore */
1155 if (cl_io_is_trunc(io)) {
1156 io->ci_restore_needed = 1;
1164 io->ci_restore_needed = 1;
1170 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1171 atomic_inc(&lov->lo_active_ios);
1174 io->ci_result = result < 0 ? result : 0;