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