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