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