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