Whamcloud - gitweb
199533080ac1438e1f5785f80d7b5c1aac6b6b28
[fs/lustre-release.git] / lustre / include / obd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  */
4
5 #ifndef __OBD_H
6 #define __OBD_H
7
8 #if defined(__linux__)
9 #include <linux/obd.h>
10 #elif defined(__APPLE__)
11 #include <darwin/obd.h>
12 #elif defined(__WINNT__)
13 #include <winnt/obd.h>
14 #else
15 #error Unsupported operating system.
16 #endif
17
18 #define IOC_OSC_TYPE         'h'
19 #define IOC_OSC_MIN_NR       20
20 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
21 #define IOC_OSC_MAX_NR       50
22
23 #define IOC_MDC_TYPE         'i'
24 #define IOC_MDC_MIN_NR       20
25 /* Moved to lustre_user.h
26 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_ioctl_data *)
27 #define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
28 #define IOC_MDC_MAX_NR       50
29
30 #include <lustre/lustre_idl.h>
31 #include <lu_object.h>
32 #include <lustre_lib.h>
33 #include <lustre_export.h>
34 #include <lustre_quota.h>
35 #include <lustre_fld.h>
36 #include <lustre_capa.h>
37 #include <class_hash.h>
38
39 #include <libcfs/bitmap.h>
40
41
42 #define MAX_OBD_DEVICES 8192
43
44 /* this is really local to the OSC */
45 struct loi_oap_pages {
46         struct list_head        lop_pending;
47         struct list_head        lop_urgent;
48         struct list_head        lop_pending_group;
49         int                     lop_num_pending;
50 };
51
52 struct osc_async_rc {
53         int     ar_rc;
54         int     ar_force_sync;
55         __u64   ar_min_xid;
56 };
57
58 struct lov_oinfo {                 /* per-stripe data structure */
59         __u64 loi_id;              /* object ID on the target OST */
60         __u64 loi_gr;              /* object group on the target OST */
61         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
62         int loi_ost_gen;           /* generation of this loi_ost_idx */
63
64         /* used by the osc to keep track of what objects to build into rpcs */
65         struct loi_oap_pages loi_read_lop;
66         struct loi_oap_pages loi_write_lop;
67         /* _cli_ is poorly named, it should be _ready_ */
68         struct list_head loi_cli_item;
69         struct list_head loi_write_item;
70         struct list_head loi_read_item;
71
72         unsigned long loi_kms_valid:1;
73         __u64 loi_kms;             /* known minimum size */
74         struct ost_lvb loi_lvb;
75         struct osc_async_rc     loi_ar;
76 };
77
78 static inline void loi_init(struct lov_oinfo *loi)
79 {
80         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
81         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
82         CFS_INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
83         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
84         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
85         CFS_INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
86         CFS_INIT_LIST_HEAD(&loi->loi_cli_item);
87         CFS_INIT_LIST_HEAD(&loi->loi_write_item);
88         CFS_INIT_LIST_HEAD(&loi->loi_read_item);
89 }
90
91 /*extent array item for describing the joined file extent info*/
92 struct lov_extent {
93         __u64 le_start;            /* extent start */
94         __u64 le_len;              /* extent length */
95         int   le_loi_idx;          /* extent #1 loi's index in lsm loi array */
96         int   le_stripe_count;     /* extent stripe count*/
97 };
98
99 /*Lov array info for describing joined file array EA info*/
100 struct lov_array_info {
101         struct llog_logid    lai_array_id;    /* MDS med llog object id */
102         unsigned             lai_ext_count; /* number of extent count */
103         struct lov_extent    *lai_ext_array; /* extent desc array */
104 };
105
106 struct lov_stripe_md {
107         spinlock_t       lsm_lock;
108         pid_t            lsm_lock_owner; /* debugging */
109
110         struct {
111                 /* Public members. */
112                 __u64 lw_object_id;        /* lov object id */
113                 __u64 lw_object_gr;        /* lov object group */
114                 __u64 lw_maxbytes;         /* maximum possible file size */
115
116                 /* LOV-private members start here -- only for use in lov/. */
117                 __u32 lw_magic;
118                 __u32 lw_stripe_size;      /* size of the stripe */
119                 __u32 lw_pattern;          /* striping pattern (RAID0, RAID1) */
120                 unsigned lw_stripe_count;  /* number of objects being striped over */
121         } lsm_wire;
122
123         struct lov_array_info *lsm_array; /*Only for joined file array info*/
124         struct lov_oinfo *lsm_oinfo[0];
125 };
126
127 #define lsm_object_id    lsm_wire.lw_object_id
128 #define lsm_object_gr    lsm_wire.lw_object_gr
129 #define lsm_maxbytes     lsm_wire.lw_maxbytes
130 #define lsm_magic        lsm_wire.lw_magic
131 #define lsm_stripe_size  lsm_wire.lw_stripe_size
132 #define lsm_pattern      lsm_wire.lw_pattern
133 #define lsm_stripe_count lsm_wire.lw_stripe_count
134
135 struct obd_info;
136
137 typedef int (*obd_enqueue_update_f)(struct obd_info *oinfo, int rc);
138
139 /* obd info for a particular level (lov, osc). */
140 struct obd_info {
141         /* Lock policy. It keeps an extent which is specific for a particular
142          * OSC. (e.g. lov_prep_enqueue_set initialises extent of the policy,
143          * and osc_enqueue passes it into ldlm_lock_match & ldlm_cli_enqueue. */
144         ldlm_policy_data_t      oi_policy;
145         /* Flags used for set request specific flags:
146            - while lock handling, the flags obtained on the enqueue
147            request are set here.
148            - while stats, the flags used for control delay/resend.
149          */
150         int                     oi_flags;
151         /* Lock handle specific for every OSC lock. */
152         struct lustre_handle   *oi_lockh;
153         /* lsm data specific for every OSC. */
154         struct lov_stripe_md   *oi_md;
155         /* obdo data specific for every OSC, if needed at all. */
156         struct obdo            *oi_oa;
157         /* statfs data specific for every OSC, if needed at all. */
158         struct obd_statfs      *oi_osfs;
159         /* An update callback which is called to update some data on upper
160          * level. E.g. it is used for update lsm->lsm_oinfo at every recieved
161          * request in osc level for enqueue requests. It is also possible to
162          * update some caller data from LOV layer if needed. */
163         obd_enqueue_update_f    oi_cb_up;
164         /* oss capability, its type is obd_capa in client to avoid copy.
165          * in contrary its type is lustre_capa in OSS. */
166         void                   *oi_capa;
167 };
168
169 /* compare all relevant fields. */
170 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
171                                     struct lov_stripe_md *m2)
172 {
173         /*
174          * ->lsm_wire contains padding, but it should be zeroed out during
175          * allocation.
176          */
177         return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
178 }
179
180 void lov_stripe_lock(struct lov_stripe_md *md);
181 void lov_stripe_unlock(struct lov_stripe_md *md);
182
183 struct obd_type {
184         struct list_head typ_chain;
185         struct obd_ops *typ_dt_ops;
186         struct md_ops *typ_md_ops;
187         cfs_proc_dir_entry_t *typ_procroot;
188         char *typ_name;
189         int  typ_refcnt;
190         struct lu_device_type *typ_lu;
191         spinlock_t obd_type_lock;
192 };
193
194 struct brw_page {
195         obd_off  off;
196         cfs_page_t *pg;
197         int count;
198         obd_flag flag;
199 };
200
201 enum async_flags {
202         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
203                               page is added to an rpc */
204         ASYNC_URGENT = 0x2, /* page must be put into an RPC before return */
205         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
206                                      to give the caller a chance to update
207                                      or cancel the size of the io */
208         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
209                                     the page is accounted for in the
210                                     obd_io_group given to
211                                     obd_queue_group_io */
212 };
213
214 struct obd_async_page_ops {
215         int  (*ap_make_ready)(void *data, int cmd);
216         int  (*ap_refresh_count)(void *data, int cmd);
217         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
218         void (*ap_update_obdo)(void *data, int cmd, struct obdo *oa,
219                                obd_valid valid);
220         int  (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
221         struct obd_capa *(*ap_lookup_capa)(void *data, int cmd);
222 };
223
224 /* the `oig' is passed down from a caller of obd rw methods.  the callee
225  * records enough state such that the caller can sleep on the oig and
226  * be woken when all the callees have finished their work */
227 struct obd_io_group {
228         spinlock_t      oig_lock;
229         atomic_t        oig_refcount;
230         int             oig_pending;
231         int             oig_rc;
232         struct list_head oig_occ_list;
233         cfs_waitq_t     oig_waitq;
234 };
235
236 /* the oig callback context lets the callee of obd rw methods register
237  * for callbacks from the caller. */
238 struct oig_callback_context {
239         struct list_head occ_oig_item;
240         /* called when the caller has received a signal while sleeping.
241          * callees of this method are encouraged to abort their state
242          * in the oig.  This may be called multiple times. */
243         void (*occ_interrupted)(struct oig_callback_context *occ);
244         unsigned long interrupted:1;
245 };
246
247 /* Individual type definitions */
248
249 struct ost_server_data;
250
251 /* hold common fields for "target" device */
252 struct obd_device_target {
253         struct super_block       *obt_sb;
254         atomic_t                  obt_quotachecking;
255         struct lustre_quota_ctxt  obt_qctxt;
256 };
257
258 typedef void (*obd_pin_extent_cb)(void *data);
259 typedef int (*obd_page_removal_cb_t)(void *data, int discard);
260 typedef int (*obd_lock_cancel_cb)(struct ldlm_lock *,struct ldlm_lock_desc *,
261                                    void *, int);
262
263 /* llog contexts */
264 enum llog_ctxt_id {
265         LLOG_CONFIG_ORIG_CTXT  =  0,
266         LLOG_CONFIG_REPL_CTXT,
267         LLOG_MDS_OST_ORIG_CTXT,
268         LLOG_MDS_OST_REPL_CTXT,
269         LLOG_SIZE_ORIG_CTXT,
270         LLOG_SIZE_REPL_CTXT,
271         LLOG_RD1_ORIG_CTXT,
272         LLOG_RD1_REPL_CTXT,
273         LLOG_TEST_ORIG_CTXT,
274         LLOG_TEST_REPL_CTXT,
275         LLOG_LOVEA_ORIG_CTXT,
276         LLOG_LOVEA_REPL_CTXT,
277         LLOG_MAX_CTXTS
278 };
279
280 #define FILTER_SUBDIR_COUNT      32            /* set to zero for no subdirs */
281
282 struct filter_subdirs {
283        cfs_dentry_t *dentry[FILTER_SUBDIR_COUNT];
284 };
285
286
287 struct filter_ext {
288         __u64                fe_start;
289         __u64                fe_end;
290 };
291
292 struct filter_obd {
293         /* NB this field MUST be first */
294         struct obd_device_target fo_obt;
295         const char          *fo_fstype;
296         struct vfsmount     *fo_vfsmnt;
297
298         int                  fo_group_count;
299         cfs_dentry_t        *fo_dentry_O;
300         cfs_dentry_t       **fo_dentry_O_groups;
301         struct filter_subdirs   *fo_dentry_O_sub;
302         struct semaphore     fo_init_lock;      /* group initialization lock */
303         int                  fo_committed_group;
304
305
306         spinlock_t           fo_objidlock;      /* protect fo_lastobjid */
307         spinlock_t           fo_translock;      /* protect fsd_last_transno */
308         struct file         *fo_rcvd_filp;
309         struct file         *fo_health_check_filp;
310         struct lr_server_data *fo_fsd;
311         unsigned long       *fo_last_rcvd_slots;
312         __u64                fo_mount_count;
313
314         unsigned long        fo_destroys_in_progress;
315         struct semaphore     fo_create_locks[FILTER_SUBDIR_COUNT];
316
317         struct list_head     fo_export_list;
318         int                  fo_subdir_count;
319
320         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
321         obd_size             fo_tot_granted;    /* all values in bytes */
322         obd_size             fo_tot_pending;
323
324         obd_size             fo_readcache_max_filesize;
325
326         struct obd_import   *fo_mdc_imp;
327         struct obd_uuid      fo_mdc_uuid;
328         struct lustre_handle fo_mdc_conn;
329         struct file        **fo_last_objid_files;
330         __u64               *fo_last_objids; /* last created objid for groups,
331                                               * protected by fo_objidlock */
332
333         struct semaphore     fo_alloc_lock;
334
335         atomic_t             fo_r_in_flight;
336         atomic_t             fo_w_in_flight;
337
338         /*
339          * per-filter pool of kiobuf's allocated by filter_common_setup() and
340          * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
341          * which ->fo_iobuf_count were allocated.
342          *
343          * This pool contains kiobuf used by
344          * filter_{prep,commit}rw_{read,write}() and is shared by all OST
345          * threads.
346          *
347          * Locking: none, each OST thread uses only one element, determined by
348          * its "ordinal number", ->t_id.
349          */
350         struct filter_iobuf    **fo_iobuf_pool;
351         int                      fo_iobuf_count;
352
353         struct list_head         fo_llog_list;
354         spinlock_t               fo_llog_list_lock;
355
356         struct brw_stats         fo_filter_stats;
357         struct lustre_quota_ctxt fo_quota_ctxt;
358         spinlock_t               fo_quotacheck_lock;
359         atomic_t                 fo_quotachecking;
360
361         int                      fo_fmd_max_num; /* per exp filter_mod_data */
362         int                      fo_fmd_max_age; /* jiffies to fmd expiry */
363
364         /* sptlrpc stuff */
365         rwlock_t                 fo_sptlrpc_lock;
366         struct sptlrpc_rule_set  fo_sptlrpc_rset;
367
368         /* capability related */
369         unsigned int             fo_fl_oss_capa;
370         struct list_head         fo_capa_keys;
371         struct hlist_head       *fo_capa_hash;
372
373         void                    *fo_lcm;
374 };
375
376 #define OSC_MAX_RIF_DEFAULT       8
377 #define OSC_MAX_RIF_MAX         256
378 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
379 #define OSC_MAX_DIRTY_MB_MAX   2048     /* arbitrary, but < MAX_LONG bytes */
380 #define OSC_DEFAULT_RESENDS      10
381
382 #define MDC_MAX_RIF_DEFAULT       8
383 #define MDC_MAX_RIF_MAX         512
384
385 struct mdc_rpc_lock;
386 struct obd_import;
387 struct lustre_cache;
388 struct client_obd {
389         struct semaphore         cl_sem;
390         struct obd_uuid          cl_target_uuid;
391         struct obd_import       *cl_import; /* ptlrpc connection state */
392         int                      cl_conn_count;
393         /* max_mds_easize is purely a performance thing so we don't have to
394          * call obd_size_diskmd() all the time. */
395         int                      cl_default_mds_easize;
396         int                      cl_max_mds_easize;
397         int                      cl_max_mds_cookiesize;
398
399         /* security configuration */
400         struct sptlrpc_rule_set  cl_sptlrpc_rset;
401         enum lustre_sec_part     cl_sec_part;
402
403         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
404         void                    *cl_llcd_offset;
405
406         /* the grant values are protected by loi_list_lock below */
407         long                     cl_dirty;         /* all _dirty_ in bytes */
408         long                     cl_dirty_max;     /* allowed w/o rpc */
409         long                     cl_avail_grant;   /* bytes of credit for ost */
410         long                     cl_lost_grant;    /* lost credits (trunc) */
411         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
412
413         /* keep track of objects that have lois that contain pages which
414          * have been queued for async brw.  this lock also protects the
415          * lists of osc_client_pages that hang off of the loi */
416         /*
417          * ->cl_loi_list_lock protects consistency of
418          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
419          * ->ap_completion() call-backs are executed under this lock. As we
420          * cannot guarantee that these call-backs never block on all platforms
421          * (as a matter of fact they do block on Mac OS X), type of
422          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
423          * and blocking mutex on Mac OS X. (Alternative is to make this lock
424          * blocking everywhere, but we don't want to slow down fast-path of
425          * our main platform.)
426          *
427          * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
428          * with client_obd_list_{un,}lock() and
429          * client_obd_list_lock_{init,done}() functions.
430          */
431         client_obd_lock_t        cl_loi_list_lock;
432         struct list_head         cl_loi_ready_list;
433         struct list_head         cl_loi_write_list;
434         struct list_head         cl_loi_read_list;
435         int                      cl_r_in_flight;
436         int                      cl_w_in_flight;
437         /* just a sum of the loi/lop pending numbers to be exported by /proc */
438         int                      cl_pending_w_pages;
439         int                      cl_pending_r_pages;
440         int                      cl_max_pages_per_rpc;
441         int                      cl_max_rpcs_in_flight;
442         struct obd_histogram     cl_read_rpc_hist;
443         struct obd_histogram     cl_write_rpc_hist;
444         struct obd_histogram     cl_read_page_hist;
445         struct obd_histogram     cl_write_page_hist;
446         struct obd_histogram     cl_read_offset_hist;
447         struct obd_histogram     cl_write_offset_hist;
448
449         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
450         atomic_t                 cl_destroy_in_flight;
451         cfs_waitq_t              cl_destroy_waitq;
452
453         struct mdc_rpc_lock     *cl_rpc_lock;
454         struct mdc_rpc_lock     *cl_setattr_lock;
455         struct mdc_rpc_lock     *cl_close_lock;
456         struct osc_creator       cl_oscc;
457
458         /* mgc datastruct */
459         struct semaphore         cl_mgc_sem;
460         struct vfsmount         *cl_mgc_vfsmnt;
461         struct dentry           *cl_mgc_configs_dir;
462         atomic_t                 cl_mgc_refcount;
463         struct obd_export       *cl_mgc_mgsexp;
464
465         /* checksumming for data sent over the network */
466         unsigned int             cl_checksum:1; /* 0 = disabled, 1 = enabled */
467         /* supported checksum types that are worked out at connect time */
468         __u32                    cl_supp_cksum_types;
469         /* checksum algorithm to be used */
470         cksum_type_t             cl_cksum_type;
471  
472         /* also protected by the poorly named _loi_list_lock lock above */
473         struct osc_async_rc      cl_ar;
474
475         /* used by quotacheck */
476         int                      cl_qchk_stat; /* quotacheck stat of the peer */
477
478         /* sequence manager */
479         struct lu_client_seq    *cl_seq;
480
481         atomic_t                 cl_resends; /* resend count */
482
483         /* Cache of triples */
484         struct lustre_cache     *cl_cache;
485         obd_lock_cancel_cb       cl_ext_lock_cancel_cb;
486 };
487 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
488
489 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
490
491 struct mgs_obd {
492         struct ptlrpc_service           *mgs_service;
493         struct vfsmount                 *mgs_vfsmnt;
494         struct super_block              *mgs_sb;
495         struct dentry                   *mgs_configs_dir;
496         struct dentry                   *mgs_fid_de;
497         struct list_head                 mgs_fs_db_list;
498         struct semaphore                 mgs_sem;
499         cfs_proc_dir_entry_t            *mgs_proc_live;
500 };
501
502 struct mds_obd {
503         /* NB this field MUST be first */
504         struct obd_device_target         mds_obt;
505         struct ptlrpc_service           *mds_service;
506         struct ptlrpc_service           *mds_setattr_service;
507         struct ptlrpc_service           *mds_readpage_service;
508         struct vfsmount                 *mds_vfsmnt;
509         cfs_dentry_t                    *mds_fid_de;
510         int                              mds_max_mdsize;
511         int                              mds_max_cookiesize;
512         struct file                     *mds_rcvd_filp;
513         spinlock_t                       mds_transno_lock;
514         __u64                            mds_last_transno;
515         __u64                            mds_mount_count;
516         __u64                            mds_io_epoch;
517         unsigned long                    mds_atime_diff;
518         struct semaphore                 mds_epoch_sem;
519         struct ll_fid                    mds_rootfid;
520         struct lr_server_data           *mds_server_data;
521         cfs_dentry_t                    *mds_pending_dir;
522         cfs_dentry_t                    *mds_logs_dir;
523         cfs_dentry_t                    *mds_objects_dir;
524         struct llog_handle              *mds_cfg_llh;
525         struct obd_device               *mds_osc_obd; /* XXX lov_obd */
526         struct obd_uuid                  mds_lov_uuid;
527         char                            *mds_profile;
528         struct obd_export               *mds_osc_exp; /* XXX lov_exp */
529         struct lov_desc                  mds_lov_desc;
530         __u32                            mds_id;
531
532         /* mark pages dirty for write. */
533         bitmap_t                         *mds_lov_page_dirty;
534         /* array for store pages with obd_id */
535         void                            **mds_lov_page_array;
536         /* file for store objid */
537         struct file                     *mds_lov_objid_filp;
538         __u32                            mds_lov_objid_count;
539         __u32                            mds_lov_objid_lastpage;
540         __u32                            mds_lov_objid_lastidx;
541
542         struct file                     *mds_health_check_filp;
543         unsigned long                   *mds_client_bitmap;
544 //        struct upcall_cache             *mds_group_hash;
545
546         struct lustre_quota_info         mds_quota_info;
547         struct semaphore                 mds_qonoff_sem;
548         struct semaphore                 mds_health_sem;
549         unsigned long                    mds_fl_user_xattr:1,
550                                          mds_fl_acl:1,
551                                          mds_evict_ost_nids:1,
552                                          mds_fl_cfglog:1,
553                                          mds_fl_synced:1;
554
555         struct upcall_cache             *mds_identity_cache;
556
557         /* for capability keys update */
558         struct lustre_capa_key          *mds_capa_keys;
559 };
560
561 /* lov objid */
562 extern __u32 mds_max_ost_index;
563
564 #define MDS_LOV_ALLOC_SIZE (CFS_PAGE_SIZE)
565
566 #define OBJID_PER_PAGE() (MDS_LOV_ALLOC_SIZE / sizeof(obd_id))
567
568 #define MDS_LOV_OBJID_PAGES_COUNT (mds_max_ost_index/OBJID_PER_PAGE())
569
570 extern int mds_lov_init_objids(struct obd_device *obd);
571 extern void mds_lov_destroy_objids(struct obd_device *obd);
572
573 struct obd_id_info {
574         __u32   idx;
575         obd_id  *data;
576 };
577
578 /* */
579
580 struct echo_obd {
581         struct obdo          eo_oa;
582         spinlock_t           eo_lock;
583         __u64                eo_lastino;
584         struct lustre_handle eo_nl_lock;
585         atomic_t             eo_prep;
586 };
587
588 struct ost_obd {
589         struct ptlrpc_service *ost_service;
590         struct ptlrpc_service *ost_create_service;
591         struct ptlrpc_service *ost_io_service;
592         struct semaphore       ost_health_sem;
593 };
594
595 struct echo_client_obd {
596         struct obd_export   *ec_exp;   /* the local connection to osc/lov */
597         spinlock_t           ec_lock;
598         struct list_head     ec_objects;
599         int                  ec_nstripes;
600         __u64                ec_unique;
601 };
602
603 struct lov_qos_oss {
604         struct obd_uuid     lqo_uuid;       /* ptlrpc's c_remote_uuid */
605         struct list_head    lqo_oss_list;   /* link to lov_qos */
606         __u32               lqo_ost_count;  /* number of osts on this oss */
607         __u64               lqo_bavail;     /* total bytes avail on OSS */
608         __u64               lqo_penalty;    /* current penalty */
609         __u64               lqo_penalty_per_obj; /* penalty decrease every obj*/
610 };
611
612 struct ltd_qos {
613         struct lov_qos_oss *ltq_oss;         /* oss info */
614         __u64               ltq_penalty;     /* current penalty */
615         __u64               ltq_penalty_per_obj; /* penalty decrease every obj*/
616         __u64               ltq_weight;      /* net weighting */
617         unsigned int        ltq_usable:1;    /* usable for striping */
618 };
619
620 struct lov_qos {
621         struct list_head    lq_oss_list;    /* list of OSSs that targets use */
622         struct rw_semaphore lq_rw_sem;
623         __u32               lq_active_oss_count;
624         __u32              *lq_rr_array;    /* round-robin optimized list */
625         unsigned int        lq_rr_size;     /* rr array size */
626         unsigned int        lq_prio_free;   /* priority for free space */
627         unsigned long       lq_dirty:1,     /* recalc qos data */
628                             lq_dirty_rr:1,  /* recalc round-robin list */
629                             lq_same_space:1,/* the ost's all have approx.
630                                                the same space avail */
631                             lq_reset:1;     /* zero current penalties */
632 };
633
634 struct lov_tgt_desc {
635         struct obd_uuid     ltd_uuid;
636         struct obd_export  *ltd_exp;
637         struct ltd_qos      ltd_qos;     /* qos info per target */
638         __u32               ltd_gen;
639         __u32               ltd_index;   /* index in lov_obd->tgts */
640         unsigned long       ltd_active:1,/* is this target up for requests */
641                             ltd_activate:1,/* should this target be activated */
642                             ltd_reap:1;  /* should this target be deleted */
643 };
644
645 struct lov_obd {
646         struct lov_desc         desc;
647         struct lov_tgt_desc   **lov_tgts;
648         struct semaphore        lov_lock;
649         struct obd_connect_data lov_ocd;
650         struct lov_qos          lov_qos;               /* qos info per lov */
651         atomic_t                lov_refcount;
652         __u32                   lov_tgt_count;         /* how many OBD's */
653         __u32                   lov_active_tgt_count;  /* how many active */
654         __u32                   lov_death_row;/* tgts scheduled to be deleted */
655         __u32                   lov_tgt_size;   /* size of tgts array */
656         __u32                   lov_start_idx;  /* start index of new inode */
657         __u32                   lov_offset_idx; /* aliasing for start_idx  */
658         int                     lov_start_count;/* reseed counter */
659         int                     lov_connects;
660         obd_page_removal_cb_t   lov_page_removal_cb;
661         obd_pin_extent_cb       lov_page_pin_cb;
662         obd_lock_cancel_cb      lov_lock_cancel_cb;
663 };
664
665 struct lmv_tgt_desc {
666         struct obd_uuid         ltd_uuid;
667         struct obd_export      *ltd_exp;
668         int                     ltd_active;   /* is this target up for requests */
669         int                     ltd_idx;
670         struct semaphore        ltd_fid_sem;
671 };
672
673 struct lmv_obd {
674         int                     refcount;
675         struct lu_client_fld    lmv_fld;
676         spinlock_t              lmv_lock;
677         struct lmv_desc         desc;
678         struct obd_uuid         cluuid;
679         struct obd_export       *exp;
680
681         int                     connected;
682         int                     max_easize;
683         int                     max_def_easize;
684         int                     max_cookiesize;
685         int                     server_timeout;
686         struct semaphore        init_sem;
687
688         struct lmv_tgt_desc     *tgts;
689         int                     tgts_size;
690
691         struct obd_connect_data *datas;
692         int                     datas_size;
693
694         struct obd_connect_data conn_data;
695 };
696
697 struct niobuf_local {
698         __u64 offset;
699         __u32 len;
700         __u32 flags;
701         cfs_page_t    *page;
702         cfs_dentry_t  *dentry;
703         int lnb_grant_used;
704         int rc;
705 };
706
707 #define LUSTRE_FLD_NAME         "fld"
708 #define LUSTRE_SEQ_NAME         "seq"
709
710 #define LUSTRE_CMM_NAME         "cmm"
711 #define LUSTRE_MDD_NAME         "mdd"
712 #define LUSTRE_OSD_NAME         "osd"
713 #define LUSTRE_LMV_NAME         "lmv"
714 #define LUSTRE_CMM_MDC_NAME     "cmm-mdc"
715
716 /* obd device type names */
717  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
718 #define LUSTRE_MDS_NAME         "mds"
719 #define LUSTRE_MDT_NAME         "mdt"
720 #define LUSTRE_MDC_NAME         "mdc"
721 #define LUSTRE_OSS_NAME         "ost"       /* FIXME change name to oss */
722 #define LUSTRE_OST_NAME         "obdfilter" /* FIXME change name to ost */
723 #define LUSTRE_OSC_NAME         "osc"
724 #define LUSTRE_LOV_NAME         "lov"
725 #define LUSTRE_MGS_NAME         "mgs"
726 #define LUSTRE_MGC_NAME         "mgc"
727
728 #define LUSTRE_CACHEOBD_NAME    "cobd"
729 #define LUSTRE_ECHO_NAME        "obdecho"
730 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
731
732 /* Constant obd names (post-rename) */
733 #define LUSTRE_MDS_OBDNAME "MDS"
734 #define LUSTRE_OSS_OBDNAME "OSS"
735 #define LUSTRE_MGS_OBDNAME "MGS"
736 #define LUSTRE_MGC_OBDNAME "MGC"
737
738 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
739 #define N_LOCAL_TEMP_PAGE 0x10000000
740
741 struct obd_trans_info {
742         __u64                    oti_transno;
743         __u64                    oti_xid;
744         /* Only used on the server side for tracking acks. */
745         struct oti_req_ack_lock {
746                 struct lustre_handle lock;
747                 __u32                mode;
748         }                        oti_ack_locks[4];
749         void                    *oti_handle;
750         struct llog_cookie       oti_onecookie;
751         struct llog_cookie      *oti_logcookies;
752         int                      oti_numcookies;
753
754         /* initial thread handling transaction */
755         int                      oti_thread_id;
756         __u32                    oti_conn_cnt;
757 };
758
759 static inline void oti_init(struct obd_trans_info *oti,
760                             struct ptlrpc_request *req)
761 {
762         if (oti == NULL)
763                 return;
764         memset(oti, 0, sizeof(*oti));
765
766         if (req == NULL)
767                 return;
768
769         oti->oti_xid = req->rq_xid;
770
771         if (req->rq_repmsg != NULL)
772                 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
773         oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
774         if (req->rq_reqmsg != NULL)
775                 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
776 }
777
778 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
779 {
780         if (!oti)
781                 return;
782
783         if (num_cookies == 1)
784                 oti->oti_logcookies = &oti->oti_onecookie;
785         else
786                 OBD_ALLOC(oti->oti_logcookies,
787                           num_cookies * sizeof(oti->oti_onecookie));
788
789         oti->oti_numcookies = num_cookies;
790 }
791
792 static inline void oti_free_cookies(struct obd_trans_info *oti)
793 {
794         if (!oti || !oti->oti_logcookies)
795                 return;
796
797         if (oti->oti_logcookies == &oti->oti_onecookie)
798                 LASSERT(oti->oti_numcookies == 1);
799         else
800                 OBD_FREE(oti->oti_logcookies,
801                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
802         oti->oti_logcookies = NULL;
803         oti->oti_numcookies = 0;
804 }
805
806 /*
807  * Events signalled through obd_notify() upcall-chain.
808  */
809 enum obd_notify_event {
810         /* Device activated */
811         OBD_NOTIFY_ACTIVE,
812         /* Device deactivated */
813         OBD_NOTIFY_INACTIVE,
814         /* Device disconnected */
815         OBD_NOTIFY_DISCON,
816         /* Connect data for import were changed */
817         OBD_NOTIFY_OCD,
818         /* Sync request */
819         OBD_NOTIFY_SYNC_NONBLOCK,
820         OBD_NOTIFY_SYNC,
821         /* Configuration event */
822         OBD_NOTIFY_CONFIG
823 };
824
825 /* bit-mask flags for config events */
826 enum config_flags {
827         CONFIG_LOG = 0x1,  /* finished processing config log */
828         CONFIG_SYNC = 0x2  /* mdt synced 1 ost */
829 };
830
831 /*
832  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
833  * and liblustre being main examples).
834  */
835 struct obd_notify_upcall {
836         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
837                           enum obd_notify_event ev, void *owner);
838         /* Opaque datum supplied by upper layer listener */
839         void *onu_owner;
840 };
841
842 struct target_recovery_data {
843         svc_handler_t     trd_recovery_handler;
844         pid_t             trd_processing_task;
845         struct completion trd_starting;
846         struct completion trd_finishing;
847 };
848
849 #define OBD_LLOG_GROUP  0
850
851 enum filter_groups {
852         FILTER_GROUP_LLOG = 1,
853         FILTER_GROUP_ECHO,
854         FILTER_GROUP_MDS0
855 };
856
857 struct obd_llog_group {
858         struct list_head   olg_list;
859         int                olg_group;
860         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
861         cfs_waitq_t        olg_waitq;
862         spinlock_t         olg_lock;
863         struct obd_export *olg_exp;
864         int                olg_initializing;
865 };
866
867 /* corresponds to one of the obd's */
868 #define MAX_OBD_NAME 128
869 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
870 struct obd_device {
871         struct obd_type        *obd_type;
872         __u32                   obd_magic;
873
874         /* common and UUID name of this device */
875         char                    obd_name[MAX_OBD_NAME];
876         struct obd_uuid         obd_uuid;
877
878         struct lu_device       *obd_lu_dev;
879
880         int                     obd_minor;
881         unsigned long obd_attached:1,      /* finished attach */
882                       obd_set_up:1,        /* finished setup */
883                       obd_recovering:1,    /* there are recoverable clients */
884                       obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
885                       obd_replayable:1,    /* recovery is enabled; inform clients */
886                       obd_no_transno:1,    /* no committed-transno notification */
887                       obd_no_recov:1,      /* fail instead of retry messages */
888                       obd_req_replaying:1, /* replaying requests */
889                       obd_stopping:1,      /* started cleanup */
890                       obd_starting:1,      /* started setup */
891                       obd_force:1,         /* cleanup with > 0 obd refcount */
892                       obd_fail:1,          /* cleanup with failover */
893                       obd_async_recov:1,   /* allow asyncronous orphan cleanup */
894                       obd_no_conn:1,       /* deny new connections */
895                       obd_inactive:1;      /* device active/inactive
896                                            * (for /proc/status only!!) */
897         /* uuid-export hash body */
898         struct lustre_class_hash_body *obd_uuid_hash_body;
899         /* nid-export hash body */
900         struct lustre_class_hash_body *obd_nid_hash_body;
901         /* nid stats body */
902         struct lustre_class_hash_body *obd_nid_stats_hash_body;
903         struct list_head        obd_nid_stats;
904         atomic_t                obd_refcount;
905         cfs_waitq_t             obd_refcount_waitq;
906         struct list_head        obd_exports;
907         int                     obd_num_exports;
908         spinlock_t              obd_nid_lock;
909         struct ldlm_namespace  *obd_namespace;
910         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
911         /* a spinlock is OK for what we do now, may need a semaphore later */
912         spinlock_t              obd_dev_lock;
913         struct semaphore        obd_dev_sem;
914         __u64                   obd_last_committed;
915         struct fsfilt_operations *obd_fsops;
916         spinlock_t              obd_osfs_lock;
917         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
918         __u64                   obd_osfs_age;
919         struct lvfs_run_ctxt    obd_lvfs_ctxt;
920         struct obd_llog_group   obd_olg; /* default llog group */
921         struct obd_device       *obd_observer;
922         struct obd_notify_upcall obd_upcall;
923         struct obd_export       *obd_self_export;
924         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
925         struct list_head        obd_exports_timed;
926         time_t                  obd_eviction_timer; /* for ping evictor */
927
928         /* XXX encapsulate all this recovery data into one struct */
929         svc_handler_t                    obd_recovery_handler;
930         pid_t                            obd_processing_task;
931         
932         int                              obd_max_recoverable_clients;
933         int                              obd_connected_clients;
934         int                              obd_recoverable_clients;
935         spinlock_t                       obd_processing_task_lock; /* BH lock (timer) */
936         __u64                            obd_next_recovery_transno;
937         int                              obd_replayed_requests;
938         int                              obd_requests_queued_for_recovery;
939         cfs_waitq_t                      obd_next_transno_waitq;
940         struct list_head                 obd_uncommitted_replies;
941         spinlock_t                       obd_uncommitted_replies_lock;
942         cfs_timer_t                      obd_recovery_timer;
943         time_t                           obd_recovery_start; /* seconds */
944         time_t                           obd_recovery_end; /* seconds */
945         time_t                           obd_recovery_max_time; /* seconds, bz13079 */
946         
947         /* new recovery stuff from CMD2 */
948         struct target_recovery_data      obd_recovery_data;
949         int                              obd_replayed_locks;
950         atomic_t                         obd_req_replay_clients;
951         atomic_t                         obd_lock_replay_clients;
952         struct list_head                 obd_req_replay_queue;
953         struct list_head                 obd_lock_replay_queue;
954         struct list_head                 obd_final_req_queue;
955         int                              obd_recovery_stage;
956
957         union {
958                 struct obd_device_target obt;
959                 struct filter_obd filter;
960                 struct mds_obd mds;
961                 struct client_obd cli;
962                 struct ost_obd ost;
963                 struct echo_client_obd echo_client;
964                 struct echo_obd echo;
965                 struct lov_obd lov;
966                 struct lmv_obd lmv;
967                 struct mgs_obd mgs;
968         } u;
969         /* Fields used by LProcFS */
970         unsigned int           obd_cntr_base;
971         struct lprocfs_stats  *obd_stats;
972
973         unsigned int           md_cntr_base;
974         struct lprocfs_stats  *md_stats;
975
976         cfs_proc_dir_entry_t  *obd_proc_entry;
977         cfs_proc_dir_entry_t  *obd_proc_exports_entry;
978         cfs_proc_dir_entry_t  *obd_svc_procroot;
979         struct lprocfs_stats  *obd_svc_stats;
980         atomic_t               obd_evict_inprogress;
981         cfs_waitq_t            obd_evict_inprogress_waitq;
982
983         /** 
984          * Ldlm pool part. Save last calculated SLV and Limit. 
985          */
986         rwlock_t               obd_pool_lock;
987         int                    obd_pool_limit;
988         __u64                  obd_pool_slv;
989 };
990
991 #define OBD_OPT_FORCE           0x0001
992 #define OBD_OPT_FAILOVER        0x0002
993
994 #define OBD_LLOG_FL_SENDNOW     0x0001
995
996 enum obd_cleanup_stage {
997 /* Special case hack for MDS LOVs */
998         OBD_CLEANUP_EARLY,
999 /* Precleanup stage 1, we must make sure all exports (other than the
1000    self-export) get destroyed. */
1001         OBD_CLEANUP_EXPORTS,
1002 /* Precleanup stage 2,  do other type-specific cleanup requiring the
1003    self-export. */
1004         OBD_CLEANUP_SELF_EXP,
1005 /* FIXME we should eliminate the "precleanup" function and make them stages
1006    of the "cleanup" function. */
1007         OBD_CLEANUP_OBD,
1008 };
1009
1010 /* get/set_info keys */
1011 #define KEY_READ_ONLY           "read-only"
1012 #define KEY_MDS_CONN            "mds_conn"
1013 #define KEY_NEXT_ID             "next_id"
1014 #define KEY_LOVDESC             "lovdesc"
1015 #define KEY_INIT_RECOV          "initial_recov"
1016 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
1017 #define KEY_FLUSH_CTX           "flush_ctx"
1018 #define KEY_CAPA_KEY            "capa_key"
1019 #define KEY_CONN_DATA           "conn_data"
1020 #define KEY_MAX_EASIZE          "max_easize"
1021 #define KEY_REVIMP_UPD          "revimp_update"
1022 #define KEY_LOV_IDX             "lov_idx"
1023 #define KEY_LAST_ID             "last_id"
1024 #define KEY_READONLY            "read-only"
1025 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
1026 #define KEY_CHECKSUM            "checksum"
1027 #define KEY_UNLINKED            "unlinked"
1028 #define KEY_EVICT_BY_NID        "evict_by_nid"
1029 #define KEY_REGISTER_TARGET     "register_target"
1030 #define KEY_SET_FS              "set_fs"
1031 #define KEY_CLEAR_FS            "clear_fs"
1032 #define KEY_BLOCKSIZE           "blocksize"
1033 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
1034 /* XXX unused ?*/
1035 #define KEY_INTERMDS            "inter_mds"
1036 #define KEY_ASYNC               "async"
1037
1038 struct lu_context;
1039
1040 static inline int it_to_lock_mode(struct lookup_intent *it)
1041 {
1042         /* CREAT needs to be tested before open (both could be set) */
1043         if (it->it_op & IT_CREAT)
1044                 return LCK_CW;
1045         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
1046                 return LCK_CR;
1047  
1048         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
1049         return -EINVAL;
1050 }
1051
1052 struct md_op_data {
1053         struct lu_fid           op_fid1; /* operation fid1 (usualy parent) */
1054         struct lu_fid           op_fid2; /* operation fid2 (usualy child) */
1055         struct lu_fid           op_fid3; /* 2 extra fids to find conflicting */
1056         struct lu_fid           op_fid4; /* to the operation locks. */
1057         mdsno_t                 op_mds;  /* what mds server open will go to */
1058         struct lustre_handle    op_handle;
1059         __u64                   op_mod_time;
1060         const char             *op_name;
1061         int                     op_namelen;
1062         __u32                   op_mode;
1063         struct lmv_stripe_md   *op_mea1;
1064         struct lmv_stripe_md   *op_mea2;
1065         __u32                   op_suppgids[2];
1066         __u32                   op_fsuid;
1067         __u32                   op_fsgid;
1068         __u32                   op_cap;
1069         void                   *op_data;
1070
1071         /* iattr fields and blocks. */
1072         struct iattr            op_attr;
1073 #ifdef __KERNEL__
1074 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
1075         unsigned int            op_attr_flags;
1076 #endif
1077 #endif
1078         loff_t                  op_attr_blocks;
1079
1080         /* Size-on-MDS epoch and flags. */
1081         __u64                   op_ioepoch;
1082         __u32                   op_flags;
1083
1084         /* Capa fields */
1085         struct obd_capa        *op_capa1;
1086         struct obd_capa        *op_capa2;
1087
1088         /* Various operation flags. */
1089         __u32                   op_bias;
1090
1091         /* Operation type */
1092         __u32                   op_opc;
1093 };
1094
1095 struct md_enqueue_info;
1096 /* metadata stat-ahead */
1097 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
1098                                 struct md_enqueue_info *minfo,
1099                                 int rc);
1100
1101 struct md_enqueue_info {
1102         struct md_op_data       mi_data;
1103         struct lookup_intent    mi_it;
1104         struct lustre_handle    mi_lockh;
1105         struct dentry          *mi_dentry;
1106         md_enqueue_cb_t         mi_cb;
1107         unsigned int            mi_generation;
1108         void                   *mi_cbdata;
1109 };
1110
1111 struct obd_ops {
1112         struct module *o_owner;
1113         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1114                            void *karg, void *uarg);
1115         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
1116                           __u32 *vallen, void *val);
1117         int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
1118                                 __u32 vallen, void *val,
1119                                 struct ptlrpc_request_set *set);
1120         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1121         int (*o_detach)(struct obd_device *dev);
1122         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1123         int (*o_precleanup)(struct obd_device *dev,
1124                             enum obd_cleanup_stage cleanup_stage);
1125         int (*o_cleanup)(struct obd_device *dev);
1126         int (*o_process_config)(struct obd_device *dev, obd_count len,
1127                                 void *data);
1128         int (*o_postrecov)(struct obd_device *dev);
1129         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1130                           int priority);
1131         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1132         /* connect to the target device with given connection
1133          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1134          * granted by the target, which are guaranteed to be a subset of flags
1135          * asked for. If @ocd == NULL, use default parameters. */
1136         int (*o_connect)(const struct lu_env *env,
1137                          struct lustre_handle *conn, struct obd_device *src,
1138                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1139                          void *localdata);
1140         int (*o_reconnect)(const struct lu_env *env,
1141                            struct obd_export *exp, struct obd_device *src,
1142                            struct obd_uuid *cluuid,
1143                            struct obd_connect_data *ocd);
1144         int (*o_disconnect)(struct obd_export *exp);
1145
1146         /* Initialize/finalize fids infrastructure. */
1147         int (*o_fid_init)(struct obd_export *exp);
1148         int (*o_fid_fini)(struct obd_export *exp);
1149
1150         /* Allocate new fid according to passed @hint. */
1151         int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1152                            struct md_op_data *op_data);
1153
1154         /* 
1155          * Object with @fid is getting deleted, we may want to do something
1156          * about this.
1157          */
1158         int (*o_fid_delete)(struct obd_export *exp, const struct lu_fid *fid);
1159
1160         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
1161                         __u64 max_age, __u32 flags);
1162         int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
1163                               __u64 max_age, struct ptlrpc_request_set *set);
1164         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1165                         struct lov_stripe_md *mem_src);
1166         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1167                           struct lov_mds_md *disk_src, int disk_len);
1168         int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
1169                          struct lov_stripe_md *mem_tgt);
1170         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1171                              obd_id *ids);
1172         /* FIXME: add fid capability support for create & destroy! */
1173         int (*o_precreate)(struct obd_export *exp);
1174         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
1175                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
1176         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
1177                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
1178                          struct obd_export *md_exp);
1179         int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
1180                          struct obd_trans_info *oti);
1181         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1182                                struct obd_trans_info *oti,
1183                                struct ptlrpc_request_set *rqset);
1184         int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
1185         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1186                                struct ptlrpc_request_set *set);
1187         int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1188                      obd_count oa_bufs, struct brw_page *pgarr,
1189                      struct obd_trans_info *oti);
1190         int (*o_brw_async)(int rw, struct obd_export *exp,
1191                            struct obd_info *oinfo, obd_count oa_bufs,
1192                            struct brw_page *pgarr, struct obd_trans_info *oti,
1193                            struct ptlrpc_request_set *);
1194         int (*o_prep_async_page)(struct obd_export *exp,
1195                                  struct lov_stripe_md *lsm,
1196                                  struct lov_oinfo *loi,
1197                                  cfs_page_t *page, obd_off offset,
1198                                  struct obd_async_page_ops *ops, void *data,
1199                                  void **res, int nocache,
1200                                  struct lustre_handle *lockh);
1201         int (*o_reget_short_lock)(struct obd_export *exp,
1202                                   struct lov_stripe_md *lsm,
1203                                   void **res, int rw,
1204                                   obd_off start, obd_off end,
1205                                   void **cookie);
1206         int (*o_release_short_lock)(struct obd_export *exp,
1207                                     struct lov_stripe_md *lsm, obd_off end,
1208                                     void *cookie, int rw);
1209         int (*o_queue_async_io)(struct obd_export *exp,
1210                                 struct lov_stripe_md *lsm,
1211                                 struct lov_oinfo *loi, void *cookie,
1212                                 int cmd, obd_off off, int count,
1213                                 obd_flag brw_flags, obd_flag async_flags);
1214         int (*o_queue_group_io)(struct obd_export *exp,
1215                                 struct lov_stripe_md *lsm,
1216                                 struct lov_oinfo *loi,
1217                                 struct obd_io_group *oig,
1218                                 void *cookie, int cmd, obd_off off, int count,
1219                                 obd_flag brw_flags, obd_flag async_flags);
1220         int (*o_trigger_group_io)(struct obd_export *exp,
1221                                   struct lov_stripe_md *lsm,
1222                                   struct lov_oinfo *loi,
1223                                   struct obd_io_group *oig);
1224         int (*o_set_async_flags)(struct obd_export *exp,
1225                                 struct lov_stripe_md *lsm,
1226                                 struct lov_oinfo *loi, void *cookie,
1227                                 obd_flag async_flags);
1228         int (*o_teardown_async_page)(struct obd_export *exp,
1229                                      struct lov_stripe_md *lsm,
1230                                      struct lov_oinfo *loi, void *cookie);
1231         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1232                            struct ost_lvb *lvb, int kms_only);
1233         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1234                             obd_off size, int shrink);
1235         int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
1236                        struct obd_trans_info *oti,
1237                        struct ptlrpc_request_set *rqset);
1238         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
1239                       struct lov_stripe_md *ea, obd_size start, obd_size end,
1240                       void *capa);
1241         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1242                          struct lov_stripe_md *src, obd_size start,
1243                          obd_size end, struct obd_trans_info *oti);
1244         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1245                       struct lustre_handle *srconn, struct lov_stripe_md *src,
1246                       obd_size start, obd_size end, struct obd_trans_info *);
1247         int (*o_iterate)(struct lustre_handle *conn,
1248                          int (*)(obd_id, obd_gr, void *),
1249                          obd_id *startid, obd_gr group, void *data);
1250         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1251                         int objcount, struct obd_ioobj *obj,
1252                         int niocount, struct niobuf_remote *remote,
1253                         struct niobuf_local *local, struct obd_trans_info *oti,
1254                         struct lustre_capa *capa);
1255         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1256                           int objcount, struct obd_ioobj *obj,
1257                           int niocount, struct niobuf_local *local,
1258                           struct obd_trans_info *oti, int rc);
1259         int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1260                          struct ldlm_enqueue_info *einfo,
1261                          struct ptlrpc_request_set *rqset);
1262         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1263                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1264                        struct lustre_handle *lockh);
1265         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1266                                ldlm_iterator_t it, void *data);
1267         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1268                         __u32 mode, struct lustre_handle *);
1269         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1270                                int flags, void *opaque);
1271         int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1272                          int join);
1273         int (*o_init_export)(struct obd_export *exp);
1274         int (*o_destroy_export)(struct obd_export *exp);
1275         int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1276                              int cmd, obd_off *);
1277
1278         /* llog related obd_methods */
1279         int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
1280                            struct obd_device *disk_obd, int count,
1281                            struct llog_catid *logid, struct obd_uuid *uuid);
1282         int (*o_llog_finish)(struct obd_device *obd, int count);
1283         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1284
1285         /* metadata-only methods */
1286         int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1287                      struct obd_capa *, struct obd_client_handle *, int flag);
1288         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1289
1290         int (*o_import_event)(struct obd_device *, struct obd_import *,
1291                               enum obd_import_event);
1292
1293         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1294                         enum obd_notify_event ev, void *data);
1295
1296         int (*o_health_check)(struct obd_device *);
1297
1298         /* quota methods */
1299         int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1300         int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1301
1302         int (*o_ping)(struct obd_export *exp);
1303
1304         int (*o_register_page_removal_cb)(struct obd_export *exp,
1305                                           obd_page_removal_cb_t cb,
1306                                           obd_pin_extent_cb pin_cb);
1307         int (*o_unregister_page_removal_cb)(struct obd_export *exp,
1308                                             obd_page_removal_cb_t cb);
1309         int (*o_register_lock_cancel_cb)(struct obd_export *exp,
1310                                        obd_lock_cancel_cb cb);
1311         int (*o_unregister_lock_cancel_cb)(struct obd_export *exp,
1312                                          obd_lock_cancel_cb cb);
1313
1314         /*
1315          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1316          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1317          * Also, add a wrapper function in include/linux/obd_class.h. */
1318 };
1319
1320 /* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */
1321 struct lmv_stripe_md {
1322         __u32         mea_magic;
1323         __u32         mea_count;
1324         __u32         mea_master;
1325         __u32         mea_padding;
1326         struct lu_fid mea_ids[0];
1327 };
1328
1329 enum {
1330         LUSTRE_OPC_MKDIR    = (1 << 0),
1331         LUSTRE_OPC_SYMLINK  = (1 << 1),
1332         LUSTRE_OPC_MKNOD    = (1 << 2),
1333         LUSTRE_OPC_CREATE   = (1 << 3),
1334         LUSTRE_OPC_ANY      = (1 << 4)
1335 };
1336
1337 /* lmv structures */
1338 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
1339 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
1340 #define MEA_MAGIC_HASH_SEGMENT   0xb222a11b
1341
1342 #define MAX_HASH_SIZE_32         0x7fffffffUL
1343 #define MAX_HASH_SIZE            0x7fffffffffffffffULL
1344 #define MAX_HASH_HIGHEST_BIT     0x1000000000000000
1345
1346 struct lustre_md {
1347         struct mdt_body         *body;
1348         struct lov_stripe_md    *lsm;
1349         struct lmv_stripe_md    *mea;
1350 #ifdef CONFIG_FS_POSIX_ACL
1351         struct posix_acl        *posix_acl;
1352 #endif
1353         struct mdt_remote_perm  *remote_perm;
1354         struct obd_capa         *mds_capa;
1355         struct obd_capa         *oss_capa;
1356 };
1357
1358 struct md_open_data {
1359         struct obd_client_handle *mod_och;
1360         struct list_head          mod_replay_list;
1361 };
1362
1363 struct lookup_intent;
1364
1365 struct md_ops {
1366         int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1367                            struct obd_capa **);
1368         int (*m_change_cbdata)(struct obd_export *, const struct lu_fid *,
1369                                ldlm_iterator_t, void *);
1370         int (*m_close)(struct obd_export *, struct md_op_data *,
1371                        struct md_open_data *, struct ptlrpc_request **);
1372         int (*m_create)(struct obd_export *, struct md_op_data *,
1373                         const void *, int, int, __u32, __u32, __u32,
1374                         __u64, struct ptlrpc_request **);
1375         int (*m_done_writing)(struct obd_export *, struct md_op_data  *,
1376                               struct md_open_data *);
1377         int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1378                          struct lookup_intent *, struct md_op_data *,
1379                          struct lustre_handle *, void *, int, int);
1380         int (*m_getattr)(struct obd_export *, const struct lu_fid *,
1381                          struct obd_capa *, obd_valid, int,
1382                          struct ptlrpc_request **);
1383         int (*m_getattr_name)(struct obd_export *, const struct lu_fid *,
1384                               struct obd_capa *, const char *, int, obd_valid,
1385                               int, __u32, struct ptlrpc_request **);
1386         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1387                              void *, int, struct lookup_intent *, int,
1388                              struct ptlrpc_request **,
1389                              ldlm_blocking_callback, int);
1390         int (*m_link)(struct obd_export *, struct md_op_data *,
1391                       struct ptlrpc_request **);
1392         int (*m_rename)(struct obd_export *, struct md_op_data *,
1393                         const char *, int, const char *, int,
1394                         struct ptlrpc_request **);
1395         int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1396                            const struct lu_fid *,
1397                            struct ptlrpc_request **);
1398         int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1399                          int , void *, int, struct ptlrpc_request **,
1400                          struct md_open_data **mod);
1401         int (*m_sync)(struct obd_export *, const struct lu_fid *,
1402                       struct obd_capa *, struct ptlrpc_request **);
1403         int (*m_readpage)(struct obd_export *, const struct lu_fid *,
1404                           struct obd_capa *, __u64, struct page *,
1405                           struct ptlrpc_request **);
1406
1407         int (*m_unlink)(struct obd_export *, struct md_op_data *,
1408                         struct ptlrpc_request **);
1409
1410         int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1411                           struct obd_capa *, obd_valid, const char *,
1412                           const char *, int, int, int, __u32,
1413                           struct ptlrpc_request **);
1414
1415         int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1416                           struct obd_capa *, obd_valid, const char *,
1417                           const char *, int, int, int,
1418                           struct ptlrpc_request **);
1419
1420         int (*m_init_ea_size)(struct obd_export *, int, int, int);
1421
1422         int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1423                                struct obd_export *, struct obd_export *,
1424                                struct lustre_md *);
1425
1426         int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1427
1428         int (*m_set_open_replay_data)(struct obd_export *,
1429                                       struct obd_client_handle *,
1430                                       struct ptlrpc_request *);
1431         int (*m_clear_open_replay_data)(struct obd_export *,
1432                                         struct obd_client_handle *);
1433         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *);
1434
1435         ldlm_mode_t (*m_lock_match)(struct obd_export *, int,
1436                                     const struct lu_fid *, ldlm_type_t,
1437                                     ldlm_policy_data_t *, ldlm_mode_t,
1438                                     struct lustre_handle *);
1439
1440         int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1441                                ldlm_policy_data_t *, ldlm_mode_t, int flags,
1442                                void *opaque);
1443         int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1444                             renew_capa_cb_t cb);
1445
1446         int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1447                                  struct obd_capa *, __u32,
1448                                  struct ptlrpc_request **);
1449
1450         int (*m_intent_getattr_async)(struct obd_export *,
1451                                       struct md_enqueue_info *,
1452                                       struct ldlm_enqueue_info *);
1453
1454         int (*m_revalidate_lock)(struct obd_export *,
1455                                  struct lookup_intent *,
1456                                  struct lu_fid *);
1457
1458         /*
1459          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1460          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1461          * wrapper function in include/linux/obd_class.h.
1462          */
1463 };
1464
1465 struct lsm_operations {
1466         void (*lsm_free)(struct lov_stripe_md *);
1467         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1468                            struct obd_export *md_exp);
1469         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1470                                      unsigned long *);
1471         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1472                                      unsigned long *);
1473         obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1474         obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1475         int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1476         int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1477         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1478                                int *stripe_count);
1479         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1480                              struct lov_mds_md *lmm);
1481 };
1482
1483 extern struct lsm_operations lsm_plain_ops;
1484 extern struct lsm_operations lsm_join_ops;
1485 static inline struct lsm_operations *lsm_op_find(int magic)
1486 {
1487         switch(magic) {
1488         case LOV_MAGIC:
1489                return &lsm_plain_ops;
1490         case LOV_MAGIC_JOIN:
1491                return &lsm_join_ops;
1492         default:
1493                CERROR("Cannot recognize lsm_magic %d\n", magic);
1494                return NULL;
1495         }
1496 }
1497
1498 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1499
1500 /* Requests for obd_extent_calc() */
1501 #define OBD_CALC_STRIPE_START   1
1502 #define OBD_CALC_STRIPE_END     2
1503
1504 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1505                                          int error)
1506 {
1507         if (error) {
1508                 CERROR("%s: transno "LPU64" commit error: %d\n",
1509                        obd->obd_name, transno, error);
1510                 return;
1511         }
1512         CDEBUG(D_HA, "%s: transno "LPU64" committed\n",
1513                obd->obd_name, transno);
1514         if (transno > obd->obd_last_committed) {
1515                 obd->obd_last_committed = transno;
1516                 ptlrpc_commit_replies (obd);
1517         }
1518 }
1519
1520 static inline void init_obd_quota_ops(quota_interface_t *interface,
1521                                       struct obd_ops *obd_ops)
1522 {
1523         if (!interface)
1524                 return;
1525
1526         LASSERT(obd_ops);
1527         obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1528         obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1529 }
1530
1531 static inline __u64 oinfo_mdsno(struct obd_info *oinfo)
1532 {
1533         return oinfo->oi_oa->o_gr - FILTER_GROUP_MDS0;
1534 }
1535
1536 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1537 {
1538         return oinfo->oi_capa;
1539 }
1540
1541 #endif /* __OBD_H */