/* opening /dev/obd */
static int obd_class_open(struct inode * inode, struct file * file)
{
- struct obd_class_user_state *ocus;
ENTRY;
- OBD_ALLOC(ocus, sizeof(*ocus));
- if (ocus == NULL)
- return (-ENOMEM);
-
- INIT_LIST_HEAD(&ocus->ocus_conns);
- file->private_data = ocus;
-
PORTAL_MODULE_USE;
RETURN(0);
}
/* closing /dev/obd */
static int obd_class_release(struct inode * inode, struct file * file)
{
- struct obd_class_user_state *ocus = file->private_data;
- struct obd_class_user_conn *c;
ENTRY;
- while (!list_empty (&ocus->ocus_conns)) {
- c = list_entry (ocus->ocus_conns.next,
- struct obd_class_user_conn, ocuc_chain);
- list_del (&c->ocuc_chain);
-
- CDEBUG (D_IOCTL, "Auto-disconnect exp %p\n", c->ocuc_exp);
-
- down (&obd_conf_sem);
- obd_disconnect (c->ocuc_exp, 0);
- up (&obd_conf_sem);
-
- OBD_FREE (c, sizeof (*c));
- }
-
- OBD_FREE (ocus, sizeof (*ocus));
-
PORTAL_MODULE_UNUSE;
RETURN(0);
}
#endif
-static int obd_class_add_user_exp(struct obd_class_user_state *ocus,
- struct obd_export *exp)
-{
- struct obd_class_user_conn *c;
- ENTRY;
- /* NB holding obd_conf_sem */
-
- OBD_ALLOC (c, sizeof (*c));
- if (c == NULL)
- RETURN(-ENOMEM);
-
- c->ocuc_exp = class_export_get(exp);
- list_add (&c->ocuc_chain, &ocus->ocus_conns);
- RETURN(0);
-}
-
-static void obd_class_remove_user_exp(struct obd_class_user_state *ocus,
- struct obd_export *exp)
-{
- struct obd_class_user_conn *c;
- ENTRY;
-
- /* NB holding obd_conf_sem or last reference */
-
- list_for_each_entry(c, &ocus->ocus_conns, ocuc_chain) {
- if (exp == c->ocuc_exp) {
- list_del (&c->ocuc_chain);
- OBD_FREE (c, sizeof (*c));
- class_export_put(exp);
- EXIT;
- return;
- }
- }
- EXIT;
-}
-
static inline void obd_data2conn(struct lustre_handle *conn,
struct obd_ioctl_data *data)
{
RETURN(rc);
}
-int class_handle_ioctl(struct obd_class_user_state *ocus, unsigned int cmd,
- unsigned long arg)
+int class_handle_ioctl(unsigned int cmd, unsigned long arg)
{
char *buf = NULL;
struct obd_ioctl_data *data;
struct portals_debug_ioctl_data *debug_data;
- struct obd_device *obd = ocus->ocus_current_obd;
- struct lustre_handle conn;
+ struct obd_device *obd = NULL;
int err = 0, len = 0, serialised = 0;
ENTRY;
}
CDEBUG(D_IOCTL, "cmd = %x, obd = %p\n", cmd, obd);
- if (!obd && cmd != OBD_IOC_DEVICE &&
- cmd != OBD_IOC_LIST && cmd != OBD_GET_VERSION &&
- cmd != OBD_IOC_NAME2DEV && cmd != OBD_IOC_UUID2DEV &&
- cmd != OBD_IOC_PROCESS_CFG) {
- CERROR("OBD ioctl: No device\n");
- GOTO(out, err = -EINVAL);
- }
if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
CERROR("OBD ioctl: data error\n");
GOTO(out, err = -EINVAL);
data = (struct obd_ioctl_data *)buf;
switch (cmd) {
- case OBD_IOC_DEVICE: {
- CDEBUG(D_IOCTL, "\n");
- if (data->ioc_dev >= MAX_OBD_DEVICES) {
- CERROR("OBD ioctl: DEVICE invalid device %d\n",
- data->ioc_dev);
- ocus->ocus_current_obd = &obd_dev[data->ioc_dev];
- GOTO(out, err = -EINVAL);
- }
- CDEBUG(D_IOCTL, "device %d\n", data->ioc_dev);
- ocus->ocus_current_obd = &obd_dev[data->ioc_dev];
- GOTO(out, err = 0);
- }
-
case OBD_IOC_PROCESS_CFG: {
char *buf;
struct lustre_cfg *lcfg;
}
-
- case OBD_IOC_CONNECT: {
- struct obd_export *exp;
- obd_data2conn(&conn, data);
-
- err = obd_connect(&conn, obd, &obd->obd_uuid);
-
- CDEBUG(D_IOCTL, "assigned export "LPX64"\n", conn.cookie);
- obd_conn2data(data, &conn);
- if (err)
- GOTO(out, err);
-
- exp = class_conn2export(&conn);
- if (exp == NULL)
- GOTO(out, err = -EINVAL);
-
- err = obd_class_add_user_exp(ocus, exp);
- if (err != 0) {
- obd_disconnect(exp, 0);
- GOTO (out, err);
- }
-
- err = copy_to_user((void *)arg, data, sizeof(*data));
- if (err != 0) {
- obd_class_remove_user_exp(ocus, exp);
- obd_disconnect(exp, 0);
- GOTO (out, err = -EFAULT);
- }
- class_export_put(exp);
- GOTO(out, err);
+ case OBD_IOC_CLOSE_UUID: {
+ struct lustre_peer peer;
+ CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
+ data->ioc_inlbuf1);
+ lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
+ GOTO(out, err = 0);
}
- case OBD_IOC_DISCONNECT: {
- struct obd_export *exp;
- obd_data2conn(&conn, data);
- exp = class_conn2export(&conn);
- if (exp == NULL)
- GOTO(out, err = -EINVAL);
+ }
- obd_class_remove_user_exp(ocus, exp);
- err = obd_disconnect(exp, 0);
- GOTO(out, err);
+ if (data->ioc_dev >= MAX_OBD_DEVICES) {
+ CERROR("OBD ioctl: No device\n");
+ GOTO(out, err = -EINVAL);
+ }
+ obd = &obd_dev[data->ioc_dev];
+ if (!(obd && obd->obd_set_up) || obd->obd_stopping) {
+ CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
+ GOTO(out, err = -EINVAL);
}
+ switch(cmd) {
case OBD_IOC_NO_TRANSNO: {
if (!obd->obd_attached) {
CERROR("Device %d not attached\n", obd->obd_minor);
GOTO(out, err = 0);
}
- case OBD_IOC_CLOSE_UUID: {
- struct lustre_peer peer;
- CDEBUG(D_IOCTL, "closing all connections to uuid %s\n",
- data->ioc_inlbuf1);
- lustre_uuid_to_peer(data->ioc_inlbuf1, &peer);
- GOTO(out, err = 0);
- }
-
default: {
- // obd_data2conn(&conn, data);
- struct obd_class_user_conn *oconn;
-
- if (list_empty(&ocus->ocus_conns))
- GOTO(out, err = -ENOTCONN);
-
- oconn = list_entry(ocus->ocus_conns.next, struct obd_class_user_conn, ocuc_chain);
- err = obd_iocontrol(cmd, oconn->ocuc_exp, len, data, NULL);
+ err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
if (err)
GOTO(out, err);
static int obd_class_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
{
- return class_handle_ioctl(filp->private_data, cmd, arg);
+ return class_handle_ioctl(cmd, arg);
}
/* declare character device */
#include <linux/list.h>
#undef __KERNEL__
+#include <linux/obd_class.h>
#include <portals/ptlctl.h>
#include "parser.h"
#include <stdio.h>
#endif
static int jt_recording;
-static uint64_t conn_cookie = -1;
static char rawbuf[8192];
static char *buf = rawbuf;
static int max = sizeof(rawbuf);
static int thread;
+static uint32_t cur_device = MAX_OBD_DEVICES;
+
union lsm_buffer {
char space [4096];
struct lov_stripe_md lsm;
static int l2_ioctl(int dev_id, int opc, void *buf)
{
-// if (jt_recording) {
-// struct obd_ioctl_data *data = buf;
-// data->ioc_command = opc;
-// opc = OBD_IOC_DORECORD;
-// }
return l_ioctl(dev_id, opc, buf);
}
#define IOC_INIT(data) \
do { \
memset(&data, 0, sizeof(data)); \
- data.ioc_cookie = conn_cookie; \
+ data.ioc_dev = cur_device; \
} while (0)
#define IOC_PACK(func, data) \
int do_disconnect(char *func, int verbose)
{
+ cur_device = MAX_OBD_DEVICES;
return 0;
}
extern command_t cmdlist[];
-static int do_device(char *func, int dev)
+static int do_device(char *func, char *devname)
{
struct obd_ioctl_data data;
+ int dev;
memset(&data, 0, sizeof(data));
- data.ioc_dev = dev;
+ dev = parse_devname(func, devname);
+ if (dev < 0)
+ return -1;
- IOC_PACK(func, data);
- return l2_ioctl(OBD_DEV_ID, OBD_IOC_DEVICE, buf);
+ cur_device = dev;
+ return 0;
}
int jt_obd_device(int argc, char **argv)
{
- int rc, dev;
+ int rc;
do_disconnect(argv[0], 1);
if (argc != 2)
return CMD_HELP;
- dev = parse_devname(argv[0], argv[1]);
- if (dev < 0)
- return -1;
-
- rc = do_device(argv[0], dev);
- if (rc < 0)
- fprintf(stderr, "error: %s: %s\n", jt_cmdname(argv[0]),
- strerror(rc = errno));
-
+ rc = do_device(argv[0], argv[1]);
return rc;
}
int jt_obd_connect(int argc, char **argv)
{
- struct obd_ioctl_data data;
- int rc;
-
- IOC_INIT(data);
-
- do_disconnect(argv[0], 1);
-
- /* XXX TODO: implement timeout per lctl usage for probe */
- if (argc != 1)
- return CMD_HELP;
-
- IOC_PACK(argv[0], data);
- rc = l2_ioctl(OBD_DEV_ID, OBD_IOC_CONNECT, buf);
- IOC_UNPACK(argv[0], data);
- if (rc < 0)
- fprintf(stderr, "error: %s: OBD_IOC_CONNECT %s\n",
- jt_cmdname(argv[0]), strerror(rc = errno));
- else
- conn_cookie = data.ioc_cookie;
- return rc;
+ return 0;
}
int jt_obd_disconnect(int argc, char **argv)
if (argc != 1)
return CMD_HELP;
- if (conn_cookie == -1)
- return 0;
-
return do_disconnect(argv[0], 0);
}
int jt_opt_device(int argc, char **argv)
{
- char *arg2[3];
int ret;
int rc;
if (argc < 3)
return CMD_HELP;
- rc = do_device("device", parse_devname(argv[0], argv[1]));
-
- if (!rc) {
- arg2[0] = "connect";
- arg2[1] = NULL;
- rc = jt_obd_connect(1, arg2);
- }
+ rc = do_device("device", argv[1]);
if (!rc)
rc = Parser_execarg(argc - 2, argv + 2, cmdlist);
memset(buf, 0, sizeof(buf));
data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_cookie = conn_cookie;
data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
data->ioc_len = obd_ioctl_packlen(data);
memset(buf, 0, sizeof(buf));
data->ioc_version = OBD_IOCTL_VERSION;
- data->ioc_cookie = conn_cookie;
data->ioc_inllen1 = sizeof(buf) - size_round(sizeof(*data));
data->ioc_len = obd_ioctl_packlen(data);