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