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