* [PATCH] block: allocate aligned write buffer for 'truncate -m full'
@ 2023-12-11 10:55 Andrey Drobyshev
2023-12-11 11:27 ` Denis V. Lunev
2024-01-25 16:46 ` Vladimir Sementsov-Ogievskiy
0 siblings, 2 replies; 6+ messages in thread
From: Andrey Drobyshev @ 2023-12-11 10:55 UTC (permalink / raw)
To: qemu-block; +Cc: qemu-devel, kwolf, hreitz, vsementsov, andrey.drobyshev, den
In case we're truncating an image opened with O_DIRECT, we might get
-EINVAL on write with unaligned buffer. In particular, when running
iotests/298 with '-nocache' we get:
qemu-io: Failed to resize underlying file: Could not write zeros for
preallocation: Invalid argument
Let's just allocate the buffer using qemu_blockalign0() instead.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
block/file-posix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/file-posix.c b/block/file-posix.c
index b862406c71..cee8de510b 100644
--- a/block/file-posix.c
+++ b/block/file-posix.c
@@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
goto out;
}
- buf = g_malloc0(65536);
+ buf = qemu_blockalign0(aiocb->bs, 65536);
seek_result = lseek(fd, current_length, SEEK_SET);
if (seek_result < 0) {
@@ -2413,7 +2413,7 @@ out:
}
}
- g_free(buf);
+ qemu_vfree(buf);
return result;
}
--
2.39.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] block: allocate aligned write buffer for 'truncate -m full'
2023-12-11 10:55 [PATCH] block: allocate aligned write buffer for 'truncate -m full' Andrey Drobyshev
@ 2023-12-11 11:27 ` Denis V. Lunev
2024-01-11 12:53 ` Andrey Drobyshev
2024-01-25 16:46 ` Vladimir Sementsov-Ogievskiy
1 sibling, 1 reply; 6+ messages in thread
From: Denis V. Lunev @ 2023-12-11 11:27 UTC (permalink / raw)
To: Andrey Drobyshev, qemu-block; +Cc: qemu-devel, kwolf, hreitz, vsementsov
On 12/11/23 11:55, Andrey Drobyshev wrote:
> In case we're truncating an image opened with O_DIRECT, we might get
> -EINVAL on write with unaligned buffer. In particular, when running
> iotests/298 with '-nocache' we get:
>
> qemu-io: Failed to resize underlying file: Could not write zeros for
> preallocation: Invalid argument
>
> Let's just allocate the buffer using qemu_blockalign0() instead.
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
> ---
> block/file-posix.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index b862406c71..cee8de510b 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
> goto out;
> }
>
> - buf = g_malloc0(65536);
> + buf = qemu_blockalign0(aiocb->bs, 65536);
>
> seek_result = lseek(fd, current_length, SEEK_SET);
> if (seek_result < 0) {
> @@ -2413,7 +2413,7 @@ out:
> }
> }
>
> - g_free(buf);
> + qemu_vfree(buf);
> return result;
> }
>
Reviewed-by: Denis V. Lunev <den@openvz.org>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: allocate aligned write buffer for 'truncate -m full'
2023-12-11 11:27 ` Denis V. Lunev
@ 2024-01-11 12:53 ` Andrey Drobyshev
2024-01-25 16:37 ` Andrey Drobyshev
0 siblings, 1 reply; 6+ messages in thread
From: Andrey Drobyshev @ 2024-01-11 12:53 UTC (permalink / raw)
To: Denis V. Lunev, qemu-block; +Cc: qemu-devel, kwolf, hreitz, vsementsov
On 12/11/23 13:27, Denis V. Lunev wrote:
> On 12/11/23 11:55, Andrey Drobyshev wrote:
>> In case we're truncating an image opened with O_DIRECT, we might get
>> -EINVAL on write with unaligned buffer. In particular, when running
>> iotests/298 with '-nocache' we get:
>>
>> qemu-io: Failed to resize underlying file: Could not write zeros for
>> preallocation: Invalid argument
>>
>> Let's just allocate the buffer using qemu_blockalign0() instead.
>>
>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>> ---
>> block/file-posix.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/block/file-posix.c b/block/file-posix.c
>> index b862406c71..cee8de510b 100644
>> --- a/block/file-posix.c
>> +++ b/block/file-posix.c
>> @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
>> goto out;
>> }
>> - buf = g_malloc0(65536);
>> + buf = qemu_blockalign0(aiocb->bs, 65536);
>> seek_result = lseek(fd, current_length, SEEK_SET);
>> if (seek_result < 0) {
>> @@ -2413,7 +2413,7 @@ out:
>> }
>> }
>> - g_free(buf);
>> + qemu_vfree(buf);
>> return result;
>> }
>>
> Reviewed-by: Denis V. Lunev <den@openvz.org>
Ping
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: allocate aligned write buffer for 'truncate -m full'
2024-01-11 12:53 ` Andrey Drobyshev
@ 2024-01-25 16:37 ` Andrey Drobyshev
0 siblings, 0 replies; 6+ messages in thread
From: Andrey Drobyshev @ 2024-01-25 16:37 UTC (permalink / raw)
To: Denis V. Lunev, qemu-block; +Cc: qemu-devel, kwolf, hreitz, vsementsov, eblake
On 1/11/24 14:53, Andrey Drobyshev wrote:
> On 12/11/23 13:27, Denis V. Lunev wrote:
>> On 12/11/23 11:55, Andrey Drobyshev wrote:
>>> In case we're truncating an image opened with O_DIRECT, we might get
>>> -EINVAL on write with unaligned buffer. In particular, when running
>>> iotests/298 with '-nocache' we get:
>>>
>>> qemu-io: Failed to resize underlying file: Could not write zeros for
>>> preallocation: Invalid argument
>>>
>>> Let's just allocate the buffer using qemu_blockalign0() instead.
>>>
>>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>>> ---
>>> block/file-posix.c | 4 ++--
>>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/block/file-posix.c b/block/file-posix.c
>>> index b862406c71..cee8de510b 100644
>>> --- a/block/file-posix.c
>>> +++ b/block/file-posix.c
>>> @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
>>> goto out;
>>> }
>>> - buf = g_malloc0(65536);
>>> + buf = qemu_blockalign0(aiocb->bs, 65536);
>>> seek_result = lseek(fd, current_length, SEEK_SET);
>>> if (seek_result < 0) {
>>> @@ -2413,7 +2413,7 @@ out:
>>> }
>>> }
>>> - g_free(buf);
>>> + qemu_vfree(buf);
>>> return result;
>>> }
>>>
>> Reviewed-by: Denis V. Lunev <den@openvz.org>
>
> Ping
Ping
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: allocate aligned write buffer for 'truncate -m full'
2023-12-11 10:55 [PATCH] block: allocate aligned write buffer for 'truncate -m full' Andrey Drobyshev
2023-12-11 11:27 ` Denis V. Lunev
@ 2024-01-25 16:46 ` Vladimir Sementsov-Ogievskiy
2024-02-08 18:32 ` Andrey Drobyshev
1 sibling, 1 reply; 6+ messages in thread
From: Vladimir Sementsov-Ogievskiy @ 2024-01-25 16:46 UTC (permalink / raw)
To: Andrey Drobyshev, qemu-block; +Cc: qemu-devel, kwolf, hreitz, den
On 11.12.23 13:55, Andrey Drobyshev wrote:
> In case we're truncating an image opened with O_DIRECT, we might get
> -EINVAL on write with unaligned buffer. In particular, when running
> iotests/298 with '-nocache' we get:
>
> qemu-io: Failed to resize underlying file: Could not write zeros for
> preallocation: Invalid argument
>
> Let's just allocate the buffer using qemu_blockalign0() instead.
>
> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
I also suggest to use QEMU_AUTO_VFREE (keep my r-b if you do).
> ---
> block/file-posix.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index b862406c71..cee8de510b 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
> goto out;
> }
>
> - buf = g_malloc0(65536);
> + buf = qemu_blockalign0(aiocb->bs, 65536);
>
> seek_result = lseek(fd, current_length, SEEK_SET);
> if (seek_result < 0) {
> @@ -2413,7 +2413,7 @@ out:
> }
> }
>
> - g_free(buf);
> + qemu_vfree(buf);
> return result;
> }
>
--
Best regards,
Vladimir
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] block: allocate aligned write buffer for 'truncate -m full'
2024-01-25 16:46 ` Vladimir Sementsov-Ogievskiy
@ 2024-02-08 18:32 ` Andrey Drobyshev
0 siblings, 0 replies; 6+ messages in thread
From: Andrey Drobyshev @ 2024-02-08 18:32 UTC (permalink / raw)
To: Vladimir Sementsov-Ogievskiy, qemu-block; +Cc: qemu-devel, kwolf, hreitz, den
On 1/25/24 18:46, Vladimir Sementsov-Ogievskiy wrote:
> On 11.12.23 13:55, Andrey Drobyshev wrote:
>> In case we're truncating an image opened with O_DIRECT, we might get
>> -EINVAL on write with unaligned buffer. In particular, when running
>> iotests/298 with '-nocache' we get:
>>
>> qemu-io: Failed to resize underlying file: Could not write zeros for
>> preallocation: Invalid argument
>>
>> Let's just allocate the buffer using qemu_blockalign0() instead.
>>
>> Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
>
> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
>
> I also suggest to use QEMU_AUTO_VFREE (keep my r-b if you do).
>
>> ---
>> block/file-posix.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/block/file-posix.c b/block/file-posix.c
>> index b862406c71..cee8de510b 100644
>> --- a/block/file-posix.c
>> +++ b/block/file-posix.c
>> @@ -2354,7 +2354,7 @@ static int handle_aiocb_truncate(void *opaque)
>> goto out;
>> }
>> - buf = g_malloc0(65536);
>> + buf = qemu_blockalign0(aiocb->bs, 65536);
>> seek_result = lseek(fd, current_length, SEEK_SET);
>> if (seek_result < 0) {
>> @@ -2413,7 +2413,7 @@ out:
>> }
>> }
>> - g_free(buf);
>> + qemu_vfree(buf);
>> return result;
>> }
>>
>
Yet another ping, just checking if any of the block maintainers is
interested
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-02-08 18:33 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-11 10:55 [PATCH] block: allocate aligned write buffer for 'truncate -m full' Andrey Drobyshev
2023-12-11 11:27 ` Denis V. Lunev
2024-01-11 12:53 ` Andrey Drobyshev
2024-01-25 16:37 ` Andrey Drobyshev
2024-01-25 16:46 ` Vladimir Sementsov-Ogievskiy
2024-02-08 18:32 ` Andrey Drobyshev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).