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