Commit 35ddd930 authored by Max Reitz's avatar Max Reitz Committed by Kevin Wolf
Browse files

qemu-img: Allow rebase with no input base



Currently, without -u, you cannot add a backing file to an image when it
currently has none:

$ qemu-img rebase -b base.qcow2 foo.qcow2
qemu-img: Could not open old backing file '': The 'file' block driver
requires a file name

It is really simple to allow this, though (effectively by setting
old_backing_size to 0), so this patch does just that.

Signed-off-by: default avatarMax Reitz <mreitz@redhat.com>
Reviewed-by: default avatarEric Blake <eblake@redhat.com>
Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
parent 433e8e3b
Loading
Loading
Loading
Loading
+34 −27
Original line number Diff line number Diff line
@@ -3312,6 +3312,7 @@ static int img_rebase(int argc, char **argv)
        char backing_name[PATH_MAX];
        QDict *options = NULL;

        if (bs->backing) {
            if (bs->backing_format[0] != '\0') {
                options = qdict_new();
                qdict_put_str(options, "driver", bs->backing_format);
@@ -3333,6 +3334,9 @@ static int img_rebase(int argc, char **argv)
                ret = -1;
                goto out;
            }
        } else {
            blk_old_backing = NULL;
        }

        if (out_baseimg[0]) {
            const char *overlay_filename;
@@ -3384,7 +3388,7 @@ static int img_rebase(int argc, char **argv)
     */
    if (!unsafe) {
        int64_t size;
        int64_t old_backing_size;
        int64_t old_backing_size = 0;
        int64_t new_backing_size = 0;
        uint64_t offset;
        int64_t n;
@@ -3400,16 +3404,19 @@ static int img_rebase(int argc, char **argv)
            ret = -1;
            goto out;
        }
        if (blk_old_backing) {
            old_backing_size = blk_getlength(blk_old_backing);
            if (old_backing_size < 0) {
                char backing_name[PATH_MAX];

            bdrv_get_backing_filename(bs, backing_name, sizeof(backing_name));
                bdrv_get_backing_filename(bs, backing_name,
                                          sizeof(backing_name));
                error_report("Could not get size of '%s': %s",
                             backing_name, strerror(-old_backing_size));
                ret = -1;
                goto out;
            }
        }
        if (blk_new_backing) {
            new_backing_size = blk_getlength(blk_new_backing);
            if (new_backing_size < 0) {