Whamcloud - gitweb
b=5150
[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         unsigned loi_kms_valid:1;
64         __u64 loi_kms;             /* known minimum size */
65         __u64 loi_rss;             /* recently seen size */
66         __u64 loi_mtime;           /* recently seen mtime */
67         __u64 loi_blocks;          /* recently seen blocks */
68 };
69
70 static inline void loi_init(struct lov_oinfo *loi)
71 {
72         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
73         INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
74         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
75         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
76         INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
77         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
78         INIT_LIST_HEAD(&loi->loi_cli_item);
79         INIT_LIST_HEAD(&loi->loi_write_item);
80         INIT_LIST_HEAD(&loi->loi_read_item);
81 }
82
83 struct lov_stripe_md {
84         /* Public members. */
85         __u64 lsm_object_id;        /* lov object id */
86         __u64 lsm_object_gr;        /* lov object id */
87         __u64 lsm_maxbytes;         /* maximum possible file size */
88         unsigned long lsm_xfersize; /* optimal transfer size */
89
90         /* LOV-private members start here -- only for use in lov/. */
91         __u32 lsm_magic;
92         __u32 lsm_stripe_size;      /* size of the stripe */
93         __u32 lsm_pattern;          /* striping pattern (RAID0, RAID1) */
94         unsigned lsm_stripe_count;  /* number of objects being striped over */
95         struct lov_oinfo lsm_oinfo[0];
96 };
97
98 static inline void dump_lsm(int level, struct lov_stripe_md *lsm)
99 {
100         int i;
101         CDEBUG(level, "objid "LPX64"/"LPU64", maxbytes "LPX64", magic 0x%08X, "
102                "stripe_size %u, stripe_count %u\n",
103                lsm->lsm_object_id, lsm->lsm_object_gr, lsm->lsm_maxbytes,
104                lsm->lsm_magic, lsm->lsm_stripe_size, lsm->lsm_stripe_count);
105         for (i = 0; i < lsm->lsm_stripe_count; i++)
106                 CDEBUG(level, "idx %u ostidx %u/%u object "LPU64"/"LPU64"\n",
107                        i, lsm->lsm_oinfo[i].loi_ost_idx,
108                        lsm->lsm_oinfo[i].loi_ost_gen,
109                        lsm->lsm_oinfo[i].loi_id, lsm->lsm_oinfo[i].loi_gr);
110 }
111
112 struct obd_type {
113         struct list_head typ_chain;
114         struct obd_ops *typ_ops;
115         struct md_ops *typ_md_ops;
116         struct proc_dir_entry *typ_procroot;
117         char *typ_name;
118         int  typ_refcnt;
119 };
120
121 struct brw_page {
122         obd_off disk_offset; /* modulo PAGE_SIZE */
123         obd_off page_offset; /* modulo PAGE_SIZE (obviously) */
124         struct page *pg;
125         int count;
126         obd_flag flag;
127 };
128
129 enum async_flags {
130         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
131                               page is added to an rpc */
132         ASYNC_URGENT = 0x2,
133         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
134                                      to give the caller a chance to update
135                                      or cancel the size of the io */
136         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
137                                     the page is accounted for in the
138                                     obd_io_group given to 
139                                     obd_queue_group_io */
140 };
141
142 struct obd_async_page_ops {
143         int  (*ap_make_ready)(void *data, int cmd);
144         int  (*ap_refresh_count)(void *data, int cmd);
145         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
146         void (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
147 };
148
149 /* the `oig' is passed down from a caller of obd rw methods.  the callee
150  * records enough state such that the caller can sleep on the oig and
151  * be woken when all the callees have finished their work */
152 struct obd_io_group {
153         spinlock_t      oig_lock;
154         atomic_t        oig_refcount;
155         int             oig_pending;
156         int             oig_rc;
157         struct list_head oig_occ_list;
158         wait_queue_head_t oig_waitq;
159 };
160
161 /* the oig callback context lets the callee of obd rw methods register
162  * for callbacks from the caller. */
163 struct oig_callback_context {
164         struct list_head occ_oig_item;
165         /* called when the caller has received a signal while sleeping.
166          * callees of this method are encouraged to abort their state 
167          * in the oig.  This may be called multiple times. */
168         void (*occ_interrupted)(struct oig_callback_context *occ);
169         int interrupted;
170 };
171
172 /* if we find more consumers this could be generalized */
173 #define OBD_HIST_MAX 32
174 struct obd_histogram {
175         spinlock_t      oh_lock;
176         unsigned long   oh_buckets[OBD_HIST_MAX];
177 };
178
179 /* reports average service time with the help of lprocfs_status.c */
180 struct obd_service_time {
181         __u32           st_num;
182         __u64           st_total_us;
183 };
184
185
186 struct ost_server_data;
187
188 #define FILTER_SUBDIR_COUNT      32            /* set to zero for no subdirs */
189
190 #define FILTER_GROUP_LLOG 1
191 #define FILTER_GROUP_ECHO 2
192 #define FILTER_GROUP_FIRST_MDS 3
193
194 struct filter_subdirs {
195         struct dentry *dentry[FILTER_SUBDIR_COUNT];
196 };
197
198 struct filter_group_llog {
199         struct list_head list;
200         int group;
201         struct obd_llogs *llogs;
202         struct obd_export *exp;
203 };
204
205 struct filter_obd {
206         const char          *fo_fstype;
207         struct super_block  *fo_sb;
208         struct vfsmount     *fo_vfsmnt;
209
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         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
279         void                    *cl_llcd_offset;
280
281         struct obd_device       *cl_mgmtcli_obd;
282
283         /* the grant values are protected by loi_list_lock below */
284         long                     cl_dirty;         /* all _dirty_ in bytes */
285         long                     cl_dirty_max;     /* allowed w/o rpc */
286         long                     cl_avail_grant;   /* bytes of credit for ost */
287         long                     cl_lost_grant;    /* lost credits (trunc) */
288         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
289
290         /* keep track of objects that have lois that contain pages which
291          * have been queued for async brw.  this lock also protects the
292          * lists of osc_client_pages that hang off of the loi */
293         spinlock_t               cl_loi_list_lock;
294         struct list_head         cl_loi_ready_list;
295         struct list_head         cl_loi_write_list;
296         struct list_head         cl_loi_read_list;
297         int                      cl_r_in_flight;
298         int                      cl_w_in_flight;
299         /* just a sum of the loi/lop pending numbers to be exported by /proc */
300         int                      cl_pending_w_pages;
301         int                      cl_pending_r_pages;
302         int                      cl_max_pages_per_rpc;
303         int                      cl_max_rpcs_in_flight;
304         struct obd_histogram     cl_read_rpc_hist;
305         struct obd_histogram     cl_write_rpc_hist;
306         struct obd_histogram     cl_read_page_hist;
307         struct obd_histogram     cl_write_page_hist;
308         struct obd_service_time  cl_read_stime;
309         struct obd_service_time  cl_write_stime;
310         struct obd_service_time  cl_enter_stime;
311
312         struct mdc_rpc_lock     *cl_rpc_lock;
313         struct mdc_rpc_lock     *cl_setattr_lock;
314         struct osc_creator       cl_oscc;
315 };
316
317 /* Like a client, with some hangers-on.  Keep mc_client_obd first so that we
318  * can reuse the various client setup/connect functions. */
319 struct mgmtcli_obd {
320         struct client_obd        mc_client_obd; /* nested */
321         struct ptlrpc_thread    *mc_ping_thread;
322         struct obd_export       *mc_ping_exp; /* XXX single-target */
323         struct list_head         mc_registered;
324         void                    *mc_hammer;
325 };
326
327 #define mc_import mc_client_obd.cl_import
328
329 struct mds_obd {
330         struct ptlrpc_service           *mds_service;
331         struct ptlrpc_service           *mds_setattr_service;
332         struct ptlrpc_service           *mds_readpage_service;
333         struct super_block              *mds_sb;
334         struct vfsmount                 *mds_vfsmnt;
335         struct dentry                   *mds_fid_de;
336         int                              mds_max_mdsize;
337         int                              mds_max_cookiesize;
338         struct file                     *mds_rcvd_filp;
339         spinlock_t                       mds_transno_lock;
340         __u64                            mds_last_transno;
341         __u64                            mds_mount_count;
342         __u64                            mds_io_epoch;
343         struct semaphore                 mds_epoch_sem;
344         struct ll_fid                    mds_rootfid;
345         struct mds_server_data          *mds_server_data;
346         struct dentry                   *mds_pending_dir;
347         struct dentry                   *mds_logs_dir;
348         struct dentry                   *mds_objects_dir;
349         struct llog_handle              *mds_cfg_llh;
350 //      struct llog_handle              *mds_catalog;
351         struct obd_device               *mds_osc_obd; /* XXX lov_obd */
352         struct obd_uuid                  mds_lov_uuid;
353         char                            *mds_profile;
354         struct obd_export               *mds_osc_exp; /* XXX lov_exp */
355         int                              mds_has_lov_desc;
356         struct lov_desc                  mds_lov_desc;
357         obd_id                          *mds_lov_objids;
358         int                              mds_lov_objids_valid;
359         int                              mds_lov_nextid_set;
360         struct file                     *mds_lov_objid_filp;
361         spinlock_t                      mds_lov_lock;
362         unsigned long                   *mds_client_bitmap;
363         struct semaphore                 mds_orphan_recovery_sem;
364         /*add mds num here for real mds and cache mds create
365           FIXME later will be totally fixed by b_cmd*/
366         int                              mds_num;
367         struct lprocfs_stats            *mds_counters;
368         int                              mds_config_version;
369
370         char                            *mds_lmv_name;
371         struct obd_device               *mds_lmv_obd; /* XXX lmv_obd */
372         struct obd_export               *mds_lmv_exp; /* XXX lov_exp */
373         struct ptlrpc_service           *mds_create_service;
374         struct semaphore                 mds_lmv_sem;
375         uid_t                            mds_squash_uid;
376         gid_t                            mds_squash_gid;
377         ptl_nid_t                        mds_nosquash_nid;
378         atomic_t                         mds_real_clients;
379         struct obd_uuid                  mds_lmv_uuid;
380         struct dentry                   *mds_fids_dir;
381         int                              mds_lmv_connected;
382         struct dentry                   *mds_unnamed_dir; /* for mdt_obd_create only */
383 };
384
385 struct echo_obd {
386         struct obdo          eo_oa;
387         spinlock_t           eo_lock;
388         __u64                eo_lastino;
389         struct lustre_handle eo_nl_lock;
390         atomic_t             eo_prep;
391 };
392
393 /*
394  * this struct does double-duty acting as either a client or
395  * server instance .. maybe not wise.
396  */
397 struct ptlbd_obd {
398         /* server's */
399         struct ptlrpc_service *ptlbd_service;
400         struct file *filp;
401         /* client's */
402         struct ptlrpc_client    bd_client;
403         struct obd_import       *bd_import;
404         struct obd_uuid         bd_server_uuid;
405         struct obd_export       *bd_exp;
406         int refcount; /* XXX sigh */
407 };
408
409 struct recovd_obd {
410         spinlock_t            recovd_lock;
411         struct list_head      recovd_managed_items; /* items managed  */
412         struct list_head      recovd_troubled_items; /* items in recovery */
413
414         wait_queue_head_t     recovd_recovery_waitq;
415         wait_queue_head_t     recovd_ctl_waitq;
416         wait_queue_head_t     recovd_waitq;
417         struct task_struct   *recovd_thread;
418         __u32                 recovd_state;
419 };
420
421 struct ost_obd {
422         spinlock_t              ost_lock;
423         struct ptlrpc_service *ost_service;
424         struct ptlrpc_service *ost_create_service;
425         struct obd_service_time ost_stimes[6];
426 };
427
428 struct echo_client_obd {
429         struct obd_export   *ec_exp;   /* the local connection to osc/lov */
430         spinlock_t           ec_lock;
431         struct list_head     ec_objects;
432         int                  ec_nstripes;
433         __u64                ec_unique;
434 };
435
436 struct cache_obd {
437         struct obd_export *cobd_real_exp;/* local connection to target obd */
438         struct obd_export *cobd_cache_exp; /* local connection to cache obd */
439         char   *cobd_real_name;
440         char   *cobd_cache_name;
441         int    refcount;
442         int    cache_on;
443 };
444
445 struct lov_tgt_desc {
446         struct obd_uuid          uuid;
447         __u32                    ltd_gen;
448         struct obd_export       *ltd_exp;
449         int                      active; /* is this target up for requests */
450 };
451
452 struct lov_obd {
453         spinlock_t lov_lock;
454         struct lov_desc desc;
455         struct semaphore lov_llog_sem;
456         int bufsize;
457         int refcount;
458         int lo_catalog_loaded:1;
459         unsigned long lov_connect_flags;
460         struct lov_tgt_desc *tgts;
461 };
462
463 struct lmv_tgt_desc {
464         struct obd_uuid         uuid;
465         struct obd_export       *ltd_exp;
466         int                      active; /* is this target up for requests */
467 };
468
469 struct lmv_obd {
470         spinlock_t              lmv_lock;
471         struct lmv_desc         desc;
472         int                     bufsize;
473         int                     refcount;
474         struct lmv_tgt_desc     *tgts;
475         struct obd_uuid         cluuid;
476         struct obd_export       *exp;
477         int                     connected;
478         int                     max_easize;
479         int                     max_cookiesize;
480         int                     server_timeout;
481         int                     connect_flags;
482         struct semaphore        init_sem;
483 };
484
485 struct niobuf_local {
486         __u64 offset;
487         __u32 len;
488         __u32 flags;
489         struct page *page;
490         struct dentry *dentry;
491         int lnb_grant_used;
492         int rc;
493 };
494
495 struct cache_manager_obd {
496         struct obd_device *cm_master_obd;       /* master lov */
497         struct obd_export *cm_master_exp;
498         struct obd_device *cm_cache_obd;        /* cache obdfilter */
499         struct obd_export *cm_cache_exp;
500         int    cm_master_group;                 /* master group*/        
501         struct cmobd_write_service   *cm_write_srv;
502 };
503         
504
505 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
506 #define N_LOCAL_TEMP_PAGE 0x10000000
507
508 struct obd_trans_info {
509         __u64                    oti_transno;
510         __u64                   *oti_objid;
511         /* Only used on the server side for tracking acks. */
512         struct oti_req_ack_lock {
513                 struct lustre_handle lock;
514                 __u32                mode;
515         }                        oti_ack_locks[4];
516         void                    *oti_handle;
517         struct llog_cookie       oti_onecookie;
518         struct llog_cookie      *oti_logcookies;
519         int                      oti_numcookies;
520 };
521
522 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
523 {
524         if (!oti)
525                 return;
526
527         if (num_cookies == 1)
528                 oti->oti_logcookies = &oti->oti_onecookie;
529         else
530                 OBD_ALLOC(oti->oti_logcookies,
531                           num_cookies * sizeof(oti->oti_onecookie));
532
533         oti->oti_numcookies = num_cookies;
534 }
535
536 static inline void oti_free_cookies(struct obd_trans_info *oti)
537 {
538         if (!oti || !oti->oti_logcookies)
539                 return;
540
541         if (oti->oti_logcookies == &oti->oti_onecookie)
542                 LASSERT(oti->oti_numcookies == 1);
543         else
544                 OBD_FREE(oti->oti_logcookies,
545                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
546         oti->oti_logcookies = NULL;
547         oti->oti_numcookies = 0;
548 }
549
550 /* llog contexts */
551 enum llog_ctxt_id {
552         LLOG_CONFIG_ORIG_CTXT =  0,
553         LLOG_CONFIG_REPL_CTXT =  1,
554         LLOG_UNLINK_ORIG_CTXT =  2,
555         LLOG_UNLINK_REPL_CTXT =  3,
556         LLOG_SIZE_ORIG_CTXT   =  4,
557         LLOG_SIZE_REPL_CTXT   =  5,
558         LLOG_MD_ORIG_CTXT     =  6,
559         LLOG_MD_REPL_CTXT     =  7,
560         LLOG_RD1_ORIG_CTXT    =  8,
561         LLOG_RD1_REPL_CTXT    =  9,
562         LLOG_TEST_ORIG_CTXT   = 10,
563         LLOG_TEST_REPL_CTXT   = 11,
564         LLOG_REINT_ORIG_CTXT  = 12,
565         LLOG_MAX_CTXTS
566 };
567
568 struct obd_llogs {
569         struct llog_ctxt        *llog_ctxt[LLOG_MAX_CTXTS];
570 };
571
572 struct target_recovery_data {
573         svc_handler_t     trd_recovery_handler;
574         pid_t             trd_processing_task;
575         struct completion trd_starting;
576         struct completion trd_finishing;
577 };
578
579 /* corresponds to one of the obd's */
580 struct obd_device {
581         struct obd_type *obd_type;
582
583         /* common and UUID name of this device */
584         char *obd_name;
585         struct obd_uuid obd_uuid;
586
587         int obd_minor;
588         unsigned int obd_attached:1, obd_set_up:1, obd_recovering:1,
589                 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
590                 obd_no_recov:1, obd_stopping:1;
591         atomic_t obd_refcount;
592         wait_queue_head_t obd_refcount_waitq;
593         struct proc_dir_entry *obd_proc_entry;
594         struct list_head       obd_exports;
595         int                    obd_num_exports;
596         struct ldlm_namespace *obd_namespace;
597         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
598         /* a spinlock is OK for what we do now, may need a semaphore later */
599         spinlock_t             obd_dev_lock;
600         __u64                  obd_last_committed;
601         struct fsfilt_operations *obd_fsops;
602         spinlock_t              obd_osfs_lock;
603         struct obd_statfs       obd_osfs;
604         unsigned long           obd_osfs_age;
605         struct lvfs_run_ctxt    obd_lvfs_ctxt;
606         struct obd_llogs        obd_llogs;
607         struct llog_ctxt        *obd_llog_ctxt[LLOG_MAX_CTXTS];
608         struct obd_device       *obd_observer;
609         struct obd_export       *obd_self_export;
610
611         struct target_recovery_data      obd_recovery_data;
612         /* XXX encapsulate all this recovery data into target_recovery_data */
613         int                              obd_max_recoverable_clients;
614         int                              obd_connected_clients;
615         int                              obd_recoverable_clients;
616         spinlock_t                       obd_processing_task_lock;
617         __u64                            obd_next_recovery_transno;
618         int                              obd_replayed_requests;
619         int                              obd_requests_queued_for_recovery;
620         wait_queue_head_t                obd_next_transno_waitq;
621         struct list_head                 obd_uncommitted_replies;
622         spinlock_t                       obd_uncommitted_replies_lock;
623         struct timer_list                obd_recovery_timer;
624         struct list_head                 obd_recovery_queue;
625         struct list_head                 obd_delayed_reply_queue;
626         time_t                           obd_recovery_start;
627         time_t                           obd_recovery_end;
628
629
630         union {
631                 struct filter_obd filter;
632                 struct mds_obd mds;
633                 struct client_obd cli;
634                 struct ost_obd ost;
635                 struct echo_client_obd echo_client;
636                 struct echo_obd echo;
637                 struct recovd_obd recovd;
638                 struct lov_obd lov;
639                 struct cache_obd cobd;
640                 struct ptlbd_obd ptlbd;
641                 struct mgmtcli_obd mgmtcli;
642                 struct lmv_obd lmv;
643                 struct cache_manager_obd cmobd;
644         } u;
645        /* Fields used by LProcFS */
646         unsigned int           obd_cntr_base;
647         struct lprocfs_stats  *obd_stats;
648         struct proc_dir_entry *obd_svc_procroot;
649         struct lprocfs_stats  *obd_svc_stats;
650 };
651
652 #define OBD_OPT_FORCE           0x0001
653 #define OBD_OPT_FAILOVER        0x0002
654 #define OBD_OPT_REAL_CLIENT     0x0004
655 #define OBD_OPT_MDS_CONNECTION  0x0008
656
657 #define OBD_LLOG_FL_SENDNOW     0x0001
658 #define OBD_LLOG_FL_CREATE      0x0002
659
660 struct mdc_op_data;
661
662 struct obd_ops {
663         struct module *o_owner;
664         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
665                            void *karg, void *uarg);
666         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
667                           __u32 *vallen, void *val);
668         int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
669                           __u32 vallen, void *val);
670         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
671         int (*o_detach)(struct obd_device *dev);
672         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
673         int (*o_precleanup)(struct obd_device *dev, int flags);
674         int (*o_cleanup)(struct obd_device *dev, int flags);
675         int (*o_process_config)(struct obd_device *dev, obd_count len,
676                                 void *data);
677         int (*o_postrecov)(struct obd_device *dev);
678         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
679                           int priority);
680         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
681         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
682                          struct obd_uuid *cluuid, unsigned long connect_flags);
683         int (*o_connect_post)(struct obd_export *exp, unsigned long connect_flags);
684         int (*o_disconnect)(struct obd_export *exp, int flags);
685
686         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
687                         unsigned long max_age);
688         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
689                         struct lov_stripe_md *mem_src);
690         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
691                           struct lov_mds_md *disk_src, int disk_len);
692         int (*o_revalidate_md)(struct obd_export *exp,  struct obdo *oa,
693                                struct lov_stripe_md *ea,
694                                struct obd_trans_info *oti);
695         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
696                              obd_id *ids);
697         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
698                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
699         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
700                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
701         int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
702                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
703         int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
704                          struct lov_stripe_md *ea);
705         int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
706                                struct lov_stripe_md *ea,
707                                struct ptlrpc_request_set *set);
708         int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
709                      struct lov_stripe_md *ea, obd_count oa_bufs,
710                      struct brw_page *pgarr, struct obd_trans_info *oti);
711         int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
712                            struct lov_stripe_md *ea, obd_count oa_bufs,
713                            struct brw_page *pgarr, struct ptlrpc_request_set *,
714                            struct obd_trans_info *oti);
715         int (*o_prep_async_page)(struct obd_export *exp, 
716                                  struct lov_stripe_md *lsm,
717                                  struct lov_oinfo *loi, 
718                                  struct page *page, obd_off offset, 
719                                  struct obd_async_page_ops *ops, void *data,
720                                  void **res);
721         int (*o_queue_async_io)(struct obd_export *exp, 
722                                 struct lov_stripe_md *lsm, 
723                                 struct lov_oinfo *loi, void *cookie, 
724                                 int cmd, obd_off off, int count, 
725                                 obd_flag brw_flags, obd_flag async_flags);
726         int (*o_queue_group_io)(struct obd_export *exp, 
727                                 struct lov_stripe_md *lsm, 
728                                 struct lov_oinfo *loi, 
729                                 struct obd_io_group *oig, 
730                                 void *cookie, int cmd, obd_off off, int count, 
731                                 obd_flag brw_flags, obd_flag async_flags);
732         int (*o_trigger_group_io)(struct obd_export *exp, 
733                                   struct lov_stripe_md *lsm, 
734                                   struct lov_oinfo *loi, 
735                                   struct obd_io_group *oig);
736         int (*o_set_async_flags)(struct obd_export *exp,
737                                 struct lov_stripe_md *lsm,
738                                 struct lov_oinfo *loi, void *cookie,
739                                 obd_flag async_flags);
740         int (*o_teardown_async_page)(struct obd_export *exp,
741                                      struct lov_stripe_md *lsm,
742                                      struct lov_oinfo *loi, void *cookie);
743         int (*o_punch)(struct obd_export *exp, struct obdo *oa,
744                        struct lov_stripe_md *ea, obd_size start,
745                        obd_size end, struct obd_trans_info *oti);
746         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
747                       struct lov_stripe_md *ea, obd_size start, obd_size end);
748         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
749                          struct lov_stripe_md *src, obd_size start,
750                          obd_size end, struct obd_trans_info *oti);
751         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
752                       struct lustre_handle *srconn, struct lov_stripe_md *src,
753                       obd_size start, obd_size end, struct obd_trans_info *);
754         int (*o_iterate)(struct lustre_handle *conn,
755                          int (*)(obd_id, obd_gr, void *),
756                          obd_id *startid, obd_gr group, void *data);
757         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
758                         int objcount, struct obd_ioobj *obj,
759                         int niocount, struct niobuf_remote *remote,
760                         struct niobuf_local *local, struct obd_trans_info *oti);
761         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
762                           int objcount, struct obd_ioobj *obj,
763                           int niocount, struct niobuf_local *local,
764                           struct obd_trans_info *oti, int rc);
765         int (*o_do_cow)(struct obd_export *exp, struct obd_ioobj *obj, 
766                         int objcount, struct niobuf_remote *rnb);
767         int (*o_write_extents)(struct obd_export *exp, struct obd_ioobj *obj,
768                                int objcount, int niocount, 
769                                struct niobuf_local *local,int rc);
770         int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
771                          __u32 type, ldlm_policy_data_t *, __u32 mode,
772                          int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
773                          void *data, __u32 lvb_len, void *lvb_swabber,
774                          struct lustre_handle *lockh);
775         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
776                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
777                        struct lustre_handle *lockh);
778         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
779                                ldlm_iterator_t it, void *data);
780         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
781                         __u32 mode, struct lustre_handle *);
782         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
783                                int flags, void *opaque);
784         int (*o_san_preprw)(int cmd, struct obd_export *exp,
785                             struct obdo *oa, int objcount,
786                             struct obd_ioobj *obj, int niocount,
787                             struct niobuf_remote *remote);
788         int (*o_init_export)(struct obd_export *exp);
789         int (*o_destroy_export)(struct obd_export *exp);
790
791         /* llog related obd_methods */
792         int (*o_llog_init)(struct obd_device *, struct obd_llogs *,
793                            struct obd_device *, int, struct llog_catid *);
794         int (*o_llog_finish)(struct obd_device *, struct obd_llogs *, int);
795         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
796
797        
798         /* metadata-only methods */
799         int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
800                      struct obd_client_handle *, int flag);
801         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
802
803         int (*o_import_event)(struct obd_device *, struct obd_import *,
804                               enum obd_import_event);
805
806         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
807                         int active, void *data);
808         int (*o_init_ea_size)(struct obd_export *, int, int);
809
810         /* 
811          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
812          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
813          * Also, add a wrapper function in include/linux/obd_class.h.
814          */
815 };
816
817 struct md_ops {
818         int (*m_getstatus)(struct obd_export *, struct ll_fid *);
819         int (*m_change_cbdata)(struct obd_export *, struct ll_fid *,
820                                ldlm_iterator_t, void *);
821         int (*m_change_cbdata_name)(struct obd_export *, struct ll_fid *,
822                                     char *, int, struct ll_fid *,
823                                     ldlm_iterator_t, void *);
824         int (*m_close)(struct obd_export *, struct obdo *,
825                        struct obd_client_handle *,
826                        struct ptlrpc_request **);
827         int (*m_create)(struct obd_export *, struct mdc_op_data *,
828                         const void *, int, int, __u32, __u32,
829                         __u64, struct ptlrpc_request **);
830         int (*m_done_writing)(struct obd_export *, struct obdo *);
831         int (*m_enqueue)(struct obd_export *, int, struct lookup_intent *,
832                          int, struct mdc_op_data *, struct lustre_handle *,
833                          void *, int, ldlm_completion_callback,
834                          ldlm_blocking_callback, void *);
835         int (*m_getattr)(struct obd_export *, struct ll_fid *,
836                          unsigned long, unsigned int,
837                          struct ptlrpc_request **);
838         int (*m_getattr_name)(struct obd_export *, struct ll_fid *,
839                               char *, int, unsigned long,
840                               unsigned int, struct ptlrpc_request **);
841         int (*m_intent_lock)(struct obd_export *,
842                              struct ll_fid *, const char *, int,
843                              void *, int, struct ll_fid *,
844                              struct lookup_intent *, int,
845                              struct ptlrpc_request **,
846                              ldlm_blocking_callback);
847         int (*m_link)(struct obd_export *, struct mdc_op_data *,
848                       struct ptlrpc_request **);
849         int (*m_rename)(struct obd_export *, struct mdc_op_data *,
850                         const char *, int, const char *, int,
851                         struct ptlrpc_request **);
852         int (*m_setattr)(struct obd_export *, struct mdc_op_data *,
853                          struct iattr *, void *, int , void *, int,
854                          struct ptlrpc_request **);
855         int (*m_sync)(struct obd_export *, struct ll_fid *,
856                       struct ptlrpc_request **);
857         int (*m_readpage)(struct obd_export *, struct ll_fid *,
858                           __u64, struct page *, struct ptlrpc_request **);
859         int (*m_unlink)(struct obd_export *, struct mdc_op_data *,
860                         struct ptlrpc_request **);
861         int (*m_valid_attrs)(struct obd_export *, struct ll_fid *);
862         struct obd_device * (*m_get_real_obd)(struct obd_export *,
863                              char *name, int len);
864         
865         int (*m_req2lustre_md)(struct obd_export *exp, 
866                                struct ptlrpc_request *req, unsigned int offset,
867                                struct obd_export *osc_exp, struct lustre_md *md);
868         int (*m_set_open_replay_data)(struct obd_export *exp,
869                                       struct obd_client_handle *och,
870                                       struct ptlrpc_request *open_req);
871         int (*m_clear_open_replay_data)(struct obd_export *exp,
872                                         struct obd_client_handle *och);
873         int (*m_store_inode_generation)(struct obd_export *exp, 
874                                         struct ptlrpc_request *req, int reqoff,
875                                         int repoff);
876         int (*m_set_lock_data)(struct obd_export *exp, __u64 *l, void *data);
877
878         int (*m_delete_object)(struct obd_export *, struct ll_fid *);
879         /* 
880          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
881          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
882          * Also, add a wrapper function in include/linux/obd_class.h.
883          */
884 };
885
886 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
887                                          int error)
888 {
889         if (error) {
890                 CERROR("%s: transno "LPD64" commit error: %d\n",
891                        obd->obd_name, transno, error);
892                 return;
893         }
894         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
895                obd->obd_name, transno);
896         if (transno > obd->obd_last_committed) {
897                 obd->obd_last_committed = transno;
898                 ptlrpc_commit_replies (obd);
899         }
900 }
901
902 #endif /* __OBD_H */