X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Finclude%2Flinux%2Fobd_class.h;h=596e0bec308cec1a818052a389d418e3c968fd64;hb=cddc16981097f8f6c6ad9b4b638f741f1d278bc6;hp=4f16f4f72b0fbbb1533cca239d151f002c004350;hpb=dd8ece265f41df5851d9978de979490e42237666;p=fs%2Flustre-release.git diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 4f16f4f..596e0be 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -6,42 +6,88 @@ #include #include -#include +#include #include /* #include */ #include #include -#define OBD_PSDEV_MAJOR 120 -#define MAX_OBD_DEVICES 8 -#define MAX_MULTI 16 +/* + * ======== OBD type Declarations =========== + */ -typedef unsigned long objid; -typedef struct inode obdattr; -#if 0 -struct obdattr { - objid oa_id; - umode_t oa_mode; - nlink_t oa_nlink; - uid_t oa_uid; - gid_t oa_gid; - off_t oa_size; - time_t oa_atime; - time_t oa_mtime; - time_t oa_ctime; - unsigned long oa_blksize; - unsigned long oa_blocks; - char oa_data[116]; - struct obd_ops *oa_op; +typedef uint64_t obd_id; +typedef uint64_t obd_gr; +typedef uint64_t obd_time; +typedef uint64_t obd_size; +typedef uint64_t obd_off; +typedef uint64_t obd_blocks; +typedef uint32_t obd_blksize; +typedef uint32_t obd_mode; +typedef uint32_t obd_uid; +typedef uint32_t obd_gid; +typedef uint32_t obd_flag; +typedef uint32_t obd_count; + +#define OBD_FL_INLINEDATA (1UL) +#define OBD_FL_OBDMDEXISTS (1UL << 1) + +#define OBD_INLINESZ 60 +#define OBD_OBDMDSZ 60 +/* Note: 64-bit types are 64-bit aligned in structure */ +struct obdo { + obd_id o_id; + obd_gr o_gr; + obd_time o_atime; + obd_time o_mtime; + obd_time o_ctime; + obd_size o_size; + obd_blocks o_blocks; + obd_blksize o_blksize; + obd_mode o_mode; + obd_uid o_uid; + obd_gid o_gid; + obd_flag o_flags; + obd_flag o_obdflags; + obd_count o_nlink; + obd_count o_generation; + obd_flag o_valid; /* hot fields in this obdo */ + char o_inline[OBD_INLINESZ]; + char o_obdmd[OBD_OBDMDSZ]; + struct list_head o_list; + struct obd_ops *o_op; }; -#endif +#define OBD_MD_FLALL (~0UL) +#define OBD_MD_FLID (1UL) +#define OBD_MD_FLATIME (1UL<<1) +#define OBD_MD_FLMTIME (1UL<<2) +#define OBD_MD_FLCTIME (1UL<<3) +#define OBD_MD_FLSIZE (1UL<<4) +#define OBD_MD_FLBLOCKS (1UL<<5) +#define OBD_MD_FLBLKSZ (1UL<<6) +#define OBD_MD_FLMODE (1UL<<7) +#define OBD_MD_FLUID (1UL<<8) +#define OBD_MD_FLGID (1UL<<9) +#define OBD_MD_FLFLAGS (1UL<<10) +#define OBD_MD_FLOBDFLG (1UL<<11) +#define OBD_MD_FLNLINK (1UL<<12) +#define OBD_MD_FLGENER (1UL<<13) +#define OBD_MD_FLINLINE (1UL<<14) +#define OBD_MD_FLOBDMD (1UL<<15) -extern struct obd_device obd_dev[MAX_OBD_DEVICES]; +/* + * ======== OBD Device Declarations =========== + */ - +#define OBD_PSDEV_MAJOR 186 +#define MAX_OBD_DEVICES 8 +#define MAX_MULTI 16 + + +extern struct obd_device obd_dev[MAX_OBD_DEVICES]; #define OBD_ATTACHED 0x1 @@ -49,7 +95,7 @@ extern struct obd_device obd_dev[MAX_OBD_DEVICES]; struct obd_conn { struct obd_device *oc_dev; - unsigned int oc_id; + uint32_t oc_id; }; /* corresponds to one of the obdx */ @@ -72,33 +118,267 @@ struct obd_device { } u; }; +/* + * ======== OBD Operations Declarations =========== + */ + + struct obd_ops { - int (*o_attach)(struct obd_device *, int len, void *); + int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg); + int (*o_get_info)(struct obd_conn *, obd_count keylen, void *key, obd_count *vallen, void **val); + int (*o_set_info)(struct obd_conn *, obd_count keylen, void *key, obd_count vallen, void *val); + int (*o_attach)(struct obd_device *, obd_count len, void *); int (*o_detach)(struct obd_device *); - int (*o_format)(struct obd_device *, int len, void *); - int (*o_partition)(struct obd_device *, int len, void *); + int (*o_setup) (struct obd_device *dev, obd_count len, void *data); + int (*o_cleanup)(struct obd_device *dev); int (*o_connect)(struct obd_conn *conn); int (*o_disconnect)(struct obd_conn *); - int (*o_setup) (struct obd_device *dev, int len, void *data); - int (*o_cleanup)(struct obd_device *dev); - int (*o_setattr)(struct obd_conn *, obdattr *oa); - int (*o_getattr)(struct obd_conn *, obdattr *oa); int (*o_statfs)(struct obd_conn *, struct statfs *statfs); - int (*o_create)(struct obd_conn *, int prealloc_ino, int *er); - int (*o_destroy)(struct obd_conn *, obdattr *oa); - int (*o_read)(struct obd_conn *, obdattr *ino, char *buf, unsigned long *count, loff_t offset); - int (*o_read2)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset); - int (*o_write)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset); - int (*o_brw)(int rw, struct obd_conn * conn, obdattr *obj, struct page *page, int create); - int (*o_preallocate)(struct obd_conn *, unsigned long *req, long inodes[32]); - int (*o_get_info)(struct obd_conn *, int keylen, void *key, int *vallen, void **val); - int (*o_set_info)(struct obd_conn *, int keylen, void *key, int vallen, void *val); - int (*o_migrate)(struct obd_conn *, obdattr *src, obdattr *dst); - int (*o_copy)(struct obd_conn *dev, obdattr *source, obdattr *target); + int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids); + int (*o_create)(struct obd_conn *, struct obdo *oa); + int (*o_destroy)(struct obd_conn *, struct obdo *oa); + int (*o_setattr)(struct obd_conn *, struct obdo *oa); + int (*o_getattr)(struct obd_conn *, struct obdo *oa); + int (*o_read)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset); + int (*o_write)(struct obd_conn *, struct obdo *oa, char *buf, obd_size *count, obd_off offset); + int (*o_brw)(int rw, struct obd_conn * conn, struct obdo *oa, char *buf, obd_size count, obd_off offset, obd_flag flags); + int (*o_punch)(struct obd_conn *, struct obdo *tgt, obd_size count, obd_off offset); + int (*o_sync)(struct obd_conn *, struct obdo *tgt, obd_size count, obd_off offset); + int (*o_migrate)(struct obd_conn *, struct obdo *dst, struct obdo *src, obd_size count, obd_off offset); + int (*o_copy)(struct obd_conn *dstconn, struct obdo *dst, struct obd_conn *srconn, struct obdo *src, obd_size count, obd_off offset); + int (*o_iterate)(struct obd_conn *, int (*)(obd_id, void *), obd_id start, void *); }; -#define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op +#define OBT(dev) dev->obd_type->typ_ops +#define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op + + +/* + * ======== OBD Metadata Support =========== + */ + +extern int obd_init_obdo_cache(void); +extern void obd_cleanup_obdo_cache(void); + + +static inline int obdo_has_inline(struct obdo *obdo) +{ + return obdo->o_obdflags & OBD_FL_INLINEDATA; +}; + +static inline int obdo_has_obdmd(struct obdo *obdo) +{ + return obdo->o_obdflags & OBD_FL_OBDMDEXISTS; +}; + +/* support routines */ +extern kmem_cache_t *obdo_cachep; + +static __inline__ struct obdo *obdo_alloc(void) +{ + struct obdo *res = NULL; + + res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL); + memset(res, 0, sizeof (*res)); + + return res; +} + +static __inline__ void obdo_free(struct obdo *oa) +{ + if ( !oa ) + return; + kmem_cache_free(obdo_cachep, oa); +} + + + +static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id) +{ + struct obdo *res = NULL; + + res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL); + if ( !res ) { + EXIT; + return NULL; + } + memset(res, 0, sizeof(*res)); + res->o_id = id; + if (OBP(conn->oc_dev, getattr)(conn, res)) { + OBD_FREE(res, sizeof(*res)); + EXIT; + return NULL; + } + EXIT; + return res; +} + +static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr) +{ + unsigned int ia_valid = attr->ia_valid; + + if (ia_valid & ATTR_ATIME) { + oa->o_atime = attr->ia_atime; + oa->o_valid |= OBD_MD_FLATIME; + } + if (ia_valid & ATTR_MTIME) { + oa->o_mtime = attr->ia_mtime; + oa->o_valid |= OBD_MD_FLMTIME; + } + if (ia_valid & ATTR_CTIME) { + oa->o_ctime = attr->ia_ctime; + oa->o_valid |= OBD_MD_FLCTIME; + } + if (ia_valid & ATTR_SIZE) { + oa->o_size = attr->ia_size; + oa->o_valid |= OBD_MD_FLSIZE; + } + if (ia_valid & ATTR_MODE) { + oa->o_mode = attr->ia_mode; + oa->o_valid |= OBD_MD_FLMODE; + if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID)) + oa->o_mode &= ~S_ISGID; + } + if (ia_valid & ATTR_UID) + { + oa->o_uid = attr->ia_uid; + oa->o_valid |= OBD_MD_FLUID; + } + if (ia_valid & ATTR_GID) { + oa->o_gid = attr->ia_gid; + oa->o_valid |= OBD_MD_FLGID; + } +} + + +static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src) +{ + CDEBUG(D_INODE, "flags %x\n", src->o_valid); + if ( src->o_valid & OBD_MD_FLATIME ) + dst->o_atime = src->o_atime; + if ( src->o_valid & OBD_MD_FLMTIME ) + dst->o_mtime = src->o_mtime; + if ( src->o_valid & OBD_MD_FLCTIME ) + dst->o_ctime = src->o_ctime; + if ( src->o_valid & OBD_MD_FLSIZE ) + dst->o_size = src->o_size; + if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */ + dst->o_blocks = src->o_blocks; + if ( src->o_valid & OBD_MD_FLBLKSZ ) + dst->o_blksize = src->o_blksize; + if ( src->o_valid & OBD_MD_FLMODE ) + dst->o_mode = src->o_mode; + if ( src->o_valid & OBD_MD_FLUID ) + dst->o_uid = src->o_uid; + if ( src->o_valid & OBD_MD_FLGID ) + dst->o_gid = src->o_gid; + if ( src->o_valid & OBD_MD_FLFLAGS ) + dst->o_flags = src->o_flags; + if ( src->o_valid & OBD_MD_FLOBDFLG ) + dst->o_obdflags = src->o_obdflags; + if ( src->o_valid & OBD_MD_FLNLINK ) + dst->o_nlink = src->o_nlink; + if ( src->o_valid & OBD_MD_FLGENER ) + dst->o_generation = src->o_generation; + if ( src->o_valid & OBD_MD_FLINLINE ) + memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline)); + if ( src->o_valid & OBD_MD_FLOBDMD ) + memcpy(dst->o_obdmd, src->o_obdmd, sizeof(src->o_obdmd)); + + dst->o_valid |= src->o_valid; +} + +static __inline__ void obdo_from_inode(struct obdo *dst, struct inode *src) +{ + CDEBUG(D_INODE, "flags %x\n", dst->o_valid); + if ( dst->o_valid & OBD_MD_FLID ) + dst->o_id = src->i_ino; + if ( dst->o_valid & OBD_MD_FLATIME ) + dst->o_atime = src->i_atime; + if ( dst->o_valid & OBD_MD_FLMTIME ) + dst->o_mtime = src->i_mtime; + if ( dst->o_valid & OBD_MD_FLCTIME ) + dst->o_ctime = src->i_ctime; + if ( dst->o_valid & OBD_MD_FLSIZE ) + dst->o_size = src->i_size; + if ( dst->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */ + dst->o_blocks = src->i_blocks; + if ( dst->o_valid & OBD_MD_FLBLKSZ ) + dst->o_blksize = src->i_blksize; + if ( dst->o_valid & OBD_MD_FLMODE ) + dst->o_mode = src->i_mode; + if ( dst->o_valid & OBD_MD_FLUID ) + dst->o_uid = src->i_uid; + if ( dst->o_valid & OBD_MD_FLGID ) + dst->o_gid = src->i_gid; + if ( dst->o_valid & OBD_MD_FLFLAGS ) + dst->o_flags = src->i_flags; + if ( dst->o_valid & OBD_MD_FLNLINK ) + dst->o_nlink = src->i_nlink; + if ( dst->o_valid & OBD_MD_FLGENER ) + dst->o_generation = src->i_generation; +} + +static __inline__ void obdo_to_inode(struct inode *dst, struct obdo *src) +{ + + CDEBUG(D_INODE, "flags %x\n", src->o_valid); + if ( src->o_valid & OBD_MD_FLID ) + dst->i_ino = src->o_id; + if ( src->o_valid & OBD_MD_FLATIME ) + dst->i_atime = src->o_atime; + if ( src->o_valid & OBD_MD_FLMTIME ) + dst->i_mtime = src->o_mtime; + if ( src->o_valid & OBD_MD_FLCTIME ) + dst->i_ctime = src->o_ctime; + if ( src->o_valid & OBD_MD_FLSIZE ) + dst->i_size = src->o_size; + if ( src->o_valid & OBD_MD_FLBLOCKS ) /* allocation of space */ + dst->i_blocks = src->o_blocks; + if ( src->o_valid & OBD_MD_FLBLKSZ ) + dst->i_blksize = src->o_blksize; + if ( src->o_valid & OBD_MD_FLMODE ) + dst->i_mode = src->o_mode; + if ( src->o_valid & OBD_MD_FLUID ) + dst->i_uid = src->o_uid; + if ( src->o_valid & OBD_MD_FLGID ) + dst->i_gid = src->o_gid; + if ( src->o_valid & OBD_MD_FLFLAGS ) + dst->i_flags = src->o_flags; + if ( src->o_valid & OBD_MD_FLNLINK ) + dst->i_nlink = src->o_nlink; + if ( src->o_valid & OBD_MD_FLGENER ) + dst->i_generation = src->o_generation; +} + +static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src) +{ + int res = 1; + + if ( src->o_valid & OBD_MD_FLMODE ) + res = (res && (dst->o_mode == src->o_mode)); + if ( src->o_valid & OBD_MD_FLUID ) + res = (res && (dst->o_uid == src->o_uid)); + if ( src->o_valid & OBD_MD_FLGID ) + res = (res && (dst->o_gid == src->o_gid)); + if ( src->o_valid & OBD_MD_FLSIZE ) + res = (res && (dst->o_size == src->o_size)); + if ( src->o_valid & OBD_MD_FLATIME ) + res = (res && (dst->o_atime == src->o_atime)); + if ( src->o_valid & OBD_MD_FLMTIME ) + res = (res && (dst->o_mtime == src->o_mtime)); + if ( src->o_valid & OBD_MD_FLCTIME ) + res = (res && (dst->o_ctime == src->o_ctime)); + if ( src->o_valid & OBD_MD_FLFLAGS ) + res = (res && (dst->o_flags == src->o_flags)); + /* allocation of space */ + if ( src->o_valid & OBD_MD_FLBLOCKS ) + res = (res && (dst->o_blocks == src->o_blocks)); + return res; +} + + int obd_register_type(struct obd_ops *ops, char *nm); int obd_unregister_type(char *nm); @@ -118,64 +398,71 @@ struct obd_prealloc_inode { }; /* generic operations shared by various OBD types */ +int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data); +int gen_multi_cleanup(struct obd_device *obddev); +int gen_multi_attach(struct obd_device *obddev, uint32_t len, void *data); +int gen_multi_detach(struct obd_device *obddev); int gen_connect (struct obd_conn *conn); int gen_disconnect(struct obd_conn *conn); -int gen_multi_setup(struct obd_device *obddev, int len, void *data); -int gen_multi_cleanup(struct obd_device *obddev); -int gen_multi_attach(struct obd_device *obddev, int len, void *data); struct obd_client *gen_client(struct obd_conn *); -int gen_multi_detach(struct obd_device *obddev); int gen_cleanup(struct obd_device *obddev); -int gen_copy_data(struct obd_conn *, obdattr *source, obdattr *target); +int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst, + struct obd_conn *src_conn, struct obdo *src, + obd_size count, obd_off offset); /* - * ioctl commands + * ======== OBD IOCL Declarations =========== */ -struct oic_attach { +struct oic_generic { + int att_connid; int att_typelen; void *att_type; int att_datalen; void *att_data; }; -struct oic_prealloc_s { - unsigned long cli_id; - unsigned long alloc; /* user sets it to the number of inodes requesting - * to be preallocated. kernel sets it to the actual number - * of succesfully preallocated inodes */ - long inodes[32]; /* actual inode numbers */ -}; -struct oic_create_s { - unsigned int conn_id; - unsigned long prealloc; +/* for preallocation */ +struct oic_prealloc_s { + uint32_t cli_id; + uint32_t alloc; /* user sets it to the number of inodes + * requesting to be preallocated. kernel + * sets it to the actual number * of + * succesfully preallocated inodes */ + obd_id ids[32]; /* actual inode numbers */ }; +/* for getattr, setattr, create, destroy */ struct oic_attr_s { - unsigned int conn_id; - unsigned long ino; - struct iattr iattr; + uint32_t conn_id; + struct obdo obdo; }; +/* for copy, migrate */ struct ioc_mv_s { - unsigned int conn_id; - objid src; - objid tgt; + unsigned int src_conn_id; + struct obdo src; + unsigned int dst_conn_id; + struct obdo dst; }; +/* for read/write */ struct oic_rw_s { - unsigned int conn_id; - unsigned long id; + uint32_t conn_id; + struct obdo obdo; char * buf; - unsigned long count; - loff_t offset; + obd_size count; + obd_off offset; }; -struct oic_partition { - int partition; - unsigned int size; +/* for punch, sync */ +struct oic_range_s { + uint32_t conn_id; + struct obdo obdo; + obd_size count; + obd_off offset; }; @@ -214,54 +501,5 @@ extern void obd_sysctl_clean (void); return -EINVAL; }} while (0) -/* support routines */ -static __inline__ obdattr *obd_empty_oa(void) -{ - obdattr *res = NULL; - OBD_ALLOC(res, obdattr *, sizeof(*res)); - return res; -} - -static __inline__ void obd_free_oa(obdattr *oa) -{ - if ( !oa ) - return; - OBD_FREE(oa,sizeof(*oa)); -} - - - -static __inline__ obdattr *obd_oa_fromid(struct obd_conn *conn, objid id) -{ - obdattr *res = NULL; - - OBD_ALLOC(res, obdattr *, sizeof(*res)); - if ( !res ) - return NULL; - - res->i_ino = id; - if (conn->oc_dev->obd_type->typ_ops->o_getattr(conn, res)) { - OBD_FREE(res, sizeof(*res)); - return NULL; - } - - return res; -} - -/* #define obd_cpy_obdo(a,b) memcpy(a, b, sizeof(*a)) */ - -static __inline__ void obd_cpy_appmd(obdattr *a, obdattr *b) -{ - a->i_mode = b->i_mode; - a->i_uid = b->i_uid; - a->i_gid = b->i_gid; - a->i_size = b->i_size; - a->i_atime = b->i_atime; - a->i_mtime = b->i_mtime; - a->i_ctime = b->i_ctime; - a->i_flags = b->i_flags; - /* allocation of space */ - a->i_blocks = b->i_blocks; -} #endif /* __LINUX_CLASS_OBD_H */