diff mbox

[v2] tcmu: Fix dev_config_store

Message ID 1499455200-90541-1-git-send-email-bryantly@linux.vnet.ibm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bryant G. Ly July 7, 2017, 7:20 p.m. UTC
Currently when there is a reconfig, the uio_info->name
does not get updated to reflect the change in the dev_config
name change.

On restart tcmu-runner there will be a mismatch between
the dev_config string in uio and the tcmu structure that contains
the string. When this occurs it'll reload the one in uio
and you lose the reconfigured device path.

v2: Created a helper function for the updating of uio_info

Signed-off-by: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
---
 drivers/target/target_core_user.c | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)

Comments

Nicholas A. Bellinger July 8, 2017, midnight UTC | #1
On Fri, 2017-07-07 at 14:20 -0500, Bryant G. Ly wrote:
> Currently when there is a reconfig, the uio_info->name
> does not get updated to reflect the change in the dev_config
> name change.
> 
> On restart tcmu-runner there will be a mismatch between
> the dev_config string in uio and the tcmu structure that contains
> the string. When this occurs it'll reload the one in uio
> and you lose the reconfigured device path.
> 
> v2: Created a helper function for the updating of uio_info
> 
> Signed-off-by: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
> ---
>  drivers/target/target_core_user.c | 32 ++++++++++++++++++++++++--------
>  1 file changed, 24 insertions(+), 8 deletions(-)
> 

Applied to target-pending/for-next.

MNC, please let me know if you have any objections.

--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mike Christie July 13, 2017, 4:10 a.m. UTC | #2
On 07/07/2017 02:20 PM, Bryant G. Ly wrote:
> Currently when there is a reconfig, the uio_info->name
> does not get updated to reflect the change in the dev_config
> name change.
> 
> On restart tcmu-runner there will be a mismatch between
> the dev_config string in uio and the tcmu structure that contains
> the string. When this occurs it'll reload the one in uio
> and you lose the reconfigured device path.
> 
> v2: Created a helper function for the updating of uio_info
> 
> Signed-off-by: Bryant G. Ly <bryantly@linux.vnet.ibm.com>
> ---
>  drivers/target/target_core_user.c | 32 ++++++++++++++++++++++++--------
>  1 file changed, 24 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
> index cbbfba0..2f1fa92 100644
> --- a/drivers/target/target_core_user.c
> +++ b/drivers/target/target_core_user.c
> @@ -1418,19 +1418,14 @@ static int tcmu_netlink_event(struct tcmu_dev *udev, enum tcmu_genl_cmd cmd,
>  	return ret;
>  }
>  
> -static int tcmu_configure_device(struct se_device *dev)
> +static int tcmu_update_uio_info(struct tcmu_dev *udev)
>  {
> -	struct tcmu_dev *udev = TCMU_DEV(dev);
>  	struct tcmu_hba *hba = udev->hba->hba_ptr;
>  	struct uio_info *info;
> -	struct tcmu_mailbox *mb;
> -	size_t size;
> -	size_t used;
> -	int ret = 0;
> +	size_t size, used;
>  	char *str;
>  
>  	info = &udev->uio_info;
> -
>  	size = snprintf(NULL, 0, "tcm-user/%u/%s/%s", hba->host_id, udev->name,
>  			udev->dev_config);
>  	size += 1; /* for \0 */
> @@ -1439,12 +1434,27 @@ static int tcmu_configure_device(struct se_device *dev)
>  		return -ENOMEM;
>  
>  	used = snprintf(str, size, "tcm-user/%u/%s", hba->host_id, udev->name);
> -
>  	if (udev->dev_config[0])
>  		snprintf(str + used, size - used, "/%s", udev->dev_config);
>  
>  	info->name = str;

When used for the reconfigure case info->name will have been set by the
initial tcmu_configure_device call, so we need a kfree of the old string.
--
To unsubscribe from this list: send the line "unsubscribe target-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index cbbfba0..2f1fa92 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -1418,19 +1418,14 @@  static int tcmu_netlink_event(struct tcmu_dev *udev, enum tcmu_genl_cmd cmd,
 	return ret;
 }
 
-static int tcmu_configure_device(struct se_device *dev)
+static int tcmu_update_uio_info(struct tcmu_dev *udev)
 {
-	struct tcmu_dev *udev = TCMU_DEV(dev);
 	struct tcmu_hba *hba = udev->hba->hba_ptr;
 	struct uio_info *info;
-	struct tcmu_mailbox *mb;
-	size_t size;
-	size_t used;
-	int ret = 0;
+	size_t size, used;
 	char *str;
 
 	info = &udev->uio_info;
-
 	size = snprintf(NULL, 0, "tcm-user/%u/%s/%s", hba->host_id, udev->name,
 			udev->dev_config);
 	size += 1; /* for \0 */
@@ -1439,12 +1434,27 @@  static int tcmu_configure_device(struct se_device *dev)
 		return -ENOMEM;
 
 	used = snprintf(str, size, "tcm-user/%u/%s", hba->host_id, udev->name);
-
 	if (udev->dev_config[0])
 		snprintf(str + used, size - used, "/%s", udev->dev_config);
 
 	info->name = str;
 
+	return 0;
+}
+
+static int tcmu_configure_device(struct se_device *dev)
+{
+	struct tcmu_dev *udev = TCMU_DEV(dev);
+	struct uio_info *info;
+	struct tcmu_mailbox *mb;
+	int ret = 0;
+
+	ret = tcmu_update_uio_info(udev);
+	if (ret)
+		return ret;
+
+	info = &udev->uio_info;
+
 	udev->mb_addr = vzalloc(CMDR_SIZE);
 	if (!udev->mb_addr) {
 		ret = -ENOMEM;
@@ -1786,6 +1796,12 @@  static ssize_t tcmu_dev_config_store(struct config_item *item, const char *page,
 			pr_err("Unable to reconfigure device\n");
 			return ret;
 		}
+		strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);
+
+		ret = tcmu_update_uio_info(udev);
+		if (ret)
+			return ret;
+		return count;
 	}
 	strlcpy(udev->dev_config, page, TCMU_CONFIG_LEN);