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