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