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;
408 if (!lu_extent_is_overlapped(&ext, &le->lle_extent))
411 for (stripe = 0; stripe < r0->lo_nr; stripe++) {
412 if (!lov_stripe_intersects(lsm, index - 1, stripe,
416 if (unlikely(r0->lo_sub[stripe] == NULL)) {
417 if (ios->cis_io->ci_type == CIT_READ ||
418 ios->cis_io->ci_type == CIT_WRITE ||
419 ios->cis_io->ci_type == CIT_FAULT)
425 end = lov_offset_mod(end, 1);
426 sub = lov_sub_get(env, lio,
427 lov_comp_index(index - 1, stripe));
433 lov_io_sub_inherit(sub, lio, start, end);
434 rc = cl_io_iter_init(sub->sub_env, &sub->sub_io);
436 cl_io_iter_fini(sub->sub_env, &sub->sub_io);
440 CDEBUG(D_VFSTRACE, "shrink: %d [%llu, %llu)\n",
443 list_add_tail(&sub->sub_linkage, &lio->lis_active);
451 static int lov_io_rw_iter_init(const struct lu_env *env,
452 const struct cl_io_slice *ios)
454 struct lov_io *lio = cl2lov_io(env, ios);
455 struct cl_io *io = ios->cis_io;
456 struct lov_stripe_md_entry *lse;
457 loff_t start = io->u.ci_rw.crw_pos;
462 LASSERT(io->ci_type == CIT_READ || io->ci_type == CIT_WRITE);
465 if (cl_io_is_append(io))
466 RETURN(lov_io_iter_init(env, ios));
468 index = lov_lsm_entry(lio->lis_object->lo_lsm, io->u.ci_rw.crw_pos);
469 if (index < 0) { /* non-existing layout component */
470 if (io->ci_type == CIT_READ) {
471 /* TODO: it needs to detect the next component and
472 * then set the next pos */
475 RETURN(lov_io_iter_init(env, ios));
481 lse = lov_lse(lio->lis_object, index);
483 ssize = lse->lsme_stripe_size;
484 lov_do_div64(start, ssize);
485 next = (start + 1) * ssize;
486 if (next <= start * ssize)
489 LASSERT(io->u.ci_rw.crw_pos >= lse->lsme_extent.e_start);
490 next = min_t(__u64, next, lse->lsme_extent.e_end);
491 next = min_t(loff_t, next, lio->lis_io_endpos);
493 io->ci_continue = next < lio->lis_io_endpos;
494 io->u.ci_rw.crw_count = next - io->u.ci_rw.crw_pos;
495 lio->lis_pos = io->u.ci_rw.crw_pos;
496 lio->lis_endpos = io->u.ci_rw.crw_pos + io->u.ci_rw.crw_count;
498 "stripe: %llu chunk: [%llu, %llu) %llu, %zd\n",
499 (__u64)start, lio->lis_pos, lio->lis_endpos,
500 (__u64)lio->lis_io_endpos, io->u.ci_rw.crw_count);
503 * XXX The following call should be optimized: we know, that
504 * [lio->lis_pos, lio->lis_endpos) intersects with exactly one stripe.
506 RETURN(lov_io_iter_init(env, ios));
509 static int lov_io_call(const struct lu_env *env, struct lov_io *lio,
510 int (*iofunc)(const struct lu_env *, struct cl_io *))
512 struct cl_io *parent = lio->lis_cl.cis_io;
513 struct lov_io_sub *sub;
517 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
518 rc = iofunc(sub->sub_env, &sub->sub_io);
522 if (parent->ci_result == 0)
523 parent->ci_result = sub->sub_io.ci_result;
528 static int lov_io_lock(const struct lu_env *env, const struct cl_io_slice *ios)
531 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_lock));
534 static int lov_io_start(const struct lu_env *env, const struct cl_io_slice *ios)
537 RETURN(lov_io_call(env, cl2lov_io(env, ios), cl_io_start));
540 static int lov_io_end_wrapper(const struct lu_env *env, struct cl_io *io)
544 * It's possible that lov_io_start() wasn't called against this
545 * sub-io, either because previous sub-io failed, or upper layer
548 if (io->ci_state == CIS_IO_GOING)
551 io->ci_state = CIS_IO_FINISHED;
555 static int lov_io_iter_fini_wrapper(const struct lu_env *env, struct cl_io *io)
557 cl_io_iter_fini(env, io);
561 static int lov_io_unlock_wrapper(const struct lu_env *env, struct cl_io *io)
563 cl_io_unlock(env, io);
567 static void lov_io_end(const struct lu_env *env, const struct cl_io_slice *ios)
571 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_end_wrapper);
576 lov_io_data_version_end(const struct lu_env *env, const struct cl_io_slice *ios)
578 struct lov_io *lio = cl2lov_io(env, ios);
579 struct cl_io *parent = lio->lis_cl.cis_io;
580 struct lov_io_sub *sub;
583 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
584 lov_io_end_wrapper(env, &sub->sub_io);
586 parent->u.ci_data_version.dv_data_version +=
587 sub->sub_io.u.ci_data_version.dv_data_version;
589 if (parent->ci_result == 0)
590 parent->ci_result = sub->sub_io.ci_result;
596 static void lov_io_iter_fini(const struct lu_env *env,
597 const struct cl_io_slice *ios)
599 struct lov_io *lio = cl2lov_io(env, ios);
603 rc = lov_io_call(env, lio, lov_io_iter_fini_wrapper);
605 while (!list_empty(&lio->lis_active))
606 list_del_init(lio->lis_active.next);
610 static void lov_io_unlock(const struct lu_env *env,
611 const struct cl_io_slice *ios)
616 rc = lov_io_call(env, cl2lov_io(env, ios), lov_io_unlock_wrapper);
621 static int lov_io_read_ahead(const struct lu_env *env,
622 const struct cl_io_slice *ios,
623 pgoff_t start, struct cl_read_ahead *ra)
625 struct lov_io *lio = cl2lov_io(env, ios);
626 struct lov_object *loo = lio->lis_object;
627 struct cl_object *obj = lov2cl(loo);
628 struct lov_layout_raid0 *r0;
629 struct lov_io_sub *sub;
633 unsigned int pps; /* pages per stripe */
639 offset = cl_offset(obj, start);
640 index = lov_lsm_entry(loo->lo_lsm, offset);
644 stripe = lov_stripe_number(loo->lo_lsm, index, offset);
646 r0 = lov_r0(loo, index);
647 if (unlikely(r0->lo_sub[stripe] == NULL))
650 sub = lov_sub_get(env, lio, lov_comp_index(index, stripe));
652 RETURN(PTR_ERR(sub));
654 lov_stripe_offset(loo->lo_lsm, index, offset, stripe, &suboff);
655 rc = cl_io_read_ahead(sub->sub_env, &sub->sub_io,
656 cl_index(lovsub2cl(r0->lo_sub[stripe]), suboff),
659 CDEBUG(D_READA, DFID " cra_end = %lu, stripes = %d, rc = %d\n",
660 PFID(lu_object_fid(lov2lu(loo))), ra->cra_end, r0->lo_nr, rc);
665 * Adjust the stripe index by layout of raid0. ra->cra_end is the
666 * maximum page index covered by an underlying DLM lock.
667 * This function converts cra_end from stripe level to file level, and
668 * make sure it's not beyond stripe boundary.
670 if (r0->lo_nr == 1) /* single stripe file */
673 /* cra_end is stripe level, convert it into file level */
674 ra_end = ra->cra_end;
675 if (ra_end != CL_PAGE_EOF)
676 ra_end = lov_stripe_pgoff(loo->lo_lsm, index, ra_end, stripe);
678 pps = lov_lse(loo, index)->lsme_stripe_size >> PAGE_SHIFT;
680 CDEBUG(D_READA, DFID " max_index = %lu, pps = %u, index = %u, "
681 "stripe_size = %u, stripe no = %u, start index = %lu\n",
682 PFID(lu_object_fid(lov2lu(loo))), ra_end, pps, index,
683 lov_lse(loo, index)->lsme_stripe_size, stripe, start);
685 /* never exceed the end of the stripe */
686 ra->cra_end = min_t(pgoff_t, ra_end, start + pps - start % pps - 1);
691 * lov implementation of cl_operations::cio_submit() method. It takes a list
692 * of pages in \a queue, splits it into per-stripe sub-lists, invokes
693 * cl_io_submit() on underlying devices to submit sub-lists, and then splices
696 * Major complication of this function is a need to handle memory cleansing:
697 * cl_io_submit() is called to write out pages as a part of VM memory
698 * reclamation, and hence it may not fail due to memory shortages (system
699 * dead-locks otherwise). To deal with this, some resources (sub-lists,
700 * sub-environment, etc.) are allocated per-device on "startup" (i.e., in a
701 * not-memory cleansing context), and in case of memory shortage, these
702 * pre-allocated resources are used by lov_io_submit() under
703 * lov_device::ld_mutex mutex.
705 static int lov_io_submit(const struct lu_env *env,
706 const struct cl_io_slice *ios,
707 enum cl_req_type crt, struct cl_2queue *queue)
709 struct cl_page_list *qin = &queue->c2_qin;
710 struct lov_io *lio = cl2lov_io(env, ios);
711 struct lov_io_sub *sub;
712 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
713 struct cl_page *page;
718 if (lio->lis_nr_subios == 1) {
719 int idx = lio->lis_single_subio_index;
721 sub = lov_sub_get(env, lio, idx);
722 LASSERT(!IS_ERR(sub));
723 LASSERT(sub == &lio->lis_single_subio);
724 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
729 cl_page_list_init(plist);
730 while (qin->pl_nr > 0) {
731 struct cl_2queue *cl2q = &lov_env_info(env)->lti_cl2q;
733 cl_2queue_init(cl2q);
735 page = cl_page_list_first(qin);
736 cl_page_list_move(&cl2q->c2_qin, qin, page);
738 index = lov_page_index(page);
739 while (qin->pl_nr > 0) {
740 page = cl_page_list_first(qin);
741 if (index != lov_page_index(page))
744 cl_page_list_move(&cl2q->c2_qin, qin, page);
747 sub = lov_sub_get(env, lio, index);
749 rc = cl_io_submit_rw(sub->sub_env, &sub->sub_io,
755 cl_page_list_splice(&cl2q->c2_qin, plist);
756 cl_page_list_splice(&cl2q->c2_qout, &queue->c2_qout);
757 cl_2queue_fini(env, cl2q);
763 cl_page_list_splice(plist, qin);
764 cl_page_list_fini(env, plist);
769 static int lov_io_commit_async(const struct lu_env *env,
770 const struct cl_io_slice *ios,
771 struct cl_page_list *queue, int from, int to,
774 struct cl_page_list *plist = &lov_env_info(env)->lti_plist;
775 struct lov_io *lio = cl2lov_io(env, ios);
776 struct lov_io_sub *sub;
777 struct cl_page *page;
781 if (lio->lis_nr_subios == 1) {
782 int idx = lio->lis_single_subio_index;
784 sub = lov_sub_get(env, lio, idx);
785 LASSERT(!IS_ERR(sub));
786 LASSERT(sub == &lio->lis_single_subio);
787 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io, queue,
792 cl_page_list_init(plist);
793 while (queue->pl_nr > 0) {
797 LASSERT(plist->pl_nr == 0);
798 page = cl_page_list_first(queue);
799 cl_page_list_move(plist, queue, page);
801 index = lov_page_index(page);
802 while (queue->pl_nr > 0) {
803 page = cl_page_list_first(queue);
804 if (index != lov_page_index(page))
807 cl_page_list_move(plist, queue, page);
810 if (queue->pl_nr > 0) /* still has more pages */
811 stripe_to = PAGE_SIZE;
813 sub = lov_sub_get(env, lio, index);
815 rc = cl_io_commit_async(sub->sub_env, &sub->sub_io,
816 plist, from, stripe_to, cb);
822 if (plist->pl_nr > 0) /* short write */
828 /* for error case, add the page back into the qin list */
829 LASSERT(ergo(rc == 0, plist->pl_nr == 0));
830 while (plist->pl_nr > 0) {
831 /* error occurred, add the uncommitted pages back into queue */
832 page = cl_page_list_last(plist);
833 cl_page_list_move_head(queue, plist, page);
839 static int lov_io_fault_start(const struct lu_env *env,
840 const struct cl_io_slice *ios)
842 struct cl_fault_io *fio;
844 struct lov_io_sub *sub;
848 fio = &ios->cis_io->u.ci_fault;
849 lio = cl2lov_io(env, ios);
850 sub = lov_sub_get(env, lio, lov_page_index(fio->ft_page));
851 sub->sub_io.u.ci_fault.ft_nob = fio->ft_nob;
853 RETURN(lov_io_start(env, ios));
856 static void lov_io_fsync_end(const struct lu_env *env,
857 const struct cl_io_slice *ios)
859 struct lov_io *lio = cl2lov_io(env, ios);
860 struct lov_io_sub *sub;
861 unsigned int *written = &ios->cis_io->u.ci_fsync.fi_nr_written;
865 list_for_each_entry(sub, &lio->lis_active, sub_linkage) {
866 struct cl_io *subio = &sub->sub_io;
868 lov_io_end_wrapper(sub->sub_env, subio);
870 if (subio->ci_result == 0)
871 *written += subio->u.ci_fsync.fi_nr_written;
876 static const struct cl_io_operations lov_io_ops = {
879 .cio_fini = lov_io_fini,
880 .cio_iter_init = lov_io_rw_iter_init,
881 .cio_iter_fini = lov_io_iter_fini,
882 .cio_lock = lov_io_lock,
883 .cio_unlock = lov_io_unlock,
884 .cio_start = lov_io_start,
885 .cio_end = lov_io_end
888 .cio_fini = lov_io_fini,
889 .cio_iter_init = lov_io_rw_iter_init,
890 .cio_iter_fini = lov_io_iter_fini,
891 .cio_lock = lov_io_lock,
892 .cio_unlock = lov_io_unlock,
893 .cio_start = lov_io_start,
894 .cio_end = lov_io_end
897 .cio_fini = lov_io_fini,
898 .cio_iter_init = lov_io_iter_init,
899 .cio_iter_fini = lov_io_iter_fini,
900 .cio_lock = lov_io_lock,
901 .cio_unlock = lov_io_unlock,
902 .cio_start = lov_io_start,
903 .cio_end = lov_io_end
905 [CIT_DATA_VERSION] = {
906 .cio_fini = lov_io_fini,
907 .cio_iter_init = lov_io_iter_init,
908 .cio_iter_fini = lov_io_iter_fini,
909 .cio_lock = lov_io_lock,
910 .cio_unlock = lov_io_unlock,
911 .cio_start = lov_io_start,
912 .cio_end = lov_io_data_version_end,
915 .cio_fini = lov_io_fini,
916 .cio_iter_init = lov_io_iter_init,
917 .cio_iter_fini = lov_io_iter_fini,
918 .cio_lock = lov_io_lock,
919 .cio_unlock = lov_io_unlock,
920 .cio_start = lov_io_fault_start,
921 .cio_end = lov_io_end
924 .cio_fini = lov_io_fini,
925 .cio_iter_init = lov_io_iter_init,
926 .cio_iter_fini = lov_io_iter_fini,
927 .cio_lock = lov_io_lock,
928 .cio_unlock = lov_io_unlock,
929 .cio_start = lov_io_start,
930 .cio_end = lov_io_fsync_end
933 .cio_fini = lov_io_fini,
934 .cio_iter_init = lov_io_iter_init,
935 .cio_iter_fini = lov_io_iter_fini,
936 .cio_lock = lov_io_lock,
937 .cio_unlock = lov_io_unlock,
938 .cio_start = lov_io_start,
939 .cio_end = lov_io_end
942 .cio_fini = lov_io_fini
945 .cio_read_ahead = lov_io_read_ahead,
946 .cio_submit = lov_io_submit,
947 .cio_commit_async = lov_io_commit_async,
950 /*****************************************************************************
952 * Empty lov io operations.
956 static void lov_empty_io_fini(const struct lu_env *env,
957 const struct cl_io_slice *ios)
959 struct lov_object *lov = cl2lov(ios->cis_obj);
962 if (atomic_dec_and_test(&lov->lo_active_ios))
963 wake_up_all(&lov->lo_waitq);
967 static int lov_empty_io_submit(const struct lu_env *env,
968 const struct cl_io_slice *ios,
969 enum cl_req_type crt, struct cl_2queue *queue)
974 static void lov_empty_impossible(const struct lu_env *env,
975 struct cl_io_slice *ios)
980 #define LOV_EMPTY_IMPOSSIBLE ((void *)lov_empty_impossible)
983 * An io operation vector for files without stripes.
985 static const struct cl_io_operations lov_empty_io_ops = {
988 .cio_fini = lov_empty_io_fini,
990 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
991 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
992 .cio_start = LOV_EMPTY_IMPOSSIBLE,
993 .cio_end = LOV_EMPTY_IMPOSSIBLE
997 .cio_fini = lov_empty_io_fini,
998 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
999 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1000 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1001 .cio_end = LOV_EMPTY_IMPOSSIBLE
1004 .cio_fini = lov_empty_io_fini,
1005 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1006 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1007 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1008 .cio_end = LOV_EMPTY_IMPOSSIBLE
1011 .cio_fini = lov_empty_io_fini,
1012 .cio_iter_init = LOV_EMPTY_IMPOSSIBLE,
1013 .cio_lock = LOV_EMPTY_IMPOSSIBLE,
1014 .cio_start = LOV_EMPTY_IMPOSSIBLE,
1015 .cio_end = LOV_EMPTY_IMPOSSIBLE
1018 .cio_fini = lov_empty_io_fini
1021 .cio_fini = lov_empty_io_fini
1024 .cio_fini = lov_empty_io_fini
1027 .cio_submit = lov_empty_io_submit,
1028 .cio_commit_async = LOV_EMPTY_IMPOSSIBLE
1031 int lov_io_init_composite(const struct lu_env *env, struct cl_object *obj,
1034 struct lov_io *lio = lov_env_io(env);
1035 struct lov_object *lov = cl2lov(obj);
1038 INIT_LIST_HEAD(&lio->lis_active);
1039 io->ci_result = lov_io_slice_init(lio, lov, io);
1040 if (io->ci_result != 0)
1041 RETURN(io->ci_result);
1043 if (io->ci_result == 0) {
1044 io->ci_result = lov_io_subio_init(env, lio, io);
1045 if (io->ci_result == 0) {
1046 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_io_ops);
1047 atomic_inc(&lov->lo_active_ios);
1050 RETURN(io->ci_result);
1053 int lov_io_init_empty(const struct lu_env *env, struct cl_object *obj,
1056 struct lov_object *lov = cl2lov(obj);
1057 struct lov_io *lio = lov_env_io(env);
1061 lio->lis_object = lov;
1062 switch (io->ci_type) {
1072 case CIT_DATA_VERSION:
1080 CERROR("Page fault on a file without stripes: "DFID"\n",
1081 PFID(lu_object_fid(&obj->co_lu)));
1085 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1086 atomic_inc(&lov->lo_active_ios);
1089 io->ci_result = result < 0 ? result : 0;
1093 int lov_io_init_released(const struct lu_env *env, struct cl_object *obj,
1096 struct lov_object *lov = cl2lov(obj);
1097 struct lov_io *lio = lov_env_io(env);
1101 LASSERT(lov->lo_lsm != NULL);
1102 lio->lis_object = lov;
1104 switch (io->ci_type) {
1106 LASSERTF(0, "invalid type %d\n", io->ci_type);
1107 result = -EOPNOTSUPP;
1112 case CIT_DATA_VERSION:
1116 /* the truncate to 0 is managed by MDT:
1117 * - in open, for open O_TRUNC
1118 * - in setattr, for truncate
1120 /* the truncate is for size > 0 so triggers a restore */
1121 if (cl_io_is_trunc(io)) {
1122 io->ci_restore_needed = 1;
1130 io->ci_restore_needed = 1;
1136 cl_io_slice_add(io, &lio->lis_cl, obj, &lov_empty_io_ops);
1137 atomic_inc(&lov->lo_active_ios);
1140 io->ci_result = result < 0 ? result : 0;