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 OSC layer.
34 * Author: Nikita Danilov <nikita.danilov@sun.com>
35 * Author: Jinshan Xiong <jinshan.xiong@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_OSC
40 #include <lustre_obdo.h>
41 #include <lustre_osc.h>
43 #include "osc_internal.h"
49 /*****************************************************************************
55 static void osc_io_fini(const struct lu_env *env, const struct cl_io_slice *io)
59 void osc_read_ahead_release(const struct lu_env *env, void *cbdata)
61 struct ldlm_lock *dlmlock = cbdata;
62 struct lustre_handle lockh;
64 ldlm_lock2handle(dlmlock, &lockh);
65 ldlm_lock_decref(&lockh, LCK_PR);
66 LDLM_LOCK_PUT(dlmlock);
68 EXPORT_SYMBOL(osc_read_ahead_release);
70 static int osc_io_read_ahead(const struct lu_env *env,
71 const struct cl_io_slice *ios,
72 pgoff_t start, struct cl_read_ahead *ra)
74 struct osc_object *osc = cl2osc(ios->cis_obj);
75 struct ldlm_lock *dlmlock;
76 int result = -ENODATA;
79 dlmlock = osc_dlmlock_at_pgoff(env, osc, start, 0);
80 if (dlmlock != NULL) {
81 LASSERT(dlmlock->l_ast_data == osc);
82 if (dlmlock->l_req_mode != LCK_PR) {
83 struct lustre_handle lockh;
84 ldlm_lock2handle(dlmlock, &lockh);
85 ldlm_lock_addref(&lockh, LCK_PR);
86 ldlm_lock_decref(&lockh, dlmlock->l_req_mode);
89 ra->cra_rpc_size = osc_cli(osc)->cl_max_pages_per_rpc;
90 ra->cra_end = cl_index(osc2cl(osc),
91 dlmlock->l_policy_data.l_extent.end);
92 ra->cra_release = osc_read_ahead_release;
93 ra->cra_cbdata = dlmlock;
101 * An implementation of cl_io_operations::cio_io_submit() method for osc
102 * layer. Iterates over pages in the in-queue, prepares each for io by calling
103 * cl_page_prep() and then either submits them through osc_io_submit_page()
104 * or, if page is already submitted, changes osc flags through
105 * osc_set_async_flags().
107 int osc_io_submit(const struct lu_env *env, const struct cl_io_slice *ios,
108 enum cl_req_type crt, struct cl_2queue *queue)
110 struct cl_page *page;
112 struct client_obd *cli = NULL;
113 struct osc_object *osc = NULL; /* to keep gcc happy */
114 struct osc_page *opg;
116 struct list_head list = LIST_HEAD_INIT(list);
118 struct cl_page_list *qin = &queue->c2_qin;
119 struct cl_page_list *qout = &queue->c2_qout;
120 unsigned int queued = 0;
123 unsigned int max_pages;
125 LASSERT(qin->pl_nr > 0);
127 CDEBUG(D_CACHE|D_READA, "%d %d\n", qin->pl_nr, crt);
129 osc = cl2osc(ios->cis_obj);
131 max_pages = cli->cl_max_pages_per_rpc;
133 brw_flags = osc_io_srvlock(cl2osc_io(env, ios)) ? OBD_BRW_SRVLOCK : 0;
134 brw_flags |= crt == CRT_WRITE ? OBD_BRW_WRITE : OBD_BRW_READ;
135 if (crt == CRT_READ && ios->cis_io->ci_ndelay)
136 brw_flags |= OBD_BRW_NDELAY;
139 * NOTE: here @page is a top-level page. This is done to avoid
140 * creation of sub-page-list.
142 cl_page_list_for_each_safe(page, tmp, qin) {
143 struct osc_async_page *oap;
149 opg = osc_cl_page_osc(page, osc);
151 LASSERT(osc == oap->oap_obj);
153 if (!list_empty(&oap->oap_pending_item) ||
154 !list_empty(&oap->oap_rpc_item)) {
155 CDEBUG(D_CACHE, "Busy oap %p page %p for submit.\n",
161 result = cl_page_prep(env, io, page, crt);
164 if (result != -EALREADY)
167 * Handle -EALREADY error: for read case, the page is
168 * already in UPTODATE state; for write, the page
175 spin_lock(&oap->oap_lock);
176 oap->oap_async_flags = ASYNC_URGENT|ASYNC_READY;
177 oap->oap_async_flags |= ASYNC_COUNT_STABLE;
178 spin_unlock(&oap->oap_lock);
180 osc_page_submit(env, opg, crt, brw_flags);
181 list_add_tail(&oap->oap_pending_item, &list);
183 if (page->cp_sync_io != NULL)
184 cl_page_list_move(qout, qin, page);
186 cl_page_list_del(env, qin, page);
188 if (++queued == max_pages) {
190 result = osc_queue_sync_pages(env, io, osc, &list,
198 result = osc_queue_sync_pages(env, io, osc, &list, brw_flags);
200 /* Update c/mtime for sync write. LU-7310 */
201 if (crt == CRT_WRITE && qout->pl_nr > 0 && result == 0) {
202 struct cl_object *obj = ios->cis_obj;
203 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
205 cl_object_attr_lock(obj);
206 attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
207 cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
208 cl_object_attr_unlock(obj);
211 CDEBUG(D_INFO, "%d/%d %d\n", qin->pl_nr, qout->pl_nr, result);
212 return qout->pl_nr > 0 ? 0 : result;
214 EXPORT_SYMBOL(osc_io_submit);
217 * This is called when a page is accessed within file in a way that creates
218 * new page, if one were missing (i.e., if there were a hole at that place in
219 * the file, or accessed page is beyond the current file size).
221 * Expand stripe KMS if necessary.
223 static void osc_page_touch_at(const struct lu_env *env,
224 struct cl_object *obj, pgoff_t idx, size_t to)
226 struct lov_oinfo *loi = cl2osc(obj)->oo_oinfo;
227 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
231 /* offset within stripe */
232 kms = cl_offset(obj, idx) + to;
234 cl_object_attr_lock(obj);
238 * ll_inode_size_lock(inode, 0); lov_stripe_lock(lsm);
242 CDEBUG(D_INODE, "stripe KMS %sincreasing %llu->%llu %llu\n",
243 kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms,
244 loi->loi_lvb.lvb_size);
246 attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
247 valid = CAT_MTIME | CAT_CTIME;
248 if (kms > loi->loi_kms) {
252 if (kms > loi->loi_lvb.lvb_size) {
253 attr->cat_size = kms;
256 cl_object_attr_update(env, obj, attr, valid);
257 cl_object_attr_unlock(obj);
260 int osc_io_commit_async(const struct lu_env *env,
261 const struct cl_io_slice *ios,
262 struct cl_page_list *qin, int from, int to,
265 struct cl_io *io = ios->cis_io;
266 struct osc_io *oio = cl2osc_io(env, ios);
267 struct osc_object *osc = cl2osc(ios->cis_obj);
268 struct cl_page *page;
269 struct cl_page *last_page;
270 struct osc_page *opg;
274 LASSERT(qin->pl_nr > 0);
276 /* Handle partial page cases */
277 last_page = cl_page_list_last(qin);
278 if (oio->oi_lockless) {
279 page = cl_page_list_first(qin);
280 if (page == last_page) {
281 cl_page_clip(env, page, from, to);
284 cl_page_clip(env, page, from, PAGE_SIZE);
286 cl_page_clip(env, last_page, 0, to);
290 while (qin->pl_nr > 0) {
291 struct osc_async_page *oap;
293 page = cl_page_list_first(qin);
294 opg = osc_cl_page_osc(page, osc);
297 if (!list_empty(&oap->oap_rpc_item)) {
298 CDEBUG(D_CACHE, "Busy oap %p page %p for submit.\n",
304 /* The page may be already in dirty cache. */
305 if (list_empty(&oap->oap_pending_item)) {
306 result = osc_page_cache_add(env, &opg->ops_cl, io);
311 osc_page_touch_at(env, osc2cl(osc), osc_index(opg),
312 page == last_page ? to : PAGE_SIZE);
314 cl_page_list_del(env, qin, page);
316 (*cb)(env, io, page);
317 /* Can't access page any more. Page can be in transfer and
318 * complete at any time. */
321 /* for sync write, kernel will wait for this page to be flushed before
322 * osc_io_end() is called, so release it earlier.
323 * for mkwrite(), it's known there is no further pages. */
324 if (cl_io_is_sync_write(io) && oio->oi_active != NULL) {
325 osc_extent_release(env, oio->oi_active);
326 oio->oi_active = NULL;
329 CDEBUG(D_INFO, "%d %d\n", qin->pl_nr, result);
332 EXPORT_SYMBOL(osc_io_commit_async);
334 int osc_io_iter_init(const struct lu_env *env, const struct cl_io_slice *ios)
336 struct osc_object *osc = cl2osc(ios->cis_obj);
337 struct obd_import *imp = osc_cli(osc)->cl_import;
340 spin_lock(&imp->imp_lock);
341 if (likely(!imp->imp_invalid)) {
342 struct osc_io *oio = osc_env_io(env);
344 atomic_inc(&osc->oo_nr_ios);
345 oio->oi_is_active = 1;
348 spin_unlock(&imp->imp_lock);
352 EXPORT_SYMBOL(osc_io_iter_init);
354 int osc_io_write_iter_init(const struct lu_env *env,
355 const struct cl_io_slice *ios)
357 struct cl_io *io = ios->cis_io;
358 struct osc_io *oio = osc_env_io(env);
359 struct osc_object *osc = cl2osc(ios->cis_obj);
360 unsigned long npages;
363 if (cl_io_is_append(io))
364 RETURN(osc_io_iter_init(env, ios));
366 npages = io->u.ci_rw.rw_range.cir_count >> PAGE_SHIFT;
367 if (io->u.ci_rw.rw_range.cir_pos & ~PAGE_MASK)
370 oio->oi_lru_reserved = osc_lru_reserve(osc_cli(osc), npages);
372 RETURN(osc_io_iter_init(env, ios));
374 EXPORT_SYMBOL(osc_io_write_iter_init);
376 void osc_io_iter_fini(const struct lu_env *env,
377 const struct cl_io_slice *ios)
379 struct osc_io *oio = osc_env_io(env);
381 if (oio->oi_is_active) {
382 struct osc_object *osc = cl2osc(ios->cis_obj);
384 oio->oi_is_active = 0;
385 LASSERT(atomic_read(&osc->oo_nr_ios) > 0);
386 if (atomic_dec_and_test(&osc->oo_nr_ios))
387 wake_up_all(&osc->oo_io_waitq);
390 EXPORT_SYMBOL(osc_io_iter_fini);
392 void osc_io_write_iter_fini(const struct lu_env *env,
393 const struct cl_io_slice *ios)
395 struct osc_io *oio = osc_env_io(env);
396 struct osc_object *osc = cl2osc(ios->cis_obj);
398 if (oio->oi_lru_reserved > 0) {
399 osc_lru_unreserve(osc_cli(osc), oio->oi_lru_reserved);
400 oio->oi_lru_reserved = 0;
402 oio->oi_write_osclock = NULL;
404 osc_io_iter_fini(env, ios);
406 EXPORT_SYMBOL(osc_io_write_iter_fini);
408 int osc_io_fault_start(const struct lu_env *env, const struct cl_io_slice *ios)
411 struct cl_fault_io *fio;
415 fio = &io->u.ci_fault;
416 CDEBUG(D_INFO, "%lu %d %zu\n",
417 fio->ft_index, fio->ft_writable, fio->ft_nob);
419 * If mapping is writeable, adjust kms to cover this page,
420 * but do not extend kms beyond actual file size.
423 if (fio->ft_writable)
424 osc_page_touch_at(env, ios->cis_obj,
425 fio->ft_index, fio->ft_nob);
428 EXPORT_SYMBOL(osc_io_fault_start);
431 static int osc_async_upcall(void *a, int rc)
433 struct osc_async_cbargs *args = a;
436 complete(&args->opc_sync);
441 * Checks that there are no pages being written in the extent being truncated.
443 static int trunc_check_cb(const struct lu_env *env, struct cl_io *io,
444 struct osc_page *ops , void *cbdata)
446 struct cl_page *page = ops->ops_cl.cpl_page;
447 struct osc_async_page *oap;
448 __u64 start = *(__u64 *)cbdata;
451 if (oap->oap_cmd & OBD_BRW_WRITE &&
452 !list_empty(&oap->oap_pending_item))
453 CL_PAGE_DEBUG(D_ERROR, env, page, "exists %llu/%s.\n",
454 start, current->comm);
456 if (PageLocked(page->cp_vmpage))
457 CDEBUG(D_CACHE, "page %p index %lu locked for %d.\n",
458 ops, osc_index(ops), oap->oap_cmd & OBD_BRW_RWMASK);
460 return CLP_GANG_OKAY;
463 static void osc_trunc_check(const struct lu_env *env, struct cl_io *io,
464 struct osc_io *oio, __u64 size)
466 struct cl_object *clob;
470 clob = oio->oi_cl.cis_obj;
471 start = cl_index(clob, size);
472 partial = cl_offset(clob, start) < size;
475 * Complain if there are pages in the truncated region.
477 osc_page_gang_lookup(env, io, cl2osc(clob),
478 start + partial, CL_PAGE_EOF,
479 trunc_check_cb, (void *)&size);
482 static int osc_io_setattr_start(const struct lu_env *env,
483 const struct cl_io_slice *slice)
485 struct cl_io *io = slice->cis_io;
486 struct osc_io *oio = cl2osc_io(env, slice);
487 struct cl_object *obj = slice->cis_obj;
488 struct lov_oinfo *loi = cl2osc(obj)->oo_oinfo;
489 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
490 struct obdo *oa = &oio->oi_oa;
491 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
492 __u64 size = io->u.ci_setattr.sa_attr.lvb_size;
493 unsigned int ia_valid = io->u.ci_setattr.sa_valid;
497 /* truncate cache dirty pages first */
498 if (cl_io_is_trunc(io))
499 result = osc_cache_truncate_start(env, cl2osc(obj), size,
502 if (result == 0 && oio->oi_lockless == 0) {
503 cl_object_attr_lock(obj);
504 result = cl_object_attr_get(env, obj, attr);
506 struct ost_lvb *lvb = &io->u.ci_setattr.sa_attr;
507 unsigned int cl_valid = 0;
509 if (ia_valid & ATTR_SIZE) {
510 attr->cat_size = attr->cat_kms = size;
511 cl_valid = (CAT_SIZE | CAT_KMS);
513 if (ia_valid & ATTR_MTIME_SET) {
514 attr->cat_mtime = lvb->lvb_mtime;
515 cl_valid |= CAT_MTIME;
517 if (ia_valid & ATTR_ATIME_SET) {
518 attr->cat_atime = lvb->lvb_atime;
519 cl_valid |= CAT_ATIME;
521 if (ia_valid & ATTR_CTIME_SET) {
522 attr->cat_ctime = lvb->lvb_ctime;
523 cl_valid |= CAT_CTIME;
525 result = cl_object_attr_update(env, obj, attr,
528 cl_object_attr_unlock(obj);
530 memset(oa, 0, sizeof(*oa));
532 oa->o_oi = loi->loi_oi;
533 obdo_set_parent_fid(oa, io->u.ci_setattr.sa_parent_fid);
534 oa->o_stripe_idx = io->u.ci_setattr.sa_stripe_index;
535 oa->o_layout = io->u.ci_setattr.sa_layout;
536 oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP |
538 if (ia_valid & ATTR_CTIME) {
539 oa->o_valid |= OBD_MD_FLCTIME;
540 oa->o_ctime = attr->cat_ctime;
542 if (ia_valid & ATTR_ATIME) {
543 oa->o_valid |= OBD_MD_FLATIME;
544 oa->o_atime = attr->cat_atime;
546 if (ia_valid & ATTR_MTIME) {
547 oa->o_valid |= OBD_MD_FLMTIME;
548 oa->o_mtime = attr->cat_mtime;
550 if (ia_valid & ATTR_SIZE) {
552 oa->o_blocks = OBD_OBJECT_EOF;
553 oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
555 if (oio->oi_lockless) {
556 oa->o_flags = OBD_FL_SRVLOCK;
557 oa->o_valid |= OBD_MD_FLFLAGS;
560 if (io->ci_layout_version > 0) {
561 /* verify layout version */
562 oa->o_valid |= OBD_MD_LAYOUT_VERSION;
563 oa->o_layout_version = io->ci_layout_version;
566 LASSERT(oio->oi_lockless == 0);
569 if (ia_valid & ATTR_ATTR_FLAG) {
570 oa->o_flags = io->u.ci_setattr.sa_attr_flags;
571 oa->o_valid |= OBD_MD_FLFLAGS;
574 init_completion(&cbargs->opc_sync);
576 if (ia_valid & ATTR_SIZE)
577 result = osc_punch_send(osc_export(cl2osc(obj)),
578 oa, osc_async_upcall, cbargs);
580 result = osc_setattr_async(osc_export(cl2osc(obj)),
581 oa, osc_async_upcall,
582 cbargs, PTLRPCD_SET);
584 cbargs->opc_rpc_sent = result == 0;
590 void osc_io_setattr_end(const struct lu_env *env,
591 const struct cl_io_slice *slice)
593 struct cl_io *io = slice->cis_io;
594 struct osc_io *oio = cl2osc_io(env, slice);
595 struct cl_object *obj = slice->cis_obj;
596 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
599 if (cbargs->opc_rpc_sent) {
600 wait_for_completion(&cbargs->opc_sync);
601 result = io->ci_result = cbargs->opc_rc;
604 if (oio->oi_lockless) {
605 /* lockless truncate */
606 struct osc_device *osd = lu2osc_dev(obj->co_lu.lo_dev);
608 LASSERT(cl_io_is_trunc(io));
609 /* XXX: Need a lock. */
610 osd->od_stats.os_lockless_truncates++;
614 if (cl_io_is_trunc(io)) {
615 __u64 size = io->u.ci_setattr.sa_attr.lvb_size;
616 osc_trunc_check(env, io, oio, size);
617 osc_cache_truncate_end(env, oio->oi_trunc);
618 oio->oi_trunc = NULL;
621 EXPORT_SYMBOL(osc_io_setattr_end);
623 struct osc_data_version_args {
624 struct osc_io *dva_oio;
628 osc_data_version_interpret(const struct lu_env *env, struct ptlrpc_request *req,
631 struct osc_data_version_args *dva = arg;
632 struct osc_io *oio = dva->dva_oio;
633 const struct ost_body *body;
639 body = req_capsule_server_get(&req->rq_pill, &RMF_OST_BODY);
641 GOTO(out, rc = -EPROTO);
643 lustre_get_wire_obdo(&req->rq_import->imp_connect_data, &oio->oi_oa,
647 oio->oi_cbarg.opc_rc = rc;
648 complete(&oio->oi_cbarg.opc_sync);
653 static int osc_io_data_version_start(const struct lu_env *env,
654 const struct cl_io_slice *slice)
656 struct cl_data_version_io *dv = &slice->cis_io->u.ci_data_version;
657 struct osc_io *oio = cl2osc_io(env, slice);
658 struct obdo *oa = &oio->oi_oa;
659 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
660 struct osc_object *obj = cl2osc(slice->cis_obj);
661 struct lov_oinfo *loi = obj->oo_oinfo;
662 struct obd_export *exp = osc_export(obj);
663 struct ptlrpc_request *req;
664 struct ost_body *body;
665 struct osc_data_version_args *dva;
669 memset(oa, 0, sizeof(*oa));
670 oa->o_oi = loi->loi_oi;
671 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
673 if (dv->dv_flags & (LL_DV_RD_FLUSH | LL_DV_WR_FLUSH)) {
674 oa->o_valid |= OBD_MD_FLFLAGS;
675 oa->o_flags |= OBD_FL_SRVLOCK;
676 if (dv->dv_flags & LL_DV_WR_FLUSH)
677 oa->o_flags |= OBD_FL_FLUSH;
680 init_completion(&cbargs->opc_sync);
682 req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_OST_GETATTR);
686 rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_GETATTR);
688 ptlrpc_request_free(req);
692 body = req_capsule_client_get(&req->rq_pill, &RMF_OST_BODY);
693 lustre_set_wire_obdo(&req->rq_import->imp_connect_data, &body->oa, oa);
695 ptlrpc_request_set_replen(req);
696 req->rq_interpret_reply = osc_data_version_interpret;
697 CLASSERT(sizeof(*dva) <= sizeof(req->rq_async_args));
698 dva = ptlrpc_req_async_args(req);
701 ptlrpcd_add_req(req);
706 static void osc_io_data_version_end(const struct lu_env *env,
707 const struct cl_io_slice *slice)
709 struct cl_data_version_io *dv = &slice->cis_io->u.ci_data_version;
710 struct osc_io *oio = cl2osc_io(env, slice);
711 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
714 wait_for_completion(&cbargs->opc_sync);
716 if (cbargs->opc_rc != 0) {
717 slice->cis_io->ci_result = cbargs->opc_rc;
718 } else if (!(oio->oi_oa.o_valid & OBD_MD_FLDATAVERSION)) {
719 slice->cis_io->ci_result = -EOPNOTSUPP;
721 dv->dv_data_version = oio->oi_oa.o_data_version;
722 slice->cis_io->ci_result = 0;
728 int osc_io_read_start(const struct lu_env *env,
729 const struct cl_io_slice *slice)
731 struct cl_object *obj = slice->cis_obj;
732 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
736 if (!slice->cis_io->ci_noatime) {
737 cl_object_attr_lock(obj);
738 attr->cat_atime = ktime_get_real_seconds();
739 rc = cl_object_attr_update(env, obj, attr, CAT_ATIME);
740 cl_object_attr_unlock(obj);
745 EXPORT_SYMBOL(osc_io_read_start);
747 int osc_io_write_start(const struct lu_env *env,
748 const struct cl_io_slice *slice)
750 struct cl_object *obj = slice->cis_obj;
751 struct cl_attr *attr = &osc_env_info(env)->oti_attr;
755 OBD_FAIL_TIMEOUT(OBD_FAIL_OSC_DELAY_SETTIME, 1);
756 cl_object_attr_lock(obj);
757 attr->cat_mtime = attr->cat_ctime = ktime_get_real_seconds();
758 rc = cl_object_attr_update(env, obj, attr, CAT_MTIME | CAT_CTIME);
759 cl_object_attr_unlock(obj);
763 EXPORT_SYMBOL(osc_io_write_start);
765 int osc_fsync_ost(const struct lu_env *env, struct osc_object *obj,
766 struct cl_fsync_io *fio)
768 struct osc_io *oio = osc_env_io(env);
769 struct obdo *oa = &oio->oi_oa;
770 struct lov_oinfo *loi = obj->oo_oinfo;
771 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
775 memset(oa, 0, sizeof(*oa));
776 oa->o_oi = loi->loi_oi;
777 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
779 /* reload size abd blocks for start and end of sync range */
780 oa->o_size = fio->fi_start;
781 oa->o_blocks = fio->fi_end;
782 oa->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
784 obdo_set_parent_fid(oa, fio->fi_fid);
786 init_completion(&cbargs->opc_sync);
788 rc = osc_sync_base(obj, oa, osc_async_upcall, cbargs, PTLRPCD_SET);
791 EXPORT_SYMBOL(osc_fsync_ost);
793 int osc_io_fsync_start(const struct lu_env *env,
794 const struct cl_io_slice *slice)
796 struct cl_io *io = slice->cis_io;
797 struct cl_fsync_io *fio = &io->u.ci_fsync;
798 struct cl_object *obj = slice->cis_obj;
799 struct osc_object *osc = cl2osc(obj);
800 pgoff_t start = cl_index(obj, fio->fi_start);
801 pgoff_t end = cl_index(obj, fio->fi_end);
805 if (fio->fi_end == OBD_OBJECT_EOF)
808 result = osc_cache_writeback_range(env, osc, start, end, 0,
809 fio->fi_mode == CL_FSYNC_DISCARD);
811 fio->fi_nr_written += result;
814 if (fio->fi_mode == CL_FSYNC_ALL) {
817 /* we have to wait for writeback to finish before we can
818 * send OST_SYNC RPC. This is bad because it causes extents
819 * to be written osc by osc. However, we usually start
820 * writeback before CL_FSYNC_ALL so this won't have any real
822 rc = osc_cache_wait_range(env, osc, start, end);
825 rc = osc_fsync_ost(env, osc, fio);
833 void osc_io_fsync_end(const struct lu_env *env,
834 const struct cl_io_slice *slice)
836 struct cl_fsync_io *fio = &slice->cis_io->u.ci_fsync;
837 struct cl_object *obj = slice->cis_obj;
838 pgoff_t start = cl_index(obj, fio->fi_start);
839 pgoff_t end = cl_index(obj, fio->fi_end);
842 if (fio->fi_mode == CL_FSYNC_LOCAL) {
843 result = osc_cache_wait_range(env, cl2osc(obj), start, end);
844 } else if (fio->fi_mode == CL_FSYNC_ALL) {
845 struct osc_io *oio = cl2osc_io(env, slice);
846 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
848 wait_for_completion(&cbargs->opc_sync);
850 result = cbargs->opc_rc;
852 slice->cis_io->ci_result = result;
854 EXPORT_SYMBOL(osc_io_fsync_end);
856 static int osc_io_ladvise_start(const struct lu_env *env,
857 const struct cl_io_slice *slice)
860 struct cl_io *io = slice->cis_io;
861 struct osc_io *oio = cl2osc_io(env, slice);
862 struct cl_object *obj = slice->cis_obj;
863 struct lov_oinfo *loi = cl2osc(obj)->oo_oinfo;
864 struct cl_ladvise_io *lio = &io->u.ci_ladvise;
865 struct obdo *oa = &oio->oi_oa;
866 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
867 struct lu_ladvise *ladvise;
868 struct ladvise_hdr *ladvise_hdr;
873 /* TODO: add multiple ladvise support in CLIO */
874 buf_size = offsetof(typeof(*ladvise_hdr), lah_advise[num_advise]);
875 if (osc_env_info(env)->oti_ladvise_buf.lb_len < buf_size)
876 lu_buf_realloc(&osc_env_info(env)->oti_ladvise_buf, buf_size);
878 ladvise_hdr = osc_env_info(env)->oti_ladvise_buf.lb_buf;
879 if (ladvise_hdr == NULL)
882 memset(ladvise_hdr, 0, buf_size);
883 ladvise_hdr->lah_magic = LADVISE_MAGIC;
884 ladvise_hdr->lah_count = num_advise;
885 ladvise_hdr->lah_flags = lio->li_flags;
887 memset(oa, 0, sizeof(*oa));
888 oa->o_oi = loi->loi_oi;
889 oa->o_valid = OBD_MD_FLID;
890 obdo_set_parent_fid(oa, lio->li_fid);
892 ladvise = ladvise_hdr->lah_advise;
893 ladvise->lla_start = lio->li_start;
894 ladvise->lla_end = lio->li_end;
895 ladvise->lla_advice = lio->li_advice;
897 if (lio->li_flags & LF_ASYNC) {
898 result = osc_ladvise_base(osc_export(cl2osc(obj)), oa,
899 ladvise_hdr, NULL, NULL, NULL);
901 init_completion(&cbargs->opc_sync);
902 result = osc_ladvise_base(osc_export(cl2osc(obj)), oa,
903 ladvise_hdr, osc_async_upcall,
904 cbargs, PTLRPCD_SET);
905 cbargs->opc_rpc_sent = result == 0;
910 static void osc_io_ladvise_end(const struct lu_env *env,
911 const struct cl_io_slice *slice)
913 struct cl_io *io = slice->cis_io;
914 struct osc_io *oio = cl2osc_io(env, slice);
915 struct osc_async_cbargs *cbargs = &oio->oi_cbarg;
917 struct cl_ladvise_io *lio = &io->u.ci_ladvise;
919 if ((!(lio->li_flags & LF_ASYNC)) && cbargs->opc_rpc_sent) {
920 wait_for_completion(&cbargs->opc_sync);
921 result = cbargs->opc_rc;
923 slice->cis_io->ci_result = result;
926 void osc_io_end(const struct lu_env *env, const struct cl_io_slice *slice)
928 struct osc_io *oio = cl2osc_io(env, slice);
930 if (oio->oi_active) {
931 osc_extent_release(env, oio->oi_active);
932 oio->oi_active = NULL;
935 EXPORT_SYMBOL(osc_io_end);
937 static const struct cl_io_operations osc_io_ops = {
940 .cio_iter_init = osc_io_iter_init,
941 .cio_iter_fini = osc_io_iter_fini,
942 .cio_start = osc_io_read_start,
943 .cio_fini = osc_io_fini
946 .cio_iter_init = osc_io_write_iter_init,
947 .cio_iter_fini = osc_io_write_iter_fini,
948 .cio_start = osc_io_write_start,
949 .cio_end = osc_io_end,
950 .cio_fini = osc_io_fini
953 .cio_iter_init = osc_io_iter_init,
954 .cio_iter_fini = osc_io_iter_fini,
955 .cio_start = osc_io_setattr_start,
956 .cio_end = osc_io_setattr_end
958 [CIT_DATA_VERSION] = {
959 .cio_start = osc_io_data_version_start,
960 .cio_end = osc_io_data_version_end,
963 .cio_iter_init = osc_io_iter_init,
964 .cio_iter_fini = osc_io_iter_fini,
965 .cio_start = osc_io_fault_start,
966 .cio_end = osc_io_end,
967 .cio_fini = osc_io_fini
970 .cio_start = osc_io_fsync_start,
971 .cio_end = osc_io_fsync_end,
972 .cio_fini = osc_io_fini
975 .cio_start = osc_io_ladvise_start,
976 .cio_end = osc_io_ladvise_end,
977 .cio_fini = osc_io_fini
980 .cio_fini = osc_io_fini
983 .cio_read_ahead = osc_io_read_ahead,
984 .cio_submit = osc_io_submit,
985 .cio_commit_async = osc_io_commit_async
988 /*****************************************************************************
990 * Transfer operations.
994 int osc_io_init(const struct lu_env *env,
995 struct cl_object *obj, struct cl_io *io)
997 struct osc_io *oio = osc_env_io(env);
999 CL_IO_SLICE_CLEAN(oio, oi_cl);
1000 cl_io_slice_add(io, &oio->oi_cl, obj, &osc_io_ops);