1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
5 #include <linux/ext2_fs.h>
6 #include <linux/time.h>
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>
17 * ======== OBD type Declarations ===========
20 typedef uint64_t obd_id;
21 typedef uint64_t obd_time;
22 typedef uint64_t obd_size;
23 typedef uint64_t obd_off;
24 typedef uint64_t obd_blocks;
25 typedef uint32_t obd_blksize;
26 typedef uint32_t obd_mode;
27 typedef uint32_t obd_uid;
28 typedef uint32_t obd_gid;
29 typedef uint32_t obd_flag;
30 typedef uint32_t obd_count;
32 #define OBD_INLINESZ 60
33 #define OBD_OBDMDSZ 64
35 #define OBD_FL_INLINEDATA (1UL)
36 #define OBD_FL_OBDMDEXISTS (1UL << 1)
38 /* Note: 64-bit types are 64-bit aligned in structure */
46 obd_blksize o_blksize;
53 obd_flag o_valid; /* hot fields in this obdo */
54 char o_inline[OBD_INLINESZ];
55 char o_obdmd[OBD_OBDMDSZ];
56 struct list_head o_list;
61 * ======== OBD Device Declarations ===========
65 #define OBD_PSDEV_MAJOR 186
66 #define MAX_OBD_DEVICES 8
70 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
73 #define OBD_ATTACHED 0x1
74 #define OBD_SET_UP 0x2
77 struct obd_device *oc_dev;
81 /* corresponds to one of the obdx */
83 struct obd_type *obd_type;
88 struct obd_conn obd_multi_conn[MAX_MULTI];
89 unsigned int obd_gen_last_id;
90 unsigned long obd_gen_prealloc_quota;
91 struct list_head obd_gen_clients;
94 struct raid1_obd raid1;
97 /* struct fc_obd fc; */
102 * ======== OBD Operations Declarations ===========
107 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
108 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key, obd_count *vallen, void **val);
109 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key, obd_count vallen, void *val);
110 int (*o_attach)(struct obd_device *, obd_count len, void *);
111 int (*o_detach)(struct obd_device *);
112 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
113 int (*o_cleanup)(struct obd_device *dev);
114 int (*o_connect)(struct obd_conn *conn);
115 int (*o_disconnect)(struct obd_conn *);
116 int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
117 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
118 int (*o_create)(struct obd_conn *, struct obdo *oa);
119 int (*o_destroy)(struct obd_conn *, struct obdo *oa);
120 int (*o_setattr)(struct obd_conn *, struct obdo *oa);
121 int (*o_getattr)(struct obd_conn *, struct obdo *oa);
122 int (*o_read)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset);
123 int (*o_write)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset);
124 int (*o_brw)(int rw, struct obd_conn * conn, struct obdo *oa, char *buf, obd_size count, obd_off offset, obd_flag flags);
125 int (*o_punch)(struct obd_conn *, struct obdo *tgt, obd_size count, obd_off offset);
126 int (*o_migrate)(struct obd_conn *, struct obdo *dst, struct obdo *src, obd_size count, obd_off offset);
127 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst, struct obd_conn *srconn, struct obdo *src, obd_size count, obd_off offset);
128 int (*o_iterate)(struct obd_conn *, int (*)(obd_id, void *), obd_id start, void *);
132 #define OBT(dev) dev->obd_type->typ_ops
133 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
137 * ======== OBD Metadata Support ===========
142 static inline int obdo_has_inline(struct obdo *obdo)
144 return obdo->o_obdflags & OBD_FL_INLINEDATA;
147 static inline int obdo_has_obdmd(struct obdo *obdo)
149 return obdo->o_obdflags & OBD_FL_OBDMDEXISTS;
152 /* support routines */
153 extern kmem_cache_t *obdo_cachep;
155 static __inline__ struct obdo *obdo_alloc(void)
157 struct obdo *res = NULL;
159 res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
160 memset(res, 0, sizeof (*res));
165 static __inline__ void obdo_free(struct obdo *oa)
169 kmem_cache_free(obdo_cachep, oa);
174 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id)
176 struct obdo *res = NULL;
178 res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
183 memset(res, 0, sizeof(*res));
185 if (OBP(conn->oc_dev, getattr)(conn, res)) {
186 OBD_FREE(res, sizeof(*res));
194 #define OBD_MD_FLALL (~0UL)
195 #define OBD_MD_FLID (1UL)
196 #define OBD_MD_FLATIME (1UL<<1)
197 #define OBD_MD_FLMTIME (1UL<<2)
198 #define OBD_MD_FLCTIME (1UL<<3)
199 #define OBD_MD_FLSIZE (1UL<<4)
200 #define OBD_MD_FLBLOCKS (1UL<<5)
201 #define OBD_MD_FLBLKSZ (1UL<<6)
202 #define OBD_MD_FLMODE (1UL<<7)
203 #define OBD_MD_FLUID (1UL<<8)
204 #define OBD_MD_FLGID (1UL<<9)
205 #define OBD_MD_FLFLAGS (1UL<<10)
206 #define OBD_MD_FLOBDFLG (1UL<<11)
207 #define OBD_MD_FLINLINE (1UL<<12)
208 #define OBD_MD_FLOBDMD (1UL<<13)
212 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
215 CDEBUG(D_INODE, "flags %x\n", src->o_valid);
216 if ( src->o_valid & OBD_MD_FLMODE )
217 dst->o_mode = src->o_mode;
218 if ( src->o_valid & OBD_MD_FLUID )
219 dst->o_uid = src->o_uid;
220 if ( src->o_valid & OBD_MD_FLGID )
221 dst->o_gid = src->o_gid;
222 if ( src->o_valid & OBD_MD_FLSIZE )
223 dst->o_size = src->o_size;
224 if ( src->o_valid & OBD_MD_FLATIME )
225 dst->o_atime = src->o_atime;
226 if ( src->o_valid & OBD_MD_FLMTIME )
227 dst->o_mtime = src->o_mtime;
228 if ( src->o_valid & OBD_MD_FLCTIME )
229 dst->o_ctime = src->o_ctime;
230 if ( src->o_valid & OBD_MD_FLFLAGS )
231 dst->o_flags = src->o_flags;
232 /* allocation of space */
233 if ( src->o_valid & OBD_MD_FLBLOCKS )
234 dst->o_blocks = src->o_blocks;
237 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
240 CDEBUG(D_INODE, "flags %x\n", dst->o_valid);
241 if ( dst->o_valid & OBD_MD_FLMODE )
242 dst->o_mode = src->i_mode;
243 if ( dst->o_valid & OBD_MD_FLUID )
244 dst->o_uid = src->i_uid;
245 if ( dst->o_valid & OBD_MD_FLGID )
246 dst->o_gid = src->i_gid;
247 if ( dst->o_valid & OBD_MD_FLSIZE )
248 dst->o_size = src->i_size;
249 if ( dst->o_valid & OBD_MD_FLATIME )
250 dst->o_atime = src->i_atime;
251 if ( dst->o_valid & OBD_MD_FLMTIME )
252 dst->o_mtime = src->i_mtime;
253 if ( dst->o_valid & OBD_MD_FLCTIME )
254 dst->o_ctime = src->i_ctime;
255 if ( dst->o_valid & OBD_MD_FLFLAGS )
256 dst->o_flags = src->i_flags;
257 /* allocation of space */
258 if ( dst->o_valid & OBD_MD_FLBLOCKS )
259 dst->o_blocks = src->i_blocks;
263 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
266 CDEBUG(D_INODE, "flags %x\n", src->o_valid);
267 if ( src->o_valid & OBD_MD_FLMODE )
268 dst->i_mode = src->o_mode;
269 if ( src->o_valid & OBD_MD_FLUID )
270 dst->i_uid = src->o_uid;
271 if ( src->o_valid & OBD_MD_FLGID )
272 dst->i_gid = src->o_gid;
273 if ( src->o_valid & OBD_MD_FLSIZE )
274 dst->i_size = src->o_size;
275 if ( src->o_valid & OBD_MD_FLATIME )
276 dst->i_atime = src->o_atime;
277 if ( src->o_valid & OBD_MD_FLMTIME )
278 dst->i_mtime = src->o_mtime;
279 if ( src->o_valid & OBD_MD_FLCTIME )
280 dst->i_ctime = src->o_ctime;
281 if ( src->o_valid & OBD_MD_FLFLAGS )
282 dst->i_flags = src->o_flags;
283 /* allocation of space */
284 if ( src->o_valid & OBD_MD_FLBLOCKS )
285 dst->i_blocks = src->o_blocks;
289 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src)
293 if ( src->o_valid & OBD_MD_FLMODE )
294 res = (res && (dst->o_mode == src->o_mode));
295 if ( src->o_valid & OBD_MD_FLUID )
296 res = (res && (dst->o_uid == src->o_uid));
297 if ( src->o_valid & OBD_MD_FLGID )
298 res = (res && (dst->o_gid == src->o_gid));
299 if ( src->o_valid & OBD_MD_FLSIZE )
300 res = (res && (dst->o_size == src->o_size));
301 if ( src->o_valid & OBD_MD_FLATIME )
302 res = (res && (dst->o_atime == src->o_atime));
303 if ( src->o_valid & OBD_MD_FLMTIME )
304 res = (res && (dst->o_mtime == src->o_mtime));
305 if ( src->o_valid & OBD_MD_FLCTIME )
306 res = (res && (dst->o_ctime == src->o_ctime));
307 if ( src->o_valid & OBD_MD_FLFLAGS )
308 res = (res && (dst->o_flags == src->o_flags));
309 /* allocation of space */
310 if ( src->o_valid & OBD_MD_FLBLOCKS )
311 res = (res && (dst->o_blocks == src->o_blocks));
317 int obd_register_type(struct obd_ops *ops, char *nm);
318 int obd_unregister_type(char *nm);
321 struct list_head cli_chain;
322 struct obd_device *cli_obd;
324 unsigned long cli_prealloc_quota;
325 struct list_head cli_prealloc_inodes;
329 struct obd_prealloc_inode {
330 struct list_head obd_prealloc_chain;
334 /* generic operations shared by various OBD types */
335 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
336 int gen_multi_cleanup(struct obd_device *obddev);
337 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
338 int gen_multi_detach(struct obd_device *obddev);
339 int gen_connect (struct obd_conn *conn);
340 int gen_disconnect(struct obd_conn *conn);
341 struct obd_client *gen_client(struct obd_conn *);
342 int gen_cleanup(struct obd_device *obddev);
343 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
344 struct obd_conn *src_conn, struct obdo *src);
349 * ======== OBD IOCL Declarations ===========
360 /* for preallocation */
361 struct oic_prealloc_s {
363 uint32_t alloc; /* user sets it to the number of inodes
364 * requesting to be preallocated. kernel
365 * sets it to the actual number * of
366 * succesfully preallocated inodes */
367 obd_id ids[32]; /* actual inode numbers */
370 /* for getattr, setattr, create, destroy */
376 /* for copy, migrate */
378 unsigned int src_conn_id;
380 unsigned int dst_conn_id;
393 /* for punch, sync */
402 #define OBD_IOC_CREATE _IOR ('f', 3, long)
403 #define OBD_IOC_SETUP _IOW ('f', 4, long)
404 #define OBD_IOC_CLEANUP _IO ('f', 5 )
405 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
406 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
407 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
408 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
409 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
410 #define OBD_IOC_READ _IOWR('f', 11, long)
411 #define OBD_IOC_WRITE _IOWR('f', 12, long)
412 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
413 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
414 #define OBD_IOC_STATFS _IOWR('f', 15, long)
415 #define OBD_IOC_SYNC _IOR ('f', 16, long)
416 #define OBD_IOC_READ2 _IOWR('f', 17, long)
417 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
418 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
419 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
420 #define OBD_IOC_DETACH _IOWR('f', 21, long)
421 #define OBD_IOC_COPY _IOWR('f', 22, long)
422 #define OBD_IOC_MIGR _IOWR('f', 23, long)
424 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
428 extern void obd_sysctl_init (void);
429 extern void obd_sysctl_clean (void);
431 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
432 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
434 return -EINVAL; }} while (0)
438 #endif /* __LINUX_CLASS_OBD_H */