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