From a77e82b2687444662fdb165e330e2e4871cb6868 Mon Sep 17 00:00:00 2001 From: braam Date: Tue, 23 Apr 2002 19:23:24 +0000 Subject: [PATCH] - newdev feature in obdctl --- lustre/include/linux/lustre_idl.h | 1 + lustre/include/linux/obd.h | 2 ++ lustre/obdclass/class_obd.c | 25 +++++++++++++++++++- lustre/utils/obdctl.c | 48 +++++++++++++++++++++++++++++++++------ 4 files changed, 68 insertions(+), 8 deletions(-) diff --git a/lustre/include/linux/lustre_idl.h b/lustre/include/linux/lustre_idl.h index 74c9c90..c36bf31 100644 --- a/lustre/include/linux/lustre_idl.h +++ b/lustre/include/linux/lustre_idl.h @@ -550,6 +550,7 @@ static inline int obd_ioctl_getdata(char *buf, char *end, void *arg) #define OBD_IOC_BRW_READ _IOWR('f', 27, long) #define OBD_IOC_BRW_WRITE _IOWR('f', 28, long) #define OBD_IOC_NAME2DEV _IOWR('f', 29, long) +#define OBD_IOC_NEWDEV _IOWR('f', 30, long) #define OBD_IOC_DEC_FS_USE_COUNT _IO ('f', 32 ) diff --git a/lustre/include/linux/obd.h b/lustre/include/linux/obd.h index 1485ef0..b1b6a06 100644 --- a/lustre/include/linux/obd.h +++ b/lustre/include/linux/obd.h @@ -196,6 +196,8 @@ struct obd_ops { int (*o_cleanup)(struct obd_device *dev); int (*o_connect)(struct obd_conn *conn); int (*o_disconnect)(struct obd_conn *conn); + + int (*o_statfs)(struct obd_conn *conn, struct statfs *statfs); int (*o_preallocate)(struct obd_conn *, obd_count *req, obd_id *ids); int (*o_create)(struct obd_conn *conn, struct obdo *oa); diff --git a/lustre/obdclass/class_obd.c b/lustre/obdclass/class_obd.c index 0aa6e78..a39dfcc 100644 --- a/lustre/obdclass/class_obd.c +++ b/lustre/obdclass/class_obd.c @@ -158,7 +158,7 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, memset(buf, 0, sizeof(buf)); if (!obd && cmd != OBD_IOC_DEVICE && cmd != TCGETS - && cmd != OBD_IOC_NAME2DEV) { + && cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_NEWDEV) { CERROR("OBD ioctl: No device\n"); RETURN(-EINVAL); } @@ -207,6 +207,29 @@ static int obd_class_ioctl (struct inode * inode, struct file * filp, RETURN(err); } + case OBD_IOC_NEWDEV: { + int dev = -1; + int i; + + filp->private_data = NULL; + for (i = 0 ; i < MAX_OBD_DEVICES ; i++) { + struct obd_device *obd = &obd_dev[i]; + if (!obd->obd_type) { + filp->private_data = obd; + dev = i; + break; + } + } + + + data->ioc_dev = dev; + if (dev == -1) + RETURN(-EINVAL); + + err = copy_to_user((int *)arg, data, sizeof(*data)); + RETURN(err); + } + case OBD_IOC_ATTACH: { struct obd_type *type; diff --git a/lustre/utils/obdctl.c b/lustre/utils/obdctl.c index 98517e8..b9fef32 100644 --- a/lustre/utils/obdctl.c +++ b/lustre/utils/obdctl.c @@ -122,6 +122,18 @@ char * obdo_print(struct obdo *obd) return strdup(buf); } +int getfd() +{ + if (fd == -1) + fd = open("/dev/obd", O_RDWR); + if (fd == -1) { + fprintf(stderr, "error: opening /dev/obd: %s\n", + strerror(errno)); + return -1; + } + return 0; +} + static char *cmdname(char *func) { static char buf[512]; @@ -432,6 +444,32 @@ static int jt_cleanup(int argc, char **argv) return rc; } +static int jt_newdev(int argc, char **argv) +{ + struct obd_ioctl_data data; + int rc; + + if (getfd()) + return -1; + + IOCINIT(data); + + if (argc != 1) { + fprintf(stderr, "usage: %s\n", cmdname(argv[0])); + return -1; + } + + rc = ioctl(fd, OBD_IOC_NEWDEV , &data); + if (rc < 0) + fprintf(stderr, "error: %s: %s\n", cmdname(argv[0]), + strerror(rc=errno)); + else { + printf("Current device set to %d\n", data.ioc_dev); + } + + return rc; +} + static int jt_attach(int argc, char **argv) { struct obd_ioctl_data data; @@ -481,13 +519,8 @@ static int jt_name2dev(int argc, char **argv) struct obd_ioctl_data data; int rc; - if (fd == -1) - fd = open("/dev/obd", O_RDWR); - if (fd == -1) { - fprintf(stderr, "error: %s: opening /dev/obd: %s\n", - cmdname(argv[0]), strerror(errno)); - return errno; - } + if (getfd()) + return -1; IOCINIT(data); @@ -861,6 +894,7 @@ command_t cmdlist[] = { "--threads "}, /* Device configuration commands */ + {"newdev", jt_newdev, 0, "set device to a new unused obd (no args)"}, {"device", jt_device, 0, "set current device (args device_no name)"}, {"name2dev", jt_name2dev, 0, "set device by name (args name)"}, {"attach", jt_attach, 0, "name the type of device (args: type data"}, -- 1.8.3.1