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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 #define DEBUG_SUBSYSTEM S_CLASS
43 #include <obd_class.h>
44 #include <obd_support.h>
45 #include <lustre_fid.h>
46 #include <linux/list.h>
47 #include <cl_object.h>
48 #include "cl_internal.h"
50 /*****************************************************************************
56 #define cl_io_for_each(slice, io) \
57 list_for_each_entry((slice), &io->ci_layers, cis_linkage)
58 #define cl_io_for_each_reverse(slice, io) \
59 list_for_each_entry_reverse((slice), &io->ci_layers, cis_linkage)
61 static inline int cl_io_type_is_valid(enum cl_io_type type
)
63 return CIT_READ
<= type
&& type
< CIT_OP_NR
;
66 static inline int cl_io_is_loopable(const struct cl_io
*io
)
68 return cl_io_type_is_valid(io
->ci_type
) && io
->ci_type
!= CIT_MISC
;
72 * Returns true iff there is an IO ongoing in the given environment.
74 int cl_io_is_going(const struct lu_env
*env
)
76 return cl_env_info(env
)->clt_current_io
!= NULL
;
78 EXPORT_SYMBOL(cl_io_is_going
);
81 * cl_io invariant that holds at all times when exported cl_io_*() functions
82 * are entered and left.
84 static int cl_io_invariant(const struct cl_io
*io
)
91 * io can own pages only when it is ongoing. Sub-io might
92 * still be in CIS_LOCKED state when top-io is in
95 ergo(io
->ci_owned_nr
> 0, io
->ci_state
== CIS_IO_GOING
||
96 (io
->ci_state
== CIS_LOCKED
&& up
!= NULL
));
100 * Finalize \a io, by calling cl_io_operations::cio_fini() bottom-to-top.
102 void cl_io_fini(const struct lu_env
*env
, struct cl_io
*io
)
104 struct cl_io_slice
*slice
;
105 struct cl_thread_info
*info
;
107 LINVRNT(cl_io_type_is_valid(io
->ci_type
));
108 LINVRNT(cl_io_invariant(io
));
110 while (!list_empty(&io
->ci_layers
)) {
111 slice
= container_of(io
->ci_layers
.prev
, struct cl_io_slice
,
113 list_del_init(&slice
->cis_linkage
);
114 if (slice
->cis_iop
->op
[io
->ci_type
].cio_fini
!= NULL
)
115 slice
->cis_iop
->op
[io
->ci_type
].cio_fini(env
, slice
);
117 * Invalidate slice to catch use after free. This assumes that
118 * slices are allocated within session and can be touched
119 * after ->cio_fini() returns.
121 slice
->cis_io
= NULL
;
123 io
->ci_state
= CIS_FINI
;
124 info
= cl_env_info(env
);
125 if (info
->clt_current_io
== io
)
126 info
->clt_current_io
= NULL
;
128 /* sanity check for layout change */
129 switch(io
->ci_type
) {
135 LASSERT(!io
->ci_need_restart
);
139 /* Check ignore layout change conf */
140 LASSERT(ergo(io
->ci_ignore_layout
|| !io
->ci_verify_layout
,
141 !io
->ci_need_restart
));
148 EXPORT_SYMBOL(cl_io_fini
);
150 static int cl_io_init0(const struct lu_env
*env
, struct cl_io
*io
,
151 enum cl_io_type iot
, struct cl_object
*obj
)
153 struct cl_object
*scan
;
156 LINVRNT(io
->ci_state
== CIS_ZERO
|| io
->ci_state
== CIS_FINI
);
157 LINVRNT(cl_io_type_is_valid(iot
));
158 LINVRNT(cl_io_invariant(io
));
161 INIT_LIST_HEAD(&io
->ci_lockset
.cls_todo
);
162 INIT_LIST_HEAD(&io
->ci_lockset
.cls_curr
);
163 INIT_LIST_HEAD(&io
->ci_lockset
.cls_done
);
164 INIT_LIST_HEAD(&io
->ci_layers
);
167 cl_object_for_each(scan
, obj
) {
168 if (scan
->co_ops
->coo_io_init
!= NULL
) {
169 result
= scan
->co_ops
->coo_io_init(env
, scan
, io
);
175 io
->ci_state
= CIS_INIT
;
180 * Initialize sub-io, by calling cl_io_operations::cio_init() top-to-bottom.
182 * \pre obj != cl_object_top(obj)
184 int cl_io_sub_init(const struct lu_env
*env
, struct cl_io
*io
,
185 enum cl_io_type iot
, struct cl_object
*obj
)
187 struct cl_thread_info
*info
= cl_env_info(env
);
189 LASSERT(obj
!= cl_object_top(obj
));
190 if (info
->clt_current_io
== NULL
)
191 info
->clt_current_io
= io
;
192 return cl_io_init0(env
, io
, iot
, obj
);
194 EXPORT_SYMBOL(cl_io_sub_init
);
197 * Initialize \a io, by calling cl_io_operations::cio_init() top-to-bottom.
199 * Caller has to call cl_io_fini() after a call to cl_io_init(), no matter
200 * what the latter returned.
202 * \pre obj == cl_object_top(obj)
203 * \pre cl_io_type_is_valid(iot)
204 * \post cl_io_type_is_valid(io->ci_type) && io->ci_type == iot
206 int cl_io_init(const struct lu_env
*env
, struct cl_io
*io
,
207 enum cl_io_type iot
, struct cl_object
*obj
)
209 struct cl_thread_info
*info
= cl_env_info(env
);
211 LASSERT(obj
== cl_object_top(obj
));
212 LASSERT(info
->clt_current_io
== NULL
);
214 info
->clt_current_io
= io
;
215 return cl_io_init0(env
, io
, iot
, obj
);
217 EXPORT_SYMBOL(cl_io_init
);
220 * Initialize read or write io.
222 * \pre iot == CIT_READ || iot == CIT_WRITE
224 int cl_io_rw_init(const struct lu_env
*env
, struct cl_io
*io
,
225 enum cl_io_type iot
, loff_t pos
, size_t count
)
227 LINVRNT(iot
== CIT_READ
|| iot
== CIT_WRITE
);
228 LINVRNT(io
->ci_obj
!= NULL
);
230 LU_OBJECT_HEADER(D_VFSTRACE
, env
, &io
->ci_obj
->co_lu
,
231 "io range: %u ["LPU64
", "LPU64
") %u %u\n",
232 iot
, (__u64
)pos
, (__u64
)pos
+ count
,
233 io
->u
.ci_rw
.crw_nonblock
, io
->u
.ci_wr
.wr_append
);
234 io
->u
.ci_rw
.crw_pos
= pos
;
235 io
->u
.ci_rw
.crw_count
= count
;
236 RETURN(cl_io_init(env
, io
, iot
, io
->ci_obj
));
238 EXPORT_SYMBOL(cl_io_rw_init
);
240 static inline const struct lu_fid
*
241 cl_lock_descr_fid(const struct cl_lock_descr
*descr
)
243 return lu_object_fid(&descr
->cld_obj
->co_lu
);
246 static int cl_lock_descr_sort(const struct cl_lock_descr
*d0
,
247 const struct cl_lock_descr
*d1
)
249 return lu_fid_cmp(cl_lock_descr_fid(d0
), cl_lock_descr_fid(d1
)) ?:
250 __diff_normalize(d0
->cld_start
, d1
->cld_start
);
253 static int cl_lock_descr_cmp(const struct cl_lock_descr
*d0
,
254 const struct cl_lock_descr
*d1
)
258 ret
= lu_fid_cmp(cl_lock_descr_fid(d0
), cl_lock_descr_fid(d1
));
261 if (d0
->cld_end
< d1
->cld_start
)
263 if (d0
->cld_start
> d0
->cld_end
)
268 static void cl_lock_descr_merge(struct cl_lock_descr
*d0
,
269 const struct cl_lock_descr
*d1
)
271 d0
->cld_start
= min(d0
->cld_start
, d1
->cld_start
);
272 d0
->cld_end
= max(d0
->cld_end
, d1
->cld_end
);
274 if (d1
->cld_mode
== CLM_WRITE
&& d0
->cld_mode
!= CLM_WRITE
)
275 d0
->cld_mode
= CLM_WRITE
;
277 if (d1
->cld_mode
== CLM_GROUP
&& d0
->cld_mode
!= CLM_GROUP
)
278 d0
->cld_mode
= CLM_GROUP
;
282 * Sort locks in lexicographical order of their (fid, start-offset) pairs.
284 static void cl_io_locks_sort(struct cl_io
*io
)
288 /* hidden treasure: bubble sort for now. */
290 struct cl_io_lock_link
*curr
;
291 struct cl_io_lock_link
*prev
;
292 struct cl_io_lock_link
*temp
;
297 list_for_each_entry_safe(curr
, temp
,
298 &io
->ci_lockset
.cls_todo
,
301 switch (cl_lock_descr_sort(&prev
->cill_descr
,
302 &curr
->cill_descr
)) {
305 * IMPOSSIBLE: Identical locks are
312 list_move_tail(&curr
->cill_linkage
,
313 &prev
->cill_linkage
);
315 continue; /* don't change prev: it's
316 * still "previous" */
317 case -1: /* already in order */
328 * Check whether \a queue contains locks matching \a need.
330 * \retval +ve there is a matching lock in the \a queue
331 * \retval 0 there are no matching locks in the \a queue
333 int cl_queue_match(const struct list_head
*queue
,
334 const struct cl_lock_descr
*need
)
336 struct cl_io_lock_link
*scan
;
338 list_for_each_entry(scan
, queue
, cill_linkage
) {
339 if (cl_lock_descr_match(&scan
->cill_descr
, need
))
344 EXPORT_SYMBOL(cl_queue_match
);
346 static int cl_queue_merge(const struct list_head
*queue
,
347 const struct cl_lock_descr
*need
)
349 struct cl_io_lock_link
*scan
;
351 list_for_each_entry(scan
, queue
, cill_linkage
) {
352 if (cl_lock_descr_cmp(&scan
->cill_descr
, need
))
354 cl_lock_descr_merge(&scan
->cill_descr
, need
);
355 CDEBUG(D_VFSTRACE
, "lock: %d: [%lu, %lu]\n",
356 scan
->cill_descr
.cld_mode
, scan
->cill_descr
.cld_start
,
357 scan
->cill_descr
.cld_end
);
364 static int cl_lockset_match(const struct cl_lockset
*set
,
365 const struct cl_lock_descr
*need
)
367 return cl_queue_match(&set
->cls_curr
, need
) ||
368 cl_queue_match(&set
->cls_done
, need
);
371 static int cl_lockset_merge(const struct cl_lockset
*set
,
372 const struct cl_lock_descr
*need
)
374 return cl_queue_merge(&set
->cls_todo
, need
) ||
375 cl_lockset_match(set
, need
);
378 static int cl_lockset_lock_one(const struct lu_env
*env
,
379 struct cl_io
*io
, struct cl_lockset
*set
,
380 struct cl_io_lock_link
*link
)
382 struct cl_lock
*lock
;
385 lock
= cl_lock_request(env
, io
, &link
->cill_descr
, "io", io
);
388 link
->cill_lock
= lock
;
389 list_move(&link
->cill_linkage
, &set
->cls_curr
);
390 if (!(link
->cill_descr
.cld_enq_flags
& CEF_ASYNC
)) {
391 result
= cl_wait(env
, lock
);
393 list_move(&link
->cill_linkage
,
398 result
= PTR_ERR(lock
);
402 static void cl_lock_link_fini(const struct lu_env
*env
, struct cl_io
*io
,
403 struct cl_io_lock_link
*link
)
405 struct cl_lock
*lock
= link
->cill_lock
;
407 list_del_init(&link
->cill_linkage
);
409 cl_lock_release(env
, lock
, "io", io
);
410 link
->cill_lock
= NULL
;
412 if (link
->cill_fini
!= NULL
)
413 link
->cill_fini(env
, link
);
417 static int cl_lockset_lock(const struct lu_env
*env
, struct cl_io
*io
,
418 struct cl_lockset
*set
)
420 struct cl_io_lock_link
*link
;
421 struct cl_io_lock_link
*temp
;
422 struct cl_lock
*lock
;
426 list_for_each_entry_safe(link
, temp
, &set
->cls_todo
, cill_linkage
) {
427 if (!cl_lockset_match(set
, &link
->cill_descr
)) {
428 /* XXX some locking to guarantee that locks aren't
429 * expanded in between. */
430 result
= cl_lockset_lock_one(env
, io
, set
, link
);
434 cl_lock_link_fini(env
, io
, link
);
437 list_for_each_entry_safe(link
, temp
,
438 &set
->cls_curr
, cill_linkage
) {
439 lock
= link
->cill_lock
;
440 result
= cl_wait(env
, lock
);
442 list_move(&link
->cill_linkage
,
452 * Takes locks necessary for the current iteration of io.
454 * Calls cl_io_operations::cio_lock() top-to-bottom to collect locks required
455 * by layers for the current iteration. Then sort locks (to avoid dead-locks),
458 int cl_io_lock(const struct lu_env
*env
, struct cl_io
*io
)
460 const struct cl_io_slice
*scan
;
463 LINVRNT(cl_io_is_loopable(io
));
464 LINVRNT(io
->ci_state
== CIS_IT_STARTED
);
465 LINVRNT(cl_io_invariant(io
));
467 cl_io_for_each(scan
, io
) {
468 if (scan
->cis_iop
->op
[io
->ci_type
].cio_lock
== NULL
)
470 result
= scan
->cis_iop
->op
[io
->ci_type
].cio_lock(env
, scan
);
475 cl_io_locks_sort(io
);
476 result
= cl_lockset_lock(env
, io
, &io
->ci_lockset
);
479 cl_io_unlock(env
, io
);
481 io
->ci_state
= CIS_LOCKED
;
484 EXPORT_SYMBOL(cl_io_lock
);
487 * Release locks takes by io.
489 void cl_io_unlock(const struct lu_env
*env
, struct cl_io
*io
)
491 struct cl_lockset
*set
;
492 struct cl_io_lock_link
*link
;
493 struct cl_io_lock_link
*temp
;
494 const struct cl_io_slice
*scan
;
496 LASSERT(cl_io_is_loopable(io
));
497 LASSERT(CIS_IT_STARTED
<= io
->ci_state
&& io
->ci_state
< CIS_UNLOCKED
);
498 LINVRNT(cl_io_invariant(io
));
500 set
= &io
->ci_lockset
;
502 list_for_each_entry_safe(link
, temp
, &set
->cls_todo
, cill_linkage
)
503 cl_lock_link_fini(env
, io
, link
);
505 list_for_each_entry_safe(link
, temp
, &set
->cls_curr
, cill_linkage
)
506 cl_lock_link_fini(env
, io
, link
);
508 list_for_each_entry_safe(link
, temp
, &set
->cls_done
, cill_linkage
) {
509 cl_unuse(env
, link
->cill_lock
);
510 cl_lock_link_fini(env
, io
, link
);
512 cl_io_for_each_reverse(scan
, io
) {
513 if (scan
->cis_iop
->op
[io
->ci_type
].cio_unlock
!= NULL
)
514 scan
->cis_iop
->op
[io
->ci_type
].cio_unlock(env
, scan
);
516 io
->ci_state
= CIS_UNLOCKED
;
517 LASSERT(!cl_env_info(env
)->clt_counters
[CNL_TOP
].ctc_nr_locks_acquired
);
520 EXPORT_SYMBOL(cl_io_unlock
);
523 * Prepares next iteration of io.
525 * Calls cl_io_operations::cio_iter_init() top-to-bottom. This exists to give
526 * layers a chance to modify io parameters, e.g., so that lov can restrict io
527 * to a single stripe.
529 int cl_io_iter_init(const struct lu_env
*env
, struct cl_io
*io
)
531 const struct cl_io_slice
*scan
;
534 LINVRNT(cl_io_is_loopable(io
));
535 LINVRNT(io
->ci_state
== CIS_INIT
|| io
->ci_state
== CIS_IT_ENDED
);
536 LINVRNT(cl_io_invariant(io
));
539 cl_io_for_each(scan
, io
) {
540 if (scan
->cis_iop
->op
[io
->ci_type
].cio_iter_init
== NULL
)
542 result
= scan
->cis_iop
->op
[io
->ci_type
].cio_iter_init(env
,
548 io
->ci_state
= CIS_IT_STARTED
;
551 EXPORT_SYMBOL(cl_io_iter_init
);
554 * Finalizes io iteration.
556 * Calls cl_io_operations::cio_iter_fini() bottom-to-top.
558 void cl_io_iter_fini(const struct lu_env
*env
, struct cl_io
*io
)
560 const struct cl_io_slice
*scan
;
562 LINVRNT(cl_io_is_loopable(io
));
563 LINVRNT(io
->ci_state
== CIS_UNLOCKED
);
564 LINVRNT(cl_io_invariant(io
));
566 cl_io_for_each_reverse(scan
, io
) {
567 if (scan
->cis_iop
->op
[io
->ci_type
].cio_iter_fini
!= NULL
)
568 scan
->cis_iop
->op
[io
->ci_type
].cio_iter_fini(env
, scan
);
570 io
->ci_state
= CIS_IT_ENDED
;
573 EXPORT_SYMBOL(cl_io_iter_fini
);
576 * Records that read or write io progressed \a nob bytes forward.
578 void cl_io_rw_advance(const struct lu_env
*env
, struct cl_io
*io
, size_t nob
)
580 const struct cl_io_slice
*scan
;
582 LINVRNT(io
->ci_type
== CIT_READ
|| io
->ci_type
== CIT_WRITE
||
584 LINVRNT(cl_io_is_loopable(io
));
585 LINVRNT(cl_io_invariant(io
));
587 io
->u
.ci_rw
.crw_pos
+= nob
;
588 io
->u
.ci_rw
.crw_count
-= nob
;
590 /* layers have to be notified. */
591 cl_io_for_each_reverse(scan
, io
) {
592 if (scan
->cis_iop
->op
[io
->ci_type
].cio_advance
!= NULL
)
593 scan
->cis_iop
->op
[io
->ci_type
].cio_advance(env
, scan
,
598 EXPORT_SYMBOL(cl_io_rw_advance
);
601 * Adds a lock to a lockset.
603 int cl_io_lock_add(const struct lu_env
*env
, struct cl_io
*io
,
604 struct cl_io_lock_link
*link
)
608 if (cl_lockset_merge(&io
->ci_lockset
, &link
->cill_descr
))
611 list_add(&link
->cill_linkage
, &io
->ci_lockset
.cls_todo
);
616 EXPORT_SYMBOL(cl_io_lock_add
);
618 static void cl_free_io_lock_link(const struct lu_env
*env
,
619 struct cl_io_lock_link
*link
)
625 * Allocates new lock link, and uses it to add a lock to a lockset.
627 int cl_io_lock_alloc_add(const struct lu_env
*env
, struct cl_io
*io
,
628 struct cl_lock_descr
*descr
)
630 struct cl_io_lock_link
*link
;
635 link
->cill_descr
= *descr
;
636 link
->cill_fini
= cl_free_io_lock_link
;
637 result
= cl_io_lock_add(env
, io
, link
);
638 if (result
) /* lock match */
639 link
->cill_fini(env
, link
);
645 EXPORT_SYMBOL(cl_io_lock_alloc_add
);
648 * Starts io by calling cl_io_operations::cio_start() top-to-bottom.
650 int cl_io_start(const struct lu_env
*env
, struct cl_io
*io
)
652 const struct cl_io_slice
*scan
;
655 LINVRNT(cl_io_is_loopable(io
));
656 LINVRNT(io
->ci_state
== CIS_LOCKED
);
657 LINVRNT(cl_io_invariant(io
));
659 io
->ci_state
= CIS_IO_GOING
;
660 cl_io_for_each(scan
, io
) {
661 if (scan
->cis_iop
->op
[io
->ci_type
].cio_start
== NULL
)
663 result
= scan
->cis_iop
->op
[io
->ci_type
].cio_start(env
, scan
);
671 EXPORT_SYMBOL(cl_io_start
);
674 * Wait until current io iteration is finished by calling
675 * cl_io_operations::cio_end() bottom-to-top.
677 void cl_io_end(const struct lu_env
*env
, struct cl_io
*io
)
679 const struct cl_io_slice
*scan
;
681 LINVRNT(cl_io_is_loopable(io
));
682 LINVRNT(io
->ci_state
== CIS_IO_GOING
);
683 LINVRNT(cl_io_invariant(io
));
685 cl_io_for_each_reverse(scan
, io
) {
686 if (scan
->cis_iop
->op
[io
->ci_type
].cio_end
!= NULL
)
687 scan
->cis_iop
->op
[io
->ci_type
].cio_end(env
, scan
);
688 /* TODO: error handling. */
690 io
->ci_state
= CIS_IO_FINISHED
;
693 EXPORT_SYMBOL(cl_io_end
);
695 static const struct cl_page_slice
*
696 cl_io_slice_page(const struct cl_io_slice
*ios
, struct cl_page
*page
)
698 const struct cl_page_slice
*slice
;
700 slice
= cl_page_at(page
, ios
->cis_obj
->co_lu
.lo_dev
->ld_type
);
701 LINVRNT(slice
!= NULL
);
706 * True iff \a page is within \a io range.
708 static int cl_page_in_io(const struct cl_page
*page
, const struct cl_io
*io
)
715 idx
= page
->cp_index
;
716 switch (io
->ci_type
) {
720 * check that [start, end) and [pos, pos + count) extents
723 if (!cl_io_is_append(io
)) {
724 const struct cl_io_rw_common
*crw
= &(io
->u
.ci_rw
);
725 start
= cl_offset(page
->cp_obj
, idx
);
726 end
= cl_offset(page
->cp_obj
, idx
+ 1);
727 result
= crw
->crw_pos
< end
&&
728 start
< crw
->crw_pos
+ crw
->crw_count
;
732 result
= io
->u
.ci_fault
.ft_index
== idx
;
741 * Called by read io, when page has to be read from the server.
743 * \see cl_io_operations::cio_read_page()
745 int cl_io_read_page(const struct lu_env
*env
, struct cl_io
*io
,
746 struct cl_page
*page
)
748 const struct cl_io_slice
*scan
;
749 struct cl_2queue
*queue
;
752 LINVRNT(io
->ci_type
== CIT_READ
|| io
->ci_type
== CIT_FAULT
);
753 LINVRNT(cl_page_is_owned(page
, io
));
754 LINVRNT(io
->ci_state
== CIS_IO_GOING
|| io
->ci_state
== CIS_LOCKED
);
755 LINVRNT(cl_page_in_io(page
, io
));
756 LINVRNT(cl_io_invariant(io
));
758 queue
= &io
->ci_queue
;
760 cl_2queue_init(queue
);
762 * ->cio_read_page() methods called in the loop below are supposed to
763 * never block waiting for network (the only subtle point is the
764 * creation of new pages for read-ahead that might result in cache
765 * shrinking, but currently only clean pages are shrunk and this
766 * requires no network io).
768 * Should this ever starts blocking, retry loop would be needed for
769 * "parallel io" (see CLO_REPEAT loops in cl_lock.c).
771 cl_io_for_each(scan
, io
) {
772 if (scan
->cis_iop
->cio_read_page
!= NULL
) {
773 const struct cl_page_slice
*slice
;
775 slice
= cl_io_slice_page(scan
, page
);
776 LINVRNT(slice
!= NULL
);
777 result
= scan
->cis_iop
->cio_read_page(env
, scan
, slice
);
783 result
= cl_io_submit_rw(env
, io
, CRT_READ
, queue
);
785 * Unlock unsent pages in case of error.
787 cl_page_list_disown(env
, io
, &queue
->c2_qin
);
788 cl_2queue_fini(env
, queue
);
791 EXPORT_SYMBOL(cl_io_read_page
);
794 * Called by write io to prepare page to receive data from user buffer.
796 * \see cl_io_operations::cio_prepare_write()
798 int cl_io_prepare_write(const struct lu_env
*env
, struct cl_io
*io
,
799 struct cl_page
*page
, unsigned from
, unsigned to
)
801 const struct cl_io_slice
*scan
;
804 LINVRNT(io
->ci_type
== CIT_WRITE
);
805 LINVRNT(cl_page_is_owned(page
, io
));
806 LINVRNT(io
->ci_state
== CIS_IO_GOING
|| io
->ci_state
== CIS_LOCKED
);
807 LINVRNT(cl_io_invariant(io
));
808 LASSERT(cl_page_in_io(page
, io
));
810 cl_io_for_each_reverse(scan
, io
) {
811 if (scan
->cis_iop
->cio_prepare_write
!= NULL
) {
812 const struct cl_page_slice
*slice
;
814 slice
= cl_io_slice_page(scan
, page
);
815 result
= scan
->cis_iop
->cio_prepare_write(env
, scan
,
824 EXPORT_SYMBOL(cl_io_prepare_write
);
827 * Called by write io after user data were copied into a page.
829 * \see cl_io_operations::cio_commit_write()
831 int cl_io_commit_write(const struct lu_env
*env
, struct cl_io
*io
,
832 struct cl_page
*page
, unsigned from
, unsigned to
)
834 const struct cl_io_slice
*scan
;
837 LINVRNT(io
->ci_type
== CIT_WRITE
);
838 LINVRNT(io
->ci_state
== CIS_IO_GOING
|| io
->ci_state
== CIS_LOCKED
);
839 LINVRNT(cl_io_invariant(io
));
841 * XXX Uh... not nice. Top level cl_io_commit_write() call (vvp->lov)
842 * already called cl_page_cache_add(), moving page into CPS_CACHED
843 * state. Better (and more general) way of dealing with such situation
846 LASSERT(cl_page_is_owned(page
, io
) || page
->cp_parent
!= NULL
);
847 LASSERT(cl_page_in_io(page
, io
));
849 cl_io_for_each(scan
, io
) {
850 if (scan
->cis_iop
->cio_commit_write
!= NULL
) {
851 const struct cl_page_slice
*slice
;
853 slice
= cl_io_slice_page(scan
, page
);
854 result
= scan
->cis_iop
->cio_commit_write(env
, scan
,
861 LINVRNT(result
<= 0);
864 EXPORT_SYMBOL(cl_io_commit_write
);
867 * Submits a list of pages for immediate io.
869 * After the function gets returned, The submitted pages are moved to
870 * queue->c2_qout queue, and queue->c2_qin contain both the pages don't need
871 * to be submitted, and the pages are errant to submit.
873 * \returns 0 if at least one page was submitted, error code otherwise.
874 * \see cl_io_operations::cio_submit()
876 int cl_io_submit_rw(const struct lu_env
*env
, struct cl_io
*io
,
877 enum cl_req_type crt
, struct cl_2queue
*queue
)
879 const struct cl_io_slice
*scan
;
882 LINVRNT(crt
< ARRAY_SIZE(scan
->cis_iop
->req_op
));
884 cl_io_for_each(scan
, io
) {
885 if (scan
->cis_iop
->req_op
[crt
].cio_submit
== NULL
)
887 result
= scan
->cis_iop
->req_op
[crt
].cio_submit(env
, scan
, crt
,
893 * If ->cio_submit() failed, no pages were sent.
895 LASSERT(ergo(result
!= 0, list_empty(&queue
->c2_qout
.pl_pages
)));
898 EXPORT_SYMBOL(cl_io_submit_rw
);
901 * Submit a sync_io and wait for the IO to be finished, or error happens.
902 * If \a timeout is zero, it means to wait for the IO unconditionally.
904 int cl_io_submit_sync(const struct lu_env
*env
, struct cl_io
*io
,
905 enum cl_req_type iot
, struct cl_2queue
*queue
,
908 struct cl_sync_io
*anchor
= &cl_env_info(env
)->clt_anchor
;
912 cl_page_list_for_each(pg
, &queue
->c2_qin
) {
913 LASSERT(pg
->cp_sync_io
== NULL
);
914 pg
->cp_sync_io
= anchor
;
917 cl_sync_io_init(anchor
, queue
->c2_qin
.pl_nr
);
918 rc
= cl_io_submit_rw(env
, io
, iot
, queue
);
921 * If some pages weren't sent for any reason (e.g.,
922 * read found up-to-date pages in the cache, or write found
923 * clean pages), count them as completed to avoid infinite
926 cl_page_list_for_each(pg
, &queue
->c2_qin
) {
927 pg
->cp_sync_io
= NULL
;
928 cl_sync_io_note(anchor
, +1);
931 /* wait for the IO to be finished. */
932 rc
= cl_sync_io_wait(env
, io
, &queue
->c2_qout
,
935 LASSERT(list_empty(&queue
->c2_qout
.pl_pages
));
936 cl_page_list_for_each(pg
, &queue
->c2_qin
)
937 pg
->cp_sync_io
= NULL
;
941 EXPORT_SYMBOL(cl_io_submit_sync
);
944 * Cancel an IO which has been submitted by cl_io_submit_rw.
946 int cl_io_cancel(const struct lu_env
*env
, struct cl_io
*io
,
947 struct cl_page_list
*queue
)
949 struct cl_page
*page
;
952 CERROR("Canceling ongoing page trasmission\n");
953 cl_page_list_for_each(page
, queue
) {
956 LINVRNT(cl_page_in_io(page
, io
));
957 rc
= cl_page_cancel(env
, page
);
958 result
= result
?: rc
;
962 EXPORT_SYMBOL(cl_io_cancel
);
967 * Pumps io through iterations calling
969 * - cl_io_iter_init()
979 * - cl_io_iter_fini()
981 * repeatedly until there is no more io to do.
983 int cl_io_loop(const struct lu_env
*env
, struct cl_io
*io
)
987 LINVRNT(cl_io_is_loopable(io
));
993 result
= cl_io_iter_init(env
, io
);
996 result
= cl_io_lock(env
, io
);
999 * Notify layers that locks has been taken,
1000 * and do actual i/o.
1002 * - llite: kms, short read;
1003 * - llite: generic_file_read();
1005 result
= cl_io_start(env
, io
);
1007 * Send any remaining pending
1010 * - llite: ll_rw_stats_tally.
1013 cl_io_unlock(env
, io
);
1014 cl_io_rw_advance(env
, io
, io
->ci_nob
- nob
);
1017 cl_io_iter_fini(env
, io
);
1018 } while (result
== 0 && io
->ci_continue
);
1020 result
= io
->ci_result
;
1021 RETURN(result
< 0 ? result
: 0);
1023 EXPORT_SYMBOL(cl_io_loop
);
1026 * Adds io slice to the cl_io.
1028 * This is called by cl_object_operations::coo_io_init() methods to add a
1029 * per-layer state to the io. New state is added at the end of
1030 * cl_io::ci_layers list, that is, it is at the bottom of the stack.
1032 * \see cl_lock_slice_add(), cl_req_slice_add(), cl_page_slice_add()
1034 void cl_io_slice_add(struct cl_io
*io
, struct cl_io_slice
*slice
,
1035 struct cl_object
*obj
,
1036 const struct cl_io_operations
*ops
)
1038 struct list_head
*linkage
= &slice
->cis_linkage
;
1040 LASSERT((linkage
->prev
== NULL
&& linkage
->next
== NULL
) ||
1041 list_empty(linkage
));
1043 list_add_tail(linkage
, &io
->ci_layers
);
1045 slice
->cis_obj
= obj
;
1046 slice
->cis_iop
= ops
;
1049 EXPORT_SYMBOL(cl_io_slice_add
);
1053 * Initializes page list.
1055 void cl_page_list_init(struct cl_page_list
*plist
)
1058 INIT_LIST_HEAD(&plist
->pl_pages
);
1059 plist
->pl_owner
= current
;
1062 EXPORT_SYMBOL(cl_page_list_init
);
1065 * Adds a page to a page list.
1067 void cl_page_list_add(struct cl_page_list
*plist
, struct cl_page
*page
)
1069 /* it would be better to check that page is owned by "current" io, but
1070 * it is not passed here. */
1071 LASSERT(page
->cp_owner
!= NULL
);
1072 LINVRNT(plist
->pl_owner
== current
);
1075 mutex_lock(&page
->cp_mutex
);
1077 LASSERT(list_empty(&page
->cp_batch
));
1078 list_add_tail(&page
->cp_batch
, &plist
->pl_pages
);
1080 lu_ref_add_at(&page
->cp_reference
, &page
->cp_queue_ref
, "queue", plist
);
1084 EXPORT_SYMBOL(cl_page_list_add
);
1087 * Removes a page from a page list.
1089 void cl_page_list_del(const struct lu_env
*env
,
1090 struct cl_page_list
*plist
, struct cl_page
*page
)
1092 LASSERT(plist
->pl_nr
> 0);
1093 LINVRNT(plist
->pl_owner
== current
);
1095 list_del_init(&page
->cp_batch
);
1097 mutex_unlock(&page
->cp_mutex
);
1100 lu_ref_del_at(&page
->cp_reference
, &page
->cp_queue_ref
, "queue", plist
);
1101 cl_page_put(env
, page
);
1104 EXPORT_SYMBOL(cl_page_list_del
);
1107 * Moves a page from one page list to another.
1109 void cl_page_list_move(struct cl_page_list
*dst
, struct cl_page_list
*src
,
1110 struct cl_page
*page
)
1112 LASSERT(src
->pl_nr
> 0);
1113 LINVRNT(dst
->pl_owner
== current
);
1114 LINVRNT(src
->pl_owner
== current
);
1116 list_move_tail(&page
->cp_batch
, &dst
->pl_pages
);
1119 lu_ref_set_at(&page
->cp_reference
, &page
->cp_queue_ref
, "queue",
1123 EXPORT_SYMBOL(cl_page_list_move
);
1126 * splice the cl_page_list, just as list head does
1128 void cl_page_list_splice(struct cl_page_list
*list
, struct cl_page_list
*head
)
1130 struct cl_page
*page
;
1131 struct cl_page
*tmp
;
1133 LINVRNT(list
->pl_owner
== current
);
1134 LINVRNT(head
->pl_owner
== current
);
1136 cl_page_list_for_each_safe(page
, tmp
, list
)
1137 cl_page_list_move(head
, list
, page
);
1140 EXPORT_SYMBOL(cl_page_list_splice
);
1142 void cl_page_disown0(const struct lu_env
*env
,
1143 struct cl_io
*io
, struct cl_page
*pg
);
1146 * Disowns pages in a queue.
1148 void cl_page_list_disown(const struct lu_env
*env
,
1149 struct cl_io
*io
, struct cl_page_list
*plist
)
1151 struct cl_page
*page
;
1152 struct cl_page
*temp
;
1154 LINVRNT(plist
->pl_owner
== current
);
1156 cl_page_list_for_each_safe(page
, temp
, plist
) {
1157 LASSERT(plist
->pl_nr
> 0);
1159 list_del_init(&page
->cp_batch
);
1161 mutex_unlock(&page
->cp_mutex
);
1165 * cl_page_disown0 rather than usual cl_page_disown() is used,
1166 * because pages are possibly in CPS_FREEING state already due
1167 * to the call to cl_page_list_discard().
1170 * XXX cl_page_disown0() will fail if page is not locked.
1172 cl_page_disown0(env
, io
, page
);
1173 lu_ref_del_at(&page
->cp_reference
, &page
->cp_queue_ref
, "queue",
1175 cl_page_put(env
, page
);
1179 EXPORT_SYMBOL(cl_page_list_disown
);
1182 * Releases pages from queue.
1184 void cl_page_list_fini(const struct lu_env
*env
, struct cl_page_list
*plist
)
1186 struct cl_page
*page
;
1187 struct cl_page
*temp
;
1189 LINVRNT(plist
->pl_owner
== current
);
1191 cl_page_list_for_each_safe(page
, temp
, plist
)
1192 cl_page_list_del(env
, plist
, page
);
1193 LASSERT(plist
->pl_nr
== 0);
1196 EXPORT_SYMBOL(cl_page_list_fini
);
1199 * Owns all pages in a queue.
1201 int cl_page_list_own(const struct lu_env
*env
,
1202 struct cl_io
*io
, struct cl_page_list
*plist
)
1204 struct cl_page
*page
;
1205 struct cl_page
*temp
;
1209 LINVRNT(plist
->pl_owner
== current
);
1212 cl_page_list_for_each_safe(page
, temp
, plist
) {
1213 LASSERT(index
<= page
->cp_index
);
1214 index
= page
->cp_index
;
1215 if (cl_page_own(env
, io
, page
) == 0)
1216 result
= result
?: page
->cp_error
;
1218 cl_page_list_del(env
, plist
, page
);
1222 EXPORT_SYMBOL(cl_page_list_own
);
1225 * Assumes all pages in a queue.
1227 void cl_page_list_assume(const struct lu_env
*env
,
1228 struct cl_io
*io
, struct cl_page_list
*plist
)
1230 struct cl_page
*page
;
1232 LINVRNT(plist
->pl_owner
== current
);
1234 cl_page_list_for_each(page
, plist
)
1235 cl_page_assume(env
, io
, page
);
1237 EXPORT_SYMBOL(cl_page_list_assume
);
1240 * Discards all pages in a queue.
1242 void cl_page_list_discard(const struct lu_env
*env
, struct cl_io
*io
,
1243 struct cl_page_list
*plist
)
1245 struct cl_page
*page
;
1247 LINVRNT(plist
->pl_owner
== current
);
1248 cl_page_list_for_each(page
, plist
)
1249 cl_page_discard(env
, io
, page
);
1252 EXPORT_SYMBOL(cl_page_list_discard
);
1255 * Unmaps all pages in a queue from user virtual memory.
1257 int cl_page_list_unmap(const struct lu_env
*env
, struct cl_io
*io
,
1258 struct cl_page_list
*plist
)
1260 struct cl_page
*page
;
1263 LINVRNT(plist
->pl_owner
== current
);
1265 cl_page_list_for_each(page
, plist
) {
1266 result
= cl_page_unmap(env
, io
, page
);
1272 EXPORT_SYMBOL(cl_page_list_unmap
);
1275 * Initialize dual page queue.
1277 void cl_2queue_init(struct cl_2queue
*queue
)
1279 cl_page_list_init(&queue
->c2_qin
);
1280 cl_page_list_init(&queue
->c2_qout
);
1283 EXPORT_SYMBOL(cl_2queue_init
);
1286 * Add a page to the incoming page list of 2-queue.
1288 void cl_2queue_add(struct cl_2queue
*queue
, struct cl_page
*page
)
1290 cl_page_list_add(&queue
->c2_qin
, page
);
1293 EXPORT_SYMBOL(cl_2queue_add
);
1296 * Disown pages in both lists of a 2-queue.
1298 void cl_2queue_disown(const struct lu_env
*env
,
1299 struct cl_io
*io
, struct cl_2queue
*queue
)
1301 cl_page_list_disown(env
, io
, &queue
->c2_qin
);
1302 cl_page_list_disown(env
, io
, &queue
->c2_qout
);
1305 EXPORT_SYMBOL(cl_2queue_disown
);
1308 * Discard (truncate) pages in both lists of a 2-queue.
1310 void cl_2queue_discard(const struct lu_env
*env
,
1311 struct cl_io
*io
, struct cl_2queue
*queue
)
1313 cl_page_list_discard(env
, io
, &queue
->c2_qin
);
1314 cl_page_list_discard(env
, io
, &queue
->c2_qout
);
1317 EXPORT_SYMBOL(cl_2queue_discard
);
1320 * Assume to own the pages in cl_2queue
1322 void cl_2queue_assume(const struct lu_env
*env
,
1323 struct cl_io
*io
, struct cl_2queue
*queue
)
1325 cl_page_list_assume(env
, io
, &queue
->c2_qin
);
1326 cl_page_list_assume(env
, io
, &queue
->c2_qout
);
1328 EXPORT_SYMBOL(cl_2queue_assume
);
1331 * Finalize both page lists of a 2-queue.
1333 void cl_2queue_fini(const struct lu_env
*env
, struct cl_2queue
*queue
)
1335 cl_page_list_fini(env
, &queue
->c2_qout
);
1336 cl_page_list_fini(env
, &queue
->c2_qin
);
1339 EXPORT_SYMBOL(cl_2queue_fini
);
1342 * Initialize a 2-queue to contain \a page in its incoming page list.
1344 void cl_2queue_init_page(struct cl_2queue
*queue
, struct cl_page
*page
)
1346 cl_2queue_init(queue
);
1347 cl_2queue_add(queue
, page
);
1350 EXPORT_SYMBOL(cl_2queue_init_page
);
1353 * Returns top-level io.
1355 * \see cl_object_top(), cl_page_top().
1357 struct cl_io
*cl_io_top(struct cl_io
*io
)
1359 while (io
->ci_parent
!= NULL
)
1363 EXPORT_SYMBOL(cl_io_top
);
1366 * Prints human readable representation of \a io to the \a f.
1368 void cl_io_print(const struct lu_env
*env
, void *cookie
,
1369 lu_printer_t printer
, const struct cl_io
*io
)
1374 * Adds request slice to the compound request.
1376 * This is called by cl_device_operations::cdo_req_init() methods to add a
1377 * per-layer state to the request. New state is added at the end of
1378 * cl_req::crq_layers list, that is, it is at the bottom of the stack.
1380 * \see cl_lock_slice_add(), cl_page_slice_add(), cl_io_slice_add()
1382 void cl_req_slice_add(struct cl_req
*req
, struct cl_req_slice
*slice
,
1383 struct cl_device
*dev
,
1384 const struct cl_req_operations
*ops
)
1386 list_add_tail(&slice
->crs_linkage
, &req
->crq_layers
);
1387 slice
->crs_dev
= dev
;
1388 slice
->crs_ops
= ops
;
1389 slice
->crs_req
= req
;
1392 EXPORT_SYMBOL(cl_req_slice_add
);
1394 static void cl_req_free(const struct lu_env
*env
, struct cl_req
*req
)
1398 LASSERT(list_empty(&req
->crq_pages
));
1399 LASSERT(req
->crq_nrpages
== 0);
1400 LINVRNT(list_empty(&req
->crq_layers
));
1401 LINVRNT(equi(req
->crq_nrobjs
> 0, req
->crq_o
!= NULL
));
1403 if (req
->crq_o
!= NULL
) {
1404 for (i
= 0; i
< req
->crq_nrobjs
; ++i
) {
1405 struct cl_object
*obj
= req
->crq_o
[i
].ro_obj
;
1407 lu_object_ref_del_at(&obj
->co_lu
,
1408 &req
->crq_o
[i
].ro_obj_ref
,
1410 cl_object_put(env
, obj
);
1413 OBD_FREE(req
->crq_o
, req
->crq_nrobjs
* sizeof req
->crq_o
[0]);
1419 static int cl_req_init(const struct lu_env
*env
, struct cl_req
*req
,
1420 struct cl_page
*page
)
1422 struct cl_device
*dev
;
1423 struct cl_page_slice
*slice
;
1427 page
= cl_page_top(page
);
1429 list_for_each_entry(slice
, &page
->cp_layers
, cpl_linkage
) {
1430 dev
= lu2cl_dev(slice
->cpl_obj
->co_lu
.lo_dev
);
1431 if (dev
->cd_ops
->cdo_req_init
!= NULL
) {
1432 result
= dev
->cd_ops
->cdo_req_init(env
,
1438 page
= page
->cp_child
;
1439 } while (page
!= NULL
&& result
== 0);
1444 * Invokes per-request transfer completion call-backs
1445 * (cl_req_operations::cro_completion()) bottom-to-top.
1447 void cl_req_completion(const struct lu_env
*env
, struct cl_req
*req
, int rc
)
1449 struct cl_req_slice
*slice
;
1452 * for the lack of list_for_each_entry_reverse_safe()...
1454 while (!list_empty(&req
->crq_layers
)) {
1455 slice
= list_entry(req
->crq_layers
.prev
,
1456 struct cl_req_slice
, crs_linkage
);
1457 list_del_init(&slice
->crs_linkage
);
1458 if (slice
->crs_ops
->cro_completion
!= NULL
)
1459 slice
->crs_ops
->cro_completion(env
, slice
, rc
);
1461 cl_req_free(env
, req
);
1464 EXPORT_SYMBOL(cl_req_completion
);
1467 * Allocates new transfer request.
1469 struct cl_req
*cl_req_alloc(const struct lu_env
*env
, struct cl_page
*page
,
1470 enum cl_req_type crt
, int nr_objects
)
1474 LINVRNT(nr_objects
> 0);
1480 OBD_ALLOC(req
->crq_o
, nr_objects
* sizeof req
->crq_o
[0]);
1481 if (req
->crq_o
!= NULL
) {
1482 req
->crq_nrobjs
= nr_objects
;
1483 req
->crq_type
= crt
;
1484 INIT_LIST_HEAD(&req
->crq_pages
);
1485 INIT_LIST_HEAD(&req
->crq_layers
);
1486 result
= cl_req_init(env
, req
, page
);
1490 cl_req_completion(env
, req
, result
);
1491 req
= ERR_PTR(result
);
1494 req
= ERR_PTR(-ENOMEM
);
1497 EXPORT_SYMBOL(cl_req_alloc
);
1500 * Adds a page to a request.
1502 void cl_req_page_add(const struct lu_env
*env
,
1503 struct cl_req
*req
, struct cl_page
*page
)
1505 struct cl_object
*obj
;
1506 struct cl_req_obj
*rqo
;
1509 page
= cl_page_top(page
);
1511 LASSERT(list_empty(&page
->cp_flight
));
1512 LASSERT(page
->cp_req
== NULL
);
1514 CL_PAGE_DEBUG(D_PAGE
, env
, page
, "req %p, %d, %u\n",
1515 req
, req
->crq_type
, req
->crq_nrpages
);
1517 list_add_tail(&page
->cp_flight
, &req
->crq_pages
);
1520 obj
= cl_object_top(page
->cp_obj
);
1521 for (i
= 0, rqo
= req
->crq_o
; obj
!= rqo
->ro_obj
; ++i
, ++rqo
) {
1522 if (rqo
->ro_obj
== NULL
) {
1525 lu_object_ref_add_at(&obj
->co_lu
, &rqo
->ro_obj_ref
,
1530 LASSERT(i
< req
->crq_nrobjs
);
1533 EXPORT_SYMBOL(cl_req_page_add
);
1536 * Removes a page from a request.
1538 void cl_req_page_done(const struct lu_env
*env
, struct cl_page
*page
)
1540 struct cl_req
*req
= page
->cp_req
;
1542 page
= cl_page_top(page
);
1544 LASSERT(!list_empty(&page
->cp_flight
));
1545 LASSERT(req
->crq_nrpages
> 0);
1547 list_del_init(&page
->cp_flight
);
1549 page
->cp_req
= NULL
;
1552 EXPORT_SYMBOL(cl_req_page_done
);
1555 * Notifies layers that request is about to depart by calling
1556 * cl_req_operations::cro_prep() top-to-bottom.
1558 int cl_req_prep(const struct lu_env
*env
, struct cl_req
*req
)
1562 const struct cl_req_slice
*slice
;
1565 * Check that the caller of cl_req_alloc() didn't lie about the number
1568 for (i
= 0; i
< req
->crq_nrobjs
; ++i
)
1569 LASSERT(req
->crq_o
[i
].ro_obj
!= NULL
);
1572 list_for_each_entry(slice
, &req
->crq_layers
, crs_linkage
) {
1573 if (slice
->crs_ops
->cro_prep
!= NULL
) {
1574 result
= slice
->crs_ops
->cro_prep(env
, slice
);
1581 EXPORT_SYMBOL(cl_req_prep
);
1584 * Fills in attributes that are passed to server together with transfer. Only
1585 * attributes from \a flags may be touched. This can be called multiple times
1586 * for the same request.
1588 void cl_req_attr_set(const struct lu_env
*env
, struct cl_req
*req
,
1589 struct cl_req_attr
*attr
, obd_valid flags
)
1591 const struct cl_req_slice
*slice
;
1592 struct cl_page
*page
;
1595 LASSERT(!list_empty(&req
->crq_pages
));
1597 /* Take any page to use as a model. */
1598 page
= list_entry(req
->crq_pages
.next
, struct cl_page
, cp_flight
);
1600 for (i
= 0; i
< req
->crq_nrobjs
; ++i
) {
1601 list_for_each_entry(slice
, &req
->crq_layers
, crs_linkage
) {
1602 const struct cl_page_slice
*scan
;
1603 const struct cl_object
*obj
;
1605 scan
= cl_page_at(page
,
1606 slice
->crs_dev
->cd_lu_dev
.ld_type
);
1607 LASSERT(scan
!= NULL
);
1608 obj
= scan
->cpl_obj
;
1609 if (slice
->crs_ops
->cro_attr_set
!= NULL
)
1610 slice
->crs_ops
->cro_attr_set(env
, slice
, obj
,
1616 EXPORT_SYMBOL(cl_req_attr_set
);
1618 /* XXX complete(), init_completion(), and wait_for_completion(), until they are
1619 * implemented in libcfs. */
1620 # include <linux/sched.h>
1623 * Initialize synchronous io wait anchor, for transfer of \a nrpages pages.
1625 void cl_sync_io_init(struct cl_sync_io
*anchor
, int nrpages
)
1627 init_waitqueue_head(&anchor
->csi_waitq
);
1628 atomic_set(&anchor
->csi_sync_nr
, nrpages
);
1629 atomic_set(&anchor
->csi_barrier
, nrpages
> 0);
1630 anchor
->csi_sync_rc
= 0;
1633 EXPORT_SYMBOL(cl_sync_io_init
);
1636 * Wait until all transfer completes. Transfer completion routine has to call
1637 * cl_sync_io_note() for every page.
1639 int cl_sync_io_wait(const struct lu_env
*env
, struct cl_io
*io
,
1640 struct cl_page_list
*queue
, struct cl_sync_io
*anchor
,
1643 struct l_wait_info lwi
= LWI_TIMEOUT_INTR(cfs_time_seconds(timeout
),
1647 LASSERT(timeout
>= 0);
1649 rc
= l_wait_event(anchor
->csi_waitq
,
1650 atomic_read(&anchor
->csi_sync_nr
) == 0,
1653 CERROR("SYNC IO failed with error: %d, try to cancel "
1654 "%d remaining pages\n",
1655 rc
, atomic_read(&anchor
->csi_sync_nr
));
1657 (void)cl_io_cancel(env
, io
, queue
);
1659 lwi
= (struct l_wait_info
) { 0 };
1660 (void)l_wait_event(anchor
->csi_waitq
,
1661 atomic_read(&anchor
->csi_sync_nr
) == 0,
1664 rc
= anchor
->csi_sync_rc
;
1666 LASSERT(atomic_read(&anchor
->csi_sync_nr
) == 0);
1667 cl_page_list_assume(env
, io
, queue
);
1669 /* wait until cl_sync_io_note() has done wakeup */
1670 while (unlikely(atomic_read(&anchor
->csi_barrier
) != 0)) {
1674 POISON(anchor
, 0x5a, sizeof *anchor
);
1677 EXPORT_SYMBOL(cl_sync_io_wait
);
1680 * Indicate that transfer of a single page completed.
1682 void cl_sync_io_note(struct cl_sync_io
*anchor
, int ioret
)
1684 if (anchor
->csi_sync_rc
== 0 && ioret
< 0)
1685 anchor
->csi_sync_rc
= ioret
;
1687 * Synchronous IO done without releasing page lock (e.g., as a part of
1688 * ->{prepare,commit}_write(). Completion is used to signal the end of
1691 LASSERT(atomic_read(&anchor
->csi_sync_nr
) > 0);
1692 if (atomic_dec_and_test(&anchor
->csi_sync_nr
)) {
1693 wake_up_all(&anchor
->csi_waitq
);
1694 /* it's safe to nuke or reuse anchor now */
1695 atomic_set(&anchor
->csi_barrier
, 0);
1699 EXPORT_SYMBOL(cl_sync_io_note
);
This page took 0.064786 seconds and 6 git commands to generate.