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