diff mbox series

[OpenWrt-Devel,fstools] blockd: don't reparse blob msg in the vlist callbacks

Message ID 20181207131310.12324-1-zajec5@gmail.com
State Accepted
Delegated to: Rafał Miłecki
Headers show
Series [OpenWrt-Devel,fstools] blockd: don't reparse blob msg in the vlist callbacks | expand

Commit Message

Rafał Miłecki Dec. 7, 2018, 1:13 p.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

ubus message is parsed in the block_hotplug() which fills all the struct
device fields. Once that is done there is no need to parse original
message again - it's enough to get required data from the struct.

This also fixes handling messages with "autofs" set to 0. They were
incorrectly interpreted due to the missing blobmsg_get_u32().

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
---
 blockd.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

Comments

John Crispin Dec. 7, 2018, 6:35 p.m. UTC | #1
On 07/12/2018 14:13, Rafał Miłecki wrote:
> From: Rafał Miłecki <rafal@milecki.pl>
>
> ubus message is parsed in the block_hotplug() which fills all the struct
> device fields. Once that is done there is no need to parse original
> message again - it's enough to get required data from the struct.
>
> This also fixes handling messages with "autofs" set to 0. They were
> incorrectly interpreted due to the missing blobmsg_get_u32().
>
> Signed-off-by: Rafał Miłecki <rafal@milecki.pl>

nice catch !

Acked-by: John Crispin <john@phrozen.org>

> ---
>   blockd.c | 16 +++-------------
>   1 file changed, 3 insertions(+), 13 deletions(-)
>
> diff --git a/blockd.c b/blockd.c
> index 1379635..29d16f2 100644
> --- a/blockd.c
> +++ b/blockd.c
> @@ -111,29 +111,19 @@ block(char *cmd, char *action, char *device)
>   static void
>   device_free(struct device *device)
>   {
> -	struct blob_attr *data[__MOUNT_MAX];
> -
> -	blobmsg_parse(mount_policy, __MOUNT_MAX, data,
> -		      blob_data(device->msg), blob_len(device->msg));
> -
> -	if (data[MOUNT_AUTOFS] && device->target)
> +	if (device->autofs && device->target)
>   		unlink(device->target);
>   }
>   
>   static void
>   device_add(struct device *device)
>   {
> -	struct blob_attr *data[__MOUNT_MAX];
>   	char path[64];
>   
> -	blobmsg_parse(mount_policy, __MOUNT_MAX, data,
> -		      blob_data(device->msg), blob_len(device->msg));
> -
> -	if (!data[MOUNT_AUTOFS])
> +	if (!device->autofs)
>   		return;
>   
> -	snprintf(path, sizeof(path), "/tmp/run/blockd/%s",
> -		 blobmsg_get_string(data[MOUNT_DEVICE]));
> +	snprintf(path, sizeof(path), "/tmp/run/blockd/%s", device->name);
>   	if (symlink(path, device->target))
>   		ULOG_ERR("failed to symlink %s->%s\n", device->target, path);
>   }
diff mbox series

Patch

diff --git a/blockd.c b/blockd.c
index 1379635..29d16f2 100644
--- a/blockd.c
+++ b/blockd.c
@@ -111,29 +111,19 @@  block(char *cmd, char *action, char *device)
 static void
 device_free(struct device *device)
 {
-	struct blob_attr *data[__MOUNT_MAX];
-
-	blobmsg_parse(mount_policy, __MOUNT_MAX, data,
-		      blob_data(device->msg), blob_len(device->msg));
-
-	if (data[MOUNT_AUTOFS] && device->target)
+	if (device->autofs && device->target)
 		unlink(device->target);
 }
 
 static void
 device_add(struct device *device)
 {
-	struct blob_attr *data[__MOUNT_MAX];
 	char path[64];
 
-	blobmsg_parse(mount_policy, __MOUNT_MAX, data,
-		      blob_data(device->msg), blob_len(device->msg));
-
-	if (!data[MOUNT_AUTOFS])
+	if (!device->autofs)
 		return;
 
-	snprintf(path, sizeof(path), "/tmp/run/blockd/%s",
-		 blobmsg_get_string(data[MOUNT_DEVICE]));
+	snprintf(path, sizeof(path), "/tmp/run/blockd/%s", device->name);
 	if (symlink(path, device->target))
 		ULOG_ERR("failed to symlink %s->%s\n", device->target, path);
 }