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 obd_id;
21 typedef uint32 obd_mode;
22 typedef uint64 obd_off;
23 typedef uint64 obd_size;
24 typedef uint32 obd_uid;
25 typedef uint32 obd_gid;
26 typedef uint32 obd_mode;
27 typedef uint32 obd_mode;
28 typedef uint32 obd_mode;
30 #define OBD_INLINE_DATASZ 60
33 #define OBD_FL_INLINED (1UL)
34 #define OBD_FL_OBDMDEXISTS (1UL << 1)
37 uint32 o_valid; /* hot fields in this obdo */
49 unsigned long o_blksize;
50 unsigned long o_blocks;
51 char o_inline_data[OBD_INLINE_DATASZ];
57 static inline int obdo_has_inlinedata(struct obdo *obdo)
59 return obdo->o_obdflags & OBD_FL_INLINEDATA;
62 static inline int obdo_has_omd(struct obdo *obdo)
64 return obdo->o_obdflags & OBD_FL_OBDMDEXISTS;
68 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 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
104 int (*o_get_info)(struct obd_conn *, int keylen, void *key, int *vallen, void **val);
105 int (*o_set_info)(struct obd_conn *, int keylen, void *key, int vallen, void *val);
106 int (*o_attach)(struct obd_device *, int len, void *);
107 int (*o_detach)(struct obd_device *);
108 int (*o_setup) (struct obd_device *dev, int len, void *data);
109 int (*o_cleanup)(struct obd_device *dev);
110 int (*o_connect)(struct obd_conn *conn);
111 int (*o_disconnect)(struct obd_conn *);
112 int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
113 int (*o_preallocate)(struct obd_conn *, uint32 *req, objid ids[32]);
114 int (*o_create)(struct obd_conn *, obdattr *new);
115 int (*o_destroy)(struct obd_conn *, obdattr *oa);
116 int (*o_setattr)(struct obd_conn *, obdattr *oa);
117 int (*o_getattr)(struct obd_conn *, obdattr *oa);
118 int (*o_read)(struct obd_conn *, obdattr *oa, char *buf, obd_size *count, obd_off offset);
119 int (*o_write)(struct obd_conn *, obdattr *oa, char *buf, obd_size *count, obd_off offset);
120 int (*o_brw)(int rw, struct obd_conn * conn, obdattr *oa, char *buf, obd_size *count, obd_off offset, uint32 flags);
121 int (*o_punch)(struct obd_conn *, obdattr *tgt, obd_size count, obd_off start);
122 int (*o_migrate)(struct obd_conn *, obdattr *dst, obdattr *src, obd_size count, obd_off start);
123 int (*o_copy)(struct obd_conn *dstconn, obdattr *dst, struct obd_conn *srconn, obdattr *src, obd_size count, obd_off start);
124 int (*o_iterate)(struct obd_conn *, int (*)(objid, void *), objid start, void *);
128 #define OBT(dev) dev->obd_type->typ_ops
129 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
131 int obd_register_type(struct obd_ops *ops, char *nm);
132 int obd_unregister_type(char *nm);
135 struct list_head cli_chain;
136 struct obd_device *cli_obd;
138 unsigned long cli_prealloc_quota;
139 struct list_head cli_prealloc_inodes;
143 struct obd_prealloc_inode {
144 struct list_head obd_prealloc_chain;
148 /* generic operations shared by various OBD types */
149 int gen_connect (struct obd_conn *conn);
150 int gen_disconnect(struct obd_conn *conn);
151 int gen_multi_setup(struct obd_device *obddev, int len, void *data);
152 int gen_multi_cleanup(struct obd_device *obddev);
153 int gen_multi_attach(struct obd_device *obddev, int len, void *data);
154 struct obd_client *gen_client(struct obd_conn *);
155 int gen_multi_detach(struct obd_device *obddev);
156 int gen_cleanup(struct obd_device *obddev);
157 int gen_copy_data(struct obd_conn *, obdattr *source, obdattr *target);
172 struct oic_prealloc_s {
173 unsigned long cli_id;
174 unsigned long alloc; /* user sets it to the number of inodes requesting
175 * to be preallocated. kernel sets it to the actual number
176 * of succesfully preallocated inodes */
177 long inodes[32]; /* actual inode numbers */
180 struct oic_create_s {
181 unsigned int conn_id;
182 unsigned long prealloc;
186 unsigned int conn_id;
192 unsigned int conn_id;
198 unsigned int conn_id;
205 struct oic_partition {
211 #define OBD_IOC_CREATE _IOR ('f', 3, long)
212 #define OBD_IOC_SETUP _IOW ('f', 4, long)
213 #define OBD_IOC_CLEANUP _IO ('f', 5 )
214 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
215 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
216 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
217 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
218 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
219 #define OBD_IOC_READ _IOWR('f', 11, long)
220 #define OBD_IOC_WRITE _IOWR('f', 12, long)
221 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
222 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
223 #define OBD_IOC_STATFS _IOWR('f', 15, long)
224 #define OBD_IOC_SYNC _IOR ('f', 16, long)
225 #define OBD_IOC_READ2 _IOWR('f', 17, long)
226 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
227 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
228 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
229 #define OBD_IOC_DETACH _IOWR('f', 21, long)
230 #define OBD_IOC_COPY _IOWR('f', 22, long)
231 #define OBD_IOC_MIGR _IOWR('f', 23, long)
233 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
237 extern void obd_sysctl_init (void);
238 extern void obd_sysctl_clean (void);
240 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
241 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
243 return -EINVAL; }} while (0)
246 /* support routines */
247 static __inline__ obdattr *obd_empty_oa(void)
250 OBD_ALLOC(res, obdattr *, sizeof(*res));
251 memset(res, 0, sizeof (*res));
255 static __inline__ void obd_free_oa(obdattr *oa)
259 OBD_FREE(oa,sizeof(*oa));
264 static __inline__ obdattr *obd_oa_fromid(struct obd_conn *conn, objid id)
268 OBD_ALLOC(res, obdattr *, sizeof(*res));
273 memset(res, 0, sizeof(*res));
275 if (conn->oc_dev->obd_type->typ_ops->o_getattr(conn, res)) {
276 OBD_FREE(res, sizeof(*res));
284 #define OBD_MD_NO (1UL) /* negates meaning of all flags */
285 #define OBD_MD_ALL (OBD_MD_NO) /* passing NO with no other flags == ALL */
286 #define OBD_MD_FLMODE (1UL<<1)
287 #define OBD_MD_FLUID (1UL<<2)
288 #define OBD_MD_FLGID (1UL<<3)
289 #define OBD_MD_FLSIZE (1UL<<4)
290 #define OBD_MD_FLATIME (1UL<<5)
291 #define OBD_MD_FLMTIME (1UL<<6)
292 #define OBD_MD_FLCTIME (1UL<<7)
293 #define OBD_MD_FLFLAGS (1UL<<8)
294 #define OBD_MD_FLBLOCKS (1UL<<9)
295 #define OBD_MD_FLOBDMD (1UL<<10)
296 #define OBD_MD_INLINED (1UL<<11)
300 static __inline__ void obdo_cpy_md(obdattr *dst, obdattr *src)
302 /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
303 * fields given by the flags. The default is to copy the field
304 * given by the flags.
306 if (src->o_valid & OBD_MD_NO)
307 src->o_valid = ~src->o_valid;
309 CDEBUG(D_INODE, "flags %x\n", src->o_valid);
310 if ( src->o_valid & OBD_MD_FLMODE )
311 dst->i_mode = src->i_mode;
312 if ( src->o_valid & OBD_MD_FLUID )
313 dst->i_uid = src->i_uid;
314 if ( src->o_valid & OBD_MD_FLGID )
315 dst->i_gid = src->i_gid;
316 if ( src->o_valid & OBD_MD_FLSIZE )
317 dst->i_size = src->i_size;
318 if ( src->o_valid & OBD_MD_FLATIME )
319 dst->i_atime = src->i_atime;
320 if ( src->o_valid & OBD_MD_FLMTIME )
321 dst->i_mtime = src->i_mtime;
322 if ( src->o_valid & OBD_MD_FLCTIME )
323 dst->i_ctime = src->i_ctime;
324 if ( src->o_valid & OBD_MD_FLFLAGS )
325 dst->i_flags = src->i_flags;
326 /* allocation of space */
327 if ( src->o_valid & OBD_MD_FLBLOCKS )
328 dst->i_blocks = src->i_blocks;
329 if ( src->o_valid & OBD_MD_FLOBDMD && src->i_blocks == 0 ) {
330 CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino);
331 memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data,
332 sizeof(src->u.ext2_i.i_data));
334 CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n",
340 static __inline__ int obdo_cmp_md(obdattr *dst, obdattr *src)
344 /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
345 * fields given by the flags. The default is to copy the field
346 * given by the flags.
348 if (src->o_valid & OBD_MD_NO)
349 src->o_valid = ~src->o_valid;
351 if ( src->o_valid & OBD_MD_FLMODE )
352 res = (res && (dst->i_mode == src->i_mode));
353 if ( src->o_valid & OBD_MD_FLUID )
354 res = (res && (dst->i_uid == src->i_uid));
355 if ( src->o_valid & OBD_MD_FLGID )
356 res = (res && (dst->i_gid == src->i_gid));
357 if ( src->o_valid & OBD_MD_FLSIZE )
358 res = (res && (dst->i_size == src->i_size));
359 if ( src->o_valid & OBD_MD_FLATIME )
360 res = (res && (dst->i_atime == src->i_atime));
361 if ( src->o_valid & OBD_MD_FLMTIME )
362 res = (res && (dst->i_mtime == src->i_mtime));
363 if ( src->o_valid & OBD_MD_FLCTIME )
364 res = (res && (dst->i_ctime == src->i_ctime));
365 if ( src->o_valid & OBD_MD_FLFLAGS )
366 res = (res && (dst->i_flags == src->i_flags));
367 /* allocation of space */
368 if ( src->o_valid & OBD_MD_FLBLOCKS )
369 res = (res && (dst->i_blocks == src->i_blocks));
374 #endif /* __LINUX_CLASS_OBD_H */