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 ||
106 !lov_r0(lov, index)->lo_sub[stripe]))
109 /* obtain new environment */
110 sub->sub_env = cl_env_get(&sub->sub_refcheck);
111 if (IS_ERR(sub->sub_env))
112 result = PTR_ERR(sub->sub_env);
114 sub_obj = lovsub2cl(lov_r0(lov, index)->lo_sub[stripe]);
115 sub_io = &sub->sub_io;
117 sub_io->ci_obj = sub_obj;
118 sub_io->ci_result = 0;
120 sub_io->ci_parent = io;
121 sub_io->ci_lockreq = io->ci_lockreq;
122 sub_io->ci_type = io->ci_type;
123 sub_io->ci_no_srvlock = io->ci_no_srvlock;
124 sub_io->ci_noatime = io->ci_noatime;
126 result = cl_io_sub_init(sub->sub_env, sub_io, io->ci_type, sub_obj);
129 lov_io_sub_fini(env, lio, sub);
134 struct lov_io_sub *lov_sub_get(const struct lu_env *env,
135 struct lov_io *lio, int index)
137 struct lov_io_sub *sub;
142 list_for_each_entry(sub, &lio->lis_subios, sub_list) {
143 if (sub->sub_subio_index == index) {
150 sub = lov_sub_alloc(lio, index);
152 GOTO(out, rc = -ENOMEM);
154 rc = lov_io_sub_init(env, lio, sub);
156 lov_sub_free(lio, sub);
160 list_add_tail(&sub->sub_list, &lio->lis_subios);
161 lio->lis_nr_subios++;
169 /*****************************************************************************
175 int lov_page_index(const struct cl_page *page)
177 const struct cl_page_slice *slice;
180 slice = cl_page_at(page, &lov_device_type);
181 LASSERT(slice != NULL);
182 LASSERT(slice->cpl_obj != NULL);
184 RETURN(cl2lov_page(slice)->lps_index);
187 static int lov_io_subio_init(const struct lu_env *env, struct lov_io *lio,
192 LASSERT(lio->lis_object != NULL);
194 INIT_LIST_HEAD(&lio->lis_subios);
195 lio->lis_single_subio_index = -1;
196 lio->lis_nr_subios = 0;
201 static int lov_io_slice_init(struct lov_io *lio,
202 struct lov_object *obj, struct cl_io *io)
207 lio->lis_object = obj;
209 LASSERT(obj->lo_lsm != NULL);
211 switch (io->ci_type) {
214 lio->lis_pos = io->u.ci_rw.crw_pos;
215 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
216 lio->lis_io_endpos = lio->lis_endpos;
217 if (cl_io_is_append(io)) {
218 LASSERT(io->ci_type == CIT_WRITE);
220 /* If there is LOV EA hole, then we may cannot locate
221 * the current file-tail exactly. */
222 if (unlikely(obj->lo_lsm->lsm_entries[0]->lsme_pattern &
227 lio->lis_endpos = OBD_OBJECT_EOF;
232 if (cl_io_is_trunc(io))
233 lio->lis_pos = io->u.ci_setattr.sa_attr.lvb_size;
236 lio->lis_endpos = OBD_OBJECT_EOF;
239 case CIT_DATA_VERSION:
241 lio->lis_endpos = OBD_OBJECT_EOF;
245 pgoff_t index = io->u.ci_fault.ft_index;
246 lio->lis_pos = cl_offset(io->ci_obj, index);
247 lio->lis_endpos = cl_offset(io->ci_obj, index + 1);
252 lio->lis_pos = io->u.ci_fsync.fi_start;
253 lio->lis_endpos = io->u.ci_fsync.fi_end;
258 lio->lis_pos = io->u.ci_ladvise.li_start;
259 lio->lis_endpos = io->u.ci_ladvise.li_end;
265 lio->lis_endpos = OBD_OBJECT_EOF;
275 static void lov_io_fini(const struct lu_env *env, const struct cl_io_slice *ios)
277 struct lov_io *lio = cl2lov_io(env, ios);
278 struct lov_object *lov = cl2lov(ios->cis_obj);
282 LASSERT(list_empty(&lio->lis_active));
284 while (!list_empty(&lio->lis_subios)) {
285 struct lov_io_sub *sub = list_entry(lio->lis_subios.next,
289 list_del_init(&sub->sub_list);
290 lio->lis_nr_subios--;
292 lov_io_sub_fini(env, lio, sub);
293 lov_sub_free(lio, sub);
295 LASSERT(lio->lis_nr_subios == 0);
297 LASSERT(atomic_read(&lov->lo_active_ios) > 0);
298 if (atomic_dec_and_test(&lov->lo_active_ios))
299 wake_up_all(&lov->lo_waitq);
303 static void lov_io_sub_inherit(struct lov_io_sub *sub, struct lov_io *lio,
304 loff_t start, loff_t end)
306 struct cl_io *io = &sub->sub_io;
307 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
308 struct cl_io *parent = lio->lis_cl.cis_io;
309 int index = lov_comp_entry(sub->sub_subio_index);
310 int stripe = lov_comp_stripe(sub->sub_subio_index);
312 switch (io->ci_type) {
314 io->u.ci_setattr.sa_attr = parent->u.ci_setattr.sa_attr;
315 io->u.ci_setattr.sa_attr_flags =
316 parent->u.ci_setattr.sa_attr_flags;
317 io->u.ci_setattr.sa_valid = parent->u.ci_setattr.sa_valid;
318 io->u.ci_setattr.sa_stripe_index = stripe;
319 io->u.ci_setattr.sa_parent_fid =
320 parent->u.ci_setattr.sa_parent_fid;
321 if (cl_io_is_trunc(io)) {
322 loff_t new_size = parent->u.ci_setattr.sa_attr.lvb_size;
324 new_size = lov_size_to_stripe(lsm, index, new_size,
326 io->u.ci_setattr.sa_attr.lvb_size = new_size;
328 lov_lsm2layout(lsm, lsm->lsm_entries[index],
329 &io->u.ci_setattr.sa_layout);
332 case CIT_DATA_VERSION: {
333 io->u.ci_data_version.dv_data_version = 0;
334 io->u.ci_data_version.dv_flags =
335 parent->u.ci_data_version.dv_flags;
339 struct cl_object *obj = parent->ci_obj;
340 loff_t off = cl_offset(obj, parent->u.ci_fault.ft_index);
342 io->u.ci_fault = parent->u.ci_fault;
343 off = lov_size_to_stripe(lsm, index, off, stripe);
344 io->u.ci_fault.ft_index = cl_index(obj, off);
348 io->u.ci_fsync.fi_start = start;
349 io->u.ci_fsync.fi_end = end;
350 io->u.ci_fsync.fi_fid = parent->u.ci_fsync.fi_fid;
351 io->u.ci_fsync.fi_mode = parent->u.ci_fsync.fi_mode;
356 io->u.ci_wr.wr_sync = cl_io_is_sync_write(parent);
357 if (cl_io_is_append(parent)) {
358 io->u.ci_wr.wr_append = 1;
360 io->u.ci_rw.crw_pos = start;
361 io->u.ci_rw.crw_count = end - start;
366 io->u.ci_ladvise.li_start = start;
367 io->u.ci_ladvise.li_end = end;
368 io->u.ci_ladvise.li_fid = parent->u.ci_ladvise.li_fid;
369 io->u.ci_ladvise.li_advice = parent->u.ci_ladvise.li_advice;
370 io->u.ci_ladvise.li_flags = parent->u.ci_ladvise.li_flags;
378 static loff_t lov_offset_mod(loff_t val, int delta)
380 if (val != OBD_OBJECT_EOF)
385 static int lov_io_iter_init(const struct lu_env *env,
386 const struct cl_io_slice *ios)
388 struct cl_io *io = ios->cis_io;
389 struct lov_io *lio = cl2lov_io(env, ios);
390 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
391 struct lov_io_sub *sub;
392 struct lov_layout_entry *le;
393 struct lu_extent ext;
399 ext.e_start = lio->lis_pos;
400 ext.e_end = lio->lis_endpos;
403 lov_foreach_layout_entry(lio->lis_object, le) {
404 struct lov_layout_raid0 *r0 = &le->lle_raid0;
410 if (!lu_extent_is_overlapped(&ext, &le->lle_extent))
413 CDEBUG(D_VFSTRACE, "component[%d] flags %#x\n",
414 index - 1, lsm->lsm_entries[index - 1]->lsme_flags);
415 if (!lsm_entry_inited(lsm, index - 1)) {
416 /* truncate IO will trigger write intent as well, and
417 * it's handled in lov_io_setattr_iter_init() */
418 if (io->ci_type == CIT_WRITE || cl_io_is_mkwrite(io)) {
419 io->ci_need_write_intent = 1;
424 /* Read from uninitialized components should return
425 * zero filled pages. */
429 for (stripe = 0; stripe < r0->lo_nr; stripe++) {
430 if (!lov_stripe_intersects(lsm, index - 1, stripe,
434 if (unlikely(r0->lo_sub[stripe] == NULL)) {
435 if (ios->cis_io->ci_type == CIT_READ ||
436 ios->cis_io->ci_type == CIT_WRITE ||
437 ios->cis_io->ci_type == CIT_FAULT)
443 end = lov_offset_mod(end, 1);
444 sub = lov_sub_get(env, lio,
445 lov_comp_index(index - 1, stripe));
451 lov_io_sub_inherit(sub, lio, start, end);
452 rc = cl_io_iter_init(sub->sub_env, &sub->sub_io);
454 cl_io_iter_fini(sub->sub_env, &sub->sub_io);
458 CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
461 list_add_tail(&sub->sub_linkage, &lio->lis_active);
469 static int lov_io_rw_iter_init(const struct lu_env *env,
470 const struct cl_io_slice *ios)
472 struct lov_io *lio = cl2lov_io(env, ios);
473 struct cl_io *io = ios->cis_io;
474 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
475 struct lov_stripe_md_entry *lse;
476 loff_t start = io->u.ci_rw.crw_pos;
481 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
484 if (cl_io_is_append(io))
485 RETURN(lov_io_iter_init(env, ios));
487 index = lov_lsm_entry(lsm, io->u.ci_rw.crw_pos);
488 if (index < 0) { /* non-existing layout component */
489 if (io->ci_type == CIT_READ) {
490 /* TODO: it needs to detect the next component and
491 * then set the next pos */
494 RETURN(lov_io_iter_init(env, ios));
500 lse = lov_lse(lio->lis_object, index);
502 ssize = lse->lsme_stripe_size;
503 lov_do_div64(start, ssize);
504 next = (start + 1) * ssize;
505 if (next <= start * ssize)
508 LASSERTF(io->u.ci_rw.crw_pos >= lse->lsme_extent.e_start,
509 "pos %lld, [%lld, %lld)\n", io->u.ci_rw.crw_pos,
510 lse->lsme_extent.e_start, lse->lsme_extent.e_end);
511 next = min_t(__u64, next, lse->lsme_extent.e_end);
512 next = min_t(loff_t, next, lio->lis_io_endpos);
514 io->ci_continue = next < lio->lis_io_endpos;
515 io->u.ci_rw.crw_count = next - io->u.ci_rw.crw_pos;
516 lio->lis_pos = io->u.ci_rw.crw_pos;
517 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
519 "stripe: %llu chunk: [%llu, %llu) %llu, %zd\n",
520 (__u64)start, lio->lis_pos, lio->lis_endpos,
521 (__u64)lio->lis_io_endpos, io->u.ci_rw.crw_count);
524 * XXX The following call should be optimized: we know, that
525 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
527 RETURN(lov_io_iter_init(env, ios));
530 static int lov_io_setattr_iter_init(const struct lu_env *env,
531 const struct cl_io_slice *ios)
533 struct lov_io *lio = cl2lov_io(env, ios);
534 struct cl_io *io = ios->cis_io;
535 struct lov_stripe_md *lsm = lio->lis_object->lo_lsm;
539 if (cl_io_is_trunc(io) && lio->lis_pos > 0) {
540 index = lov_lsm_entry(lsm, lio->lis_pos - 1);
541 if (index > 0 && !lsm_entry_inited(lsm, index)) {
542 io->ci_need_write_intent = 1;
543 RETURN(io->ci_result = -ENODATA);
547 RETURN(lov_io_iter_init(env, ios));
550 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
551 int (*iofunc)(const struct lu_env *, struct cl_io *))
553 struct cl_io *parent = lio->lis_cl.cis_io;
554 struct lov_io_sub *sub;
558 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
559 rc = iofunc(sub->sub_env, &sub->sub_io);
563 if (parent->ci_result == 0)
564 parent->ci_result = sub->sub_io.ci_result;
569 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
572 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
575 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
578 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
581 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
585 * It's possible that lov_io_start() wasn't called against this
586 * sub-io, either because previous sub-io failed, or upper layer
589 if (io->ci_state == CIS_IO_GOING)
592 io->ci_state = CIS_IO_FINISHED;
596 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
598 cl_io_iter_fini(env, io);
602 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
604 cl_io_unlock(env, io);
608 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
612 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
617 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
619 struct lov_io *lio = cl2lov_io(env, ios);
620 struct cl_io *parent = lio->lis_cl.cis_io;
621 struct lov_io_sub *sub;
624 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
625 lov_io_end_wrapper(env, &sub->sub_io);
627 parent->u.ci_data_version.dv_data_version +=
628 sub->sub_io.u.ci_data_version.dv_data_version;
630 if (parent->ci_result == 0)
631 parent->ci_result = sub->sub_io.ci_result;
637 static void lov_io_iter_fini(const struct lu_env *env,
638 const struct cl_io_slice *ios)
640 struct lov_io *lio = cl2lov_io(env, ios);
644 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
646 while (!list_empty(&lio->lis_active))
647 list_del_init(lio->lis_active.next);
651 static void lov_io_unlock(const struct lu_env *env,
652 const struct cl_io_slice *ios)
657 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
662 static int lov_io_read_ahead(const struct lu_env *env,
663 const struct cl_io_slice *ios,
664 pgoff_t start, struct cl_read_ahead *ra)
666 struct lov_io *lio = cl2lov_io(env, ios);
667 struct lov_object *loo = lio->lis_object;
668 struct cl_object *obj = lov2cl(loo);
669 struct lov_layout_raid0 *r0;
670 struct lov_io_sub *sub;
674 unsigned int pps; /* pages per stripe */
680 offset = cl_offset(obj, start);
681 index = lov_lsm_entry(loo->lo_lsm, offset);
682 if (index < 0 || !lsm_entry_inited(loo->lo_lsm, index))
685 stripe = lov_stripe_number(loo->lo_lsm, index, offset);
687 r0 = lov_r0(loo, index);
688 if (unlikely(r0->lo_sub[stripe] == NULL))
691 sub = lov_sub_get(env, lio, lov_comp_index(index, stripe));
693 RETURN(PTR_ERR(sub));
695 lov_stripe_offset(loo->lo_lsm, index, offset, stripe, &suboff);
696 rc = cl_io_read_ahead(sub->sub_env, &sub->sub_io,
697 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
700 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
701 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
706 * Adjust the stripe index by layout of comp. ra->cra_end is the
707 * maximum page index covered by an underlying DLM lock.
708 * This function converts cra_end from stripe level to file level, and
709 * make sure it's not beyond stripe and component boundary.
712 /* cra_end is stripe level, convert it into file level */
713 ra_end = ra->cra_end;
714 if (ra_end != CL_PAGE_EOF)
715 ra->cra_end = lov_stripe_pgoff(loo->lo_lsm, index,
718 /* boundary of current component */
719 ra_end = cl_index(obj, (loff_t)lov_lse(loo, index)->lsme_extent.e_end);
720 if (ra_end != CL_PAGE_EOF && ra->cra_end >= ra_end)
721 ra->cra_end = ra_end - 1;
723 if (r0->lo_nr == 1) /* single stripe file */
726 pps = lov_lse(loo, index)->lsme_stripe_size >> PAGE_SHIFT;
728 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, index = %u, "
729 "stripe_size = %u, stripe no = %u, start index = %lu\n",
730 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, pps, index,
731 lov_lse(loo, index)->lsme_stripe_size, stripe, start);
733 /* never exceed the end of the stripe */
734 ra->cra_end = min_t(pgoff_t,
735 ra->cra_end, start + pps - start % pps - 1);
740 * lov implementation of cl_operations::cio_submit() method. It takes a list
741 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
742 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
745 * Major complication of this function is a need to handle memory cleansing:
746 * cl_io_submit() is called to write out pages as a part of VM memory
747 * reclamation, and hence it may not fail due to memory shortages (system
748 * dead-locks otherwise). To deal with this, some resources (sub-lists,
749 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
750 * not-memory cleansing context), and in case of memory shortage, these
751 * pre-allocated resources are used by lov_io_submit() under
752 * lov_device::ld_mutex mutex.
754 static int lov_io_submit(const struct lu_env *env,
755 const struct cl_io_slice *ios,
756 enum cl_req_type crt, struct cl_2queue *queue)
758 struct cl_page_list *qin = &queue->c2_qin;
759 struct lov_io *lio = cl2lov_io(env, ios);
760 struct lov_io_sub *sub;
761 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
762 struct cl_page *page;
767 if (lio->lis_nr_subios == 1) {
768 int idx = lio->lis_single_subio_index;
770 sub = lov_sub_get(env, lio, idx);
771 LASSERT(!IS_ERR(sub));
772 LASSERT(sub == &lio->lis_single_subio);
773 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
778 cl_page_list_init(plist);
779 while (qin->pl_nr > 0) {
780 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
782 cl_2queue_init(cl2q);
784 page = cl_page_list_first(qin);
785 cl_page_list_move(&cl2q->c2_qin, qin, page);
787 index = lov_page_index(page);
788 while (qin->pl_nr > 0) {
789 page = cl_page_list_first(qin);
790 if (index != lov_page_index(page))
793 cl_page_list_move(&cl2q->c2_qin, qin, page);
796 sub = lov_sub_get(env, lio, index);
798 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
804 cl_page_list_splice(&cl2q->c2_qin, plist);
805 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
806 cl_2queue_fini(env, cl2q);
812 cl_page_list_splice(plist, qin);
813 cl_page_list_fini(env, plist);
818 static int lov_io_commit_async(const struct lu_env *env,
819 const struct cl_io_slice *ios,
820 struct cl_page_list *queue, int from, int to,
823 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
824 struct lov_io *lio = cl2lov_io(env, ios);
825 struct lov_io_sub *sub;
826 struct cl_page *page;
830 if (lio->lis_nr_subios == 1) {
831 int idx = lio->lis_single_subio_index;
833 sub = lov_sub_get(env, lio, idx);
834 LASSERT(!IS_ERR(sub));
835 LASSERT(sub == &lio->lis_single_subio);
836 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io, queue,
841 cl_page_list_init(plist);
842 while (queue->pl_nr > 0) {
846 LASSERT(plist->pl_nr == 0);
847 page = cl_page_list_first(queue);
848 cl_page_list_move(plist, queue, page);
850 index = lov_page_index(page);
851 while (queue->pl_nr > 0) {
852 page = cl_page_list_first(queue);
853 if (index != lov_page_index(page))
856 cl_page_list_move(plist, queue, page);
859 if (queue->pl_nr > 0) /* still has more pages */
860 stripe_to = PAGE_SIZE;
862 sub = lov_sub_get(env, lio, index);
864 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io,
865 plist, from, stripe_to, cb);
871 if (plist->pl_nr > 0) /* short write */
877 /* for error case, add the page back into the qin list */
878 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
879 while (plist->pl_nr > 0) {
880 /* error occurred, add the uncommitted pages back into queue */
881 page = cl_page_list_last(plist);
882 cl_page_list_move_head(queue, plist, page);
888 static int lov_io_fault_start(const struct lu_env *env,
889 const struct cl_io_slice *ios)
891 struct cl_fault_io *fio;
893 struct lov_io_sub *sub;
897 fio = &ios->cis_io->u.ci_fault;
898 lio = cl2lov_io(env, ios);
899 sub = lov_sub_get(env, lio, lov_page_index(fio->ft_page));
900 sub->sub_io.u.ci_fault.ft_nob = fio->ft_nob;
902 RETURN(lov_io_start(env, ios));
905 static void lov_io_fsync_end(const struct lu_env *env,
906 const struct cl_io_slice *ios)
908 struct lov_io *lio = cl2lov_io(env, ios);
909 struct lov_io_sub *sub;
910 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
914 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
915 struct cl_io *subio = &sub->sub_io;
917 lov_io_end_wrapper(sub->sub_env, subio);
919 if (subio->ci_result == 0)
920 *written += subio->u.ci_fsync.fi_nr_written;
925 static const struct cl_io_operations lov_io_ops = {
928 .cio_fini = lov_io_fini,
929 .cio_iter_init = lov_io_rw_iter_init,
930 .cio_iter_fini = lov_io_iter_fini,
931 .cio_lock = lov_io_lock,
932 .cio_unlock = lov_io_unlock,
933 .cio_start = lov_io_start,
934 .cio_end = lov_io_end
937 .cio_fini = lov_io_fini,
938 .cio_iter_init = lov_io_rw_iter_init,
939 .cio_iter_fini = lov_io_iter_fini,
940 .cio_lock = lov_io_lock,
941 .cio_unlock = lov_io_unlock,
942 .cio_start = lov_io_start,
943 .cio_end = lov_io_end
946 .cio_fini = lov_io_fini,
947 .cio_iter_init = lov_io_setattr_iter_init,
948 .cio_iter_fini = lov_io_iter_fini,
949 .cio_lock = lov_io_lock,
950 .cio_unlock = lov_io_unlock,
951 .cio_start = lov_io_start,
952 .cio_end = lov_io_end
954 [CIT_DATA_VERSION] = {
955 .cio_fini = lov_io_fini,
956 .cio_iter_init = lov_io_iter_init,
957 .cio_iter_fini = lov_io_iter_fini,
958 .cio_lock = lov_io_lock,
959 .cio_unlock = lov_io_unlock,
960 .cio_start = lov_io_start,
961 .cio_end = lov_io_data_version_end,
964 .cio_fini = lov_io_fini,
965 .cio_iter_init = lov_io_iter_init,
966 .cio_iter_fini = lov_io_iter_fini,
967 .cio_lock = lov_io_lock,
968 .cio_unlock = lov_io_unlock,
969 .cio_start = lov_io_fault_start,
970 .cio_end = lov_io_end
973 .cio_fini = lov_io_fini,
974 .cio_iter_init = lov_io_iter_init,
975 .cio_iter_fini = lov_io_iter_fini,
976 .cio_lock = lov_io_lock,
977 .cio_unlock = lov_io_unlock,
978 .cio_start = lov_io_start,
979 .cio_end = lov_io_fsync_end
982 .cio_fini = lov_io_fini,
983 .cio_iter_init = lov_io_iter_init,
984 .cio_iter_fini = lov_io_iter_fini,
985 .cio_lock = lov_io_lock,
986 .cio_unlock = lov_io_unlock,
987 .cio_start = lov_io_start,
988 .cio_end = lov_io_end
991 .cio_fini = lov_io_fini
994 .cio_read_ahead = lov_io_read_ahead,
995 .cio_submit = lov_io_submit,
996 .cio_commit_async = lov_io_commit_async,
999 /*****************************************************************************
1001 * Empty lov io operations.
1005 static void lov_empty_io_fini(const struct lu_env *env,
1006 const struct cl_io_slice *ios)
1008 struct lov_object *lov = cl2lov(ios->cis_obj);
1011 if (atomic_dec_and_test(&lov->lo_active_ios))
1012 wake_up_all(&lov->lo_waitq);
1016 static int lov_empty_io_submit(const struct lu_env *env,
1017 const struct cl_io_slice *ios,
1018 enum cl_req_type crt, struct cl_2queue *queue)
1023 static void lov_empty_impossible(const struct lu_env *env,
1024 struct cl_io_slice *ios)
1029 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
1032 * An io operation vector for files without stripes.
1034 static const struct cl_io_operations lov_empty_io_ops = {
1037 .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
1046 .cio_fini = lov_empty_io_fini,
1047 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1048 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1049 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1050 .cio_end = LOV_EMPTY_IMPOSSIBLE
1053 .cio_fini = lov_empty_io_fini,
1054 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1055 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1056 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1057 .cio_end = LOV_EMPTY_IMPOSSIBLE
1060 .cio_fini = lov_empty_io_fini,
1061 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1062 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1063 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1064 .cio_end = LOV_EMPTY_IMPOSSIBLE
1067 .cio_fini = lov_empty_io_fini
1070 .cio_fini = lov_empty_io_fini
1073 .cio_fini = lov_empty_io_fini
1076 .cio_submit = lov_empty_io_submit,
1077 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
1080 int lov_io_init_composite(const struct lu_env *env, struct cl_object *obj,
1083 struct lov_io *lio = lov_env_io(env);
1084 struct lov_object *lov = cl2lov(obj);
1087 INIT_LIST_HEAD(&lio->lis_active);
1088 io->ci_result = lov_io_slice_init(lio, lov, io);
1089 if (io->ci_result != 0)
1090 RETURN(io->ci_result);
1092 if (io->ci_result == 0) {
1093 io->ci_result = lov_io_subio_init(env, lio, io);
1094 if (io->ci_result == 0) {
1095 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
1096 atomic_inc(&lov->lo_active_ios);
1099 RETURN(io->ci_result);
1102 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
1105 struct lov_object *lov = cl2lov(obj);
1106 struct lov_io *lio = lov_env_io(env);
1110 lio->lis_object = lov;
1111 switch (io->ci_type) {
1121 case CIT_DATA_VERSION:
1129 CERROR("Page fault on a file without stripes: "DFID"\n",
1130 PFID(lu_object_fid(&obj->co_lu)));
1134 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1135 atomic_inc(&lov->lo_active_ios);
1138 io->ci_result = result < 0 ? result : 0;
1142 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1145 struct lov_object *lov = cl2lov(obj);
1146 struct lov_io *lio = lov_env_io(env);
1150 LASSERT(lov->lo_lsm != NULL);
1151 lio->lis_object = lov;
1153 switch (io->ci_type) {
1155 LASSERTF(0, "invalid type %d\n", io->ci_type);
1156 result = -EOPNOTSUPP;
1161 case CIT_DATA_VERSION:
1165 /* the truncate to 0 is managed by MDT:
1166 * - in open, for open O_TRUNC
1167 * - in setattr, for truncate
1169 /* the truncate is for size > 0 so triggers a restore */
1170 if (cl_io_is_trunc(io)) {
1171 io->ci_restore_needed = 1;
1179 io->ci_restore_needed = 1;
1185 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1186 atomic_inc(&lov->lo_active_ios);
1189 io->ci_result = result < 0 ? result : 0;