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