- int rc;
-
- switch (cmd) {
- case IOC_LIBCFS_CONFIGURE:
- return lnet_configure(NULL);
-
- case IOC_LIBCFS_UNCONFIGURE:
- return lnet_unconfigure();
-
- default:
- /* Passing LNET_PID_ANY only gives me a ref if the net is up
- * already; I'll need it to ensure the net can't go down while
- * I'm called into it */
- rc = LNetNIInit(LNET_PID_ANY);
- if (rc >= 0) {
- rc = LNetCtl(cmd, data);
- LNetNIFini();
- }
- return rc;
- }
+ struct lnet_ioctl_config_ni *conf =
+ (struct lnet_ioctl_config_ni *)hdr;
+ int rc;
+
+ if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
+ return -EINVAL;
+
+ mutex_lock(&lnet_config_mutex);
+ if (the_lnet.ln_niinit_self)
+ rc = lnet_dyn_add_ni(conf);
+ else
+ rc = -EINVAL;
+ mutex_unlock(&lnet_config_mutex);
+
+ return rc;
+}
+
+static int
+lnet_dyn_unconfigure_ni(struct libcfs_ioctl_hdr *hdr)
+{
+ struct lnet_ioctl_config_ni *conf =
+ (struct lnet_ioctl_config_ni *) hdr;
+ int rc;
+
+ if (conf->lic_cfg_hdr.ioc_len < sizeof(*conf))
+ return -EINVAL;
+
+ mutex_lock(&lnet_config_mutex);
+ if (the_lnet.ln_niinit_self)
+ rc = lnet_dyn_del_ni(conf);
+ else
+ rc = -EINVAL;
+ mutex_unlock(&lnet_config_mutex);
+
+ return rc;
+}
+
+static int
+lnet_ioctl(struct notifier_block *nb,
+ unsigned long cmd, void *vdata)
+{
+ struct libcfs_ioctl_hdr *hdr = vdata;
+ int rc;
+
+ switch (cmd) {
+ case IOC_LIBCFS_CONFIGURE: {
+ struct libcfs_ioctl_data *data =
+ (struct libcfs_ioctl_data *)hdr;
+
+ if (data->ioc_hdr.ioc_len < sizeof(*data)) {
+ rc = -EINVAL;
+ } else {
+ the_lnet.ln_nis_from_mod_params = data->ioc_flags;
+ rc = lnet_configure(NULL);
+ }
+ break;
+ }
+
+ case IOC_LIBCFS_UNCONFIGURE:
+ rc = lnet_unconfigure();
+ break;
+
+ case IOC_LIBCFS_ADD_NET:
+ rc = lnet_dyn_configure_net(hdr);
+ break;
+
+ case IOC_LIBCFS_DEL_NET:
+ rc = lnet_dyn_unconfigure_net(hdr);
+ break;
+
+ case IOC_LIBCFS_ADD_LOCAL_NI:
+ rc = lnet_dyn_configure_ni(hdr);
+ break;
+
+ case IOC_LIBCFS_DEL_LOCAL_NI:
+ rc = lnet_dyn_unconfigure_ni(hdr);
+ break;
+
+ default:
+ /* Passing LNET_PID_ANY only gives me a ref if the net is up
+ * already; I'll need it to ensure the net can't go down while
+ * I'm called into it */
+ rc = LNetNIInit(LNET_PID_ANY);
+ if (rc >= 0) {
+ rc = LNetCtl(cmd, hdr);
+ LNetNIFini();
+ }
+ break;
+ }
+ return notifier_from_ioctl_errno(rc);