Commit f59adb32 authored by Max Reitz's avatar Max Reitz
Browse files

block: Add .bdrv_truncate() error messages



Add missing error messages for the block driver implementations of
.bdrv_truncate(); drop the generic one from block.c's bdrv_truncate().

Since one of these changes touches a mis-indented block in
block/file-posix.c, this patch fixes that coding style issue along the
way.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Message-id: 20170328205129.15138-5-mreitz@redhat.com
Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
parent 4bff28b8
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -3334,8 +3334,6 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, Error **errp)
        bdrv_dirty_bitmap_truncate(bs);
        bdrv_parent_cb_resize(bs);
        ++bs->write_gen;
    } else if (errp && !*errp) {
        error_setg_errno(errp, -ret, "Failed to resize image");
    }
    return ret;
}
+12 −5
Original line number Diff line number Diff line
@@ -1411,20 +1411,27 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
{
    BDRVRawState *s = bs->opaque;
    struct stat st;
    int ret;

    if (fstat(s->fd, &st)) {
        return -errno;
        ret = -errno;
        error_setg_errno(errp, -ret, "Failed to fstat() the file");
        return ret;
    }

    if (S_ISREG(st.st_mode)) {
        if (ftruncate(s->fd, offset) < 0) {
            return -errno;
            ret = -errno;
            error_setg_errno(errp, -ret, "Failed to resize the file");
            return ret;
        }
    } else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
        if (offset > raw_getlength(bs)) {
            error_setg(errp, "Cannot grow device files");
            return -EINVAL;
        }
    } else {
        error_setg(errp, "Resizing this file is not supported");
        return -ENOTSUP;
    }

+3 −1
Original line number Diff line number Diff line
@@ -1100,7 +1100,9 @@ static int qemu_gluster_truncate(BlockDriverState *bs, int64_t offset,

    ret = glfs_ftruncate(s->fd, offset);
    if (ret < 0) {
        return -errno;
        ret = -errno;
        error_setg_errno(errp, -ret, "Failed to truncate file");
        return ret;
    }

    return 0;
+2 −0
Original line number Diff line number Diff line
@@ -2065,6 +2065,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
    Error *local_err = NULL;

    if (iscsilun->type != TYPE_DISK) {
        error_setg(errp, "Cannot resize non-disk iSCSI devices");
        return -ENOTSUP;
    }

@@ -2075,6 +2076,7 @@ static int iscsi_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
    }

    if (offset > iscsi_getlength(bs)) {
        error_setg(errp, "Cannot grow iSCSI devices");
        return -EINVAL;
    }

+9 −1
Original line number Diff line number Diff line
@@ -767,7 +767,15 @@ static int64_t nfs_get_allocated_file_size(BlockDriverState *bs)
static int nfs_file_truncate(BlockDriverState *bs, int64_t offset, Error **errp)
{
    NFSClient *client = bs->opaque;
    return nfs_ftruncate(client->context, client->fh, offset);
    int ret;

    ret = nfs_ftruncate(client->context, client->fh, offset);
    if (ret < 0) {
        error_setg_errno(errp, -ret, "Failed to truncate file");
        return ret;
    }

    return 0;
}

/* Note that this will not re-establish a connection with the NFS server
Loading