Whamcloud - gitweb
b=6332
[fs/lustre-release.git] / lustre / include / linux / obd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef __OBD_H
11 #define __OBD_H
12
13 #define IOC_OSC_TYPE         'h'
14 #define IOC_OSC_MIN_NR       20
15 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
16 #define IOC_OSC_CTL_RECOVERY _IOWR(IOC_OSC_TYPE, 22, struct obd_device *)
17 #define IOC_OSC_MAX_NR       50
18
19 #define IOC_MDC_TYPE         'i'
20 #define IOC_MDC_MIN_NR       20
21 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
22 /* Moved to lustre_user.h
23 #define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
24 #define IOC_MDC_MAX_NR       50
25
26 #ifdef __KERNEL__
27 # include <linux/fs.h>
28 # include <linux/list.h>
29 # include <linux/sched.h> /* for struct task_struct, for current.h */
30 # include <asm/current.h> /* for smp_lock.h */
31 # include <linux/smp_lock.h>
32 # include <linux/proc_fs.h>
33 # include <linux/mount.h>
34 #endif
35
36 #include <linux/lvfs.h>
37 #include <linux/lustre_lib.h>
38 #include <linux/lustre_idl.h>
39 #include <linux/lustre_export.h>
40
41 /* this is really local to the OSC */
42 struct loi_oap_pages {
43         struct list_head        lop_pending;
44         int                     lop_num_pending;
45         struct list_head        lop_urgent;
46         struct list_head        lop_pending_group;
47 };
48
49 struct lov_oinfo {                 /* per-stripe data structure */
50         __u64 loi_id;              /* object ID on the target OST */
51         __u64 loi_gr;              /* object group on the target OST */
52         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
53         int loi_ost_gen;           /* generation of this loi_ost_idx */
54
55         /* used by the osc to keep track of what objects to build into rpcs */
56         struct loi_oap_pages loi_read_lop;
57         struct loi_oap_pages loi_write_lop;
58         /* _cli_ is poorly named, it should be _ready_ */
59         struct list_head loi_cli_item;
60         struct list_head loi_write_item;
61         struct list_head loi_read_item;
62
63         unsigned loi_kms_valid:1;
64         __u64 loi_kms;             /* known minimum size */
65         __u64 loi_rss;             /* recently seen size */
66         __u64 loi_mtime;           /* recently seen mtime */
67         __u64 loi_blocks;          /* recently seen blocks */
68 };
69
70 static inline void loi_init(struct lov_oinfo *loi)
71 {
72         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
73         INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
74         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
75         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
76         INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
77         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
78         INIT_LIST_HEAD(&loi->loi_cli_item);
79         INIT_LIST_HEAD(&loi->loi_write_item);
80         INIT_LIST_HEAD(&loi->loi_read_item);
81 }
82
83 struct lov_stripe_md {
84         /* Public members. */
85         __u64 lsm_object_id;        /* lov object id */
86         __u64 lsm_object_gr;        /* lov object id */
87         __u64 lsm_maxbytes;         /* maximum possible file size */
88         unsigned long lsm_xfersize; /* optimal transfer size */
89
90         /* LOV-private members start here -- only for use in lov/. */
91         __u32 lsm_magic;
92         __u32 lsm_stripe_size;      /* size of the stripe */
93         __u32 lsm_pattern;          /* striping pattern (RAID0, RAID1) */
94         unsigned lsm_stripe_count;  /* number of objects being striped over */
95         struct lov_oinfo lsm_oinfo[0];
96 };
97
98 static inline void dump_lsm(int level, struct lov_stripe_md *lsm)
99 {
100         int i;
101         CDEBUG(level, "objid "LPX64"/"LPU64", maxbytes "LPX64", magic 0x%08X, "
102                "stripe_size %u, stripe_count %u\n",
103                lsm->lsm_object_id, lsm->lsm_object_gr, lsm->lsm_maxbytes,
104                lsm->lsm_magic, lsm->lsm_stripe_size, lsm->lsm_stripe_count);
105         for (i = 0; i < lsm->lsm_stripe_count; i++)
106                 CDEBUG(level, "idx %u ostidx %u/%u object "LPU64"/"LPU64"\n",
107                        i, lsm->lsm_oinfo[i].loi_ost_idx,
108                        lsm->lsm_oinfo[i].loi_ost_gen,
109                        lsm->lsm_oinfo[i].loi_id, lsm->lsm_oinfo[i].loi_gr);
110 }
111
112 struct obd_type {
113         struct list_head typ_chain;
114         struct obd_ops *typ_ops;
115         struct md_ops *typ_md_ops;
116         struct proc_dir_entry *typ_procroot;
117         char *typ_name;
118         int  typ_refcnt;
119 };
120
121 struct brw_page {
122         obd_off disk_offset; /* modulo PAGE_SIZE */
123         obd_off page_offset; /* modulo PAGE_SIZE (obviously) */
124         struct page *pg;
125         int count;
126         obd_flags flag;
127 };
128
129 enum async_flags {
130         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
131                               page is added to an rpc */
132         ASYNC_URGENT = 0x2,
133         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
134                                      to give the caller a chance to update
135                                      or cancel the size of the io */
136         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
137                                     the page is accounted for in the
138                                     obd_io_group given to 
139                                     obd_queue_group_io */
140 };
141
142 struct obd_async_page_ops {
143         int  (*ap_make_ready)(void *data, int cmd);
144         int  (*ap_refresh_count)(void *data, int cmd);
145         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
146         void (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
147 };
148
149 /* the `oig' is passed down from a caller of obd rw methods.  the callee
150  * records enough state such that the caller can sleep on the oig and
151  * be woken when all the callees have finished their work */
152 struct obd_io_group {
153         spinlock_t      oig_lock;
154         atomic_t        oig_refcount;
155         int             oig_pending;
156         int             oig_rc;
157         struct list_head oig_occ_list;
158         wait_queue_head_t oig_waitq;
159 };
160
161 /* the oig callback context lets the callee of obd rw methods register
162  * for callbacks from the caller. */
163 struct oig_callback_context {
164         struct list_head occ_oig_item;
165         /* called when the caller has received a signal while sleeping.
166          * callees of this method are encouraged to abort their state 
167          * in the oig.  This may be called multiple times. */
168         void (*occ_interrupted)(struct oig_callback_context *occ);
169         int interrupted;
170 };
171
172 /* if we find more consumers this could be generalized */
173 #define OBD_HIST_MAX 32
174 struct obd_histogram {
175         spinlock_t      oh_lock;
176         unsigned long   oh_buckets[OBD_HIST_MAX];
177 };
178
179 /* reports average service time with the help of lprocfs_status.c */
180 struct obd_service_time {
181         __u32           st_num;
182         __u64           st_total_us;
183 };
184
185
186 struct ost_server_data;
187
188 #define FILTER_SUBDIR_COUNT      32            /* set to zero for no subdirs */
189
190 #define FILTER_GROUP_LLOG 1
191 #define FILTER_GROUP_ECHO 2
192 #define FILTER_GROUP_FIRST_MDS 3
193
194 struct filter_subdirs {
195         struct dentry *dentry[FILTER_SUBDIR_COUNT];
196 };
197
198 struct filter_group_llog {
199         struct list_head list;
200         int group;
201         struct obd_llogs *llogs;
202         struct obd_export *exp;
203 };
204
205 struct filter_obd {
206         const char          *fo_fstype;
207         struct super_block  *fo_sb;
208         struct vfsmount     *fo_vfsmnt;
209         struct lvfs_obd_ctxt *fo_lvfs_ctxt;
210
211         int                    fo_group_count;
212         struct dentry         *fo_dentry_O;     /* the "O"bject directory dentry */
213         struct dentry         **fo_groups;      /* dentries for each group dir */
214         struct filter_subdirs *fo_subdirs;      /* subdir array per group */
215         __u64                 *fo_last_objids;  /* per-group last created objid */
216         struct file          **fo_last_objid_files;
217         struct semaphore     fo_init_lock;      /* group initialization lock */
218         int                  fo_committed_group;
219
220         spinlock_t           fo_objidlock;      /* protect fo_lastobjid increment */
221         spinlock_t           fo_translock;      /* protect fsd_last_rcvd increment */
222         struct file         *fo_rcvd_filp;
223         struct filter_server_data *fo_fsd;
224         unsigned long       *fo_last_rcvd_slots;
225         __u64                fo_mount_count;
226
227         unsigned long        fo_destroys_in_progress;
228         struct semaphore     fo_create_locks[32];
229
230         struct file_operations *fo_fop;
231         struct inode_operations *fo_iop;
232         struct address_space_operations *fo_aops;
233
234         struct list_head     fo_export_list;
235         int                  fo_subdir_count;
236
237         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
238         obd_size             fo_tot_granted;    /* all values in bytes */
239         obd_size             fo_tot_pending;
240
241         obd_size             fo_readcache_max_filesize;
242
243         struct obd_import   *fo_mdc_imp;
244         struct obd_uuid      fo_mdc_uuid;
245         struct lustre_handle fo_mdc_conn;
246
247         struct semaphore     fo_alloc_lock;
248
249         struct obd_histogram     fo_r_pages;
250         struct obd_histogram     fo_w_pages;
251         struct obd_histogram     fo_r_discont_pages;
252         struct obd_histogram     fo_w_discont_pages;
253         struct obd_histogram     fo_r_discont_blocks;
254         struct obd_histogram     fo_w_discont_blocks;
255
256         struct list_head         fo_llog_list;
257         spinlock_t               fo_llog_list_lock;
258 };
259
260 struct mds_server_data;
261
262 #define OSC_MAX_RIF_DEFAULT       8
263 #define OSC_MAX_RIF_MAX          64
264 #define OSC_MAX_DIRTY_DEFAULT   (4*OSC_MAX_RIF_DEFAULT*PTLRPC_MAX_BRW_SIZE>>20)
265 #define OSC_MAX_DIRTY_MB_MAX    512     /* totally arbitrary */
266
267
268 struct mdc_rpc_lock;
269 struct client_obd {
270         struct obd_import       *cl_import;
271         struct semaphore         cl_sem;
272         int                      cl_conn_count;
273         /* max_mds_easize is purely a performance thing so we don't have to
274          * call obd_size_wiremd() all the time. */
275         int                      cl_max_mds_easize;
276         int                      cl_max_mds_cookiesize;
277         kdev_t                   cl_sandev;
278
279         /* security flavors */
280         __u32                    cl_sec_flavor;
281         __u32                    cl_sec_subflavor;
282
283         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
284         void                    *cl_llcd_offset;
285
286         struct obd_device       *cl_mgmtcli_obd;
287
288         /* the grant values are protected by loi_list_lock below */
289         long                     cl_dirty;         /* all _dirty_ in bytes */
290         long                     cl_dirty_max;     /* allowed w/o rpc */
291         long                     cl_avail_grant;   /* bytes of credit for ost */
292         long                     cl_lost_grant;    /* lost credits (trunc) */
293         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
294
295         /* keep track of objects that have lois that contain pages which
296          * have been queued for async brw.  this lock also protects the
297          * lists of osc_client_pages that hang off of the loi */
298         spinlock_t               cl_loi_list_lock;
299         struct list_head         cl_loi_ready_list;
300         struct list_head         cl_loi_write_list;
301         struct list_head         cl_loi_read_list;
302         int                      cl_r_in_flight;
303         int                      cl_w_in_flight;
304         /* just a sum of the loi/lop pending numbers to be exported by /proc */
305         int                      cl_pending_w_pages;
306         int                      cl_pending_r_pages;
307         int                      cl_max_pages_per_rpc;
308         int                      cl_max_rpcs_in_flight;
309         struct obd_histogram     cl_read_rpc_hist;
310         struct obd_histogram     cl_write_rpc_hist;
311         struct obd_histogram     cl_read_page_hist;
312         struct obd_histogram     cl_write_page_hist;
313         struct obd_service_time  cl_read_stime;
314         struct obd_service_time  cl_write_stime;
315         struct obd_service_time  cl_enter_stime;
316
317         struct mdc_rpc_lock     *cl_rpc_lock;
318         struct mdc_rpc_lock     *cl_setattr_lock; 
319         struct mdc_rpc_lock     *cl_close_lock;
320         struct osc_creator       cl_oscc;
321         int                      cl_async:1;
322 };
323
324 /* Like a client, with some hangers-on.  Keep mc_client_obd first so that we
325  * can reuse the various client setup/connect functions. */
326 struct mgmtcli_obd {
327         struct client_obd        mc_client_obd; /* nested */
328         struct ptlrpc_thread    *mc_ping_thread;
329         struct obd_export       *mc_ping_exp; /* XXX single-target */
330         struct list_head         mc_registered;
331         void                    *mc_hammer;
332 };
333
334 #define mc_import mc_client_obd.cl_import
335
336 struct mds_obd {
337         struct ptlrpc_service           *mds_service;
338         struct ptlrpc_service           *mds_setattr_service;
339         struct ptlrpc_service           *mds_readpage_service;
340         struct super_block              *mds_sb;
341         struct vfsmount                 *mds_vfsmnt;
342         struct dentry                   *mds_id_de;
343         struct lvfs_obd_ctxt            *mds_lvfs_ctxt;
344         int                              mds_max_mdsize;
345         int                              mds_max_cookiesize;
346         struct file                     *mds_rcvd_filp;
347         struct file                     *mds_fid_filp;
348         struct file                     *mds_virtid_filp;
349         spinlock_t                       mds_transno_lock;
350         __u64                            mds_last_transno;
351         __u64                            mds_mount_count;
352         __u64                            mds_io_epoch;
353         
354         __u64                            mds_last_fid;
355         __u64                            mds_virtid_fid;
356         spinlock_t                       mds_last_fid_lock;
357         
358         struct semaphore                 mds_epoch_sem;
359         struct lustre_id                 mds_rootid;
360         struct mds_server_data          *mds_server_data;
361         struct dentry                   *mds_pending_dir;
362         struct dentry                   *mds_logs_dir;
363         struct dentry                   *mds_objects_dir;
364         struct llog_handle              *mds_cfg_llh;
365         char                            *mds_profile;
366         struct obd_device               *mds_dt_obd;
367         struct obd_uuid                  mds_dt_uuid;
368         struct obd_export               *mds_dt_exp;
369         int                              mds_has_dt_desc;
370         struct lov_desc                  mds_dt_desc;
371         obd_id                          *mds_dt_objids;
372         int                              mds_dt_objids_valid;
373         int                              mds_dt_nextid_set;
374         struct file                     *mds_dt_objid_filp;
375         spinlock_t                       mds_dt_lock;
376         unsigned long                   *mds_client_bitmap;
377         struct semaphore                 mds_orphan_recovery_sem;
378         
379         int                              mds_num;
380         int                              mds_config_version;
381
382         char                            *mds_md_name;
383         struct obd_device               *mds_md_obd;
384         struct obd_export               *mds_md_exp;
385         struct semaphore                 mds_md_sem;
386         struct obd_uuid                  mds_md_uuid;
387         int                              mds_md_connected;
388
389         struct ptlrpc_service           *mds_create_service;
390         uid_t                            mds_squash_uid;
391         gid_t                            mds_squash_gid;
392         ptl_nid_t                        mds_nosquash_nid;
393         atomic_t                         mds_real_clients;
394         atomic_t                         mds_open_count;
395         struct dentry                   *mds_id_dir;
396         int                              mds_obd_type;
397         struct dentry                   *mds_unnamed_dir; /* for mdt_obd_create only */
398
399         /* security related */
400         char                            *mds_mds_sec;
401         char                            *mds_ost_sec;
402 };
403
404 struct echo_obd {
405         struct obdo          eo_oa;
406         spinlock_t           eo_lock;
407         __u64                eo_lastino;
408         struct lustre_handle eo_nl_lock;
409         atomic_t             eo_prep;
410 };
411
412 /*
413  * this struct does double-duty acting as either a client or
414  * server instance .. maybe not wise.
415  */
416 struct ptlbd_obd {
417         /* server's */
418         struct ptlrpc_service *ptlbd_service;
419         struct file *filp;
420         /* client's */
421         struct ptlrpc_client    bd_client;
422         struct obd_import       *bd_import;
423         struct obd_uuid         bd_server_uuid;
424         struct obd_export       *bd_exp;
425         int refcount; /* XXX sigh */
426 };
427
428 struct recovd_obd {
429         spinlock_t            recovd_lock;
430         struct list_head      recovd_managed_items; /* items managed  */
431         struct list_head      recovd_troubled_items; /* items in recovery */
432
433         wait_queue_head_t     recovd_recovery_waitq;
434         wait_queue_head_t     recovd_ctl_waitq;
435         wait_queue_head_t     recovd_waitq;
436         struct task_struct   *recovd_thread;
437         __u32                 recovd_state;
438 };
439
440 struct ost_obd {
441         spinlock_t             ost_lock;
442         struct ptlrpc_service *ost_service;
443         struct ptlrpc_service *ost_create_service;
444         struct obd_service_time ost_stimes[6];
445 };
446
447 struct echo_client_obd {
448         struct obd_export      *ec_exp;     /* the local connection to osc/lov */
449         spinlock_t              ec_lock;
450         struct list_head        ec_objects;
451         int                     ec_nstripes;
452         __u64                   ec_unique;
453 };
454
455 struct cache_obd {
456         struct obd_export      *master_exp; /* local connection to master obd */
457         struct obd_export      *cache_exp;  /* local connection to cache obd */
458         struct obd_device      *master;
459         struct obd_device      *cache;
460         char                   *master_name;
461         char                   *cache_name;
462         int                     refcount;
463         int                     cache_on;
464         struct semaphore        sem;
465 };
466
467 struct cm_obd {
468         struct obd_export      *cache_exp;  /* local connection to cache obd */
469         struct obd_export      *master_exp;
470         struct obd_device      *cache_obd;
471         struct obd_device      *master_obd;
472         int                     master_group;
473         struct cmobd_write_service *write_srv;
474 };
475
476 struct conf_obd {
477         struct super_block      *cfobd_sb;
478         struct vfsmount         *cfobd_vfsmnt;
479         struct dentry           *cfobd_logs_dir;
480         struct dentry           *cfobd_objects_dir;
481         struct dentry           *cfobd_pending_dir;
482         struct llog_handle      *cfobd_cfg_llh;
483         struct lvfs_obd_ctxt    *cfobd_lvfs_ctxt;
484 };
485
486 struct lov_tgt_desc {
487         struct obd_uuid         uuid;
488         __u32                   ltd_gen;
489         struct obd_export      *ltd_exp;
490         int                     active;   /* is this target up for requests */
491 };
492
493 struct lov_obd {
494         spinlock_t              lov_lock;
495         struct lov_desc         desc;
496         int                     bufsize;
497         int                     refcount;
498         int                     lo_catalog_loaded:1, async:1;
499         struct semaphore        lov_llog_sem;
500         unsigned long           lov_connect_flags;
501         struct lov_tgt_desc    *tgts;
502 };
503
504 struct lmv_tgt_desc {
505         struct obd_uuid         uuid;
506         struct obd_export      *ltd_exp;
507         int                     active;   /* is this target up for requests */
508 };
509
510 struct lmv_obd {
511         int                     refcount;
512         spinlock_t              lmv_lock;
513         struct lmv_desc         desc;
514         struct lmv_tgt_desc     *tgts;
515         struct obd_uuid         cluuid;
516         struct obd_export       *exp;
517
518         int                     tgts_size;
519         int                     connected;
520         int                     max_easize;
521         int                     max_cookiesize;
522         int                     server_timeout;
523         int                     connect_flags;
524         struct semaphore        init_sem;
525         struct obd_connect_data conn_data;
526 };
527
528 struct niobuf_local {
529         __u64 offset;
530         __u32 len;
531         __u32 flags;
532         struct page *page;
533         struct dentry *dentry;
534         int lnb_grant_used;
535         int rc;
536 };
537
538 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
539 #define N_LOCAL_TEMP_PAGE 0x10000000
540
541 struct obd_trans_info {
542         __u64                    oti_transno;
543         __u64                   *oti_objid;
544         /* Only used on the server side for tracking acks. */
545         struct oti_req_ack_lock {
546                 struct lustre_handle lock;
547                 __u32                mode;
548         }                        oti_ack_locks[4];
549         void                    *oti_handle;
550         struct llog_cookie       oti_onecookie;
551         struct llog_cookie      *oti_logcookies;
552         int                      oti_numcookies;
553 };
554
555 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
556 {
557         if (!oti)
558                 return;
559
560         if (num_cookies == 1)
561                 oti->oti_logcookies = &oti->oti_onecookie;
562         else
563                 OBD_ALLOC(oti->oti_logcookies,
564                           num_cookies * sizeof(oti->oti_onecookie));
565
566         oti->oti_numcookies = num_cookies;
567 }
568
569 static inline void oti_free_cookies(struct obd_trans_info *oti)
570 {
571         if (!oti || !oti->oti_logcookies)
572                 return;
573
574         if (oti->oti_logcookies == &oti->oti_onecookie)
575                 LASSERT(oti->oti_numcookies == 1);
576         else
577                 OBD_FREE(oti->oti_logcookies,
578                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
579         oti->oti_logcookies = NULL;
580         oti->oti_numcookies = 0;
581 }
582
583 /* llog contexts */
584 enum llog_ctxt_id {
585         LLOG_CONFIG_ORIG_CTXT =  0,
586         LLOG_CONFIG_REPL_CTXT =  1,
587         LLOG_UNLINK_ORIG_CTXT =  2,
588         LLOG_UNLINK_REPL_CTXT =  3,
589         LLOG_SIZE_ORIG_CTXT   =  4,
590         LLOG_SIZE_REPL_CTXT   =  5,
591         LLOG_MD_ORIG_CTXT     =  6,
592         LLOG_MD_REPL_CTXT     =  7,
593         LLOG_RD1_ORIG_CTXT    =  8,
594         LLOG_RD1_REPL_CTXT    =  9,
595         LLOG_TEST_ORIG_CTXT   = 10,
596         LLOG_TEST_REPL_CTXT   = 11,
597         LLOG_REINT_ORIG_CTXT  = 12,
598         LLOG_MAX_CTXTS
599 };
600
601 struct obd_llogs {
602         struct llog_ctxt        *llog_ctxt[LLOG_MAX_CTXTS];
603 };
604
605 struct target_recovery_data {
606         svc_handler_t     trd_recovery_handler;
607         pid_t             trd_processing_task;
608         struct completion trd_starting;
609         struct completion trd_finishing;
610 };
611
612 /* corresponds to one of the obd's */
613 struct obd_device {
614         struct obd_type *obd_type;
615
616         /* common and UUID name of this device */
617         char *obd_name;
618         struct obd_uuid obd_uuid;
619
620         int obd_minor;
621         unsigned int obd_attached:1, obd_set_up:1, obd_recovering:1,
622                 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
623                 obd_no_recov:1, obd_stopping:1;
624         atomic_t obd_refcount;
625         wait_queue_head_t obd_refcount_waitq;
626         struct proc_dir_entry *obd_proc_entry;
627         struct list_head       obd_exports;
628         int                    obd_num_exports;
629         struct ldlm_namespace *obd_namespace;
630         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
631         /* a spinlock is OK for what we do now, may need a semaphore later */
632         spinlock_t             obd_dev_lock;
633         __u64                  obd_last_committed;
634         struct fsfilt_operations *obd_fsops;
635         spinlock_t              obd_osfs_lock;
636         struct obd_statfs       obd_osfs;
637         unsigned long           obd_osfs_age;
638         struct lvfs_run_ctxt    obd_lvfs_ctxt;
639         struct obd_llogs        obd_llogs;
640         struct llog_ctxt        *obd_llog_ctxt[LLOG_MAX_CTXTS];
641         struct obd_device       *obd_observer;
642         struct obd_export       *obd_self_export;
643
644         struct target_recovery_data      obd_recovery_data;
645         /* XXX encapsulate all this recovery data into target_recovery_data */
646         int                              obd_max_recoverable_clients;
647         int                              obd_connected_clients;
648         int                              obd_recoverable_clients;
649         spinlock_t                       obd_processing_task_lock;
650         __u64                            obd_next_recovery_transno;
651         int                              obd_replayed_requests;
652         int                              obd_replayed_locks;
653         int                              obd_requests_queued_for_recovery;
654         wait_queue_head_t                obd_next_transno_waitq;
655         struct list_head                 obd_uncommitted_replies;
656         spinlock_t                       obd_uncommitted_replies_lock;
657         struct timer_list                obd_recovery_timer;
658         time_t                           obd_recovery_start;
659         time_t                           obd_recovery_end;
660
661         atomic_t                         obd_req_replay_clients;
662         atomic_t                         obd_lock_replay_clients;
663
664         struct list_head                 obd_req_replay_queue;
665         struct list_head                 obd_lock_replay_queue;
666         struct list_head                 obd_final_req_queue;
667         int                              obd_recovery_stage;
668
669         union {
670                 struct filter_obd        filter;
671                 struct mds_obd           mds;
672                 struct client_obd        cli;
673                 struct ost_obd           ost;
674                 struct echo_client_obd   echocli;
675                 struct echo_obd          echo;
676                 struct recovd_obd        recovd;
677                 struct lov_obd           lov;
678                 struct cache_obd         cobd;
679                 struct ptlbd_obd         ptlbd;
680                 struct mgmtcli_obd       mgmtcli;
681                 struct lmv_obd           lmv;
682                 struct cm_obd            cm;
683                 struct conf_obd          conf;
684         } u;
685         
686         /* fields used by LProcFS */
687         unsigned int           obd_cntr_base;
688         struct lprocfs_stats  *obd_stats;
689         unsigned int           md_cntr_base;
690         struct lprocfs_stats  *md_stats;
691
692         struct proc_dir_entry *obd_svc_procroot;
693         struct lprocfs_stats  *obd_svc_stats;
694 };
695
696 #define OBD_OPT_FORCE             (1 << 0)
697 #define OBD_OPT_FAILOVER          (1 << 1)
698 #define OBD_OPT_REAL_CLIENT       (1 << 2)
699 #define OBD_OPT_MDS_CONNECTION    (1 << 3)
700
701 #define OBD_LLOG_FL_SENDNOW       (1 << 0)
702 #define OBD_LLOG_FL_CREATE        (1 << 1)
703
704 struct mdc_op_data;
705
706 struct obd_ops {
707         struct module *o_owner;
708         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
709                            void *karg, void *uarg);
710         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
711                           __u32 *vallen, void *val);
712         int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
713                           __u32 vallen, void *val);
714         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
715         int (*o_detach)(struct obd_device *dev);
716         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
717         int (*o_precleanup)(struct obd_device *dev, int flags);
718         int (*o_cleanup)(struct obd_device *dev, int flags);
719         int (*o_process_config)(struct obd_device *dev, obd_count len,
720                                 void *data);
721         int (*o_postrecov)(struct obd_device *dev);
722         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
723                           int priority);
724         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
725         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
726                          struct obd_uuid *cluuid, struct obd_connect_data *data,
727                          unsigned long flags);
728         int (*o_connect_post)(struct obd_export *exp, unsigned, unsigned long);
729         int (*o_disconnect)(struct obd_export *exp, unsigned long flags);
730
731         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
732                         unsigned long max_age);
733         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
734                         struct lov_stripe_md *mem_src);
735         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
736                           struct lov_mds_md *disk_src, int disk_len);
737         int (*o_revalidate_md)(struct obd_export *exp,  struct obdo *oa,
738                                struct lov_stripe_md *ea,
739                                struct obd_trans_info *oti);
740         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
741                              obd_id *ids);
742         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
743                         void *acl, int acl_size,
744                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
745         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
746                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
747         int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
748                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
749         int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
750                          struct lov_stripe_md *ea);
751         int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
752                                struct lov_stripe_md *ea,
753                                struct ptlrpc_request_set *set);
754         int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
755                      struct lov_stripe_md *ea, obd_count oa_bufs,
756                      struct brw_page *pgarr, struct obd_trans_info *oti);
757         int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
758                            struct lov_stripe_md *ea, obd_count oa_bufs,
759                            struct brw_page *pgarr, struct ptlrpc_request_set *,
760                            struct obd_trans_info *oti);
761         int (*o_prep_async_page)(struct obd_export *exp, 
762                                  struct lov_stripe_md *lsm,
763                                  struct lov_oinfo *loi, 
764                                  struct page *page, obd_off offset, 
765                                  struct obd_async_page_ops *ops, void *data,
766                                  void **res);
767         int (*o_queue_async_io)(struct obd_export *exp, 
768                                 struct lov_stripe_md *lsm, 
769                                 struct lov_oinfo *loi, void *cookie, 
770                                 int cmd, obd_off off, int count, 
771                                 obd_flags brw_flags, obd_flags async_flags);
772         int (*o_queue_group_io)(struct obd_export *exp, 
773                                 struct lov_stripe_md *lsm, 
774                                 struct lov_oinfo *loi, 
775                                 struct obd_io_group *oig, 
776                                 void *cookie, int cmd, obd_off off, int count, 
777                                 obd_flags brw_flags, obd_flags async_flags);
778         int (*o_trigger_group_io)(struct obd_export *exp, 
779                                   struct lov_stripe_md *lsm, 
780                                   struct lov_oinfo *loi, 
781                                   struct obd_io_group *oig);
782         int (*o_set_async_flags)(struct obd_export *exp,
783                                 struct lov_stripe_md *lsm,
784                                 struct lov_oinfo *loi, void *cookie,
785                                 obd_flags async_flags);
786         int (*o_teardown_async_page)(struct obd_export *exp,
787                                      struct lov_stripe_md *lsm,
788                                      struct lov_oinfo *loi, void *cookie);
789         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
790                             obd_off size, int shrink);
791         int (*o_punch)(struct obd_export *exp, struct obdo *oa,
792                        struct lov_stripe_md *ea, obd_size start,
793                        obd_size end, struct obd_trans_info *oti);
794         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
795                       struct lov_stripe_md *ea, obd_size start, obd_size end);
796         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
797                          struct lov_stripe_md *src, obd_size start,
798                          obd_size end, struct obd_trans_info *oti);
799         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
800                       struct lustre_handle *srconn, struct lov_stripe_md *src,
801                       obd_size start, obd_size end, struct obd_trans_info *);
802         int (*o_iterate)(struct lustre_handle *conn,
803                          int (*)(obd_id, obd_gr, void *),
804                          obd_id *startid, obd_gr group, void *data);
805         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
806                         int objcount, struct obd_ioobj *obj,
807                         int niocount, struct niobuf_remote *remote,
808                         struct niobuf_local *local, struct obd_trans_info *oti);
809         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
810                           int objcount, struct obd_ioobj *obj,
811                           int niocount, struct niobuf_local *local,
812                           struct obd_trans_info *oti, int rc);
813         int (*o_do_cow)(struct obd_export *exp, struct obd_ioobj *obj, 
814                         int objcount, struct niobuf_remote *rnb);
815         int (*o_write_extents)(struct obd_export *exp, struct obd_ioobj *obj,
816                                int objcount, int niocount, 
817                                struct niobuf_local *local,int rc);
818         int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
819                          __u32 type, ldlm_policy_data_t *, __u32 mode,
820                          int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
821                          void *data, __u32 lvb_len, void *lvb_swabber,
822                          struct lustre_handle *lockh);
823         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
824                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
825                        struct lustre_handle *lockh);
826         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
827                                ldlm_iterator_t it, void *data);
828         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
829                         __u32 mode, struct lustre_handle *);
830         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
831                                int flags, void *opaque);
832         int (*o_san_preprw)(int cmd, struct obd_export *exp,
833                             struct obdo *oa, int objcount,
834                             struct obd_ioobj *obj, int niocount,
835                             struct niobuf_remote *remote);
836         int (*o_init_export)(struct obd_export *exp);
837         int (*o_destroy_export)(struct obd_export *exp);
838
839         /* llog related obd_methods */
840         int (*o_llog_init)(struct obd_device *, struct obd_llogs *,
841                            struct obd_device *, int, struct llog_catid *);
842         int (*o_llog_finish)(struct obd_device *, struct obd_llogs *, int);
843         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
844
845        
846         /* metadata-only methods */
847         int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
848                      struct obd_client_handle *, int flag);
849         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
850
851         int (*o_import_event)(struct obd_device *, struct obd_import *,
852                               enum obd_import_event);
853
854         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
855                         int active, void *data);
856
857         /* this method is needed for cmobd to make say to LMV "get ready" when
858          * master obd is LMV. This is needed, because LMV is initialized in
859          * "defered" manner to let all MDSs to be set up first. */
860         int (*o_getready)(struct obd_export *exp);
861         int (*o_init_ea_size)(struct obd_export *, int, int);
862
863         /* 
864          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
865          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
866          * Also, add a wrapper function in include/linux/obd_class.h.
867          */
868 };
869
870 struct md_ops {
871         int (*m_getstatus)(struct obd_export *, struct lustre_id *);
872         int (*m_change_cbdata)(struct obd_export *, struct lustre_id *,
873                                ldlm_iterator_t, void *);
874         int (*m_change_cbdata_name)(struct obd_export *, struct lustre_id *,
875                                     char *, int, struct lustre_id *,
876                                     ldlm_iterator_t, void *);
877         int (*m_close)(struct obd_export *, struct obdo *,
878                        struct obd_client_handle *,
879                        struct ptlrpc_request **);
880         int (*m_create)(struct obd_export *, struct mdc_op_data *,
881                         const void *, int, int, __u32, __u32,
882                         __u64, struct ptlrpc_request **);
883         int (*m_done_writing)(struct obd_export *, struct obdo *);
884         int (*m_enqueue)(struct obd_export *, int, struct lookup_intent *,
885                          int, struct mdc_op_data *, struct lustre_handle *,
886                          void *, int, ldlm_completion_callback,
887                          ldlm_blocking_callback, void *);
888         int (*m_getattr)(struct obd_export *, struct lustre_id *,
889                          __u64, const char *, int,
890                          unsigned int, struct ptlrpc_request **);
891         int (*m_getattr_lock)(struct obd_export *, struct lustre_id *,
892                               char *, int, __u64,
893                               unsigned int, struct ptlrpc_request **);
894         int (*m_intent_lock)(struct obd_export *,
895                              struct lustre_id *, const char *, int,
896                              void *, int, struct lustre_id *,
897                              struct lookup_intent *, int,
898                              struct ptlrpc_request **,
899                              ldlm_blocking_callback);
900         int (*m_link)(struct obd_export *, struct mdc_op_data *,
901                       struct ptlrpc_request **);
902         int (*m_rename)(struct obd_export *, struct mdc_op_data *,
903                         const char *, int, const char *, int,
904                         struct ptlrpc_request **);
905         int (*m_setattr)(struct obd_export *, struct mdc_op_data *,
906                          struct iattr *, void *, int , void *, int,
907                          struct ptlrpc_request **);
908         int (*m_sync)(struct obd_export *, struct lustre_id *,
909                       struct ptlrpc_request **);
910         int (*m_readpage)(struct obd_export *, struct lustre_id *,
911                           __u64, struct page *, struct ptlrpc_request **);
912         int (*m_unlink)(struct obd_export *, struct mdc_op_data *,
913                         struct ptlrpc_request **);
914         int (*m_valid_attrs)(struct obd_export *, struct lustre_id *);
915         
916         struct obd_device *(*m_get_real_obd)(struct obd_export *, struct lustre_id *);
917         
918         int (*m_req2lustre_md)(struct obd_export *exp, 
919                                struct ptlrpc_request *req, unsigned int offset,
920                                struct obd_export *osc_exp, struct lustre_md *md);
921         int (*m_set_open_replay_data)(struct obd_export *exp,
922                                       struct obd_client_handle *och,
923                                       struct ptlrpc_request *open_req);
924         int (*m_clear_open_replay_data)(struct obd_export *exp,
925                                         struct obd_client_handle *och);
926         int (*m_store_inode_generation)(struct obd_export *exp, 
927                                         struct ptlrpc_request *req, int reqoff,
928                                         int repoff);
929         int (*m_set_lock_data)(struct obd_export *exp, __u64 *l, void *data);
930
931         int (*m_delete_inode)(struct obd_export *, struct lustre_id *);
932
933         /*
934          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
935          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
936          * wrapper function in include/linux/obd_class.h.
937          */
938 };
939
940 static inline void obd_transno_commit_cb(struct obd_device *obd,
941                                          __u64 transno, int error)
942 {
943         if (error) {
944                 CERROR("%s: transno "LPD64" commit error: %d\n",
945                        obd->obd_name, transno, error);
946                 return;
947         }
948         
949         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
950                obd->obd_name, transno);
951
952         if (transno > obd->obd_last_committed) {
953                 obd->obd_last_committed = transno;
954                 ptlrpc_commit_replies (obd);
955         }
956 }
957
958 #endif /* __OBD_H */