lustre-src/lustre/include/cl_object.h

00001 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
00002  * vim:expandtab:shiftwidth=8:tabstop=8:
00003  *
00004  * GPL HEADER START
00005  *
00006  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License version 2 only,
00010  * as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * General Public License version 2 for more details (a copy is included
00016  * in the LICENSE file that accompanied this code).
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * version 2 along with this program; If not, see
00020  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
00021  *
00022  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
00023  * CA 95054 USA or visit www.sun.com if you need additional information or
00024  * have any questions.
00025  *
00026  * GPL HEADER END
00027  */
00028 /*
00029  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
00030  * Use is subject to license terms.
00031  */
00032 /*
00033  * This file is part of Lustre, http://www.lustre.org/
00034  * Lustre is a trademark of Sun Microsystems, Inc.
00035  */
00036 #ifndef _LUSTRE_CL_OBJECT_H
00037 #define _LUSTRE_CL_OBJECT_H
00038 
00097 /*
00098  * super-class definitions.
00099  */
00100 #include <lu_object.h>
00101 #include <lvfs.h>
00102 #ifdef __KERNEL__
00103 #        include <linux/mutex.h>
00104 #        include <linux/radix-tree.h>
00105 #endif
00106 
00107 struct inode;
00108 
00109 struct cl_device;
00110 struct cl_device_operations;
00111 
00112 struct cl_object;
00113 struct cl_object_page_operations;
00114 struct cl_object_lock_operations;
00115 
00116 struct cl_page;
00117 struct cl_page_slice;
00118 struct cl_lock;
00119 struct cl_lock_slice;
00120 
00121 struct cl_lock_operations;
00122 struct cl_page_operations;
00123 
00124 struct cl_io;
00125 struct cl_io_slice;
00126 
00127 struct cl_req;
00128 struct cl_req_slice;
00129 
00135 struct cl_device_operations {
00145         int (*cdo_req_init)(const struct lu_env *env, struct cl_device *dev,
00146                             struct cl_req *req);
00147 };
00148 
00154 struct cl_device {
00156         struct lu_device                   cd_lu_dev;
00158         const struct cl_device_operations *cd_ops;
00159 };
00160 
00168 struct cl_attr {
00170         loff_t cat_size;
00176         loff_t cat_kms;
00178         time_t cat_mtime;
00180         time_t cat_atime;
00182         time_t cat_ctime;
00188         __u64  cat_blocks;
00192         uid_t  cat_uid;
00196         gid_t  cat_gid;
00197 };
00198 
00202 enum cl_attr_valid {
00203         CAT_SIZE   = 1 << 0,
00204         CAT_KMS    = 1 << 1,
00205         CAT_MTIME  = 1 << 3,
00206         CAT_ATIME  = 1 << 4,
00207         CAT_CTIME  = 1 << 5,
00208         CAT_BLOCKS = 1 << 6,
00209         CAT_UID    = 1 << 7,
00210         CAT_GID    = 1 << 8
00211 };
00212 
00249 struct cl_object {
00251         struct lu_object                   co_lu;
00253         const struct cl_object_operations *co_ops;
00254 };
00255 
00261 struct cl_object_conf {
00263         struct lu_object_conf     coc_lu;
00264         union {
00268                 struct lustre_md *coc_md;
00273                 struct lov_oinfo *coc_oinfo;
00274         } u;
00278         struct inode             *coc_inode;
00279 };
00280 
00286 struct cl_object_operations {
00302         struct cl_page *(*coo_page_init)(const struct lu_env *env,
00303                                          struct cl_object *obj,
00304                                          struct cl_page *page,
00305                                          cfs_page_t *vmpage);
00313         int  (*coo_lock_init)(const struct lu_env *env,
00314                               struct cl_object *obj, struct cl_lock *lock,
00315                               const struct cl_io *io);
00325         int  (*coo_io_init)(const struct lu_env *env,
00326                             struct cl_object *obj, struct cl_io *io);
00338         int (*coo_attr_get)(const struct lu_env *env, struct cl_object *obj,
00339                             struct cl_attr *attr);
00351         int (*coo_attr_set)(const struct lu_env *env, struct cl_object *obj,
00352                             const struct cl_attr *attr, unsigned valid);
00359         int (*coo_conf_set)(const struct lu_env *env, struct cl_object *obj,
00360                             const struct cl_object_conf *conf);
00369         int (*coo_glimpse)(const struct lu_env *env,
00370                            const struct cl_object *obj, struct ost_lvb *lvb);
00371 };
00372 
00376 struct cl_object_header {
00379         struct lu_object_header  coh_lu;
00386         cfs_spinlock_t           coh_page_guard;
00388         cfs_spinlock_t           coh_lock_guard;
00391         struct radix_tree_root   coh_tree;
00393         unsigned long            coh_pages;
00395         cfs_list_t               coh_locks;
00396 
00404         struct cl_object_header *coh_parent;
00412         cfs_spinlock_t           coh_attr_guard;
00417         unsigned                 coh_nesting;
00418 };
00419 
00424 #define cl_object_for_each(slice, obj)                                      \
00425         cfs_list_for_each_entry((slice),                                    \
00426                                 &(obj)->co_lu.lo_header->loh_layers,        \
00427                                 co_lu.lo_linkage)
00428 
00432 #define cl_object_for_each_reverse(slice, obj)                               \
00433         cfs_list_for_each_entry_reverse((slice),                             \
00434                                         &(obj)->co_lu.lo_header->loh_layers, \
00435                                         co_lu.lo_linkage)
00436 
00438 #ifndef pgoff_t
00439 #define pgoff_t unsigned long
00440 #endif
00441 
00442 #define CL_PAGE_EOF ((pgoff_t)~0ull)
00443 
00566 enum cl_page_state {
00583         CPS_CACHED,
00612         CPS_OWNED,
00640         CPS_PAGEOUT,
00652         CPS_PAGEIN,
00662         CPS_FREEING,
00663         CPS_NR
00664 };
00665 
00666 enum cl_page_type {
00669         CPT_CACHEABLE = 1,
00670 
00674         CPT_TRANSIENT,
00675 };
00676 
00680 enum cl_page_flags {
00685         CPF_READ_COMPLETED = 1 << 0
00686 };
00687 
00697 struct cl_page {
00699         cfs_atomic_t             cp_ref;
00701         struct cl_object        *cp_obj;
00703         pgoff_t                  cp_index;
00705         cfs_list_t               cp_layers;
00707         struct cl_page          *cp_parent;
00710         struct cl_page          *cp_child;
00715         const enum cl_page_state cp_state;
00719         cfs_list_t               cp_batch;
00721         cfs_mutex_t              cp_mutex;
00723         cfs_list_t               cp_flight;
00725         int                      cp_error;
00726 
00731         enum cl_page_type        cp_type;
00732 
00737         struct cl_io            *cp_owner;
00741         cfs_task_t              *cp_task;
00747         struct cl_req           *cp_req;
00749         struct lu_ref            cp_reference;
00751         struct lu_ref_link      *cp_obj_ref;
00753         struct lu_ref_link      *cp_queue_ref;
00755         unsigned                 cp_flags;
00757         struct cl_sync_io       *cp_sync_io;
00758 };
00759 
00765 struct cl_page_slice {
00766         struct cl_page                  *cpl_page;
00771         struct cl_object                *cpl_obj;
00772         const struct cl_page_operations *cpl_ops;
00774         cfs_list_t                       cpl_linkage;
00775 };
00776 
00783 enum cl_lock_mode {
00789         CLM_PHANTOM,
00790         CLM_READ,
00791         CLM_WRITE,
00792         CLM_GROUP
00793 };
00794 
00799 enum cl_req_type {
00800         CRT_READ,
00801         CRT_WRITE,
00802         CRT_NR
00803 };
00804 
00814 struct cl_page_operations {
00824         cfs_page_t *(*cpo_vmpage)(const struct lu_env *env,
00825                                   const struct cl_page_slice *slice);
00835         int  (*cpo_own)(const struct lu_env *env,
00836                         const struct cl_page_slice *slice,
00837                         struct cl_io *io, int nonblock);
00843         void (*cpo_disown)(const struct lu_env *env,
00844                            const struct cl_page_slice *slice, struct cl_io *io);
00852         void (*cpo_assume)(const struct lu_env *env,
00853                            const struct cl_page_slice *slice, struct cl_io *io);
00861         void (*cpo_unassume)(const struct lu_env *env,
00862                              const struct cl_page_slice *slice,
00863                              struct cl_io *io);
00870         void  (*cpo_export)(const struct lu_env *env,
00871                             const struct cl_page_slice *slice, int uptodate);
00878         int (*cpo_unmap)(const struct lu_env *env,
00879                          const struct cl_page_slice *slice, struct cl_io *io);
00888         int (*cpo_is_vmlocked)(const struct lu_env *env,
00889                                const struct cl_page_slice *slice);
00900         void (*cpo_discard)(const struct lu_env *env,
00901                             const struct cl_page_slice *slice,
00902                             struct cl_io *io);
00910         void (*cpo_delete)(const struct lu_env *env,
00911                            const struct cl_page_slice *slice);
00913         void (*cpo_fini)(const struct lu_env *env,
00914                          struct cl_page_slice *slice);
00915 
00931         int (*cpo_is_under_lock)(const struct lu_env *env,
00932                                  const struct cl_page_slice *slice,
00933                                  struct cl_io *io);
00934 
00940         int (*cpo_print)(const struct lu_env *env,
00941                          const struct cl_page_slice *slice,
00942                          void *cookie, lu_printer_t p);
00962         struct {
00973                 int  (*cpo_prep)(const struct lu_env *env,
00974                                  const struct cl_page_slice *slice,
00975                                  struct cl_io *io);
00988                 void (*cpo_completion)(const struct lu_env *env,
00989                                        const struct cl_page_slice *slice,
00990                                        int ioret);
01001                 int  (*cpo_make_ready)(const struct lu_env *env,
01002                                        const struct cl_page_slice *slice);
01020                 int  (*cpo_cache_add)(const struct lu_env *env,
01021                                       const struct cl_page_slice *slice,
01022                                       struct cl_io *io);
01023         } io[CRT_NR];
01037         void (*cpo_clip)(const struct lu_env *env,
01038                          const struct cl_page_slice *slice,
01039                          int from, int to);
01055         int (*cpo_cancel)(const struct lu_env *env,
01056                           const struct cl_page_slice *slice);
01058 };
01059 
01063 #define CL_PAGE_DEBUG(mask, env, page, format, ...)                     \
01064 do {                                                                    \
01065         static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask);              \
01066                                                                         \
01067         if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {                   \
01068                 cl_page_print(env, &__info, lu_cdebug_printer, page);   \
01069                 CDEBUG(mask, format , ## __VA_ARGS__);                  \
01070         }                                                               \
01071 } while (0)
01072 
01076 #define CL_PAGE_HEADER(mask, env, page, format, ...)                    \
01077 do {                                                                    \
01078         static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask);              \
01079                                                                         \
01080         if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {                   \
01081                 cl_page_header_print(env, &__info, lu_cdebug_printer, page); \
01082                 CDEBUG(mask, format , ## __VA_ARGS__);                  \
01083         }                                                               \
01084 } while (0)
01085 
01293 struct cl_lock_descr {
01295         struct cl_object *cld_obj;
01297         pgoff_t           cld_start;
01299         pgoff_t           cld_end;
01301         __u64             cld_gid;
01303         enum cl_lock_mode cld_mode;
01308         __u32             cld_enq_flags;
01309 };
01310 
01311 #define DDESCR "%s(%d):[%lu, %lu]"
01312 #define PDESCR(descr)                                                   \
01313         cl_lock_mode_name((descr)->cld_mode), (descr)->cld_mode,        \
01314         (descr)->cld_start, (descr)->cld_end
01315 
01316 const char *cl_lock_mode_name(const enum cl_lock_mode mode);
01317 
01393 enum cl_lock_state {
01397         CLS_NEW,
01402         CLS_QUEUING,
01407         CLS_ENQUEUED,
01411         CLS_HELD,
01422         CLS_INTRANSIT,
01426         CLS_CACHED,
01430         CLS_FREEING,
01431         CLS_NR
01432 };
01433 
01434 enum cl_lock_flags {
01439         CLF_CANCELLED  = 1 << 0,
01441         CLF_CANCELPEND = 1 << 1,
01443         CLF_DOOMED     = 1 << 2
01444 };
01445 
01468 struct cl_lock_closure {
01474         struct cl_lock   *clc_origin;
01479         cfs_list_t        clc_list;
01495         int               clc_wait;
01497         int               clc_nr;
01498 };
01499 
01503 struct cl_lock {
01505         cfs_atomic_t          cll_ref;
01507         cfs_list_t            cll_layers;
01512         cfs_list_t            cll_linkage;
01519         struct cl_lock_descr  cll_descr;
01521         enum cl_lock_state    cll_state;
01523         cfs_waitq_t           cll_wq;
01537         cfs_mutex_t           cll_guard;
01538         cfs_task_t           *cll_guarder;
01539         int                   cll_depth;
01540 
01544         cfs_task_t           *cll_intransit_owner;
01545         int                   cll_error;
01552         int                   cll_holds;
01560         int                   cll_users;
01565         unsigned long         cll_flags;
01571         cfs_list_t            cll_inclosure;
01575         struct cl_lock       *cll_conflict;
01579         struct lu_ref         cll_reference;
01583         struct lu_ref         cll_holders;
01587         struct lu_ref_link   *cll_obj_ref;
01588 #ifdef CONFIG_LOCKDEP
01589         /* "dep_map" name is assumed by lockdep.h macros. */
01590         struct lockdep_map    dep_map;
01591 #endif
01592 };
01593 
01599 struct cl_lock_slice {
01600         struct cl_lock                  *cls_lock;
01603         struct cl_object                *cls_obj;
01604         const struct cl_lock_operations *cls_ops;
01606         cfs_list_t                       cls_linkage;
01607 };
01608 
01614 enum cl_lock_transition {
01616         CLO_WAIT   = 1,
01618         CLO_REPEAT = 2
01619 };
01620 
01625 struct cl_lock_operations {
01663         int  (*clo_enqueue)(const struct lu_env *env,
01664                             const struct cl_lock_slice *slice,
01665                             struct cl_io *io, __u32 enqflags);
01671         int  (*clo_wait)(const struct lu_env *env,
01672                          const struct cl_lock_slice *slice);
01682         int  (*clo_unuse)(const struct lu_env *env,
01683                           const struct cl_lock_slice *slice);
01691         int  (*clo_use)(const struct lu_env *env,
01692                         const struct cl_lock_slice *slice);
01702         void (*clo_state)(const struct lu_env *env,
01703                           const struct cl_lock_slice *slice,
01704                           enum cl_lock_state st);
01717         int (*clo_fits_into)(const struct lu_env *env,
01718                              const struct cl_lock_slice *slice,
01719                              const struct cl_lock_descr *need,
01720                              const struct cl_io *io);
01732         void (*clo_cancel)(const struct lu_env *env,
01733                            const struct cl_lock_slice *slice);
01741         unsigned long (*clo_weigh)(const struct lu_env *env,
01742                                    const struct cl_lock_slice *slice);
01748         int (*clo_closure)(const struct lu_env *env,
01749                            const struct cl_lock_slice *slice,
01750                            struct cl_lock_closure *closure);
01757         int (*clo_modify)(const struct lu_env *env,
01758                           const struct cl_lock_slice *slice,
01759                           const struct cl_lock_descr *updated);
01770         void (*clo_delete)(const struct lu_env *env,
01771                            const struct cl_lock_slice *slice);
01778         void (*clo_fini)(const struct lu_env *env, struct cl_lock_slice *slice);
01782         int (*clo_print)(const struct lu_env *env,
01783                          void *cookie, lu_printer_t p,
01784                          const struct cl_lock_slice *slice);
01785 };
01786 
01787 #define CL_LOCK_DEBUG(mask, env, lock, format, ...)                     \
01788 do {                                                                    \
01789         static DECLARE_LU_CDEBUG_PRINT_INFO(__info, mask);              \
01790                                                                         \
01791         if (cfs_cdebug_show(mask, DEBUG_SUBSYSTEM)) {                   \
01792                 cl_lock_print(env, &__info, lu_cdebug_printer, lock);   \
01793                 CDEBUG(mask, format , ## __VA_ARGS__);                  \
01794         }                                                               \
01795 } while (0)
01796 
01818 struct cl_page_list {
01819         unsigned             pl_nr;
01820         cfs_list_t           pl_pages;
01821         cfs_task_t          *pl_owner;
01822 };
01823 
01828 struct cl_2queue {
01829         struct cl_page_list c2_qin;
01830         struct cl_page_list c2_qout;
01831 };
01832 
01888 enum cl_io_type {
01890         CIT_READ,
01892         CIT_WRITE,
01894         CIT_SETATTR,
01898         CIT_FAULT,
01918         CIT_MISC,
01919         CIT_OP_NR
01920 };
01921 
01925 enum cl_io_state {
01927         CIS_ZERO,
01929         CIS_INIT,
01931         CIS_IT_STARTED,
01933         CIS_LOCKED,
01935         CIS_IO_GOING,
01937         CIS_IO_FINISHED,
01939         CIS_UNLOCKED,
01941         CIS_IT_ENDED,
01943         CIS_FINI
01944 };
01945 
01946 enum cl_req_priority {
01947         CRP_NORMAL,
01948         CRP_CANCEL
01949 };
01950 
01959 struct cl_io_slice {
01960         struct cl_io                  *cis_io;
01962         struct cl_object              *cis_obj;
01964         const struct cl_io_operations *cis_iop;
01969         cfs_list_t                     cis_linkage;
01970 };
01971 
01972 
01977 struct cl_io_operations {
01983         struct {
01993                 int (*cio_iter_init) (const struct lu_env *env,
01994                                       const struct cl_io_slice *slice);
02004                 void (*cio_iter_fini) (const struct lu_env *env,
02005                                        const struct cl_io_slice *slice);
02015                 int  (*cio_lock) (const struct lu_env *env,
02016                                   const struct cl_io_slice *slice);
02024                 void  (*cio_unlock)(const struct lu_env *env,
02025                                     const struct cl_io_slice *slice);
02035                 int  (*cio_start)(const struct lu_env *env,
02036                                   const struct cl_io_slice *slice);
02041                 void (*cio_end)  (const struct lu_env *env,
02042                                   const struct cl_io_slice *slice);
02047                 void (*cio_advance)(const struct lu_env *env,
02048                                     const struct cl_io_slice *slice,
02049                                     size_t nob);
02053                 void (*cio_fini) (const struct lu_env *env,
02054                                   const struct cl_io_slice *slice);
02055         } op[CIT_OP_NR];
02056         struct {
02065                 int  (*cio_submit)(const struct lu_env *env,
02066                                    const struct cl_io_slice *slice,
02067                                    enum cl_req_type crt,
02068                                    struct cl_2queue *queue,
02069                                    enum cl_req_priority priority);
02070         } req_op[CRT_NR];
02079         int (*cio_read_page)(const struct lu_env *env,
02080                              const struct cl_io_slice *slice,
02081                              const struct cl_page_slice *page);
02092         int (*cio_prepare_write)(const struct lu_env *env,
02093                                  const struct cl_io_slice *slice,
02094                                  const struct cl_page_slice *page,
02095                                  unsigned from, unsigned to);
02103         int (*cio_commit_write)(const struct lu_env *env,
02104                                 const struct cl_io_slice *slice,
02105                                 const struct cl_page_slice *page,
02106                                 unsigned from, unsigned to);
02110         int (*cio_print)(const struct lu_env *env, void *cookie,
02111                          lu_printer_t p, const struct cl_io_slice *slice);
02112 };
02113 
02118 enum cl_enq_flags {
02123         CEF_NONBLOCK     = 0x00000001,
02128         CEF_ASYNC        = 0x00000002,
02134         CEF_DISCARD_DATA = 0x00000004,
02142         CEF_MUST         = 0x00000008,
02153         CEF_NEVER        = 0x00000010,
02157         CEF_MASK         = 0x0000001f
02158 };
02159 
02164 struct cl_io_lock_link {
02166         cfs_list_t           cill_linkage;
02167         struct cl_lock_descr cill_descr;
02168         struct cl_lock      *cill_lock;
02170         void               (*cill_fini)(const struct lu_env *env,
02171                                         struct cl_io_lock_link *link);
02172 };
02173 
02203 struct cl_lockset {
02205         cfs_list_t  cls_todo;
02207         cfs_list_t  cls_curr;
02209         cfs_list_t  cls_done;
02210 };
02211 
02216 enum cl_io_lock_dmd {
02218         CILR_MANDATORY = 0,
02220         CILR_MAYBE,
02222         CILR_NEVER
02223 };
02224 
02225 struct cl_io_rw_common {
02226         loff_t      crw_pos;
02227         size_t      crw_count;
02228         int         crw_nonblock;
02229 };
02230 
02231 
02241 struct cl_io {
02243         enum cl_io_type                ci_type;
02245         enum cl_io_state               ci_state;
02247         struct cl_object              *ci_obj;
02252         struct cl_io                  *ci_parent;
02254         cfs_list_t                     ci_layers;
02256         struct cl_lockset              ci_lockset;
02258         enum cl_io_lock_dmd            ci_lockreq;
02263         int                            ci_no_srvlock;
02264         union {
02265                 struct cl_rd_io {
02266                         struct cl_io_rw_common rd;
02267                 } ci_rd;
02268                 struct cl_wr_io {
02269                         struct cl_io_rw_common wr;
02270                         int                    wr_append;
02271                 } ci_wr;
02272                 struct cl_io_rw_common ci_rw;
02273                 struct cl_setattr_io {
02274                         struct ost_lvb   sa_attr;
02275                         unsigned int     sa_valid;
02276                         struct obd_capa *sa_capa;
02277                 } ci_setattr;
02278                 struct cl_fault_io {
02280                         pgoff_t         ft_index;
02282                         int             ft_nob;
02284                         int             ft_writable;
02286                         int             ft_executable;
02288                         struct cl_page *ft_page;
02289                 } ci_fault;
02290         } u;
02291         struct cl_2queue     ci_queue;
02292         size_t               ci_nob;
02293         int                  ci_result;
02294         int                  ci_continue;
02298         unsigned             ci_owned_nr;
02299 };
02300 
02368 struct cl_req_attr {
02370         struct obdo     *cra_oa;
02372         struct obd_capa *cra_capa;
02373 };
02374 
02381 struct cl_req_operations {
02388         int  (*cro_prep)(const struct lu_env *env,
02389                          const struct cl_req_slice *slice);
02401         void (*cro_attr_set)(const struct lu_env *env,
02402                              const struct cl_req_slice *slice,
02403                              const struct cl_object *obj,
02404                              struct cl_req_attr *attr, obd_valid flags);
02410         void (*cro_completion)(const struct lu_env *env,
02411                                const struct cl_req_slice *slice, int ioret);
02412 };
02413 
02417 struct cl_req_obj {
02419         struct cl_object   *ro_obj;
02421         struct lu_ref_link *ro_obj_ref;
02422         /* something else? Number of pages for a given object? */
02423 };
02424 
02450 struct cl_req {
02451         enum cl_req_type      crq_type;
02453         cfs_list_t            crq_pages;
02455         unsigned              crq_nrpages;
02457         struct cl_req_obj    *crq_o;
02459         unsigned              crq_nrobjs;
02460         cfs_list_t            crq_layers;
02461 };
02462 
02466 struct cl_req_slice {
02467         struct cl_req    *crs_req;
02468         struct cl_device *crs_dev;
02469         cfs_list_t        crs_linkage;
02470         const struct cl_req_operations *crs_ops;
02471 };
02472 
02473 /* @} cl_req */
02474 
02478 struct cache_stats {
02479         const char    *cs_name;
02481         cfs_atomic_t   cs_created;
02483         cfs_atomic_t   cs_lookup;
02485         cfs_atomic_t   cs_hit;
02487         cfs_atomic_t   cs_total;
02490         cfs_atomic_t   cs_busy;
02491 };
02492 
02494 void cache_stats_init (struct cache_stats *cs, const char *name);
02495 int  cache_stats_print(const struct cache_stats *cs,
02496                        char *page, int count, int header);
02497 
02503 struct cl_site {
02504         struct lu_site        cs_lu;
02514         struct cache_stats    cs_pages;
02515         struct cache_stats    cs_locks;
02516         cfs_atomic_t          cs_pages_state[CPS_NR];
02517         cfs_atomic_t          cs_locks_state[CLS_NR];
02518 };
02519 
02520 int  cl_site_init (struct cl_site *s, struct cl_device *top);
02521 void cl_site_fini (struct cl_site *s);
02522 void cl_stack_fini(const struct lu_env *env, struct cl_device *cl);
02523 
02528 int cl_site_stats_print(const struct cl_site *s, char *page, int count);
02529 
02537 static inline struct cl_site *lu2cl_site(const struct lu_site *site)
02538 {
02539         return container_of(site, struct cl_site, cs_lu);
02540 }
02541 
02542 static inline int lu_device_is_cl(const struct lu_device *d)
02543 {
02544         return d->ld_type->ldt_tags & LU_DEVICE_CL;
02545 }
02546 
02547 static inline struct cl_device *lu2cl_dev(const struct lu_device *d)
02548 {
02549         LASSERT(d == NULL || IS_ERR(d) || lu_device_is_cl(d));
02550         return container_of0(d, struct cl_device, cd_lu_dev);
02551 }
02552 
02553 static inline struct lu_device *cl2lu_dev(struct cl_device *d)
02554 {
02555         return &d->cd_lu_dev;
02556 }
02557 
02558 static inline struct cl_object *lu2cl(const struct lu_object *o)
02559 {
02560         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_cl(o->lo_dev));
02561         return container_of0(o, struct cl_object, co_lu);
02562 }
02563 
02564 static inline const struct cl_object_conf *
02565 lu2cl_conf(const struct lu_object_conf *conf)
02566 {
02567         return container_of0(conf, struct cl_object_conf, coc_lu);
02568 }
02569 
02570 static inline struct cl_object *cl_object_next(const struct cl_object *obj)
02571 {
02572         return obj ? lu2cl(lu_object_next(&obj->co_lu)) : NULL;
02573 }
02574 
02575 static inline struct cl_device *cl_object_device(const struct cl_object *o)
02576 {
02577         LASSERT(o == NULL || IS_ERR(o) || lu_device_is_cl(o->co_lu.lo_dev));
02578         return container_of0(o->co_lu.lo_dev, struct cl_device, cd_lu_dev);
02579 }
02580 
02581 static inline struct cl_object_header *luh2coh(const struct lu_object_header *h)
02582 {
02583         return container_of0(h, struct cl_object_header, coh_lu);
02584 }
02585 
02586 static inline struct cl_site *cl_object_site(const struct cl_object *obj)
02587 {
02588         return lu2cl_site(obj->co_lu.lo_dev->ld_site);
02589 }
02590 
02591 static inline
02592 struct cl_object_header *cl_object_header(const struct cl_object *obj)
02593 {
02594         return luh2coh(obj->co_lu.lo_header);
02595 }
02596 
02597 static inline int cl_device_init(struct cl_device *d, struct lu_device_type *t)
02598 {
02599         return lu_device_init(&d->cd_lu_dev, t);
02600 }
02601 
02602 static inline void cl_device_fini(struct cl_device *d)
02603 {
02604         lu_device_fini(&d->cd_lu_dev);
02605 }
02606 
02607 void cl_page_slice_add(struct cl_page *page, struct cl_page_slice *slice,
02608                        struct cl_object *obj,
02609                        const struct cl_page_operations *ops);
02610 void cl_lock_slice_add(struct cl_lock *lock, struct cl_lock_slice *slice,
02611                        struct cl_object *obj,
02612                        const struct cl_lock_operations *ops);
02613 void cl_io_slice_add(struct cl_io *io, struct cl_io_slice *slice,
02614                      struct cl_object *obj, const struct cl_io_operations *ops);
02615 void cl_req_slice_add(struct cl_req *req, struct cl_req_slice *slice,
02616                       struct cl_device *dev,
02617                       const struct cl_req_operations *ops);
02622 struct cl_object *cl_object_top (struct cl_object *o);
02623 struct cl_object *cl_object_find(const struct lu_env *env, struct cl_device *cd,
02624                                  const struct lu_fid *fid,
02625                                  const struct cl_object_conf *c);
02626 
02627 int  cl_object_header_init(struct cl_object_header *h);
02628 void cl_object_header_fini(struct cl_object_header *h);
02629 void cl_object_put        (const struct lu_env *env, struct cl_object *o);
02630 void cl_object_get        (struct cl_object *o);
02631 void cl_object_attr_lock  (struct cl_object *o);
02632 void cl_object_attr_unlock(struct cl_object *o);
02633 int  cl_object_attr_get   (const struct lu_env *env, struct cl_object *obj,
02634                            struct cl_attr *attr);
02635 int  cl_object_attr_set   (const struct lu_env *env, struct cl_object *obj,
02636                            const struct cl_attr *attr, unsigned valid);
02637 int  cl_object_glimpse    (const struct lu_env *env, struct cl_object *obj,
02638                            struct ost_lvb *lvb);
02639 int  cl_conf_set          (const struct lu_env *env, struct cl_object *obj,
02640                            const struct cl_object_conf *conf);
02641 void cl_object_prune      (const struct lu_env *env, struct cl_object *obj);
02642 void cl_object_kill       (const struct lu_env *env, struct cl_object *obj);
02643 int  cl_object_has_locks  (struct cl_object *obj);
02644 
02648 static inline int cl_object_same(struct cl_object *o0, struct cl_object *o1)
02649 {
02650         return cl_object_header(o0) == cl_object_header(o1);
02651 }
02652 
02657 struct cl_page       *cl_page_lookup(struct cl_object_header *hdr,
02658                                      pgoff_t index);
02659 void                  cl_page_gang_lookup(const struct lu_env *env,
02660                                           struct cl_object *obj,
02661                                           struct cl_io *io,
02662                                           pgoff_t start, pgoff_t end,
02663                                           struct cl_page_list *plist,
02664                                           int nonblock,
02665                                           int *resched);
02666 struct cl_page *cl_page_find        (const struct lu_env *env,
02667                                      struct cl_object *obj,
02668                                      pgoff_t idx, struct page *vmpage,
02669                                      enum cl_page_type type);
02670 struct cl_page *cl_page_find_sub    (const struct lu_env *env,
02671                                      struct cl_object *obj,
02672                                      pgoff_t idx, struct page *vmpage,
02673                                      struct cl_page *parent);
02674 void            cl_page_get         (struct cl_page *page);
02675 void            cl_page_put         (const struct lu_env *env,
02676                                      struct cl_page *page);
02677 void            cl_page_print       (const struct lu_env *env, void *cookie,
02678                                      lu_printer_t printer,
02679                                      const struct cl_page *pg);
02680 void            cl_page_header_print(const struct lu_env *env, void *cookie,
02681                                      lu_printer_t printer,
02682                                      const struct cl_page *pg);
02683 cfs_page_t     *cl_page_vmpage      (const struct lu_env *env,
02684                                      struct cl_page *page);
02685 struct cl_page *cl_vmpage_page      (cfs_page_t *vmpage, struct cl_object *obj);
02686 struct cl_page *cl_page_top         (struct cl_page *page);
02687 int             cl_is_page          (const void *addr);
02688 
02689 const struct cl_page_slice *cl_page_at(const struct cl_page *page,
02690                                        const struct lu_device_type *dtype);
02691 
02699 int  cl_page_own        (const struct lu_env *env,
02700                          struct cl_io *io, struct cl_page *page);
02701 int  cl_page_own_try    (const struct lu_env *env,
02702                          struct cl_io *io, struct cl_page *page);
02703 void cl_page_assume     (const struct lu_env *env,
02704                          struct cl_io *io, struct cl_page *page);
02705 void cl_page_unassume   (const struct lu_env *env,
02706                          struct cl_io *io, struct cl_page *pg);
02707 void cl_page_disown     (const struct lu_env *env,
02708                          struct cl_io *io, struct cl_page *page);
02709 int  cl_page_is_owned   (const struct cl_page *pg, const struct cl_io *io);
02710 
02720 int  cl_page_prep       (const struct lu_env *env, struct cl_io *io,
02721                          struct cl_page *pg, enum cl_req_type crt);
02722 void cl_page_completion (const struct lu_env *env,
02723                          struct cl_page *pg, enum cl_req_type crt, int ioret);
02724 int  cl_page_make_ready (const struct lu_env *env, struct cl_page *pg,
02725                          enum cl_req_type crt);
02726 int  cl_page_cache_add  (const struct lu_env *env, struct cl_io *io,
02727                          struct cl_page *pg, enum cl_req_type crt);
02728 void cl_page_clip       (const struct lu_env *env, struct cl_page *pg,
02729                          int from, int to);
02730 int  cl_page_cancel     (const struct lu_env *env, struct cl_page *page);
02731 
02740 void    cl_page_discard      (const struct lu_env *env, struct cl_io *io,
02741                               struct cl_page *pg);
02742 void    cl_page_delete       (const struct lu_env *env, struct cl_page *pg);
02743 int     cl_page_unmap        (const struct lu_env *env, struct cl_io *io,
02744                               struct cl_page *pg);
02745 int     cl_page_is_vmlocked  (const struct lu_env *env,
02746                               const struct cl_page *pg);
02747 void    cl_page_export       (const struct lu_env *env,
02748                               struct cl_page *pg, int uptodate);
02749 int     cl_page_is_under_lock(const struct lu_env *env, struct cl_io *io,
02750                               struct cl_page *page);
02751 loff_t  cl_offset            (const struct cl_object *obj, pgoff_t idx);
02752 pgoff_t cl_index             (const struct cl_object *obj, loff_t offset);
02753 int     cl_page_size         (const struct cl_object *obj);
02754 int     cl_pages_prune       (const struct lu_env *env, struct cl_object *obj);
02755 
02756 void cl_lock_print      (const struct lu_env *env, void *cookie,
02757                          lu_printer_t printer, const struct cl_lock *lock);
02758 void cl_lock_descr_print(const struct lu_env *env, void *cookie,
02759                          lu_printer_t printer,
02760                          const struct cl_lock_descr *descr);
02761 /* @} helper */
02762 
02768 struct cl_lock *cl_lock_hold(const struct lu_env *env, const struct cl_io *io,
02769                              const struct cl_lock_descr *need,
02770                              const char *scope, const void *source);
02771 struct cl_lock *cl_lock_peek(const struct lu_env *env, const struct cl_io *io,
02772                              const struct cl_lock_descr *need,
02773                              const char *scope, const void *source);
02774 struct cl_lock *cl_lock_request(const struct lu_env *env, struct cl_io *io,
02775                                 const struct cl_lock_descr *need,
02776                                 const char *scope, const void *source);
02777 struct cl_lock *cl_lock_at_page(const struct lu_env *env, struct cl_object *obj,
02778                                 struct cl_page *page, struct cl_lock *except,
02779                                 int pending, int canceld);
02780 
02781 const struct cl_lock_slice *cl_lock_at(const struct cl_lock *lock,
02782                                        const struct lu_device_type *dtype);
02783 
02784 void  cl_lock_get       (struct cl_lock *lock);
02785 void  cl_lock_get_trust (struct cl_lock *lock);
02786 void  cl_lock_put       (const struct lu_env *env, struct cl_lock *lock);
02787 void  cl_lock_hold_add  (const struct lu_env *env, struct cl_lock *lock,
02788                          const char *scope, const void *source);
02789 void  cl_lock_unhold    (const struct lu_env *env, struct cl_lock *lock,
02790                          const char *scope, const void *source);
02791 void  cl_lock_release   (const struct lu_env *env, struct cl_lock *lock,
02792                          const char *scope, const void *source);
02793 void  cl_lock_user_add  (const struct lu_env *env, struct cl_lock *lock);
02794 int   cl_lock_user_del  (const struct lu_env *env, struct cl_lock *lock);
02795 
02796 enum cl_lock_state cl_lock_intransit(const struct lu_env *env,
02797                                      struct cl_lock *lock);
02798 
02799 void cl_lock_extransit(const struct lu_env *env, struct cl_lock *lock,
02800                        enum cl_lock_state state);
02801 
02802 int cl_lock_is_intransit(struct cl_lock *lock);
02803 
02836 int   cl_enqueue    (const struct lu_env *env, struct cl_lock *lock,
02837                      struct cl_io *io, __u32 flags);
02838 int   cl_wait       (const struct lu_env *env, struct cl_lock *lock);
02839 void  cl_unuse      (const struct lu_env *env, struct cl_lock *lock);
02840 int   cl_enqueue_try(const struct lu_env *env, struct cl_lock *lock,
02841                      struct cl_io *io, __u32 flags);
02842 int   cl_unuse_try  (const struct lu_env *env, struct cl_lock *lock);
02843 int   cl_wait_try   (const struct lu_env *env, struct cl_lock *lock);
02844 int   cl_use_try    (const struct lu_env *env, struct cl_lock *lock, int atomic);
02847 void cl_lock_signal      (const struct lu_env *env, struct cl_lock *lock);
02848 int  cl_lock_state_wait  (const struct lu_env *env, struct cl_lock *lock);
02849 void cl_lock_state_set   (const struct lu_env *env, struct cl_lock *lock,
02850                           enum cl_lock_state state);
02851 int  cl_queue_match      (const cfs_list_t *queue,
02852                           const struct cl_lock_descr *need);
02853 
02854 void cl_lock_mutex_get  (const struct lu_env *env, struct cl_lock *lock);
02855 int  cl_lock_mutex_try  (const struct lu_env *env, struct cl_lock *lock);
02856 void cl_lock_mutex_put  (const struct lu_env *env, struct cl_lock *lock);
02857 int  cl_lock_is_mutexed (struct cl_lock *lock);
02858 int  cl_lock_nr_mutexed (const struct lu_env *env);
02859 int  cl_lock_page_out   (const struct lu_env *env, struct cl_lock *lock,
02860                          int discard);
02861 int  cl_lock_ext_match  (const struct cl_lock_descr *has,
02862                          const struct cl_lock_descr *need);
02863 int  cl_lock_descr_match(const struct cl_lock_descr *has,
02864                          const struct cl_lock_descr *need);
02865 int  cl_lock_mode_match (enum cl_lock_mode has, enum cl_lock_mode need);
02866 int  cl_lock_modify     (const struct lu_env *env, struct cl_lock *lock,
02867                          const struct cl_lock_descr *desc);
02868 
02869 void cl_lock_closure_init (const struct lu_env *env,
02870                            struct cl_lock_closure *closure,
02871                            struct cl_lock *origin, int wait);
02872 void cl_lock_closure_fini (struct cl_lock_closure *closure);
02873 int  cl_lock_closure_build(const struct lu_env *env, struct cl_lock *lock,
02874                            struct cl_lock_closure *closure);
02875 void cl_lock_disclosure   (const struct lu_env *env,
02876                            struct cl_lock_closure *closure);
02877 int  cl_lock_enclosure    (const struct lu_env *env, struct cl_lock *lock,
02878                            struct cl_lock_closure *closure);
02879 
02880 void cl_lock_cancel(const struct lu_env *env, struct cl_lock *lock);
02881 void cl_lock_delete(const struct lu_env *env, struct cl_lock *lock);
02882 void cl_lock_error (const struct lu_env *env, struct cl_lock *lock, int error);
02883 void cl_locks_prune(const struct lu_env *env, struct cl_object *obj, int wait);
02884 int  cl_is_lock    (const void *addr);
02885 
02886 unsigned long cl_lock_weigh(const struct lu_env *env, struct cl_lock *lock);
02887 
02893 int   cl_io_init         (const struct lu_env *env, struct cl_io *io,
02894                           enum cl_io_type iot, struct cl_object *obj);
02895 int   cl_io_sub_init     (const struct lu_env *env, struct cl_io *io,
02896                           enum cl_io_type iot, struct cl_object *obj);
02897 int   cl_io_rw_init      (const struct lu_env *env, struct cl_io *io,
02898                           enum cl_io_type iot, loff_t pos, size_t count);
02899 int   cl_io_loop         (const struct lu_env *env, struct cl_io *io);
02900 
02901 void  cl_io_fini         (const struct lu_env *env, struct cl_io *io);
02902 int   cl_io_iter_init    (const struct lu_env *env, struct cl_io *io);
02903 void  cl_io_iter_fini    (const struct lu_env *env, struct cl_io *io);
02904 int   cl_io_lock         (const struct lu_env *env, struct cl_io *io);
02905 void  cl_io_unlock       (const struct lu_env *env, struct cl_io *io);
02906 int   cl_io_start        (const struct lu_env *env, struct cl_io *io);
02907 void  cl_io_end          (const struct lu_env *env, struct cl_io *io);
02908 int   cl_io_lock_add     (const struct lu_env *env, struct cl_io *io,
02909                           struct cl_io_lock_link *link);
02910 int   cl_io_lock_alloc_add(const struct lu_env *env, struct cl_io *io,
02911                            struct cl_lock_descr *descr);
02912 int   cl_io_read_page    (const struct lu_env *env, struct cl_io *io,
02913                           struct cl_page *page);
02914 int   cl_io_prepare_write(const struct lu_env *env, struct cl_io *io,
02915                           struct cl_page *page, unsigned from, unsigned to);
02916 int   cl_io_commit_write (const struct lu_env *env, struct cl_io *io,
02917                           struct cl_page *page, unsigned from, unsigned to);
02918 int   cl_io_submit_rw    (const struct lu_env *env, struct cl_io *io,
02919                           enum cl_req_type iot, struct cl_2queue *queue,
02920                           enum cl_req_priority priority);
02921 int   cl_io_submit_sync  (const struct lu_env *env, struct cl_io *io,
02922                           enum cl_req_type iot, struct cl_2queue *queue,
02923                           enum cl_req_priority priority, long timeout);
02924 void  cl_io_rw_advance   (const struct lu_env *env, struct cl_io *io,
02925                           size_t nob);
02926 int   cl_io_cancel       (const struct lu_env *env, struct cl_io *io,
02927                           struct cl_page_list *queue);
02928 int   cl_io_is_going     (const struct lu_env *env);
02929 
02933 static inline int cl_io_is_append(const struct cl_io *io)
02934 {
02935         return io->ci_type == CIT_WRITE && io->u.ci_wr.wr_append;
02936 }
02937 
02941 static inline int cl_io_is_trunc(const struct cl_io *io)
02942 {
02943         return io->ci_type == CIT_SETATTR &&
02944                 (io->u.ci_setattr.sa_valid & ATTR_SIZE);
02945 }
02946 
02947 struct cl_io *cl_io_top(struct cl_io *io);
02948 
02949 void cl_io_print(const struct lu_env *env, void *cookie,
02950                  lu_printer_t printer, const struct cl_io *io);
02951 
02952 #define CL_IO_SLICE_CLEAN(foo_io, base)                                 \
02953 do {                                                                    \
02954         typeof(foo_io) __foo_io = (foo_io);                             \
02955                                                                         \
02956         CLASSERT(offsetof(typeof(*__foo_io), base) == 0);               \
02957         memset(&__foo_io->base + 1, 0,                                  \
02958                (sizeof *__foo_io) - sizeof __foo_io->base);             \
02959 } while (0)
02960 
02969 #define cl_page_list_for_each(page, list)                               \
02970         cfs_list_for_each_entry((page), &(list)->pl_pages, cp_batch)
02971 
02975 #define cl_page_list_for_each_safe(page, temp, list)                    \
02976         cfs_list_for_each_entry_safe((page), (temp), &(list)->pl_pages, cp_batch)
02977 
02978 void cl_page_list_init   (struct cl_page_list *plist);
02979 void cl_page_list_add    (struct cl_page_list *plist, struct cl_page *page);
02980 void cl_page_list_move   (struct cl_page_list *dst, struct cl_page_list *src,
02981                           struct cl_page *page);
02982 void cl_page_list_splice (struct cl_page_list *list,
02983                           struct cl_page_list *head);
02984 void cl_page_list_del    (const struct lu_env *env,
02985                           struct cl_page_list *plist, struct cl_page *page);
02986 void cl_page_list_disown (const struct lu_env *env,
02987                           struct cl_io *io, struct cl_page_list *plist);
02988 int  cl_page_list_own    (const struct lu_env *env,
02989                           struct cl_io *io, struct cl_page_list *plist);
02990 void cl_page_list_assume (const struct lu_env *env,
02991                           struct cl_io *io, struct cl_page_list *plist);
02992 void cl_page_list_discard(const struct lu_env *env,
02993                           struct cl_io *io, struct cl_page_list *plist);
02994 int  cl_page_list_unmap  (const struct lu_env *env,
02995                           struct cl_io *io, struct cl_page_list *plist);
02996 void cl_page_list_fini   (const struct lu_env *env, struct cl_page_list *plist);
02997 
02998 void cl_2queue_init     (struct cl_2queue *queue);
02999 void cl_2queue_add      (struct cl_2queue *queue, struct cl_page *page);
03000 void cl_2queue_disown   (const struct lu_env *env,
03001                          struct cl_io *io, struct cl_2queue *queue);
03002 void cl_2queue_assume   (const struct lu_env *env,
03003                          struct cl_io *io, struct cl_2queue *queue);
03004 void cl_2queue_discard  (const struct lu_env *env,
03005                          struct cl_io *io, struct cl_2queue *queue);
03006 void cl_2queue_fini     (const struct lu_env *env, struct cl_2queue *queue);
03007 void cl_2queue_init_page(struct cl_2queue *queue, struct cl_page *page);
03008 
03013 struct cl_req *cl_req_alloc(const struct lu_env *env, struct cl_page *page,
03014                             enum cl_req_type crt, int nr_objects);
03015 
03016 void cl_req_page_add  (const struct lu_env *env, struct cl_req *req,
03017                        struct cl_page *page);
03018 void cl_req_page_done (const struct lu_env *env, struct cl_page *page);
03019 int  cl_req_prep      (const struct lu_env *env, struct cl_req *req);
03020 void cl_req_attr_set  (const struct lu_env *env, struct cl_req *req,
03021                        struct cl_req_attr *attr, obd_valid flags);
03022 void cl_req_completion(const struct lu_env *env, struct cl_req *req, int ioret);
03023 
03033 struct cl_sync_io {
03035         cfs_atomic_t          csi_sync_nr;
03037         cfs_waitq_t          csi_waitq;
03039         int                   csi_sync_rc;
03040 };
03041 
03042 void cl_sync_io_init(struct cl_sync_io *anchor, int nrpages);
03043 int  cl_sync_io_wait(const struct lu_env *env, struct cl_io *io,
03044                      struct cl_page_list *queue, struct cl_sync_io *anchor,
03045                      long timeout);
03046 void cl_sync_io_note(struct cl_sync_io *anchor, int ioret);
03047 
03089 struct cl_env_nest {
03090         int   cen_refcheck;
03091         void *cen_cookie;
03092 };
03093 
03094 struct lu_env *cl_env_peek       (int *refcheck);
03095 struct lu_env *cl_env_get        (int *refcheck);
03096 struct lu_env *cl_env_alloc      (int *refcheck, __u32 tags);
03097 struct lu_env *cl_env_nested_get (struct cl_env_nest *nest);
03098 void           cl_env_put        (struct lu_env *env, int *refcheck);
03099 void           cl_env_nested_put (struct cl_env_nest *nest, struct lu_env *env);
03100 void          *cl_env_reenter    (void);
03101 void           cl_env_reexit     (void *cookie);
03102 void           cl_env_implant    (struct lu_env *env, int *refcheck);
03103 void           cl_env_unplant    (struct lu_env *env, int *refcheck);
03104 unsigned       cl_env_cache_purge(unsigned nr);
03105 
03108 /*
03109  * Misc
03110  */
03111 void cl_attr2lvb(struct ost_lvb *lvb, const struct cl_attr *attr);
03112 void cl_lvb2attr(struct cl_attr *attr, const struct ost_lvb *lvb);
03113 
03114 struct cl_device *cl_type_setup(const struct lu_env *env, struct lu_site *site,
03115                                 struct lu_device_type *ldt,
03116                                 struct lu_device *next);
03119 #endif /* _LINUX_CL_OBJECT_H */

Generated on Mon Apr 12 04:18:20 2010 for Lustre 1.10.0.40-0-g9a80ff7 by doxygen 1.4.7

Contact | About Sun | News | Employment | Privacy | Terms of Use | Trademarks | (C) 2008 Sun Microsystems, Inc.