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