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>
16 #define OBD_PSDEV_MAJOR 186
17 #define MAX_OBD_DEVICES 8
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 60
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 */
56 struct list_head o_list;
61 static inline int obdo_has_inline(struct obdo *obdo)
63 return obdo->o_obdflags & OBD_FL_INLINEDATA;
66 static inline int obdo_has_obdmd(struct obdo *obdo)
68 return obdo->o_obdflags & OBD_FL_OBDMDEXISTS;
72 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
78 #define OBD_ATTACHED 0x1
79 #define OBD_SET_UP 0x2
82 struct obd_device *oc_dev;
86 /* corresponds to one of the obdx */
88 struct obd_type *obd_type;
93 struct obd_conn obd_multi_conn[MAX_MULTI];
94 unsigned int obd_gen_last_id;
95 unsigned long obd_gen_prealloc_quota;
96 struct list_head obd_gen_clients;
99 struct raid1_obd raid1;
100 struct snap_obd snap;
102 /* struct fc_obd fc; */
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 (*)(objid, 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
135 int obd_register_type(struct obd_ops *ops, char *nm);
136 int obd_unregister_type(char *nm);
139 struct list_head cli_chain;
140 struct obd_device *cli_obd;
142 unsigned long cli_prealloc_quota;
143 struct list_head cli_prealloc_inodes;
147 struct obd_prealloc_inode {
148 struct list_head obd_prealloc_chain;
152 /* generic operations shared by various OBD types */
153 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
154 int gen_multi_cleanup(struct obd_device *obddev);
155 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
156 int gen_multi_detach(struct obd_device *obddev);
157 int gen_connect (struct obd_conn *conn);
158 int gen_disconnect(struct obd_conn *conn);
159 struct obd_client *gen_client(struct obd_conn *);
160 int gen_cleanup(struct obd_device *obddev);
161 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
162 struct obd_conn *src_conn, struct obdo *src);
177 struct oic_prealloc_s {
178 unsigned long cli_id;
179 unsigned long alloc; /* user sets it to the number of inodes requesting
180 * to be preallocated. kernel sets it to the actual number
181 * of succesfully preallocated inodes */
182 long inodes[32]; /* actual inode numbers */
185 struct oic_create_s {
186 unsigned int conn_id;
187 unsigned long prealloc;
191 unsigned int conn_id;
197 unsigned int conn_id;
203 unsigned int conn_id;
210 struct oic_partition {
216 #define OBD_IOC_CREATE _IOR ('f', 3, long)
217 #define OBD_IOC_SETUP _IOW ('f', 4, long)
218 #define OBD_IOC_CLEANUP _IO ('f', 5 )
219 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
220 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
221 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
222 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
223 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
224 #define OBD_IOC_READ _IOWR('f', 11, long)
225 #define OBD_IOC_WRITE _IOWR('f', 12, long)
226 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
227 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
228 #define OBD_IOC_STATFS _IOWR('f', 15, long)
229 #define OBD_IOC_SYNC _IOR ('f', 16, long)
230 #define OBD_IOC_READ2 _IOWR('f', 17, long)
231 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
232 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
233 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
234 #define OBD_IOC_DETACH _IOWR('f', 21, long)
235 #define OBD_IOC_COPY _IOWR('f', 22, long)
236 #define OBD_IOC_MIGR _IOWR('f', 23, long)
238 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
242 extern void obd_sysctl_init (void);
243 extern void obd_sysctl_clean (void);
245 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
246 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
248 return -EINVAL; }} while (0)
251 /* support routines */
252 static __inline__ struct obdo *obd_empty_oa(void)
254 struct obdo *res = NULL;
256 /* XXX we should probably use a slab cache here */
257 OBD_ALLOC(res, struct obdo *, sizeof(*res));
258 memset(res, 0, sizeof (*res));
263 static __inline__ void obd_free_oa(struct obdo *oa)
267 OBD_FREE(oa, sizeof(*oa));
272 static __inline__ struct obdo *obd_oa_fromid(struct obd_conn *conn, obd_id id)
274 struct obdo *res = NULL;
276 OBD_ALLOC(res, struct obdo *, sizeof(*res));
281 memset(res, 0, sizeof(*res));
283 if (OBD(conn->oc_dev, getattr)(conn, res)) {
284 OBD_FREE(res, sizeof(*res));
292 #define OBD_MD_FLALL (~0UL)
293 #define OBD_MD_FLID (1UL)
294 #define OBD_MD_FLATIME (1UL<<1)
295 #define OBD_MD_FLMTIME (1UL<<2)
296 #define OBD_MD_FLCTIME (1UL<<3)
297 #define OBD_MD_FLSIZE (1UL<<4)
298 #define OBD_MD_FLBLOCKS (1UL<<5)
299 #define OBD_MD_FLBLKSZ (1UL<<6)
300 #define OBD_MD_FLMODE (1UL<<7)
301 #define OBD_MD_FLUID (1UL<<8)
302 #define OBD_MD_FLGID (1UL<<9)
303 #define OBD_MD_FLFLAGS (1UL<<10)
304 #define OBD_MD_FLOBDFLG (1UL<<11)
305 #define OBD_MD_FLINLINE (1UL<<12)
306 #define OBD_MD_FLOBDMD (1UL<<13)
310 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
312 /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
313 * fields given by the flags. The default is to copy the field
314 * given by the flags.
316 if (src->o_valid & OBD_MD_NO)
317 src->o_valid = ~src->o_valid;
319 CDEBUG(D_INODE, "flags %x\n", src->o_valid);
320 if ( src->o_valid & OBD_MD_FLMODE )
321 dst->i_mode = src->i_mode;
322 if ( src->o_valid & OBD_MD_FLUID )
323 dst->i_uid = src->i_uid;
324 if ( src->o_valid & OBD_MD_FLGID )
325 dst->i_gid = src->i_gid;
326 if ( src->o_valid & OBD_MD_FLSIZE )
327 dst->i_size = src->i_size;
328 if ( src->o_valid & OBD_MD_FLATIME )
329 dst->i_atime = src->i_atime;
330 if ( src->o_valid & OBD_MD_FLMTIME )
331 dst->i_mtime = src->i_mtime;
332 if ( src->o_valid & OBD_MD_FLCTIME )
333 dst->i_ctime = src->i_ctime;
334 if ( src->o_valid & OBD_MD_FLFLAGS )
335 dst->i_flags = src->i_flags;
336 /* allocation of space */
337 if ( src->o_valid & OBD_MD_FLBLOCKS )
338 dst->i_blocks = src->i_blocks;
339 if ( src->o_valid & OBD_MD_FLOBDMD && src->i_blocks == 0 ) {
340 CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino);
341 memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data,
342 sizeof(src->u.ext2_i.i_data));
344 CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n",
349 static __inline__ void obdo_cpy_from_inode(struct obdo *dst, struct inode *src)
353 static __inline__ void obdo_cpy_from_oa(struct inode *dst, struct obdo *src)
357 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src)
361 if ( src->o_valid & OBD_MD_FLMODE )
362 res = (res && (dst->i_mode == src->i_mode));
363 if ( src->o_valid & OBD_MD_FLUID )
364 res = (res && (dst->i_uid == src->i_uid));
365 if ( src->o_valid & OBD_MD_FLGID )
366 res = (res && (dst->i_gid == src->i_gid));
367 if ( src->o_valid & OBD_MD_FLSIZE )
368 res = (res && (dst->i_size == src->i_size));
369 if ( src->o_valid & OBD_MD_FLATIME )
370 res = (res && (dst->i_atime == src->i_atime));
371 if ( src->o_valid & OBD_MD_FLMTIME )
372 res = (res && (dst->i_mtime == src->i_mtime));
373 if ( src->o_valid & OBD_MD_FLCTIME )
374 res = (res && (dst->i_ctime == src->i_ctime));
375 if ( src->o_valid & OBD_MD_FLFLAGS )
376 res = (res && (dst->i_flags == src->i_flags));
377 /* allocation of space */
378 if ( src->o_valid & OBD_MD_FLBLOCKS )
379 res = (res && (dst->i_blocks == src->i_blocks));
384 #endif /* __LINUX_CLASS_OBD_H */