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>
33 * ======== OBD Device Declarations ===========
37 #define OBD_PSDEV_MAJOR 186
38 #define MAX_OBD_DEVICES 8
42 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
45 #define OBD_ATTACHED 0x1
46 #define OBD_SET_UP 0x2
49 struct obd_device *oc_dev;
59 struct dentry *dentry; /* file system obd device names */
60 __u8 _uuid[16]; /* uuid obd device names */
63 #include <linux/obd_ext2.h>
64 #include <linux/obd_filter.h>
65 #include <linux/lustre_mds.h>
66 #include <linux/obd_snap.h>
67 #include <linux/obd_trace.h>
68 /* #include <linux/obd_fc.h> */
69 #include <linux/obd_raid1.h>
70 #include <linux/obd_ost.h>
73 /* corresponds to one of the obdx */
75 struct obd_type *obd_type;
79 obd_devicename obd_fsname;
80 struct proc_dir_entry *obd_proc_entry;
82 struct obd_conn obd_multi_conn[MAX_MULTI];
83 unsigned int obd_gen_last_id;
84 unsigned long obd_gen_prealloc_quota;
85 struct list_head obd_gen_clients;
88 struct filter_obd filter;
90 struct raid1_obd raid1;
92 struct trace_obd trace;
97 extern struct proc_dir_entry *proc_lustre_register_obd_device(struct obd_device *obd);
98 extern void proc_lustre_release_obd_device(struct obd_device *obd);
99 extern void proc_lustre_remove_obd_entry(const char* name, struct obd_device *obd);
102 * ======== OBD Operations Declarations ===========
105 #define OBD_BRW_READ (READ)
106 #define OBD_BRW_WRITE (WRITE)
107 #define OBD_BRW_RWMASK (READ | WRITE)
108 #define OBD_BRW_CREATE (0x00000010UL)
111 int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg,
113 int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key,
114 obd_count *vallen, void **val);
115 int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key,
116 obd_count vallen, void *val);
117 int (*o_attach)(struct obd_device *dev, obd_count len, void *data);
118 int (*o_detach)(struct obd_device *dev);
119 int (*o_setup) (struct obd_device *dev, obd_count len, void *data);
120 int (*o_cleanup)(struct obd_device *dev);
121 int (*o_connect)(struct obd_conn *conn);
122 int (*o_disconnect)(struct obd_conn *conn);
123 int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs);
124 int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids);
125 int (*o_create)(struct obd_conn *conn, struct obdo *oa);
126 int (*o_destroy)(struct obd_conn *conn, struct obdo *oa);
127 int (*o_setattr)(struct obd_conn *conn, struct obdo *oa);
128 int (*o_getattr)(struct obd_conn *conn, struct obdo *oa);
129 int (*o_read)(struct obd_conn *conn, struct obdo *oa, char *buf,
130 obd_size *count, obd_off offset);
131 int (*o_write)(struct obd_conn *conn, struct obdo *oa, char *buf,
132 obd_size *count, obd_off offset);
133 int (*o_brw)(int rw, struct obd_conn *conn, obd_count num_oa,
134 struct obdo **oa, obd_count *oa_bufs, struct page **buf,
135 obd_size *count, obd_off *offset, obd_flag *flags);
136 int (*o_punch)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
138 int (*o_sync)(struct obd_conn *conn, struct obdo *tgt, obd_size count,
140 int (*o_migrate)(struct obd_conn *conn, struct obdo *dst,
141 struct obdo *src, obd_size count, obd_off offset);
142 int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst,
143 struct obd_conn *srconn, struct obdo *src,
144 obd_size count, obd_off offset);
145 int (*o_iterate)(struct obd_conn *conn, int (*)(obd_id, obd_gr, void *),
146 obd_id *startid, obd_gr group, void *data);
151 struct obd_conn *conn;
159 #define OBT(dev) dev->obd_type->typ_ops
160 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
164 /* This value is not arbitrarily chosen. KIO_STATIC_PAGES from linux/iobuf.h */
165 #define MAX_IOVEC (KIO_STATIC_PAGES - 1)
169 * ======== OBD Metadata Support ===========
172 extern int obd_init_obdo_cache(void);
173 extern void obd_cleanup_obdo_cache(void);
176 static inline int obdo_has_inline(struct obdo *obdo)
178 return (obdo->o_valid & OBD_MD_FLINLINE &&
179 obdo->o_obdflags & OBD_FL_INLINEDATA);
182 static inline int obdo_has_obdmd(struct obdo *obdo)
184 return (obdo->o_valid & OBD_MD_FLOBDMD &&
185 obdo->o_obdflags & OBD_FL_OBDMDEXISTS);
189 /* support routines */
190 extern kmem_cache_t *obdo_cachep;
192 static __inline__ struct obdo *obdo_alloc(void)
194 struct obdo *oa = NULL;
196 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
197 memset(oa, 0, sizeof (*oa));
202 static __inline__ void obdo_free(struct obdo *oa)
206 kmem_cache_free(obdo_cachep, oa);
211 static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id,
212 obd_mode mode, obd_flag valid)
221 return ERR_PTR(-ENOMEM);
227 if ((err = OBP(conn->oc_dev, getattr)(conn, oa))) {
236 static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
238 unsigned int ia_valid = attr->ia_valid;
240 if (ia_valid & ATTR_ATIME) {
241 oa->o_atime = attr->ia_atime;
242 oa->o_valid |= OBD_MD_FLATIME;
244 if (ia_valid & ATTR_MTIME) {
245 oa->o_mtime = attr->ia_mtime;
246 oa->o_valid |= OBD_MD_FLMTIME;
248 if (ia_valid & ATTR_CTIME) {
249 oa->o_ctime = attr->ia_ctime;
250 oa->o_valid |= OBD_MD_FLCTIME;
252 if (ia_valid & ATTR_SIZE) {
253 oa->o_size = attr->ia_size;
254 oa->o_valid |= OBD_MD_FLSIZE;
256 if (ia_valid & ATTR_MODE) {
257 oa->o_mode = attr->ia_mode;
258 oa->o_valid |= OBD_MD_FLMODE;
259 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
260 oa->o_mode &= ~S_ISGID;
262 if (ia_valid & ATTR_UID)
264 oa->o_uid = attr->ia_uid;
265 oa->o_valid |= OBD_MD_FLUID;
267 if (ia_valid & ATTR_GID) {
268 oa->o_gid = attr->ia_gid;
269 oa->o_valid |= OBD_MD_FLGID;
274 static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa)
276 unsigned int ia_valid = oa->o_valid;
278 memset(attr, 0, sizeof(*attr));
279 if (ia_valid & OBD_MD_FLATIME) {
280 attr->ia_atime = oa->o_atime;
281 attr->ia_valid |= ATTR_ATIME;
283 if (ia_valid & OBD_MD_FLMTIME) {
284 attr->ia_mtime = oa->o_mtime;
285 attr->ia_valid |= ATTR_MTIME;
287 if (ia_valid & OBD_MD_FLCTIME) {
288 attr->ia_ctime = oa->o_ctime;
289 attr->ia_valid |= ATTR_CTIME;
291 if (ia_valid & OBD_MD_FLSIZE) {
292 attr->ia_size = oa->o_size;
293 attr->ia_valid |= ATTR_SIZE;
295 if (ia_valid & OBD_MD_FLMODE) {
296 attr->ia_mode = oa->o_mode;
297 attr->ia_valid |= ATTR_MODE;
298 if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
299 attr->ia_mode &= ~S_ISGID;
301 if (ia_valid & OBD_MD_FLUID)
303 attr->ia_uid = oa->o_uid;
304 attr->ia_valid |= ATTR_UID;
306 if (ia_valid & OBD_MD_FLGID) {
307 attr->ia_gid = oa->o_gid;
308 attr->ia_valid |= ATTR_GID;
313 /* WARNING: the file systems must take care not to tinker with
314 attributes they don't manage (such as blocks). */
316 static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src)
318 if ( dst->o_valid & OBD_MD_FLID )
319 dst->o_id = src->i_ino;
320 if ( dst->o_valid & OBD_MD_FLATIME )
321 dst->o_atime = src->i_atime;
322 if ( dst->o_valid & OBD_MD_FLMTIME )
323 dst->o_mtime = src->i_mtime;
324 if ( dst->o_valid & OBD_MD_FLCTIME )
325 dst->o_ctime = src->i_ctime;
326 if ( dst->o_valid & OBD_MD_FLSIZE )
327 dst->o_size = src->i_size;
328 if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
329 dst->o_blocks = src->i_blocks;
330 if ( dst->o_valid & OBD_MD_FLBLKSZ )
331 dst->o_blksize = src->i_blksize;
332 if ( dst->o_valid & OBD_MD_FLMODE )
333 dst->o_mode = src->i_mode;
334 if ( dst->o_valid & OBD_MD_FLUID )
335 dst->o_uid = src->i_uid;
336 if ( dst->o_valid & OBD_MD_FLGID )
337 dst->o_gid = src->i_gid;
338 if ( dst->o_valid & OBD_MD_FLFLAGS )
339 dst->o_flags = src->i_flags;
340 if ( dst->o_valid & OBD_MD_FLNLINK )
341 dst->o_nlink = src->i_nlink;
342 if ( dst->o_valid & OBD_MD_FLGENER )
343 dst->o_generation = src->i_generation;
346 static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src)
349 if ( src->o_valid & OBD_MD_FLID )
350 dst->i_ino = src->o_id;
351 if ( src->o_valid & OBD_MD_FLATIME )
352 dst->i_atime = src->o_atime;
353 if ( src->o_valid & OBD_MD_FLMTIME )
354 dst->i_mtime = src->o_mtime;
355 if ( src->o_valid & OBD_MD_FLCTIME )
356 dst->i_ctime = src->o_ctime;
357 if ( src->o_valid & OBD_MD_FLSIZE )
358 dst->i_size = src->o_size;
359 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
360 dst->i_blocks = src->o_blocks;
361 if ( src->o_valid & OBD_MD_FLBLKSZ )
362 dst->i_blksize = src->o_blksize;
363 if ( src->o_valid & OBD_MD_FLMODE )
364 dst->i_mode = src->o_mode;
365 if ( src->o_valid & OBD_MD_FLUID )
366 dst->i_uid = src->o_uid;
367 if ( src->o_valid & OBD_MD_FLGID )
368 dst->i_gid = src->o_gid;
369 if ( src->o_valid & OBD_MD_FLFLAGS )
370 dst->i_flags = src->o_flags;
371 if ( src->o_valid & OBD_MD_FLNLINK )
372 dst->i_nlink = src->o_nlink;
373 if ( src->o_valid & OBD_MD_FLGENER )
374 dst->i_generation = src->o_generation;
379 static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src)
382 CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
383 src->o_id, src->o_valid, dst->o_id);
385 if ( src->o_valid & OBD_MD_FLATIME )
386 dst->o_atime = src->o_atime;
387 if ( src->o_valid & OBD_MD_FLMTIME )
388 dst->o_mtime = src->o_mtime;
389 if ( src->o_valid & OBD_MD_FLCTIME )
390 dst->o_ctime = src->o_ctime;
391 if ( src->o_valid & OBD_MD_FLSIZE )
392 dst->o_size = src->o_size;
393 if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */
394 dst->o_blocks = src->o_blocks;
395 if ( src->o_valid & OBD_MD_FLBLKSZ )
396 dst->o_blksize = src->o_blksize;
397 if ( src->o_valid & OBD_MD_FLMODE )
398 dst->o_mode = src->o_mode;
399 if ( src->o_valid & OBD_MD_FLUID )
400 dst->o_uid = src->o_uid;
401 if ( src->o_valid & OBD_MD_FLGID )
402 dst->o_gid = src->o_gid;
403 if ( src->o_valid & OBD_MD_FLFLAGS )
404 dst->o_flags = src->o_flags;
406 if ( src->o_valid & OBD_MD_FLOBDFLG )
407 dst->o_obdflags = src->o_obdflags;
409 if ( src->o_valid & OBD_MD_FLNLINK )
410 dst->o_nlink = src->o_nlink;
411 if ( src->o_valid & OBD_MD_FLGENER )
412 dst->o_generation = src->o_generation;
413 if ( src->o_valid & OBD_MD_FLINLINE &&
414 src->o_obdflags & OBD_FL_INLINEDATA) {
415 memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
416 dst->o_obdflags |= OBD_FL_INLINEDATA;
418 if ( src->o_valid & OBD_MD_FLOBDMD &&
419 src->o_obdflags & OBD_FL_OBDMDEXISTS) {
420 memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd));
421 dst->o_obdflags |= OBD_FL_OBDMDEXISTS;
424 dst->o_valid |= src->o_valid;
428 /* returns FALSE if comparison (by flags) is same, TRUE if changed */
429 static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src,
434 if ( compare & OBD_MD_FLATIME )
435 res = (res || (dst->o_atime != src->o_atime));
436 if ( compare & OBD_MD_FLMTIME )
437 res = (res || (dst->o_mtime != src->o_mtime));
438 if ( compare & OBD_MD_FLCTIME )
439 res = (res || (dst->o_ctime != src->o_ctime));
440 if ( compare & OBD_MD_FLSIZE )
441 res = (res || (dst->o_size != src->o_size));
442 if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
443 res = (res || (dst->o_blocks != src->o_blocks));
444 if ( compare & OBD_MD_FLBLKSZ )
445 res = (res || (dst->o_blksize != src->o_blksize));
446 if ( compare & OBD_MD_FLMODE )
447 res = (res || (dst->o_mode != src->o_mode));
448 if ( compare & OBD_MD_FLUID )
449 res = (res || (dst->o_uid != src->o_uid));
450 if ( compare & OBD_MD_FLGID )
451 res = (res || (dst->o_gid != src->o_gid));
452 if ( compare & OBD_MD_FLFLAGS )
453 res = (res || (dst->o_flags != src->o_flags));
454 if ( compare & OBD_MD_FLNLINK )
455 res = (res || (dst->o_nlink != src->o_nlink));
456 if ( compare & OBD_MD_FLGENER )
457 res = (res || (dst->o_generation != src->o_generation));
458 /* XXX Don't know if thses should be included here - wasn't previously
459 if ( compare & OBD_MD_FLINLINE )
460 res = (res || memcmp(dst->o_inline, src->o_inline));
461 if ( compare & OBD_MD_FLOBDMD )
462 res = (res || memcmp(dst->o_obdmd, src->o_obdmd));
469 int obd_register_type(struct obd_ops *ops, char *nm);
470 int obd_unregister_type(char *nm);
473 struct list_head cli_chain;
474 struct obd_device *cli_obd;
476 unsigned long cli_prealloc_quota;
477 struct list_head cli_prealloc_inodes;
481 struct obd_prealloc_inode {
482 struct list_head obd_prealloc_chain;
486 /* generic operations shared by various OBD types */
487 int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
488 int gen_multi_cleanup(struct obd_device *obddev);
489 int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data);
490 int gen_multi_detach(struct obd_device *obddev);
491 int gen_connect (struct obd_conn *conn);
492 int gen_disconnect(struct obd_conn *conn);
493 struct obd_client *gen_client(const struct obd_conn *);
494 int gen_cleanup(struct obd_device *obddev);
495 int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst,
496 struct obd_conn *src_conn, struct obdo *src,
497 obd_size count, obd_off offset);
502 extern void obd_sysctl_init (void);
503 extern void obd_sysctl_clean (void);
505 #define CHKCONN(conn) do { if (!gen_client(conn)) {\
506 printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
508 return -EINVAL; }} while (0)
512 #endif /* __LINUX_CLASS_OBD_H */