From 3573dfc86d22ab10c579521590576094eeb17c2c Mon Sep 17 00:00:00 2001 From: braam Date: Fri, 31 Dec 1999 20:02:56 +0000 Subject: [PATCH] Phase 1 of the obdo implementation. The class driver is now much cleaner, the header file is mostly in roughly the right shape. --- lustre/include/linux/obd_class.h | 390 +++++++++++++++------------ lustre/include/linux/obd_snap_support.h | 6 +- lustre/obdclass/class_obd.c | 459 ++++++++++++-------------------- lustre/obdclass/genops.c | 69 +++-- lustre/obdfs/namei.c | 8 +- 5 files changed, 457 insertions(+), 475 deletions(-) diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 1a880c2..b50962d 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -13,9 +13,9 @@ #include -#define OBD_PSDEV_MAJOR 186 -#define MAX_OBD_DEVICES 8 -#define MAX_MULTI 16 +/* + * ======== OBD type Declarations =========== + */ typedef uint64_t obd_id; typedef uint64_t obd_time; @@ -30,7 +30,7 @@ typedef uint32_t obd_flag; typedef uint32_t obd_count; #define OBD_INLINESZ 60 -#define OBD_OBDMDSZ 60 +#define OBD_OBDMDSZ 64 #define OBD_FL_INLINEDATA (1UL) #define OBD_FL_OBDMDEXISTS (1UL << 1) @@ -51,36 +51,31 @@ struct obdo { obd_flag o_obdflags; obd_count o_nlink; obd_flag o_valid; /* hot fields in this obdo */ - char *o_inline; - char *o_obdmd; + char o_inline[OBD_INLINESZ]; + char o_obdmd[OBD_OBDMDSZ]; struct list_head o_list; struct obd_ops *o_op; }; +/* + * ======== OBD Device Declarations =========== + */ -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; -}; +#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 #define OBD_SET_UP 0x2 struct obd_conn { struct obd_device *oc_dev; - unsigned int oc_id; + uint32_t oc_id; }; /* corresponds to one of the obdx */ @@ -103,6 +98,11 @@ struct obd_device { } u; }; +/* + * ======== OBD Operations Declarations =========== + */ + + struct obd_ops { 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); @@ -121,166 +121,68 @@ struct obd_ops { 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_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_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 (*)(objid, void *), obd_id start, void *); + int (*o_iterate)(struct obd_conn *, int (*)(obd_id, void *), obd_id start, void *); }; #define OBT(dev) dev->obd_type->typ_ops #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op -int obd_register_type(struct obd_ops *ops, char *nm); -int obd_unregister_type(char *nm); - -struct obd_client { - struct list_head cli_chain; - struct obd_device *cli_obd; - unsigned int cli_id; - unsigned long cli_prealloc_quota; - struct list_head cli_prealloc_inodes; -}; - - -struct obd_prealloc_inode { - struct list_head obd_prealloc_chain; - unsigned long 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); -struct obd_client *gen_client(struct obd_conn *); -int gen_cleanup(struct obd_device *obddev); -int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst, - struct obd_conn *src_conn, struct obdo *src); - - /* - * ioctl commands + * ======== OBD Metadata Support =========== */ -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; -}; -struct oic_attr_s { - unsigned int conn_id; - unsigned long ino; - struct iattr iattr; -}; - -struct ioc_mv_s { - unsigned int conn_id; - objid src; - objid dst; -}; - -struct oic_rw_s { - unsigned int conn_id; - unsigned long id; - char * buf; - unsigned long count; - loff_t offset; +static inline int obdo_has_inline(struct obdo *obdo) +{ + return obdo->o_obdflags & OBD_FL_INLINEDATA; }; -struct oic_partition { - int partition; - unsigned int size; +static inline int obdo_has_obdmd(struct obdo *obdo) +{ + return obdo->o_obdflags & OBD_FL_OBDMDEXISTS; }; - -#define OBD_IOC_CREATE _IOR ('f', 3, long) -#define OBD_IOC_SETUP _IOW ('f', 4, long) -#define OBD_IOC_CLEANUP _IO ('f', 5 ) -#define OBD_IOC_DESTROY _IOW ('f', 6, long) -#define OBD_IOC_PREALLOCATE _IOWR('f', 7, long) -#define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 ) -#define OBD_IOC_SETATTR _IOW ('f', 9, long) -#define OBD_IOC_GETATTR _IOR ('f', 10, long) -#define OBD_IOC_READ _IOWR('f', 11, long) -#define OBD_IOC_WRITE _IOWR('f', 12, long) -#define OBD_IOC_CONNECT _IOR ('f', 13, long) -#define OBD_IOC_DISCONNECT _IOW ('f', 14, long) -#define OBD_IOC_STATFS _IOWR('f', 15, long) -#define OBD_IOC_SYNC _IOR ('f', 16, long) -#define OBD_IOC_READ2 _IOWR('f', 17, long) -#define OBD_IOC_FORMAT _IOWR('f', 18, long) -#define OBD_IOC_PARTITION _IOWR('f', 19, long) -#define OBD_IOC_ATTACH _IOWR('f', 20, long) -#define OBD_IOC_DETACH _IOWR('f', 21, long) -#define OBD_IOC_COPY _IOWR('f', 22, long) -#define OBD_IOC_MIGR _IOWR('f', 23, long) - -#define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 ) - - -/* sysctl.c */ -extern void obd_sysctl_init (void); -extern void obd_sysctl_clean (void); - -#define CHKCONN(conn) do { if (!gen_client(conn)) {\ - printk("%s %d invalid client %u\n", __FILE__, __LINE__, \ - conn->oc_id);\ - return -EINVAL; }} while (0) - - /* support routines */ -static __inline__ struct obdo *obd_empty_oa(void) +extern kmem_cache_t *obdo_cachep; + +static __inline__ struct obdo *obdo_alloc(void) { struct obdo *res = NULL; - /* XXX we should probably use a slab cache here */ - OBD_ALLOC(res, struct obdo *, sizeof(*res)); + res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL); memset(res, 0, sizeof (*res)); return res; } -static __inline__ void obd_free_oa(struct obdo *oa) +static __inline__ void obdo_free(struct obdo *oa) { if ( !oa ) return; - OBD_FREE(oa, sizeof(*oa)); + kmem_cache_free(obdo_cachep, oa); } -static __inline__ struct obdo *obd_oa_fromid(struct obd_conn *conn, obd_id id) +static __inline__ struct obdo *obdo_fromid(struct obd_conn *conn, obd_id id) { struct obdo *res = NULL; - OBD_ALLOC(res, struct obdo *, sizeof(*res)); + res = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL); if ( !res ) { EXIT; return NULL; } memset(res, 0, sizeof(*res)); res->o_id = id; - if (OBD(conn->oc_dev, getattr)(conn, res)) { + if (OBP(conn->oc_dev, getattr)(conn, res)) { OBD_FREE(res, sizeof(*res)); EXIT; return NULL; @@ -309,49 +211,79 @@ static __inline__ struct obdo *obd_oa_fromid(struct obd_conn *conn, obd_id id) static __inline__ void obdo_cpy_md(struct obdo *dst, struct obdo *src) { - /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those - * fields given by the flags. The default is to copy the field - * given by the flags. - */ - if (src->o_valid & OBD_MD_NO) - src->o_valid = ~src->o_valid; CDEBUG(D_INODE, "flags %x\n", src->o_valid); if ( src->o_valid & OBD_MD_FLMODE ) - dst->i_mode = src->i_mode; + dst->o_mode = src->o_mode; if ( src->o_valid & OBD_MD_FLUID ) - dst->i_uid = src->i_uid; + dst->o_uid = src->o_uid; if ( src->o_valid & OBD_MD_FLGID ) - dst->i_gid = src->i_gid; + dst->o_gid = src->o_gid; if ( src->o_valid & OBD_MD_FLSIZE ) - dst->i_size = src->i_size; + dst->o_size = src->o_size; if ( src->o_valid & OBD_MD_FLATIME ) - dst->i_atime = src->i_atime; + dst->o_atime = src->o_atime; if ( src->o_valid & OBD_MD_FLMTIME ) - dst->i_mtime = src->i_mtime; + dst->o_mtime = src->o_mtime; if ( src->o_valid & OBD_MD_FLCTIME ) - dst->i_ctime = src->i_ctime; + dst->o_ctime = src->o_ctime; if ( src->o_valid & OBD_MD_FLFLAGS ) - dst->i_flags = src->i_flags; + dst->o_flags = src->o_flags; /* allocation of space */ if ( src->o_valid & OBD_MD_FLBLOCKS ) - dst->i_blocks = src->i_blocks; - if ( src->o_valid & OBD_MD_FLOBDMD && src->i_blocks == 0 ) { - CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino); - memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data, - sizeof(src->u.ext2_i.i_data)); - } else { - CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n", - src->i_ino); - } + dst->o_blocks = src->o_blocks; } -static __inline__ void obdo_cpy_from_inode(struct obdo *dst, struct inode *src) +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_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_FLSIZE ) + dst->o_size = src->i_size; + 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_FLFLAGS ) + dst->o_flags = src->i_flags; + /* allocation of space */ + if ( dst->o_valid & OBD_MD_FLBLOCKS ) + dst->o_blocks = src->i_blocks; + } -static __inline__ void obdo_cpy_from_oa(struct inode *dst, struct obdo *src) +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_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_FLSIZE ) + dst->i_size = src->o_size; + 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_FLFLAGS ) + dst->i_flags = src->o_flags; + /* allocation of space */ + if ( src->o_valid & OBD_MD_FLBLOCKS ) + dst->i_blocks = src->o_blocks; + } static __inline__ int obdo_cmp_md(struct obdo *dst, struct obdo *src) @@ -359,26 +291,148 @@ 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->i_mode == src->i_mode)); + res = (res && (dst->o_mode == src->o_mode)); if ( src->o_valid & OBD_MD_FLUID ) - res = (res && (dst->i_uid == src->i_uid)); + res = (res && (dst->o_uid == src->o_uid)); if ( src->o_valid & OBD_MD_FLGID ) - res = (res && (dst->i_gid == src->i_gid)); + res = (res && (dst->o_gid == src->o_gid)); if ( src->o_valid & OBD_MD_FLSIZE ) - res = (res && (dst->i_size == src->i_size)); + res = (res && (dst->o_size == src->o_size)); if ( src->o_valid & OBD_MD_FLATIME ) - res = (res && (dst->i_atime == src->i_atime)); + res = (res && (dst->o_atime == src->o_atime)); if ( src->o_valid & OBD_MD_FLMTIME ) - res = (res && (dst->i_mtime == src->i_mtime)); + res = (res && (dst->o_mtime == src->o_mtime)); if ( src->o_valid & OBD_MD_FLCTIME ) - res = (res && (dst->i_ctime == src->i_ctime)); + res = (res && (dst->o_ctime == src->o_ctime)); if ( src->o_valid & OBD_MD_FLFLAGS ) - res = (res && (dst->i_flags == src->i_flags)); + res = (res && (dst->o_flags == src->o_flags)); /* allocation of space */ if ( src->o_valid & OBD_MD_FLBLOCKS ) - res = (res && (dst->i_blocks == src->i_blocks)); + 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); + +struct obd_client { + struct list_head cli_chain; + struct obd_device *cli_obd; + unsigned int cli_id; + unsigned long cli_prealloc_quota; + struct list_head cli_prealloc_inodes; +}; + + +struct obd_prealloc_inode { + struct list_head obd_prealloc_chain; + unsigned long 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); +struct obd_client *gen_client(struct obd_conn *); +int gen_cleanup(struct obd_device *obddev); +int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst, + struct obd_conn *src_conn, struct obdo *src); + + + +/* + * ======== OBD IOCL Declarations =========== + */ +struct oic_generic { + int att_connid; + int att_typelen; + void *att_type; + int att_datalen; + void *att_data; +}; + + +/* 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 { + uint32_t conn_id; + struct obdo obdo; +}; + +/* for copy, migrate */ +struct ioc_mv_s { + unsigned int src_conn_id; + struct obdo src; + unsigned int dst_conn_id; + struct obdo dst; +}; + +/* for read/write */ +struct oic_rw_s { + uint32_t conn_id; + struct obdo obdo; + char * buf; + obd_size count; + obd_off offset; +}; + +/* for punch, sync */ +struct oic_range_s { + uint32_t conn_id; + struct obdo obdo; + obd_size count; + obd_off offset; +}; + + +#define OBD_IOC_CREATE _IOR ('f', 3, long) +#define OBD_IOC_SETUP _IOW ('f', 4, long) +#define OBD_IOC_CLEANUP _IO ('f', 5 ) +#define OBD_IOC_DESTROY _IOW ('f', 6, long) +#define OBD_IOC_PREALLOCATE _IOWR('f', 7, long) +#define OBD_IOC_DEC_USE_COUNT _IO ('f', 8 ) +#define OBD_IOC_SETATTR _IOW ('f', 9, long) +#define OBD_IOC_GETATTR _IOR ('f', 10, long) +#define OBD_IOC_READ _IOWR('f', 11, long) +#define OBD_IOC_WRITE _IOWR('f', 12, long) +#define OBD_IOC_CONNECT _IOR ('f', 13, long) +#define OBD_IOC_DISCONNECT _IOW ('f', 14, long) +#define OBD_IOC_STATFS _IOWR('f', 15, long) +#define OBD_IOC_SYNC _IOR ('f', 16, long) +#define OBD_IOC_READ2 _IOWR('f', 17, long) +#define OBD_IOC_FORMAT _IOWR('f', 18, long) +#define OBD_IOC_PARTITION _IOWR('f', 19, long) +#define OBD_IOC_ATTACH _IOWR('f', 20, long) +#define OBD_IOC_DETACH _IOWR('f', 21, long) +#define OBD_IOC_COPY _IOWR('f', 22, long) +#define OBD_IOC_MIGR _IOWR('f', 23, long) + +#define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 ) + + +/* sysctl.c */ +extern void obd_sysctl_init (void); +extern void obd_sysctl_clean (void); + +#define CHKCONN(conn) do { if (!gen_client(conn)) {\ + printk("%s %d invalid client %u\n", __FILE__, __LINE__, \ + conn->oc_id);\ + return -EINVAL; }} while (0) + + + #endif /* __LINUX_CLASS_OBD_H */ diff --git a/lustre/include/linux/obd_snap_support.h b/lustre/include/linux/obd_snap_support.h index aca70cd..ca4e615 100644 --- a/lustre/include/linux/obd_snap_support.h +++ b/lustre/include/linux/obd_snap_support.h @@ -13,9 +13,9 @@ struct snap_iterdata { inline struct obd_conn *child_conn(struct obd_conn *conn); -int snap_deleteobj(objid id, void *data); -int snap_restoreobj(objid id, void *data); -int snap_printobj(objid id, void *data); +int snap_deleteobj(obd_id id, void *data); +int snap_restoreobj(obd_id id, void *data); +int snap_printobj(obd_id id, void *data); int snap_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg, void *uarg); #endif diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 09ae2e9..8560d6e 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -155,6 +155,9 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, unsigned int cmd, unsigned long arg) { struct obd_device *obddev; + /* NOTE this must be larger than any of the ioctl data structs */ + char buff[1024]; + void *karg = buff; struct obd_conn conn; int err, dev; long int cli_id; /* connect, disconnect */ @@ -173,11 +176,12 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return -EINVAL; case OBD_IOC_ATTACH: { struct obd_type *type; - struct oic_generic input; + struct oic_generic *input = karg; ENTRY; /* have we attached a type to this device */ - if ( obddev->obd_type || (obddev->obd_flags & OBD_ATTACHED) ){ + if ( obddev->obd_type || + (obddev->obd_flags & OBD_ATTACHED) ){ CDEBUG(D_IOCTL, "OBD Device %d already attached to type %s.\n", dev, obddev->obd_type->typ_name); @@ -192,15 +196,15 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return err; } - err = getdata(input.att_typelen + 1, &input.att_type); + err = getdata(input->att_typelen + 1, &input->att_type); if ( err ) { EXIT; return err; } /* find the type */ - type = obd_nm_to_type(input.att_type); - OBD_FREE(input.att_type, input.att_typelen + 1); + type = obd_nm_to_type(input->att_type); + OBD_FREE(input->att_type, input->att_typelen + 1); if ( !type ) { printk("Unknown obd type dev %d\n", dev); EXIT; @@ -209,7 +213,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, obddev->obd_type = type; /* get the attach data */ - err = getdata(input.att_datalen, &input.att_data); + err = getdata(input->att_datalen, &input->att_data); if ( err ) { EXIT; return err; @@ -219,7 +223,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, obddev->obd_multi_count = 0; CDEBUG(D_IOCTL, "Attach %d, datalen %d, type %s\n", - dev, input.att_datalen, obddev->obd_type->typ_name); + dev, input->att_datalen, obddev->obd_type->typ_name); + /* maybe we are done */ if ( !OBT(obddev) || !OBP(obddev, attach) ) { obddev->obd_flags |= OBD_ATTACHED; type->typ_refcnt++; @@ -231,9 +236,9 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, } /* do the attach */ - err = OBP(obddev, attach)(obddev, input.att_datalen, - input.att_data); - OBD_FREE(input.att_data, input.att_datalen); + err = OBP(obddev, attach)(obddev, input->att_datalen, + input->att_data); + OBD_FREE(input->att_data, input->att_datalen); if ( err ) { obddev->obd_flags &= ~OBD_ATTACHED; @@ -280,177 +285,12 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return 0; } - case OBD_IOC_FORMAT: { - struct ioc_format { - int format_datalen; - void *format_data; - } input; - - /* have we attached a type to this device */ - if ( !obddev->obd_type ) { - CDEBUG(D_IOCTL, "OBD Device %d has no type.\n", dev); - return -ENODEV; - } - - /* get main structure */ - err = copy_from_user(&input, (void *) arg, sizeof(input)); - if (err) - return err; - - err = getdata(input.format_datalen, &input.format_data); - if (err) - return err; - - if ( !OBT(obddev) || !OBP(obddev, format) ) - return -EOPNOTSUPP; - - /* do the format */ - CDEBUG(D_IOCTL, "Format %d, type %s\n", dev, - obddev->obd_type->typ_name); - err = OBP(obddev, format)(obddev, input.format_datalen, - input.format_data); - - OBD_FREE(input.format_data, input.format_datalen); - return err; - } - case OBD_IOC_PARTITION: { - struct ioc_part { - int part_datalen; - void *part_data; - } input; - - /* have we attached a type to this device */ - if ( !obddev->obd_type ) { - CDEBUG(D_IOCTL, "OBD Device %d has no type.\n", dev); - return -ENODEV; - } - - /* get main structure */ - err = copy_from_user(&input, (void *) arg, sizeof(input)); - if (err) - return err; - - err = getdata(input.part_datalen, &input.part_data); - if (err) - return err; - - if ( !OBT(obddev) || !OBP(obddev, partition) ) - return -EOPNOTSUPP; - - /* do the partition */ - CDEBUG(D_IOCTL, "Partition %d, type %s\n", dev, - obddev->obd_type->typ_name); - err = OBP(obddev, partition)(obddev, input.part_datalen, - input.part_data); - - OBD_FREE(input.part_data, input.part_datalen); - return err; - } - - case OBD_IOC_COPY: { - struct ioc_mv_s mvdata; - struct ioc_part { - int part_datalen; - void *part_data; - } input; - obdattr *src, *dst; - - if ( (!(obddev->obd_flags & OBD_SET_UP)) || - (!(obddev->obd_flags & OBD_ATTACHED))) { - CDEBUG(D_IOCTL, "Device not attached or set up\n"); - return -ENODEV; - } - - /* get main structure */ - err = copy_from_user(&input, (void *) arg, sizeof(input)); - if (err) - return err; - - err = copy_from_user(&mvdata, input.part_data, sizeof(mvdata)); - if (err) - return err; - - if ( !OBT(obddev) || !OBP(obddev, copy) ) - return -EOPNOTSUPP; - - /* do the partition */ - CDEBUG(D_IOCTL, "Copy %d, type %s dst %ld src %ld\n", dev, - obddev->obd_type->typ_name, mvdata.dst, mvdata.src); - - conn.oc_id = mvdata.conn_id; - src = obd_oa_fromid(&conn, mvdata.src); - if ( !src ) - return -ENOENT; - dst = obd_oa_fromid(&conn, mvdata.dst); - if ( ! dst ) { - obd_free_oa(src); - return -ENOENT; - } - - err = OBP(obddev, copy)(&conn, dst, src); - - obd_free_oa(src); - obd_free_oa(dst); - return err; - } - case OBD_IOC_MIGR: { - struct ioc_mv_s mvdata; - struct ioc_part { - int part_datalen; - void *part_data; - } input; - obdattr *src, *dst; - - if ( (!(obddev->obd_flags & OBD_SET_UP)) || - (!(obddev->obd_flags & OBD_ATTACHED))) { - CDEBUG(D_IOCTL, "Device not attached or set up\n"); - return -ENODEV; - } - - /* get main structure */ - err = copy_from_user(&input, (void *) arg, sizeof(input)); - if (err) - return err; - - - CDEBUG(D_IOCTL, "Migrate copying %d\n", sizeof(mvdata)); - err = copy_from_user(&mvdata, input.part_data, sizeof(mvdata)); - if (err) - return err; - - if ( !OBT(obddev) || !OBP(obddev, migrate) ) - return -EOPNOTSUPP; - - /* do the partition */ - CDEBUG(D_IOCTL, "Migrate %d, type %s conn %d src %ld dst %ld\n", - dev, obddev->obd_type->typ_name, mvdata.conn_id, - mvdata.src, mvdata.dst); - - - if ( ! (src = obd_empty_oa()) ) - return -ENOMEM; - if ( ! (dst = obd_empty_oa()) ) { - obd_free_oa(src); - return -ENOMEM; - } - - src->i_ino = mvdata.src; - dst->i_ino = mvdata.dst; - - conn.oc_id = mvdata.conn_id; - - err = OBP(obddev, migrate)(&conn, dst, src); - - obd_free_oa(src); - obd_free_oa(dst); - return err; - } - case OBD_IOC_SETUP: { struct ioc_setup { int setup_datalen; void *setup_data; - } input; + } *input; + input = karg; ENTRY; /* have we attached a type to this device */ @@ -475,7 +315,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return err; } - err = getdata(input.setup_datalen, &input.setup_data); + err = getdata(input->setup_datalen, &input->setup_data); if (err) { EXIT; return err; @@ -493,8 +333,8 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return 0; } - err = OBP(obddev, setup)(obddev, input.setup_datalen, - input.setup_data); + err = OBP(obddev, setup)(obddev, input->setup_datalen, + input->setup_data); if ( err ) { obddev->obd_flags &= ~OBD_SET_UP; @@ -565,7 +405,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return err; return copy_to_user((int *)arg, &conn.oc_id, - sizeof(int)); + sizeof(uint32_t)); } case OBD_IOC_DISCONNECT: /* frees data structures */ @@ -582,33 +422,29 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, OBP(obddev, disconnect)(&conn); return 0; + /* XXX sync needs to be done */ case OBD_IOC_SYNC: { - /* sync doesn't need a connection ID, because it knows - * what device it was called on, and can thus get the - * superblock that it needs. */ - /* has this minor been registered? */ + struct oic_range_s *foo = karg; + if (!obddev->obd_type) return -ENODEV; - if (!obddev->u.ext2.ext2_sb || !obddev->u.ext2.ext2_sb->s_dev) { - CDEBUG(D_IOCTL, "fatal: device not initialized.\n"); - err = -ENODEV; - } else { - err = fsync_dev(obddev->u.ext2.ext2_sb->s_dev); - if ( err ) - CDEBUG(D_IOCTL, "sync: fsync_dev failure\n"); - else - CDEBUG(D_IOCTL, "sync: success\n"); + err = copy_from_user(&foo, (const void *)arg, sizeof(foo)); + if (err) { + EXIT; + return err; } return put_user(err, (int *) arg); } case OBD_IOC_CREATE: { - struct oic_create_s foo; - objid id; + struct oic_attr_s *foo = karg; - if ( copy_from_user(&foo, (const void *)arg, sizeof(foo)) ) - return -EFAULT; + err = copy_from_user(&foo, (const void *)arg, sizeof(foo)); + if (err) { + EXIT; + return err; + } /* has this minor been registered? */ if ( !(obddev->obd_flags & OBD_ATTACHED) || @@ -616,51 +452,46 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, CDEBUG(D_IOCTL, "Device not attached or set up\n"); return -ENODEV; } - conn.oc_id = foo.conn_id; + conn.oc_id = foo->conn_id; if ( !OBT(obddev) || !OBP(obddev, create) ) return -EOPNOTSUPP; - err = OBP(obddev, create)(&conn, foo.prealloc, &id); + err = OBP(obddev, create)(&conn, &foo->obdo); if (err) { - CDEBUG(D_IOCTL, "create: obd_inode_new failure\n"); - /* 0 is the only error value */ - put_user(0, (int *) arg); + EXIT; return err; } - return put_user(id, (int *) arg); + err = copy_to_user((int *)arg, &foo, sizeof(foo)); + EXIT; + return err; } + case OBD_IOC_DESTROY: { - struct destroy_s { - unsigned int conn_id; - unsigned int ino; - } destroy; - obdattr *oa; + struct oic_attr_s *foo = karg; - if ( ! (oa = obd_empty_oa()) ) - return -ENOMEM; - /* has this minor been registered? */ if (!obddev->obd_type) return -ENODEV; - copy_from_user(&destroy, (int *)arg, sizeof(struct destroy_s)); + err = copy_from_user(&foo, (int *)arg, sizeof(*foo)); + if ( err ) { + EXIT; + return err; + } + if ( !OBT(obddev) || !OBP(obddev, destroy) ) return -EOPNOTSUPP; - oa->i_ino = destroy.ino; - conn.oc_id = destroy.conn_id; - err = OBP(obddev, destroy)(&conn, oa); - OBD_FREE(oa, sizeof(*oa)); + conn.oc_id = foo->conn_id; + err = OBP(obddev, destroy)(&conn, &foo->obdo); + EXIT; return err; } - case OBD_IOC_SETATTR: { - struct oic_attr_s foo; - obdattr *oa; - if ( ! (oa = obd_empty_oa()) ) - return -ENOMEM; + case OBD_IOC_SETATTR: { + struct oic_attr_s *foo = karg; /* has this minor been registered? */ if (!obddev->obd_type) @@ -673,98 +504,90 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, if ( !OBT(obddev) || !OBP(obddev, setattr) ) return -EOPNOTSUPP; - oa->i_ino = foo.ino; - inode_setattr(oa, &foo.iattr); - conn.oc_id = foo.conn_id; - err = OBP(obddev, setattr)(&conn, oa); - OBD_FREE(oa, sizeof(*oa)); + conn.oc_id = foo->conn_id; + err = OBP(obddev, setattr)(&conn, &foo->obdo); + EXIT; return err; } case OBD_IOC_GETATTR: { - struct oic_getattr { - unsigned int conn_id; - unsigned long ino; - } foo; - struct iattr iattr; - obdattr *oa; + struct oic_attr_s *foo = karg; err = copy_from_user(&foo, (int *)arg, sizeof(foo)); if (err) return err; - conn.oc_id = foo.conn_id; - oa = obd_oa_fromid(&conn, foo.ino); - if ( !oa ) - return -ENOENT; + conn.oc_id = foo->conn_id; + err = OBP(obddev, getattr)(&conn, &foo->obdo); + if ( err ) { + EXIT; + return err; + } - inode_to_iattr(oa, &iattr); - err = copy_to_user((int *)arg, &iattr, sizeof(iattr)); + err = copy_to_user((int *)arg, &foo, sizeof(foo)); + EXIT; return err; } case OBD_IOC_READ: { - obdattr *oa = NULL; int err; - struct oic_rw_s rw_s; /* read, write ioctl str */ + struct oic_rw_s *rw_s = karg; /* read, write ioctl str */ err = copy_from_user(&rw_s, (int *)arg, sizeof(rw_s)); - if ( err ) - goto READ_OUT; + if ( err ) { + EXIT; + return err; + } - conn.oc_id = rw_s.conn_id; - if ( ! (oa = obd_oa_fromid(&conn, rw_s.id)) ) - return -ENOENT; + conn.oc_id = rw_s->conn_id; if ( !OBT(obddev) || !OBP(obddev, read) ) { err = -EOPNOTSUPP; - goto READ_OUT; + EXIT; + return err; } - err = OBP(obddev, read)(&conn, oa, rw_s.buf, &rw_s.count, - rw_s.offset); - if ( err ) - goto READ_OUT; - - err = copy_to_user((int*)arg, &rw_s.count, sizeof(rw_s.count)); - - READ_OUT: - if ( oa ) - OBD_FREE(oa, sizeof(*oa)); + err = OBP(obddev, read)(&conn, &rw_s->obdo, rw_s->buf, + &rw_s->count, rw_s->offset); + if ( err ) { + EXIT; + return err; + } + + err = copy_to_user((int*)arg, &rw_s->count, sizeof(rw_s->count)); + EXIT; return err; } case OBD_IOC_WRITE: { - obdattr *oa = NULL; - struct oic_rw_s rw_s; /* read, write ioctl str */ + struct oic_rw_s *rw_s = karg; /* read, write ioctl str */ err = copy_from_user(&rw_s, (int *)arg, sizeof(rw_s)); - if ( err ) - goto WRITE_OUT; + if ( err ) { + EXIT; + return err; + } - conn.oc_id = rw_s.conn_id; - oa = obd_oa_fromid(&conn, rw_s.id); - if ( !oa ) - return -ENOENT; + conn.oc_id = rw_s->conn_id; if ( !OBT(obddev) || !OBP(obddev, write) ) { err = -EOPNOTSUPP; - goto WRITE_OUT; + return err; } - err = OBP(obddev, write)(&conn, oa, rw_s.buf, &rw_s.count, - rw_s.offset); - if ( err ) - goto WRITE_OUT; - - err = copy_to_user((int*)arg, &rw_s.count, sizeof(rw_s.count)); + err = OBP(obddev, write)(&conn, &rw_s->obdo, rw_s->buf, + &rw_s->count, rw_s->offset); + if ( err ) { + EXIT; + return err; + } - WRITE_OUT: - OBD_FREE(oa, sizeof(*oa)); + err = copy_to_user((int*)arg, &rw_s->count, sizeof(rw_s->count)); + EXIT; return err; } case OBD_IOC_PREALLOCATE: { - struct oic_prealloc_s prealloc; + struct oic_prealloc_s *prealloc = karg; /* has this minor been registered? */ if (!obddev->obd_type) @@ -783,13 +606,17 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, if ( !OBT(obddev) || !OBP(obddev, preallocate) ) return -EOPNOTSUPP; - conn.oc_id = prealloc.cli_id; - err = OBP(obddev, preallocate)(&conn, &prealloc.alloc, - prealloc.inodes); - if ( err ) + conn.oc_id = prealloc->cli_id; + err = OBP(obddev, preallocate)(&conn, &prealloc->alloc, + prealloc->ids); + if ( err ) { + EXIT; return err; + } - return copy_to_user((int *)arg, &prealloc, sizeof(prealloc)); + err =copy_to_user((int *)arg, &prealloc, sizeof(prealloc)); + EXIT; + return err; } case OBD_IOC_STATFS: { struct statfs *tmp; @@ -808,12 +635,79 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, conn.oc_id = conn_id; err = OBP(obddev, statfs)(&conn, &buf); - if ( err ) + if ( err ) { + EXIT; return err; + } err = copy_to_user(tmp, &buf, sizeof(buf)); + EXIT; return err; } + case OBD_IOC_COPY: { + struct ioc_mv_s *mvdata = karg; + + if ( (!(obddev->obd_flags & OBD_SET_UP)) || + (!(obddev->obd_flags & OBD_ATTACHED))) { + CDEBUG(D_IOCTL, "Device not attached or set up\n"); + return -ENODEV; + } + + /* get main structure */ + err = copy_from_user(&mvdata, (void *) arg, sizeof(*mvdata)); + if (err) { + EXIT; + return err; + } + + if ( !OBT(obddev) || !OBP(obddev, copy) ) + return -EOPNOTSUPP; + + /* do the partition */ + CDEBUG(D_IOCTL, "Copy %d, type %s dst %Ld src %Ld\n", dev, + obddev->obd_type->typ_name, mvdata->dst.o_id, + mvdata->src.o_id); + + conn.oc_id = mvdata->src_conn_id; + + err = OBP(obddev, copy)(&conn, &mvdata->dst, + &conn, &mvdata->src, + mvdata->src.o_size, 0); + return err; + } + + case OBD_IOC_MIGR: { + struct ioc_mv_s *mvdata = karg; + + if ( (!(obddev->obd_flags & OBD_SET_UP)) || + (!(obddev->obd_flags & OBD_ATTACHED))) { + CDEBUG(D_IOCTL, "Device not attached or set up\n"); + return -ENODEV; + } + + err = copy_from_user(&mvdata, (void *) arg, sizeof(*mvdata)); + if (err) { + EXIT; + return err; + } + + CDEBUG(D_IOCTL, "Migrate copying %d\n", sizeof(mvdata)); + + if ( !OBT(obddev) || !OBP(obddev, migrate) ) + return -EOPNOTSUPP; + + /* do the partition */ + CDEBUG(D_IOCTL, "Migrate %d, type %s conn %d src %Ld dst %Ld\n", + dev, obddev->obd_type->typ_name, mvdata->src_conn_id, + mvdata->src.o_id, mvdata->dst.o_id); + + conn.oc_id = mvdata->src_conn_id; + err = OBP(obddev, migrate)(&conn, &mvdata->dst, &mvdata->src, + mvdata->dst.o_size, 0); + + return err; + } + default: { struct obd_type *type; struct oic_generic input; @@ -852,7 +746,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, /* get the generic data */ karg = input.att_data; - err = getdata(input.att_datalen, &karg); + err = getdata(input.att_datalen, karg); if ( err ) { EXIT; return err; @@ -986,6 +880,7 @@ EXPORT_SYMBOL(gen_client); EXPORT_SYMBOL(gen_cleanup); EXPORT_SYMBOL(gen_disconnect); EXPORT_SYMBOL(gen_copy_data); +EXPORT_SYMBOL(obdo_cachep); /* EXPORT_SYMBOL(gen_multi_attach); */ EXPORT_SYMBOL(gen_multi_setup); diff --git a/lustre/obdclass/genops.c b/lustre/obdclass/genops.c index 3a12443..be13204 100644 --- a/lustre/obdclass/genops.c +++ b/lustre/obdclass/genops.c @@ -6,22 +6,50 @@ * */ -#include -#include -#include +#include +#include +#include #include +#include +#include #include -#include -#include -#include -#include -#include -#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + #include #include extern struct obd_device obd_dev[MAX_OBD_DEVICES]; +kmem_cache_t *obdo_cachep; + +int obd_init_obdo_cache(void) +{ + /* XXX need to free this somewhere? */ + ENTRY; + obdo_cachep = kmem_cache_create("obdo_cache", + sizeof(struct obdo), + 0, SLAB_HWCACHE_ALIGN, + NULL, NULL); + if (obdo_cachep == NULL) { + EXIT; + return -ENOMEM; + } + EXIT; + return 0; +} + /* map connection to client */ struct obd_client *gen_client(struct obd_conn *conn) @@ -95,7 +123,7 @@ int gen_disconnect(struct obd_conn *conn) * used to make calls to these devices. * data holds nothing */ -int gen_multi_setup(struct obd_device *obddev, int len, void *data) +int gen_multi_setup(struct obd_device *obddev, uint32_t len, void *data) { int i; @@ -200,15 +228,16 @@ void lck_page(struct page *page) } /* XXX this should return errors correctly, so should migrate!!! */ -int gen_copy_data(struct obd_conn *conn, obdattr *dst, obdattr *src) +int gen_copy_data(struct obd_conn *dst_conn, struct obdo *dst, + struct obd_conn *src_conn, struct obdo *src) { struct page *page; unsigned long index = 0; int rc; ENTRY; - CDEBUG(D_INODE, "src: ino %ld blocks %ld, size %Ld, dst: ino %ld\n", - src->i_ino, src->i_blocks, src->i_size, dst->i_ino); + CDEBUG(D_INODE, "src: ino %Ld blocks %Ld, size %Ld, dst: ino %Ld\n", + src->o_id, src->o_blocks, src->o_size, dst->o_id); page = alloc_page(GFP_USER); if ( !page ) { EXIT; @@ -217,16 +246,20 @@ int gen_copy_data(struct obd_conn *conn, obdattr *dst, obdattr *src) lck_page(page); - while (index < ((src->i_size + PAGE_SIZE - 1) >> PAGE_SHIFT)) { + while (index < ((src->o_size + PAGE_SIZE - 1) >> PAGE_SHIFT)) { page->index = index; - rc = OBP(conn->oc_dev, brw)(READ, conn, src, page, 0); + rc = OBP(src_conn->oc_dev, brw) + (READ, src_conn, src, (char *)page_address(page), + PAGE_SIZE, (page->index) << PAGE_SHIFT, 0); if ( rc != PAGE_SIZE ) break; CDEBUG(D_INODE, "Read page %ld ...\n", page->index); - rc = OBP(conn->oc_dev, brw)(WRITE, conn, dst, page, 1); + rc = OBP(dst_conn->oc_dev, brw) + (WRITE, dst_conn, dst, (char *)page_address(page), + PAGE_SIZE, (page->index) << PAGE_SHIFT, 1); if ( rc != PAGE_SIZE) break; @@ -234,8 +267,8 @@ int gen_copy_data(struct obd_conn *conn, obdattr *dst, obdattr *src) index ++; } - dst->i_size = src->i_size; - dst->i_blocks = src->i_blocks; + dst->o_size = src->o_size; + dst->o_blocks = src->o_blocks; UnlockPage(page); __free_page(page); diff --git a/lustre/obdfs/namei.c b/lustre/obdfs/namei.c index b874135..b16a5ef 100644 --- a/lustre/obdfs/namei.c +++ b/lustre/obdfs/namei.c @@ -454,7 +454,7 @@ int obdfs_create (struct inode * dir, struct dentry * dentry, int mode) struct page *page; struct ext2_dir_entry_2 * de; int err = -EIO; - objid id; + obd_id id; ENTRY; @@ -506,7 +506,7 @@ int obdfs_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev) struct ext2_dir_entry_2 * de; int err; - objid id; + obd_id id; ENTRY; @@ -557,7 +557,7 @@ int obdfs_mkdir(struct inode * dir, struct dentry * dentry, int mode) struct page *page, *inode_page; struct ext2_dir_entry_2 * de; int err; - objid id; + obd_id id; ENTRY; @@ -835,7 +835,7 @@ int obdfs_symlink (struct inode * dir, struct dentry *dentry, const char * symna char * link; int i, l, err = -EIO; char c; - objid id; + obd_id id; ENTRY; /* -- 1.8.3.1