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