TCMU Enable Reconfiguration Patches
Subsystems (3)
v2 cover TCMU Enable Reconfiguration Patches
This patch consists of adding a netlink to allow for reconfiguration of a device in tcmu.
It also changes and adds some attributes that are reconfigurable:write_cache, device size, and device path.
Bryant G. Ly (5):
tcmu: Support emulate_write_cache
tcmu: Add netlink for device reconfiguration
tcmu: Make dev_size configurable via userspace
tcmu: Make dev_config configurable
tcmu: Add Type of reconfig into netlink
drivers/target/target_core_user.c | 159 ++++++++++++++++++++++++++++++++-- include/uapi/linux/target_core_user.h | 2 + 2 files changed, 155 insertions(+), 6 deletions(-)
Signature · 1 line
2.5.4 (Apple Git-61)
PATCH v2 1/5 tcmu: Support emulate_write_cache
This will enable the toggling of write_cache in tcmu through targetcli-fb
--- drivers/target/target_core_user.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/target/target_core_user.c +30 -0
@@ -1290,6 +1290,8 @@ static int tcmu_configure_device(struct se_device *dev)/* Other attributes can be configured in userspace */ if (!dev->dev_attrib.hw_max_sectors) dev->dev_attrib.hw_max_sectors =128 ; +if (!dev->dev_attrib.emulate_write_cache) + dev->dev_attrib.emulate_write_cache =0 ; dev->dev_attrib.hw_queue_depth =128 ;/*
@@ -1546,6 +1548,32 @@ static ssize_t tcmu_cmd_time_out_store(struct config_item *item, const char *pag }CONFIGFS_ATTR (tcmu_, cmd_time_out); +static ssize_t tcmu_emulate_write_cache_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 ,"%i\n" , da->emulate_write_cache); +} + +static ssize_t tcmu_emulate_write_cache_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); +int val; +int ret; + + ret =kstrtouint (page,0 , &val); +if (ret <0 ) +return ret; + + da->emulate_write_cache = val; +return count; +} +CONFIGFS_ATTR (tcmu_, emulate_write_cache); +static struct configfs_attribute **tcmu_attrs;static struct target_backend_ops tcmu_ops = {
@@ -1682,6 +1710,8 @@ static int __init tcmu_module_init(void) tcmu_attrs[i] = passthrough_attrib_attrs[i]; } tcmu_attrs[i] = &tcmu_attr_cmd_time_out; + i++; + tcmu_attrs[i] = &tcmu_attr_emulate_write_cache; tcmu_ops.tb_dev_attrib_attrs = tcmu_attrs; ret =transport_backend_register (&tcmu_ops);
Signature · 1 line
2.5.4 (Apple Git-61)
PATCH v2 2/5 tcmu: Add netlink for device reconfiguration
In reply to Bryant G. LyThis gives tcmu the ability to handle events that can cause reconfiguration, such as resize, path changes, write_cache, etc...
--- drivers/target/target_core_user.c | 12 ++++++++++++ include/uapi/linux/target_core_user.h | 1 + 2 files changed, 13 insertions(+)
drivers/target/target_core_user.c +12 -0
@@ -1562,6 +1562,7 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, {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;int ret;
@@ -1570,6 +1571,17 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item,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); +if (ret) { +pr_err ("Unable to reconfigure device\n" ); +return ret; + } + }return count; }CONFIGFS_ATTR (tcmu_, emulate_write_cache);
include/uapi/linux/target_core_user.h +1 -0
@@ -130,6 +130,7 @@ enum tcmu_genl_cmd {TCMU_CMD_UNSPEC ,TCMU_CMD_ADDED_DEVICE ,TCMU_CMD_REMOVED_DEVICE , +TCMU_CMD_RECONFIG_DEVICE , __TCMU_CMD_MAX, };#define TCMU_CMD_MAX (__TCMU_CMD_MAX - 1)
Signature · 1 line
2.5.4 (Apple Git-61)
PATCH v2 3/5 tcmu: Make dev_size configurable via userspace
In reply to Bryant G. LyAllow tcmu backstores to be able to set the device size after it has been configured via set attribute.
Part of support in userspace to support certain backstores changing device size.
--- drivers/target/target_core_user.c | 59 +++++++++++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 5 deletions(-)
drivers/target/target_core_user.c +54 -5
@@ -1548,6 +1548,44 @@ static ssize_t tcmu_cmd_time_out_store(struct config_item *item, const char *pag }CONFIGFS_ATTR (tcmu_, cmd_time_out); +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); + +return snprintf (page,PAGE_SIZE ,"%zu\n" , udev->dev_size); +} + +static ssize_t tcmu_dev_size_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); +unsigned long val; +int ret; + + ret =kstrtoul (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); +if (ret) { +pr_err ("Unable to reconfigure device\n" ); +return ret; + } + } + +return count; +} +CONFIGFS_ATTR (tcmu_, dev_size); +static ssize_t tcmu_emulate_write_cache_show (struct config_item *item,char *page) {
@@ -1586,6 +1624,13 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item, }CONFIGFS_ATTR (tcmu_, emulate_write_cache); +struct configfs_attribute *tcmu_attrib_attrs[] = { + &tcmu_attr_cmd_time_out, + &tcmu_attr_dev_size, + &tcmu_attr_emulate_write_cache, +NULL , +}; +static struct configfs_attribute **tcmu_attrs;static struct target_backend_ops tcmu_ops = {
@@ -1685,7 +1730,7 @@ static int unmap_thread_fn(void *data)static int __init tcmu_module_init (void ) { -int ret, i, len =0 ; +int ret, i, k, len =0 ;BUILD_BUG_ON ((sizeof (struct tcmu_cmd_entry ) %TCMU_OP_ALIGN_SIZE ) !=0 );
@@ -1710,7 +1755,10 @@ static int __init tcmu_module_init(void)for (i =0 ; passthrough_attrib_attrs[i] !=NULL ; i++) { len +=sizeof (struct configfs_attribute *); } - len +=sizeof (struct configfs_attribute *) *2 ; +for (i =0 ; tcmu_attrib_attrs[i] !=NULL ; i++) { + len +=sizeof (struct configfs_attribute *); + } + len +=sizeof (struct configfs_attribute *); tcmu_attrs =kzalloc (len,GFP_KERNEL );if (!tcmu_attrs) {
@@ -1721,9 +1769,10 @@ static int __init tcmu_module_init(void)for (i =0 ; passthrough_attrib_attrs[i] !=NULL ; i++) { tcmu_attrs[i] = passthrough_attrib_attrs[i]; } - tcmu_attrs[i] = &tcmu_attr_cmd_time_out; - i++; - tcmu_attrs[i] = &tcmu_attr_emulate_write_cache; +for (k =0 ; tcmu_attrib_attrs[k] !=NULL ; k++) { + tcmu_attrs[i] = tcmu_attrib_attrs[k]; + i++; + } tcmu_ops.tb_dev_attrib_attrs = tcmu_attrs; ret =transport_backend_register (&tcmu_ops);
Signature · 1 line
2.5.4 (Apple Git-61)
PATCH v2 4/5 tcmu: Make dev_config configurable
In reply to Bryant G. LyThis allows for userspace to change the device path after it has been created. Thus giving the user the ability to change the path. The use case for this is to allow for virtual optical to have media change.
--- drivers/target/target_core_user.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)
drivers/target/target_core_user.c +41 -0
@@ -1548,6 +1548,46 @@ static ssize_t tcmu_cmd_time_out_store(struct config_item *item, const char *pag }CONFIGFS_ATTR (tcmu_, cmd_time_out); +static ssize_t tcmu_dev_path_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); + +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) +{ +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; + + copy =kstrdup (page,GFP_KERNEL ); +if (!copy) { +kree (copy); +return -EINVAL ; + } +strcpy (udev->dev_config, copy); + +/* 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); +if (ret) { +pr_err ("Unable to reconfigure device\n" ); +return ret; + } + } + +return count; +} +CONFIGFS_ATTR (tcmu_, dev_path); +static ssize_t tcmu_dev_size_show (struct config_item *item,char *page) { struct se_dev_attrib *da = container_of(to_config_group(item),
@@ -1626,6 +1666,7 @@ CONFIGFS_ATTR(tcmu_, emulate_write_cache);struct configfs_attribute *tcmu_attrib_attrs[] = { &tcmu_attr_cmd_time_out, + &tcmu_attr_dev_path, &tcmu_attr_dev_size, &tcmu_attr_emulate_write_cache,NULL ,
Signature · 1 line
2.5.4 (Apple Git-61)
kbuild test robot
build botRe: [PATCH v2 4/5] tcmu: Make dev_config configurable
reproduce:
Hi Bryant,
[auto build test ERROR on target/master]
[also build test ERROR on v4.12-rc3 next-20170530]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Bryant-G-Ly/TCMU-Enable-Reconfiguration-Patches/20170531-062328 base: https://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending.git master config: i386-randconfig-x005-201722 (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386
All errors (new ones prefixed by >>):
drivers//target/target_core_user.c: In function 'tcmu_dev_path_store':
>> drivers//target/target_core_user.c:1571:3: error: implicit declaration of function 'kree' [-Werror=implicit-function-declaration]
kree(copy);
^~~~cc1: some warnings being treated as errors
vim +/kree +1571 drivers//target/target_core_user.c
1555 struct tcmu_dev *udev = TCMU_DEV(da->da_dev);
1556
1557 return snprintf(page, PAGE_SIZE, "%s\n", udev->dev_config);
1558 }
1559
1560 static ssize_t tcmu_dev_path_store(struct config_item *item, const char *page,
1561 size_t count)
1562 {
1563 struct se_dev_attrib *da = container_of(to_config_group(item),
1564 struct se_dev_attrib, da_group);
1565 struct tcmu_dev *udev = TCMU_DEV(da->da_dev);
1566 char *copy = NULL;
1567 int ret;
1568
1569 copy = kstrdup(page, GFP_KERNEL);
1570 if (!copy) {
> 1571 kree(copy);
1572 return -EINVAL;
1573 }
1574 strcpy(udev->dev_config, copy);
1575
1576 /* Check if device has been configured before */
1577 if (tcmu_dev_configured(udev)) {
1578 ret = tcmu_netlink_event(TCMU_CMD_RECONFIG_DEVICE,
1579 udev->uio_info.name,
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Re: [PATCH v2 4/5] tcmu: Make dev_config configurable
In reply to Bryant G. LyQuoted 32 lines · Bryant G. Ly
This allows for userspace to change the device path after it has been created. Thus giving the user the ability to change the path. The use case for this is to allow for virtual optical to have media change.
Signed-off-by Bryant G. Ly <[email protected]>--- drivers/target/target_core_user.c | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+)drivers/target/target_core_user.c +14
-0@@ -1548,6 +1548,46 @@ static ssize_t tcmu_cmd_time_out_store(struct config_item *item, const char *pag }CONFIGFS_ATTR (tcmu_, cmd_time_out); +static ssize_t tcmu_dev_path_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); + +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) +{ +struct se_dev_attrib *da =container_of (to_config_group (item), + struct se_dev_attrib, da_group);
drivers/target/target_core_user.c static ssize_t tcmu_cmd_time_out_store(struct config_item *item, const char *pag · line 1574
Quoted 10 lines
drivers/target/target_core_user.c +10
-0+struct tcmu_dev *udev =TCMU_DEV (da->da_dev); +char *copy =NULL ; +int ret; + + copy =kstrdup (page,GFP_KERNEL ); +if (!copy) { +kree (copy); +return -EINVAL ; + } +strcpy (udev->dev_config, copy);
I think we need to do strlcpy with TCMU_CONFIG_LEN here.
PATCH v2 5/5 tcmu: Add Type of reconfig into netlink
In reply to Bryant G. LyThis patch adds more info about the attribute being changed, so that usersapce can easily figure out what is happening.
--- drivers/target/target_core_user.c | 27 +++++++++++++++++++++------ include/uapi/linux/target_core_user.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-)
drivers/target/target_core_user.c +21 -6
@@ -190,6 +190,13 @@ static struct genl_family tcmu_genl_family __ro_after_init = { .netnsok = true, }; +enum tcmu_reconfig_types { + No_reconfig, + Config_path, + Config_size, + Config_writecache +}; +#define tcmu_cmd_set_dbi_cur (cmd, index) ((cmd)->dbi_cur = (index))#define tcmu_cmd_reset_dbi_cur (cmd) tcmu_cmd_set_dbi_cur(cmd, 0)#define tcmu_cmd_set_dbi (cmd, index) ((cmd)->dbi[(cmd)->dbi_cur++] = (index))
@@ -1176,7 +1183,8 @@ static int tcmu_release(struct uio_info *info, struct inode *inode)return 0 ; } -static int tcmu_netlink_event (enum tcmu_genl_cmd cmd,const char *name,int minor) +static int tcmu_netlink_event (enum tcmu_genl_cmd cmd,const char *name, +int minor,int type) {struct sk_buff *skb;void *msg_header;
@@ -1198,6 +1206,10 @@ static int tcmu_netlink_event(enum tcmu_genl_cmd cmd, const char *name, int minoif (ret <0 ) goto free_skb; + ret =nla_put_u32 (skb,TCMU_ATTR_TYPE , type); +if (ret <0 ) + goto free_skb; +genlmsg_end (skb, msg_header); ret = genlmsg_multicast_allns(&tcmu_genl_family, skb, 0,
@@ -1301,7 +1313,7 @@ static int tcmu_configure_device(struct se_device *dev)kref_get (&udev->kref); ret =tcmu_netlink_event (TCMU_CMD_ADDED_DEVICE , udev->uio_info.name, - udev->uio_info.uio_dev->minor); + udev->uio_info.uio_dev->minor, No_reconfig);if (ret) goto err_netlink;
@@ -1383,7 +1395,7 @@ static void tcmu_free_device(struct se_device *dev)if (tcmu_dev_configured (udev)) {tcmu_netlink_event (TCMU_CMD_REMOVED_DEVICE , udev->uio_info.name, - udev->uio_info.uio_dev->minor); + udev->uio_info.uio_dev->minor, No_reconfig);uio_unregister_device (&udev->uio_info); }
@@ -1577,7 +1589,8 @@ static ssize_t tcmu_dev_path_store(struct config_item *item, const char *page,if (tcmu_dev_configured (udev)) { ret =tcmu_netlink_event (TCMU_CMD_RECONFIG_DEVICE , udev->uio_info.name, - udev->uio_info.uio_dev->minor); + udev->uio_info.uio_dev->minor, + Config_path);if (ret) {pr_err ("Unable to reconfigure device\n" );return ret;
@@ -1615,7 +1628,8 @@ static ssize_t tcmu_dev_size_store(struct config_item *item, const char *page,if (tcmu_dev_configured (udev)) { ret =tcmu_netlink_event (TCMU_CMD_RECONFIG_DEVICE , udev->uio_info.name, - udev->uio_info.uio_dev->minor); + udev->uio_info.uio_dev->minor, + Config_size);if (ret) {pr_err ("Unable to reconfigure device\n" );return ret;
@@ -1654,7 +1668,8 @@ static ssize_t tcmu_emulate_write_cache_store(struct config_item *item,if (tcmu_dev_configured (udev)) { ret =tcmu_netlink_event (TCMU_CMD_RECONFIG_DEVICE , udev->uio_info.name, - udev->uio_info.uio_dev->minor); + udev->uio_info.uio_dev->minor, + Config_writecache);if (ret) {pr_err ("Unable to reconfigure device\n" );return ret;
include/uapi/linux/target_core_user.h +1 -0
@@ -139,6 +139,7 @@ enum tcmu_genl_attr {TCMU_ATTR_UNSPEC ,TCMU_ATTR_DEVICE ,TCMU_ATTR_MINOR , +TCMU_ATTR_TYPE , __TCMU_ATTR_MAX, };#define TCMU_ATTR_MAX (__TCMU_ATTR_MAX - 1)
Signature · 1 line
2.5.4 (Apple Git-61)
Re: [PATCH v2 5/5] tcmu: Add Type of reconfig into netlink
Quoted 14 lines · Bryant G. Ly
This patch adds more info about the attribute being changed, so that usersapce can easily figure out what is happening.
Signed-off-by Bryant G. Ly <[email protected]>--- drivers/target/target_core_user.c | 27 +++++++++++++++++++++------ include/uapi/linux/target_core_user.h | 1 + 2 files changed, 22 insertions(+), 6 deletions(-)drivers/target/target_core_user.c +0
-0
drivers/target/target_core_user.c static struct genl_family tcmu_genl_family __ro_after_init = { · line 197
Quoted 8 lines
drivers/target/target_core_user.c +5
-0@@ -190,6 +190,13 @@ static struct genl_family tcmu_genl_family __ro_after_init = { .netnsok = true, }; +enum tcmu_reconfig_types { + No_reconfig, + Config_path, + Config_size, + Config_writecache
This this goes in target_core_user.h.
Let's just do all caps for the names to make the style in there.
Hi Bryant & Co,
Quoted 13 lines · Bryant G. Ly
This patch consists of adding a netlink to allow for reconfiguration of a device in tcmu.
It also changes and adds some attributes that are reconfigurable:
write_cache, device size, and device path.Bryant G. Ly (5):
tcmu: Supportemulate_write_cache
tcmu: Add netlink for device reconfiguration
tcmu: Makedev_sizeconfigurable via userspace
tcmu: Makedev_configconfigurable
tcmu: Add Type of reconfig into netlink
Quoted 4 lines
drivers/target/target_core_user.c | 159 ++++++++++++++++++++++++++++++++-- include/uapi/linux/target_core_user.h | 2 + 2 files changed, 155 insertions(+), 6 deletions(-)
Are these ready for merge..?
MNC..?