[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 07/16] block/file-posix: G
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate |
Date: |
Mon, 20 Mar 2017 11:00:23 +0000 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
On Mon, Mar 13, 2017 at 10:40:36PM +0100, Max Reitz wrote:
> Currently, raw_regular_truncate() is intended for setting the size of a
> newly created file. However, we also want to use it for truncating an
> existing file in which case only the newly added space (when growing)
> should be preallocated.
>
> This also means that if resizing failed, we should try to restore the
> original file size. This is important when using preallocation.
>
> Signed-off-by: Max Reitz <address@hidden>
> ---
> block/file-posix.c | 73
> ++++++++++++++++++++++++++++++++++++++++++++----------
> 1 file changed, 60 insertions(+), 13 deletions(-)
>
> diff --git a/block/file-posix.c b/block/file-posix.c
> index 35a9e43f3e..cd229324ba 100644
> --- a/block/file-posix.c
> +++ b/block/file-posix.c
> @@ -1384,11 +1384,39 @@ static void raw_close(BlockDriverState *bs)
> }
> }
>
> -static int raw_regular_truncate(int fd, int64_t offset, PreallocMode
> prealloc,
> +/**
> + * Truncates the given regular file @fd to @offset and, when growing, fills
> the
> + * new space according to @prealloc.
> + *
> + * @create must be true iff the file is new. In that case, @bs is ignored. If
> + * @create is false, @bs must be valid and correspond to the same file as
> @fd.
Returns: 0 on success, -errno on failure.
> + */
> +static int raw_regular_truncate(int fd, BlockDriverState *bs, int64_t offset,
The presence of both a file descriptor and a BlockDriverState (actually
it must be a BDRVRawState) arguments is unusual. It seems bs is needed
for bdrv_getlength().
How about using fstat(fd, &st) and then dropping bs and create?
> + PreallocMode prealloc, bool create,
> Error **errp)
> {
> int result = 0;
> - char *buf;
> + int64_t current_length = 0;
> + char *buf = NULL;
> +
> + assert(create || bs);
> + if (!create) {
> + BDRVRawState *s = bs->opaque;
> + assert(s->fd == fd);
> + }
> +
> + if (!create) {
> + current_length = bdrv_getlength(bs);
> + if (current_length < 0) {
> + error_setg_errno(errp, -current_length,
> + "Could not inquire current length");
> + return -current_length;
> + }
> +
> + if (current_length > offset && prealloc != PREALLOC_MODE_OFF) {
> + return -ENOTSUP;
> + }
Missing error_setg().
signature.asc
Description: PGP signature
- [Qemu-block] [PATCH for-2.10 03/16] block: Add PreallocMode to blk_truncate(), (continued)
- [Qemu-block] [PATCH for-2.10 03/16] block: Add PreallocMode to blk_truncate(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 04/16] qemu-img: Expose PreallocMode for resizing, Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 05/16] block/file-posix: Small fixes in raw_create(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 06/16] block/file-posix: Extract raw_regular_truncate(), Max Reitz, 2017/03/13
- [Qemu-block] [PATCH for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate, Max Reitz, 2017/03/13
- Re: [Qemu-block] [Qemu-devel] [PATCH for-2.10 07/16] block/file-posix: Generalize raw_regular_truncate,
Stefan Hajnoczi <=
[Qemu-block] [PATCH for-2.10 08/16] block/file-posix: Preallocation for truncate, Max Reitz, 2017/03/13
[Qemu-block] [PATCH for-2.10 09/16] block/qcow2: Generalize preallocate(), Max Reitz, 2017/03/13
[Qemu-block] [PATCH for-2.10 10/16] block/qcow2: Lock s->lock in preallocate(), Max Reitz, 2017/03/13