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