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