static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct iscsi_target *target = NULL; long err; u32 id; err = down_interruptible(&ioctl_sem); if (err < 0) return err; if (cmd == GET_MODULE_INFO) { err = get_module_info(arg); goto done; } if (cmd == ADD_TARGET) { err = add_target(arg); goto done; } err = get_user(id, (u32 *) arg); if (err < 0) goto done; /* locking handled in target_del */ if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (!target) { err = -ENOENT; goto done; } err = target_lock(target, 1); if (err < 0) goto done; switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; default: eprintk("invalid ioctl cmd %x\n", cmd); err = -EINVAL; } target_unlock(target); done: up(&ioctl_sem); return err; }
static long ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct iscsi_target *target = NULL; long err; u32 id; if ((err = get_user(id, (u32 *) arg)) != 0) goto done; if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (cmd == ADD_TARGET) if (target) { err = -EEXIST; eprintk("Target %u already exist!\n", id); goto done; } switch (cmd) { case ADD_TARGET: assert(!target); err = add_target(arg); goto done; } if (!target) { eprintk("can't find the target %u\n", id); err = -EINVAL; goto done; } if ((err = target_lock(target, 1)) < 0) { eprintk("interrupted %ld %d\n", err, cmd); goto done; } switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; } if (target) target_unlock(target); done: return err; }
int iet_ioctl(struct cdev *dev, unsigned long cmd, caddr_t iarg, int fflag, struct thread *td) #endif { struct iscsi_target *target = NULL; long err; u32 id; #ifdef FREEBSD unsigned long arg = (unsigned long)(iarg); /* Avoid make warnings */ #endif err = mutex_lock_interruptible(&ioctl_mutex); if (err != 0) return err; if (cmd == GET_MODULE_INFO) { err = get_module_info(arg); goto done; } if (cmd == ADD_TARGET) { err = add_target(arg); goto done; } err = copy_from_user(&id, (u32 *) (unsigned long)arg, sizeof(u32)); if (err < 0) goto done; /* locking handled in target_del */ if (cmd == DEL_TARGET) { err = target_del(id); goto done; } target = target_lookup_by_id(id); if (!target) { err = -ENOENT; goto done; } err = target_lock(target, 1); if (err < 0) goto done; switch (cmd) { case ADD_VOLUME: err = add_volume(target, arg); break; case DEL_VOLUME: err = del_volume(target, arg); break; case ADD_SESSION: err = add_session(target, arg); break; case DEL_SESSION: err = del_session(target, arg); break; case GET_SESSION_INFO: err = get_session_info(target, arg); break; case ISCSI_PARAM_SET: err = iscsi_param_config(target, arg, 1); break; case ISCSI_PARAM_GET: err = iscsi_param_config(target, arg, 0); break; case ADD_CONN: err = add_conn(target, arg); break; case DEL_CONN: err = del_conn(target, arg); break; case GET_CONN_INFO: err = get_conn_info(target, arg); break; default: eprintk("invalid ioctl cmd %lx\n", (unsigned long)cmd); err = -EINVAL; } target_unlock(target); done: mutex_unlock(&ioctl_mutex); #ifdef FREEBSD if (err < 0) err = -(err); #endif return err; }