Whamcloud - gitweb
- many changes about fids:
[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
5 #ifndef __OBD_H
6 #define __OBD_H
7
8 #define IOC_OSC_TYPE         'h'
9 #define IOC_OSC_MIN_NR       20
10 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
11 #define IOC_OSC_MAX_NR       50
12
13 #define IOC_MDC_TYPE         'i'
14 #define IOC_MDC_MIN_NR       20
15 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
16 /* Moved to lustre_user.h
17 #define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
18 #define IOC_MDC_MAX_NR       50
19
20 #ifdef __KERNEL__
21 # include <linux/fs.h>
22 # include <linux/list.h>
23 # include <linux/sched.h> /* for struct task_struct, for current.h */
24 # include <asm/current.h> /* for smp_lock.h */
25 # include <linux/smp_lock.h>
26 # include <linux/proc_fs.h>
27 # include <linux/mount.h>
28 #endif
29
30 #include <linux/lustre_lib.h>
31 #include <linux/lustre_idl.h>
32 #include <linux/lustre_export.h>
33 #include <linux/lustre_quota.h>
34
35 #include <linux/lu_object.h>
36
37 /* this is really local to the OSC */
38 struct loi_oap_pages {
39         struct list_head        lop_pending;
40         int                     lop_num_pending;
41         struct list_head        lop_urgent;
42         struct list_head        lop_pending_group;
43 };
44
45 struct osc_async_rc {
46         int     ar_rc;
47         int     ar_force_sync;
48         int     ar_min_xid;
49 };
50
51 struct lov_oinfo {                 /* per-stripe data structure */
52         __u64 loi_id;              /* object ID on the target OST */
53         __u64 loi_gr;              /* object group on the target OST */
54         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
55         int loi_ost_gen;           /* generation of this loi_ost_idx */
56
57         /* used by the osc to keep track of what objects to build into rpcs */
58         struct loi_oap_pages loi_read_lop;
59         struct loi_oap_pages loi_write_lop;
60         /* _cli_ is poorly named, it should be _ready_ */
61         struct list_head loi_cli_item;
62         struct list_head loi_write_item;
63         struct list_head loi_read_item;
64
65         unsigned loi_kms_valid:1;
66         __u64 loi_kms;             /* known minimum size */
67         struct ost_lvb loi_lvb;
68         struct osc_async_rc     loi_ar;
69 };
70
71 static inline void loi_init(struct lov_oinfo *loi)
72 {
73         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
74         INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
75         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
76         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
77         INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
78         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
79         INIT_LIST_HEAD(&loi->loi_cli_item);
80         INIT_LIST_HEAD(&loi->loi_write_item);
81         INIT_LIST_HEAD(&loi->loi_read_item);
82 }
83 /*extent array item for describing the joined file extent info*/
84 struct lov_extent {
85         __u64 le_start;            /* extent start */
86         __u64 le_len;              /* extent length */
87         int   le_loi_idx;          /* extent #1 loi's index in lsm loi array */
88         int   le_stripe_count;     /* extent stripe count*/
89 };
90
91 /*Lov array info for describing joined file array EA info*/
92 struct lov_array_info {
93         struct llog_logid    lai_array_id;    /* MDS med llog object id */
94         unsigned             lai_ext_count; /* number of extent count */
95         struct lov_extent    *lai_ext_array; /* extent desc array */
96 };
97
98 struct lov_stripe_md {
99         spinlock_t       lsm_lock;
100         void            *lsm_lock_owner; /* debugging */
101
102         struct {
103                 /* Public members. */
104                 __u64 lw_object_id;        /* lov object id */
105                 __u64 lw_object_gr;        /* lov object id */
106                 __u64 lw_maxbytes;         /* maximum possible file size */
107                 unsigned long lw_xfersize; /* optimal transfer size */
108
109                 /* LOV-private members start here -- only for use in lov/. */
110                 __u32 lw_magic;
111                 __u32 lw_stripe_size;      /* size of the stripe */
112                 __u32 lw_pattern;          /* striping pattern (RAID0, RAID1) */
113                 unsigned lw_stripe_count;  /* number of objects being striped over */
114         } lsm_wire;
115
116         struct lov_array_info *lsm_array; /*Only for joined file array info*/
117         struct lov_oinfo lsm_oinfo[0];
118 };
119
120 #define lsm_object_id    lsm_wire.lw_object_id
121 #define lsm_object_gr    lsm_wire.lw_object_gr
122 #define lsm_maxbytes     lsm_wire.lw_maxbytes
123 #define lsm_xfersize     lsm_wire.lw_xfersize
124 #define lsm_magic        lsm_wire.lw_magic
125 #define lsm_stripe_size  lsm_wire.lw_stripe_size
126 #define lsm_pattern      lsm_wire.lw_pattern
127 #define lsm_stripe_count lsm_wire.lw_stripe_count
128
129 /* compare all relevant fields. */
130 static inline int lov_stripe_md_cmp(struct lov_stripe_md *m1,
131                                     struct lov_stripe_md *m2)
132 {
133         /*
134          * ->lsm_wire contains padding, but it should be zeroed out during
135          * allocation.
136          */
137         return memcmp(&m1->lsm_wire, &m2->lsm_wire, sizeof m1->lsm_wire);
138 }
139
140 void lov_stripe_lock(struct lov_stripe_md *md);
141 void lov_stripe_unlock(struct lov_stripe_md *md);
142
143 struct obd_type {
144         struct list_head typ_chain;
145         struct obd_ops *typ_ops;
146         struct proc_dir_entry *typ_procroot;
147         char *typ_name;
148         int  typ_refcnt;
149         struct lu_device_type *typ_lu;
150 };
151
152 struct brw_page {
153         obd_off  off;
154         struct page *pg;
155         int count;
156         obd_flag flag;
157 };
158
159 enum async_flags {
160         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
161                               page is added to an rpc */
162         ASYNC_URGENT = 0x2,
163         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
164                                      to give the caller a chance to update
165                                      or cancel the size of the io */
166         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
167                                     the page is accounted for in the
168                                     obd_io_group given to
169                                     obd_queue_group_io */
170 };
171
172 struct obd_async_page_ops {
173         int  (*ap_make_ready)(void *data, int cmd);
174         int  (*ap_refresh_count)(void *data, int cmd);
175         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
176         void (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
177 };
178
179 /* the `oig' is passed down from a caller of obd rw methods.  the callee
180  * records enough state such that the caller can sleep on the oig and
181  * be woken when all the callees have finished their work */
182 struct obd_io_group {
183         spinlock_t      oig_lock;
184         atomic_t        oig_refcount;
185         int             oig_pending;
186         int             oig_rc;
187         struct list_head oig_occ_list;
188         wait_queue_head_t oig_waitq;
189 };
190
191 /* the oig callback context lets the callee of obd rw methods register
192  * for callbacks from the caller. */
193 struct oig_callback_context {
194         struct list_head occ_oig_item;
195         /* called when the caller has received a signal while sleeping.
196          * callees of this method are encouraged to abort their state
197          * in the oig.  This may be called multiple times. */
198         void (*occ_interrupted)(struct oig_callback_context *occ);
199         unsigned int interrupted:1;
200 };
201
202 /* if we find more consumers this could be generalized */
203 #define OBD_HIST_MAX 32
204 struct obd_histogram {
205         spinlock_t      oh_lock;
206         unsigned long   oh_buckets[OBD_HIST_MAX];
207 };
208
209 /* Individual type definitions */
210
211 struct ost_server_data;
212
213 /* hold common fields for "target" device */
214 struct obd_device_target {
215         struct super_block       *obt_sb;
216         atomic_t                  obt_quotachecking;
217         struct lustre_quota_ctxt  obt_qctxt;
218 };
219
220 #define FILTER_GROUP_LLOG 1
221 #define FILTER_GROUP_ECHO 2
222
223 struct filter_ext {
224         __u64                fe_start;
225         __u64                fe_end;
226 };
227
228 struct filter_obd {
229         /* NB this field MUST be first */
230         struct obd_device_target fo_obt;
231         const char          *fo_fstype;
232         struct vfsmount     *fo_vfsmnt;
233         struct dentry       *fo_dentry_O;
234         struct dentry      **fo_dentry_O_groups;
235         struct dentry      **fo_dentry_O_sub;
236         spinlock_t           fo_objidlock;      /* protect fo_lastobjid */
237         spinlock_t           fo_translock;      /* protect fsd_last_transno */
238         struct file         *fo_rcvd_filp;
239         struct file         *fo_health_check_filp;
240         struct lr_server_data *fo_fsd;
241         unsigned long       *fo_last_rcvd_slots;
242         __u64                fo_mount_count;
243
244         int                  fo_destroy_in_progress;
245         struct semaphore     fo_create_lock;
246
247         struct list_head     fo_export_list;
248         int                  fo_subdir_count;
249
250         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
251         obd_size             fo_tot_granted;    /* all values in bytes */
252         obd_size             fo_tot_pending;
253
254         obd_size             fo_readcache_max_filesize;
255
256         struct obd_import   *fo_mdc_imp;
257         struct obd_uuid      fo_mdc_uuid;
258         struct lustre_handle fo_mdc_conn;
259         struct file        **fo_last_objid_files;
260         __u64               *fo_last_objids; /* last created objid for groups,
261                                               * protected by fo_objidlock */
262
263         struct semaphore     fo_alloc_lock;
264
265         spinlock_t fo_stats_lock;
266         int fo_r_in_flight; /* protected by fo_stats_lock */
267         int fo_w_in_flight; /* protected by fo_stats_lock */
268
269         /*
270          * per-filter pool of kiobuf's allocated by filter_common_setup() and
271          * torn down by filter_cleanup(). Contains OST_NUM_THREADS elements of
272          * which ->fo_iobuf_count were allocated.
273          *
274          * This pool contains kiobuf used by
275          * filter_{prep,commit}rw_{read,write}() and is shared by all OST
276          * threads.
277          *
278          * Locking: none, each OST thread uses only one element, determined by
279          * its "ordinal number", ->t_id.
280          */
281         struct filter_iobuf    **fo_iobuf_pool;
282         int                      fo_iobuf_count;
283
284         struct obd_histogram     fo_r_pages;
285         struct obd_histogram     fo_w_pages;
286         struct obd_histogram     fo_read_rpc_hist;
287         struct obd_histogram     fo_write_rpc_hist;
288         struct obd_histogram     fo_r_io_time;
289         struct obd_histogram     fo_w_io_time;
290         struct obd_histogram     fo_r_discont_pages;
291         struct obd_histogram     fo_w_discont_pages;
292         struct obd_histogram     fo_r_discont_blocks;
293         struct obd_histogram     fo_w_discont_blocks;
294         struct obd_histogram     fo_r_disk_iosize;
295         struct obd_histogram     fo_w_disk_iosize;
296
297         struct lustre_quota_ctxt fo_quota_ctxt;
298         spinlock_t               fo_quotacheck_lock;
299         atomic_t                 fo_quotachecking;
300 };
301
302 #define OSC_MAX_RIF_DEFAULT       8
303 #define OSC_MAX_RIF_MAX         256
304 #define OSC_MAX_DIRTY_DEFAULT  (OSC_MAX_RIF_DEFAULT * 4)
305 #define OSC_MAX_DIRTY_MB_MAX   2048     /* totally arbitrary */
306
307 struct mdc_rpc_lock;
308 struct client_obd {
309         struct obd_import       *cl_import;
310         struct semaphore         cl_sem;
311         int                      cl_conn_count;
312         /* max_mds_easize is purely a performance thing so we don't have to
313          * call obd_size_diskmd() all the time. */
314         int                      cl_default_mds_easize;
315         int                      cl_max_mds_easize;
316         int                      cl_max_mds_cookiesize;
317         kdev_t                   cl_sandev;
318
319         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
320         void                    *cl_llcd_offset;
321
322         /* the grant values are protected by loi_list_lock below */
323         long                     cl_dirty;         /* all _dirty_ in bytes */
324         long                     cl_dirty_max;     /* allowed w/o rpc */
325         long                     cl_avail_grant;   /* bytes of credit for ost */
326         long                     cl_lost_grant;    /* lost credits (trunc) */
327         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
328
329         /* keep track of objects that have lois that contain pages which
330          * have been queued for async brw.  this lock also protects the
331          * lists of osc_client_pages that hang off of the loi */
332         spinlock_t               cl_loi_list_lock;
333         struct list_head         cl_loi_ready_list;
334         struct list_head         cl_loi_write_list;
335         struct list_head         cl_loi_read_list;
336         int                      cl_r_in_flight;
337         int                      cl_w_in_flight;
338         /* just a sum of the loi/lop pending numbers to be exported by /proc */
339         int                      cl_pending_w_pages;
340         int                      cl_pending_r_pages;
341         int                      cl_max_pages_per_rpc;
342         int                      cl_max_rpcs_in_flight;
343         struct obd_histogram     cl_read_rpc_hist;
344         struct obd_histogram     cl_write_rpc_hist;
345         struct obd_histogram     cl_read_page_hist;
346         struct obd_histogram     cl_write_page_hist;
347         struct obd_histogram     cl_read_offset_hist;
348         struct obd_histogram     cl_write_offset_hist;
349
350         struct mdc_rpc_lock     *cl_rpc_lock;
351         struct mdc_rpc_lock     *cl_setattr_lock;
352         struct osc_creator       cl_oscc;
353
354         /* mgc datastruct */
355         struct semaphore         cl_mgc_sem;
356         struct vfsmount         *cl_mgc_vfsmnt;
357         struct dentry           *cl_mgc_configs_dir;
358         atomic_t                 cl_mgc_refcount;
359         struct obd_export       *cl_mgc_mgsexp;
360
361         /* Flags section */
362         unsigned int             cl_checksum:1; /* debug checksums */
363
364         /* also protected by the poorly named _loi_list_lock lock above */
365         struct osc_async_rc      cl_ar;
366
367         /* used by quotacheck */
368         int                      cl_qchk_stat; /* quotacheck stat of the peer */
369         struct ptlrpc_request_pool *cl_rq_pool; /* emergency pool of requests */
370 };
371
372 #define CL_NOT_QUOTACHECKED 1   /* client->cl_qchk_stat init value */
373
374 struct mgs_obd {
375         struct ptlrpc_service           *mgs_service;
376         struct vfsmount                 *mgs_vfsmnt;
377         struct super_block              *mgs_sb;
378         struct dentry                   *mgs_configs_dir;
379         struct dentry                   *mgs_fid_de;
380         spinlock_t                       mgs_fs_db_lock; /* add/remove db's */
381         struct list_head                 mgs_fs_db_list;
382         struct semaphore                 mgs_log_sem;    /* unused */
383 };
384
385 struct mds_obd {
386         /* NB this field MUST be first */
387         struct obd_device_target         mds_obt;
388         struct ptlrpc_service           *mds_service;
389         struct ptlrpc_service           *mds_setattr_service;
390         struct ptlrpc_service           *mds_readpage_service;
391         struct vfsmount                 *mds_vfsmnt;
392         struct dentry                   *mds_fid_de;
393         int                              mds_max_mdsize;
394         int                              mds_max_cookiesize;
395         struct file                     *mds_rcvd_filp;
396         spinlock_t                       mds_transno_lock;
397         __u64                            mds_last_transno;
398         __u64                            mds_mount_count;
399         __u64                            mds_io_epoch;
400         unsigned long                    mds_atime_diff;
401         struct semaphore                 mds_epoch_sem;
402         struct ll_fid                    mds_rootfid;
403         struct lr_server_data           *mds_server_data;
404         struct dentry                   *mds_pending_dir;
405         struct dentry                   *mds_logs_dir;
406         struct dentry                   *mds_objects_dir;
407         struct llog_handle              *mds_cfg_llh;
408 //        struct llog_handle              *mds_catalog;
409         struct obd_device               *mds_osc_obd; /* XXX lov_obd */
410         struct obd_uuid                  mds_lov_uuid;
411         char                            *mds_profile;
412         struct obd_export               *mds_osc_exp; /* XXX lov_exp */
413         struct lov_desc                  mds_lov_desc;
414         obd_id                          *mds_lov_objids;
415         int                              mds_lov_objids_size;
416         __u32                            mds_lov_objids_in_file;
417         unsigned int                     mds_lov_objids_dirty:1;
418         int                              mds_lov_nextid_set;
419         struct file                     *mds_lov_objid_filp;
420         struct file                     *mds_health_check_filp;
421         unsigned long                   *mds_client_bitmap;
422         struct semaphore                 mds_orphan_recovery_sem;
423         struct upcall_cache             *mds_group_hash;
424
425         struct lustre_quota_info         mds_quota_info;
426         struct semaphore                 mds_qonoff_sem;
427         struct semaphore                 mds_health_sem;
428         unsigned long                    mds_lov_objids_valid:1,
429                                          mds_fl_user_xattr:1,
430                                          mds_fl_acl:1;
431 };
432
433 struct echo_obd {
434         struct obdo          eo_oa;
435         spinlock_t           eo_lock;
436         __u64                eo_lastino;
437         struct lustre_handle eo_nl_lock;
438         atomic_t             eo_prep;
439 };
440
441 struct ost_obd {
442         struct ptlrpc_service *ost_service;
443         struct ptlrpc_service *ost_create_service;
444         struct ptlrpc_service *ost_io_service;
445         struct semaphore       ost_health_sem;
446 };
447
448 struct echo_client_obd {
449         struct obd_export   *ec_exp;   /* the local connection to osc/lov */
450         spinlock_t           ec_lock;
451         struct list_head     ec_objects;
452         int                  ec_nstripes;
453         __u64                ec_unique;
454 };
455
456 struct lov_tgt_desc {
457         struct obd_uuid          uuid;
458         __u32                    ltd_gen;
459         struct obd_export       *ltd_exp;
460         unsigned int             active:1, /* is this target up for requests */
461                                  reap:1;   /* should this target be deleted */
462 };
463
464 struct lov_obd {
465         struct semaphore lov_lock;
466         atomic_t refcount;
467         struct lov_desc desc;
468         struct obd_connect_data ocd;
469         int bufsize;
470         int connects;
471         int death_row;      /* Do we have tgts scheduled to be deleted?
472                                (Make this a linked list?) */
473         unsigned int lo_catalog_loaded:1;
474         struct lov_tgt_desc *tgts;
475 };
476
477 struct niobuf_local {
478         __u64 offset;
479         __u32 len;
480         __u32 flags;
481         struct page *page;
482         struct dentry *dentry;
483         int lnb_grant_used;
484         int rc;
485 };
486
487
488 /* device types (not names--FIXME) */
489 /* FIXME all the references to these defines need to be updated */
490 #define LUSTRE_MDS_NAME "mds"
491 #define LUSTRE_MDT_NAME "mdt"
492 #define LUSTRE_MDT0_NAME "mdt0"
493 #define LUSTRE_CMM0_NAME "cmm0"
494 #define LUSTRE_OSD0_NAME "osd0"
495
496 #define LUSTRE_MDC_NAME "mdc"
497
498 /* FIXME just the names need to be changed */
499 #define LUSTRE_OSS_NAME "ost" /*FIXME oss*/
500 #define LUSTRE_OST_NAME "obdfilter" /* FIXME ost*/
501 #define LUSTRE_OSTSAN_NAME "sanobdfilter"
502
503 #define LUSTRE_OSC_NAME "osc"
504 #define LUSTRE_FILTER_NAME "filter"
505 #define LUSTRE_SANOSC_NAME "sanosc"
506 #define LUSTRE_SANOST_NAME "sanost"
507 #define LUSTRE_MGS_NAME "mgs"
508 #define LUSTRE_MGC_NAME "mgc"
509
510 #define LUSTRE_MGS_OBDNAME "MGS"
511 #define LUSTRE_MGC_OBDNAME "MGC"
512
513
514 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
515 #define N_LOCAL_TEMP_PAGE 0x10000000
516
517 struct obd_trans_info {
518         __u64                    oti_transno;
519         __u64                   *oti_objid;
520         /* Only used on the server side for tracking acks. */
521         struct oti_req_ack_lock {
522                 struct lustre_handle lock;
523                 __u32                mode;
524         }                        oti_ack_locks[4];
525         void                    *oti_handle;
526         struct llog_cookie       oti_onecookie;
527         struct llog_cookie      *oti_logcookies;
528         int                      oti_numcookies;
529
530         /* initial thread handling transaction */
531         int                      oti_thread_id;
532 };
533
534 static inline void oti_init(struct obd_trans_info *oti,
535                             struct ptlrpc_request *req)
536 {
537         if (oti == NULL)
538                 return;
539         memset(oti, 0, sizeof *oti);
540
541         if (req == NULL)
542                 return;
543
544         if (req->rq_repmsg && req->rq_reqmsg != 0)
545                 oti->oti_transno = req->rq_repmsg->transno;
546         oti->oti_thread_id = req->rq_svc_thread ? req->rq_svc_thread->t_id : -1;
547 }
548
549 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
550 {
551         if (!oti)
552                 return;
553
554         if (num_cookies == 1)
555                 oti->oti_logcookies = &oti->oti_onecookie;
556         else
557                 OBD_ALLOC(oti->oti_logcookies,
558                           num_cookies * sizeof(oti->oti_onecookie));
559
560         oti->oti_numcookies = num_cookies;
561 }
562
563 static inline void oti_free_cookies(struct obd_trans_info *oti)
564 {
565         if (!oti || !oti->oti_logcookies)
566                 return;
567
568         if (oti->oti_logcookies == &oti->oti_onecookie)
569                 LASSERT(oti->oti_numcookies == 1);
570         else
571                 OBD_FREE(oti->oti_logcookies,
572                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
573         oti->oti_logcookies = NULL;
574         oti->oti_numcookies = 0;
575 }
576
577 /* llog contexts */
578 enum llog_ctxt_id {
579         LLOG_CONFIG_ORIG_CTXT  =  0,
580         LLOG_CONFIG_REPL_CTXT  =  1,
581         LLOG_MDS_OST_ORIG_CTXT =  2,
582         LLOG_MDS_OST_REPL_CTXT =  3,
583         LLOG_SIZE_ORIG_CTXT    =  4,
584         LLOG_SIZE_REPL_CTXT    =  5,
585         LLOG_MD_ORIG_CTXT      =  6,
586         LLOG_MD_REPL_CTXT      =  7,
587         LLOG_RD1_ORIG_CTXT     =  8,
588         LLOG_RD1_REPL_CTXT     =  9,
589         LLOG_TEST_ORIG_CTXT    = 10,
590         LLOG_TEST_REPL_CTXT    = 11,
591         LLOG_LOVEA_ORIG_CTXT  = 12,
592         LLOG_LOVEA_REPL_CTXT  = 13,
593         LLOG_MAX_CTXTS
594 };
595
596 /*
597  * Events signalled through obd_notify() upcall-chain.
598  */
599 enum obd_notify_event {
600         /* Device activated */
601         OBD_NOTIFY_ACTIVE,
602         /* Device deactivated */
603         OBD_NOTIFY_INACTIVE,
604         /* Connect data for import were changed */
605         OBD_NOTIFY_OCD,
606         /* Sync request */
607         OBD_NOTIFY_SYNC_NONBLOCK,
608         OBD_NOTIFY_SYNC
609 };
610
611 /*
612  * Data structure used to pass obd_notify()-event to non-obd listeners (llite
613  * and liblustre being main examples).
614  */
615 struct obd_notify_upcall {
616         int (*onu_upcall)(struct obd_device *host, struct obd_device *watched,
617                           enum obd_notify_event ev, void *owner);
618         /* Opaque datum supplied by upper layer listener */
619         void *onu_owner;
620 };
621
622
623 /* corresponds to one of the obd's */
624 struct obd_device {
625         struct obd_type        *obd_type;
626         /* common and UUID name of this device */
627         char                   *obd_name;
628         struct obd_uuid         obd_uuid;
629
630         struct lu_device       *obd_lu_dev;
631
632         int                     obd_minor;
633         unsigned int obd_attached:1, obd_set_up:1, obd_recovering:1,
634                 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
635                 obd_no_recov:1, obd_stopping:1, obd_starting:1,
636                 obd_force:1, obd_fail:1, obd_async_recov:1;
637         atomic_t obd_refcount;
638         wait_queue_head_t obd_refcount_waitq;
639         struct proc_dir_entry  *obd_proc_entry;
640         struct list_head        obd_exports;
641         int                     obd_num_exports;
642         struct ldlm_namespace  *obd_namespace;
643         struct ptlrpc_client    obd_ldlm_client; /* XXX OST/MDS only */
644         /* a spinlock is OK for what we do now, may need a semaphore later */
645         spinlock_t              obd_dev_lock;
646         __u64                   obd_last_committed;
647         struct fsfilt_operations *obd_fsops;
648         spinlock_t              obd_osfs_lock;
649         struct obd_statfs       obd_osfs;       /* locked by obd_osfs_lock */
650         unsigned long           obd_osfs_age;   /* jiffies */
651         struct lvfs_run_ctxt    obd_lvfs_ctxt;
652         struct llog_ctxt        *obd_llog_ctxt[LLOG_MAX_CTXTS];
653         struct obd_device       *obd_observer;
654         struct obd_notify_upcall obd_upcall;
655         struct obd_export       *obd_self_export;
656         /* list of exports in LRU order, for ping evictor, with obd_dev_lock */
657         struct list_head        obd_exports_timed;
658         time_t                  obd_eviction_timer; /* for ping evictor */
659
660         /* XXX encapsulate all this recovery data into one struct */
661         svc_handler_t                    obd_recovery_handler;
662         int                              obd_max_recoverable_clients;
663         int                              obd_connected_clients;
664         int                              obd_recoverable_clients;
665         spinlock_t                       obd_processing_task_lock;
666         pid_t                            obd_processing_task;
667         __u64                            obd_next_recovery_transno;
668         int                              obd_replayed_requests;
669         int                              obd_requests_queued_for_recovery;
670         wait_queue_head_t                obd_next_transno_waitq;
671         struct list_head                 obd_uncommitted_replies;
672         spinlock_t                       obd_uncommitted_replies_lock;
673         struct timer_list                obd_recovery_timer;
674         struct list_head                 obd_recovery_queue;
675         struct list_head                 obd_delayed_reply_queue;
676         time_t                           obd_recovery_start;
677         time_t                           obd_recovery_end;
678
679         union {
680                 struct obd_device_target obt;
681                 struct filter_obd filter;
682                 struct mds_obd mds;
683                 struct client_obd cli;
684                 struct ost_obd ost;
685                 struct echo_client_obd echo_client;
686                 struct echo_obd echo;
687                 struct lov_obd lov;
688                 struct mgs_obd mgs;
689         } u;
690         /* Fields used by LProcFS */
691         unsigned int           obd_cntr_base;
692         struct lprocfs_stats  *obd_stats;
693         struct proc_dir_entry *obd_svc_procroot;
694         struct lprocfs_stats  *obd_svc_stats;
695 };
696
697 #define OBD_OPT_FORCE           0x0001
698 #define OBD_OPT_FAILOVER        0x0002
699
700 #define OBD_LLOG_FL_SENDNOW     0x0001
701
702
703 /* Special case hack for MDS LOVs */
704 #define OBD_CLEANUP_EARLY       0
705 /* Precleanup stage 1, we must make sure all exports (other than the
706    self-export) get destroyed. */
707 #define OBD_CLEANUP_EXPORTS     1
708 /* Precleanup stage 2,  do other type-specific cleanup requiring the
709    self-export. */
710 #define OBD_CLEANUP_SELF_EXP    2
711 /* FIXME we should eliminate the "precleanup" function and make them stages
712    of the "cleanup" function. */
713 #define OBD_CLEANUP_OBD         3
714
715 struct obd_ops {
716         struct module *o_owner;
717         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
718                            void *karg, void *uarg);
719         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
720                           __u32 *vallen, void *val);
721         int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
722                           __u32 vallen, void *val);
723         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
724         int (*o_detach)(struct obd_device *dev);
725         int (*o_setup) (struct obd_device *dev, struct lustre_cfg *cfg);
726         int (*o_precleanup)(struct obd_device *dev, int cleanup_stage);
727         int (*o_cleanup)(struct obd_device *dev);
728         int (*o_process_config)(struct obd_device *dev, obd_count len,
729                                 void *data);
730         int (*o_postrecov)(struct obd_device *dev);
731         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
732                           int priority);
733         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
734         /* connect to the target device with given connection
735          * data. @ocd->ocd_connect_flags is modified to reflect flags actually
736          * granted by the target, which are guaranteed to be a subset of flags
737          * asked for. If @ocd == NULL, use default parameters. */
738         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
739                          struct obd_uuid *cluuid, struct obd_connect_data *ocd);
740         int (*o_reconnect)(struct obd_export *exp, struct obd_device *src,
741                            struct obd_uuid *cluuid,
742                            struct obd_connect_data *ocd);
743         int (*o_disconnect)(struct obd_export *exp);
744
745         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
746                         unsigned long max_age);
747         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
748                         struct lov_stripe_md *mem_src);
749         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
750                           struct lov_mds_md *disk_src, int disk_len);
751         int (*o_checkmd)(struct obd_export *exp, struct obd_export *md_exp,
752                          struct lov_stripe_md *mem_tgt);
753         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
754                              obd_id *ids);
755         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
756                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
757         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
758                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
759                          struct obd_export *md_exp);
760         int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
761                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
762         int (*o_setattr_async)(struct obd_export *exp, struct obdo *oa,
763                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
764         int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
765                          struct lov_stripe_md *ea);
766         int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
767                                struct lov_stripe_md *ea,
768                                struct ptlrpc_request_set *set);
769         int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
770                      struct lov_stripe_md *ea, obd_count oa_bufs,
771                      struct brw_page *pgarr, struct obd_trans_info *oti);
772         int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
773                            struct lov_stripe_md *ea, obd_count oa_bufs,
774                            struct brw_page *pgarr, struct ptlrpc_request_set *,
775                            struct obd_trans_info *oti);
776         int (*o_prep_async_page)(struct obd_export *exp,
777                                  struct lov_stripe_md *lsm,
778                                  struct lov_oinfo *loi,
779                                  struct page *page, obd_off offset,
780                                  struct obd_async_page_ops *ops, void *data,
781                                  void **res);
782         int (*o_queue_async_io)(struct obd_export *exp,
783                                 struct lov_stripe_md *lsm,
784                                 struct lov_oinfo *loi, void *cookie,
785                                 int cmd, obd_off off, int count,
786                                 obd_flag brw_flags, obd_flag async_flags);
787         int (*o_queue_group_io)(struct obd_export *exp,
788                                 struct lov_stripe_md *lsm,
789                                 struct lov_oinfo *loi,
790                                 struct obd_io_group *oig,
791                                 void *cookie, int cmd, obd_off off, int count,
792                                 obd_flag brw_flags, obd_flag async_flags);
793         int (*o_trigger_group_io)(struct obd_export *exp,
794                                   struct lov_stripe_md *lsm,
795                                   struct lov_oinfo *loi,
796                                   struct obd_io_group *oig);
797         int (*o_set_async_flags)(struct obd_export *exp,
798                                 struct lov_stripe_md *lsm,
799                                 struct lov_oinfo *loi, void *cookie,
800                                 obd_flag async_flags);
801         int (*o_teardown_async_page)(struct obd_export *exp,
802                                      struct lov_stripe_md *lsm,
803                                      struct lov_oinfo *loi, void *cookie);
804         int (*o_merge_lvb)(struct obd_export *exp, struct lov_stripe_md *lsm,
805                            struct ost_lvb *lvb, int kms_only);
806         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
807                             obd_off size, int shrink);
808         int (*o_punch)(struct obd_export *exp, struct obdo *oa,
809                        struct lov_stripe_md *ea, obd_size start,
810                        obd_size end, struct obd_trans_info *oti);
811         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
812                       struct lov_stripe_md *ea, obd_size start, obd_size end);
813         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
814                          struct lov_stripe_md *src, obd_size start,
815                          obd_size end, struct obd_trans_info *oti);
816         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
817                       struct lustre_handle *srconn, struct lov_stripe_md *src,
818                       obd_size start, obd_size end, struct obd_trans_info *);
819         int (*o_iterate)(struct lustre_handle *conn,
820                          int (*)(obd_id, obd_gr, void *),
821                          obd_id *startid, obd_gr group, void *data);
822         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
823                         int objcount, struct obd_ioobj *obj,
824                         int niocount, struct niobuf_remote *remote,
825                         struct niobuf_local *local, struct obd_trans_info *oti);
826         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
827                           int objcount, struct obd_ioobj *obj,
828                           int niocount, struct niobuf_local *local,
829                           struct obd_trans_info *oti, int rc);
830         int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
831                          __u32 type, ldlm_policy_data_t *, __u32 mode,
832                          int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
833                          void *data, __u32 lvb_len, void *lvb_swabber,
834                          struct lustre_handle *lockh);
835         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
836                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
837                        struct lustre_handle *lockh);
838         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
839                                ldlm_iterator_t it, void *data);
840         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
841                         __u32 mode, struct lustre_handle *);
842         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
843                                int flags, void *opaque);
844         int (*o_join_lru)(struct obd_export *, struct lov_stripe_md *,
845                          int join);
846         int (*o_san_preprw)(int cmd, struct obd_export *exp,
847                             struct obdo *oa, int objcount,
848                             struct obd_ioobj *obj, int niocount,
849                             struct niobuf_remote *remote);
850         int (*o_init_export)(struct obd_export *exp);
851         int (*o_destroy_export)(struct obd_export *exp);
852
853         /* llog related obd_methods */
854         int (*o_llog_init)(struct obd_device *obd, struct obd_device *disk_obd,
855                            int count, struct llog_catid *logid);
856         int (*o_llog_finish)(struct obd_device *obd, int count);
857
858         /* metadata-only methods */
859         int (*o_pin)(struct obd_export *, struct lu_fid *fid,
860                      struct obd_client_handle *, int flag);
861         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
862
863         int (*o_import_event)(struct obd_device *, struct obd_import *,
864                               enum obd_import_event);
865
866         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
867                         enum obd_notify_event ev, void *data);
868
869         int (*o_health_check)(struct obd_device *);
870
871         /* quota methods */
872         int (*o_quotacheck)(struct obd_export *, struct obd_quotactl *);
873         int (*o_quotactl)(struct obd_export *, struct obd_quotactl *);
874
875         /*
876          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
877          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
878          * Also, add a wrapper function in include/linux/obd_class.h.
879          *
880          * Also note that if you add it to the END, you also have to change
881          * the num_stats calculation.
882          *
883          */
884 };
885
886 struct lsm_operations {
887         void (*lsm_free)(struct lov_stripe_md *);
888         int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa,
889                            struct obd_export *md_exp);
890         void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, obd_off *,
891                                      unsigned long *);
892         void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, obd_off *,
893                                      unsigned long *);
894         obd_off (*lsm_stripe_offset_by_index)(struct lov_stripe_md *, int);
895         int (*lsm_stripe_index_by_offset)(struct lov_stripe_md *, obd_off);
896         int (*lsm_revalidate) (struct lov_stripe_md *, struct obd_device *obd);
897         int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
898                                int *stripe_count);
899         int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
900                              struct lov_mds_md *lmm);
901 };
902
903 extern struct lsm_operations lsm_plain_ops;
904 extern struct lsm_operations lsm_join_ops;
905 static inline struct lsm_operations *lsm_op_find(int magic)
906 {
907         switch(magic) {
908         case LOV_MAGIC:
909                return &lsm_plain_ops;
910         case LOV_MAGIC_JOIN:
911                return &lsm_join_ops;
912         default:
913                CERROR("Cannot recognize lsm_magic %d", magic);
914                return NULL;
915         }
916 }
917
918 int lvfs_check_io_health(struct obd_device *obd, struct file *file);
919
920 static inline void obd_transno_commit_cb(struct obd_device *obd, __u64 transno,
921                                          int error)
922 {
923         if (error) {
924                 CERROR("%s: transno "LPD64" commit error: %d\n",
925                        obd->obd_name, transno, error);
926                 return;
927         }
928         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
929                obd->obd_name, transno);
930         if (transno > obd->obd_last_committed) {
931                 obd->obd_last_committed = transno;
932                 ptlrpc_commit_replies (obd);
933         }
934 }
935
936 static inline void init_obd_quota_ops(quota_interface_t *interface,
937                                       struct obd_ops *obd_ops)
938 {
939         if (!interface)
940                 return;
941
942         LASSERT(obd_ops);
943         obd_ops->o_quotacheck = QUOTA_OP(interface, check);
944         obd_ops->o_quotactl = QUOTA_OP(interface, ctl);
945 }
946
947 /* get/set_info keys */
948 #define KEY_MDS_CONN "mds_conn"
949 #define KEY_NEXT_ID  "next_id"
950 #define KEY_LOVDESC  "lovdesc"
951 #define KEY_INIT_RECOV "initial_recov"
952 #define KEY_INIT_RECOV_BACKUP "init_recov_bk"
953
954 #endif /* __OBD_H */