Whamcloud - gitweb
Backout changes made to day in efforts to make test 41 work. It passes with
[fs/lustre-release.git] / lustre / include / linux / obd.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  * This code is issued under the GNU General Public License.
7  * See the file COPYING in this distribution
8  */
9
10 #ifndef __OBD_H
11 #define __OBD_H
12
13 #define IOC_OSC_TYPE         'h'
14 #define IOC_OSC_MIN_NR       20
15 #define IOC_OSC_SET_ACTIVE   _IOWR(IOC_OSC_TYPE, 21, struct obd_device *)
16 #define IOC_OSC_CTL_RECOVERY _IOWR(IOC_OSC_TYPE, 22, struct obd_device *)
17 #define IOC_OSC_MAX_NR       50
18
19 #define IOC_MDC_TYPE         'i'
20 #define IOC_MDC_MIN_NR       20
21 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
22 /* Moved to lustre_user.h
23 #define IOC_MDC_GETSTRIPE    _IOWR(IOC_MDC_TYPE, 21, struct lov_mds_md *) */
24 #define IOC_MDC_MAX_NR       50
25
26 #ifdef __KERNEL__
27 # include <linux/fs.h>
28 # include <linux/list.h>
29 # include <linux/sched.h> /* for struct task_struct, for current.h */
30 # include <asm/current.h> /* for smp_lock.h */
31 # include <linux/smp_lock.h>
32 # include <linux/proc_fs.h>
33 # include <linux/mount.h>
34 #endif
35
36 #define OBD_MDS_DEVICENAME         "mds"
37 #define OBD_MDT_DEVICENAME         "mdt"
38 #define OBD_MDC_DEVICENAME         "mdc"
39 #define OBD_LMV_DEVICENAME         "lmv"
40 #define OBD_LOV_DEVICENAME         "lov"
41 #define OBD_OST_DEVICENAME         "ost"
42 #define OBD_OSC_DEVICENAME         "osc"
43
44 #define OBD_LDLM_DEVICENAME        "ldlm"
45 #define OBD_CACHE_DEVICENAME       "cobd"
46 #define OBD_CMOBD_DEVICENAME       "cmobd"
47 #define OBD_CONF_DEVICENAME        "confobd"
48
49 #define OBD_SANOSC_DEVICENAME      "sanosc"
50 #define OBD_SANOST_DEVICENAME      "sanost"
51
52 #define OBD_ECHO_DEVICENAME        "obdecho"
53 #define OBD_ECHO_CLIENT_DEVICENAME "echo_client"
54
55 #define OBD_FILTER_DEVICENAME      "obdfilter"
56 #define OBD_FILTER_SAN_DEVICENAME  "sanobdfilter"
57
58 #define OBD_MGMTCLI_DEVICENAME     "mgmt_cli"
59 #define OBD_PTLBD_SV_DEVICENAME    "ptlbd_server"
60 #define OBD_PTLBD_CL_DEVICENAME    "ptlbd_client"
61
62 #include <linux/lvfs.h>
63 #include <linux/lustre_lib.h>
64 #include <linux/lustre_idl.h>
65 #include <linux/lustre_export.h>
66 #include <linux/lustre_sec.h>
67
68 /* this is really local to the OSC */
69 struct loi_oap_pages {
70         struct list_head        lop_pending;
71         int                     lop_num_pending;
72         struct list_head        lop_urgent;
73         struct list_head        lop_pending_group;
74 };
75
76 struct lov_oinfo {                 /* per-stripe data structure */
77         __u64 loi_id;              /* object ID on the target OST */
78         __u64 loi_gr;              /* object group on the target OST */
79         int loi_ost_idx;           /* OST stripe index in lov_tgt_desc->tgts */
80         int loi_ost_gen;           /* generation of this loi_ost_idx */
81
82         /* used by the osc to keep track of what objects to build into rpcs */
83         struct loi_oap_pages loi_read_lop;
84         struct loi_oap_pages loi_write_lop;
85         /* _cli_ is poorly named, it should be _ready_ */
86         struct list_head loi_cli_item;
87         struct list_head loi_write_item;
88         struct list_head loi_read_item;
89
90         unsigned loi_kms_valid:1;
91         __u64 loi_kms;             /* known minimum size */
92         __u64 loi_rss;             /* recently seen size */
93         __u64 loi_mtime;           /* recently seen mtime */
94         __u64 loi_blocks;          /* recently seen blocks */
95 };
96
97 static inline void loi_init(struct lov_oinfo *loi)
98 {
99         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending);
100         INIT_LIST_HEAD(&loi->loi_read_lop.lop_urgent);
101         INIT_LIST_HEAD(&loi->loi_read_lop.lop_pending_group);
102         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending);
103         INIT_LIST_HEAD(&loi->loi_write_lop.lop_urgent);
104         INIT_LIST_HEAD(&loi->loi_write_lop.lop_pending_group);
105         INIT_LIST_HEAD(&loi->loi_cli_item);
106         INIT_LIST_HEAD(&loi->loi_write_item);
107         INIT_LIST_HEAD(&loi->loi_read_item);
108 }
109
110 struct lov_stripe_md {
111         /* Public members. */
112         __u64 lsm_object_id;        /* lov object id */
113         __u64 lsm_object_gr;        /* lov object id */
114         __u64 lsm_maxbytes;         /* maximum possible file size */
115         unsigned long lsm_xfersize; /* optimal transfer size */
116
117         /* LOV-private members start here -- only for use in lov/. */
118         __u32 lsm_magic;
119         __u32 lsm_stripe_size;      /* size of the stripe */
120         __u32 lsm_pattern;          /* striping pattern (RAID0, RAID1) */
121         unsigned lsm_stripe_count;  /* number of objects being striped over */
122         struct lov_oinfo lsm_oinfo[0];
123 };
124
125 static inline void dump_lsm(int level, struct lov_stripe_md *lsm)
126 {
127         int i;
128         CDEBUG(level, "objid "LPX64"/"LPU64", maxbytes "LPX64", magic 0x%08X, "
129                "stripe_size %u, stripe_count %u\n",
130                lsm->lsm_object_id, lsm->lsm_object_gr, lsm->lsm_maxbytes,
131                lsm->lsm_magic, lsm->lsm_stripe_size, lsm->lsm_stripe_count);
132         for (i = 0; i < lsm->lsm_stripe_count; i++)
133                 CDEBUG(level, "idx %u ostidx %u/%u object "LPU64"/"LPU64"\n",
134                        i, lsm->lsm_oinfo[i].loi_ost_idx,
135                        lsm->lsm_oinfo[i].loi_ost_gen,
136                        lsm->lsm_oinfo[i].loi_id, lsm->lsm_oinfo[i].loi_gr);
137 }
138
139 struct obd_type {
140         struct list_head typ_chain;
141         struct obd_ops *typ_ops;
142         struct md_ops *typ_md_ops;
143         struct proc_dir_entry *typ_procroot;
144         char *typ_name;
145         int  typ_refcnt;
146 };
147
148 struct brw_page {
149         obd_off disk_offset; /* modulo PAGE_SIZE */
150         obd_off page_offset; /* modulo PAGE_SIZE (obviously) */
151         struct page *pg;
152         int count;
153         obd_flags flag;
154 };
155
156 enum async_flags {
157         ASYNC_READY = 0x1, /* ap_make_ready will not be called before this
158                               page is added to an rpc */
159         ASYNC_URGENT = 0x2,
160         ASYNC_COUNT_STABLE = 0x4, /* ap_refresh_count will not be called
161                                      to give the caller a chance to update
162                                      or cancel the size of the io */
163         ASYNC_GROUP_SYNC = 0x8,  /* ap_completion will not be called, instead
164                                     the page is accounted for in the
165                                     obd_io_group given to 
166                                     obd_queue_group_io */
167 };
168
169 struct obd_async_page_ops {
170         int  (*ap_make_ready)(void *data, int cmd);
171         int  (*ap_refresh_count)(void *data, int cmd);
172         void (*ap_fill_obdo)(void *data, int cmd, struct obdo *oa);
173         void (*ap_completion)(void *data, int cmd, struct obdo *oa, int rc);
174 };
175
176 /* the `oig' is passed down from a caller of obd rw methods.  the callee
177  * records enough state such that the caller can sleep on the oig and
178  * be woken when all the callees have finished their work */
179 struct obd_io_group {
180         spinlock_t      oig_lock;
181         atomic_t        oig_refcount;
182         int             oig_pending;
183         int             oig_rc;
184         struct list_head oig_occ_list;
185         wait_queue_head_t oig_waitq;
186 };
187
188 /* the oig callback context lets the callee of obd rw methods register
189  * for callbacks from the caller. */
190 struct oig_callback_context {
191         struct list_head occ_oig_item;
192         /* called when the caller has received a signal while sleeping.
193          * callees of this method are encouraged to abort their state 
194          * in the oig.  This may be called multiple times. */
195         void (*occ_interrupted)(struct oig_callback_context *occ);
196         int interrupted;
197 };
198
199 /* if we find more consumers this could be generalized */
200 #define OBD_HIST_MAX 32
201 struct obd_histogram {
202         spinlock_t      oh_lock;
203         unsigned long   oh_buckets[OBD_HIST_MAX];
204 };
205
206 /* reports average service time with the help of lprocfs_status.c */
207 struct obd_service_time {
208         __u32           st_num;
209         __u64           st_total_us;
210 };
211
212 struct ost_server_data;
213
214 #define FILTER_SUBDIR_COUNT      32            /* set to zero for no subdirs */
215
216 #define FILTER_GROUP_LLOG 1
217 #define FILTER_GROUP_ECHO 2
218 #define FILTER_GROUP_FIRST_MDS 3
219
220 struct filter_subdirs {
221         struct dentry *dentry[FILTER_SUBDIR_COUNT];
222 };
223
224 struct filter_group_llog {
225         struct list_head list;
226         int group;
227         struct obd_llogs *llogs;
228         struct obd_export *exp;
229 };
230
231 struct filter_obd {
232         const char          *fo_fstype;
233         struct super_block  *fo_sb;
234         struct vfsmount     *fo_vfsmnt;
235         struct lvfs_obd_ctxt *fo_lvfs_ctxt;
236
237         int                    fo_group_count;
238         struct dentry         *fo_dentry_O;     /* the "O"bject directory dentry */
239         struct dentry         **fo_groups;      /* dentries for each group dir */
240         struct filter_subdirs *fo_subdirs;      /* subdir array per group */
241         __u64                 *fo_last_objids;  /* per-group last created objid */
242         struct file          **fo_last_objid_files;
243         struct semaphore     fo_init_lock;      /* group initialization lock */
244         int                  fo_committed_group;
245
246         spinlock_t           fo_objidlock;      /* protect fo_lastobjid increment */
247         spinlock_t           fo_lastidlock;     /* protect last_id increment */
248         spinlock_t           fo_translock;      /* protect fsd_last_rcvd increment */
249         struct file         *fo_rcvd_filp;
250         struct filter_server_data *fo_fsd;
251         unsigned long       *fo_last_rcvd_slots;
252         __u64                fo_mount_count;
253
254         unsigned long        fo_destroys_in_progress;
255         struct semaphore     fo_create_locks[32];
256
257         struct file_operations *fo_fop;
258         struct inode_operations *fo_iop;
259         struct address_space_operations *fo_aops;
260
261         struct list_head     fo_export_list;
262         int                  fo_subdir_count;
263
264         obd_size             fo_tot_dirty;      /* protected by obd_osfs_lock */
265         obd_size             fo_tot_granted;    /* all values in bytes */
266         obd_size             fo_tot_pending;
267
268         obd_size             fo_readcache_max_filesize;
269
270         struct obd_import   *fo_mdc_imp;
271         struct obd_uuid      fo_mdc_uuid;
272         struct lustre_handle fo_mdc_conn;
273
274         struct semaphore     fo_alloc_lock;
275
276         struct obd_histogram     fo_r_pages;
277         struct obd_histogram     fo_w_pages;
278         struct obd_histogram     fo_r_discont_pages;
279         struct obd_histogram     fo_w_discont_pages;
280         struct obd_histogram     fo_r_discont_blocks;
281         struct obd_histogram     fo_w_discont_blocks;
282
283         struct list_head         fo_llog_list;
284         spinlock_t               fo_llog_list_lock;
285
286         /* which secure flavor from remote is denied */
287         spinlock_t               fo_denylist_lock;
288         struct list_head         fo_denylist;
289
290         /* capability related */
291         int                      fo_capa_stat;
292         spinlock_t               fo_capa_lock;
293
294         struct list_head         fo_capa_keys;
295 };
296
297 struct mds_server_data;
298
299 #define OSC_MAX_RIF_DEFAULT      8
300 #define OSC_MAX_RIF_MAX          64
301 #define OSC_MAX_DIRTY_DEFAULT    (4*OSC_MAX_RIF_DEFAULT*PTLRPC_MAX_BRW_SIZE>>20)
302 #define OSC_MAX_DIRTY_MB_MAX     512     /* totally arbitrary */
303
304 struct mdc_rpc_lock;
305 struct client_obd {
306         struct obd_import       *cl_import;
307         struct semaphore         cl_sem;
308         int                      cl_conn_count;
309         /* max_mds_easize is purely a performance thing so we don't have to
310          * call obd_size_wiremd() all the time. */
311         int                      cl_max_mds_easize;
312         int                      cl_max_mds_cookiesize;
313         kdev_t                   cl_sandev;
314
315         /* security flavors */
316         __u32                    cl_sec_flavor;
317         unsigned long            cl_sec_flags;
318
319         //struct llog_canceld_ctxt *cl_llcd; /* it's included by obd_llog_ctxt */
320         void                    *cl_llcd_offset;
321
322         struct obd_device       *cl_mgmtcli_obd;
323
324         /* the grant values are protected by loi_list_lock below */
325         long                     cl_dirty;         /* all _dirty_ in bytes */
326         long                     cl_dirty_max;     /* allowed w/o rpc */
327         long                     cl_avail_grant;   /* bytes of credit for ost */
328         long                     cl_lost_grant;    /* lost credits (trunc) */
329         struct list_head         cl_cache_waiters; /* waiting for cache/grant */
330
331         /* keep track of objects that have lois that contain pages which
332          * have been queued for async brw.  this lock also protects the
333          * lists of osc_client_pages that hang off of the loi */
334         spinlock_t               cl_loi_list_lock;
335         struct list_head         cl_loi_ready_list;
336         struct list_head         cl_loi_write_list;
337         struct list_head         cl_loi_read_list;
338         int                      cl_r_in_flight;
339         int                      cl_w_in_flight;
340         /* just a sum of the loi/lop pending numbers to be exported by /proc */
341         int                      cl_pending_w_pages;
342         int                      cl_pending_r_pages;
343         int                      cl_max_pages_per_rpc;
344         int                      cl_max_rpcs_in_flight;
345         struct obd_histogram     cl_read_rpc_hist;
346         struct obd_histogram     cl_write_rpc_hist;
347         struct obd_histogram     cl_read_page_hist;
348         struct obd_histogram     cl_write_page_hist;
349         struct obd_service_time  cl_read_stime;
350         struct obd_service_time  cl_write_stime;
351         struct obd_service_time  cl_enter_stime;
352
353         struct mdc_rpc_lock     *cl_rpc_lock;
354         struct mdc_rpc_lock     *cl_setattr_lock; 
355         struct mdc_rpc_lock     *cl_close_lock;
356         struct osc_creator       cl_oscc;
357         int                      cl_async:1;
358
359         /* debug stuff */
360         struct timeval           cl_last_write_time;
361         unsigned long            cl_write_gap_sum;
362         unsigned long            cl_write_gaps;
363         unsigned long            cl_write_num;
364         unsigned long            cl_read_num;
365         unsigned long            cl_cache_wait_num;
366         unsigned long            cl_cache_wait_sum;
367
368         unsigned long            cl_dirty_num;
369         unsigned long            cl_dirty_sum;
370         unsigned long            cl_dirty_av;
371         
372         unsigned long            cl_dirty_dmax;
373         unsigned long            cl_dirty_dmin;
374
375         unsigned long            cl_sync_rpcs;
376 };
377
378 /* Like a client, with some hangers-on.  Keep mc_client_obd first so that we
379  * can reuse the various client setup/connect functions. */
380 struct mgmtcli_obd {
381         struct client_obd        mc_client_obd; /* nested */
382         struct ptlrpc_thread    *mc_ping_thread;
383         struct obd_export       *mc_ping_exp; /* XXX single-target */
384         struct list_head         mc_registered;
385         void                    *mc_hammer;
386 };
387
388 #define mc_import mc_client_obd.cl_import
389
390 struct mds_obd {
391         struct ptlrpc_service           *mds_service;
392         struct ptlrpc_service           *mds_setattr_service;
393         struct ptlrpc_service           *mds_readpage_service;
394         struct ptlrpc_service           *mds_close_service;
395         struct super_block              *mds_sb;
396         struct vfsmount                 *mds_vfsmnt;
397         struct dentry                   *mds_id_de;
398         struct lvfs_obd_ctxt            *mds_lvfs_ctxt;
399         int                              mds_max_mdsize;
400         int                              mds_max_cookiesize;
401         struct file                     *mds_rcvd_filp;
402         struct file                     *mds_fid_filp;
403         struct file                     *mds_virtid_filp;
404         spinlock_t                       mds_transno_lock;
405         __u64                            mds_last_transno;
406         __u64                            mds_mount_count;
407         __u64                            mds_io_epoch;
408         
409         __u64                            mds_last_fid;
410         __u64                            mds_virtid_fid;
411         spinlock_t                       mds_last_fid_lock;
412         
413         struct semaphore                 mds_epoch_sem;
414         struct lustre_id                 mds_rootid;
415         struct mds_server_data          *mds_server_data;
416         struct dentry                   *mds_pending_dir;
417         struct dentry                   *mds_logs_dir;
418         struct dentry                   *mds_objects_dir;
419         struct llog_handle              *mds_cfg_llh;
420         char                            *mds_profile;
421         struct obd_device               *mds_dt_obd;
422         struct obd_uuid                  mds_dt_uuid;
423         struct obd_export               *mds_dt_exp;
424         int                              mds_has_dt_desc;
425         struct lov_desc                  mds_dt_desc;
426
427         spinlock_t                       mds_dt_lock;
428         obd_id                          *mds_dt_objids;
429         struct file                     *mds_dt_objid_filp;
430         int                              mds_dt_objids_valid;
431
432         unsigned long                   *mds_client_bitmap;
433         struct semaphore                 mds_orphan_recovery_sem;
434         
435         int                              mds_num;
436         int                              mds_config_version;
437
438         char                            *mds_md_name;
439         struct obd_device               *mds_md_obd;
440         struct obd_export               *mds_md_exp;
441         struct semaphore                 mds_md_sem;
442         struct obd_uuid                  mds_md_uuid;
443         int                              mds_md_connected;
444
445         struct ptlrpc_service           *mds_create_service;
446         uid_t                            mds_squash_uid;
447         gid_t                            mds_squash_gid;
448         ptl_nid_t                        mds_nosquash_nid;
449         atomic_t                         mds_real_clients;
450         atomic_t                         mds_open_count;
451         struct dentry                   *mds_id_dir;
452         int                              mds_obd_type;
453         struct dentry                   *mds_unnamed_dir; /* for mdt_obd_create only */
454
455         /* security related */
456         char                            *mds_mds_sec;
457         char                            *mds_ost_sec;
458
459         /* which secure flavor from remote to this mds is denied */
460         spinlock_t                      mds_denylist_lock;
461         struct list_head                mds_denylist;
462
463         /* fid->ino mapping related fields */
464         spinlock_t                      mds_fidmap_lock;
465         struct hlist_head              *mds_fidmap_table;
466         unsigned long                   mds_fidmap_size;
467
468         /* cache fid extents stuff */
469         spinlock_t                      mds_fidext_lock;
470         __u64                           mds_fidext_thumb;
471         int                             mds_crypto_type;
472
473         /* capability related */
474         int                              mds_capa_stat;     /* 1: on, 0: off */
475         unsigned long                    mds_capa_timeout;  /* sec */
476
477         struct mds_capa_key              mds_capa_keys[2];  /* red & black key */
478         int                              mds_capa_key_idx;  /* the red key index */
479         struct file                     *mds_capa_keys_filp;
480         unsigned long                    mds_capa_key_timeout; /* sec */
481 };
482
483 struct echo_obd {
484         struct obdo          eo_oa;
485         spinlock_t           eo_lock;
486         __u64                eo_lastino;
487         struct lustre_handle eo_nl_lock;
488         atomic_t             eo_prep;
489 };
490
491 /*
492  * this struct does double-duty acting as either a client or
493  * server instance .. maybe not wise.
494  */
495 struct ptlbd_obd {
496         /* server's */
497         struct ptlrpc_service *ptlbd_service;
498         struct file *filp;
499         /* client's */
500         struct ptlrpc_client    bd_client;
501         struct obd_import       *bd_import;
502         struct obd_uuid         bd_server_uuid;
503         struct obd_export       *bd_exp;
504         int refcount; /* XXX sigh */
505 };
506
507 struct recovd_obd {
508         spinlock_t            recovd_lock;
509         struct list_head      recovd_managed_items; /* items managed  */
510         struct list_head      recovd_troubled_items; /* items in recovery */
511
512         wait_queue_head_t     recovd_recovery_waitq;
513         wait_queue_head_t     recovd_ctl_waitq;
514         wait_queue_head_t     recovd_waitq;
515         struct task_struct   *recovd_thread;
516         __u32                 recovd_state;
517 };
518
519 struct ost_obd {
520         spinlock_t             ost_lock;
521         struct ptlrpc_service *ost_service;
522         struct ptlrpc_service *ost_create_service;
523         struct ptlrpc_service *ost_destroy_service;
524         struct obd_service_time ost_stimes[6];
525 };
526
527 struct echo_client_obd {
528         struct obd_export      *ec_exp;     /* the local connection to osc/lov */
529         spinlock_t              ec_lock;
530         struct list_head        ec_objects;
531         int                     ec_nstripes;
532         __u64                   ec_unique;
533 };
534
535 struct cache_obd {
536         struct obd_export      *master_exp; /* local connection to master obd */
537         struct obd_export      *cache_exp;  /* local connection to cache obd */
538         struct obd_export      *cache_real_exp;
539         struct obd_export      *master_real_exp;
540         struct obd_device      *master;
541         struct obd_device      *cache;
542         char                   *master_name;
543         char                   *cache_name;
544         int                     refcount;
545         int                     cache_on;
546         struct semaphore        sem;
547         struct lov_desc         dt_desc; /* data lovdesc */
548 };
549
550 struct cm_obd {
551         struct obd_export      *cache_exp;  /* local connection to cache obd */
552         struct obd_export      *master_exp;
553         struct obd_device      *cache_obd;
554         struct obd_device      *master_obd;
555         int                     master_group;
556         struct cmobd_write_service *write_srv;
557         struct lov_desc         master_desc; /* master device lovdesc */
558 };
559
560 struct conf_obd {
561         struct super_block      *cfobd_sb;
562         struct vfsmount         *cfobd_vfsmnt;
563         struct dentry           *cfobd_logs_dir;
564         struct dentry           *cfobd_objects_dir;
565         struct dentry           *cfobd_pending_dir;
566         struct llog_handle      *cfobd_cfg_llh;
567         struct lvfs_obd_ctxt    *cfobd_lvfs_ctxt;
568 };
569
570 enum lov_tgt_flags {
571         LTD_ACTIVE      = 0x1, /* is this target up for requests   */
572         LTD_DEL_PENDING = 0x2, /* delete event pending for this tgt */
573 };
574
575 struct lov_tgt_desc {
576         struct obd_uuid         uuid;
577         __u32                   ltd_gen;
578         struct obd_export      *ltd_exp;
579         unsigned int            ltd_flags;
580         int                     ltd_refcount;
581 };
582
583 struct lov_obd {
584         spinlock_t              lov_lock;
585         struct lov_desc         desc;
586         int                     bufsize;
587         int                     refcount;
588         int                     lo_catalog_loaded:1, async:1;
589         struct semaphore        lov_llog_sem;
590         unsigned long           lov_connect_flags;
591         wait_queue_head_t       lov_tgt_waitq;
592         struct lov_tgt_desc    *tgts;
593 };
594
595 struct lmv_tgt_desc {
596         struct obd_uuid         uuid;
597         struct obd_export      *ltd_exp;
598         int                     active;   /* is this target up for requests */
599 };
600
601 struct lmv_obd {
602         int                     refcount;
603         spinlock_t              lmv_lock;
604         struct lmv_desc         desc;
605         struct lmv_tgt_desc     *tgts;
606         struct obd_uuid         cluuid;
607         struct obd_export       *exp;
608
609         int                     tgts_size;
610         int                     connected;
611         int                     max_easize;
612         int                     max_cookiesize;
613         int                     server_timeout;
614         int                     connect_flags;
615         struct semaphore        init_sem;
616         struct obd_connect_data conn_data;
617 };
618 struct gks_crypto_key {
619         char *key;
620         int   len; 
621 };
622 struct gks_obd {
623         struct ptlrpc_service    *gks_service;
624         struct crypto_tfm        *gks_mac_tfm;       
625         struct crypto_tfm        *gks_key_tfm;
626         struct gks_crypto_key    gks_key;
627 };
628
629 struct niobuf_local {
630         __u64 offset;
631         __u32 len;
632         __u32 flags;
633         struct page *page;
634         struct dentry *dentry;
635         int lnb_grant_used;
636         int rc;
637 };
638
639 #define OBD_MODE_ASYNC (1 << 0)
640 #define OBD_MODE_CROW  (1 << 1)
641
642 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
643 #define N_LOCAL_TEMP_PAGE 0x10000000
644
645 struct obd_trans_info {
646         __u64                    oti_transno;
647         __u64                   *oti_objid;
648
649         /* only used on the server side for tracking acks. */
650         struct oti_req_ack_lock {
651                 struct lustre_handle lock;
652                 __u32                mode;
653         }                        oti_ack_locks[4];
654         void                    *oti_handle;
655         struct llog_cookie       oti_onecookie;
656         struct llog_cookie      *oti_logcookies;
657         int                      oti_numcookies;
658         int                      oti_flags;
659         /* save nid for security purposes like audit */
660         __u64                    oti_nid; 
661 };
662
663 static inline void oti_alloc_cookies(struct obd_trans_info *oti,int num_cookies)
664 {
665         if (!oti)
666                 return;
667
668         if (num_cookies == 1)
669                 oti->oti_logcookies = &oti->oti_onecookie;
670         else
671                 OBD_ALLOC(oti->oti_logcookies,
672                           num_cookies * sizeof(oti->oti_onecookie));
673
674         oti->oti_numcookies = num_cookies;
675 }
676
677 static inline void oti_free_cookies(struct obd_trans_info *oti)
678 {
679         if (!oti || !oti->oti_logcookies)
680                 return;
681
682         if (oti->oti_logcookies == &oti->oti_onecookie)
683                 LASSERT(oti->oti_numcookies == 1);
684         else
685                 OBD_FREE(oti->oti_logcookies,
686                          oti->oti_numcookies * sizeof(oti->oti_onecookie));
687         oti->oti_logcookies = NULL;
688         oti->oti_numcookies = 0;
689 }
690
691 /* llog contexts */
692 enum llog_ctxt_id {
693         LLOG_CONFIG_ORIG_CTXT =  0,
694         LLOG_CONFIG_REPL_CTXT =  1,
695         LLOG_UNLINK_ORIG_CTXT =  2,
696         LLOG_UNLINK_REPL_CTXT =  3,
697         LLOG_SIZE_ORIG_CTXT   =  4,
698         LLOG_SIZE_REPL_CTXT   =  5,
699         LLOG_MD_ORIG_CTXT     =  6,
700         LLOG_MD_REPL_CTXT     =  7,
701         LLOG_RD1_ORIG_CTXT    =  8,
702         LLOG_RD1_REPL_CTXT    =  9,
703         LLOG_TEST_ORIG_CTXT   = 10,
704         LLOG_TEST_REPL_CTXT   = 11,
705         LLOG_REINT_ORIG_CTXT  = 12,
706         LLOG_AUDIT_ORIG_CTXT  = 13,
707         LLOG_MAX_CTXTS
708 };
709
710 struct obd_llogs {
711         struct llog_ctxt        *llog_ctxt[LLOG_MAX_CTXTS];
712 };
713
714 struct target_recovery_data {
715         svc_handler_t     trd_recovery_handler;
716         pid_t             trd_processing_task;
717         struct completion trd_starting;
718         struct completion trd_finishing;
719 };
720
721 /* corresponds to one of the obd's */
722 struct obd_device {
723         struct obd_type *obd_type;
724
725         /* common and UUID name of this device */
726         char *obd_name;
727         struct obd_uuid obd_uuid;
728
729         int obd_minor;
730         unsigned int obd_attached:1, obd_set_up:1, obd_recovering:1,
731                 obd_abort_recovery:1, obd_replayable:1, obd_no_transno:1,
732                 obd_no_recov:1, obd_stopping:1, obd_req_replaying:1;
733         atomic_t obd_refcount;
734         wait_queue_head_t obd_refcount_waitq;
735         struct proc_dir_entry *obd_proc_entry;
736         struct list_head       obd_exports;
737         int                    obd_num_exports;
738         struct ldlm_namespace *obd_namespace;
739         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
740         /* a spinlock is OK for what we do now, may need a semaphore later */
741         spinlock_t             obd_dev_lock;
742         __u64                  obd_last_committed;
743         struct fsfilt_operations *obd_fsops;
744         spinlock_t              obd_osfs_lock;
745         struct obd_statfs       obd_osfs;
746         unsigned long           obd_osfs_age;
747         struct lvfs_run_ctxt    obd_lvfs_ctxt;
748         struct obd_llogs        obd_llogs;
749         struct llog_ctxt        *obd_llog_ctxt[LLOG_MAX_CTXTS];
750         struct obd_device       *obd_observer;
751         struct obd_export       *obd_self_export;
752
753         struct target_recovery_data      obd_recovery_data;
754         /* XXX encapsulate all this recovery data into target_recovery_data */
755         int                              obd_max_recoverable_clients;
756         int                              obd_connected_clients;
757         int                              obd_recoverable_clients;
758         spinlock_t                       obd_processing_task_lock;
759         __u64                            obd_next_recovery_transno;
760         int                              obd_replayed_requests;
761         int                              obd_replayed_locks;
762         int                              obd_requests_queued_for_recovery;
763         wait_queue_head_t                obd_next_transno_waitq;
764         struct list_head                 obd_uncommitted_replies;
765         spinlock_t                       obd_uncommitted_replies_lock;
766         struct timer_list                obd_recovery_timer;
767         time_t                           obd_recovery_start;
768         time_t                           obd_recovery_end;
769
770         atomic_t                         obd_req_replay_clients;
771         atomic_t                         obd_lock_replay_clients;
772
773         struct list_head                 obd_req_replay_queue;
774         struct list_head                 obd_lock_replay_queue;
775         struct list_head                 obd_final_req_queue;
776         int                              obd_recovery_stage;
777
778         union {
779                 struct filter_obd        filter;
780                 struct mds_obd           mds;
781                 struct client_obd        cli;
782                 struct ost_obd           ost;
783                 struct echo_client_obd   echocli;
784                 struct echo_obd          echo;
785                 struct recovd_obd        recovd;
786                 struct lov_obd           lov;
787                 struct cache_obd         cobd;
788                 struct ptlbd_obd         ptlbd;
789                 struct mgmtcli_obd       mgmtcli;
790                 struct lmv_obd           lmv;
791                 struct cm_obd            cm;
792                 struct conf_obd          conf;
793                 struct gks_obd           gks;
794         } u;
795         
796         /* fields used by LProcFS */
797         unsigned int           obd_cntr_base;
798         struct lprocfs_stats  *obd_stats;
799         unsigned int           md_cntr_base;
800         struct lprocfs_stats  *md_stats;
801
802         struct proc_dir_entry *obd_svc_procroot;
803         struct lprocfs_stats  *obd_svc_stats;
804 };
805
806 #define OBD_OPT_FORCE             (1 << 0)
807 #define OBD_OPT_FAILOVER          (1 << 1)
808 #define OBD_OPT_REAL_CLIENT       (1 << 2)
809 #define OBD_OPT_MDS_CONNECTION    (1 << 3)
810
811 #define OBD_LLOG_FL_SENDNOW       (1 << 0)
812 #define OBD_LLOG_FL_CREATE        (1 << 1)
813
814 struct mdc_op_data;
815
816 struct obd_ops {
817         struct module *o_owner;
818         int (*o_iocontrol)(unsigned int cmd, struct obd_export *exp, int len,
819                            void *karg, void *uarg);
820         int (*o_get_info)(struct obd_export *, __u32 keylen, void *key,
821                           __u32 *vallen, void *val);
822         int (*o_set_info)(struct obd_export *, __u32 keylen, void *key,
823                           __u32 vallen, void *val);
824         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
825         int (*o_detach)(struct obd_device *dev);
826         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
827         int (*o_precleanup)(struct obd_device *dev, int flags);
828         int (*o_cleanup)(struct obd_device *dev, int flags);
829         int (*o_process_config)(struct obd_device *dev, obd_count len,
830                                 void *data);
831         int (*o_postrecov)(struct obd_device *dev);
832         int (*o_add_conn)(struct obd_import *imp, struct obd_uuid *uuid,
833                           int priority);
834         int (*o_del_conn)(struct obd_import *imp, struct obd_uuid *uuid);
835         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
836                          struct obd_uuid *cluuid, struct obd_connect_data *data,
837                          unsigned long flags);
838         int (*o_connect_post)(struct obd_export *exp, unsigned, unsigned long);
839         int (*o_disconnect)(struct obd_export *exp, unsigned long flags);
840
841         int (*o_statfs)(struct obd_device *obd, struct obd_statfs *osfs,
842                         unsigned long max_age);
843         int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
844                         struct lov_stripe_md *mem_src);
845         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
846                           struct lov_mds_md *disk_src, int disk_len);
847         int (*o_revalidate_md)(struct obd_export *exp,  struct obdo *oa,
848                                struct lov_stripe_md *ea,
849                                struct obd_trans_info *oti);
850         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
851                              obd_id *ids);
852         int (*o_create)(struct obd_export *exp,  struct obdo *oa,
853                         void *acl, int acl_size,
854                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
855         int (*o_destroy)(struct obd_export *exp, struct obdo *oa,
856                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
857         int (*o_setattr)(struct obd_export *exp, struct obdo *oa,
858                          struct lov_stripe_md *ea, struct obd_trans_info *oti,
859                          struct lustre_capa *capa);
860         int (*o_getattr)(struct obd_export *exp, struct obdo *oa,
861                          struct lov_stripe_md *ea);
862         int (*o_getattr_async)(struct obd_export *exp, struct obdo *oa,
863                                struct lov_stripe_md *ea,
864                                struct ptlrpc_request_set *set);
865         int (*o_brw)(int rw, struct obd_export *exp, struct obdo *oa,
866                      struct lov_stripe_md *ea, obd_count oa_bufs,
867                      struct brw_page *pgarr, struct obd_trans_info *oti);
868         int (*o_brw_async)(int rw, struct obd_export *exp, struct obdo *oa,
869                            struct lov_stripe_md *ea, obd_count oa_bufs,
870                            struct brw_page *pgarr, struct ptlrpc_request_set *,
871                            struct obd_trans_info *oti);
872         int (*o_prep_async_page)(struct obd_export *exp, 
873                                  struct lov_stripe_md *lsm,
874                                  struct lov_oinfo *loi, 
875                                  struct page *page, obd_off offset, 
876                                  struct obd_async_page_ops *ops, void *data,
877                                  void **res);
878         int (*o_queue_async_io)(struct obd_export *exp, 
879                                 struct lov_stripe_md *lsm, 
880                                 struct lov_oinfo *loi, void *cookie, 
881                                 int cmd, obd_off off, int count, 
882                                 obd_flags brw_flags, obd_flags async_flags);
883         int (*o_queue_group_io)(struct obd_export *exp, 
884                                 struct lov_stripe_md *lsm, 
885                                 struct lov_oinfo *loi, 
886                                 struct obd_io_group *oig, 
887                                 void *cookie, int cmd, obd_off off, int count, 
888                                 obd_flags brw_flags, obd_flags async_flags);
889         int (*o_trigger_group_io)(struct obd_export *exp, 
890                                   struct lov_stripe_md *lsm, 
891                                   struct lov_oinfo *loi, 
892                                   struct obd_io_group *oig);
893         int (*o_set_async_flags)(struct obd_export *exp,
894                                 struct lov_stripe_md *lsm,
895                                 struct lov_oinfo *loi, void *cookie,
896                                 obd_flags async_flags);
897         int (*o_teardown_async_page)(struct obd_export *exp,
898                                      struct lov_stripe_md *lsm,
899                                      struct lov_oinfo *loi, void *cookie);
900         int (*o_adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm,
901                             obd_off size, int shrink);
902         int (*o_punch)(struct obd_export *exp, struct obdo *oa,
903                        struct lov_stripe_md *ea, obd_size start,
904                        obd_size end, struct obd_trans_info *oti,
905                        struct lustre_capa *capa);
906         int (*o_sync)(struct obd_export *exp, struct obdo *oa,
907                       struct lov_stripe_md *ea, obd_size start, obd_size end);
908         int (*o_migrate)(struct lustre_handle *conn, struct lov_stripe_md *dst,
909                          struct lov_stripe_md *src, obd_size start,
910                          obd_size end, struct obd_trans_info *oti);
911         int (*o_copy)(struct lustre_handle *dstconn, struct lov_stripe_md *dst,
912                       struct lustre_handle *srconn, struct lov_stripe_md *src,
913                       obd_size start, obd_size end, struct obd_trans_info *);
914         int (*o_iterate)(struct lustre_handle *conn,
915                          int (*)(obd_id, obd_gr, void *),
916                          obd_id *startid, obd_gr group, void *data);
917         int (*o_preprw)(int cmd, struct obd_export *exp, struct obdo *oa,
918                         int objcount, struct obd_ioobj *obj,
919                         int niocount, struct niobuf_remote *remote,
920                         struct niobuf_local *local, struct obd_trans_info *oti,
921                         struct lustre_capa *capa);
922         int (*o_commitrw)(int cmd, struct obd_export *exp, struct obdo *oa,
923                           int objcount, struct obd_ioobj *obj,
924                           int niocount, struct niobuf_local *local,
925                           struct obd_trans_info *oti, int rc);
926         int (*o_do_cow)(struct obd_export *exp, struct obd_ioobj *obj, 
927                         int objcount, struct niobuf_remote *rnb);
928         int (*o_write_extents)(struct obd_export *exp, struct obd_ioobj *obj,
929                                int objcount, int niocount, 
930                                struct niobuf_local *local,int rc);
931         int (*o_enqueue)(struct obd_export *, struct lov_stripe_md *,
932                          __u32 type, ldlm_policy_data_t *, __u32 mode,
933                          int *flags, void *bl_cb, void *cp_cb, void *gl_cb,
934                          void *data, __u32 lvb_len, void *lvb_swabber,
935                          struct lustre_handle *lockh);
936         int (*o_match)(struct obd_export *, struct lov_stripe_md *, __u32 type,
937                        ldlm_policy_data_t *, __u32 mode, int *flags, void *data,
938                        struct lustre_handle *lockh);
939         int (*o_change_cbdata)(struct obd_export *, struct lov_stripe_md *,
940                                ldlm_iterator_t it, void *data);
941         int (*o_cancel)(struct obd_export *, struct lov_stripe_md *md,
942                         __u32 mode, struct lustre_handle *);
943         int (*o_cancel_unused)(struct obd_export *, struct lov_stripe_md *,
944                                int flags, void *opaque);
945         int (*o_san_preprw)(int cmd, struct obd_export *exp,
946                             struct obdo *oa, int objcount,
947                             struct obd_ioobj *obj, int niocount,
948                             struct niobuf_remote *remote);
949         int (*o_init_export)(struct obd_export *exp);
950         int (*o_destroy_export)(struct obd_export *exp);
951
952         /* llog related obd_methods */
953         int (*o_llog_init)(struct obd_device *, struct obd_llogs *,
954                            struct obd_device *, int, struct llog_catid *);
955         int (*o_llog_finish)(struct obd_device *, struct obd_llogs *, int);
956         int (*o_llog_connect)(struct obd_export *, struct llogd_conn_body *);
957
958        
959         /* metadata-only methods */
960         int (*o_pin)(struct obd_export *, obd_id ino, __u32 gen, int type,
961                      struct obd_client_handle *, int flag);
962         int (*o_unpin)(struct obd_export *, struct obd_client_handle *, int);
963
964         int (*o_import_event)(struct obd_device *, struct obd_import *,
965                               enum obd_import_event);
966
967         int (*o_notify)(struct obd_device *obd, struct obd_device *watched,
968                         int active, void *data);
969
970         int (*o_init_ea_size)(struct obd_export *, int, int);
971
972         /* 
973          * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line
974          * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c.
975          * Also, add a wrapper function in include/linux/obd_class.h.
976          */
977 };
978
979 struct md_ops {
980         int (*m_getstatus)(struct obd_export *, struct lustre_id *);
981         int (*m_change_cbdata)(struct obd_export *, struct lustre_id *,
982                                ldlm_iterator_t, void *);
983         int (*m_change_cbdata_name)(struct obd_export *, struct lustre_id *,
984                                     char *, int, struct lustre_id *,
985                                     ldlm_iterator_t, void *);
986         int (*m_close)(struct obd_export *, struct mdc_op_data *,
987                        struct obd_client_handle *, struct ptlrpc_request **);
988         int (*m_create)(struct obd_export *, struct mdc_op_data *,
989                         const void *, int, int, __u32, __u32,
990                         __u64, struct ptlrpc_request **);
991         int (*m_done_writing)(struct obd_export *, struct obdo *);
992         int (*m_enqueue)(struct obd_export *, int, struct lookup_intent *,
993                          int, struct mdc_op_data *, struct lustre_handle *,
994                          void *, int, ldlm_completion_callback,
995                          ldlm_blocking_callback, void *);
996         int (*m_getattr)(struct obd_export *, struct lustre_id *,
997                          __u64, const char *, const void *, unsigned int,
998                          unsigned int, struct obd_capa *,
999                          struct ptlrpc_request **);
1000         int (*m_access_check)(struct obd_export *, struct lustre_id *,
1001                               struct ptlrpc_request **);
1002         int (*m_getattr_lock)(struct obd_export *, struct lustre_id *,
1003                               char *, int, __u64,
1004                               unsigned int, struct ptlrpc_request **);
1005         int (*m_intent_lock)(struct obd_export *,
1006                              struct lustre_id *, const char *, int,
1007                              void *, int, struct lustre_id *,
1008                              struct lookup_intent *, int,
1009                              struct ptlrpc_request **,
1010                              ldlm_blocking_callback);
1011         int (*m_link)(struct obd_export *, struct mdc_op_data *,
1012                       struct ptlrpc_request **);
1013         int (*m_rename)(struct obd_export *, struct mdc_op_data *,
1014                         const char *, int, const char *, int,
1015                         struct ptlrpc_request **);
1016         int (*m_setattr)(struct obd_export *, struct mdc_op_data *,
1017                          struct iattr *, void *, int , void *, int,
1018                          void *, int, struct ptlrpc_request **);
1019         int (*m_sync)(struct obd_export *, struct lustre_id *,
1020                       struct ptlrpc_request **);
1021         int (*m_readpage)(struct obd_export *, struct lustre_id *,
1022                           __u64, struct page *, struct ptlrpc_request **);
1023         int (*m_unlink)(struct obd_export *, struct mdc_op_data *,
1024                         struct ptlrpc_request **);
1025         int (*m_valid_attrs)(struct obd_export *, struct lustre_id *);
1026         
1027         struct obd_device *(*m_get_real_obd)(struct obd_export *, struct lustre_id *);
1028         
1029         int (*m_req2lustre_md)(struct obd_export *exp, 
1030                                struct ptlrpc_request *req, unsigned int offset,
1031                                struct obd_export *osc_exp, struct lustre_md *md);
1032         int (*m_set_open_replay_data)(struct obd_export *exp,
1033                                       struct obd_client_handle *och,
1034                                       struct ptlrpc_request *open_req);
1035         int (*m_clear_open_replay_data)(struct obd_export *exp,
1036                                         struct obd_client_handle *och);
1037         int (*m_store_inode_generation)(struct obd_export *exp, 
1038                                         struct ptlrpc_request *req, int reqoff,
1039                                         int repoff);
1040         int (*m_set_lock_data)(struct obd_export *exp, __u64 *l, void *data);
1041
1042         int (*m_delete_inode)(struct obd_export *, struct lustre_id *);
1043
1044         /*
1045          * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to
1046          * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
1047          * wrapper function in include/linux/obd_class.h.
1048          */
1049 };
1050
1051 static inline void obd_transno_commit_cb(struct obd_device *obd,
1052                                          __u64 transno, int error)
1053 {
1054         if (error) {
1055                 CERROR("%s: transno "LPD64" commit error: %d\n",
1056                        obd->obd_name, transno, error);
1057                 return;
1058         }
1059         
1060         CDEBUG(D_HA, "%s: transno "LPD64" committed\n",
1061                obd->obd_name, transno);
1062
1063         if (transno > obd->obd_last_committed) {
1064                 obd->obd_last_committed = transno;
1065                 ptlrpc_commit_replies (obd);
1066         }
1067 }
1068
1069 static inline int obd_md_type(struct obd_device *obd)
1070 {
1071         if (!strcmp(obd->obd_type->typ_name, OBD_MDC_DEVICENAME) ||
1072             !strcmp(obd->obd_type->typ_name, OBD_LMV_DEVICENAME))
1073                 return 1;
1074
1075         return 0;
1076 }
1077
1078 static inline int obd_dt_type(struct obd_device *obd)
1079 {
1080         if (!strcmp(obd->obd_type->typ_name, OBD_LOV_DEVICENAME) ||
1081             !strcmp(obd->obd_type->typ_name, OBD_OSC_DEVICENAME))
1082                 return 1;
1083
1084         return 0;
1085 }
1086
1087 #endif /* __OBD_H */