Whamcloud - gitweb
b=11089
[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         int     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         void            *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 /* llog contexts */
259 enum llog_ctxt_id {
260         LLOG_CONFIG_ORIG_CTXT  =  0,
261         LLOG_CONFIG_REPL_CTXT,
262         LLOG_MDS_OST_ORIG_CTXT,
263         LLOG_MDS_OST_REPL_CTXT,
264         LLOG_SIZE_ORIG_CTXT,
265         LLOG_SIZE_REPL_CTXT,
266         LLOG_RD1_ORIG_CTXT,
267         LLOG_RD1_REPL_CTXT,
268         LLOG_TEST_ORIG_CTXT,
269         LLOG_TEST_REPL_CTXT,
270         LLOG_LOVEA_ORIG_CTXT,
271         LLOG_LOVEA_REPL_CTXT,
272         LLOG_MAX_CTXTS
273 };
274
275 #define FILTER_SUBDIR_COUNT      32            /* set to zero for no subdirs */
276
277 struct filter_subdirs {
278        cfs_dentry_t *dentry[FILTER_SUBDIR_COUNT];
279 };
280
281
282 struct filter_ext {
283         __u64                fe_start;
284         __u64                fe_end;
285 };
286
287 struct filter_obd {
288         /* NB this field MUST be first */
289         struct obd_device_target fo_obt;
290         const char          *fo_fstype;
291         struct vfsmount     *fo_vfsmnt;
292
293         int                  fo_group_count;
294         cfs_dentry_t        *fo_dentry_O;
295         cfs_dentry_t       **fo_dentry_O_groups;
296         struct filter_subdirs   *fo_dentry_O_sub;
297         struct semaphore     fo_init_lock;      /* group initialization lock */
298         int                  fo_committed_group;
299
300
301         spinlock_t           fo_objidlock;      /* protect fo_lastobjid */
302         spinlock_t           fo_translock;      /* protect fsd_last_transno */
303         struct file         *fo_rcvd_filp;
304         struct file         *fo_health_check_filp;
305         struct lr_server_data *fo_fsd;
306         unsigned long       *fo_last_rcvd_slots;
307         __u64                fo_mount_count;
308
309         unsigned long        fo_destroys_in_progress;
310         struct semaphore     fo_create_locks[FILTER_SUBDIR_COUNT];
311
312         struct list_head     fo_export_list;
313         int                  fo_subdir_count;
314
315         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
316         obd_size             fo_tot_granted;    /* all values in bytes */
317         obd_size             fo_tot_pending;
318
319         obd_size             fo_readcache_max_filesize;
320
321         struct obd_import   *fo_mdc_imp;
322         struct obd_uuid      fo_mdc_uuid;
323         struct lustre_handle fo_mdc_conn;
324         struct file        **fo_last_objid_files;
325         __u64               *fo_last_objids; /* last created objid for groups,
326                                               * protected by fo_objidlock */
327
328         struct semaphore     fo_alloc_lock;
329
330         atomic_t             fo_r_in_flight;
331         atomic_t             fo_w_in_flight;
332
333         /*
334          * per-filter pool of kiobuf's allocated by filter_common_setup() and
335          * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
336          * which ->fo_iobuf_count were allocated.
337          *
338          * This pool contains kiobuf used by
339          * filter_{prep,commit}rw_{read,write}() and is shared by all OST
340          * threads.
341          *
342          * Locking: none, each OST thread uses only one element, determined by
343          * its "ordinal number", ->t_id.
344          */
345         struct filter_iobuf    **fo_iobuf_pool;
346         int                      fo_iobuf_count;
347
348         struct list_head         fo_llog_list;
349         spinlock_t               fo_llog_list_lock;
350
351         struct brw_stats         fo_filter_stats;
352         struct lustre_quota_ctxt fo_quota_ctxt;
353         spinlock_t               fo_quotacheck_lock;
354         atomic_t                 fo_quotachecking;
355
356         int                      fo_fmd_max_num; /* per exp filter_mod_data */
357         int                      fo_fmd_max_age; /* jiffies to fmd expiry */
358
359         /* sptlrpc stuff */
360         rwlock_t                 fo_sptlrpc_lock;
361         struct sptlrpc_rule_set  fo_sptlrpc_rset;
362
363         /* capability related */
364         unsigned int             fo_fl_oss_capa;
365         struct list_head         fo_capa_keys;
366         struct hlist_head       *fo_capa_hash;
367
368         void                    *fo_lcm;
369 };
370
371 #define OSC_MAX_RIF_DEFAULT       8
372 #define OSC_MAX_RIF_MAX         256
373 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
374 #define OSC_MAX_DIRTY_MB_MAX   2048     /* arbitrary, but < MAX_LONG bytes */
375 #define OSC_DEFAULT_RESENDS      10
376
377 #define MDC_MAX_RIF_DEFAULT       8
378 #define MDC_MAX_RIF_MAX         512
379
380 struct mdc_rpc_lock;
381 struct obd_import;
382 struct client_obd {
383         struct semaphore         cl_sem;
384         struct obd_uuid          cl_target_uuid;
385         struct obd_import       *cl_import; /* ptlrpc connection state */
386         int                      cl_conn_count;
387         /* max_mds_easize is purely a performance thing so we don't have to
388          * call obd_size_diskmd() all the time. */
389         int                      cl_default_mds_easize;
390         int                      cl_max_mds_easize;
391         int                      cl_max_mds_cookiesize;
392
393         /* security configuration */
394         struct sptlrpc_rule_set  cl_sptlrpc_rset;
395         enum lustre_sec_part     cl_sec_part;
396
397         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
398         void                    *cl_llcd_offset;
399
400         /* the grant values are protected by loi_list_lock below */
401         long                     cl_dirty;         /* all _dirty_ in bytes */
402         long                     cl_dirty_max;     /* allowed w/o rpc */
403         long                     cl_avail_grant;   /* bytes of credit for ost */
404         long                     cl_lost_grant;    /* lost credits (trunc) */
405         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
406
407         /* keep track of objects that have lois that contain pages which
408          * have been queued for async brw.  this lock also protects the
409          * lists of osc_client_pages that hang off of the loi */
410         /*
411          * ->cl_loi_list_lock protects consistency of
412          * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and
413          * ->ap_completion() call-backs are executed under this lock. As we
414          * cannot guarantee that these call-backs never block on all platforms
415          * (as a matter of fact they do block on Mac OS X), type of
416          * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux
417          * and blocking mutex on Mac OS X. (Alternative is to make this lock
418          * blocking everywhere, but we don't want to slow down fast-path of
419          * our main platform.)
420          *
421          * Exact type of ->cl_loi_list_lock is defined in arch/obd.h together
422          * with client_obd_list_{un,}lock() and
423          * client_obd_list_lock_{init,done}() functions.
424          */
425         client_obd_lock_t        cl_loi_list_lock;
426         struct list_head         cl_loi_ready_list;
427         struct list_head         cl_loi_write_list;
428         struct list_head         cl_loi_read_list;
429         int                      cl_r_in_flight;
430         int                      cl_w_in_flight;
431         /* just a sum of the loi/lop pending numbers to be exported by /proc */
432         int                      cl_pending_w_pages;
433         int                      cl_pending_r_pages;
434         int                      cl_max_pages_per_rpc;
435         int                      cl_max_rpcs_in_flight;
436         struct obd_histogram     cl_read_rpc_hist;
437         struct obd_histogram     cl_write_rpc_hist;
438         struct obd_histogram     cl_read_page_hist;
439         struct obd_histogram     cl_write_page_hist;
440         struct obd_histogram     cl_read_offset_hist;
441         struct obd_histogram     cl_write_offset_hist;
442
443         /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */
444         atomic_t                 cl_destroy_in_flight;
445         cfs_waitq_t              cl_destroy_waitq;
446
447         struct mdc_rpc_lock     *cl_rpc_lock;
448         struct mdc_rpc_lock     *cl_setattr_lock;
449         struct mdc_rpc_lock     *cl_close_lock;
450         struct osc_creator       cl_oscc;
451
452         /* mgc datastruct */
453         struct semaphore         cl_mgc_sem;
454         struct vfsmount         *cl_mgc_vfsmnt;
455         struct dentry           *cl_mgc_configs_dir;
456         atomic_t                 cl_mgc_refcount;
457         struct obd_export       *cl_mgc_mgsexp;
458
459         /* checksumming for data sent over the network */
460         unsigned int             cl_checksum:1; /* 0 = disabled, 1 = enabled */
461         /* supported checksum types that are worked out at connect time */
462         __u32                    cl_supp_cksum_types;
463         /* checksum algorithm to be used */
464         cksum_type_t             cl_cksum_type;
465  
466         /* also protected by the poorly named _loi_list_lock lock above */
467         struct osc_async_rc      cl_ar;
468
469         /* used by quotacheck */
470         int                      cl_qchk_stat; /* quotacheck stat of the peer */
471
472         /* sequence manager */
473         struct lu_client_seq    *cl_seq;
474
475         atomic_t                 cl_resends; /* resend count */
476 };
477 #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid)
478
479 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
480
481 struct mgs_obd {
482         struct ptlrpc_service           *mgs_service;
483         struct vfsmount                 *mgs_vfsmnt;
484         struct super_block              *mgs_sb;
485         struct dentry                   *mgs_configs_dir;
486         struct dentry                   *mgs_fid_de;
487         struct list_head                 mgs_fs_db_list;
488         struct semaphore                 mgs_sem;
489         cfs_proc_dir_entry_t            *mgs_proc_live;
490 };
491
492 struct mds_obd {
493         /* NB this field MUST be first */
494         struct obd_device_target         mds_obt;
495         struct ptlrpc_service           *mds_service;
496         struct ptlrpc_service           *mds_setattr_service;
497         struct ptlrpc_service           *mds_readpage_service;
498         struct vfsmount                 *mds_vfsmnt;
499         cfs_dentry_t                    *mds_fid_de;
500         int                              mds_max_mdsize;
501         int                              mds_max_cookiesize;
502         struct file                     *mds_rcvd_filp;
503         spinlock_t                       mds_transno_lock;
504         __u64                            mds_last_transno;
505         __u64                            mds_mount_count;
506         __u64                            mds_io_epoch;
507         unsigned long                    mds_atime_diff;
508         struct semaphore                 mds_epoch_sem;
509         struct ll_fid                    mds_rootfid;
510         struct lr_server_data           *mds_server_data;
511         cfs_dentry_t                    *mds_pending_dir;
512         cfs_dentry_t                    *mds_logs_dir;
513         cfs_dentry_t                    *mds_objects_dir;
514         struct llog_handle              *mds_cfg_llh;
515         struct obd_device               *mds_osc_obd; /* XXX lov_obd */
516         struct obd_uuid                  mds_lov_uuid;
517         char                            *mds_profile;
518         struct obd_export               *mds_osc_exp; /* XXX lov_exp */
519         struct lov_desc                  mds_lov_desc;
520         __u32                            mds_id;
521
522         /* mark pages dirty for write. */
523         bitmap_t                         *mds_lov_page_dirty;
524         /* array for store pages with obd_id */
525         void                            **mds_lov_page_array;
526         /* file for store objid */
527         struct file                     *mds_lov_objid_filp;
528         __u32                            mds_lov_objid_count;
529         __u32                            mds_lov_objid_lastpage;
530         __u32                            mds_lov_objid_lastidx;
531
532         struct file                     *mds_health_check_filp;
533         unsigned long                   *mds_client_bitmap;
534 //        struct upcall_cache             *mds_group_hash;
535
536         struct lustre_quota_info         mds_quota_info;
537         struct semaphore                 mds_qonoff_sem;
538         struct semaphore                 mds_health_sem;
539         unsigned long                    mds_fl_user_xattr:1,
540                                          mds_fl_acl:1,
541                                          mds_evict_ost_nids:1,
542                                          mds_fl_cfglog:1,
543                                          mds_fl_synced:1;
544
545         struct upcall_cache             *mds_identity_cache;
546
547         /* for capability keys update */
548         struct lustre_capa_key          *mds_capa_keys;
549 };
550
551 /* lov objid */
552 extern __u32 mds_max_ost_index;
553
554 #define MDS_LOV_ALLOC_SIZE (CFS_PAGE_SIZE)
555
556 #define OBJID_PER_PAGE() (MDS_LOV_ALLOC_SIZE / sizeof(obd_id))
557
558 #define MDS_LOV_OBJID_PAGES_COUNT (mds_max_ost_index/OBJID_PER_PAGE())
559
560 extern int mds_lov_init_objids(struct obd_device *obd);
561 extern void mds_lov_destroy_objids(struct obd_device *obd);
562
563 struct obd_id_info {
564         __u32   idx;
565         obd_id  *data;
566 };
567
568 /* */
569
570 struct echo_obd {
571         struct obdo          eo_oa;
572         spinlock_t           eo_lock;
573         __u64                eo_lastino;
574         struct lustre_handle eo_nl_lock;
575         atomic_t             eo_prep;
576 };
577
578 struct ost_obd {
579         struct ptlrpc_service *ost_service;
580         struct ptlrpc_service *ost_create_service;
581         struct ptlrpc_service *ost_io_service;
582         struct semaphore       ost_health_sem;
583 };
584
585 struct echo_client_obd {
586         struct obd_export   *ec_exp;   /* the local connection to osc/lov */
587         spinlock_t           ec_lock;
588         struct list_head     ec_objects;
589         int                  ec_nstripes;
590         __u64                ec_unique;
591 };
592
593 struct lov_qos_oss {
594         struct obd_uuid     lqo_uuid;       /* ptlrpc's c_remote_uuid */
595         struct list_head    lqo_oss_list;   /* link to lov_qos */
596         __u32               lqo_ost_count;  /* number of osts on this oss */
597         __u64               lqo_bavail;     /* total bytes avail on OSS */
598         __u64               lqo_penalty;    /* current penalty */
599         __u64               lqo_penalty_per_obj; /* penalty decrease every obj*/
600 };
601
602 struct ltd_qos {
603         struct lov_qos_oss *ltq_oss;         /* oss info */
604         __u64               ltq_penalty;     /* current penalty */
605         __u64               ltq_penalty_per_obj; /* penalty decrease every obj*/
606         __u64               ltq_weight;      /* net weighting */
607         unsigned int        ltq_usable:1;    /* usable for striping */
608 };
609
610 struct lov_qos {
611         struct list_head    lq_oss_list;    /* list of OSSs that targets use */
612         struct rw_semaphore lq_rw_sem;
613         __u32               lq_active_oss_count;
614         __u32              *lq_rr_array;    /* round-robin optimized list */
615         unsigned int        lq_rr_size;     /* rr array size */
616         unsigned int        lq_prio_free;   /* priority for free space */
617         unsigned long       lq_dirty:1,     /* recalc qos data */
618                             lq_dirty_rr:1,  /* recalc round-robin list */
619                             lq_same_space:1,/* the ost's all have approx.
620                                                the same space avail */
621                             lq_reset:1;     /* zero current penalties */
622 };
623
624 struct lov_tgt_desc {
625         struct obd_uuid     ltd_uuid;
626         struct obd_export  *ltd_exp;
627         struct ltd_qos      ltd_qos;     /* qos info per target */
628         __u32               ltd_gen;
629         __u32               ltd_index;   /* index in lov_obd->tgts */
630         unsigned long       ltd_active:1,/* is this target up for requests */
631                             ltd_activate:1,/* should this target be activated */
632                             ltd_reap:1;  /* should this target be deleted */
633 };
634
635 struct lov_obd {
636         struct lov_desc         desc;
637         struct lov_tgt_desc   **lov_tgts;
638         struct semaphore        lov_lock;
639         struct obd_connect_data lov_ocd;
640         struct lov_qos          lov_qos;               /* qos info per lov */
641         atomic_t                lov_refcount;
642         __u32                   lov_tgt_count;         /* how many OBD's */
643         __u32                   lov_active_tgt_count;  /* how many active */
644         __u32                   lov_death_row;/* tgts scheduled to be deleted */
645         __u32                   lov_tgt_size;   /* size of tgts array */
646         __u32                   lov_start_idx;  /* start index of new inode */
647         __u32                   lov_offset_idx; /* aliasing for start_idx  */
648         int                     lov_start_count;/* reseed counter */
649         int                     lov_connects;
650 };
651
652 struct lmv_tgt_desc {
653         struct obd_uuid         ltd_uuid;
654         struct obd_export      *ltd_exp;
655         int                     ltd_active;   /* is this target up for requests */
656         int                     ltd_idx;
657         struct semaphore        ltd_fid_sem;
658 };
659
660 struct lmv_obd {
661         int                     refcount;
662         struct lu_client_fld    lmv_fld;
663         spinlock_t              lmv_lock;
664         struct lmv_desc         desc;
665         struct obd_uuid         cluuid;
666         struct obd_export       *exp;
667
668         int                     connected;
669         int                     max_easize;
670         int                     max_def_easize;
671         int                     max_cookiesize;
672         int                     server_timeout;
673         struct semaphore        init_sem;
674
675         struct lmv_tgt_desc     *tgts;
676         int                     tgts_size;
677
678         struct obd_connect_data *datas;
679         int                     datas_size;
680
681         struct obd_connect_data conn_data;
682 };
683
684 struct niobuf_local {
685         __u64 offset;
686         __u32 len;
687         __u32 flags;
688         cfs_page_t    *page;
689         cfs_dentry_t  *dentry;
690         int lnb_grant_used;
691         int rc;
692 };
693
694 #define LUSTRE_FLD_NAME         "fld"
695 #define LUSTRE_SEQ_NAME         "seq"
696
697 #define LUSTRE_CMM_NAME         "cmm"
698 #define LUSTRE_MDD_NAME         "mdd"
699 #define LUSTRE_OSD_NAME         "osd"
700 #define LUSTRE_LMV_NAME         "lmv"
701 #define LUSTRE_CMM_MDC_NAME     "cmm-mdc"
702
703 /* obd device type names */
704  /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */
705 #define LUSTRE_MDS_NAME         "mds"
706 #define LUSTRE_MDT_NAME         "mdt"
707 #define LUSTRE_MDC_NAME         "mdc"
708 #define LUSTRE_OSS_NAME         "ost"       /* FIXME change name to oss */
709 #define LUSTRE_OST_NAME         "obdfilter" /* FIXME change name to ost */
710 #define LUSTRE_OSC_NAME         "osc"
711 #define LUSTRE_LOV_NAME         "lov"
712 #define LUSTRE_MGS_NAME         "mgs"
713 #define LUSTRE_MGC_NAME         "mgc"
714
715 #define LUSTRE_CACHEOBD_NAME    "cobd"
716 #define LUSTRE_ECHO_NAME        "obdecho"
717 #define LUSTRE_ECHO_CLIENT_NAME "echo_client"
718
719 /* Constant obd names (post-rename) */
720 #define LUSTRE_MDS_OBDNAME "MDS"
721 #define LUSTRE_OSS_OBDNAME "OSS"
722 #define LUSTRE_MGS_OBDNAME "MGS"
723 #define LUSTRE_MGC_OBDNAME "MGC"
724
725 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
726 #define N_LOCAL_TEMP_PAGE 0x10000000
727
728 struct obd_trans_info {
729         __u64                    oti_transno;
730         __u64                    oti_xid;
731         /* Only used on the server side for tracking acks. */
732         struct oti_req_ack_lock {
733                 struct lustre_handle lock;
734                 __u32                mode;
735         }                        oti_ack_locks[4];
736         void                    *oti_handle;
737         struct llog_cookie       oti_onecookie;
738         struct llog_cookie      *oti_logcookies;
739         int                      oti_numcookies;
740
741         /* initial thread handling transaction */
742         int                      oti_thread_id;
743         __u32                    oti_conn_cnt;
744 };
745
746 static inline void oti_init(struct obd_trans_info *oti,
747                             struct ptlrpc_request *req)
748 {
749         if (oti == NULL)
750                 return;
751         memset(oti, 0, sizeof(*oti));
752
753         if (req == NULL)
754                 return;
755
756         oti->oti_xid = req->rq_xid;
757
758         if (req->rq_repmsg != NULL)
759                 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
760         oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
761         if (req->rq_reqmsg != NULL)
762                 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
763 }
764
765 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
766 {
767         if (!oti)
768                 return;
769
770         if (num_cookies == 1)
771                 oti->oti_logcookies = &oti->oti_onecookie;
772         else
773                 OBD_ALLOC(oti->oti_logcookies,
774                           num_cookies * sizeof(oti->oti_onecookie));
775
776         oti->oti_numcookies = num_cookies;
777 }
778
779 static inline void oti_free_cookies(struct obd_trans_info *oti)
780 {
781         if (!oti || !oti->oti_logcookies)
782                 return;
783
784         if (oti->oti_logcookies == &oti->oti_onecookie)
785                 LASSERT(oti->oti_numcookies == 1);
786         else
787                 OBD_FREE(oti->oti_logcookies,
788                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
789         oti->oti_logcookies = NULL;
790         oti->oti_numcookies = 0;
791 }
792
793 /*
794  * Events signalled through obd_notify() upcall-chain.
795  */
796 enum obd_notify_event {
797         /* Device activated */
798         OBD_NOTIFY_ACTIVE,
799         /* Device deactivated */
800         OBD_NOTIFY_INACTIVE,
801         /* Device disconnected */
802         OBD_NOTIFY_DISCON,
803         /* Connect data for import were changed */
804         OBD_NOTIFY_OCD,
805         /* Sync request */
806         OBD_NOTIFY_SYNC_NONBLOCK,
807         OBD_NOTIFY_SYNC,
808         /* Configuration event */
809         OBD_NOTIFY_CONFIG
810 };
811
812 /* bit-mask flags for config events */
813 enum config_flags {
814         CONFIG_LOG = 0x1,  /* finished processing config log */
815         CONFIG_SYNC = 0x2  /* mdt synced 1 ost */
816 };
817
818 /*
819  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
820  * and liblustre being main examples).
821  */
822 struct obd_notify_upcall {
823         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
824                           enum obd_notify_event ev, void *owner);
825         /* Opaque datum supplied by upper layer listener */
826         void *onu_owner;
827 };
828
829 struct target_recovery_data {
830         svc_handler_t     trd_recovery_handler;
831         pid_t             trd_processing_task;
832         struct completion trd_starting;
833         struct completion trd_finishing;
834 };
835
836 #define OBD_LLOG_GROUP  0
837
838 enum filter_groups {
839         FILTER_GROUP_LLOG = 1,
840         FILTER_GROUP_ECHO,
841         FILTER_GROUP_MDS0
842 };
843
844 struct obd_llog_group {
845         struct list_head   olg_list;
846         int                olg_group;
847         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
848         cfs_waitq_t        olg_waitq;
849         spinlock_t         olg_lock;
850         struct obd_export *olg_exp;
851 };
852
853 /* corresponds to one of the obd's */
854 #define MAX_OBD_NAME 128
855 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
856 struct obd_device {
857         struct obd_type        *obd_type;
858         __u32                   obd_magic;
859
860         /* common and UUID name of this device */
861         char                    obd_name[MAX_OBD_NAME];
862         struct obd_uuid         obd_uuid;
863
864         struct lu_device       *obd_lu_dev;
865
866         int                     obd_minor;
867         unsigned long obd_attached:1,      /* finished attach */
868                       obd_set_up:1,        /* finished setup */
869                       obd_recovering:1,    /* there are recoverable clients */
870                       obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
871                       obd_replayable:1,    /* recovery is enabled; inform clients */
872                       obd_no_transno:1,    /* no committed-transno notification */
873                       obd_no_recov:1,      /* fail instead of retry messages */
874                       obd_req_replaying:1, /* replaying requests */
875                       obd_stopping:1,      /* started cleanup */
876                       obd_starting:1,      /* started setup */
877                       obd_force:1,         /* cleanup with > 0 obd refcount */
878                       obd_fail:1,          /* cleanup with failover */
879                       obd_async_recov:1,   /* allow asyncronous orphan cleanup */
880                       obd_no_conn:1,       /* deny new connections */
881                       obd_inactive:1;      /* device active/inactive
882                                            * (for /proc/status only!!) */
883         /* uuid-export hash body */
884         struct lustre_class_hash_body *obd_uuid_hash_body;
885         /* nid-export hash body */
886         struct lustre_class_hash_body *obd_nid_hash_body;
887         /* nid stats body */
888         struct lustre_class_hash_body *obd_nid_stats_hash_body;
889         struct list_head        obd_nid_stats;
890         atomic_t                obd_refcount;
891         cfs_waitq_t             obd_refcount_waitq;
892         struct list_head        obd_exports;
893         int                     obd_num_exports;
894         spinlock_t              obd_nid_lock;
895         struct ldlm_namespace  *obd_namespace;
896         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
897         /* a spinlock is OK for what we do now, may need a semaphore later */
898         spinlock_t              obd_dev_lock;
899         struct semaphore        obd_dev_sem;
900         __u64                   obd_last_committed;
901         struct fsfilt_operations *obd_fsops;
902         spinlock_t              obd_osfs_lock;
903         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
904         __u64                   obd_osfs_age;
905         struct lvfs_run_ctxt    obd_lvfs_ctxt;
906         struct obd_llog_group   obd_olg; /* default llog group */
907         struct obd_device       *obd_observer;
908         struct obd_notify_upcall obd_upcall;
909         struct obd_export       *obd_self_export;
910         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
911         struct list_head        obd_exports_timed;
912         time_t                  obd_eviction_timer; /* for ping evictor */
913
914         /* XXX encapsulate all this recovery data into one struct */
915         svc_handler_t                    obd_recovery_handler;
916         pid_t                            obd_processing_task;
917         
918         int                              obd_max_recoverable_clients;
919         int                              obd_connected_clients;
920         int                              obd_recoverable_clients;
921         spinlock_t                       obd_processing_task_lock; /* BH lock (timer) */
922         __u64                            obd_next_recovery_transno;
923         int                              obd_replayed_requests;
924         int                              obd_requests_queued_for_recovery;
925         cfs_waitq_t                      obd_next_transno_waitq;
926         struct list_head                 obd_uncommitted_replies;
927         spinlock_t                       obd_uncommitted_replies_lock;
928         cfs_timer_t                      obd_recovery_timer;
929         time_t                           obd_recovery_start; /* seconds */
930         time_t                           obd_recovery_end; /* seconds */
931         time_t                           obd_recovery_max_time; /* seconds, bz13079 */
932         
933         /* new recovery stuff from CMD2 */
934         struct target_recovery_data      obd_recovery_data;
935         int                              obd_replayed_locks;
936         atomic_t                         obd_req_replay_clients;
937         atomic_t                         obd_lock_replay_clients;
938         struct list_head                 obd_req_replay_queue;
939         struct list_head                 obd_lock_replay_queue;
940         struct list_head                 obd_final_req_queue;
941         int                              obd_recovery_stage;
942
943         union {
944                 struct obd_device_target obt;
945                 struct filter_obd filter;
946                 struct mds_obd mds;
947                 struct client_obd cli;
948                 struct ost_obd ost;
949                 struct echo_client_obd echo_client;
950                 struct echo_obd echo;
951                 struct lov_obd lov;
952                 struct lmv_obd lmv;
953                 struct mgs_obd mgs;
954         } u;
955         /* Fields used by LProcFS */
956         unsigned int           obd_cntr_base;
957         struct lprocfs_stats  *obd_stats;
958
959         unsigned int           md_cntr_base;
960         struct lprocfs_stats  *md_stats;
961
962         cfs_proc_dir_entry_t  *obd_proc_entry;
963         cfs_proc_dir_entry_t  *obd_proc_exports_entry;
964         cfs_proc_dir_entry_t  *obd_svc_procroot;
965         struct lprocfs_stats  *obd_svc_stats;
966         atomic_t               obd_evict_inprogress;
967         cfs_waitq_t            obd_evict_inprogress_waitq;
968 };
969
970 #define OBD_OPT_FORCE           0x0001
971 #define OBD_OPT_FAILOVER        0x0002
972
973 #define OBD_LLOG_FL_SENDNOW     0x0001
974
975 enum obd_cleanup_stage {
976 /* Special case hack for MDS LOVs */
977         OBD_CLEANUP_EARLY,
978 /* Precleanup stage 1, we must make sure all exports (other than the
979    self-export) get destroyed. */
980         OBD_CLEANUP_EXPORTS,
981 /* Precleanup stage 2,  do other type-specific cleanup requiring the
982    self-export. */
983         OBD_CLEANUP_SELF_EXP,
984 /* FIXME we should eliminate the "precleanup" function and make them stages
985    of the "cleanup" function. */
986         OBD_CLEANUP_OBD,
987 };
988
989 /* get/set_info keys */
990 #define KEY_READ_ONLY           "read-only"
991 #define KEY_MDS_CONN            "mds_conn"
992 #define KEY_NEXT_ID             "next_id"
993 #define KEY_LOVDESC             "lovdesc"
994 #define KEY_INIT_RECOV          "initial_recov"
995 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
996 #define KEY_FLUSH_CTX           "flush_ctx"
997 #define KEY_CAPA_KEY            "capa_key"
998 #define KEY_CONN_DATA           "conn_data"
999 #define KEY_MAX_EASIZE          "max_easize"
1000 #define KEY_REVIMP_UPD          "revimp_update"
1001 #define KEY_LOV_IDX             "lov_idx"
1002 #define KEY_LAST_ID             "last_id"
1003 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
1004 #define KEY_BLOCKSIZE           "blocksize"
1005 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
1006
1007 struct lu_context;
1008
1009 struct md_op_data {
1010         struct lu_fid           op_fid1; /* operation fid1 (usualy parent) */
1011         struct lu_fid           op_fid2; /* operation fid2 (usualy child) */
1012         struct lu_fid           op_fid3; /* 2 extra fids to find conflicting */
1013         struct lu_fid           op_fid4; /* to the operation locks. */
1014         mdsno_t                 op_mds;  /* what mds server open will go to */
1015         struct lustre_handle    op_handle;
1016         __u64                   op_mod_time;
1017         const char             *op_name;
1018         int                     op_namelen;
1019         __u32                   op_mode;
1020         struct lmv_stripe_md   *op_mea1;
1021         struct lmv_stripe_md   *op_mea2;
1022         __u32                   op_suppgids[2];
1023         __u32                   op_fsuid;
1024         __u32                   op_fsgid;
1025         __u32                   op_cap;
1026         void                   *op_data;
1027
1028         /* iattr fields and blocks. */
1029         struct iattr            op_attr;
1030 #ifdef __KERNEL__
1031 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
1032         unsigned int            op_attr_flags;
1033 #endif
1034 #endif
1035         loff_t                  op_attr_blocks;
1036
1037         /* Size-on-MDS epoch and flags. */
1038         __u64                   op_ioepoch;
1039         __u32                   op_flags;
1040
1041         /* Capa fields */
1042         struct obd_capa        *op_capa1;
1043         struct obd_capa        *op_capa2;
1044
1045         /* Various operation flags. */
1046         __u32                   op_bias;
1047
1048         /* Operation type */
1049         __u32                   op_opc;
1050 };
1051
1052 struct obd_ops {
1053         struct module *o_owner;
1054         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1055                            void *karg, void *uarg);
1056         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
1057                           __u32 *vallen, void *val);
1058         int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
1059                                 __u32 vallen, void *val,
1060                                 struct ptlrpc_request_set *set);
1061         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1062         int (*o_detach)(struct obd_device *dev);
1063         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1064         int (*o_precleanup)(struct obd_device *dev,
1065                             enum obd_cleanup_stage cleanup_stage);
1066         int (*o_cleanup)(struct obd_device *dev);
1067         int (*o_process_config)(struct obd_device *dev, obd_count len,
1068                                 void *data);
1069         int (*o_postrecov)(struct obd_device *dev);
1070         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1071                           int priority);
1072         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1073         /* connect to the target device with given connection
1074          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1075          * granted by the target, which are guaranteed to be a subset of flags
1076          * asked for. If @ocd == NULL, use default parameters. */
1077         int (*o_connect)(const struct lu_env *env,
1078                          struct lustre_handle *conn, struct obd_device *src,
1079                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1080                          void *localdata);
1081         int (*o_reconnect)(const struct lu_env *env,
1082                            struct obd_export *exp, struct obd_device *src,
1083                            struct obd_uuid *cluuid,
1084                            struct obd_connect_data *ocd);
1085         int (*o_disconnect)(struct obd_export *exp);
1086
1087         /* Initialize/finalize fids infrastructure. */
1088         int (*o_fid_init)(struct obd_export *exp);
1089         int (*o_fid_fini)(struct obd_export *exp);
1090
1091         /* Allocate new fid according to passed @hint. */
1092         int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1093                            struct md_op_data *op_data);
1094
1095         /* 
1096          * Object with @fid is getting deleted, we may want to do something
1097          * about this.
1098          */
1099         int (*o_fid_delete)(struct obd_export *exp, const struct lu_fid *fid);
1100
1101         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
1102                         __u64 max_age, __u32 flags);
1103         int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
1104                               __u64 max_age, struct ptlrpc_request_set *set);
1105         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1106                         struct lov_stripe_md *mem_src);
1107         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1108                           struct lov_mds_md *disk_src, int disk_len);
1109         int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
1110                          struct lov_stripe_md *mem_tgt);
1111         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1112                              obd_id *ids);
1113         /* FIXME: add fid capability support for create & destroy! */
1114         int (*o_precreate)(struct obd_export *exp);
1115         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
1116                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
1117         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
1118                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
1119                          struct obd_export *md_exp);
1120         int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
1121                          struct obd_trans_info *oti);
1122         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1123                                struct obd_trans_info *oti,
1124                                struct ptlrpc_request_set *rqset);
1125         int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
1126         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1127                                struct ptlrpc_request_set *set);
1128         int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1129                      obd_count oa_bufs, struct brw_page *pgarr,
1130                      struct obd_trans_info *oti);
1131         int (*o_brw_async)(int rw, struct obd_export *exp,
1132                            struct obd_info *oinfo, obd_count oa_bufs,
1133                            struct brw_page *pgarr, struct obd_trans_info *oti,
1134                            struct ptlrpc_request_set *);
1135         int (*o_prep_async_page)(struct obd_export *exp,
1136                                  struct lov_stripe_md *lsm,
1137                                  struct lov_oinfo *loi,
1138                                  cfs_page_t *page, obd_off offset,
1139                                  struct obd_async_page_ops *ops, void *data,
1140                                  void **res);
1141         int (*o_queue_async_io)(struct obd_export *exp,
1142                                 struct lov_stripe_md *lsm,
1143                                 struct lov_oinfo *loi, void *cookie,
1144                                 int cmd, obd_off off, int count,
1145                                 obd_flag brw_flags, obd_flag async_flags);
1146         int (*o_queue_group_io)(struct obd_export *exp,
1147                                 struct lov_stripe_md *lsm,
1148                                 struct lov_oinfo *loi,
1149                                 struct obd_io_group *oig,
1150                                 void *cookie, int cmd, obd_off off, int count,
1151                                 obd_flag brw_flags, obd_flag async_flags);
1152         int (*o_trigger_group_io)(struct obd_export *exp,
1153                                   struct lov_stripe_md *lsm,
1154                                   struct lov_oinfo *loi,
1155                                   struct obd_io_group *oig);
1156         int (*o_set_async_flags)(struct obd_export *exp,
1157                                 struct lov_stripe_md *lsm,
1158                                 struct lov_oinfo *loi, void *cookie,
1159                                 obd_flag async_flags);
1160         int (*o_teardown_async_page)(struct obd_export *exp,
1161                                      struct lov_stripe_md *lsm,
1162                                      struct lov_oinfo *loi, void *cookie);
1163         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1164                            struct ost_lvb *lvb, int kms_only);
1165         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1166                             obd_off size, int shrink);
1167         int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
1168                        struct obd_trans_info *oti,
1169                        struct ptlrpc_request_set *rqset);
1170         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
1171                       struct lov_stripe_md *ea, obd_size start, obd_size end,
1172                       void *capa);
1173         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1174                          struct lov_stripe_md *src, obd_size start,
1175                          obd_size end, struct obd_trans_info *oti);
1176         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1177                       struct lustre_handle *srconn, struct lov_stripe_md *src,
1178                       obd_size start, obd_size end, struct obd_trans_info *);
1179         int (*o_iterate)(struct lustre_handle *conn,
1180                          int (*)(obd_id, obd_gr, void *),
1181                          obd_id *startid, obd_gr group, void *data);
1182         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1183                         int objcount, struct obd_ioobj *obj,
1184                         int niocount, struct niobuf_remote *remote,
1185                         struct niobuf_local *local, struct obd_trans_info *oti,
1186                         struct lustre_capa *capa);
1187         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1188                           int objcount, struct obd_ioobj *obj,
1189                           int niocount, struct niobuf_local *local,
1190                           struct obd_trans_info *oti, int rc);
1191         int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1192                          struct ldlm_enqueue_info *einfo,
1193                          struct ptlrpc_request_set *rqset);
1194         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1195                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1196                        struct lustre_handle *lockh);
1197         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1198                                ldlm_iterator_t it, void *data);
1199         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1200                         __u32 mode, struct lustre_handle *);
1201         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1202                                int flags, void *opaque);
1203         int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1204                          int join);
1205         int (*o_init_export)(struct obd_export *exp);
1206         int (*o_destroy_export)(struct obd_export *exp);
1207         int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1208                              int cmd, obd_off *);
1209
1210         /* llog related obd_methods */
1211         int (*o_llog_init)(struct obd_device *obd, int group,
1212                            struct obd_device *disk_obd, int count,
1213                            struct llog_catid *logid, struct obd_uuid *uuid);
1214         int (*o_llog_finish)(struct obd_device *obd, int count);
1215         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1216
1217         /* metadata-only methods */
1218         int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1219                      struct obd_capa *, struct obd_client_handle *, int flag);
1220         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1221
1222         int (*o_import_event)(struct obd_device *, struct obd_import *,
1223                               enum obd_import_event);
1224
1225         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1226                         enum obd_notify_event ev, void *data);
1227
1228         int (*o_health_check)(struct obd_device *);
1229
1230         /* quota methods */
1231         int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1232         int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1233
1234         int (*o_ping)(struct obd_export *exp);
1235         /*
1236          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1237          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1238          * Also, add a wrapper function in include/linux/obd_class.h. */
1239 };
1240
1241 /* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */
1242 struct lmv_stripe_md {
1243         __u32         mea_magic;
1244         __u32         mea_count;
1245         __u32         mea_master;
1246         __u32         mea_padding;
1247         struct lu_fid mea_ids[0];
1248 };
1249
1250 enum {
1251         LUSTRE_OPC_MKDIR    = (1 << 0),
1252         LUSTRE_OPC_SYMLINK  = (1 << 1),
1253         LUSTRE_OPC_MKNOD    = (1 << 2),
1254         LUSTRE_OPC_CREATE   = (1 << 3),
1255         LUSTRE_OPC_ANY      = (1 << 4)
1256 };
1257
1258 /* lmv structures */
1259 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
1260 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
1261 #define MEA_MAGIC_HASH_SEGMENT   0xb222a11b
1262
1263 #define MAX_HASH_SIZE_32         0x7fffffffUL
1264 #define MAX_HASH_SIZE            0x7fffffffffffffffULL
1265 #define MAX_HASH_HIGHEST_BIT     0x1000000000000000
1266
1267 struct lustre_md {
1268         struct mdt_body         *body;
1269         struct lov_stripe_md    *lsm;
1270         struct lmv_stripe_md    *mea;
1271 #ifdef CONFIG_FS_POSIX_ACL
1272         struct posix_acl        *posix_acl;
1273 #endif
1274         struct mdt_remote_perm  *remote_perm;
1275         struct obd_capa         *mds_capa;
1276         struct obd_capa         *oss_capa;
1277 };
1278
1279 struct md_open_data {
1280         struct obd_client_handle *mod_och;
1281         struct list_head          mod_replay_list;
1282 };
1283
1284 struct lookup_intent;
1285
1286 struct md_ops {
1287         int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1288                            struct obd_capa **);
1289         int (*m_change_cbdata)(struct obd_export *, const struct lu_fid *,
1290                                ldlm_iterator_t, void *);
1291         int (*m_close)(struct obd_export *, struct md_op_data *,
1292                        struct md_open_data *, struct ptlrpc_request **);
1293         int (*m_create)(struct obd_export *, struct md_op_data *,
1294                         const void *, int, int, __u32, __u32, __u32,
1295                         __u64, struct ptlrpc_request **);
1296         int (*m_done_writing)(struct obd_export *, struct md_op_data  *,
1297                               struct md_open_data *);
1298         int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1299                          struct lookup_intent *, struct md_op_data *,
1300                          struct lustre_handle *, void *, int, int);
1301         int (*m_getattr)(struct obd_export *, const struct lu_fid *,
1302                          struct obd_capa *, obd_valid, int,
1303                          struct ptlrpc_request **);
1304         int (*m_getattr_name)(struct obd_export *, const struct lu_fid *,
1305                               struct obd_capa *, const char *, int, obd_valid,
1306                               int, __u32, struct ptlrpc_request **);
1307         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1308                              void *, int, struct lookup_intent *, int,
1309                              struct ptlrpc_request **,
1310                              ldlm_blocking_callback, int);
1311         int (*m_link)(struct obd_export *, struct md_op_data *,
1312                       struct ptlrpc_request **);
1313         int (*m_rename)(struct obd_export *, struct md_op_data *,
1314                         const char *, int, const char *, int,
1315                         struct ptlrpc_request **);
1316         int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1317                            const struct lu_fid *,
1318                            struct ptlrpc_request **);
1319         int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1320                          int , void *, int, struct ptlrpc_request **,
1321                          struct md_open_data **mod);
1322         int (*m_sync)(struct obd_export *, const struct lu_fid *,
1323                       struct obd_capa *, struct ptlrpc_request **);
1324         int (*m_readpage)(struct obd_export *, const struct lu_fid *,
1325                           struct obd_capa *, __u64, struct page *,
1326                           struct ptlrpc_request **);
1327
1328         int (*m_unlink)(struct obd_export *, struct md_op_data *,
1329                         struct ptlrpc_request **);
1330
1331         int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1332                           struct obd_capa *, obd_valid, const char *,
1333                           const char *, int, int, int, __u32,
1334                           struct ptlrpc_request **);
1335
1336         int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1337                           struct obd_capa *, obd_valid, const char *,
1338                           const char *, int, int, int,
1339                           struct ptlrpc_request **);
1340
1341         int (*m_init_ea_size)(struct obd_export *, int, int, int);
1342
1343         int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1344                                struct obd_export *, struct obd_export *,
1345                                struct lustre_md *);
1346
1347         int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1348
1349         int (*m_set_open_replay_data)(struct obd_export *,
1350                                       struct obd_client_handle *,
1351                                       struct ptlrpc_request *);
1352         int (*m_clear_open_replay_data)(struct obd_export *,
1353                                         struct obd_client_handle *);
1354         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *);
1355
1356         ldlm_mode_t (*m_lock_match)(struct obd_export *, int,
1357                                     const struct lu_fid *, ldlm_type_t,
1358                                     ldlm_policy_data_t *, ldlm_mode_t,
1359                                     struct lustre_handle *);
1360
1361         int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1362                                ldlm_policy_data_t *, ldlm_mode_t, int flags,
1363                                void *opaque);
1364         int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1365                             renew_capa_cb_t cb);
1366
1367         int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1368                                  struct obd_capa *, __u32,
1369                                  struct ptlrpc_request **);
1370
1371         /*
1372          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1373          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1374          * wrapper function in include/linux/obd_class.h.
1375          */
1376 };
1377
1378 struct lsm_operations {
1379         void (*lsm_free)(struct lov_stripe_md *);
1380         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1381                            struct obd_export *md_exp);
1382         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1383                                      unsigned long *);
1384         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1385                                      unsigned long *);
1386         obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1387         obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1388         int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1389         int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1390         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1391                                int *stripe_count);
1392         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1393                              struct lov_mds_md *lmm);
1394 };
1395
1396 extern struct lsm_operations lsm_plain_ops;
1397 extern struct lsm_operations lsm_join_ops;
1398 static inline struct lsm_operations *lsm_op_find(int magic)
1399 {
1400         switch(magic) {
1401         case LOV_MAGIC:
1402                return &lsm_plain_ops;
1403         case LOV_MAGIC_JOIN:
1404                return &lsm_join_ops;
1405         default:
1406                CERROR("Cannot recognize lsm_magic %d\n", magic);
1407                return NULL;
1408         }
1409 }
1410
1411 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1412
1413 /* Requests for obd_extent_calc() */
1414 #define OBD_CALC_STRIPE_START   1
1415 #define OBD_CALC_STRIPE_END     2
1416
1417 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1418                                          int error)
1419 {
1420         if (error) {
1421                 CERROR("%s: transno "LPD64" commit error: %d\n",
1422                        obd->obd_name, transno, error);
1423                 return;
1424         }
1425         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
1426                obd->obd_name, transno);
1427         if (transno > obd->obd_last_committed) {
1428                 obd->obd_last_committed = transno;
1429                 ptlrpc_commit_replies (obd);
1430         }
1431 }
1432
1433 static inline void init_obd_quota_ops(quota_interface_t *interface,
1434                                       struct obd_ops *obd_ops)
1435 {
1436         if (!interface)
1437                 return;
1438
1439         LASSERT(obd_ops);
1440         obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1441         obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1442 }
1443
1444 static inline __u64 oinfo_mdsno(struct obd_info *oinfo)
1445 {
1446         return oinfo->oi_oa->o_gr - FILTER_GROUP_MDS0;
1447 }
1448
1449 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1450 {
1451         return oinfo->oi_capa;
1452 }
1453
1454 #endif /* __OBD_H */