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_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;
33 #define OBD_FL_INLINEDATA (1UL)
34 #define OBD_FL_OBDMDEXISTS (1UL << 1)
36 #define OBD_INLINESZ 60
37 #define OBD_OBDMDSZ 64
38 /* Note: 64-bit types are 64-bit aligned in structure */
47 obd_blksize o_blksize;
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;
62 * ======== OBD Device Declarations ===========
66 #define OBD_PSDEV_MAJOR 186
67 #define MAX_OBD_DEVICES 8
71 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
74 #define OBD_ATTACHED 0x1
75 #define OBD_SET_UP 0x2
78 struct obd_device *oc_dev;
82 /* corresponds to one of the obdx */
84 struct obd_type *obd_type;
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;
95 struct raid1_obd raid1;
98 /* struct fc_obd fc; */
103 * ======== OBD Operations Declarations ===========
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 *);
134 #define OBT(dev) dev->obd_type->typ_ops
135 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
139 * ======== OBD Metadata Support ===========
142 extern int obd_init_obdo_cache(void);
145 static inline int obdo_has_inline(struct obdo *obdo)
147 return obdo->o_obdflags & OBD_FL_INLINEDATA;
150 static inline int obdo_has_obdmd(struct obdo *obdo)
152 return obdo->o_obdflags & OBD_FL_OBDMDEXISTS;
155 /* support routines */
156 extern kmem_cache_t *obdo_cachep;
158 static __inline__ struct obdo *obdo_alloc(void)
160 struct obdo *res = NULL;
162 res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
163 memset(res, 0, sizeof (*res));
168 static __inline__ void obdo_free(struct obdo *oa)
172 kmem_cache_free(obdo_cachep, oa);
177 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id)
179 struct obdo *res = NULL;
181 res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
186 memset(res, 0, sizeof(*res));
188 if (OBP(conn->oc_dev, getattr)(conn, res)) {
189 OBD_FREE(res, sizeof(*res));
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)
215 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
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;
240 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
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;
266 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
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;
292 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src)
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));
320 int obd_register_type(struct obd_ops *ops, char *nm);
321 int obd_unregister_type(char *nm);
324 struct list_head cli_chain;
325 struct obd_device *cli_obd;
327 unsigned long cli_prealloc_quota;
328 struct list_head cli_prealloc_inodes;
332 struct obd_prealloc_inode {
333 struct list_head obd_prealloc_chain;
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);
353 * ======== OBD IOCL Declarations ===========
364 /* for preallocation */
365 struct oic_prealloc_s {
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 */
374 /* for getattr, setattr, create, destroy */
380 /* for copy, migrate */
382 unsigned int src_conn_id;
384 unsigned int dst_conn_id;
397 /* for punch, sync */
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)
428 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
432 extern void obd_sysctl_init (void);
433 extern void obd_sysctl_clean (void);
435 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
436 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
438 return -EINVAL; }} while (0)
442 #endif /* __LINUX_CLASS_OBD_H */