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_sim.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 120
17 #define MAX_OBD_DEVICES 8
20 typedef unsigned long objid;
21 typedef struct inode obdattr;
33 unsigned long oa_blksize;
34 unsigned long oa_blocks;
36 struct obd_ops *oa_op;
41 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
47 #define OBD_ATTACHED 0x1
48 #define OBD_SET_UP 0x2
51 struct obd_device *oc_dev;
55 /* corresponds to one of the obdx */
57 struct obd_type *obd_type;
62 struct obd_conn obd_multi_conn[MAX_MULTI];
63 unsigned int obd_gen_last_id;
64 unsigned long obd_gen_prealloc_quota;
65 struct list_head obd_gen_clients;
68 struct raid1_obd raid1;
71 /* struct fc_obd fc; */
76 int (*o_attach)(struct obd_device *, int len, void *);
77 int (*o_detach)(struct obd_device *);
78 int (*o_format)(struct obd_device *, int len, void *);
79 int (*o_partition)(struct obd_device *, int len, void *);
80 int (*o_connect)(struct obd_conn *conn);
81 int (*o_disconnect)(struct obd_conn *);
82 int (*o_setup) (struct obd_device *dev, int len, void *data);
83 int (*o_cleanup)(struct obd_device *dev);
84 int (*o_setattr)(struct obd_conn *, obdattr *oa);
85 int (*o_getattr)(struct obd_conn *, obdattr *oa);
86 int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
87 int (*o_create)(struct obd_conn *, int prealloc_ino, int *er);
88 int (*o_destroy)(struct obd_conn *, obdattr *oa);
89 int (*o_read)(struct obd_conn *, obdattr *ino, char *buf, unsigned long *count, loff_t offset);
90 int (*o_read2)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
91 int (*o_write)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
92 int (*o_brw)(int rw, struct obd_conn * conn, obdattr *obj, struct page *page, int create);
93 int (*o_preallocate)(struct obd_conn *, unsigned long *req, long inodes[32]);
94 int (*o_get_info)(struct obd_conn *, int keylen, void *key, int *vallen, void **val);
95 int (*o_set_info)(struct obd_conn *, int keylen, void *key, int vallen, void *val);
96 int (*o_migrate)(struct obd_conn *, obdattr *src, obdattr *dst);
97 int (*o_copy)(struct obd_conn *dev, obdattr *source, obdattr *target);
98 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
99 int (*o_iterate)(struct obd_conn *, objid, int (*)(objid, void *), void *);
103 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
105 int obd_register_type(struct obd_ops *ops, char *nm);
106 int obd_unregister_type(char *nm);
109 struct list_head cli_chain;
110 struct obd_device *cli_obd;
112 unsigned long cli_prealloc_quota;
113 struct list_head cli_prealloc_inodes;
117 struct obd_prealloc_inode {
118 struct list_head obd_prealloc_chain;
122 /* generic operations shared by various OBD types */
123 int gen_connect (struct obd_conn *conn);
124 int gen_disconnect(struct obd_conn *conn);
125 int gen_multi_setup(struct obd_device *obddev, int len, void *data);
126 int gen_multi_cleanup(struct obd_device *obddev);
127 int gen_multi_attach(struct obd_device *obddev, int len, void *data);
128 struct obd_client *gen_client(struct obd_conn *);
129 int gen_multi_detach(struct obd_device *obddev);
130 int gen_cleanup(struct obd_device *obddev);
131 int gen_copy_data(struct obd_conn *, obdattr *source, obdattr *target);
146 struct oic_prealloc_s {
147 unsigned long cli_id;
148 unsigned long alloc; /* user sets it to the number of inodes requesting
149 * to be preallocated. kernel sets it to the actual number
150 * of succesfully preallocated inodes */
151 long inodes[32]; /* actual inode numbers */
154 struct oic_create_s {
155 unsigned int conn_id;
156 unsigned long prealloc;
160 unsigned int conn_id;
166 unsigned int conn_id;
172 unsigned int conn_id;
179 struct oic_partition {
185 #define OBD_IOC_CREATE _IOR ('f', 3, long)
186 #define OBD_IOC_SETUP _IOW ('f', 4, long)
187 #define OBD_IOC_CLEANUP _IO ('f', 5 )
188 #define OBD_IOC_DESTROY _IOW ('f', 6, long)
189 #define OBD_IOC_PREALLOCATE _IOWR('f', 7, long)
190 #define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 )
191 #define OBD_IOC_SETATTR _IOW ('f', 9, long)
192 #define OBD_IOC_GETATTR _IOR ('f', 10, long)
193 #define OBD_IOC_READ _IOWR('f', 11, long)
194 #define OBD_IOC_WRITE _IOWR('f', 12, long)
195 #define OBD_IOC_CONNECT _IOR ('f', 13, long)
196 #define OBD_IOC_DISCONNECT _IOW ('f', 14, long)
197 #define OBD_IOC_STATFS _IOWR('f', 15, long)
198 #define OBD_IOC_SYNC _IOR ('f', 16, long)
199 #define OBD_IOC_READ2 _IOWR('f', 17, long)
200 #define OBD_IOC_FORMAT _IOWR('f', 18, long)
201 #define OBD_IOC_PARTITION _IOWR('f', 19, long)
202 #define OBD_IOC_ATTACH _IOWR('f', 20, long)
203 #define OBD_IOC_DETACH _IOWR('f', 21, long)
204 #define OBD_IOC_COPY _IOWR('f', 22, long)
205 #define OBD_IOC_MIGR _IOWR('f', 23, long)
207 #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 )
211 extern void obd_sysctl_init (void);
212 extern void obd_sysctl_clean (void);
214 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
215 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
217 return -EINVAL; }} while (0)
220 /* support routines */
221 static __inline__ obdattr *obd_empty_oa(void)
224 OBD_ALLOC(res, obdattr *, sizeof(*res));
225 memset(res, 0, sizeof (*res));
229 static __inline__ void obd_free_oa(obdattr *oa)
233 OBD_FREE(oa,sizeof(*oa));
238 static __inline__ obdattr *obd_oa_fromid(struct obd_conn *conn, objid id)
242 OBD_ALLOC(res, obdattr *, sizeof(*res));
247 memset(res, 0, sizeof(*res));
249 if (conn->oc_dev->obd_type->typ_ops->o_getattr(conn, res)) {
250 OBD_FREE(res, sizeof(*res));
258 #define OBD_MD_FLMODE (1UL<<1)
259 #define OBD_MD_FLUID (1UL<<2)
260 #define OBD_MD_FLGID (1UL<<3)
261 #define OBD_MD_FLSIZE (1UL<<4)
262 #define OBD_MD_FLATIME (1UL<<5)
263 #define OBD_MD_FLMTIME (1UL<<6)
264 #define OBD_MD_FLCTIME (1UL<<7)
265 #define OBD_MD_FLFLAGS (1UL<<8)
266 #define OBD_MD_FLBLOCKS (1UL<<9)
267 #define OBD_MD_FLOBDMD (1UL<<10)
270 static __inline__ void obdo_cpy_md(obdattr *dst, obdattr *src, int mask)
272 CDEBUG(D_INODE, "flags %x\n", mask);
273 if ( ! (mask & OBD_MD_FLMODE) )
274 dst->i_mode = src->i_mode;
275 if ( ! (mask & OBD_MD_FLUID) )
276 dst->i_uid = src->i_uid;
277 if ( ! (mask & OBD_MD_FLGID) )
278 dst->i_gid = src->i_gid;
279 if ( ! (mask & OBD_MD_FLSIZE) )
280 dst->i_size = src->i_size;
281 if ( ! (mask & OBD_MD_FLATIME) )
282 dst->i_atime = src->i_atime;
283 if ( ! (mask & OBD_MD_FLMTIME) )
284 dst->i_mtime = src->i_mtime;
285 if ( ! (mask & OBD_MD_FLCTIME) )
286 dst->i_ctime = src->i_ctime;
287 if ( ! (mask & OBD_MD_FLFLAGS) )
288 dst->i_flags = src->i_flags;
289 /* allocation of space */
290 if ( ! (mask & OBD_MD_FLBLOCKS) )
291 dst->i_blocks = src->i_blocks;
292 if ( ! (mask & OBD_MD_FLOBDMD) && !src->i_blocks ) {
293 CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino);
294 memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data,
295 sizeof(src->u.ext2_i.i_data));
297 CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n", src->i_ino);
301 static __inline__ int obdo_cmp_md(obdattr *dst, obdattr *src, int mask)
304 if ( ! (mask & OBD_MD_FLMODE) )
305 res = (res && (dst->i_mode == src->i_mode));
306 if ( ! (mask & OBD_MD_FLUID) )
307 res = (res && (dst->i_uid == src->i_uid));
308 if ( ! (mask & OBD_MD_FLGID) )
309 res = (res && (dst->i_gid == src->i_gid));
310 if ( ! (mask & OBD_MD_FLSIZE) )
311 res = (res && (dst->i_size == src->i_size));
312 if ( ! (mask & OBD_MD_FLATIME) )
313 res = (res && (dst->i_atime == src->i_atime));
314 if ( ! (mask & OBD_MD_FLMTIME) )
315 res = (res && (dst->i_mtime == src->i_mtime));
316 if ( ! (mask & OBD_MD_FLCTIME) )
317 res = (res && (dst->i_ctime == src->i_ctime));
318 if ( ! (mask & OBD_MD_FLFLAGS) )
319 res = (res && (dst->i_flags == src->i_flags));
320 /* allocation of space */
321 if ( ! (mask & OBD_MD_FLBLOCKS) )
322 res = (res && (dst->i_blocks == src->i_blocks));
327 static __inline__ void obd_cpy_appmd(obdattr *dst, obdattr *src)
329 dst->i_mode = src->i_mode;
330 dst->i_uid = src->i_uid;
331 dst->i_gid = src->i_gid;
332 dst->i_size = src->i_size;
333 dst->i_atime = src->i_atime;
334 dst->i_mtime = src->i_mtime;
335 dst->i_ctime = src->i_ctime;
336 dst->i_flags = src->i_flags;
337 /* allocation of space */
338 dst->i_blocks = src->i_blocks;
341 #endif /* __LINUX_CLASS_OBD_H */