1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
4 * Copyright (C) 2001 Cluster File Systems, Inc.
6 * This code is issued under the GNU General Public License.
7 * See the file COPYING in this distribution
13 #include <linux/list.h>
16 #include <asm/segment.h>
17 #include <asm/uaccess.h>
18 #include <linux/types.h>
20 #include <linux/time.h>
22 #include <linux/lustre_lib.h>
23 #include <linux/lustre_idl.h>
24 #include <linux/obd.h>
26 #include <linux/obd_ext2.h>
27 #include <linux/obd_filter.h>
28 #include <linux/lustre_mds.h>
29 #include <linux/obd_snap.h>
30 #include <linux/obd_trace.h>
31 /* #include <linux/obd_fc.h> */
32 #include <linux/obd_raid1.h>
33 #include <linux/obd_rpc.h>
42 * ======== OBD Device Declarations ===========
46 #define OBD_PSDEV_MAJOR 186
47 #define MAX_OBD_DEVICES 8
51 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
54 #define OBD_ATTACHED 0x1
55 #define OBD_SET_UP 0x2
58 struct obd_device *oc_dev;
65 struct dentry *dentry; /* file system obd device names */
66 __u8 _uuid[16]; /* uuid obd device names */
71 /* corresponds to one of the obdx */
73 struct obd_type *obd_type;
77 obd_devicename obd_fsname;
78 struct proc_dir_entry *obd_proc_entry;
80 struct obd_conn obd_multi_conn[MAX_MULTI];
81 unsigned int obd_gen_last_id;
82 unsigned long obd_gen_prealloc_quota;
83 struct list_head obd_gen_clients;
86 struct filter_obd filter;
88 struct raid1_obd raid1;
90 struct trace_obd trace;
91 /* struct fc_obd fc; */
95 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
96 extern void proc_lustre_release_obd_device(struct obd_device *obd);
97 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
100 * ======== OBD Operations Declarations ===========
103 #define OBD_BRW_READ (READ)
104 #define OBD_BRW_WRITE (WRITE)
105 #define OBD_BRW_RWMASK (READ | WRITE)
106 #define OBD_BRW_CREATE (0x00000010UL)
109 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
111 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
112 obd_count *vallen, void **val);
113 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
114 obd_count vallen, void *val);
115 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
116 int (*o_detach)(struct obd_device *dev);
117 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
118 int (*o_cleanup)(struct obd_device *dev);
119 int (*o_connect)(struct obd_conn *conn);
120 int (*o_disconnect)(struct obd_conn *conn);
121 int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
122 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
123 int (*o_create)(struct obd_conn *conn, struct obdo *oa);
124 int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
125 int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
126 int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
127 int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
128 obd_size *count, obd_off offset);
129 int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
130 obd_size *count, obd_off offset);
131 int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
132 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
133 obd_size *count, obd_off *offset, obd_flag *flags);
134 int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
136 int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
138 int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
139 struct obdo *src, obd_size count, obd_off offset);
140 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
141 struct obd_conn *srconn, struct obdo *src,
142 obd_size count, obd_off offset);
143 int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
144 obd_id *startid, obd_gr group, void *data);
149 struct obd_conn *conn;
157 #define OBT(dev) dev->obd_type->typ_ops
158 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
162 /* This value is not arbitrarily chosen. KIO_STATIC_PAGES from linux/iobuf.h */
163 #define MAX_IOVEC (KIO_STATIC_PAGES - 1)
167 * ======== OBD Metadata Support ===========
170 extern int obd_init_obdo_cache(void);
171 extern void obd_cleanup_obdo_cache(void);
174 static inline int obdo_has_inline(struct obdo *obdo)
176 return (obdo->o_valid & OBD_MD_FLINLINE &&
177 obdo->o_obdflags & OBD_FL_INLINEDATA);
180 static inline int obdo_has_obdmd(struct obdo *obdo)
182 return (obdo->o_valid & OBD_MD_FLOBDMD &&
183 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
187 /* support routines */
188 extern kmem_cache_t *obdo_cachep;
190 static __inline__ struct obdo *obdo_alloc(void)
192 struct obdo *oa = NULL;
194 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
195 memset(oa, 0, sizeof (*oa));
200 static __inline__ void obdo_free(struct obdo *oa)
204 kmem_cache_free(obdo_cachep, oa);
209 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
210 obd_mode mode, obd_flag valid)
219 return ERR_PTR(-ENOMEM);
225 if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
234 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
236 unsigned int ia_valid = attr->ia_valid;
238 if (ia_valid & ATTR_ATIME) {
239 oa->o_atime = attr->ia_atime;
240 oa->o_valid |= OBD_MD_FLATIME;
242 if (ia_valid & ATTR_MTIME) {
243 oa->o_mtime = attr->ia_mtime;
244 oa->o_valid |= OBD_MD_FLMTIME;
246 if (ia_valid & ATTR_CTIME) {
247 oa->o_ctime = attr->ia_ctime;
248 oa->o_valid |= OBD_MD_FLCTIME;
250 if (ia_valid & ATTR_SIZE) {
251 oa->o_size = attr->ia_size;
252 oa->o_valid |= OBD_MD_FLSIZE;
254 if (ia_valid & ATTR_MODE) {
255 oa->o_mode = attr->ia_mode;
256 oa->o_valid |= OBD_MD_FLMODE;
257 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
258 oa->o_mode &= ~S_ISGID;
260 if (ia_valid & ATTR_UID)
262 oa->o_uid = attr->ia_uid;
263 oa->o_valid |= OBD_MD_FLUID;
265 if (ia_valid & ATTR_GID) {
266 oa->o_gid = attr->ia_gid;
267 oa->o_valid |= OBD_MD_FLGID;
272 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
274 unsigned int ia_valid = oa->o_valid;
276 memset(attr, 0, sizeof(*attr));
277 if (ia_valid & OBD_MD_FLATIME) {
278 attr->ia_atime = oa->o_atime;
279 attr->ia_valid |= ATTR_ATIME;
281 if (ia_valid & OBD_MD_FLMTIME) {
282 attr->ia_mtime = oa->o_mtime;
283 attr->ia_valid |= ATTR_MTIME;
285 if (ia_valid & OBD_MD_FLCTIME) {
286 attr->ia_ctime = oa->o_ctime;
287 attr->ia_valid |= ATTR_CTIME;
289 if (ia_valid & OBD_MD_FLSIZE) {
290 attr->ia_size = oa->o_size;
291 attr->ia_valid |= ATTR_SIZE;
293 if (ia_valid & OBD_MD_FLMODE) {
294 attr->ia_mode = oa->o_mode;
295 attr->ia_valid |= ATTR_MODE;
296 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
297 attr->ia_mode &= ~S_ISGID;
299 if (ia_valid & OBD_MD_FLUID)
301 attr->ia_uid = oa->o_uid;
302 attr->ia_valid |= ATTR_UID;
304 if (ia_valid & OBD_MD_FLGID) {
305 attr->ia_gid = oa->o_gid;
306 attr->ia_valid |= ATTR_GID;
311 /* WARNING: the file systems must take care not to tinker with
312 attributes they don't manage (such as blocks). */
314 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
316 if ( dst->o_valid & OBD_MD_FLID )
317 dst->o_id = src->i_ino;
318 if ( dst->o_valid & OBD_MD_FLATIME )
319 dst->o_atime = src->i_atime;
320 if ( dst->o_valid & OBD_MD_FLMTIME )
321 dst->o_mtime = src->i_mtime;
322 if ( dst->o_valid & OBD_MD_FLCTIME )
323 dst->o_ctime = src->i_ctime;
324 if ( dst->o_valid & OBD_MD_FLSIZE )
325 dst->o_size = src->i_size;
326 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
327 dst->o_blocks = src->i_blocks;
328 if ( dst->o_valid & OBD_MD_FLBLKSZ )
329 dst->o_blksize = src->i_blksize;
330 if ( dst->o_valid & OBD_MD_FLMODE )
331 dst->o_mode = src->i_mode;
332 if ( dst->o_valid & OBD_MD_FLUID )
333 dst->o_uid = src->i_uid;
334 if ( dst->o_valid & OBD_MD_FLGID )
335 dst->o_gid = src->i_gid;
336 if ( dst->o_valid & OBD_MD_FLFLAGS )
337 dst->o_flags = src->i_flags;
338 if ( dst->o_valid & OBD_MD_FLNLINK )
339 dst->o_nlink = src->i_nlink;
340 if ( dst->o_valid & OBD_MD_FLGENER )
341 dst->o_generation = src->i_generation;
344 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
347 if ( src->o_valid & OBD_MD_FLID )
348 dst->i_ino = src->o_id;
349 if ( src->o_valid & OBD_MD_FLATIME )
350 dst->i_atime = src->o_atime;
351 if ( src->o_valid & OBD_MD_FLMTIME )
352 dst->i_mtime = src->o_mtime;
353 if ( src->o_valid & OBD_MD_FLCTIME )
354 dst->i_ctime = src->o_ctime;
355 if ( src->o_valid & OBD_MD_FLSIZE )
356 dst->i_size = src->o_size;
357 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
358 dst->i_blocks = src->o_blocks;
359 if ( src->o_valid & OBD_MD_FLBLKSZ )
360 dst->i_blksize = src->o_blksize;
361 if ( src->o_valid & OBD_MD_FLMODE )
362 dst->i_mode = src->o_mode;
363 if ( src->o_valid & OBD_MD_FLUID )
364 dst->i_uid = src->o_uid;
365 if ( src->o_valid & OBD_MD_FLGID )
366 dst->i_gid = src->o_gid;
367 if ( src->o_valid & OBD_MD_FLFLAGS )
368 dst->i_flags = src->o_flags;
369 if ( src->o_valid & OBD_MD_FLNLINK )
370 dst->i_nlink = src->o_nlink;
371 if ( src->o_valid & OBD_MD_FLGENER )
372 dst->i_generation = src->o_generation;
377 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
380 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
381 src->o_id, src->o_valid, dst->o_id);
383 if ( src->o_valid & OBD_MD_FLATIME )
384 dst->o_atime = src->o_atime;
385 if ( src->o_valid & OBD_MD_FLMTIME )
386 dst->o_mtime = src->o_mtime;
387 if ( src->o_valid & OBD_MD_FLCTIME )
388 dst->o_ctime = src->o_ctime;
389 if ( src->o_valid & OBD_MD_FLSIZE )
390 dst->o_size = src->o_size;
391 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
392 dst->o_blocks = src->o_blocks;
393 if ( src->o_valid & OBD_MD_FLBLKSZ )
394 dst->o_blksize = src->o_blksize;
395 if ( src->o_valid & OBD_MD_FLMODE )
396 dst->o_mode = src->o_mode;
397 if ( src->o_valid & OBD_MD_FLUID )
398 dst->o_uid = src->o_uid;
399 if ( src->o_valid & OBD_MD_FLGID )
400 dst->o_gid = src->o_gid;
401 if ( src->o_valid & OBD_MD_FLFLAGS )
402 dst->o_flags = src->o_flags;
404 if ( src->o_valid & OBD_MD_FLOBDFLG )
405 dst->o_obdflags = src->o_obdflags;
407 if ( src->o_valid & OBD_MD_FLNLINK )
408 dst->o_nlink = src->o_nlink;
409 if ( src->o_valid & OBD_MD_FLGENER )
410 dst->o_generation = src->o_generation;
411 if ( src->o_valid & OBD_MD_FLINLINE &&
412 src->o_obdflags & OBD_FL_INLINEDATA) {
413 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
414 dst->o_obdflags |= OBD_FL_INLINEDATA;
416 if ( src->o_valid & OBD_MD_FLOBDMD &&
417 src->o_obdflags & OBD_FL_OBDMDEXISTS) {
418 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
419 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
422 dst->o_valid |= src->o_valid;
426 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
427 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
432 if ( compare & OBD_MD_FLATIME )
433 res = (res || (dst->o_atime != src->o_atime));
434 if ( compare & OBD_MD_FLMTIME )
435 res = (res || (dst->o_mtime != src->o_mtime));
436 if ( compare & OBD_MD_FLCTIME )
437 res = (res || (dst->o_ctime != src->o_ctime));
438 if ( compare & OBD_MD_FLSIZE )
439 res = (res || (dst->o_size != src->o_size));
440 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
441 res = (res || (dst->o_blocks != src->o_blocks));
442 if ( compare & OBD_MD_FLBLKSZ )
443 res = (res || (dst->o_blksize != src->o_blksize));
444 if ( compare & OBD_MD_FLMODE )
445 res = (res || (dst->o_mode != src->o_mode));
446 if ( compare & OBD_MD_FLUID )
447 res = (res || (dst->o_uid != src->o_uid));
448 if ( compare & OBD_MD_FLGID )
449 res = (res || (dst->o_gid != src->o_gid));
450 if ( compare & OBD_MD_FLFLAGS )
451 res = (res || (dst->o_flags != src->o_flags));
452 if ( compare & OBD_MD_FLNLINK )
453 res = (res || (dst->o_nlink != src->o_nlink));
454 if ( compare & OBD_MD_FLGENER )
455 res = (res || (dst->o_generation != src->o_generation));
456 /* XXX Don't know if thses should be included here - wasn't previously
457 if ( compare & OBD_MD_FLINLINE )
458 res = (res || memcmp(dst->o_inline, src->o_inline));
459 if ( compare & OBD_MD_FLOBDMD )
460 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
467 int obd_register_type(struct obd_ops *ops, char *nm);
468 int obd_unregister_type(char *nm);
471 struct list_head cli_chain;
472 struct obd_device *cli_obd;
474 unsigned long cli_prealloc_quota;
475 struct list_head cli_prealloc_inodes;
479 struct obd_prealloc_inode {
480 struct list_head obd_prealloc_chain;
484 /* generic operations shared by various OBD types */
485 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
486 int gen_multi_cleanup(struct obd_device *obddev);
487 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
488 int gen_multi_detach(struct obd_device *obddev);
489 int gen_connect (struct obd_conn *conn);
490 int gen_disconnect(struct obd_conn *conn);
491 struct obd_client *gen_client(const struct obd_conn *);
492 int gen_cleanup(struct obd_device *obddev);
493 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
494 struct obd_conn *src_conn, struct obdo *src,
495 obd_size count, obd_off offset);
500 extern void obd_sysctl_init (void);
501 extern void obd_sysctl_clean (void);
503 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
504 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
506 return -EINVAL; }} while (0)
510 #endif /* __LINUX_CLASS_OBD_H */