Whamcloud - gitweb
b=16098
[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
791 static inline void oti_init(struct obd_trans_info *oti,
792                             struct ptlrpc_request *req)
793 {
794         if (oti == NULL)
795                 return;
796         memset(oti, 0, sizeof(*oti));
797
798         if (req == NULL)
799                 return;
800
801         oti->oti_xid = req->rq_xid;
802
803         if (req->rq_repmsg != NULL)
804                 oti->oti_transno = lustre_msg_get_transno(req->rq_repmsg);
805         oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
806         if (req->rq_reqmsg != NULL)
807                 oti->oti_conn_cnt = lustre_msg_get_conn_cnt(req->rq_reqmsg);
808 }
809
810 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
811 {
812         if (!oti)
813                 return;
814
815         if (num_cookies == 1)
816                 oti->oti_logcookies = &oti->oti_onecookie;
817         else
818                 OBD_ALLOC(oti->oti_logcookies,
819                           num_cookies * sizeof(oti->oti_onecookie));
820
821         oti->oti_numcookies = num_cookies;
822 }
823
824 static inline void oti_free_cookies(struct obd_trans_info *oti)
825 {
826         if (!oti || !oti->oti_logcookies)
827                 return;
828
829         if (oti->oti_logcookies == &oti->oti_onecookie)
830                 LASSERT(oti->oti_numcookies == 1);
831         else
832                 OBD_FREE(oti->oti_logcookies,
833                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
834         oti->oti_logcookies = NULL;
835         oti->oti_numcookies = 0;
836 }
837
838 /*
839  * Events signalled through obd_notify() upcall-chain.
840  */
841 enum obd_notify_event {
842         /* Device activated */
843         OBD_NOTIFY_ACTIVE,
844         /* Device deactivated */
845         OBD_NOTIFY_INACTIVE,
846         /* Device disconnected */
847         OBD_NOTIFY_DISCON,
848         /* Connect data for import were changed */
849         OBD_NOTIFY_OCD,
850         /* Sync request */
851         OBD_NOTIFY_SYNC_NONBLOCK,
852         OBD_NOTIFY_SYNC,
853         /* Configuration event */
854         OBD_NOTIFY_CONFIG
855 };
856
857 /* bit-mask flags for config events */
858 enum config_flags {
859         CONFIG_LOG = 0x1,  /* finished processing config log */
860         CONFIG_SYNC = 0x2  /* mdt synced 1 ost */
861 };
862
863 /*
864  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
865  * and liblustre being main examples).
866  */
867 struct obd_notify_upcall {
868         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
869                           enum obd_notify_event ev, void *owner);
870         /* Opaque datum supplied by upper layer listener */
871         void *onu_owner;
872 };
873
874 struct target_recovery_data {
875         svc_handler_t     trd_recovery_handler;
876         pid_t             trd_processing_task;
877         struct completion trd_starting;
878         struct completion trd_finishing;
879 };
880
881 #define OBD_LLOG_GROUP  0
882
883 enum filter_groups {
884         FILTER_GROUP_LLOG = 1,
885         FILTER_GROUP_ECHO,
886         FILTER_GROUP_MDS0
887 };
888
889 struct obd_llog_group {
890         struct list_head   olg_list;
891         int                olg_group;
892         struct llog_ctxt  *olg_ctxts[LLOG_MAX_CTXTS];
893         cfs_waitq_t        olg_waitq;
894         spinlock_t         olg_lock;
895         struct obd_export *olg_exp;
896         int                olg_initializing;
897 };
898
899 /* corresponds to one of the obd's */
900 #define MAX_OBD_NAME 128
901 #define OBD_DEVICE_MAGIC        0XAB5CD6EF
902 struct obd_device {
903         struct obd_type        *obd_type;
904         __u32                   obd_magic;
905
906         /* common and UUID name of this device */
907         char                    obd_name[MAX_OBD_NAME];
908         struct obd_uuid         obd_uuid;
909
910         struct lu_device       *obd_lu_dev;
911
912         int                     obd_minor;
913         unsigned long obd_attached:1,      /* finished attach */
914                       obd_set_up:1,        /* finished setup */
915                       obd_recovering:1,    /* there are recoverable clients */
916                       obd_abort_recovery:1,/* somebody ioctl'ed us to abort */
917                       obd_replayable:1,    /* recovery is enabled; inform clients */
918                       obd_no_transno:1,    /* no committed-transno notification */
919                       obd_no_recov:1,      /* fail instead of retry messages */
920                       obd_req_replaying:1, /* replaying requests */
921                       obd_stopping:1,      /* started cleanup */
922                       obd_starting:1,      /* started setup */
923                       obd_force:1,         /* cleanup with > 0 obd refcount */
924                       obd_fail:1,          /* cleanup with failover */
925                       obd_async_recov:1,   /* allow asyncronous orphan cleanup */
926                       obd_no_conn:1,       /* deny new connections */
927                       obd_inactive:1;      /* device active/inactive
928                                            * (for /proc/status only!!) */
929         /* uuid-export hash body */
930         struct lustre_class_hash_body *obd_uuid_hash_body;
931         /* nid-export hash body */
932         struct lustre_class_hash_body *obd_nid_hash_body;
933         /* nid stats body */
934         struct lustre_class_hash_body *obd_nid_stats_hash_body;
935         struct list_head        obd_nid_stats;
936         atomic_t                obd_refcount;
937         cfs_waitq_t             obd_refcount_waitq;
938         struct list_head        obd_exports;
939         int                     obd_num_exports;
940         spinlock_t              obd_nid_lock;
941         struct ldlm_namespace  *obd_namespace;
942         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
943         /* a spinlock is OK for what we do now, may need a semaphore later */
944         spinlock_t              obd_dev_lock;
945         struct semaphore        obd_dev_sem;
946         __u64                   obd_last_committed;
947         struct fsfilt_operations *obd_fsops;
948         spinlock_t              obd_osfs_lock;
949         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
950         __u64                   obd_osfs_age;
951         struct lvfs_run_ctxt    obd_lvfs_ctxt;
952         struct obd_llog_group   obd_olg; /* default llog group */
953         struct obd_device       *obd_observer;
954         struct obd_notify_upcall obd_upcall;
955         struct obd_export       *obd_self_export;
956         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
957         struct list_head        obd_exports_timed;
958         time_t                  obd_eviction_timer; /* for ping evictor */
959
960         /* XXX encapsulate all this recovery data into one struct */
961         svc_handler_t                    obd_recovery_handler;
962         pid_t                            obd_processing_task;
963         
964         int                              obd_max_recoverable_clients;
965         int                              obd_connected_clients;
966         int                              obd_recoverable_clients;
967         spinlock_t                       obd_processing_task_lock; /* BH lock (timer) */
968         __u64                            obd_next_recovery_transno;
969         int                              obd_replayed_requests;
970         int                              obd_requests_queued_for_recovery;
971         cfs_waitq_t                      obd_next_transno_waitq;
972         struct list_head                 obd_uncommitted_replies;
973         spinlock_t                       obd_uncommitted_replies_lock;
974         cfs_timer_t                      obd_recovery_timer;
975         time_t                           obd_recovery_start; /* seconds */
976         time_t                           obd_recovery_end; /* seconds, for lprocfs_status */
977         time_t                           obd_recovery_max_time; /* seconds, bz13079 */
978         int                              obd_recovery_timeout;
979         
980         /* new recovery stuff from CMD2 */
981         struct target_recovery_data      obd_recovery_data;
982         int                              obd_replayed_locks;
983         atomic_t                         obd_req_replay_clients;
984         atomic_t                         obd_lock_replay_clients;
985         struct list_head                 obd_req_replay_queue;
986         struct list_head                 obd_lock_replay_queue;
987         struct list_head                 obd_final_req_queue;
988         int                              obd_recovery_stage;
989
990         union {
991                 struct obd_device_target obt;
992                 struct filter_obd filter;
993                 struct mds_obd mds;
994                 struct client_obd cli;
995                 struct ost_obd ost;
996                 struct echo_client_obd echo_client;
997                 struct echo_obd echo;
998                 struct lov_obd lov;
999                 struct lmv_obd lmv;
1000                 struct mgs_obd mgs;
1001         } u;
1002         /* Fields used by LProcFS */
1003         unsigned int           obd_cntr_base;
1004         struct lprocfs_stats  *obd_stats;
1005
1006         unsigned int           md_cntr_base;
1007         struct lprocfs_stats  *md_stats;
1008
1009         cfs_proc_dir_entry_t  *obd_proc_entry;
1010         cfs_proc_dir_entry_t  *obd_proc_exports_entry;
1011         cfs_proc_dir_entry_t  *obd_svc_procroot;
1012         struct lprocfs_stats  *obd_svc_stats;
1013         atomic_t               obd_evict_inprogress;
1014         cfs_waitq_t            obd_evict_inprogress_waitq;
1015
1016         /** 
1017          * Ldlm pool part. Save last calculated SLV and Limit. 
1018          */
1019         rwlock_t               obd_pool_lock;
1020         int                    obd_pool_limit;
1021         __u64                  obd_pool_slv;
1022 };
1023
1024 #define OBD_OPT_FORCE           0x0001
1025 #define OBD_OPT_FAILOVER        0x0002
1026
1027 #define OBD_LLOG_FL_SENDNOW     0x0001
1028
1029 enum obd_cleanup_stage {
1030 /* Special case hack for MDS LOVs */
1031         OBD_CLEANUP_EARLY,
1032 /* can be directly mapped to .ldto_device_fini() */
1033         OBD_CLEANUP_EXPORTS,
1034 };
1035
1036 /* get/set_info keys */
1037 #define KEY_READ_ONLY           "read-only"
1038 #define KEY_MDS_CONN            "mds_conn"
1039 #define KEY_NEXT_ID             "next_id"
1040 #define KEY_LOVDESC             "lovdesc"
1041 #define KEY_INIT_RECOV          "initial_recov"
1042 #define KEY_INIT_RECOV_BACKUP   "init_recov_bk"
1043 #define KEY_FLUSH_CTX           "flush_ctx"
1044 #define KEY_CAPA_KEY            "capa_key"
1045 #define KEY_CONN_DATA           "conn_data"
1046 #define KEY_MAX_EASIZE          "max_easize"
1047 #define KEY_REVIMP_UPD          "revimp_update"
1048 #define KEY_LOV_IDX             "lov_idx"
1049 #define KEY_LAST_ID             "last_id"
1050 #define KEY_READONLY            "read-only"
1051 #define KEY_LOCK_TO_STRIPE      "lock_to_stripe"
1052 #define KEY_CHECKSUM            "checksum"
1053 #define KEY_UNLINKED            "unlinked"
1054 #define KEY_EVICT_BY_NID        "evict_by_nid"
1055 #define KEY_REGISTER_TARGET     "register_target"
1056 #define KEY_SET_FS              "set_fs"
1057 #define KEY_CLEAR_FS            "clear_fs"
1058 #define KEY_BLOCKSIZE           "blocksize"
1059 #define KEY_BLOCKSIZE_BITS      "blocksize_bits"
1060 /* XXX unused ?*/
1061 #define KEY_INTERMDS            "inter_mds"
1062 #define KEY_ASYNC               "async"
1063
1064 struct lu_context;
1065
1066 static inline int it_to_lock_mode(struct lookup_intent *it)
1067 {
1068         /* CREAT needs to be tested before open (both could be set) */
1069         if (it->it_op & IT_CREAT)
1070                 return LCK_CW;
1071         else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP))
1072                 return LCK_CR;
1073  
1074         LASSERTF(0, "Invalid it_op: %d\n", it->it_op);
1075         return -EINVAL;
1076 }
1077
1078 struct md_op_data {
1079         struct lu_fid           op_fid1; /* operation fid1 (usualy parent) */
1080         struct lu_fid           op_fid2; /* operation fid2 (usualy child) */
1081         struct lu_fid           op_fid3; /* 2 extra fids to find conflicting */
1082         struct lu_fid           op_fid4; /* to the operation locks. */
1083         mdsno_t                 op_mds;  /* what mds server open will go to */
1084         struct lustre_handle    op_handle;
1085         __u64                   op_mod_time;
1086         const char             *op_name;
1087         int                     op_namelen;
1088         __u32                   op_mode;
1089         struct lmv_stripe_md   *op_mea1;
1090         struct lmv_stripe_md   *op_mea2;
1091         __u32                   op_suppgids[2];
1092         __u32                   op_fsuid;
1093         __u32                   op_fsgid;
1094         __u32                   op_cap;
1095         void                   *op_data;
1096
1097         /* iattr fields and blocks. */
1098         struct iattr            op_attr;
1099 #ifdef __KERNEL__
1100 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
1101         unsigned int            op_attr_flags;
1102 #endif
1103 #endif
1104         loff_t                  op_attr_blocks;
1105
1106         /* Size-on-MDS epoch and flags. */
1107         __u64                   op_ioepoch;
1108         __u32                   op_flags;
1109
1110         /* Capa fields */
1111         struct obd_capa        *op_capa1;
1112         struct obd_capa        *op_capa2;
1113
1114         /* Various operation flags. */
1115         __u32                   op_bias;
1116
1117         /* Operation type */
1118         __u32                   op_opc;
1119 };
1120
1121 struct md_enqueue_info;
1122 /* metadata stat-ahead */
1123 typedef int (* md_enqueue_cb_t)(struct ptlrpc_request *req,
1124                                 struct md_enqueue_info *minfo,
1125                                 int rc);
1126
1127 struct md_enqueue_info {
1128         struct md_op_data       mi_data;
1129         struct lookup_intent    mi_it;
1130         struct lustre_handle    mi_lockh;
1131         struct dentry          *mi_dentry;
1132         md_enqueue_cb_t         mi_cb;
1133         unsigned int            mi_generation;
1134         void                   *mi_cbdata;
1135 };
1136
1137 struct obd_ops {
1138         struct module *o_owner;
1139         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
1140                            void *karg, void *uarg);
1141         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
1142                           __u32 *vallen, void *val, struct lov_stripe_md *lsm);
1143         int (*o_set_info_async)(struct obd_export *, __u32 keylen, void *key,
1144                                 __u32 vallen, void *val,
1145                                 struct ptlrpc_request_set *set);
1146         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
1147         int (*o_detach)(struct obd_device *dev);
1148         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
1149         int (*o_precleanup)(struct obd_device *dev,
1150                             enum obd_cleanup_stage cleanup_stage);
1151         int (*o_cleanup)(struct obd_device *dev);
1152         int (*o_process_config)(struct obd_device *dev, obd_count len,
1153                                 void *data);
1154         int (*o_postrecov)(struct obd_device *dev);
1155         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
1156                           int priority);
1157         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
1158         /* connect to the target device with given connection
1159          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
1160          * granted by the target, which are guaranteed to be a subset of flags
1161          * asked for. If @ocd == NULL, use default parameters. */
1162         int (*o_connect)(const struct lu_env *env,
1163                          struct lustre_handle *conn, struct obd_device *src,
1164                          struct obd_uuid *cluuid, struct obd_connect_data *ocd,
1165                          void *localdata);
1166         int (*o_reconnect)(const struct lu_env *env,
1167                            struct obd_export *exp, struct obd_device *src,
1168                            struct obd_uuid *cluuid,
1169                            struct obd_connect_data *ocd);
1170         int (*o_disconnect)(struct obd_export *exp);
1171
1172         /* Initialize/finalize fids infrastructure. */
1173         int (*o_fid_init)(struct obd_export *exp);
1174         int (*o_fid_fini)(struct obd_export *exp);
1175
1176         /* Allocate new fid according to passed @hint. */
1177         int (*o_fid_alloc)(struct obd_export *exp, struct lu_fid *fid,
1178                            struct md_op_data *op_data);
1179
1180         /* 
1181          * Object with @fid is getting deleted, we may want to do something
1182          * about this.
1183          */
1184         int (*o_fid_delete)(struct obd_export *exp, const struct lu_fid *fid);
1185
1186         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
1187                         __u64 max_age, __u32 flags);
1188         int (*o_statfs_async)(struct obd_device *obd, struct obd_info *oinfo,
1189                               __u64 max_age, struct ptlrpc_request_set *set);
1190         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
1191                         struct lov_stripe_md *mem_src);
1192         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
1193                           struct lov_mds_md *disk_src, int disk_len);
1194         int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
1195                          struct lov_stripe_md *mem_tgt);
1196         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
1197                              obd_id *ids);
1198         /* FIXME: add fid capability support for create & destroy! */
1199         int (*o_precreate)(struct obd_export *exp);
1200         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
1201                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
1202         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
1203                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
1204                          struct obd_export *md_exp);
1205         int (*o_setattr)(struct obd_export *exp, struct obd_info *oinfo,
1206                          struct obd_trans_info *oti);
1207         int (*o_setattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1208                                struct obd_trans_info *oti,
1209                                struct ptlrpc_request_set *rqset);
1210         int (*o_getattr)(struct obd_export *exp, struct obd_info *oinfo);
1211         int (*o_getattr_async)(struct obd_export *exp, struct obd_info *oinfo,
1212                                struct ptlrpc_request_set *set);
1213         int (*o_brw)(int rw, struct obd_export *exp, struct obd_info *oinfo,
1214                      obd_count oa_bufs, struct brw_page *pgarr,
1215                      struct obd_trans_info *oti);
1216         int (*o_brw_async)(int rw, struct obd_export *exp,
1217                            struct obd_info *oinfo, obd_count oa_bufs,
1218                            struct brw_page *pgarr, struct obd_trans_info *oti,
1219                            struct ptlrpc_request_set *);
1220         int (*o_prep_async_page)(struct obd_export *exp,
1221                                  struct lov_stripe_md *lsm,
1222                                  struct lov_oinfo *loi,
1223                                  cfs_page_t *page, obd_off offset,
1224                                  struct obd_async_page_ops *ops, void *data,
1225                                  void **res, int nocache,
1226                                  struct lustre_handle *lockh);
1227         int (*o_reget_short_lock)(struct obd_export *exp,
1228                                   struct lov_stripe_md *lsm,
1229                                   void **res, int rw,
1230                                   obd_off start, obd_off end,
1231                                   void **cookie);
1232         int (*o_release_short_lock)(struct obd_export *exp,
1233                                     struct lov_stripe_md *lsm, obd_off end,
1234                                     void *cookie, int rw);
1235         int (*o_queue_async_io)(struct obd_export *exp,
1236                                 struct lov_stripe_md *lsm,
1237                                 struct lov_oinfo *loi, void *cookie,
1238                                 int cmd, obd_off off, int count,
1239                                 obd_flag brw_flags, obd_flag async_flags);
1240         int (*o_queue_group_io)(struct obd_export *exp,
1241                                 struct lov_stripe_md *lsm,
1242                                 struct lov_oinfo *loi,
1243                                 struct obd_io_group *oig,
1244                                 void *cookie, int cmd, obd_off off, int count,
1245                                 obd_flag brw_flags, obd_flag async_flags);
1246         int (*o_trigger_group_io)(struct obd_export *exp,
1247                                   struct lov_stripe_md *lsm,
1248                                   struct lov_oinfo *loi,
1249                                   struct obd_io_group *oig);
1250         int (*o_set_async_flags)(struct obd_export *exp,
1251                                 struct lov_stripe_md *lsm,
1252                                 struct lov_oinfo *loi, void *cookie,
1253                                 obd_flag async_flags);
1254         int (*o_teardown_async_page)(struct obd_export *exp,
1255                                      struct lov_stripe_md *lsm,
1256                                      struct lov_oinfo *loi, void *cookie);
1257         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
1258                            struct ost_lvb *lvb, int kms_only);
1259         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
1260                             obd_off size, int shrink);
1261         int (*o_punch)(struct obd_export *exp, struct obd_info *oinfo,
1262                        struct obd_trans_info *oti,
1263                        struct ptlrpc_request_set *rqset);
1264         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
1265                       struct lov_stripe_md *ea, obd_size start, obd_size end,
1266                       void *capa);
1267         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
1268                          struct lov_stripe_md *src, obd_size start,
1269                          obd_size end, struct obd_trans_info *oti);
1270         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
1271                       struct lustre_handle *srconn, struct lov_stripe_md *src,
1272                       obd_size start, obd_size end, struct obd_trans_info *);
1273         int (*o_iterate)(struct lustre_handle *conn,
1274                          int (*)(obd_id, obd_gr, void *),
1275                          obd_id *startid, obd_gr group, void *data);
1276         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
1277                         int objcount, struct obd_ioobj *obj,
1278                         int niocount, struct niobuf_remote *remote,
1279                         struct niobuf_local *local, struct obd_trans_info *oti,
1280                         struct lustre_capa *capa);
1281         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
1282                           int objcount, struct obd_ioobj *obj,
1283                           int niocount, struct niobuf_local *local,
1284                           struct obd_trans_info *oti, int rc);
1285         int (*o_enqueue)(struct obd_export *, struct obd_info *oinfo,
1286                          struct ldlm_enqueue_info *einfo,
1287                          struct ptlrpc_request_set *rqset);
1288         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
1289                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
1290                        struct lustre_handle *lockh);
1291         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
1292                                ldlm_iterator_t it, void *data);
1293         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
1294                         __u32 mode, struct lustre_handle *);
1295         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
1296                                int flags, void *opaque);
1297         int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
1298                          int join);
1299         int (*o_init_export)(struct obd_export *exp);
1300         int (*o_destroy_export)(struct obd_export *exp);
1301         int (*o_extent_calc)(struct obd_export *, struct lov_stripe_md *,
1302                              int cmd, obd_off *);
1303
1304         /* llog related obd_methods */
1305         int (*o_llog_init)(struct obd_device *obd, struct obd_llog_group *grp,
1306                            struct obd_device *disk_obd, int count,
1307                            struct llog_catid *logid, struct obd_uuid *uuid);
1308         int (*o_llog_finish)(struct obd_device *obd, int count);
1309         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
1310
1311         /* metadata-only methods */
1312         int (*o_pin)(struct obd_export *, const struct lu_fid *fid,
1313                      struct obd_capa *, struct obd_client_handle *, int flag);
1314         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
1315
1316         int (*o_import_event)(struct obd_device *, struct obd_import *,
1317                               enum obd_import_event);
1318
1319         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
1320                         enum obd_notify_event ev, void *data);
1321
1322         int (*o_health_check)(struct obd_device *);
1323
1324         /* quota methods */
1325         int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
1326         int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
1327
1328         int (*o_ping)(struct obd_export *exp);
1329
1330         int (*o_register_page_removal_cb)(struct obd_export *exp,
1331                                           obd_page_removal_cb_t cb,
1332                                           obd_pin_extent_cb pin_cb);
1333         int (*o_unregister_page_removal_cb)(struct obd_export *exp,
1334                                             obd_page_removal_cb_t cb);
1335         int (*o_register_lock_cancel_cb)(struct obd_export *exp,
1336                                        obd_lock_cancel_cb cb);
1337         int (*o_unregister_lock_cancel_cb)(struct obd_export *exp,
1338                                          obd_lock_cancel_cb cb);
1339
1340         /*
1341          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
1342          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
1343          * Also, add a wrapper function in include/linux/obd_class.h. */
1344 };
1345
1346 /* TODO: lmv_stripe_md should contain mds capabilities for all slave fids */
1347 struct lmv_stripe_md {
1348         __u32         mea_magic;
1349         __u32         mea_count;
1350         __u32         mea_master;
1351         __u32         mea_padding;
1352         struct lu_fid mea_ids[0];
1353 };
1354
1355 enum {
1356         LUSTRE_OPC_MKDIR    = (1 << 0),
1357         LUSTRE_OPC_SYMLINK  = (1 << 1),
1358         LUSTRE_OPC_MKNOD    = (1 << 2),
1359         LUSTRE_OPC_CREATE   = (1 << 3),
1360         LUSTRE_OPC_ANY      = (1 << 4)
1361 };
1362
1363 /* lmv structures */
1364 #define MEA_MAGIC_LAST_CHAR      0xb2221ca1
1365 #define MEA_MAGIC_ALL_CHARS      0xb222a11c
1366 #define MEA_MAGIC_HASH_SEGMENT   0xb222a11b
1367
1368 #define MAX_HASH_SIZE_32         0x7fffffffUL
1369 #define MAX_HASH_SIZE            0x7fffffffffffffffULL
1370 #define MAX_HASH_HIGHEST_BIT     0x1000000000000000
1371
1372 struct lustre_md {
1373         struct mdt_body         *body;
1374         struct lov_stripe_md    *lsm;
1375         struct lmv_stripe_md    *mea;
1376 #ifdef CONFIG_FS_POSIX_ACL
1377         struct posix_acl        *posix_acl;
1378 #endif
1379         struct mdt_remote_perm  *remote_perm;
1380         struct obd_capa         *mds_capa;
1381         struct obd_capa         *oss_capa;
1382 };
1383
1384 struct md_open_data {
1385         struct obd_client_handle *mod_och;
1386         struct list_head          mod_replay_list;
1387 };
1388
1389 struct lookup_intent;
1390
1391 struct md_ops {
1392         int (*m_getstatus)(struct obd_export *, struct lu_fid *,
1393                            struct obd_capa **);
1394         int (*m_change_cbdata)(struct obd_export *, const struct lu_fid *,
1395                                ldlm_iterator_t, void *);
1396         int (*m_close)(struct obd_export *, struct md_op_data *,
1397                        struct md_open_data *, struct ptlrpc_request **);
1398         int (*m_create)(struct obd_export *, struct md_op_data *,
1399                         const void *, int, int, __u32, __u32, __u32,
1400                         __u64, struct ptlrpc_request **);
1401         int (*m_done_writing)(struct obd_export *, struct md_op_data  *,
1402                               struct md_open_data *);
1403         int (*m_enqueue)(struct obd_export *, struct ldlm_enqueue_info *,
1404                          struct lookup_intent *, struct md_op_data *,
1405                          struct lustre_handle *, void *, int, int);
1406         int (*m_getattr)(struct obd_export *, const struct lu_fid *,
1407                          struct obd_capa *, obd_valid, int,
1408                          struct ptlrpc_request **);
1409         int (*m_getattr_name)(struct obd_export *, const struct lu_fid *,
1410                               struct obd_capa *, const char *, int, obd_valid,
1411                               int, __u32, struct ptlrpc_request **);
1412         int (*m_intent_lock)(struct obd_export *, struct md_op_data *,
1413                              void *, int, struct lookup_intent *, int,
1414                              struct ptlrpc_request **,
1415                              ldlm_blocking_callback, int);
1416         int (*m_link)(struct obd_export *, struct md_op_data *,
1417                       struct ptlrpc_request **);
1418         int (*m_rename)(struct obd_export *, struct md_op_data *,
1419                         const char *, int, const char *, int,
1420                         struct ptlrpc_request **);
1421         int (*m_is_subdir)(struct obd_export *, const struct lu_fid *,
1422                            const struct lu_fid *,
1423                            struct ptlrpc_request **);
1424         int (*m_setattr)(struct obd_export *, struct md_op_data *, void *,
1425                          int , void *, int, struct ptlrpc_request **,
1426                          struct md_open_data **mod);
1427         int (*m_sync)(struct obd_export *, const struct lu_fid *,
1428                       struct obd_capa *, struct ptlrpc_request **);
1429         int (*m_readpage)(struct obd_export *, const struct lu_fid *,
1430                           struct obd_capa *, __u64, struct page *,
1431                           struct ptlrpc_request **);
1432
1433         int (*m_unlink)(struct obd_export *, struct md_op_data *,
1434                         struct ptlrpc_request **);
1435
1436         int (*m_setxattr)(struct obd_export *, const struct lu_fid *,
1437                           struct obd_capa *, obd_valid, const char *,
1438                           const char *, int, int, int, __u32,
1439                           struct ptlrpc_request **);
1440
1441         int (*m_getxattr)(struct obd_export *, const struct lu_fid *,
1442                           struct obd_capa *, obd_valid, const char *,
1443                           const char *, int, int, int,
1444                           struct ptlrpc_request **);
1445
1446         int (*m_init_ea_size)(struct obd_export *, int, int, int);
1447
1448         int (*m_get_lustre_md)(struct obd_export *, struct ptlrpc_request *,
1449                                struct obd_export *, struct obd_export *,
1450                                struct lustre_md *);
1451
1452         int (*m_free_lustre_md)(struct obd_export *, struct lustre_md *);
1453
1454         int (*m_set_open_replay_data)(struct obd_export *,
1455                                       struct obd_client_handle *,
1456                                       struct ptlrpc_request *);
1457         int (*m_clear_open_replay_data)(struct obd_export *,
1458                                         struct obd_client_handle *);
1459         int (*m_set_lock_data)(struct obd_export *, __u64 *, void *);
1460
1461         ldlm_mode_t (*m_lock_match)(struct obd_export *, int,
1462                                     const struct lu_fid *, ldlm_type_t,
1463                                     ldlm_policy_data_t *, ldlm_mode_t,
1464                                     struct lustre_handle *);
1465
1466         int (*m_cancel_unused)(struct obd_export *, const struct lu_fid *,
1467                                ldlm_policy_data_t *, ldlm_mode_t, int flags,
1468                                void *opaque);
1469         int (*m_renew_capa)(struct obd_export *, struct obd_capa *oc,
1470                             renew_capa_cb_t cb);
1471
1472         int (*m_get_remote_perm)(struct obd_export *, const struct lu_fid *,
1473                                  struct obd_capa *, __u32,
1474                                  struct ptlrpc_request **);
1475
1476         int (*m_intent_getattr_async)(struct obd_export *,
1477                                       struct md_enqueue_info *,
1478                                       struct ldlm_enqueue_info *);
1479
1480         int (*m_revalidate_lock)(struct obd_export *,
1481                                  struct lookup_intent *,
1482                                  struct lu_fid *);
1483
1484         /*
1485          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1486          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1487          * wrapper function in include/linux/obd_class.h.
1488          */
1489 };
1490
1491 struct lsm_operations {
1492         void (*lsm_free)(struct lov_stripe_md *);
1493         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
1494                            struct obd_export *md_exp);
1495         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
1496                                      unsigned long *);
1497         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
1498                                      unsigned long *);
1499         obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
1500         obd_off (*lsm_stripe_offset_by_offset)(struct lov_stripe_md *, obd_off);
1501         int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
1502         int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
1503         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
1504                                int *stripe_count);
1505         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
1506                              struct lov_mds_md *lmm);
1507 };
1508
1509 extern struct lsm_operations lsm_plain_ops;
1510 extern struct lsm_operations lsm_join_ops;
1511 static inline struct lsm_operations *lsm_op_find(int magic)
1512 {
1513         switch(magic) {
1514         case LOV_MAGIC:
1515                return &lsm_plain_ops;
1516         case LOV_MAGIC_JOIN:
1517                return &lsm_join_ops;
1518         default:
1519                CERROR("Cannot recognize lsm_magic %d\n", magic);
1520                return NULL;
1521         }
1522 }
1523
1524 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
1525
1526 /* Requests for obd_extent_calc() */
1527 #define OBD_CALC_STRIPE_START   1
1528 #define OBD_CALC_STRIPE_END     2
1529
1530 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
1531                                          int error)
1532 {
1533         if (error) {
1534                 CERROR("%s: transno "LPU64" commit error: %d\n",
1535                        obd->obd_name, transno, error);
1536                 return;
1537         }
1538         if (transno > obd->obd_last_committed) {
1539                 CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
1540                        obd->obd_name, transno);
1541                 obd->obd_last_committed = transno;
1542                 ptlrpc_commit_replies (obd);
1543         } else {
1544                 CDEBUG(D_INFO, "%s: transno "LPD64" committed\n",
1545                        obd->obd_name, transno);
1546         }
1547 }
1548
1549 static inline void init_obd_quota_ops(quota_interface_t *interface,
1550                                       struct obd_ops *obd_ops)
1551 {
1552         if (!interface)
1553                 return;
1554
1555         LASSERT(obd_ops);
1556         obd_ops->o_quotacheck = QUOTA_OP(interface, check);
1557         obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
1558 }
1559
1560 static inline __u64 oinfo_mdsno(struct obd_info *oinfo)
1561 {
1562         return oinfo->oi_oa->o_gr - FILTER_GROUP_MDS0;
1563 }
1564
1565 static inline struct lustre_capa *oinfo_capa(struct obd_info *oinfo)
1566 {
1567         return oinfo->oi_capa;
1568 }
1569
1570 #endif /* __OBD_H */