Whamcloud - gitweb
- teeny fix to ll_revalidate2; this will be trumped by my fix for 626244
[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 #include <linux/fs.h>
13 #include <linux/list.h>
14 #include <linux/smp_lock.h>
15 #include <linux/proc_fs.h>
16
17 #include <linux/lustre_lib.h>
18 #include <linux/lustre_idl.h>
19 #include <linux/lustre_mds.h>
20 #include <linux/lustre_export.h>
21
22 struct obd_type {
23         struct list_head typ_chain;
24         struct obd_ops *typ_ops;
25         char *typ_name;
26         int  typ_refcnt;
27 };
28
29 struct brw_page {
30         struct page *pg;
31         obd_size count;
32         obd_off  off;
33         obd_flag flag;
34 };
35
36 struct lov_oinfo { /* per-child structure */
37         __u64 loi_id;              /* object ID on the target OST */
38         __u64 loi_size;            /* size of this object on the target OST */
39         struct lustre_handle *loi_handle; /* handle for object on OST */
40         int loi_ost_idx;           /* OST stripe index in lmd_objects array */
41 };
42
43 struct lov_stripe_md {
44         __u32 lsm_magic;
45         __u32 lsm_mds_easize;      /* packed size for MDS of ea - KILL ME*/
46         __u64 lsm_object_id;       /* lov object id */
47         __u64 lsm_stripe_size;     /* size of the stripe */
48         __u32 lsm_stripe_pattern;  /* per-lov object stripe pattern */
49         int   lsm_stripe_offset;   /* offset of first stripe in lmd_objects */
50         int   lsm_stripe_count;    /* how many objects are being striped on */
51         int   lsm_ost_count;       /* how many OSTs are in this LOV - KILL ME */
52         struct lov_oinfo lsm_oinfo[0];
53 };
54
55 /* Individual type definitions */
56
57 struct ext2_obd {
58         struct super_block *e2_sb;
59         struct vfsmount *e2_vfsmnt;
60 };
61
62 struct obd_ucred {
63         __u32 ouc_fsuid;
64         __u32 ouc_fsgid;
65 };
66
67 #define OBD_RUN_CTXT_MAGIC      0xC0FFEEAA
68 #define OBD_CTXT_DEBUG          /* development-only debugging */
69 struct obd_run_ctxt {
70         struct vfsmount *pwdmnt;
71         struct dentry   *pwd;
72         mm_segment_t     fs;
73         __u32            fsuid;
74         __u32            fsgid;
75         __u32            override;
76 #ifdef OBD_CTXT_DEBUG
77         __u32            magic;
78 #endif
79 };
80
81
82 #ifdef OBD_CTXT_DEBUG
83 #define OBD_SET_CTXT_MAGIC(ctxt) (ctxt)->magic = OBD_RUN_CTXT_MAGIC
84 #else
85 #define OBD_SET_CTXT_MAGIC(ctxt) do {} while(0)
86 #endif
87
88 struct filter_obd {
89         char *fo_fstype;
90         struct super_block *fo_sb;
91         struct vfsmount *fo_vfsmnt;
92         struct obd_run_ctxt fo_ctxt;
93         struct dentry *fo_dentry_O;
94         struct dentry *fo_dentry_O_mode[16];
95         spinlock_t fo_lock;
96         __u64 fo_lastino;
97         struct file_operations *fo_fop;
98         struct inode_operations *fo_iop;
99         struct address_space_operations *fo_aops;
100         struct list_head fo_export_list;
101 };
102
103 struct mds_server_data;
104
105 struct client_obd {
106         struct obd_import    cl_import;
107         struct semaphore     cl_sem;
108         int                  cl_conn_count;
109         obd_uuid_t           cl_target_uuid; /* XXX -> lustre_name */
110         int                  cl_max_mds_easize;
111         int                  cl_max_ost_easize;
112 };
113
114 struct mds_obd {
115         struct ptlrpc_service *mds_service;
116
117         char *mds_fstype;
118         struct super_block *mds_sb;
119         struct super_operations *mds_sop;
120         struct vfsmount *mds_vfsmnt;
121         struct obd_run_ctxt mds_ctxt;
122         struct file_operations *mds_fop;
123         struct inode_operations *mds_iop;
124         struct address_space_operations *mds_aops;
125         struct mds_fs_operations *mds_fsops;
126         int mds_max_mdsize;
127         struct file *mds_rcvd_filp;
128         spinlock_t mds_last_lock;
129         __u64 mds_last_committed;
130         __u64 mds_last_rcvd;
131         __u64 mds_mount_count;
132         struct ll_fid mds_rootfid;
133         struct mds_server_data *mds_server_data;
134 };
135
136 struct ldlm_obd {
137         struct ptlrpc_service *ldlm_service;
138         struct ptlrpc_client *ldlm_client;
139         struct ptlrpc_connection *ldlm_server_conn;
140 };
141
142 struct echo_obd {
143         char *eo_fstype;
144         struct obdo oa;
145         spinlock_t eo_lock;
146         __u64 eo_lastino;
147         atomic_t eo_getattr;
148         atomic_t eo_setattr;
149         atomic_t eo_create;
150         atomic_t eo_destroy;
151         atomic_t eo_prep;
152         atomic_t eo_read;
153         atomic_t eo_write;
154 };
155
156 struct recovd_obd {
157         spinlock_t            recovd_lock;
158         struct list_head      recovd_managed_items; /* items managed  */
159         struct list_head      recovd_troubled_items; /* items in recovery */
160
161         wait_queue_head_t     recovd_recovery_waitq;
162         wait_queue_head_t     recovd_ctl_waitq;
163         wait_queue_head_t     recovd_waitq;
164         struct task_struct   *recovd_thread;
165         __u32                 recovd_state;
166 };
167
168 struct trace_obd {
169         struct obdtrace_opstats *stats;
170 };
171
172 #if 0
173 struct snap_obd {
174         unsigned int snap_index;  /* which snapshot index are we accessing */
175         int snap_tableno;
176 };
177
178 #endif
179
180 struct ost_obd {
181         struct ptlrpc_service *ost_service;
182         struct lustre_handle ost_conn;   /* the local connection to the OBD */
183 };
184
185
186 struct lov_tgt_desc {
187         obd_uuid_t uuid;
188         struct lustre_handle conn;
189         int active; /* is this target available for requests, etc */
190 };
191
192 struct lov_obd {
193         spinlock_t lov_lock;
194         struct obd_device *mdcobd;
195         struct lov_desc desc;
196         int bufsize;
197         int refcount;
198         struct lov_tgt_desc *tgts;
199 };
200
201 struct niobuf_local {
202         __u64 offset;
203         __u32 len;
204         __u32 xid;
205         __u32 flags;
206         void *addr;
207         struct page *page;
208         void *target_private;
209         struct dentry *dentry;
210 };
211
212 #define N_LOCAL_TEMP_PAGE 0x00000001
213
214 /* corresponds to one of the obd's */
215 struct obd_device {
216         struct obd_type *obd_type;
217
218         /* common and UUID name of this device */
219         char *obd_name;
220         obd_uuid_t obd_uuid;
221
222         int obd_minor;
223         int obd_flags;
224         struct proc_dir_entry *obd_proc_entry;
225         struct list_head       obd_exports;
226         struct list_head       obd_imports;
227         struct ldlm_namespace *obd_namespace;
228         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
229         /* a spinlock is OK for what we do now, may need a semaphore later */
230         spinlock_t obd_dev_lock;
231         union {
232                 struct ext2_obd ext2;
233                 struct filter_obd filter;
234                 struct mds_obd mds;
235                 struct client_obd cli;
236                 struct ost_obd ost;
237                 //                struct osc_obd osc;
238                 struct ldlm_obd ldlm;
239                 struct echo_obd echo;
240                 struct recovd_obd recovd;
241                 struct trace_obd trace;
242                 struct lov_obd lov;
243 #if 0
244                 struct snap_obd snap;
245 #endif
246         } u;
247        /* Fields used by LProcFS */
248         unsigned int cntr_mem_size;
249         void* counters;
250 };
251
252 struct io_cb_data;
253
254 struct obd_ops {
255         int (*o_iocontrol)(long cmd, struct lustre_handle *, int len,
256                            void *karg, void *uarg);
257         int (*o_get_info)(struct lustre_handle *, obd_count keylen, void *key,
258                           obd_count *vallen, void **val);
259         int (*o_set_info)(struct lustre_handle *, obd_count keylen, void *key,
260                           obd_count vallen, void *val);
261         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
262         int (*o_detach)(struct obd_device *dev);
263         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
264         int (*o_cleanup)(struct obd_device *dev);
265         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
266                          obd_uuid_t cluuid, struct recovd_obd *recovd,
267                          ptlrpc_recovery_cb_t recover);
268         int (*o_disconnect)(struct lustre_handle *conn);
269
270
271         int (*o_statfs)(struct lustre_handle *conn, struct obd_statfs *osfs);
272         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
273                              obd_id *ids);
274         int (*o_create)(struct lustre_handle *conn,  struct obdo *oa,
275                         struct lov_stripe_md **ea);
276         int (*o_destroy)(struct lustre_handle *conn, struct obdo *oa,
277                          struct lov_stripe_md *ea);
278         int (*o_setattr)(struct lustre_handle *conn, struct obdo *oa,
279                          struct lov_stripe_md *ea);
280         int (*o_getattr)(struct lustre_handle *conn, struct obdo *oa,
281                          struct lov_stripe_md *ea);
282         int (*o_open)(struct lustre_handle *conn, struct obdo *oa,
283                       struct lov_stripe_md *ea);
284         int (*o_close)(struct lustre_handle *conn, struct obdo *oa,
285                        struct lov_stripe_md *ea);
286         int (*o_brw)(int rw, struct lustre_handle *conn,
287                      struct lov_stripe_md *ea, obd_count oa_bufs,
288                      struct brw_page *pgarr, brw_callback_t callback,
289                      struct io_cb_data *data);
290         int (*o_punch)(struct lustre_handle *conn, struct obdo *tgt,
291                        struct lov_stripe_md *ea, obd_size count,
292                        obd_off offset);
293         int (*o_sync)(struct lustre_handle *conn, struct obdo *tgt,
294                       obd_size count, obd_off offset);
295         int (*o_migrate)(struct lustre_handle *conn, struct obdo *dst,
296                          struct obdo *src, obd_size count, obd_off offset);
297         int (*o_copy)(struct lustre_handle *dstconn, struct obdo *dst,
298                       struct lustre_handle *srconn, struct obdo *src,
299                       obd_size count, obd_off offset);
300         int (*o_iterate)(struct lustre_handle *conn,
301                          int (*)(obd_id, obd_gr, void *),
302                          obd_id *startid, obd_gr group, void *data);
303         int (*o_preprw)(int cmd, struct lustre_handle *conn,
304                         int objcount, struct obd_ioobj *obj,
305                         int niocount, struct niobuf_remote *remote,
306                         struct niobuf_local *local, void **desc_private);
307         int (*o_commitrw)(int cmd, struct lustre_handle *conn,
308                           int objcount, struct obd_ioobj *obj,
309                           int niocount, struct niobuf_local *local,
310                           void *desc_private);
311         int (*o_enqueue)(struct lustre_handle *conn, struct lov_stripe_md *md,
312                          struct lustre_handle *parent_lock,
313                          __u32 type, void *cookie, int cookielen, __u32 mode,
314                          int *flags, void *cb, void *data, int datalen,
315                          struct lustre_handle *lockh);
316         int (*o_cancel)(struct lustre_handle *, struct lov_stripe_md *md,
317                         __u32 mode, struct lustre_handle *);
318         int (*o_cancel_unused)(struct lustre_handle *, struct lov_stripe_md *,
319                                int local_only);
320 };
321
322 static inline void *mds_fs_start(struct mds_obd *mds, struct inode *inode,
323                                  int op)
324 {
325         return mds->mds_fsops->fs_start(inode, op);
326 }
327
328 static inline int mds_fs_commit(struct mds_obd *mds, struct inode *inode,
329                                 void *handle)
330 {
331         return mds->mds_fsops->fs_commit(inode, handle);
332 }
333
334 static inline int mds_fs_setattr(struct mds_obd *mds, struct dentry *dentry,
335                                  void *handle, struct iattr *iattr)
336 {
337         int rc;
338         /*
339          * NOTE: we probably don't need to take i_sem here when changing
340          *       ATTR_SIZE because the MDS never needs to truncate a file.
341          *       The ext2/ext3 code never truncates a directory, and files
342          *       stored on the MDS are entirely sparse (no data blocks).
343          *       If we do need to get it, we can do it here.
344          */
345         lock_kernel();
346         rc = mds->mds_fsops->fs_setattr(dentry, handle, iattr);
347         unlock_kernel();
348
349         return rc;
350 }
351
352 static inline int mds_fs_set_md(struct mds_obd *mds, struct inode *inode,
353                                   void *handle, struct lov_mds_md *md)
354 {
355         return mds->mds_fsops->fs_set_md(inode, handle, md);
356 }
357
358 static inline int mds_fs_get_md(struct mds_obd *mds, struct inode *inode,
359                                   struct lov_mds_md *md)
360 {
361         return mds->mds_fsops->fs_get_md(inode, md);
362 }
363
364 static inline ssize_t mds_fs_readpage(struct mds_obd *mds, struct file *file,
365                                       char *buf, size_t count, loff_t *offset)
366 {
367         return mds->mds_fsops->fs_readpage(file, buf, count, offset);
368 }
369
370 /* Set up callback to update mds->mds_last_committed with the current
371  * value of mds->mds_last_recieved when this transaction is on disk.
372  */
373 static inline int mds_fs_set_last_rcvd(struct mds_obd *mds, void *handle)
374 {
375         return mds->mds_fsops->fs_set_last_rcvd(mds, handle);
376 }
377
378 /* Enable data journaling on the given file */
379 static inline ssize_t mds_fs_journal_data(struct mds_obd *mds,
380                                           struct file *file)
381 {
382         return mds->mds_fsops->fs_journal_data(file);
383 }
384
385 static inline int mds_fs_statfs(struct mds_obd *mds, struct statfs *sfs)
386 {
387         if (mds->mds_fsops->fs_statfs)
388                 return mds->mds_fsops->fs_statfs(mds->mds_sb, sfs);
389
390         return vfs_statfs(mds->mds_sb, sfs);
391 }
392
393 #endif