Whamcloud - gitweb
A few more changes.
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
3
4 #include <linux/fs.h>
5 #include <linux/ext2_fs.h>
6 #include <linux/time.h>
7 #include <linux/obd.h>
8
9 #include <linux/obd_ext2.h>
10 #include <linux/obd_snap.h>
11 /* #include <linux/obd_fc.h> */
12 #include <linux/obd_raid1.h>
13 #include <linux/obd_rpc.h>
14
15
16 /*
17  *  ======== OBD type Declarations ===========
18  */
19
20 typedef uint64_t        obd_id;
21 typedef uint64_t        obd_gr;
22 typedef uint64_t        obd_time;
23 typedef uint64_t        obd_size;
24 typedef uint64_t        obd_off;
25 typedef uint64_t        obd_blocks;
26 typedef uint32_t        obd_blksize;
27 typedef uint32_t        obd_mode;
28 typedef uint32_t        obd_uid;
29 typedef uint32_t        obd_gid;
30 typedef uint32_t        obd_flag;
31 typedef uint32_t        obd_count;
32
33 #define OBD_FL_INLINEDATA       (1UL)  
34 #define OBD_FL_OBDMDEXISTS      (1UL << 1)
35
36 #define OBD_INLINESZ    60
37 #define OBD_OBDMDSZ     64
38 /* Note: 64-bit types are 64-bit aligned in structure */
39 struct obdo {
40         obd_id                  o_id;
41         obd_gr                  o_gr;
42         obd_time                o_atime;
43         obd_time                o_mtime;
44         obd_time                o_ctime;
45         obd_size                o_size;
46         obd_blocks              o_blocks;
47         obd_blksize             o_blksize;
48         obd_mode                o_mode;
49         obd_uid                 o_uid;
50         obd_gid                 o_gid;
51         obd_flag                o_flags;
52         obd_flag                o_obdflags;
53         obd_count               o_nlink;
54         obd_flag                o_valid;        /* hot fields in this obdo */
55         char                    o_inline[OBD_INLINESZ];
56         char                    o_obdmd[OBD_OBDMDSZ];
57         struct list_head        o_list;
58         struct obd_ops          *o_op;
59 };
60
61 /*
62  *  ======== OBD Device Declarations ===========
63  */
64
65
66 #define OBD_PSDEV_MAJOR 186
67 #define MAX_OBD_DEVICES 8
68 #define MAX_MULTI 16
69
70
71 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
72
73
74 #define OBD_ATTACHED 0x1
75 #define OBD_SET_UP   0x2
76
77 struct obd_conn {
78         struct obd_device *oc_dev;
79         uint32_t oc_id;
80 };
81
82 /* corresponds to one of the obdx */
83 struct obd_device {
84         struct obd_type *obd_type;
85         int obd_minor;
86         int obd_flags;
87         int obd_refcnt; 
88         int obd_multi_count;
89         struct obd_conn obd_multi_conn[MAX_MULTI];
90         unsigned int obd_gen_last_id;
91         unsigned long obd_gen_prealloc_quota;
92         struct list_head obd_gen_clients;
93         union {
94                 struct ext2_obd ext2;
95                 struct raid1_obd raid1;
96                 struct snap_obd snap;
97                 struct rpc_obd rpc;
98                 /* struct fc_obd fc; */
99         } u;
100 };
101
102 /*
103  *  ======== OBD Operations Declarations ===========
104  */
105
106
107 struct obd_ops {
108         int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
109         int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key, obd_count *vallen, void **val);
110         int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key, obd_count vallen, void *val);
111         int (*o_attach)(struct obd_device *, obd_count len, void *);
112         int (*o_detach)(struct obd_device *);
113         int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
114         int (*o_cleanup)(struct obd_device *dev);
115         int (*o_connect)(struct obd_conn *conn);
116         int (*o_disconnect)(struct obd_conn *);
117         int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
118         int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
119         int (*o_create)(struct obd_conn *,  struct obdo *oa);
120         int (*o_destroy)(struct obd_conn *, struct obdo *oa);
121         int (*o_setattr)(struct obd_conn *, struct obdo *oa);
122         int (*o_getattr)(struct obd_conn *, struct obdo *oa);
123         int (*o_read)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset);
124         int (*o_write)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset);
125         int (*o_brw)(int rw, struct obd_conn * conn, struct obdo *oa, char *buf, obd_size count, obd_off offset, obd_flag flags);
126         int (*o_punch)(struct obd_conn *, struct obdo *tgt, obd_size count, obd_off offset);
127         int (*o_sync)(struct obd_conn *, struct obdo *tgt, obd_size count, obd_off offset);
128         int (*o_migrate)(struct obd_conn *, struct obdo *dst, struct obdo *src, obd_size count, obd_off offset);
129         int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst, struct obd_conn *srconn, struct obdo *src, obd_size count, obd_off offset);
130         int (*o_iterate)(struct obd_conn *, int (*)(obd_id, void *), obd_id start, void *);
131
132 };
133
134 #define OBT(dev)        dev->obd_type->typ_ops
135 #define OBP(dev,op)     dev->obd_type->typ_ops->o_ ## op
136
137
138 /*
139  *  ======== OBD Metadata Support  ===========
140  */
141
142 extern int obd_init_obdo_cache(void);
143
144
145 static inline int obdo_has_inline(struct obdo *obdo)
146 {
147         return obdo->o_obdflags & OBD_FL_INLINEDATA;
148 };
149
150 static inline int obdo_has_obdmd(struct obdo *obdo)
151 {
152         return obdo->o_obdflags & OBD_FL_OBDMDEXISTS;
153 };
154
155 /* support routines */
156 extern kmem_cache_t *obdo_cachep;
157
158 static __inline__ struct obdo *obdo_alloc(void)
159 {
160         struct obdo *res = NULL;
161
162         res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
163         memset(res, 0, sizeof (*res));
164
165         return res;
166 }
167
168 static __inline__ void obdo_free(struct obdo *oa)
169 {
170         if ( !oa ) 
171                 return;
172         kmem_cache_free(obdo_cachep, oa);
173 }
174
175
176
177 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id)
178 {
179         struct obdo *res = NULL;
180
181         res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
182         if ( !res ) {
183                 EXIT;
184                 return NULL;
185         }
186         memset(res, 0, sizeof(*res));
187         res->o_id = id;
188         if (OBP(conn->oc_dev, getattr)(conn, res)) {
189                 OBD_FREE(res, sizeof(*res));
190                 EXIT;
191                 return NULL;
192         }
193         EXIT;
194         return res;
195 }
196
197 #define OBD_MD_FLALL    (~0UL)
198 #define OBD_MD_FLID     (1UL)
199 #define OBD_MD_FLATIME  (1UL<<1)
200 #define OBD_MD_FLMTIME  (1UL<<2)
201 #define OBD_MD_FLCTIME  (1UL<<3)
202 #define OBD_MD_FLSIZE   (1UL<<4)
203 #define OBD_MD_FLBLOCKS (1UL<<5)
204 #define OBD_MD_FLBLKSZ  (1UL<<6)
205 #define OBD_MD_FLMODE   (1UL<<7)
206 #define OBD_MD_FLUID    (1UL<<8)
207 #define OBD_MD_FLGID    (1UL<<9)
208 #define OBD_MD_FLFLAGS  (1UL<<10)
209 #define OBD_MD_FLOBDFLG (1UL<<11)
210 #define OBD_MD_FLINLINE (1UL<<12)
211 #define OBD_MD_FLOBDMD  (1UL<<13)
212
213
214
215 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
216 {
217
218         CDEBUG(D_INODE, "flags %x\n", src->o_valid);
219         if ( src->o_valid & OBD_MD_FLMODE ) 
220                 dst->o_mode = src->o_mode;
221         if ( src->o_valid & OBD_MD_FLUID ) 
222                 dst->o_uid = src->o_uid;
223         if ( src->o_valid & OBD_MD_FLGID ) 
224                 dst->o_gid = src->o_gid;
225         if ( src->o_valid & OBD_MD_FLSIZE ) 
226                 dst->o_size = src->o_size;
227         if ( src->o_valid & OBD_MD_FLATIME ) 
228                 dst->o_atime = src->o_atime;
229         if ( src->o_valid & OBD_MD_FLMTIME ) 
230                 dst->o_mtime = src->o_mtime;
231         if ( src->o_valid & OBD_MD_FLCTIME ) 
232                 dst->o_ctime = src->o_ctime;
233         if ( src->o_valid & OBD_MD_FLFLAGS ) 
234                 dst->o_flags = src->o_flags;
235         /* allocation of space */
236         if ( src->o_valid & OBD_MD_FLBLOCKS ) 
237                 dst->o_blocks = src->o_blocks;
238 }
239
240 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
241 {
242
243         CDEBUG(D_INODE, "flags %x\n", dst->o_valid);
244         if ( dst->o_valid & OBD_MD_FLMODE ) 
245                 dst->o_mode = src->i_mode;
246         if ( dst->o_valid & OBD_MD_FLUID ) 
247                 dst->o_uid = src->i_uid;
248         if ( dst->o_valid & OBD_MD_FLGID ) 
249                 dst->o_gid = src->i_gid;
250         if ( dst->o_valid & OBD_MD_FLSIZE ) 
251                 dst->o_size = src->i_size;
252         if ( dst->o_valid & OBD_MD_FLATIME ) 
253                 dst->o_atime = src->i_atime;
254         if ( dst->o_valid & OBD_MD_FLMTIME ) 
255                 dst->o_mtime = src->i_mtime;
256         if ( dst->o_valid & OBD_MD_FLCTIME ) 
257                 dst->o_ctime = src->i_ctime;
258         if ( dst->o_valid & OBD_MD_FLFLAGS ) 
259                 dst->o_flags = src->i_flags;
260         /* allocation of space */
261         if ( dst->o_valid & OBD_MD_FLBLOCKS ) 
262                 dst->o_blocks = src->i_blocks;
263
264 }
265
266 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
267 {
268
269         CDEBUG(D_INODE, "flags %x\n", src->o_valid);
270         if ( src->o_valid & OBD_MD_FLMODE ) 
271                 dst->i_mode = src->o_mode;
272         if ( src->o_valid & OBD_MD_FLUID ) 
273                 dst->i_uid = src->o_uid;
274         if ( src->o_valid & OBD_MD_FLGID ) 
275                 dst->i_gid = src->o_gid;
276         if ( src->o_valid & OBD_MD_FLSIZE ) 
277                 dst->i_size = src->o_size;
278         if ( src->o_valid & OBD_MD_FLATIME ) 
279                 dst->i_atime = src->o_atime;
280         if ( src->o_valid & OBD_MD_FLMTIME ) 
281                 dst->i_mtime = src->o_mtime;
282         if ( src->o_valid & OBD_MD_FLCTIME ) 
283                 dst->i_ctime = src->o_ctime;
284         if ( src->o_valid & OBD_MD_FLFLAGS ) 
285                 dst->i_flags = src->o_flags;
286         /* allocation of space */
287         if ( src->o_valid & OBD_MD_FLBLOCKS ) 
288                 dst->i_blocks = src->o_blocks;
289
290 }
291
292 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src)
293 {
294         int res = 1;
295
296         if ( src->o_valid & OBD_MD_FLMODE )
297                 res = (res && (dst->o_mode == src->o_mode));
298         if ( src->o_valid & OBD_MD_FLUID )
299                 res = (res && (dst->o_uid == src->o_uid));
300         if ( src->o_valid & OBD_MD_FLGID )
301                 res = (res && (dst->o_gid == src->o_gid));
302         if ( src->o_valid & OBD_MD_FLSIZE )
303                 res = (res && (dst->o_size == src->o_size));
304         if ( src->o_valid & OBD_MD_FLATIME )
305                 res = (res && (dst->o_atime == src->o_atime));
306         if ( src->o_valid & OBD_MD_FLMTIME )
307                 res = (res && (dst->o_mtime == src->o_mtime));
308         if ( src->o_valid & OBD_MD_FLCTIME )
309                 res = (res && (dst->o_ctime == src->o_ctime));
310         if ( src->o_valid & OBD_MD_FLFLAGS )
311                 res = (res && (dst->o_flags == src->o_flags));
312         /* allocation of space */
313         if ( src->o_valid & OBD_MD_FLBLOCKS )
314                 res = (res && (dst->o_blocks == src->o_blocks));
315         return res;
316 }
317
318
319
320 int obd_register_type(struct obd_ops *ops, char *nm);
321 int obd_unregister_type(char *nm);
322
323 struct obd_client {
324         struct list_head cli_chain;
325         struct obd_device *cli_obd;
326         unsigned int cli_id;
327         unsigned long cli_prealloc_quota;
328         struct list_head cli_prealloc_inodes;
329 };
330
331
332 struct obd_prealloc_inode {
333         struct list_head obd_prealloc_chain;
334         unsigned long inode;
335 };
336
337 /* generic operations shared by various OBD types */
338 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
339 int gen_multi_cleanup(struct obd_device *obddev);
340 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
341 int gen_multi_detach(struct obd_device *obddev);
342 int gen_connect (struct obd_conn *conn);
343 int gen_disconnect(struct obd_conn *conn);
344 struct obd_client *gen_client(struct obd_conn *);
345 int gen_cleanup(struct obd_device *obddev);
346 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
347                   struct obd_conn *src_conn, struct obdo *src,
348                   obd_size count, obd_off offset);
349
350
351
352 /*
353  *  ======== OBD IOCL Declarations ===========
354  */
355 struct oic_generic {
356         int  att_connid;
357         int  att_typelen;
358         void *att_type;
359         int  att_datalen;
360         void *att_data;
361 };
362
363
364 /* for preallocation */
365 struct oic_prealloc_s {
366         uint32_t cli_id;
367         uint32_t alloc; /* user sets it to the number of inodes
368                           * requesting to be preallocated.  kernel
369                           * sets it to the actual number * of
370                           * succesfully preallocated inodes */
371         obd_id  ids[32]; /* actual inode numbers */
372 };
373
374 /* for getattr, setattr, create, destroy */
375 struct oic_attr_s {
376         uint32_t conn_id;
377         struct obdo  obdo;
378 };
379
380 /* for copy, migrate */
381 struct ioc_mv_s {
382         unsigned int src_conn_id;
383         struct obdo  src;
384         unsigned int dst_conn_id;
385         struct obdo  dst;
386 };
387
388 /* for read/write */
389 struct oic_rw_s {
390         uint32_t conn_id;
391         struct obdo obdo;
392         char * buf;
393         obd_size count;
394         obd_off offset;
395 };
396
397 /* for punch, sync */
398 struct oic_range_s {
399         uint32_t conn_id;
400         struct obdo obdo;
401         obd_size count;
402         obd_off offset;
403 };
404
405
406 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
407 #define OBD_IOC_SETUP                  _IOW ('f',  4, long)
408 #define OBD_IOC_CLEANUP                _IO  ('f',  5      )
409 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
410 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
411 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
412 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
413 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
414 #define OBD_IOC_READ                   _IOWR('f', 11, long)
415 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
416 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
417 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
418 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
419 #define OBD_IOC_SYNC                   _IOR ('f',  16, long)
420 #define OBD_IOC_READ2                  _IOWR('f', 17, long)
421 #define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
422 #define OBD_IOC_PARTITION              _IOWR('f', 19, long)
423 #define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
424 #define OBD_IOC_DETACH                 _IOWR('f', 21, long)
425 #define OBD_IOC_COPY                   _IOWR('f', 22, long)
426 #define OBD_IOC_MIGR                   _IOWR('f', 23, long)
427
428 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
429
430
431 /* sysctl.c */
432 extern void obd_sysctl_init (void);
433 extern void obd_sysctl_clean (void);
434
435 #define CHKCONN(conn)   do { if (!gen_client(conn)) {\
436                 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
437                        conn->oc_id);\
438                 return -EINVAL; }} while (0) 
439
440
441
442 #endif /* __LINUX_CLASS_OBD_H */