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