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