From 66499317a6e5963e3e88e53922ffeadca466985b Mon Sep 17 00:00:00 2001 From: braam Date: Mon, 21 Jan 2002 01:17:17 +0000 Subject: [PATCH] Fix a broken macro. --- lustre/include/linux/obd_class.h | 139 ++++++++++++++++++++++++++++++++- lustre/llite/super.c | 19 +---- lustre/obdclass/class_obd.c | 164 ++++++++++----------------------------- lustre/obdfs/namei.c | 7 +- lustre/obdfs/super.c | 2 +- lustre/utils/obdctl.c | 44 ++++++++++- 6 files changed, 225 insertions(+), 150 deletions(-) diff --git a/lustre/include/linux/obd_class.h b/lustre/include/linux/obd_class.h index 398c7eb..80c2b15 100644 --- a/lustre/include/linux/obd_class.h +++ b/lustre/include/linux/obd_class.h @@ -146,12 +146,147 @@ struct obd_request { char *pbuf1; }; - - +static inline int obd_check_conn(struct obd_conn *conn) +{ + struct obd_device *obd; + if (!conn) { + printk("obd_check_conn: NULL conn\n"); + return -ENOTCONN; + } + obd = conn->oc_dev; + if (!obd) { + printk("obd_check_conn: NULL obd\n"); + return -ENODEV; + } + + if (!obd->obd_flags & OBD_ATTACHED ) { + printk("obd_check_conn: obd %d not attached\n", obd->obd_minor); + return -ENODEV; + } + + if (!obd->obd_flags & OBD_SET_UP) { + printk("obd_check_conn: obd %d not setup\n", obd->obd_minor); + return -ENODEV; + } + + if (!obd->obd_type) { + printk("obd_check_conn: obd %d not typed\n", obd->obd_minor); + return -ENODEV; + } + + if (!obd->obd_type->typ_ops) { + printk("obd_check_conn: obd %d no operations\n", obd->obd_minor); + return -EOPNOTSUPP; + } + return 0; +} #define OBT(dev) dev->obd_type->typ_ops #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op +#define OBD_CHECK_OP(conn,op) do { \ + int rc = obd_check_conn(conn);\ + if (rc) { printk("obd: error in operation: " #op "\n"); return rc; }\ + if (!OBP(conn->oc_dev,op)) { printk("obd_" #op ": dev %d no operation\n", conn->oc_dev->obd_minor); \ + return -EOPNOTSUPP;\ + }\ +} while (0) + +static inline int obd_get_info(struct obd_conn *conn, obd_count keylen, void *key, + obd_count *vallen, void **val) +{ + int rc; + OBD_CHECK_OP(conn,get_info); + + rc = OBP(conn->oc_dev, get_info)(conn, keylen, key, vallen, val); + EXIT; + return rc; +} + +static inline int obd_set_info(struct obd_conn *conn, obd_count keylen, void *key, + obd_count vallen, void *val) +{ + int rc; + OBD_CHECK_OP(conn,set_info); + + rc = OBP(conn->oc_dev, set_info)(conn, keylen, key, vallen, val); + EXIT; + return rc; +} + +static inline int obd_cleanup(struct obd_device *obd) +{ + struct obd_conn conn; + int rc; + conn.oc_dev = obd; + + OBD_CHECK_OP((&conn),cleanup); + + rc = OBP(conn.oc_dev, cleanup)(obd); + EXIT; + return rc; +} + +static inline int obd_create(struct obd_conn *conn, struct obdo *obdo) +{ + int rc; + OBD_CHECK_OP(conn,create); + + rc = OBP(conn->oc_dev, create)(conn, obdo); + EXIT; + return rc; +} + +static inline int obd_destroy(struct obd_conn *conn, struct obdo *obdo) +{ + int rc; + OBD_CHECK_OP(conn,destroy); + + rc = OBP(conn->oc_dev, destroy)(conn, obdo); + EXIT; + return rc; +} + +static inline int obd_getattr(struct obd_conn *conn, struct obdo *obdo) +{ + int rc; + OBD_CHECK_OP(conn,getattr); + + rc = OBP(conn->oc_dev, getattr)(conn, obdo); + EXIT; + return rc; +} + +static inline int obd_setattr(struct obd_conn *conn, struct obdo *obdo) +{ + int rc; + OBD_CHECK_OP(conn,setattr); + + rc = OBP(conn->oc_dev, setattr)(conn, obdo); + EXIT; + return rc; +} + +static inline int obd_connect(struct obd_conn *conn) +{ + int rc; + OBD_CHECK_OP(conn,connect); + + rc = OBP(conn->oc_dev, connect)(conn); + EXIT; + return rc; +} + +static inline int obd_disconnect(struct obd_conn *conn) +{ + int rc; + OBD_CHECK_OP(conn,disconnect); + + rc = OBP(conn->oc_dev, disconnect)(conn); + EXIT; + return rc; +} + #endif /* This value is not arbitrarily chosen. KIO_STATIC_PAGES from linux/iobuf.h */ diff --git a/lustre/llite/super.c b/lustre/llite/super.c index 66d0a40..d788210 100644 --- a/lustre/llite/super.c +++ b/lustre/llite/super.c @@ -1,5 +1,5 @@ /* - * OBDFS Super operations + * Lustre Light Super operations * * This code is issued under the GNU General Public License. * See the file COPYING in this distribution @@ -121,25 +121,14 @@ static struct super_block * ll_read_super(struct super_block *sb, } CDEBUG(D_INFO, "\n"); - obddev = &obd_dev[devno]; - - - CDEBUG(D_INFO, "\n"); - if ( ! (obddev->obd_flags & OBD_ATTACHED) || - ! (obddev->obd_flags & OBD_SET_UP) ){ - printk("device %s not attached or not set up (%d)\n", - device, MINOR(devno)); - EXIT; - goto ERR;; - } - CDEBUG(D_INFO, "\n"); + obddev = &obd_dev[devno]; sbi->ll_obd = obddev; sbi->ll_ops = sbi->ll_obd->obd_type->typ_ops; sbi->ll_conn.oc_dev = obddev; - CDEBUG(D_INFO, "\n"); - err = sbi->ll_ops->o_connect(&sbi->ll_conn); + + err = obd_connect(&sbi->ll_conn); CDEBUG(D_INFO, "\n"); if ( err ) { printk("OBDFS: cannot connect to %s\n", device); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 7b75e89..3202dff 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -271,33 +271,13 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, } case OBD_IOC_CLEANUP: { ENTRY; - /* has this minor been registered? */ - if (!obd->obd_type) { - printk("OBD cleanup dev %d has no type.\n", - obd->obd_minor); - EXIT; - return -ENODEV; - } - if ( (!(obd->obd_flags & OBD_SET_UP)) || - (!(obd->obd_flags & OBD_ATTACHED))) { - printk("OBD cleanup device %d not attached/set up\n", - obd->obd_minor); - EXIT; - return -ENODEV; - } - - if ( !OBT(obd) || !OBP(obd, cleanup) ) - goto cleanup_out; - - /* cleanup has no argument */ - err = OBP(obd, cleanup)(obd); + err = obd_cleanup(obd); if ( err ) { EXIT; return err; } - cleanup_out: obd->obd_flags &= ~OBD_SET_UP; obd->obd_type->typ_refcnt--; EXIT; @@ -306,19 +286,11 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, case OBD_IOC_CONNECT: { - if ( (!(obd->obd_flags & OBD_SET_UP)) || - (!(obd->obd_flags & OBD_ATTACHED))) { - CDEBUG(D_IOCTL, "Device not attached or set up\n"); - return -ENODEV; - } - - if ( !OBT(obd) || !OBP(obd, connect) ) - return -EOPNOTSUPP; - conn.oc_id = data->ioc_conn1; conn.oc_dev = obd; - - err = OBP(obd, connect)(&conn); + + err = obd_connect(&conn); + CDEBUG(D_IOCTL, "assigned connection %d\n", conn.oc_id); data->ioc_conn1 = conn.oc_id; if ( err ) @@ -326,18 +298,13 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return copy_to_user((int *)arg, data, sizeof(*data)); } - case OBD_IOC_DISCONNECT: { - if (!obd->obd_type) - return -ENODEV; - - if ( !OBT(obd) || !OBP(obd, disconnect)) - return -EOPNOTSUPP; - + case OBD_IOC_DISCONNECT: { conn.oc_id = data->ioc_conn1; conn.oc_dev = obd; - OBP(obd, disconnect)(&conn); - return 0; + + err = obd_disconnect(&conn); + return err; } case OBD_IOC_DEC_USE_COUNT: { @@ -346,19 +313,10 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, } case OBD_IOC_CREATE: { - /* has this minor been registered? */ - if ( !(obd->obd_flags & OBD_ATTACHED) || - !(obd->obd_flags & OBD_SET_UP)) { - CDEBUG(D_IOCTL, "Device not attached or set up\n"); - return -ENODEV; - } conn.oc_id = data->ioc_conn1; conn.oc_dev = obd; - if ( !OBT(obd) || !OBP(obd, create) ) - return -EOPNOTSUPP; - - err = OBP(obd, create)(&conn, &data->ioc_obdo1); + err = obd_create(&conn, &data->ioc_obdo1); if (err) { EXIT; return err; @@ -370,22 +328,40 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, } case OBD_IOC_GETATTR: { - /* has this minor been registered? */ - printk("---> getattr!"); - if ( !(obd->obd_flags & OBD_ATTACHED) || - !(obd->obd_flags & OBD_SET_UP)) { - CDEBUG(D_IOCTL, "Device not attached or set up\n"); - return -ENODEV; + conn.oc_id = data->ioc_conn1; + conn.oc_dev = obd; + + err = obd_getattr(&conn, &data->ioc_obdo1); + if (err) { + EXIT; + return err; } + + err = copy_to_user((int *)arg, data, sizeof(*data)); + EXIT; + return err; + } + + case OBD_IOC_SETATTR: { conn.oc_id = data->ioc_conn1; conn.oc_dev = obd; - if ( !OBT(obd) || !OBP(obd, getattr) ) { - EXIT; - return -EOPNOTSUPP; - } + err = obd_setattr(&conn, &data->ioc_obdo1); + if (err) { + EXIT; + return err; + } - err = OBP(obd, getattr)(&conn, &data->ioc_obdo1); + err = copy_to_user((int *)arg, data, sizeof(*data)); + EXIT; + return err; + } + + case OBD_IOC_DESTROY: { + conn.oc_id = data->ioc_conn1; + conn.oc_dev = obd; + + err = obd_destroy(&conn, &data->ioc_obdo1); if (err) { EXIT; return err; @@ -394,7 +370,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, err = copy_to_user((int *)arg, data, sizeof(*data)); EXIT; return err; - } + } #if 0 case OBD_IOC_SYNC: { @@ -428,68 +404,6 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, return put_user(err, (int *) arg); } - case OBD_IOC_DESTROY: { - struct oic_attr_s *attr = tmp_buf; - - /* has this minor been registered? */ - if (!obd->obd_type) - return -ENODEV; - - err = copy_from_user(attr, (int *)arg, sizeof(*attr)); - if ( err ) { - EXIT; - return err; - } - - if ( !OBT(obd) || !OBP(obd, destroy) ) - return -EOPNOTSUPP; - - conn.oc_id = attr->conn_id; - err = OBP(obd, destroy)(&conn, &attr->obdo); - EXIT; - return err; - } - - case OBD_IOC_SETATTR: { - struct oic_attr_s *attr = tmp_buf; - - /* has this minor been registered? */ - if (!obd->obd_type) - return -ENODEV; - - err = copy_from_user(attr, (int *)arg, sizeof(*attr)); - if (err) - return err; - - if ( !OBT(obd) || !OBP(obd, setattr) ) - return -EOPNOTSUPP; - - conn.oc_id = attr->conn_id; - err = OBP(obd, setattr)(&conn, &attr->obdo); - EXIT; - return err; - } - - case OBD_IOC_GETATTR: { - struct oic_attr_s *attr = tmp_buf; - - err = copy_from_user(attr, (int *)arg, sizeof(*attr)); - if (err) - return err; - - conn.oc_id = attr->conn_id; - ODEBUG(&attr->obdo); - err = OBP(obd, getattr)(&conn, &attr->obdo); - if ( err ) { - EXIT; - return err; - } - - err = copy_to_user((int *)arg, attr, sizeof(*attr)); - EXIT; - return err; - } - case OBD_IOC_READ: { int err; struct oic_rw_s *rw_s = tmp_buf; /* read, write ioctl str */ diff --git a/lustre/obdfs/namei.c b/lustre/obdfs/namei.c index f0e55c6..e912050 100644 --- a/lustre/obdfs/namei.c +++ b/lustre/obdfs/namei.c @@ -139,11 +139,6 @@ static struct inode *obdfs_new_inode(struct inode *dir, int mode) int err; ENTRY; - if (IOPS(dir, create) == NULL) { - printk(KERN_ERR __FUNCTION__ ": no create method!\n"); - EXIT; - return ERR_PTR(-EIO); - } oa = obdo_alloc(); if (!oa) { EXIT; @@ -154,7 +149,7 @@ static struct inode *obdfs_new_inode(struct inode *dir, int mode) oa->o_mode = mode; oa->o_valid |= OBD_MD_FLMODE; CDEBUG(D_INODE, "\n"); - err = IOPS(dir, create)(IID(dir), oa); + err = obd_create(IID(dir), oa); CDEBUG(D_INODE, "\n"); if ( err ) { diff --git a/lustre/obdfs/super.c b/lustre/obdfs/super.c index f3c36a7..e0ac338 100644 --- a/lustre/obdfs/super.c +++ b/lustre/obdfs/super.c @@ -141,7 +141,7 @@ static struct super_block * obdfs_read_super(struct super_block *sb, sbi->osi_ops = sbi->osi_obd->obd_type->typ_ops; sbi->osi_conn.oc_dev = obddev; - err = sbi->osi_ops->o_connect(&sbi->osi_conn); + err = obd_connect(&sbi->osi_conn); if ( err ) { printk("OBDFS: cannot connect to %s\n", device); EXIT; diff --git a/lustre/utils/obdctl.c b/lustre/utils/obdctl.c index 47a4f98..f6552a6 100644 --- a/lustre/utils/obdctl.c +++ b/lustre/utils/obdctl.c @@ -303,7 +303,7 @@ static int jt_create(int argc, char **argv) } else { data.ioc_obdo1.o_mode = 0100644; } - data.ioc_obdo1.o_mode = OBD_MD_FLMODE; + data.ioc_obdo1.o_valid = OBD_MD_FLMODE; if (argc > 3) { silent = strtoul(argv[3], NULL, 0); @@ -323,6 +323,46 @@ static int jt_create(int argc, char **argv) return 0; } +static int jt_setattr(int argc, char **argv) +{ + struct obd_ioctl_data data; + int rc; + + IOCINIT(data); + if (argc < 2) { + printf("usage %s id mode\n", argv[0]); + } + + data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0); + data.ioc_obdo1.o_mode = strtoul(argv[2], NULL, 0); + data.ioc_obdo1.o_valid = OBD_MD_FLMODE; + + rc = ioctl(fd, OBD_IOC_SETATTR , &data); + if (rc < 0) { + printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno)); + } + return rc; +} + +static int jt_destroy(int argc, char **argv) +{ + struct obd_ioctl_data data; + int rc; + + IOCINIT(data); + if (argc < 1) { + printf("usage %s id\n", argv[0]); + } + + data.ioc_obdo1.o_id = strtoul(argv[1], NULL, 0); + + rc = ioctl(fd, OBD_IOC_DESTROY , &data); + if (rc < 0) { + printf("setattr: %x %s\n", OBD_IOC_SETATTR, strerror(errno)); + } + return rc; +} + static int jt_getattr(int argc, char **argv) { struct obd_ioctl_data data; @@ -355,7 +395,9 @@ command_t list[] = { {"detach", jt_detach, 0, "detach the current device (arg: )"}, {"cleanup", jt_cleanup, 0, "cleanup the current device (arg: )"}, {"create", jt_create, 0, "create [count [mode [silent]]]"}, + {"destroy", jt_destroy, 0, "destroy id"}, {"getattr", jt_getattr, 0, "getattr id"}, + {"setattr", jt_setattr, 0, "setattr id mode"}, {"connect", jt_connect, 0, "connect - get a connection to device"}, {"disconnect", jt_disconnect, 0, "disconnect - break connection to device"}, {"help", Parser_help, 0, "help"}, -- 1.8.3.1