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