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