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, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #ifndef _LUSTRE_CL_OBJECT_H
33 #define _LUSTRE_CL_OBJECT_H
35 /** \defgroup clio clio
37 * Client objects implement io operations and cache pages.
39 * Examples: lov and osc are implementations of cl interface.
41 * Big Theory Statement.
45 * Client implementation is based on the following data-types:
51 * - cl_lock represents an extent lock on an object.
53 * - cl_io represents high-level i/o activity such as whole read/write
54 * system call, or write-out of pages from under the lock being
55 * canceled. cl_io has sub-ios that can be stopped and resumed
56 * independently, thus achieving high degree of transfer
57 * parallelism. Single cl_io can be advanced forward by
58 * the multiple threads (although in the most usual case of
59 * read/write system call it is associated with the single user
60 * thread, that issued the system call).
64 * - to avoid confusion high-level I/O operation like read or write system
65 * call is referred to as "an io", whereas low-level I/O operation, like
66 * RPC, is referred to as "a transfer"
68 * - "generic code" means generic (not file system specific) code in the
69 * hosting environment. "cl-code" means code (mostly in cl_*.c files) that
70 * is not layer specific.
76 * - cl_object_header::coh_page_guard
79 * See the top comment in cl_object.c for the description of overall locking and
80 * reference-counting design.
82 * See comments below for the description of i/o, page, and dlm-locking
89 * super-class definitions.
91 #include <linux/aio.h>
94 #include <libcfs/libcfs.h>
95 #include <libcfs/libcfs_ptask.h>
96 #include <lu_object.h>
97 #include <linux/atomic.h>
98 #include <linux/mutex.h>
99 #include <linux/radix-tree.h>
100 #include <linux/spinlock.h>
101 #include <linux/wait.h>
102 #include <linux/pagevec.h>
103 #include <lustre_dlm.h>
113 struct cl_page_slice;
115 struct cl_lock_slice;
117 struct cl_lock_operations;
118 struct cl_page_operations;
125 extern struct cfs_ptask_engine *cl_io_engine;
128 * Device in the client stack.
130 * \see vvp_device, lov_device, lovsub_device, osc_device
134 struct lu_device cd_lu_dev;
137 /** \addtogroup cl_object cl_object
140 * "Data attributes" of cl_object. Data attributes can be updated
141 * independently for a sub-object, and top-object's attributes are calculated
142 * from sub-objects' ones.
145 /** Object size, in bytes */
148 * Known minimal size, in bytes.
150 * This is only valid when at least one DLM lock is held.
153 /** Modification time. Measured in seconds since epoch. */
155 /** Access time. Measured in seconds since epoch. */
157 /** Change time. Measured in seconds since epoch. */
160 * Blocks allocated to this cl_object on the server file system.
162 * \todo XXX An interface for block size is needed.
166 * User identifier for quota purposes.
170 * Group identifier for quota purposes.
174 /* nlink of the directory */
177 /* Project identifier for quota purpose. */
182 * Fields in cl_attr that are being set.
197 * Sub-class of lu_object with methods common for objects on the client
200 * cl_object: represents a regular file system object, both a file and a
201 * stripe. cl_object is based on lu_object: it is identified by a fid,
202 * layered, cached, hashed, and lrued. Important distinction with the server
203 * side, where md_object and dt_object are used, is that cl_object "fans out"
204 * at the lov/sns level: depending on the file layout, single file is
205 * represented as a set of "sub-objects" (stripes). At the implementation
206 * level, struct lov_object contains an array of cl_objects. Each sub-object
207 * is a full-fledged cl_object, having its fid, living in the lru and hash
210 * This leads to the next important difference with the server side: on the
211 * client, it's quite usual to have objects with the different sequence of
212 * layers. For example, typical top-object is composed of the following
218 * whereas its sub-objects are composed of
223 * layers. Here "lovsub" is a mostly dummy layer, whose purpose is to keep
224 * track of the object-subobject relationship.
226 * Sub-objects are not cached independently: when top-object is about to
227 * be discarded from the memory, all its sub-objects are torn-down and
230 * \see vvp_object, lov_object, lovsub_object, osc_object
234 struct lu_object co_lu;
235 /** per-object-layer operations */
236 const struct cl_object_operations *co_ops;
237 /** offset of page slice in cl_page buffer */
242 * Description of the client object configuration. This is used for the
243 * creation of a new client object that is identified by a more state than
246 struct cl_object_conf {
248 struct lu_object_conf coc_lu;
251 * Object layout. This is consumed by lov.
253 struct lu_buf coc_layout;
255 * Description of particular stripe location in the
256 * cluster. This is consumed by osc.
258 struct lov_oinfo *coc_oinfo;
261 * VFS inode. This is consumed by vvp.
263 struct inode *coc_inode;
265 * Layout lock handle.
267 struct ldlm_lock *coc_lock;
269 * Operation to handle layout, OBJECT_CONF_XYZ.
275 /** configure layout, set up a new stripe, must be called while
276 * holding layout lock. */
278 /** invalidate the current stripe configuration due to losing
280 OBJECT_CONF_INVALIDATE = 1,
281 /** wait for old layout to go away so that new layout can be
287 CL_LAYOUT_GEN_NONE = (u32)-2, /* layout lock was cancelled */
288 CL_LAYOUT_GEN_EMPTY = (u32)-1, /* for empty layout */
292 /** the buffer to return the layout in lov_mds_md format. */
293 struct lu_buf cl_buf;
294 /** size of layout in lov_mds_md format. */
296 /** size of DoM component if exists or zero otherwise */
297 u64 cl_dom_comp_size;
298 /** Layout generation. */
300 /** whether layout is a composite one */
301 bool cl_is_composite;
305 * Operations implemented for each cl object layer.
307 * \see vvp_ops, lov_ops, lovsub_ops, osc_ops
309 struct cl_object_operations {
311 * Initialize page slice for this layer. Called top-to-bottom through
312 * every object layer when a new cl_page is instantiated. Layer
313 * keeping private per-page data, or requiring its own page operations
314 * vector should allocate these data here, and attach then to the page
315 * by calling cl_page_slice_add(). \a vmpage is locked (in the VM
318 * \retval NULL success.
320 * \retval ERR_PTR(errno) failure code.
322 * \retval valid-pointer pointer to already existing referenced page
323 * to be used instead of newly created.
325 int (*coo_page_init)(const struct lu_env *env, struct cl_object *obj,
326 struct cl_page *page, pgoff_t index);
328 * Initialize lock slice for this layer. Called top-to-bottom through
329 * every object layer when a new cl_lock is instantiated. Layer
330 * keeping private per-lock data, or requiring its own lock operations
331 * vector should allocate these data here, and attach then to the lock
332 * by calling cl_lock_slice_add(). Mandatory.
334 int (*coo_lock_init)(const struct lu_env *env,
335 struct cl_object *obj, struct cl_lock *lock,
336 const struct cl_io *io);
338 * Initialize io state for a given layer.
340 * called top-to-bottom once per io existence to initialize io
341 * state. If layer wants to keep some state for this type of io, it
342 * has to embed struct cl_io_slice in lu_env::le_ses, and register
343 * slice with cl_io_slice_add(). It is guaranteed that all threads
344 * participating in this io share the same session.
346 int (*coo_io_init)(const struct lu_env *env,
347 struct cl_object *obj, struct cl_io *io);
349 * Fill portion of \a attr that this layer controls. This method is
350 * called top-to-bottom through all object layers.
352 * \pre cl_object_header::coh_attr_guard of the top-object is locked.
354 * \return 0: to continue
355 * \return +ve: to stop iterating through layers (but 0 is returned
356 * from enclosing cl_object_attr_get())
357 * \return -ve: to signal error
359 int (*coo_attr_get)(const struct lu_env *env, struct cl_object *obj,
360 struct cl_attr *attr);
364 * \a valid is a bitmask composed from enum #cl_attr_valid, and
365 * indicating what attributes are to be set.
367 * \pre cl_object_header::coh_attr_guard of the top-object is locked.
369 * \return the same convention as for
370 * cl_object_operations::coo_attr_get() is used.
372 int (*coo_attr_update)(const struct lu_env *env, struct cl_object *obj,
373 const struct cl_attr *attr, unsigned valid);
375 * Update object configuration. Called top-to-bottom to modify object
378 * XXX error conditions and handling.
380 int (*coo_conf_set)(const struct lu_env *env, struct cl_object *obj,
381 const struct cl_object_conf *conf);
383 * Glimpse ast. Executed when glimpse ast arrives for a lock on this
384 * object. Layers are supposed to fill parts of \a lvb that will be
385 * shipped to the glimpse originator as a glimpse result.
387 * \see vvp_object_glimpse(), lovsub_object_glimpse(),
388 * \see osc_object_glimpse()
390 int (*coo_glimpse)(const struct lu_env *env,
391 const struct cl_object *obj, struct ost_lvb *lvb);
393 * Object prune method. Called when the layout is going to change on
394 * this object, therefore each layer has to clean up their cache,
395 * mainly pages and locks.
397 int (*coo_prune)(const struct lu_env *env, struct cl_object *obj);
399 * Object getstripe method.
401 int (*coo_getstripe)(const struct lu_env *env, struct cl_object *obj,
402 struct lov_user_md __user *lum, size_t size);
404 * Get FIEMAP mapping from the object.
406 int (*coo_fiemap)(const struct lu_env *env, struct cl_object *obj,
407 struct ll_fiemap_info_key *fmkey,
408 struct fiemap *fiemap, size_t *buflen);
410 * Get layout and generation of the object.
412 int (*coo_layout_get)(const struct lu_env *env, struct cl_object *obj,
413 struct cl_layout *layout);
415 * Get maximum size of the object.
417 loff_t (*coo_maxbytes)(struct cl_object *obj);
419 * Set request attributes.
421 void (*coo_req_attr_set)(const struct lu_env *env,
422 struct cl_object *obj,
423 struct cl_req_attr *attr);
427 * Extended header for client object.
429 struct cl_object_header {
430 /** Standard lu_object_header. cl_object::co_lu::lo_header points
432 struct lu_object_header coh_lu;
435 * Parent object. It is assumed that an object has a well-defined
436 * parent, but not a well-defined child (there may be multiple
437 * sub-objects, for the same top-object). cl_object_header::coh_parent
438 * field allows certain code to be written generically, without
439 * limiting possible cl_object layouts unduly.
441 struct cl_object_header *coh_parent;
443 * Protects consistency between cl_attr of parent object and
444 * attributes of sub-objects, that the former is calculated ("merged")
447 * \todo XXX this can be read/write lock if needed.
449 spinlock_t coh_attr_guard;
451 * Size of cl_page + page slices
453 unsigned short coh_page_bufsize;
455 * Number of objects above this one: 0 for a top-object, 1 for its
458 unsigned char coh_nesting;
462 * Helper macro: iterate over all layers of the object \a obj, assigning every
463 * layer top-to-bottom to \a slice.
465 #define cl_object_for_each(slice, obj) \
466 list_for_each_entry((slice), \
467 &(obj)->co_lu.lo_header->loh_layers,\
471 * Helper macro: iterate over all layers of the object \a obj, assigning every
472 * layer bottom-to-top to \a slice.
474 #define cl_object_for_each_reverse(slice, obj) \
475 list_for_each_entry_reverse((slice), \
476 &(obj)->co_lu.lo_header->loh_layers,\
481 #define CL_PAGE_EOF ((pgoff_t)~0ull)
483 /** \addtogroup cl_page cl_page
487 * Layered client page.
489 * cl_page: represents a portion of a file, cached in the memory. All pages
490 * of the given file are of the same size, and are kept in the radix tree
491 * hanging off the cl_object. cl_page doesn't fan out, but as sub-objects
492 * of the top-level file object are first class cl_objects, they have their
493 * own radix trees of pages and hence page is implemented as a sequence of
494 * struct cl_pages's, linked into double-linked list through
495 * cl_page::cp_parent and cl_page::cp_child pointers, each residing in the
496 * corresponding radix tree at the corresponding logical offset.
498 * cl_page is associated with VM page of the hosting environment (struct
499 * page in Linux kernel, for example), struct page. It is assumed, that this
500 * association is implemented by one of cl_page layers (top layer in the
501 * current design) that
503 * - intercepts per-VM-page call-backs made by the environment (e.g.,
506 * - translates state (page flag bits) and locking between lustre and
509 * The association between cl_page and struct page is immutable and
510 * established when cl_page is created.
512 * cl_page can be "owned" by a particular cl_io (see below), guaranteeing
513 * this io an exclusive access to this page w.r.t. other io attempts and
514 * various events changing page state (such as transfer completion, or
515 * eviction of the page from the memory). Note, that in general cl_io
516 * cannot be identified with a particular thread, and page ownership is not
517 * exactly equal to the current thread holding a lock on the page. Layer
518 * implementing association between cl_page and struct page has to implement
519 * ownership on top of available synchronization mechanisms.
521 * While lustre client maintains the notion of an page ownership by io,
522 * hosting MM/VM usually has its own page concurrency control
523 * mechanisms. For example, in Linux, page access is synchronized by the
524 * per-page PG_locked bit-lock, and generic kernel code (generic_file_*())
525 * takes care to acquire and release such locks as necessary around the
526 * calls to the file system methods (->readpage(), ->prepare_write(),
527 * ->commit_write(), etc.). This leads to the situation when there are two
528 * different ways to own a page in the client:
530 * - client code explicitly and voluntary owns the page (cl_page_own());
532 * - VM locks a page and then calls the client, that has "to assume"
533 * the ownership from the VM (cl_page_assume()).
535 * Dual methods to release ownership are cl_page_disown() and
536 * cl_page_unassume().
538 * cl_page is reference counted (cl_page::cp_ref). When reference counter
539 * drops to 0, the page is returned to the cache, unless it is in
540 * cl_page_state::CPS_FREEING state, in which case it is immediately
543 * The general logic guaranteeing the absence of "existential races" for
544 * pages is the following:
546 * - there are fixed known ways for a thread to obtain a new reference
549 * - by doing a lookup in the cl_object radix tree, protected by the
552 * - by starting from VM-locked struct page and following some
553 * hosting environment method (e.g., following ->private pointer in
554 * the case of Linux kernel), see cl_vmpage_page();
556 * - when the page enters cl_page_state::CPS_FREEING state, all these
557 * ways are severed with the proper synchronization
558 * (cl_page_delete());
560 * - entry into cl_page_state::CPS_FREEING is serialized by the VM page
563 * - no new references to the page in cl_page_state::CPS_FREEING state
564 * are allowed (checked in cl_page_get()).
566 * Together this guarantees that when last reference to a
567 * cl_page_state::CPS_FREEING page is released, it is safe to destroy the
568 * page, as neither references to it can be acquired at that point, nor
571 * cl_page is a state machine. States are enumerated in enum
572 * cl_page_state. Possible state transitions are enumerated in
573 * cl_page_state_set(). State transition process (i.e., actual changing of
574 * cl_page::cp_state field) is protected by the lock on the underlying VM
577 * Linux Kernel implementation.
579 * Binding between cl_page and struct page (which is a typedef for
580 * struct page) is implemented in the vvp layer. cl_page is attached to the
581 * ->private pointer of the struct page, together with the setting of
582 * PG_private bit in page->flags, and acquiring additional reference on the
583 * struct page (much like struct buffer_head, or any similar file system
584 * private data structures).
586 * PG_locked lock is used to implement both ownership and transfer
587 * synchronization, that is, page is VM-locked in CPS_{OWNED,PAGE{IN,OUT}}
588 * states. No additional references are acquired for the duration of the
591 * \warning *THIS IS NOT* the behavior expected by the Linux kernel, where
592 * write-out is "protected" by the special PG_writeback bit.
596 * States of cl_page. cl_page.c assumes particular order here.
598 * The page state machine is rather crude, as it doesn't recognize finer page
599 * states like "dirty" or "up to date". This is because such states are not
600 * always well defined for the whole stack (see, for example, the
601 * implementation of the read-ahead, that hides page up-to-dateness to track
602 * cache hits accurately). Such sub-states are maintained by the layers that
603 * are interested in them.
607 * Page is in the cache, un-owned. Page leaves cached state in the
610 * - [cl_page_state::CPS_OWNED] io comes across the page and
613 * - [cl_page_state::CPS_PAGEOUT] page is dirty, the
614 * req-formation engine decides that it wants to include this page
615 * into an RPC being constructed, and yanks it from the cache;
617 * - [cl_page_state::CPS_FREEING] VM callback is executed to
618 * evict the page form the memory;
620 * \invariant cl_page::cp_owner == NULL && cl_page::cp_req == NULL
624 * Page is exclusively owned by some cl_io. Page may end up in this
625 * state as a result of
627 * - io creating new page and immediately owning it;
629 * - [cl_page_state::CPS_CACHED] io finding existing cached page
632 * - [cl_page_state::CPS_OWNED] io finding existing owned page
633 * and waiting for owner to release the page;
635 * Page leaves owned state in the following cases:
637 * - [cl_page_state::CPS_CACHED] io decides to leave the page in
638 * the cache, doing nothing;
640 * - [cl_page_state::CPS_PAGEIN] io starts read transfer for
643 * - [cl_page_state::CPS_PAGEOUT] io starts immediate write
644 * transfer for this page;
646 * - [cl_page_state::CPS_FREEING] io decides to destroy this
647 * page (e.g., as part of truncate or extent lock cancellation).
649 * \invariant cl_page::cp_owner != NULL && cl_page::cp_req == NULL
653 * Page is being written out, as a part of a transfer. This state is
654 * entered when req-formation logic decided that it wants this page to
655 * be sent through the wire _now_. Specifically, it means that once
656 * this state is achieved, transfer completion handler (with either
657 * success or failure indication) is guaranteed to be executed against
658 * this page independently of any locks and any scheduling decisions
659 * made by the hosting environment (that effectively means that the
660 * page is never put into cl_page_state::CPS_PAGEOUT state "in
661 * advance". This property is mentioned, because it is important when
662 * reasoning about possible dead-locks in the system). The page can
663 * enter this state as a result of
665 * - [cl_page_state::CPS_OWNED] an io requesting an immediate
666 * write-out of this page, or
668 * - [cl_page_state::CPS_CACHED] req-forming engine deciding
669 * that it has enough dirty pages cached to issue a "good"
672 * The page leaves cl_page_state::CPS_PAGEOUT state when the transfer
673 * is completed---it is moved into cl_page_state::CPS_CACHED state.
675 * Underlying VM page is locked for the duration of transfer.
677 * \invariant: cl_page::cp_owner == NULL && cl_page::cp_req != NULL
681 * Page is being read in, as a part of a transfer. This is quite
682 * similar to the cl_page_state::CPS_PAGEOUT state, except that
683 * read-in is always "immediate"---there is no such thing a sudden
684 * construction of read request from cached, presumably not up to date,
687 * Underlying VM page is locked for the duration of transfer.
689 * \invariant: cl_page::cp_owner == NULL && cl_page::cp_req != NULL
693 * Page is being destroyed. This state is entered when client decides
694 * that page has to be deleted from its host object, as, e.g., a part
697 * Once this state is reached, there is no way to escape it.
699 * \invariant: cl_page::cp_owner == NULL && cl_page::cp_req == NULL
706 /** Host page, the page is from the host inode which the cl_page
710 /** Transient page, the transient cl_page is used to bind a cl_page
711 * to vmpage which is not belonging to the same object of cl_page.
712 * it is used in DirectIO and lockless IO. */
717 * Fields are protected by the lock on struct page, except for atomics and
720 * \invariant Data type invariants are in cl_page_invariant(). Basically:
721 * cl_page::cp_parent and cl_page::cp_child are a well-formed double-linked
722 * list, consistent with the parent/child pointers in the cl_page::cp_obj and
723 * cl_page::cp_owner (when set).
726 /** Reference counter. */
728 /** An object this page is a part of. Immutable after creation. */
729 struct cl_object *cp_obj;
731 struct page *cp_vmpage;
732 /** Linkage of pages within group. Pages must be owned */
733 struct list_head cp_batch;
734 /** List of slices. Immutable after creation. */
735 struct list_head cp_layers;
737 * Page state. This field is const to avoid accidental update, it is
738 * modified only internally within cl_page.c. Protected by a VM lock.
740 const enum cl_page_state cp_state;
742 * Page type. Only CPT_TRANSIENT is used so far. Immutable after
745 enum cl_page_type cp_type;
748 * Owning IO in cl_page_state::CPS_OWNED state. Sub-page can be owned
749 * by sub-io. Protected by a VM lock.
751 struct cl_io *cp_owner;
752 /** List of references to this page, for debugging. */
753 struct lu_ref cp_reference;
754 /** Link to an object, for debugging. */
755 struct lu_ref_link cp_obj_ref;
756 /** Link to a queue, for debugging. */
757 struct lu_ref_link cp_queue_ref;
758 /** Assigned if doing a sync_io */
759 struct cl_sync_io *cp_sync_io;
763 * Per-layer part of cl_page.
765 * \see vvp_page, lov_page, osc_page
767 struct cl_page_slice {
768 struct cl_page *cpl_page;
771 * Object slice corresponding to this page slice. Immutable after
774 struct cl_object *cpl_obj;
775 const struct cl_page_operations *cpl_ops;
776 /** Linkage into cl_page::cp_layers. Immutable after creation. */
777 struct list_head cpl_linkage;
781 * Lock mode. For the client extent locks.
793 * Requested transfer type.
802 * Per-layer page operations.
804 * Methods taking an \a io argument are for the activity happening in the
805 * context of given \a io. Page is assumed to be owned by that io, except for
806 * the obvious cases (like cl_page_operations::cpo_own()).
808 * \see vvp_page_ops, lov_page_ops, osc_page_ops
810 struct cl_page_operations {
812 * cl_page<->struct page methods. Only one layer in the stack has to
813 * implement these. Current code assumes that this functionality is
814 * provided by the topmost layer, see cl_page_disown0() as an example.
818 * Called when \a io acquires this page into the exclusive
819 * ownership. When this method returns, it is guaranteed that the is
820 * not owned by other io, and no transfer is going on against
824 * \see vvp_page_own(), lov_page_own()
826 int (*cpo_own)(const struct lu_env *env,
827 const struct cl_page_slice *slice,
828 struct cl_io *io, int nonblock);
829 /** Called when ownership it yielded. Optional.
831 * \see cl_page_disown()
832 * \see vvp_page_disown()
834 void (*cpo_disown)(const struct lu_env *env,
835 const struct cl_page_slice *slice, struct cl_io *io);
837 * Called for a page that is already "owned" by \a io from VM point of
840 * \see cl_page_assume()
841 * \see vvp_page_assume(), lov_page_assume()
843 void (*cpo_assume)(const struct lu_env *env,
844 const struct cl_page_slice *slice, struct cl_io *io);
845 /** Dual to cl_page_operations::cpo_assume(). Optional. Called
846 * bottom-to-top when IO releases a page without actually unlocking
849 * \see cl_page_unassume()
850 * \see vvp_page_unassume()
852 void (*cpo_unassume)(const struct lu_env *env,
853 const struct cl_page_slice *slice,
856 * Announces whether the page contains valid data or not by \a uptodate.
858 * \see cl_page_export()
859 * \see vvp_page_export()
861 void (*cpo_export)(const struct lu_env *env,
862 const struct cl_page_slice *slice, int uptodate);
864 * Checks whether underlying VM page is locked (in the suitable
865 * sense). Used for assertions.
867 * \retval -EBUSY: page is protected by a lock of a given mode;
868 * \retval -ENODATA: page is not protected by a lock;
869 * \retval 0: this layer cannot decide. (Should never happen.)
871 int (*cpo_is_vmlocked)(const struct lu_env *env,
872 const struct cl_page_slice *slice);
875 * Update file attributes when all we have is this page. Used for tiny
876 * writes to update attributes when we don't have a full cl_io.
878 void (*cpo_page_touch)(const struct lu_env *env,
879 const struct cl_page_slice *slice, size_t to);
885 * Called when page is truncated from the object. Optional.
887 * \see cl_page_discard()
888 * \see vvp_page_discard(), osc_page_discard()
890 void (*cpo_discard)(const struct lu_env *env,
891 const struct cl_page_slice *slice,
894 * Called when page is removed from the cache, and is about to being
895 * destroyed. Optional.
897 * \see cl_page_delete()
898 * \see vvp_page_delete(), osc_page_delete()
900 void (*cpo_delete)(const struct lu_env *env,
901 const struct cl_page_slice *slice);
902 /** Destructor. Frees resources and slice itself. */
903 void (*cpo_fini)(const struct lu_env *env,
904 struct cl_page_slice *slice,
905 struct pagevec *pvec);
907 * Optional debugging helper. Prints given page slice.
909 * \see cl_page_print()
911 int (*cpo_print)(const struct lu_env *env,
912 const struct cl_page_slice *slice,
913 void *cookie, lu_printer_t p);
922 * Request type dependent vector of operations.
924 * Transfer operations depend on transfer mode (cl_req_type). To avoid
925 * passing transfer mode to each and every of these methods, and to
926 * avoid branching on request type inside of the methods, separate
927 * methods for cl_req_type:CRT_READ and cl_req_type:CRT_WRITE are
928 * provided. That is, method invocation usually looks like
930 * slice->cp_ops.io[req->crq_type].cpo_method(env, slice, ...);
934 * Called when a page is submitted for a transfer as a part of
937 * \return 0 : page is eligible for submission;
938 * \return -EALREADY : skip this page;
939 * \return -ve : error.
941 * \see cl_page_prep()
943 int (*cpo_prep)(const struct lu_env *env,
944 const struct cl_page_slice *slice,
947 * Completion handler. This is guaranteed to be eventually
948 * fired after cl_page_operations::cpo_prep() or
949 * cl_page_operations::cpo_make_ready() call.
951 * This method can be called in a non-blocking context. It is
952 * guaranteed however, that the page involved and its object
953 * are pinned in memory (and, hence, calling cl_page_put() is
956 * \see cl_page_completion()
958 void (*cpo_completion)(const struct lu_env *env,
959 const struct cl_page_slice *slice,
962 * Called when cached page is about to be added to the
963 * ptlrpc request as a part of req formation.
965 * \return 0 : proceed with this page;
966 * \return -EAGAIN : skip this page;
967 * \return -ve : error.
969 * \see cl_page_make_ready()
971 int (*cpo_make_ready)(const struct lu_env *env,
972 const struct cl_page_slice *slice);
975 * Tell transfer engine that only [to, from] part of a page should be
978 * This is used for immediate transfers.
980 * \todo XXX this is not very good interface. It would be much better
981 * if all transfer parameters were supplied as arguments to
982 * cl_io_operations::cio_submit() call, but it is not clear how to do
983 * this for page queues.
985 * \see cl_page_clip()
987 void (*cpo_clip)(const struct lu_env *env,
988 const struct cl_page_slice *slice,
991 * \pre the page was queued for transferring.
992 * \post page is removed from client's pending list, or -EBUSY
993 * is returned if it has already been in transferring.
995 * This is one of seldom page operation which is:
996 * 0. called from top level;
997 * 1. don't have vmpage locked;
998 * 2. every layer should synchronize execution of its ->cpo_cancel()
999 * with completion handlers. Osc uses client obd lock for this
1000 * purpose. Based on there is no vvp_page_cancel and
1001 * lov_page_cancel(), cpo_cancel is defacto protected by client lock.
1003 * \see osc_page_cancel().
1005 int (*cpo_cancel)(const struct lu_env *env,
1006 const struct cl_page_slice *slice);
1008 * Write out a page by kernel. This is only called by ll_writepage
1011 * \see cl_page_flush()
1013 int (*cpo_flush)(const struct lu_env *env,
1014 const struct cl_page_slice *slice,
1020 * Helper macro, dumping detailed information about \a page into a log.
1022 #define CL_PAGE_DEBUG(mask, env, page, format, ...) \
1024 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
1025 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, NULL); \
1026 cl_page_print(env, &msgdata, lu_cdebug_printer, page); \
1027 CDEBUG(mask, format , ## __VA_ARGS__); \
1032 * Helper macro, dumping shorter information about \a page into a log.
1034 #define CL_PAGE_HEADER(mask, env, page, format, ...) \
1036 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
1037 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, NULL); \
1038 cl_page_header_print(env, &msgdata, lu_cdebug_printer, page); \
1039 CDEBUG(mask, format , ## __VA_ARGS__); \
1043 static inline struct page *cl_page_vmpage(const struct cl_page *page)
1045 LASSERT(page->cp_vmpage != NULL);
1046 return page->cp_vmpage;
1050 * Check if a cl_page is in use.
1052 * Client cache holds a refcount, this refcount will be dropped when
1053 * the page is taken out of cache, see vvp_page_delete().
1055 static inline bool __page_in_use(const struct cl_page *page, int refc)
1057 return (atomic_read(&page->cp_ref) > refc + 1);
1061 * Caller itself holds a refcount of cl_page.
1063 #define cl_page_in_use(pg) __page_in_use(pg, 1)
1065 * Caller doesn't hold a refcount.
1067 #define cl_page_in_use_noref(pg) __page_in_use(pg, 0)
1071 /** \addtogroup cl_lock cl_lock
1075 * Extent locking on the client.
1079 * The locking model of the new client code is built around
1083 * data-type representing an extent lock on a regular file. cl_lock is a
1084 * layered object (much like cl_object and cl_page), it consists of a header
1085 * (struct cl_lock) and a list of layers (struct cl_lock_slice), linked to
1086 * cl_lock::cll_layers list through cl_lock_slice::cls_linkage.
1088 * Typical cl_lock consists of one layer:
1090 * - lov_lock (lov specific data).
1092 * lov_lock contains an array of sub-locks. Each of these sub-locks is a
1093 * normal cl_lock: it has a header (struct cl_lock) and a list of layers:
1097 * Each sub-lock is associated with a cl_object (representing stripe
1098 * sub-object or the file to which top-level cl_lock is associated to), and is
1099 * linked into that cl_object::coh_locks. In this respect cl_lock is similar to
1100 * cl_object (that at lov layer also fans out into multiple sub-objects), and
1101 * is different from cl_page, that doesn't fan out (there is usually exactly
1102 * one osc_page for every vvp_page). We shall call vvp-lov portion of the lock
1103 * a "top-lock" and its lovsub-osc portion a "sub-lock".
1107 * cl_lock is a cacheless data container for the requirements of locks to
1108 * complete the IO. cl_lock is created before I/O starts and destroyed when the
1111 * cl_lock depends on LDLM lock to fulfill lock semantics. LDLM lock is attached
1112 * to cl_lock at OSC layer. LDLM lock is still cacheable.
1114 * INTERFACE AND USAGE
1116 * Two major methods are supported for cl_lock: clo_enqueue and clo_cancel. A
1117 * cl_lock is enqueued by cl_lock_request(), which will call clo_enqueue()
1118 * methods for each layer to enqueue the lock. At the LOV layer, if a cl_lock
1119 * consists of multiple sub cl_locks, each sub locks will be enqueued
1120 * correspondingly. At OSC layer, the lock enqueue request will tend to reuse
1121 * cached LDLM lock; otherwise a new LDLM lock will have to be requested from
1124 * cl_lock_cancel() must be called to release a cl_lock after use. clo_cancel()
1125 * method will be called for each layer to release the resource held by this
1126 * lock. At OSC layer, the reference count of LDLM lock, which is held at
1127 * clo_enqueue time, is released.
1129 * LDLM lock can only be canceled if there is no cl_lock using it.
1131 * Overall process of the locking during IO operation is as following:
1133 * - once parameters for IO are setup in cl_io, cl_io_operations::cio_lock()
1134 * is called on each layer. Responsibility of this method is to add locks,
1135 * needed by a given layer into cl_io.ci_lockset.
1137 * - once locks for all layers were collected, they are sorted to avoid
1138 * dead-locks (cl_io_locks_sort()), and enqueued.
1140 * - when all locks are acquired, IO is performed;
1142 * - locks are released after IO is complete.
1144 * Striping introduces major additional complexity into locking. The
1145 * fundamental problem is that it is generally unsafe to actively use (hold)
1146 * two locks on the different OST servers at the same time, as this introduces
1147 * inter-server dependency and can lead to cascading evictions.
1149 * Basic solution is to sub-divide large read/write IOs into smaller pieces so
1150 * that no multi-stripe locks are taken (note that this design abandons POSIX
1151 * read/write semantics). Such pieces ideally can be executed concurrently. At
1152 * the same time, certain types of IO cannot be sub-divived, without
1153 * sacrificing correctness. This includes:
1155 * - O_APPEND write, where [0, EOF] lock has to be taken, to guarantee
1158 * - ftruncate(fd, offset), where [offset, EOF] lock has to be taken.
1160 * Also, in the case of read(fd, buf, count) or write(fd, buf, count), where
1161 * buf is a part of memory mapped Lustre file, a lock or locks protecting buf
1162 * has to be held together with the usual lock on [offset, offset + count].
1164 * Interaction with DLM
1166 * In the expected setup, cl_lock is ultimately backed up by a collection of
1167 * DLM locks (struct ldlm_lock). Association between cl_lock and DLM lock is
1168 * implemented in osc layer, that also matches DLM events (ASTs, cancellation,
1169 * etc.) into cl_lock_operation calls. See struct osc_lock for a more detailed
1170 * description of interaction with DLM.
1176 struct cl_lock_descr {
1177 /** Object this lock is granted for. */
1178 struct cl_object *cld_obj;
1179 /** Index of the first page protected by this lock. */
1181 /** Index of the last page (inclusive) protected by this lock. */
1183 /** Group ID, for group lock */
1186 enum cl_lock_mode cld_mode;
1188 * flags to enqueue lock. A combination of bit-flags from
1189 * enum cl_enq_flags.
1191 __u32 cld_enq_flags;
1194 #define DDESCR "%s(%d):[%lu, %lu]:%x"
1195 #define PDESCR(descr) \
1196 cl_lock_mode_name((descr)->cld_mode), (descr)->cld_mode, \
1197 (descr)->cld_start, (descr)->cld_end, (descr)->cld_enq_flags
1199 const char *cl_lock_mode_name(const enum cl_lock_mode mode);
1202 * Layered client lock.
1205 /** List of slices. Immutable after creation. */
1206 struct list_head cll_layers;
1207 /** lock attribute, extent, cl_object, etc. */
1208 struct cl_lock_descr cll_descr;
1212 * Per-layer part of cl_lock
1214 * \see lov_lock, osc_lock
1216 struct cl_lock_slice {
1217 struct cl_lock *cls_lock;
1218 /** Object slice corresponding to this lock slice. Immutable after
1220 struct cl_object *cls_obj;
1221 const struct cl_lock_operations *cls_ops;
1222 /** Linkage into cl_lock::cll_layers. Immutable after creation. */
1223 struct list_head cls_linkage;
1228 * \see lov_lock_ops, osc_lock_ops
1230 struct cl_lock_operations {
1233 * Attempts to enqueue the lock. Called top-to-bottom.
1235 * \retval 0 this layer has enqueued the lock successfully
1236 * \retval >0 this layer has enqueued the lock, but need to wait on
1237 * @anchor for resources
1238 * \retval -ve failure
1240 * \see lov_lock_enqueue(), osc_lock_enqueue()
1242 int (*clo_enqueue)(const struct lu_env *env,
1243 const struct cl_lock_slice *slice,
1244 struct cl_io *io, struct cl_sync_io *anchor);
1246 * Cancel a lock, release its DLM lock ref, while does not cancel the
1249 void (*clo_cancel)(const struct lu_env *env,
1250 const struct cl_lock_slice *slice);
1253 * Destructor. Frees resources and the slice.
1255 * \see lov_lock_fini(), osc_lock_fini()
1257 void (*clo_fini)(const struct lu_env *env, struct cl_lock_slice *slice);
1259 * Optional debugging helper. Prints given lock slice.
1261 int (*clo_print)(const struct lu_env *env,
1262 void *cookie, lu_printer_t p,
1263 const struct cl_lock_slice *slice);
1266 #define CL_LOCK_DEBUG(mask, env, lock, format, ...) \
1268 if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) { \
1269 LIBCFS_DEBUG_MSG_DATA_DECL(msgdata, mask, NULL); \
1270 cl_lock_print(env, &msgdata, lu_cdebug_printer, lock); \
1271 CDEBUG(mask, format , ## __VA_ARGS__); \
1275 #define CL_LOCK_ASSERT(expr, env, lock) do { \
1279 CL_LOCK_DEBUG(D_ERROR, env, lock, "failed at %s.\n", #expr); \
1285 /** \addtogroup cl_page_list cl_page_list
1286 * Page list used to perform collective operations on a group of pages.
1288 * Pages are added to the list one by one. cl_page_list acquires a reference
1289 * for every page in it. Page list is used to perform collective operations on
1292 * - submit pages for an immediate transfer,
1294 * - own pages on behalf of certain io (waiting for each page in turn),
1298 * When list is finalized, it releases references on all pages it still has.
1300 * \todo XXX concurrency control.
1304 struct cl_page_list {
1306 struct list_head pl_pages;
1307 struct task_struct *pl_owner;
1311 * A 2-queue of pages. A convenience data-type for common use case, 2-queue
1312 * contains an incoming page list and an outgoing page list.
1315 struct cl_page_list c2_qin;
1316 struct cl_page_list c2_qout;
1319 /** @} cl_page_list */
1321 /** \addtogroup cl_io cl_io
1326 * cl_io represents a high level I/O activity like
1327 * read(2)/write(2)/truncate(2) system call, or cancellation of an extent
1330 * cl_io is a layered object, much like cl_{object,page,lock} but with one
1331 * important distinction. We want to minimize number of calls to the allocator
1332 * in the fast path, e.g., in the case of read(2) when everything is cached:
1333 * client already owns the lock over region being read, and data are cached
1334 * due to read-ahead. To avoid allocation of cl_io layers in such situations,
1335 * per-layer io state is stored in the session, associated with the io, see
1336 * struct {vvp,lov,osc}_io for example. Sessions allocation is amortized
1337 * by using free-lists, see cl_env_get().
1339 * There is a small predefined number of possible io types, enumerated in enum
1342 * cl_io is a state machine, that can be advanced concurrently by the multiple
1343 * threads. It is up to these threads to control the concurrency and,
1344 * specifically, to detect when io is done, and its state can be safely
1347 * For read/write io overall execution plan is as following:
1349 * (0) initialize io state through all layers;
1351 * (1) loop: prepare chunk of work to do
1353 * (2) call all layers to collect locks they need to process current chunk
1355 * (3) sort all locks to avoid dead-locks, and acquire them
1357 * (4) process the chunk: call per-page methods
1358 * cl_io_operations::cio_prepare_write(),
1359 * cl_io_operations::cio_commit_write() for write)
1365 * To implement the "parallel IO mode", lov layer creates sub-io's (lazily to
1366 * address allocation efficiency issues mentioned above), and returns with the
1367 * special error condition from per-page method when current sub-io has to
1368 * block. This causes io loop to be repeated, and lov switches to the next
1369 * sub-io in its cl_io_operations::cio_iter_init() implementation.
1374 /** read system call */
1376 /** write system call */
1378 /** truncate, utime system calls */
1380 /** get data version */
1383 * page fault handling
1387 * fsync system call handling
1388 * To write out a range of file
1392 * glimpse. An io context to acquire glimpse lock.
1396 * Miscellaneous io. This is used for occasional io activity that
1397 * doesn't fit into other types. Currently this is used for:
1399 * - cancellation of an extent lock. This io exists as a context
1400 * to write dirty pages from under the lock being canceled back
1403 * - VM induced page write-out. An io context for writing page out
1404 * for memory cleansing;
1406 * - grouplock. An io context to acquire group lock.
1408 * CIT_MISC io is used simply as a context in which locks and pages
1409 * are manipulated. Such io has no internal "process", that is,
1410 * cl_io_loop() is never called for it.
1415 * To give advice about access of a file
1422 * States of cl_io state machine
1425 /** Not initialized. */
1429 /** IO iteration started. */
1433 /** Actual IO is in progress. */
1435 /** IO for the current iteration finished. */
1437 /** Locks released. */
1439 /** Iteration completed. */
1441 /** cl_io finalized. */
1446 * IO state private for a layer.
1448 * This is usually embedded into layer session data, rather than allocated
1451 * \see vvp_io, lov_io, osc_io
1453 struct cl_io_slice {
1454 struct cl_io *cis_io;
1455 /** corresponding object slice. Immutable after creation. */
1456 struct cl_object *cis_obj;
1457 /** io operations. Immutable after creation. */
1458 const struct cl_io_operations *cis_iop;
1460 * linkage into a list of all slices for a given cl_io, hanging off
1461 * cl_io::ci_layers. Immutable after creation.
1463 struct list_head cis_linkage;
1466 typedef void (*cl_commit_cbt)(const struct lu_env *, struct cl_io *,
1469 struct cl_read_ahead {
1470 /* Maximum page index the readahead window will end.
1471 * This is determined DLM lock coverage, RPC and stripe boundary.
1472 * cra_end is included. */
1474 /* optimal RPC size for this read, by pages */
1475 unsigned long cra_rpc_size;
1476 /* Release callback. If readahead holds resources underneath, this
1477 * function should be called to release it. */
1478 void (*cra_release)(const struct lu_env *env, void *cbdata);
1479 /* Callback data for cra_release routine */
1483 static inline void cl_read_ahead_release(const struct lu_env *env,
1484 struct cl_read_ahead *ra)
1486 if (ra->cra_release != NULL)
1487 ra->cra_release(env, ra->cra_cbdata);
1488 memset(ra, 0, sizeof(*ra));
1493 * Per-layer io operations.
1494 * \see vvp_io_ops, lov_io_ops, lovsub_io_ops, osc_io_ops
1496 struct cl_io_operations {
1498 * Vector of io state transition methods for every io type.
1500 * \see cl_page_operations::io
1504 * Prepare io iteration at a given layer.
1506 * Called top-to-bottom at the beginning of each iteration of
1507 * "io loop" (if it makes sense for this type of io). Here
1508 * layer selects what work it will do during this iteration.
1510 * \see cl_io_operations::cio_iter_fini()
1512 int (*cio_iter_init) (const struct lu_env *env,
1513 const struct cl_io_slice *slice);
1515 * Finalize io iteration.
1517 * Called bottom-to-top at the end of each iteration of "io
1518 * loop". Here layers can decide whether IO has to be
1521 * \see cl_io_operations::cio_iter_init()
1523 void (*cio_iter_fini) (const struct lu_env *env,
1524 const struct cl_io_slice *slice);
1526 * Collect locks for the current iteration of io.
1528 * Called top-to-bottom to collect all locks necessary for
1529 * this iteration. This methods shouldn't actually enqueue
1530 * anything, instead it should post a lock through
1531 * cl_io_lock_add(). Once all locks are collected, they are
1532 * sorted and enqueued in the proper order.
1534 int (*cio_lock) (const struct lu_env *env,
1535 const struct cl_io_slice *slice);
1537 * Finalize unlocking.
1539 * Called bottom-to-top to finish layer specific unlocking
1540 * functionality, after generic code released all locks
1541 * acquired by cl_io_operations::cio_lock().
1543 void (*cio_unlock)(const struct lu_env *env,
1544 const struct cl_io_slice *slice);
1546 * Start io iteration.
1548 * Once all locks are acquired, called top-to-bottom to
1549 * commence actual IO. In the current implementation,
1550 * top-level vvp_io_{read,write}_start() does all the work
1551 * synchronously by calling generic_file_*(), so other layers
1552 * are called when everything is done.
1554 int (*cio_start)(const struct lu_env *env,
1555 const struct cl_io_slice *slice);
1557 * Called top-to-bottom at the end of io loop. Here layer
1558 * might wait for an unfinished asynchronous io.
1560 void (*cio_end) (const struct lu_env *env,
1561 const struct cl_io_slice *slice);
1563 * Called bottom-to-top to notify layers that read/write IO
1564 * iteration finished, with \a nob bytes transferred.
1566 void (*cio_advance)(const struct lu_env *env,
1567 const struct cl_io_slice *slice,
1570 * Called once per io, bottom-to-top to release io resources.
1572 void (*cio_fini) (const struct lu_env *env,
1573 const struct cl_io_slice *slice);
1577 * Submit pages from \a queue->c2_qin for IO, and move
1578 * successfully submitted pages into \a queue->c2_qout. Return
1579 * non-zero if failed to submit even the single page. If
1580 * submission failed after some pages were moved into \a
1581 * queue->c2_qout, completion callback with non-zero ioret is
1584 int (*cio_submit)(const struct lu_env *env,
1585 const struct cl_io_slice *slice,
1586 enum cl_req_type crt,
1587 struct cl_2queue *queue);
1589 * Queue async page for write.
1590 * The difference between cio_submit and cio_queue is that
1591 * cio_submit is for urgent request.
1593 int (*cio_commit_async)(const struct lu_env *env,
1594 const struct cl_io_slice *slice,
1595 struct cl_page_list *queue, int from, int to,
1598 * Decide maximum read ahead extent
1600 * \pre io->ci_type == CIT_READ
1602 int (*cio_read_ahead)(const struct lu_env *env,
1603 const struct cl_io_slice *slice,
1604 pgoff_t start, struct cl_read_ahead *ra);
1606 * Optional debugging helper. Print given io slice.
1608 int (*cio_print)(const struct lu_env *env, void *cookie,
1609 lu_printer_t p, const struct cl_io_slice *slice);
1613 * Flags to lock enqueue procedure.
1618 * instruct server to not block, if conflicting lock is found. Instead
1619 * -EWOULDBLOCK is returned immediately.
1621 CEF_NONBLOCK = 0x00000001,
1623 * Tell lower layers this is a glimpse request, translated to
1624 * LDLM_FL_HAS_INTENT at LDLM layer.
1626 * Also, because glimpse locks never block other locks, we count this
1627 * as automatically compatible with other osc locks.
1628 * (see osc_lock_compatible)
1630 CEF_GLIMPSE = 0x00000002,
1632 * tell the server to instruct (though a flag in the blocking ast) an
1633 * owner of the conflicting lock, that it can drop dirty pages
1634 * protected by this lock, without sending them to the server.
1636 CEF_DISCARD_DATA = 0x00000004,
1638 * tell the sub layers that it must be a `real' lock. This is used for
1639 * mmapped-buffer locks, glimpse locks, manually requested locks
1640 * (LU_LADVISE_LOCKAHEAD) that must never be converted into lockless
1643 * \see vvp_mmap_locks(), cl_glimpse_lock, cl_request_lock().
1645 CEF_MUST = 0x00000008,
1647 * tell the sub layers that never request a `real' lock. This flag is
1648 * not used currently.
1650 * cl_io::ci_lockreq and CEF_{MUST,NEVER} flags specify lockless
1651 * conversion policy: ci_lockreq describes generic information of lock
1652 * requirement for this IO, especially for locks which belong to the
1653 * object doing IO; however, lock itself may have precise requirements
1654 * that are described by the enqueue flags.
1656 CEF_NEVER = 0x00000010,
1658 * tell the dlm layer this is a speculative lock request
1659 * speculative lock requests are locks which are not requested as part
1660 * of an I/O operation. Instead, they are requested because we expect
1661 * to use them in the future. They are requested asynchronously at the
1664 * Currently used for asynchronous glimpse locks and manually requested
1665 * locks (LU_LADVISE_LOCKAHEAD).
1667 CEF_SPECULATIVE = 0x00000020,
1669 * enqueue a lock to test DLM lock existence.
1671 CEF_PEEK = 0x00000040,
1673 * Lock match only. Used by group lock in I/O as group lock
1674 * is known to exist.
1676 CEF_LOCK_MATCH = 0x00000080,
1678 * tell the DLM layer to lock only the requested range
1680 CEF_LOCK_NO_EXPAND = 0x00000100,
1682 * mask of enq_flags.
1684 CEF_MASK = 0x000001ff,
1688 * Link between lock and io. Intermediate structure is needed, because the
1689 * same lock can be part of multiple io's simultaneously.
1691 struct cl_io_lock_link {
1692 /** linkage into one of cl_lockset lists. */
1693 struct list_head cill_linkage;
1694 struct cl_lock cill_lock;
1695 /** optional destructor */
1696 void (*cill_fini)(const struct lu_env *env,
1697 struct cl_io_lock_link *link);
1699 #define cill_descr cill_lock.cll_descr
1702 * Lock-set represents a collection of locks, that io needs at a
1703 * time. Generally speaking, client tries to avoid holding multiple locks when
1706 * - holding extent locks over multiple ost's introduces the danger of
1707 * "cascading timeouts";
1709 * - holding multiple locks over the same ost is still dead-lock prone,
1710 * see comment in osc_lock_enqueue(),
1712 * but there are certain situations where this is unavoidable:
1714 * - O_APPEND writes have to take [0, EOF] lock for correctness;
1716 * - truncate has to take [new-size, EOF] lock for correctness;
1718 * - SNS has to take locks across full stripe for correctness;
1720 * - in the case when user level buffer, supplied to {read,write}(file0),
1721 * is a part of a memory mapped lustre file, client has to take a dlm
1722 * locks on file0, and all files that back up the buffer (or a part of
1723 * the buffer, that is being processed in the current chunk, in any
1724 * case, there are situations where at least 2 locks are necessary).
1726 * In such cases we at least try to take locks in the same consistent
1727 * order. To this end, all locks are first collected, then sorted, and then
1731 /** locks to be acquired. */
1732 struct list_head cls_todo;
1733 /** locks acquired. */
1734 struct list_head cls_done;
1738 * Lock requirements(demand) for IO. It should be cl_io_lock_req,
1739 * but 'req' is always to be thought as 'request' :-)
1741 enum cl_io_lock_dmd {
1742 /** Always lock data (e.g., O_APPEND). */
1744 /** Layers are free to decide between local and global locking. */
1746 /** Never lock: there is no cache (e.g., liblustre). */
1750 enum cl_fsync_mode {
1751 /** start writeback, do not wait for them to finish */
1753 /** start writeback and wait for them to finish */
1755 /** discard all of dirty pages in a specific file range */
1756 CL_FSYNC_DISCARD = 2,
1757 /** start writeback and make sure they have reached storage before
1758 * return. OST_SYNC RPC must be issued and finished */
1762 struct cl_io_range {
1768 struct cl_io_pt *cip_next;
1769 struct cfs_ptask cip_task;
1770 struct kiocb cip_iocb;
1771 struct iov_iter cip_iter;
1772 struct file *cip_file;
1773 enum cl_io_type cip_iot;
1774 unsigned int cip_need_restart:1;
1783 * cl_io is shared by all threads participating in this IO (in current
1784 * implementation only one thread advances IO, but parallel IO design and
1785 * concurrent copy_*_user() require multiple threads acting on the same IO. It
1786 * is up to these threads to serialize their activities, including updates to
1787 * mutable cl_io fields.
1790 /** type of this IO. Immutable after creation. */
1791 enum cl_io_type ci_type;
1792 /** current state of cl_io state machine. */
1793 enum cl_io_state ci_state;
1794 /** main object this io is against. Immutable after creation. */
1795 struct cl_object *ci_obj;
1797 * Upper layer io, of which this io is a part of. Immutable after
1800 struct cl_io *ci_parent;
1801 /** List of slices. Immutable after creation. */
1802 struct list_head ci_layers;
1803 /** list of locks (to be) acquired by this io. */
1804 struct cl_lockset ci_lockset;
1805 /** lock requirements, this is just a help info for sublayers. */
1806 enum cl_io_lock_dmd ci_lockreq;
1807 /** layout version when this IO occurs */
1808 __u32 ci_layout_version;
1811 struct iov_iter rw_iter;
1812 struct kiocb rw_iocb;
1813 struct cl_io_range rw_range;
1814 struct file *rw_file;
1815 unsigned int rw_nonblock:1,
1818 int (*rw_ptask)(struct cfs_ptask *ptask);
1820 struct cl_setattr_io {
1821 struct ost_lvb sa_attr;
1822 unsigned int sa_attr_flags;
1823 unsigned int sa_avalid; /* ATTR_* */
1824 unsigned int sa_xvalid; /* OP_XVALID */
1825 int sa_stripe_index;
1826 struct ost_layout sa_layout;
1827 const struct lu_fid *sa_parent_fid;
1829 struct cl_data_version_io {
1830 u64 dv_data_version;
1831 u32 dv_layout_version;
1834 struct cl_fault_io {
1835 /** page index within file. */
1837 /** bytes valid byte on a faulted page. */
1839 /** writable page? for nopage() only */
1841 /** page of an executable? */
1843 /** page_mkwrite() */
1845 /** resulting page */
1846 struct cl_page *ft_page;
1848 struct cl_fsync_io {
1851 /** file system level fid */
1852 struct lu_fid *fi_fid;
1853 enum cl_fsync_mode fi_mode;
1854 /* how many pages were written/discarded */
1855 unsigned int fi_nr_written;
1857 struct cl_ladvise_io {
1860 /** file system level fid */
1861 struct lu_fid *li_fid;
1862 enum lu_ladvise_type li_advice;
1866 struct cl_2queue ci_queue;
1869 unsigned int ci_continue:1,
1871 * This io has held grouplock, to inform sublayers that
1872 * don't do lockless i/o.
1876 * The whole IO need to be restarted because layout has been changed
1880 * to not refresh layout - the IO issuer knows that the layout won't
1881 * change(page operations, layout change causes all page to be
1882 * discarded), or it doesn't matter if it changes(sync).
1886 * Need MDS intervention to complete a write.
1887 * Write intent is required for the following cases:
1888 * 1. component being written is not initialized, or
1889 * 2. the mirrored files are NOT in WRITE_PENDING state.
1891 ci_need_write_intent:1,
1893 * Check if layout changed after the IO finishes. Mainly for HSM
1894 * requirement. If IO occurs to openning files, it doesn't need to
1895 * verify layout because HSM won't release openning files.
1896 * Right now, only two opertaions need to verify layout: glimpse
1901 * file is released, restore has to to be triggered by vvp layer
1903 ci_restore_needed:1,
1908 /** Set to 1 if parallel execution is allowed for current I/O? */
1910 /* Tell sublayers not to expand LDLM locks requested for this IO */
1911 ci_lock_no_expand:1,
1913 * Set if non-delay RPC should be used for this IO.
1915 * If this file has multiple mirrors, and if the OSTs of the current
1916 * mirror is inaccessible, non-delay RPC would error out quickly so
1917 * that the upper layer can try to access the next mirror.
1921 * How many times the read has retried before this one.
1922 * Set by the top level and consumed by the LOV.
1924 unsigned ci_ndelay_tried;
1926 * Designated mirror index for this I/O.
1928 unsigned ci_designated_mirror;
1930 * Number of pages owned by this IO. For invariant checking.
1932 unsigned ci_owned_nr;
1934 * Range of write intent. Valid if ci_need_write_intent is set.
1936 struct lu_extent ci_write_intent;
1942 * Per-transfer attributes.
1944 struct cl_req_attr {
1945 enum cl_req_type cra_type;
1947 struct cl_page *cra_page;
1948 /** Generic attributes for the server consumption. */
1949 struct obdo *cra_oa;
1951 char cra_jobid[LUSTRE_JOBID_SIZE];
1954 enum cache_stats_item {
1955 /** how many cache lookups were performed */
1957 /** how many times cache lookup resulted in a hit */
1959 /** how many entities are in the cache right now */
1961 /** how many entities in the cache are actively used (and cannot be
1962 * evicted) right now */
1964 /** how many entities were created at all */
1969 #define CS_NAMES { "lookup", "hit", "total", "busy", "create" }
1972 * Stats for a generic cache (similar to inode, lu_object, etc. caches).
1974 struct cache_stats {
1975 const char *cs_name;
1976 atomic_t cs_stats[CS_NR];
1979 /** These are not exported so far */
1980 void cache_stats_init (struct cache_stats *cs, const char *name);
1983 * Client-side site. This represents particular client stack. "Global"
1984 * variables should (directly or indirectly) be added here to allow multiple
1985 * clients to co-exist in the single address space.
1988 struct lu_site cs_lu;
1990 * Statistical counters. Atomics do not scale, something better like
1991 * per-cpu counters is needed.
1993 * These are exported as /proc/fs/lustre/llite/.../site
1995 * When interpreting keep in mind that both sub-locks (and sub-pages)
1996 * and top-locks (and top-pages) are accounted here.
1998 struct cache_stats cs_pages;
1999 atomic_t cs_pages_state[CPS_NR];
2002 int cl_site_init(struct cl_site *s, struct cl_device *top);
2003 void cl_site_fini(struct cl_site *s);
2004 void cl_stack_fini(const struct lu_env *env, struct cl_device *cl);
2007 * Output client site statistical counters into a buffer. Suitable for
2008 * ll_rd_*()-style functions.
2010 int cl_site_stats_print(const struct cl_site *site, struct seq_file *m);
2015 * Type conversion and accessory functions.
2019 static inline struct cl_site *lu2cl_site(const struct lu_site *site)
2021 return container_of(site, struct cl_site, cs_lu);
2024 static inline struct cl_device *lu2cl_dev(const struct lu_device *d)
2026 LASSERT(d == NULL || IS_ERR(d) || lu_device_is_cl(d));
2027 return container_of0(d, struct cl_device, cd_lu_dev);
2030 static inline struct lu_device *cl2lu_dev(struct cl_device *d)
2032 return &d->cd_lu_dev;
2035 static inline struct cl_object *lu2cl(const struct lu_object *o)
2037 LASSERT(o == NULL || IS_ERR(o) || lu_device_is_cl(o->lo_dev));
2038 return container_of0(o, struct cl_object, co_lu);
2041 static inline const struct cl_object_conf *
2042 lu2cl_conf(const struct lu_object_conf *conf)
2044 return container_of0(conf, struct cl_object_conf, coc_lu);
2047 static inline struct cl_object *cl_object_next(const struct cl_object *obj)
2049 return obj ? lu2cl(lu_object_next(&obj->co_lu)) : NULL;
2052 static inline struct cl_object_header *luh2coh(const struct lu_object_header *h)
2054 return container_of0(h, struct cl_object_header, coh_lu);
2057 static inline struct cl_site *cl_object_site(const struct cl_object *obj)
2059 return lu2cl_site(obj->co_lu.lo_dev->ld_site);
2063 struct cl_object_header *cl_object_header(const struct cl_object *obj)
2065 return luh2coh(obj->co_lu.lo_header);
2068 static inline int cl_device_init(struct cl_device *d, struct lu_device_type *t)
2070 return lu_device_init(&d->cd_lu_dev, t);
2073 static inline void cl_device_fini(struct cl_device *d)
2075 lu_device_fini(&d->cd_lu_dev);
2078 void cl_page_slice_add(struct cl_page *page, struct cl_page_slice *slice,
2079 struct cl_object *obj, pgoff_t index,
2080 const struct cl_page_operations *ops);
2081 void cl_lock_slice_add(struct cl_lock *lock, struct cl_lock_slice *slice,
2082 struct cl_object *obj,
2083 const struct cl_lock_operations *ops);
2084 void cl_io_slice_add(struct cl_io *io, struct cl_io_slice *slice,
2085 struct cl_object *obj, const struct cl_io_operations *ops);
2088 /** \defgroup cl_object cl_object
2090 struct cl_object *cl_object_top (struct cl_object *o);
2091 struct cl_object *cl_object_find(const struct lu_env *env, struct cl_device *cd,
2092 const struct lu_fid *fid,
2093 const struct cl_object_conf *c);
2095 int cl_object_header_init(struct cl_object_header *h);
2096 void cl_object_header_fini(struct cl_object_header *h);
2097 void cl_object_put (const struct lu_env *env, struct cl_object *o);
2098 void cl_object_get (struct cl_object *o);
2099 void cl_object_attr_lock (struct cl_object *o);
2100 void cl_object_attr_unlock(struct cl_object *o);
2101 int cl_object_attr_get(const struct lu_env *env, struct cl_object *obj,
2102 struct cl_attr *attr);
2103 int cl_object_attr_update(const struct lu_env *env, struct cl_object *obj,
2104 const struct cl_attr *attr, unsigned valid);
2105 int cl_object_glimpse (const struct lu_env *env, struct cl_object *obj,
2106 struct ost_lvb *lvb);
2107 int cl_conf_set (const struct lu_env *env, struct cl_object *obj,
2108 const struct cl_object_conf *conf);
2109 int cl_object_prune (const struct lu_env *env, struct cl_object *obj);
2110 void cl_object_kill (const struct lu_env *env, struct cl_object *obj);
2111 int cl_object_getstripe(const struct lu_env *env, struct cl_object *obj,
2112 struct lov_user_md __user *lum, size_t size);
2113 int cl_object_fiemap(const struct lu_env *env, struct cl_object *obj,
2114 struct ll_fiemap_info_key *fmkey, struct fiemap *fiemap,
2116 int cl_object_layout_get(const struct lu_env *env, struct cl_object *obj,
2117 struct cl_layout *cl);
2118 loff_t cl_object_maxbytes(struct cl_object *obj);
2121 * Returns true, iff \a o0 and \a o1 are slices of the same object.
2123 static inline int cl_object_same(struct cl_object *o0, struct cl_object *o1)
2125 return cl_object_header(o0) == cl_object_header(o1);
2128 static inline void cl_object_page_init(struct cl_object *clob, int size)
2130 clob->co_slice_off = cl_object_header(clob)->coh_page_bufsize;
2131 cl_object_header(clob)->coh_page_bufsize += cfs_size_round(size);
2132 WARN_ON(cl_object_header(clob)->coh_page_bufsize > 512);
2135 static inline void *cl_object_page_slice(struct cl_object *clob,
2136 struct cl_page *page)
2138 return (void *)((char *)page + clob->co_slice_off);
2142 * Return refcount of cl_object.
2144 static inline int cl_object_refc(struct cl_object *clob)
2146 struct lu_object_header *header = clob->co_lu.lo_header;
2147 return atomic_read(&header->loh_ref);
2152 /** \defgroup cl_page cl_page
2160 /* callback of cl_page_gang_lookup() */
2162 struct cl_page *cl_page_find (const struct lu_env *env,
2163 struct cl_object *obj,
2164 pgoff_t idx, struct page *vmpage,
2165 enum cl_page_type type);
2166 struct cl_page *cl_page_alloc (const struct lu_env *env,
2167 struct cl_object *o, pgoff_t ind,
2168 struct page *vmpage,
2169 enum cl_page_type type);
2170 void cl_page_get (struct cl_page *page);
2171 void cl_page_put (const struct lu_env *env,
2172 struct cl_page *page);
2173 void cl_pagevec_put (const struct lu_env *env,
2174 struct cl_page *page,
2175 struct pagevec *pvec);
2176 void cl_page_print (const struct lu_env *env, void *cookie,
2177 lu_printer_t printer,
2178 const struct cl_page *pg);
2179 void cl_page_header_print(const struct lu_env *env, void *cookie,
2180 lu_printer_t printer,
2181 const struct cl_page *pg);
2182 struct cl_page *cl_vmpage_page (struct page *vmpage, struct cl_object *obj);
2183 struct cl_page *cl_page_top (struct cl_page *page);
2185 const struct cl_page_slice *cl_page_at(const struct cl_page *page,
2186 const struct lu_device_type *dtype);
2191 * Functions dealing with the ownership of page by io.
2195 int cl_page_own (const struct lu_env *env,
2196 struct cl_io *io, struct cl_page *page);
2197 int cl_page_own_try (const struct lu_env *env,
2198 struct cl_io *io, struct cl_page *page);
2199 void cl_page_assume (const struct lu_env *env,
2200 struct cl_io *io, struct cl_page *page);
2201 void cl_page_unassume (const struct lu_env *env,
2202 struct cl_io *io, struct cl_page *pg);
2203 void cl_page_disown (const struct lu_env *env,
2204 struct cl_io *io, struct cl_page *page);
2205 int cl_page_is_owned (const struct cl_page *pg, const struct cl_io *io);
2212 * Functions dealing with the preparation of a page for a transfer, and
2213 * tracking transfer state.
2216 int cl_page_prep (const struct lu_env *env, struct cl_io *io,
2217 struct cl_page *pg, enum cl_req_type crt);
2218 void cl_page_completion (const struct lu_env *env,
2219 struct cl_page *pg, enum cl_req_type crt, int ioret);
2220 int cl_page_make_ready (const struct lu_env *env, struct cl_page *pg,
2221 enum cl_req_type crt);
2222 int cl_page_cache_add (const struct lu_env *env, struct cl_io *io,
2223 struct cl_page *pg, enum cl_req_type crt);
2224 void cl_page_clip (const struct lu_env *env, struct cl_page *pg,
2226 int cl_page_cancel (const struct lu_env *env, struct cl_page *page);
2227 int cl_page_flush (const struct lu_env *env, struct cl_io *io,
2228 struct cl_page *pg);
2234 * \name helper routines
2235 * Functions to discard, delete and export a cl_page.
2238 void cl_page_discard(const struct lu_env *env, struct cl_io *io,
2239 struct cl_page *pg);
2240 void cl_page_delete(const struct lu_env *env, struct cl_page *pg);
2241 int cl_page_is_vmlocked(const struct lu_env *env,
2242 const struct cl_page *pg);
2243 void cl_page_touch(const struct lu_env *env, const struct cl_page *pg,
2245 void cl_page_export(const struct lu_env *env,
2246 struct cl_page *pg, int uptodate);
2247 loff_t cl_offset(const struct cl_object *obj, pgoff_t idx);
2248 pgoff_t cl_index(const struct cl_object *obj, loff_t offset);
2249 size_t cl_page_size(const struct cl_object *obj);
2251 void cl_lock_print(const struct lu_env *env, void *cookie,
2252 lu_printer_t printer, const struct cl_lock *lock);
2253 void cl_lock_descr_print(const struct lu_env *env, void *cookie,
2254 lu_printer_t printer,
2255 const struct cl_lock_descr *descr);
2259 * Data structure managing a client's cached pages. A count of
2260 * "unstable" pages is maintained, and an LRU of clean pages is
2261 * maintained. "unstable" pages are pages pinned by the ptlrpc
2262 * layer for recovery purposes.
2264 struct cl_client_cache {
2266 * # of client cache refcount
2267 * # of users (OSCs) + 2 (held by llite and lov)
2271 * # of threads are doing shrinking
2273 unsigned int ccc_lru_shrinkers;
2275 * # of LRU entries available
2277 atomic_long_t ccc_lru_left;
2279 * List of entities(OSCs) for this LRU cache
2281 struct list_head ccc_lru;
2283 * Max # of LRU entries
2285 unsigned long ccc_lru_max;
2287 * Lock to protect ccc_lru list
2289 spinlock_t ccc_lru_lock;
2291 * Set if unstable check is enabled
2293 unsigned int ccc_unstable_check:1;
2295 * # of unstable pages for this mount point
2297 atomic_long_t ccc_unstable_nr;
2299 * Waitq for awaiting unstable pages to reach zero.
2300 * Used at umounting time and signaled on BRW commit
2302 wait_queue_head_t ccc_unstable_waitq;
2305 * cl_cache functions
2307 struct cl_client_cache *cl_cache_init(unsigned long lru_page_max);
2308 void cl_cache_incref(struct cl_client_cache *cache);
2309 void cl_cache_decref(struct cl_client_cache *cache);
2313 /** \defgroup cl_lock cl_lock
2315 int cl_lock_request(const struct lu_env *env, struct cl_io *io,
2316 struct cl_lock *lock);
2317 int cl_lock_init(const struct lu_env *env, struct cl_lock *lock,
2318 const struct cl_io *io);
2319 void cl_lock_fini(const struct lu_env *env, struct cl_lock *lock);
2320 const struct cl_lock_slice *cl_lock_at(const struct cl_lock *lock,
2321 const struct lu_device_type *dtype);
2322 void cl_lock_release(const struct lu_env *env, struct cl_lock *lock);
2324 int cl_lock_enqueue(const struct lu_env *env, struct cl_io *io,
2325 struct cl_lock *lock, struct cl_sync_io *anchor);
2326 void cl_lock_cancel(const struct lu_env *env, struct cl_lock *lock);
2330 /** \defgroup cl_io cl_io
2333 int cl_io_init (const struct lu_env *env, struct cl_io *io,
2334 enum cl_io_type iot, struct cl_object *obj);
2335 int cl_io_sub_init (const struct lu_env *env, struct cl_io *io,
2336 enum cl_io_type iot, struct cl_object *obj);
2337 int cl_io_rw_init (const struct lu_env *env, struct cl_io *io,
2338 enum cl_io_type iot, loff_t pos, size_t count);
2339 int cl_io_loop (const struct lu_env *env, struct cl_io *io);
2341 void cl_io_fini (const struct lu_env *env, struct cl_io *io);
2342 int cl_io_iter_init (const struct lu_env *env, struct cl_io *io);
2343 void cl_io_iter_fini (const struct lu_env *env, struct cl_io *io);
2344 int cl_io_lock (const struct lu_env *env, struct cl_io *io);
2345 void cl_io_unlock (const struct lu_env *env, struct cl_io *io);
2346 int cl_io_start (const struct lu_env *env, struct cl_io *io);
2347 void cl_io_end (const struct lu_env *env, struct cl_io *io);
2348 int cl_io_lock_add (const struct lu_env *env, struct cl_io *io,
2349 struct cl_io_lock_link *link);
2350 int cl_io_lock_alloc_add(const struct lu_env *env, struct cl_io *io,
2351 struct cl_lock_descr *descr);
2352 int cl_io_submit_rw (const struct lu_env *env, struct cl_io *io,
2353 enum cl_req_type iot, struct cl_2queue *queue);
2354 int cl_io_submit_sync (const struct lu_env *env, struct cl_io *io,
2355 enum cl_req_type iot, struct cl_2queue *queue,
2357 int cl_io_commit_async (const struct lu_env *env, struct cl_io *io,
2358 struct cl_page_list *queue, int from, int to,
2360 int cl_io_read_ahead (const struct lu_env *env, struct cl_io *io,
2361 pgoff_t start, struct cl_read_ahead *ra);
2362 void cl_io_rw_advance (const struct lu_env *env, struct cl_io *io,
2364 int cl_io_cancel (const struct lu_env *env, struct cl_io *io,
2365 struct cl_page_list *queue);
2368 * True, iff \a io is an O_APPEND write(2).
2370 static inline int cl_io_is_append(const struct cl_io *io)
2372 return io->ci_type == CIT_WRITE && io->u.ci_rw.rw_append;
2375 static inline int cl_io_is_sync_write(const struct cl_io *io)
2377 return io->ci_type == CIT_WRITE && io->u.ci_rw.rw_sync;
2380 static inline int cl_io_is_mkwrite(const struct cl_io *io)
2382 return io->ci_type == CIT_FAULT && io->u.ci_fault.ft_mkwrite;
2386 * True, iff \a io is a truncate(2).
2388 static inline int cl_io_is_trunc(const struct cl_io *io)
2390 return io->ci_type == CIT_SETATTR &&
2391 (io->u.ci_setattr.sa_avalid & ATTR_SIZE);
2394 struct cl_io *cl_io_top(struct cl_io *io);
2396 void cl_io_print(const struct lu_env *env, void *cookie,
2397 lu_printer_t printer, const struct cl_io *io);
2399 #define CL_IO_SLICE_CLEAN(foo_io, base) \
2401 typeof(foo_io) __foo_io = (foo_io); \
2403 memset(&__foo_io->base, 0, \
2404 sizeof(*__foo_io) - offsetof(typeof(*__foo_io), base)); \
2409 /** \defgroup cl_page_list cl_page_list
2413 * Last page in the page list.
2415 static inline struct cl_page *cl_page_list_last(struct cl_page_list *plist)
2417 LASSERT(plist->pl_nr > 0);
2418 return list_entry(plist->pl_pages.prev, struct cl_page, cp_batch);
2421 static inline struct cl_page *cl_page_list_first(struct cl_page_list *plist)
2423 LASSERT(plist->pl_nr > 0);
2424 return list_entry(plist->pl_pages.next, struct cl_page, cp_batch);
2428 * Iterate over pages in a page list.
2430 #define cl_page_list_for_each(page, list) \
2431 list_for_each_entry((page), &(list)->pl_pages, cp_batch)
2434 * Iterate over pages in a page list, taking possible removals into account.
2436 #define cl_page_list_for_each_safe(page, temp, list) \
2437 list_for_each_entry_safe((page), (temp), &(list)->pl_pages, cp_batch)
2439 void cl_page_list_init (struct cl_page_list *plist);
2440 void cl_page_list_add (struct cl_page_list *plist, struct cl_page *page);
2441 void cl_page_list_move (struct cl_page_list *dst, struct cl_page_list *src,
2442 struct cl_page *page);
2443 void cl_page_list_move_head(struct cl_page_list *dst, struct cl_page_list *src,
2444 struct cl_page *page);
2445 void cl_page_list_splice (struct cl_page_list *list,
2446 struct cl_page_list *head);
2447 void cl_page_list_del (const struct lu_env *env,
2448 struct cl_page_list *plist, struct cl_page *page);
2449 void cl_page_list_disown (const struct lu_env *env,
2450 struct cl_io *io, struct cl_page_list *plist);
2451 void cl_page_list_assume (const struct lu_env *env,
2452 struct cl_io *io, struct cl_page_list *plist);
2453 void cl_page_list_discard(const struct lu_env *env,
2454 struct cl_io *io, struct cl_page_list *plist);
2455 void cl_page_list_fini (const struct lu_env *env, struct cl_page_list *plist);
2457 void cl_2queue_init (struct cl_2queue *queue);
2458 void cl_2queue_add (struct cl_2queue *queue, struct cl_page *page);
2459 void cl_2queue_disown (const struct lu_env *env,
2460 struct cl_io *io, struct cl_2queue *queue);
2461 void cl_2queue_assume (const struct lu_env *env,
2462 struct cl_io *io, struct cl_2queue *queue);
2463 void cl_2queue_discard (const struct lu_env *env,
2464 struct cl_io *io, struct cl_2queue *queue);
2465 void cl_2queue_fini (const struct lu_env *env, struct cl_2queue *queue);
2466 void cl_2queue_init_page(struct cl_2queue *queue, struct cl_page *page);
2468 /** @} cl_page_list */
2470 void cl_req_attr_set(const struct lu_env *env, struct cl_object *obj,
2471 struct cl_req_attr *attr);
2473 /** \defgroup cl_sync_io cl_sync_io
2477 * Anchor for synchronous transfer. This is allocated on a stack by thread
2478 * doing synchronous transfer, and a pointer to this structure is set up in
2479 * every page submitted for transfer. Transfer completion routine updates
2480 * anchor and wakes up waiting thread when transfer is complete.
2483 /** number of pages yet to be transferred. */
2484 atomic_t csi_sync_nr;
2487 /** barrier of destroy this structure */
2488 atomic_t csi_barrier;
2489 /** completion to be signaled when transfer is complete. */
2490 wait_queue_head_t csi_waitq;
2491 /** callback to invoke when this IO is finished */
2492 void (*csi_end_io)(const struct lu_env *,
2493 struct cl_sync_io *);
2496 void cl_sync_io_init(struct cl_sync_io *anchor, int nr,
2497 void (*end)(const struct lu_env *, struct cl_sync_io *));
2498 int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor,
2500 void cl_sync_io_note(const struct lu_env *env, struct cl_sync_io *anchor,
2502 void cl_sync_io_end(const struct lu_env *env, struct cl_sync_io *anchor);
2504 /** @} cl_sync_io */
2506 /** \defgroup cl_env cl_env
2508 * lu_env handling for a client.
2510 * lu_env is an environment within which lustre code executes. Its major part
2511 * is lu_context---a fast memory allocation mechanism that is used to conserve
2512 * precious kernel stack space. Originally lu_env was designed for a server,
2515 * - there is a (mostly) fixed number of threads, and
2517 * - call chains have no non-lustre portions inserted between lustre code.
2519 * On a client both these assumtpion fails, because every user thread can
2520 * potentially execute lustre code as part of a system call, and lustre calls
2521 * into VFS or MM that call back into lustre.
2523 * To deal with that, cl_env wrapper functions implement the following
2526 * - allocation and destruction of environment is amortized by caching no
2527 * longer used environments instead of destroying them;
2529 * \see lu_env, lu_context, lu_context_key
2532 struct lu_env *cl_env_get(__u16 *refcheck);
2533 struct lu_env *cl_env_alloc(__u16 *refcheck, __u32 tags);
2534 void cl_env_put(struct lu_env *env, __u16 *refcheck);
2535 unsigned cl_env_cache_purge(unsigned nr);
2536 struct lu_env *cl_env_percpu_get(void);
2537 void cl_env_percpu_put(struct lu_env *env);
2544 void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr);
2545 void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb);
2547 struct cl_device *cl_type_setup(const struct lu_env *env, struct lu_site *site,
2548 struct lu_device_type *ldt,
2549 struct lu_device *next);
2552 int cl_global_init(void);
2553 void cl_global_fini(void);
2555 #endif /* _LINUX_CL_OBJECT_H */