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