Whamcloud - gitweb
75759d3b229e09f9da9560d6387dd5ba1a1fb230
[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_objidlock;        /* protects fo_lastobjid increment */
96         __u64 fo_lastobjid;
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         spinlock_t fo_fddlock;          /* protects setting dentry->d_fsdata */
102 };
103
104 struct mds_server_data;
105
106 struct client_obd {
107         struct obd_import    cl_import;
108         struct semaphore     cl_sem;
109         int                  cl_conn_count;
110         obd_uuid_t           cl_target_uuid; /* XXX -> lustre_name */
111         int                  cl_max_mds_easize;
112         int                  cl_max_ost_easize;
113         struct obd_device   *cl_containing_lov;
114 };
115
116 #define IOC_OSC_TYPE         'h'
117 #define IOC_OSC_MIN_NR       20
118 #define IOC_OSC_REGISTER_LOV _IOWR('h', 20, struct obd_device *)
119 #define IOC_OSC_MAX_NR       50
120
121 struct mds_obd {
122         struct ptlrpc_service *mds_service;
123
124         char *mds_fstype;
125         struct super_block *mds_sb;
126         struct super_operations *mds_sop;
127         struct vfsmount *mds_vfsmnt;
128         struct obd_run_ctxt mds_ctxt;
129         struct file_operations *mds_fop;
130         struct inode_operations *mds_iop;
131         struct address_space_operations *mds_aops;
132         struct mds_fs_operations *mds_fsops;
133         int mds_max_mdsize;
134         struct file *mds_rcvd_filp;
135         spinlock_t mds_last_lock;
136         __u64 mds_last_committed;
137         __u64 mds_last_rcvd;
138         __u64 mds_mount_count;
139         struct ll_fid mds_rootfid;
140         struct mds_server_data *mds_server_data;
141 };
142
143 struct ldlm_obd {
144         struct ptlrpc_service *ldlm_service;
145         struct ptlrpc_client *ldlm_client;
146         struct ptlrpc_connection *ldlm_server_conn;
147 };
148
149 struct echo_obd {
150         char *eo_fstype;
151         struct obdo oa;
152         spinlock_t eo_lock;
153         __u64 eo_lastino;
154         atomic_t eo_getattr;
155         atomic_t eo_setattr;
156         atomic_t eo_create;
157         atomic_t eo_destroy;
158         atomic_t eo_prep;
159         atomic_t eo_read;
160         atomic_t eo_write;
161 };
162
163 struct recovd_obd {
164         spinlock_t            recovd_lock;
165         struct list_head      recovd_managed_items; /* items managed  */
166         struct list_head      recovd_troubled_items; /* items in recovery */
167
168         wait_queue_head_t     recovd_recovery_waitq;
169         wait_queue_head_t     recovd_ctl_waitq;
170         wait_queue_head_t     recovd_waitq;
171         struct task_struct   *recovd_thread;
172         __u32                 recovd_state;
173 };
174
175 struct trace_obd {
176         struct obdtrace_opstats *stats;
177 };
178
179 #if 0
180 struct snap_obd {
181         unsigned int snap_index;  /* which snapshot index are we accessing */
182         int snap_tableno;
183 };
184
185 #endif
186
187 struct ost_obd {
188         struct ptlrpc_service *ost_service;
189         struct lustre_handle ost_conn;   /* the local connection to the OBD */
190 };
191
192
193 struct lov_tgt_desc {
194         obd_uuid_t uuid;
195         struct lustre_handle conn;
196         int active; /* is this target available for requests, etc */
197 };
198
199 struct lov_obd {
200         spinlock_t lov_lock;
201         struct obd_device *mdcobd;
202         struct lov_desc desc;
203         int bufsize;
204         int refcount;
205         struct lov_tgt_desc *tgts;
206 };
207
208 struct niobuf_local {
209         __u64 offset;
210         __u32 len;
211         __u32 xid;
212         __u32 flags;
213         void *addr;
214         struct page *page;
215         void *target_private;
216         struct dentry *dentry;
217 };
218
219 #define N_LOCAL_TEMP_PAGE 0x00000001
220
221 /* corresponds to one of the obd's */
222 struct obd_device {
223         struct obd_type *obd_type;
224
225         /* common and UUID name of this device */
226         char *obd_name;
227         obd_uuid_t obd_uuid;
228
229         int obd_minor;
230         int obd_flags;
231         struct proc_dir_entry *obd_proc_entry;
232         struct list_head       obd_exports;
233         struct list_head       obd_imports;
234         struct ldlm_namespace *obd_namespace;
235         struct ptlrpc_client   obd_ldlm_client; /* XXX OST/MDS only */
236         /* a spinlock is OK for what we do now, may need a semaphore later */
237         spinlock_t obd_dev_lock;
238         union {
239                 struct ext2_obd ext2;
240                 struct filter_obd filter;
241                 struct mds_obd mds;
242                 struct client_obd cli;
243                 struct ost_obd ost;
244                 //                struct osc_obd osc;
245                 struct ldlm_obd ldlm;
246                 struct echo_obd echo;
247                 struct recovd_obd recovd;
248                 struct trace_obd trace;
249                 struct lov_obd lov;
250 #if 0
251                 struct snap_obd snap;
252 #endif
253         } u;
254        /* Fields used by LProcFS */
255         unsigned int cntr_mem_size;
256         void* counters;
257 };
258
259 struct io_cb_data;
260
261 struct obd_ops {
262         int (*o_iocontrol)(long cmd, struct lustre_handle *, int len,
263                            void *karg, void *uarg);
264         int (*o_get_info)(struct lustre_handle *, obd_count keylen, void *key,
265                           obd_count *vallen, void **val);
266         int (*o_set_info)(struct lustre_handle *, obd_count keylen, void *key,
267                           obd_count vallen, void *val);
268         int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
269         int (*o_detach)(struct obd_device *dev);
270         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
271         int (*o_cleanup)(struct obd_device *dev);
272         int (*o_connect)(struct lustre_handle *conn, struct obd_device *src,
273                          obd_uuid_t cluuid, struct recovd_obd *recovd,
274                          ptlrpc_recovery_cb_t recover);
275         int (*o_disconnect)(struct lustre_handle *conn);
276
277
278         int (*o_statfs)(struct lustre_handle *conn, struct obd_statfs *osfs);
279         int (*o_preallocate)(struct lustre_handle *, obd_count *req,
280                              obd_id *ids);
281         int (*o_create)(struct lustre_handle *conn,  struct obdo *oa,
282                         struct lov_stripe_md **ea);
283         int (*o_destroy)(struct lustre_handle *conn, struct obdo *oa,
284                          struct lov_stripe_md *ea);
285         int (*o_setattr)(struct lustre_handle *conn, struct obdo *oa,
286                          struct lov_stripe_md *ea);
287         int (*o_getattr)(struct lustre_handle *conn, struct obdo *oa,
288                          struct lov_stripe_md *ea);
289         int (*o_open)(struct lustre_handle *conn, struct obdo *oa,
290                       struct lov_stripe_md *ea);
291         int (*o_close)(struct lustre_handle *conn, struct obdo *oa,
292                        struct lov_stripe_md *ea);
293         int (*o_brw)(int rw, struct lustre_handle *conn,
294                      struct lov_stripe_md *ea, obd_count oa_bufs,
295                      struct brw_page *pgarr, brw_callback_t callback,
296                      struct io_cb_data *data);
297         int (*o_punch)(struct lustre_handle *conn, struct obdo *tgt,
298                        struct lov_stripe_md *ea, obd_size count,
299                        obd_off offset);
300         int (*o_sync)(struct lustre_handle *conn, struct obdo *tgt,
301                       obd_size count, obd_off offset);
302         int (*o_migrate)(struct lustre_handle *conn, struct obdo *dst,
303                          struct obdo *src, obd_size count, obd_off offset);
304         int (*o_copy)(struct lustre_handle *dstconn, struct obdo *dst,
305                       struct lustre_handle *srconn, struct obdo *src,
306                       obd_size count, obd_off offset);
307         int (*o_iterate)(struct lustre_handle *conn,
308                          int (*)(obd_id, obd_gr, void *),
309                          obd_id *startid, obd_gr group, void *data);
310         int (*o_preprw)(int cmd, struct lustre_handle *conn,
311                         int objcount, struct obd_ioobj *obj,
312                         int niocount, struct niobuf_remote *remote,
313                         struct niobuf_local *local, void **desc_private);
314         int (*o_commitrw)(int cmd, struct lustre_handle *conn,
315                           int objcount, struct obd_ioobj *obj,
316                           int niocount, struct niobuf_local *local,
317                           void *desc_private);
318         int (*o_enqueue)(struct lustre_handle *conn, struct lov_stripe_md *md,
319                          struct lustre_handle *parent_lock,
320                          __u32 type, void *cookie, int cookielen, __u32 mode,
321                          int *flags, void *cb, void *data, int datalen,
322                          struct lustre_handle *lockh);
323         int (*o_cancel)(struct lustre_handle *, struct lov_stripe_md *md,
324                         __u32 mode, struct lustre_handle *);
325         int (*o_cancel_unused)(struct lustre_handle *, struct lov_stripe_md *,
326                                int local_only);
327 };
328
329 static inline void *mds_fs_start(struct mds_obd *mds, struct inode *inode,
330                                  int op)
331 {
332         return mds->mds_fsops->fs_start(inode, op);
333 }
334
335 static inline int mds_fs_commit(struct mds_obd *mds, struct inode *inode,
336                                 void *handle)
337 {
338         return mds->mds_fsops->fs_commit(inode, handle);
339 }
340
341 static inline int mds_fs_setattr(struct mds_obd *mds, struct dentry *dentry,
342                                  void *handle, struct iattr *iattr)
343 {
344         int rc;
345         /*
346          * NOTE: we probably don't need to take i_sem here when changing
347          *       ATTR_SIZE because the MDS never needs to truncate a file.
348          *       The ext2/ext3 code never truncates a directory, and files
349          *       stored on the MDS are entirely sparse (no data blocks).
350          *       If we do need to get it, we can do it here.
351          */
352         lock_kernel();
353         rc = mds->mds_fsops->fs_setattr(dentry, handle, iattr);
354         unlock_kernel();
355
356         return rc;
357 }
358
359 static inline int mds_fs_set_md(struct mds_obd *mds, struct inode *inode,
360                                   void *handle, struct lov_mds_md *md)
361 {
362         return mds->mds_fsops->fs_set_md(inode, handle, md);
363 }
364
365 static inline int mds_fs_get_md(struct mds_obd *mds, struct inode *inode,
366                                   struct lov_mds_md *md)
367 {
368         return mds->mds_fsops->fs_get_md(inode, md);
369 }
370
371 static inline ssize_t mds_fs_readpage(struct mds_obd *mds, struct file *file,
372                                       char *buf, size_t count, loff_t *offset)
373 {
374         return mds->mds_fsops->fs_readpage(file, buf, count, offset);
375 }
376
377 /* Set up callback to update mds->mds_last_committed with the current
378  * value of mds->mds_last_recieved when this transaction is on disk.
379  */
380 static inline int mds_fs_set_last_rcvd(struct mds_obd *mds, void *handle)
381 {
382         return mds->mds_fsops->fs_set_last_rcvd(mds, handle);
383 }
384
385 /* Enable data journaling on the given file */
386 static inline ssize_t mds_fs_journal_data(struct mds_obd *mds,
387                                           struct file *file)
388 {
389         return mds->mds_fsops->fs_journal_data(file);
390 }
391
392 static inline int mds_fs_statfs(struct mds_obd *mds, struct statfs *sfs)
393 {
394         if (mds->mds_fsops->fs_statfs)
395                 return mds->mds_fsops->fs_statfs(mds->mds_sb, sfs);
396
397         return vfs_statfs(mds->mds_sb, sfs);
398 }
399
400 #endif