Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[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 struct lov_oinfo { /* per-child structure */
14         __u64 loi_id;              /* object ID on the target OST */
15         struct lustre_handle *loi_handle; /* open file handle for obj on OST */
16         int loi_ost_idx;           /* OST stripe index in lmd_objects array */
17 };
18
19 struct lov_stripe_md {
20         __u64 lsm_object_id;        /* lov object id */
21         __u32 lsm_magic;
22         __u32 lsm_stripe_size;      /* size of the stripe */
23         unsigned lsm_stripe_offset; /* offset of first stripe in lmd_objects */
24         unsigned lsm_stripe_count;  /* how many objects are being striped on */
25         struct lov_oinfo lsm_oinfo[0];
26 };
27
28 #define IOC_OSC_TYPE         'h'
29 #define IOC_OSC_MIN_NR       20
30 #define IOC_OSC_REGISTER_LOV _IOWR(IOC_OSC_TYPE, 20, struct obd_device *)
31 #define IOC_OSC_MAX_NR       50
32
33 #define IOC_MDC_TYPE         'i'
34 #define IOC_MDC_MIN_NR       20
35 #define IOC_MDC_LOOKUP       _IOWR(IOC_MDC_TYPE, 20, struct obd_device *)
36 #define IOC_MDC_MAX_NR       50
37
38 #ifdef __KERNEL__
39 # include <linux/fs.h>
40 # include <linux/list.h>
41 # include <linux/sched.h> /* for struct task_struct, for current.h */
42 # include <asm/current.h> /* for smp_lock.h */
43 # include <linux/smp_lock.h>
44 # include <linux/proc_fs.h>
45
46 # include <linux/lustre_lib.h>
47 # include <linux/lustre_idl.h>
48 # include <linux/lustre_mds.h>
49 # include <linux/lustre_export.h>
50 #endif
51
52 struct obd_type {
53         struct list_head typ_chain;
54         struct obd_ops *typ_ops;
55         struct proc_dir_entry *typ_procroot;
56         char *typ_name;
57         int  typ_refcnt;
58 };
59
60 struct brw_page {
61         obd_off  off;
62         struct page *pg;
63         int count;
64         obd_flag flag;
65 };
66
67 /* Individual type definitions */
68
69 struct ext2_obd {
70         struct super_block *e2_sb;
71         struct vfsmount *e2_vfsmnt;
72 };
73
74 struct obd_ucred {
75         __u32 ouc_fsuid;
76         __u32 ouc_fsgid;
77         __u32 ouc_cap;
78         __u32 ouc_suppgid1;
79         __u32 ouc_suppgid2;
80 };
81
82 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
83 #define OBD_CTXT_DEBUG          /* development-only debugging */
84 struct obd_run_ctxt {
85         struct vfsmount *pwdmnt;
86         struct dentry   *pwd;
87         mm_segment_t     fs;
88         __u32            fsuid;
89         __u32            fsgid;
90         __u32            cap;
91 #ifdef OBD_CTXT_DEBUG
92         __u32            magic;
93 #endif
94 };
95
96
97 #ifdef OBD_CTXT_DEBUG
98 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
99 #else
100 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
101 #endif
102
103 struct ost_server_data;
104
105 #define FILTER_TRANSNO_SEM
106
107 #ifndef OST_RECOVERY
108 #undef FILTER_TRANSNO_SEM
109 #endif
110
111 struct filter_obd {
112         char *fo_fstype;
113         struct super_block *fo_sb;
114         struct vfsmount *fo_vfsmnt;
115         struct obd_run_ctxt fo_ctxt;
116         struct dentry *fo_dentry_O;
117         struct dentry *fo_dentry_O_mode[16];
118         struct dentry **fo_dentry_O_sub;
119         spinlock_t fo_objidlock;        /* protects fo_lastobjid increment */
120 #ifdef FILTER_TRANSNO_SEM
121         struct semaphore fo_transno_sem;
122 #else
123         spinlock_t fo_translock;        /* protects fsd_last_rcvd increment */
124 #endif
125         struct file *fo_rcvd_filp;
126         struct filter_server_data *fo_fsd;
127         unsigned long *fo_last_rcvd_slots;
128
129         struct file_operations *fo_fop;
130         struct inode_operations *fo_iop;
131         struct address_space_operations *fo_aops;
132         struct list_head fo_export_list;
133         spinlock_t fo_fddlock;          /* protects setting dentry->d_fsdata */
134         int fo_subdir_count;
135 };
136
137 struct mds_server_data;
138
139 struct client_obd {
140         struct obd_import    cl_import;
141         struct semaphore     cl_sem;
142         int                  cl_conn_count;
143         struct obd_uuid           cl_target_uuid; /* XXX -> lustre_name */
144         /* max_mds_easize is purely a performance thing so we don't have to
145          * call obd_size_wiremd() all the time. */
146         int                  cl_max_mds_easize;
147         struct obd_device   *cl_containing_lov;
148         kdev_t               cl_sandev;
149 };
150
151 struct mds_obd {
152         struct ptlrpc_service           *mds_service;
153         struct ptlrpc_service           *mds_setattr_service;
154         struct ptlrpc_service           *mds_readpage_service;
155
156         struct super_block              *mds_sb;
157         struct vfsmount                 *mds_vfsmnt;
158         struct obd_run_ctxt              mds_ctxt;
159         struct file_operations          *mds_fop;
160         struct inode_operations         *mds_iop;
161         struct address_space_operations *mds_aops;
162
163         int                              mds_max_mdsize;
164         struct file                     *mds_rcvd_filp;
165         spinlock_t                       mds_transno_lock;
166         __u64                            mds_last_transno;
167         __u64                            mds_mount_count;
168         struct ll_fid                    mds_rootfid;
169         struct mds_server_data          *mds_server_data;
170
171         int                              mds_has_lov_desc;
172         struct lov_desc                  mds_lov_desc;
173 };
174
175 struct ldlm_obd {
176         struct ptlrpc_service *ldlm_cb_service;
177         struct ptlrpc_service *ldlm_cancel_service;
178         struct ptlrpc_client *ldlm_client;
179         struct ptlrpc_connection *ldlm_server_conn;
180 };
181
182 struct echo_obd {
183         char *eo_fstype;
184         struct obdo oa;
185         spinlock_t eo_lock;
186         __u64 eo_lastino;
187         atomic_t eo_getattr;
188         atomic_t eo_setattr;
189         atomic_t eo_create;
190         atomic_t eo_destroy;
191         atomic_t eo_prep;
192         atomic_t eo_read;
193         atomic_t eo_write;
194 };
195
196 /*
197  * this struct does double-duty acting as either a client or
198  * server instance .. maybe not wise.
199  */
200 struct ptlbd_obd {
201         /* server's */
202         struct ptlrpc_service *ptlbd_service;
203         struct file *filp;
204         /* client's */
205         struct ptlrpc_client bd_client;
206         struct obd_import bd_import;
207         int refcount; /* XXX sigh */
208 };
209
210 struct recovd_obd {
211         spinlock_t            recovd_lock;
212         struct list_head      recovd_managed_items; /* items managed  */
213         struct list_head      recovd_troubled_items; /* items in recovery */
214
215         wait_queue_head_t     recovd_recovery_waitq;
216         wait_queue_head_t     recovd_ctl_waitq;
217         wait_queue_head_t     recovd_waitq;
218         struct task_struct   *recovd_thread;
219         __u32                 recovd_state;
220 };
221
222 struct trace_obd {
223         struct obdtrace_opstats *stats;
224 };
225
226 #if 0
227 struct snap_obd {
228         unsigned int snap_index;  /* which snapshot index are we accessing */
229         int snap_tableno;
230 };
231
232 #endif
233
234 struct ost_obd {
235         struct ptlrpc_service *ost_service;
236 };
237
238 struct echo_client_obd {
239         struct lustre_handle ec_conn;   /* the local connection to osc/lov */
240         spinlock_t           ec_lock;
241         struct list_head     ec_objects;
242         int                  ec_lsmsize;
243         int                  ec_nstripes;
244         __u64                ec_unique;
245 };
246
247 struct cache_obd {
248         struct lustre_handle cobd_target;       /* local connection to target obd */
249         struct lustre_handle cobd_cache;        /* local connection to cache obd */
250 };
251
252 struct lov_tgt_desc {
253         struct obd_uuid uuid;
254         struct lustre_handle conn;
255         int active; /* is this target available for requests, etc */
256 };
257
258 struct lov_obd {
259         spinlock_t lov_lock;
260         struct obd_device *mdcobd;
261         struct lov_desc desc;
262         int bufsize;
263         int refcount;
264         struct lov_tgt_desc *tgts;
265 };
266
267 struct niobuf_local {
268         __u64 offset;
269         __u32 len;
270         __u32 xid;
271         __u32 flags;
272         void *addr;
273         struct page *page;
274         void *target_private;
275         struct dentry *dentry;
276 };
277
278 /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */
279 #define N_LOCAL_TEMP_PAGE 0x10000000
280
281 struct obd_trans_info {
282         __u64     oti_transno;
283 };
284
285 /* corresponds to one of the obd's */
286 struct obd_device {
287         struct obd_type *obd_type;
288
289         /* common and UUID name of this device */
290         char *obd_name;
291         struct obd_uuid obd_uuid;
292
293         int obd_minor;
294         int obd_flags;
295         struct proc_dir_entry *obd_proc_entry;
296         struct list_head       obd_exports;
297         struct list_head       obd_imports;
298         struct ldlm_namespace *obd_namespace;
299         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
300         /* a spinlock is OK for what we do now, may need a semaphore later */
301         spinlock_t obd_dev_lock;
302         __u64                  obd_last_committed;
303         struct fsfilt_operations *obd_fsops;
304
305         /* XXX encapsulate all this recovery data into one struct */
306         svc_handler_t                    obd_recovery_handler;
307         int                              obd_recoverable_clients;
308         spinlock_t                       obd_processing_task_lock;
309         pid_t                            obd_processing_task;
310         __u64                            obd_next_recovery_transno;
311         wait_queue_head_t                obd_next_transno_waitq;
312         struct timer_list                obd_recovery_timer;
313         struct list_head                 obd_recovery_queue;
314         struct list_head                 obd_delayed_reply_queue;
315
316         union {
317                 struct ext2_obd ext2;
318                 struct filter_obd filter;
319                 struct mds_obd mds;
320                 struct client_obd cli;
321                 struct ost_obd ost;
322                 struct echo_client_obd echo_client;;
323                 struct ldlm_obd ldlm;
324                 struct echo_obd echo;
325                 struct recovd_obd recovd;
326                 struct trace_obd trace;
327                 struct lov_obd lov;
328                 struct cache_obd cobd;
329                 struct ptlbd_obd ptlbd;
330 #if 0
331                 struct snap_obd snap;
332 #endif
333         } u;
334        /* Fields used by LProcFS */
335         unsigned int cntr_mem_size;
336         void *counters;
337 };
338
339 struct obd_ops {
340         struct module *o_owner;
341         int (*o_iocontrol)(unsigned int cmd, struct lustre_handle *, int len,
342                            void *karg, void *uarg);
343         int (*o_get_info)(struct lustre_handle *, obd_count keylen, void *key,
344                           obd_count *vallen, void **val);
345         int (*o_set_info)(struct lustre_handle *, obd_count keylen, void *key,
346                           obd_count vallen, void *val);
347         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
348         int (*o_detach)(struct obd_device *dev);
349         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
350         int (*o_cleanup)(struct obd_device *dev);
351         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
352                          struct obd_uuid *cluuid, struct recovd_obd *recovd,
353                          ptlrpc_recovery_cb_t recover);
354         int (*o_disconnect)(struct lustre_handle *conn);
355
356
357         int (*o_statfs)(struct lustre_handle *conn, struct obd_statfs *osfs);
358         int (*o_syncfs)(struct lustre_handle *conn);
359         int (*o_packmd)(struct lustre_handle *, struct lov_mds_md **wire_tgt,
360                         struct lov_stripe_md *mem_src);
361         int (*o_unpackmd)(struct lustre_handle *,
362                           struct lov_stripe_md **mem_tgt,
363                           struct lov_mds_md *wire_src);
364         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
365                              obd_id *ids);
366         int (*o_create)(struct lustre_handle *conn,  struct obdo *oa,
367                         struct lov_stripe_md **ea, struct obd_trans_info *oti);
368         int (*o_destroy)(struct lustre_handle *conn, struct obdo *oa,
369                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
370         int (*o_setattr)(struct lustre_handle *conn, struct obdo *oa,
371                          struct lov_stripe_md *ea, struct obd_trans_info *oti);
372         int (*o_getattr)(struct lustre_handle *conn, struct obdo *oa,
373                          struct lov_stripe_md *ea);
374         int (*o_open)(struct lustre_handle *conn, struct obdo *oa,
375                       struct lov_stripe_md *ea, struct obd_trans_info *oti);
376         int (*o_close)(struct lustre_handle *conn, struct obdo *oa,
377                        struct lov_stripe_md *ea, struct obd_trans_info *oti);
378         int (*o_brw)(int rw, struct lustre_handle *conn,
379                      struct lov_stripe_md *ea, obd_count oa_bufs,
380                      struct brw_page *pgarr, struct obd_brw_set *,
381                      struct obd_trans_info *oti);
382         int (*o_punch)(struct lustre_handle *conn, struct obdo *tgt,
383                        struct lov_stripe_md *ea, obd_size count,
384                        obd_off offset, struct obd_trans_info *oti);
385         int (*o_sync)(struct lustre_handle *conn, struct obdo *tgt,
386                       obd_size count, obd_off offset);
387         int (*o_migrate)(struct lustre_handle *conn, struct obdo *dst,
388                          struct obdo *src, obd_size count, obd_off offset);
389         int (*o_copy)(struct lustre_handle *dstconn, struct obdo *dst,
390                       struct lustre_handle *srconn, struct obdo *src,
391                       obd_size count, obd_off offset, struct obd_trans_info *);
392         int (*o_iterate)(struct lustre_handle *conn,
393                          int (*)(obd_id, obd_gr, void *),
394                          obd_id *startid, obd_gr group, void *data);
395         int (*o_preprw)(int cmd, struct lustre_handle *conn,
396                         int objcount, struct obd_ioobj *obj,
397                         int niocount, struct niobuf_remote *remote,
398                         struct niobuf_local *local, void **desc_private, 
399                         struct obd_trans_info *oti);
400         int (*o_commitrw)(int cmd, struct lustre_handle *conn,
401                           int objcount, struct obd_ioobj *obj,
402                           int niocount, struct niobuf_local *local,
403                           void *desc_private, struct obd_trans_info *oti);
404         int (*o_enqueue)(struct lustre_handle *conn, struct lov_stripe_md *md,
405                          struct lustre_handle *parent_lock,
406                          __u32 type, void *cookie, int cookielen, __u32 mode,
407                          int *flags, void *cb, void *data, int datalen,
408                          struct lustre_handle *lockh);
409         int (*o_cancel)(struct lustre_handle *, struct lov_stripe_md *md,
410                         __u32 mode, struct lustre_handle *);
411         int (*o_cancel_unused)(struct lustre_handle *, struct lov_stripe_md *,
412                                int local_only);
413         int (*o_san_preprw)(int cmd, struct lustre_handle *conn,
414                             int objcount, struct obd_ioobj *obj,
415                             int niocount, struct niobuf_remote *remote);
416 };
417 #endif /* __OBD_H */