}
static int tcmu_netlink_event(enum tcmu_genl_cmd cmd, const char *name,
- int minor, int type)
+ int minor, int reconfig_attr,
+ const void *reconfig_data)
{
struct sk_buff *skb;
void *msg_header;
if (ret < 0)
goto free_skb;
- ret = nla_put_u32(skb, TCMU_ATTR_TYPE, type);
- if (ret < 0)
- goto free_skb;
+ if (cmd == TCMU_CMD_RECONFIG_DEVICE) {
+ switch (reconfig_attr) {
+ case TCMU_ATTR_DEV_CFG:
+ ret = nla_put_string(skb, reconfig_attr, reconfig_data);
+ break;
+ case TCMU_ATTR_DEV_SIZE:
+ ret = nla_put_u64_64bit(skb, reconfig_attr,
+ *((u64 *)reconfig_data),
+ TCMU_ATTR_PAD);
+ break;
+ case TCMU_ATTR_WRITECACHE:
+ ret = nla_put_u8(skb, reconfig_attr,
+ *((u8 *)reconfig_data));
+ break;
+ default:
+ BUG();
+ }
+
+ if (ret < 0)
+ goto free_skb;
+ }
genlmsg_end(skb, msg_header);
kref_get(&udev->kref);
ret = tcmu_netlink_event(TCMU_CMD_ADDED_DEVICE, udev->uio_info.name,
- udev->uio_info.uio_dev->minor, NO_RECONFIG);
+ udev->uio_info.uio_dev->minor, 0, NULL);
if (ret)
goto err_netlink;
if (tcmu_dev_configured(udev)) {
tcmu_netlink_event(TCMU_CMD_REMOVED_DEVICE, udev->uio_info.name,
- udev->uio_info.uio_dev->minor, NO_RECONFIG);
+ udev->uio_info.uio_dev->minor, 0, NULL);
uio_unregister_device(&udev->uio_info);
}
}
CONFIGFS_ATTR(tcmu_, cmd_time_out);
-static ssize_t tcmu_dev_path_show(struct config_item *item, char *page)
+static ssize_t tcmu_dev_config_show(struct config_item *item, char *page)
{
struct se_dev_attrib *da = container_of(to_config_group(item),
struct se_dev_attrib, da_group);
return snprintf(page, PAGE_SIZE, "%s\n", udev->dev_config);
}
-static ssize_t tcmu_dev_path_store(struct config_item *item, const char *page,
- size_t count)
+static ssize_t tcmu_dev_config_store(struct config_item *item, const char *page,
+ size_t count)
{
struct se_dev_attrib *da = container_of(to_config_group(item),
struct se_dev_attrib, da_group);
struct tcmu_dev *udev = TCMU_DEV(da->da_dev);
- char *copy = NULL;
- int ret;
+ int ret, len;
- copy = kstrdup(page, GFP_KERNEL);
- if (!copy) {
- kfree(copy);
+ len = strlen(page);
+ if (!len || len > TCMU_CONFIG_LEN - 1)
return -EINVAL;
- }
- strlcpy(udev->dev_config, copy, TCMU_CONFIG_LEN);
/* Check if device has been configured before */
if (tcmu_dev_configured(udev)) {
ret = tcmu_netlink_event(TCMU_CMD_RECONFIG_DEVICE,
udev->uio_info.name,
udev->uio_info.uio_dev->minor,
- CONFIG_PATH);
+ TCMU_ATTR_DEV_CFG, page);
if (ret) {
pr_err("Unable to reconfigure device\n");
return ret;
}
}
+ strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
return count;
}
-CONFIGFS_ATTR(tcmu_, dev_path);
+CONFIGFS_ATTR(tcmu_, dev_config);
static ssize_t tcmu_dev_size_show(struct config_item *item, char *page)
{
struct se_dev_attrib *da = container_of(to_config_group(item),
struct se_dev_attrib, da_group);
struct tcmu_dev *udev = TCMU_DEV(da->da_dev);
- unsigned long val;
+ u64 val;
int ret;
- ret = kstrtoul(page, 0, &val);
+ ret = kstrtou64(page, 0, &val);
if (ret < 0)
return ret;
- udev->dev_size = val;
/* Check if device has been configured before */
if (tcmu_dev_configured(udev)) {
ret = tcmu_netlink_event(TCMU_CMD_RECONFIG_DEVICE,
udev->uio_info.name,
udev->uio_info.uio_dev->minor,
- CONFIG_SIZE);
+ TCMU_ATTR_DEV_SIZE, &val);
if (ret) {
pr_err("Unable to reconfigure device\n");
return ret;
}
}
-
+ udev->dev_size = val;
return count;
}
CONFIGFS_ATTR(tcmu_, dev_size);
struct se_dev_attrib *da = container_of(to_config_group(item),
struct se_dev_attrib, da_group);
struct tcmu_dev *udev = TCMU_DEV(da->da_dev);
- int val;
+ u8 val;
int ret;
- ret = kstrtouint(page, 0, &val);
+ ret = kstrtou8(page, 0, &val);
if (ret < 0)
return ret;
- da->emulate_write_cache = val;
-
/* Check if device has been configured before */
if (tcmu_dev_configured(udev)) {
ret = tcmu_netlink_event(TCMU_CMD_RECONFIG_DEVICE,
udev->uio_info.name,
udev->uio_info.uio_dev->minor,
- CONFIG_WRITECACHE);
+ TCMU_ATTR_WRITECACHE, &val);
if (ret) {
pr_err("Unable to reconfigure device\n");
return ret;
}
}
+
+ da->emulate_write_cache = val;
return count;
}
CONFIGFS_ATTR(tcmu_, emulate_write_cache);
static struct configfs_attribute *tcmu_attrib_attrs[] = {
&tcmu_attr_cmd_time_out,
- &tcmu_attr_dev_path,
+ &tcmu_attr_dev_config,
&tcmu_attr_dev_size,
&tcmu_attr_emulate_write_cache,
NULL,