|
|
9ae3a8 |
From c21689e9b457b3790a5d0294c2815f2df561dece Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <c21689e9b457b3790a5d0294c2815f2df561dece.1420654015.git.jen@redhat.com>
|
|
|
9ae3a8 |
From: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 18 Dec 2014 11:11:06 -0600
|
|
|
9ae3a8 |
Subject: [CHANGE] block: delete cow block driver
|
|
|
9ae3a8 |
To: rhvirt-patches@redhat.com,
|
|
|
9ae3a8 |
jen@redhat.com
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1418901066-25891-1-git-send-email-stefanha@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62969
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH RESEND] block: delete cow block driver
|
|
|
9ae3a8 |
Bugzilla: 1175325
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This patch removes support for the cow file format.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Normally we do not break backwards compatibility but in this case there
|
|
|
9ae3a8 |
is no impact and it is the most logical option. Extraordinary claims
|
|
|
9ae3a8 |
require extraordinary evidence so I will show why removing the cow block
|
|
|
9ae3a8 |
driver is the right thing to do.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
The cow file format is the disk image format for Usermode Linux, a way
|
|
|
9ae3a8 |
of running a Linux system in userspace. The performance of UML was
|
|
|
9ae3a8 |
never great and it was hacky, but it enjoyed some popularity before
|
|
|
9ae3a8 |
hardware virtualization support became mainstream.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
QEMU's block/cow.c is supposed to read this image file format.
|
|
|
9ae3a8 |
Unfortunately the file format was underspecified:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
1. Earlier Linux versions used the MAXPATHLEN constant for the backing
|
|
|
9ae3a8 |
filename field. The value of MAXPATHLEN can change, so Linux
|
|
|
9ae3a8 |
switched to a 4096 literal but QEMU has a 1024 literal.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
2. Padding was not used on the header struct (both in the Linux kernel
|
|
|
9ae3a8 |
and in QEMU) so the struct layout varied across architectures. In
|
|
|
9ae3a8 |
particular, i386 and x86_64 were different due to int64_t alignment
|
|
|
9ae3a8 |
differences. Linux now uses __attribute__((packed)), QEMU does not.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Therefore:
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
1. QEMU cow images do not conform to the Linux cow image file format.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
2. cow images cannot be shared between different host architectures.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This means QEMU cow images are useless and QEMU has not had bug reports
|
|
|
9ae3a8 |
from users actually hitting these issues.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Let's get rid of this thing, it serves no purpose and no one will be
|
|
|
9ae3a8 |
affected.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
Message-id: 1410877464-20481-1-git-send-email-stefanha@redhat.com
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 550830f9351291c585c963204ad9127998b1c1ce)
|
|
|
9ae3a8 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Conflicts:
|
|
|
9ae3a8 |
block/Makefile.objs
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Context conflict, easy to resolve.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
block/cow.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
No problem, we're deleting this file anyway.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
qapi/block-core.json
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Downstream still uses qapi-schema.json.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
tests/image-fuzzer/runner.py
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Not present downstream, skip it.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
tests/qemu-iotests/069
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Context conflict, easy to resolve.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
tests/qemu-iotests/072
|
|
|
9ae3a8 |
tests/qemu-iotests/099
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Not present downstream, skip these tests.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
ui/cocoa.m
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
We just want to drop "cow", the context conflict does not matter.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/Makefile.objs | 2 +-
|
|
|
9ae3a8 |
block/cow.c | 402 ----------------------------------------------
|
|
|
9ae3a8 |
qapi-schema.json | 2 +-
|
|
|
9ae3a8 |
qemu-doc.texi | 9 --
|
|
|
9ae3a8 |
qemu-img.texi | 4 +-
|
|
|
9ae3a8 |
qmp-commands.hx | 2 +-
|
|
|
9ae3a8 |
tests/qemu-iotests/069 | 2 +-
|
|
|
9ae3a8 |
tests/qemu-iotests/common | 6 -
|
|
|
9ae3a8 |
ui/cocoa.m | 2 +-
|
|
|
9ae3a8 |
9 files changed, 7 insertions(+), 424 deletions(-)
|
|
|
9ae3a8 |
delete mode 100644 block/cow.c
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/Makefile.objs b/block/Makefile.objs
|
|
|
9ae3a8 |
index 0be180f..ebc350b 100644
|
|
|
9ae3a8 |
--- a/block/Makefile.objs
|
|
|
9ae3a8 |
+++ b/block/Makefile.objs
|
|
|
9ae3a8 |
@@ -1,4 +1,4 @@
|
|
|
9ae3a8 |
-block-obj-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
|
|
|
9ae3a8 |
+block-obj-y += raw.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
|
|
|
9ae3a8 |
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
|
|
9ae3a8 |
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
|
|
9ae3a8 |
block-obj-y += qed-check.o
|
|
|
9ae3a8 |
diff --git a/block/cow.c b/block/cow.c
|
|
|
9ae3a8 |
deleted file mode 100644
|
|
|
9ae3a8 |
index c75668b..0000000
|
|
|
9ae3a8 |
--- a/block/cow.c
|
|
|
9ae3a8 |
+++ /dev/null
|
|
|
9ae3a8 |
@@ -1,402 +0,0 @@
|
|
|
9ae3a8 |
-/*
|
|
|
9ae3a8 |
- * Block driver for the COW format
|
|
|
9ae3a8 |
- *
|
|
|
9ae3a8 |
- * Copyright (c) 2004 Fabrice Bellard
|
|
|
9ae3a8 |
- *
|
|
|
9ae3a8 |
- * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
9ae3a8 |
- * of this software and associated documentation files (the "Software"), to deal
|
|
|
9ae3a8 |
- * in the Software without restriction, including without limitation the rights
|
|
|
9ae3a8 |
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
9ae3a8 |
- * copies of the Software, and to permit persons to whom the Software is
|
|
|
9ae3a8 |
- * furnished to do so, subject to the following conditions:
|
|
|
9ae3a8 |
- *
|
|
|
9ae3a8 |
- * The above copyright notice and this permission notice shall be included in
|
|
|
9ae3a8 |
- * all copies or substantial portions of the Software.
|
|
|
9ae3a8 |
- *
|
|
|
9ae3a8 |
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
9ae3a8 |
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
9ae3a8 |
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
9ae3a8 |
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
9ae3a8 |
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
9ae3a8 |
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
9ae3a8 |
- * THE SOFTWARE.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
-#include "qemu-common.h"
|
|
|
9ae3a8 |
-#include "block/block_int.h"
|
|
|
9ae3a8 |
-#include "qemu/module.h"
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/**************************************************************/
|
|
|
9ae3a8 |
-/* COW block driver using file system holes */
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/* user mode linux compatible COW file */
|
|
|
9ae3a8 |
-#define COW_MAGIC 0x4f4f4f4d /* MOOO */
|
|
|
9ae3a8 |
-#define COW_VERSION 2
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-struct cow_header_v2 {
|
|
|
9ae3a8 |
- uint32_t magic;
|
|
|
9ae3a8 |
- uint32_t version;
|
|
|
9ae3a8 |
- char backing_file[1024];
|
|
|
9ae3a8 |
- int32_t mtime;
|
|
|
9ae3a8 |
- uint64_t size;
|
|
|
9ae3a8 |
- uint32_t sectorsize;
|
|
|
9ae3a8 |
-};
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-typedef struct BDRVCowState {
|
|
|
9ae3a8 |
- CoMutex lock;
|
|
|
9ae3a8 |
- int64_t cow_sectors_offset;
|
|
|
9ae3a8 |
-} BDRVCowState;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_probe(const uint8_t *buf, int buf_size, const char *filename)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- const struct cow_header_v2 *cow_header = (const void *)buf;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (buf_size >= sizeof(struct cow_header_v2) &&
|
|
|
9ae3a8 |
- be32_to_cpu(cow_header->magic) == COW_MAGIC &&
|
|
|
9ae3a8 |
- be32_to_cpu(cow_header->version) == COW_VERSION)
|
|
|
9ae3a8 |
- return 100;
|
|
|
9ae3a8 |
- else
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
- Error **errp)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- struct cow_header_v2 cow_header;
|
|
|
9ae3a8 |
- int bitmap_size;
|
|
|
9ae3a8 |
- int64_t size;
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* see if it is a cow image */
|
|
|
9ae3a8 |
- ret = bdrv_pread(bs->file, 0, &cow_header, sizeof(cow_header));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- goto fail;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (be32_to_cpu(cow_header.magic) != COW_MAGIC) {
|
|
|
9ae3a8 |
- error_setg(errp, "Image not in COW format");
|
|
|
9ae3a8 |
- ret = -EINVAL;
|
|
|
9ae3a8 |
- goto fail;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (be32_to_cpu(cow_header.version) != COW_VERSION) {
|
|
|
9ae3a8 |
- char version[64];
|
|
|
9ae3a8 |
- snprintf(version, sizeof(version),
|
|
|
9ae3a8 |
- "COW version %" PRIu32, cow_header.version);
|
|
|
9ae3a8 |
- error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
|
|
|
9ae3a8 |
- bs->device_name, "cow", version);
|
|
|
9ae3a8 |
- ret = -ENOTSUP;
|
|
|
9ae3a8 |
- goto fail;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* cow image found */
|
|
|
9ae3a8 |
- size = be64_to_cpu(cow_header.size);
|
|
|
9ae3a8 |
- bs->total_sectors = size / 512;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- pstrcpy(bs->backing_file, sizeof(bs->backing_file),
|
|
|
9ae3a8 |
- cow_header.backing_file);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- bitmap_size = ((bs->total_sectors + 7) >> 3) + sizeof(cow_header);
|
|
|
9ae3a8 |
- s->cow_sectors_offset = (bitmap_size + 511) & ~511;
|
|
|
9ae3a8 |
- qemu_co_mutex_init(&s->lock);
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
- fail:
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/*
|
|
|
9ae3a8 |
- * XXX(hch): right now these functions are extremely inefficient.
|
|
|
9ae3a8 |
- * We should just read the whole bitmap we'll need in one go instead.
|
|
|
9ae3a8 |
- */
|
|
|
9ae3a8 |
-static inline int cow_set_bit(BlockDriverState *bs, int64_t bitnum, bool *first)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- uint64_t offset = sizeof(struct cow_header_v2) + bitnum / 8;
|
|
|
9ae3a8 |
- uint8_t bitmap;
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (bitmap & (1 << (bitnum % 8))) {
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (*first) {
|
|
|
9ae3a8 |
- ret = bdrv_flush(bs->file);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- *first = false;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- bitmap |= (1 << (bitnum % 8));
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_pwrite(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-#define BITS_PER_BITMAP_SECTOR (512 * 8)
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/* Cannot use bitmap.c on big-endian machines. */
|
|
|
9ae3a8 |
-static int cow_test_bit(int64_t bitnum, const uint8_t *bitmap)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- return (bitmap[bitnum / 8] & (1 << (bitnum & 7))) != 0;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_find_streak(const uint8_t *bitmap, int value, int start, int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int streak_value = value ? 0xFF : 0;
|
|
|
9ae3a8 |
- int last = MIN(start + nb_sectors, BITS_PER_BITMAP_SECTOR);
|
|
|
9ae3a8 |
- int bitnum = start;
|
|
|
9ae3a8 |
- while (bitnum < last) {
|
|
|
9ae3a8 |
- if ((bitnum & 7) == 0 && bitmap[bitnum / 8] == streak_value) {
|
|
|
9ae3a8 |
- bitnum += 8;
|
|
|
9ae3a8 |
- continue;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (cow_test_bit(bitnum, bitmap) == value) {
|
|
|
9ae3a8 |
- bitnum++;
|
|
|
9ae3a8 |
- continue;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- break;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return MIN(bitnum, last) - start;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-/* Return true if first block has been changed (ie. current version is
|
|
|
9ae3a8 |
- * in COW file). Set the number of continuous blocks for which that
|
|
|
9ae3a8 |
- * is true. */
|
|
|
9ae3a8 |
-static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs,
|
|
|
9ae3a8 |
- int64_t sector_num, int nb_sectors, int *num_same)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int64_t bitnum = sector_num + sizeof(struct cow_header_v2) * 8;
|
|
|
9ae3a8 |
- uint64_t offset = (bitnum / 8) & -BDRV_SECTOR_SIZE;
|
|
|
9ae3a8 |
- uint8_t bitmap[BDRV_SECTOR_SIZE];
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
- int changed;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_pread(bs->file, offset, &bitmap, sizeof(bitmap));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- bitnum &= BITS_PER_BITMAP_SECTOR - 1;
|
|
|
9ae3a8 |
- changed = cow_test_bit(bitnum, bitmap);
|
|
|
9ae3a8 |
- *num_same = cow_find_streak(bitmap, changed, bitnum, nb_sectors);
|
|
|
9ae3a8 |
- return changed;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int64_t coroutine_fn cow_co_get_block_status(BlockDriverState *bs,
|
|
|
9ae3a8 |
- int64_t sector_num, int nb_sectors, int *num_same)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- int ret = cow_co_is_allocated(bs, sector_num, nb_sectors, num_same);
|
|
|
9ae3a8 |
- int64_t offset = s->cow_sectors_offset + (sector_num << BDRV_SECTOR_BITS);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return (ret ? BDRV_BLOCK_DATA : 0) | offset | BDRV_BLOCK_OFFSET_VALID;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_update_bitmap(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
- int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int error = 0;
|
|
|
9ae3a8 |
- int i;
|
|
|
9ae3a8 |
- bool first = true;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- for (i = 0; i < nb_sectors; i++) {
|
|
|
9ae3a8 |
- error = cow_set_bit(bs, sector_num + i, &first);
|
|
|
9ae3a8 |
- if (error) {
|
|
|
9ae3a8 |
- break;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return error;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int coroutine_fn cow_read(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
- uint8_t *buf, int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- int ret, n;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- while (nb_sectors > 0) {
|
|
|
9ae3a8 |
- ret = cow_co_is_allocated(bs, sector_num, nb_sectors, &n);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- if (ret) {
|
|
|
9ae3a8 |
- ret = bdrv_pread(bs->file,
|
|
|
9ae3a8 |
- s->cow_sectors_offset + sector_num * 512,
|
|
|
9ae3a8 |
- buf, n * 512);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- if (bs->backing_hd) {
|
|
|
9ae3a8 |
- /* read from the base image */
|
|
|
9ae3a8 |
- ret = bdrv_read(bs->backing_hd, sector_num, buf, n);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- memset(buf, 0, n * 512);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- nb_sectors -= n;
|
|
|
9ae3a8 |
- sector_num += n;
|
|
|
9ae3a8 |
- buf += n * 512;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- return 0;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static coroutine_fn int cow_co_read(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
- uint8_t *buf, int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- qemu_co_mutex_lock(&s->lock);
|
|
|
9ae3a8 |
- ret = cow_read(bs, sector_num, buf, nb_sectors);
|
|
|
9ae3a8 |
- qemu_co_mutex_unlock(&s->lock);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_write(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
- const uint8_t *buf, int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_pwrite(bs->file, s->cow_sectors_offset + sector_num * 512,
|
|
|
9ae3a8 |
- buf, nb_sectors * 512);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- return cow_update_bitmap(bs, sector_num, nb_sectors);
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static coroutine_fn int cow_co_write(BlockDriverState *bs, int64_t sector_num,
|
|
|
9ae3a8 |
- const uint8_t *buf, int nb_sectors)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
- BDRVCowState *s = bs->opaque;
|
|
|
9ae3a8 |
- qemu_co_mutex_lock(&s->lock);
|
|
|
9ae3a8 |
- ret = cow_write(bs, sector_num, buf, nb_sectors);
|
|
|
9ae3a8 |
- qemu_co_mutex_unlock(&s->lock);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static void cow_close(BlockDriverState *bs)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static int cow_create(const char *filename, QEMUOptionParameter *options,
|
|
|
9ae3a8 |
- Error **errp)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- struct cow_header_v2 cow_header;
|
|
|
9ae3a8 |
- struct stat st;
|
|
|
9ae3a8 |
- int64_t image_sectors = 0;
|
|
|
9ae3a8 |
- const char *image_filename = NULL;
|
|
|
9ae3a8 |
- Error *local_err = NULL;
|
|
|
9ae3a8 |
- int ret;
|
|
|
9ae3a8 |
- BlockDriverState *cow_bs;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* Read out options */
|
|
|
9ae3a8 |
- while (options && options->name) {
|
|
|
9ae3a8 |
- if (!strcmp(options->name, BLOCK_OPT_SIZE)) {
|
|
|
9ae3a8 |
- image_sectors = options->value.n / 512;
|
|
|
9ae3a8 |
- } else if (!strcmp(options->name, BLOCK_OPT_BACKING_FILE)) {
|
|
|
9ae3a8 |
- image_filename = options->value.s;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- options++;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_create_file(filename, options, &local_err);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- error_propagate(errp, local_err);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_file_open(&cow_bs, filename, NULL, BDRV_O_RDWR, &local_err);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- error_propagate(errp, local_err);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- memset(&cow_header, 0, sizeof(cow_header));
|
|
|
9ae3a8 |
- cow_header.magic = cpu_to_be32(COW_MAGIC);
|
|
|
9ae3a8 |
- cow_header.version = cpu_to_be32(COW_VERSION);
|
|
|
9ae3a8 |
- if (image_filename) {
|
|
|
9ae3a8 |
- /* Note: if no file, we put a dummy mtime */
|
|
|
9ae3a8 |
- cow_header.mtime = cpu_to_be32(0);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- if (stat(image_filename, &st) != 0) {
|
|
|
9ae3a8 |
- goto mtime_fail;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- cow_header.mtime = cpu_to_be32(st.st_mtime);
|
|
|
9ae3a8 |
- mtime_fail:
|
|
|
9ae3a8 |
- pstrcpy(cow_header.backing_file, sizeof(cow_header.backing_file),
|
|
|
9ae3a8 |
- image_filename);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
- cow_header.sectorsize = cpu_to_be32(512);
|
|
|
9ae3a8 |
- cow_header.size = cpu_to_be64(image_sectors * 512);
|
|
|
9ae3a8 |
- ret = bdrv_pwrite(cow_bs, 0, &cow_header, sizeof(cow_header));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- goto exit;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- /* resize to include at least all the bitmap */
|
|
|
9ae3a8 |
- ret = bdrv_truncate(cow_bs,
|
|
|
9ae3a8 |
- sizeof(cow_header) + ((image_sectors + 7) >> 3));
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
- goto exit;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-exit:
|
|
|
9ae3a8 |
- bdrv_unref(cow_bs);
|
|
|
9ae3a8 |
- return ret;
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static QEMUOptionParameter cow_create_options[] = {
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- .name = BLOCK_OPT_SIZE,
|
|
|
9ae3a8 |
- .type = OPT_SIZE,
|
|
|
9ae3a8 |
- .help = "Virtual disk size"
|
|
|
9ae3a8 |
- },
|
|
|
9ae3a8 |
- {
|
|
|
9ae3a8 |
- .name = BLOCK_OPT_BACKING_FILE,
|
|
|
9ae3a8 |
- .type = OPT_STRING,
|
|
|
9ae3a8 |
- .help = "File name of a base image"
|
|
|
9ae3a8 |
- },
|
|
|
9ae3a8 |
- { NULL }
|
|
|
9ae3a8 |
-};
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static BlockDriver bdrv_cow = {
|
|
|
9ae3a8 |
- .format_name = "cow",
|
|
|
9ae3a8 |
- .instance_size = sizeof(BDRVCowState),
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- .bdrv_probe = cow_probe,
|
|
|
9ae3a8 |
- .bdrv_open = cow_open,
|
|
|
9ae3a8 |
- .bdrv_close = cow_close,
|
|
|
9ae3a8 |
- .bdrv_create = cow_create,
|
|
|
9ae3a8 |
- .bdrv_has_zero_init = bdrv_has_zero_init_1,
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- .bdrv_read = cow_co_read,
|
|
|
9ae3a8 |
- .bdrv_write = cow_co_write,
|
|
|
9ae3a8 |
- .bdrv_co_get_block_status = cow_co_get_block_status,
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- .create_options = cow_create_options,
|
|
|
9ae3a8 |
-};
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-static void bdrv_cow_init(void)
|
|
|
9ae3a8 |
-{
|
|
|
9ae3a8 |
- bdrv_register(&bdrv_cow);
|
|
|
9ae3a8 |
-}
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-block_init(bdrv_cow_init);
|
|
|
9ae3a8 |
diff --git a/qapi-schema.json b/qapi-schema.json
|
|
|
9ae3a8 |
index 2af2643..8a7cf0b 100644
|
|
|
9ae3a8 |
--- a/qapi-schema.json
|
|
|
9ae3a8 |
+++ b/qapi-schema.json
|
|
|
9ae3a8 |
@@ -826,6 +826,7 @@
|
|
|
9ae3a8 |
# 'file', 'file', 'ftp', 'ftps', 'host_cdrom', 'host_device',
|
|
|
9ae3a8 |
# 'host_floppy', 'http', 'https', 'nbd', 'parallels', 'qcow',
|
|
|
9ae3a8 |
# 'qcow2', 'raw', 'tftp', 'vdi', 'vmdk', 'vpc', 'vvfat'
|
|
|
9ae3a8 |
+# 2.2: 'cow' dropped
|
|
|
9ae3a8 |
#
|
|
|
9ae3a8 |
# @backing_file: #optional the name of the backing file (for copy-on-write)
|
|
|
9ae3a8 |
#
|
|
|
9ae3a8 |
@@ -4076,7 +4077,6 @@
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
'bochs': 'BlockdevOptionsGenericFormat',
|
|
|
9ae3a8 |
'cloop': 'BlockdevOptionsGenericFormat',
|
|
|
9ae3a8 |
- 'cow': 'BlockdevOptionsGenericCOWFormat',
|
|
|
9ae3a8 |
'dmg': 'BlockdevOptionsGenericFormat',
|
|
|
9ae3a8 |
'parallels': 'BlockdevOptionsGenericFormat',
|
|
|
9ae3a8 |
'qcow': 'BlockdevOptionsGenericCOWFormat',
|
|
|
9ae3a8 |
diff --git a/qemu-doc.texi b/qemu-doc.texi
|
|
|
9ae3a8 |
index ff124fe..33f709a 100644
|
|
|
9ae3a8 |
--- a/qemu-doc.texi
|
|
|
9ae3a8 |
+++ b/qemu-doc.texi
|
|
|
9ae3a8 |
@@ -621,15 +621,6 @@ File name of a base image (see @option{create} subcommand)
|
|
|
9ae3a8 |
If this option is set to @code{on}, the image is encrypted.
|
|
|
9ae3a8 |
@end table
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-@item cow
|
|
|
9ae3a8 |
-User Mode Linux Copy On Write image format. It is supported only for
|
|
|
9ae3a8 |
-compatibility with previous versions.
|
|
|
9ae3a8 |
-Supported options:
|
|
|
9ae3a8 |
-@table @code
|
|
|
9ae3a8 |
-@item backing_file
|
|
|
9ae3a8 |
-File name of a base image (see @option{create} subcommand)
|
|
|
9ae3a8 |
-@end table
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
@item vdi
|
|
|
9ae3a8 |
VirtualBox 1.1 compatible image format.
|
|
|
9ae3a8 |
Supported options:
|
|
|
9ae3a8 |
diff --git a/qemu-img.texi b/qemu-img.texi
|
|
|
9ae3a8 |
index e943856..2099dd1 100644
|
|
|
9ae3a8 |
--- a/qemu-img.texi
|
|
|
9ae3a8 |
+++ b/qemu-img.texi
|
|
|
9ae3a8 |
@@ -201,8 +201,8 @@ compression is read-only. It means that if a compressed sector is
|
|
|
9ae3a8 |
rewritten, then it is rewritten as uncompressed data.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Image conversion is also useful to get smaller image when using a
|
|
|
9ae3a8 |
-growable format such as @code{qcow} or @code{cow}: the empty sectors
|
|
|
9ae3a8 |
-are detected and suppressed from the destination image.
|
|
|
9ae3a8 |
+growable format such as @code{qcow}: the empty sectors are detected and
|
|
|
9ae3a8 |
+suppressed from the destination image.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@var{sparse_size} indicates the consecutive number of bytes (defaults to 4k)
|
|
|
9ae3a8 |
that must contain only zeros for qemu-img to create a sparse image during
|
|
|
9ae3a8 |
diff --git a/qmp-commands.hx b/qmp-commands.hx
|
|
|
9ae3a8 |
index 9c11213..44dd48e 100644
|
|
|
9ae3a8 |
--- a/qmp-commands.hx
|
|
|
9ae3a8 |
+++ b/qmp-commands.hx
|
|
|
9ae3a8 |
@@ -1903,7 +1903,7 @@ Each json-object contain the following:
|
|
|
9ae3a8 |
- "file": device file name (json-string)
|
|
|
9ae3a8 |
- "ro": true if read-only, false otherwise (json-bool)
|
|
|
9ae3a8 |
- "drv": driver format name (json-string)
|
|
|
9ae3a8 |
- - Possible values: "blkdebug", "bochs", "cloop", "cow", "dmg",
|
|
|
9ae3a8 |
+ - Possible values: "blkdebug", "bochs", "cloop", "dmg",
|
|
|
9ae3a8 |
"file", "file", "ftp", "ftps", "host_cdrom",
|
|
|
9ae3a8 |
"host_device", "host_floppy", "http", "https",
|
|
|
9ae3a8 |
"nbd", "parallels", "qcow", "qcow2", "raw",
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/069 b/tests/qemu-iotests/069
|
|
|
9ae3a8 |
index 50347d9..d606685 100755
|
|
|
9ae3a8 |
--- a/tests/qemu-iotests/069
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/069
|
|
|
9ae3a8 |
@@ -38,7 +38,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
|
|
|
9ae3a8 |
. ./common.rc
|
|
|
9ae3a8 |
. ./common.filter
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-_supported_fmt cow qed qcow qcow2 vmdk
|
|
|
9ae3a8 |
+_supported_fmt qed qcow qcow2 vmdk
|
|
|
9ae3a8 |
_supported_proto generic
|
|
|
9ae3a8 |
_supported_os Linux
|
|
|
9ae3a8 |
_unsupported_imgopts "subformat=monolithicFlat" "subformat=twoGbMaxExtentFlat"
|
|
|
9ae3a8 |
diff --git a/tests/qemu-iotests/common b/tests/qemu-iotests/common
|
|
|
9ae3a8 |
index f8c1b56..a90415a 100644
|
|
|
9ae3a8 |
--- a/tests/qemu-iotests/common
|
|
|
9ae3a8 |
+++ b/tests/qemu-iotests/common
|
|
|
9ae3a8 |
@@ -129,7 +129,6 @@ common options
|
|
|
9ae3a8 |
check options
|
|
|
9ae3a8 |
-raw test raw (default)
|
|
|
9ae3a8 |
-bochs test bochs
|
|
|
9ae3a8 |
- -cow test cow
|
|
|
9ae3a8 |
-cloop test cloop
|
|
|
9ae3a8 |
-parallels test parallels
|
|
|
9ae3a8 |
-qcow test qcow
|
|
|
9ae3a8 |
@@ -171,11 +170,6 @@ testlist options
|
|
|
9ae3a8 |
xpand=false
|
|
|
9ae3a8 |
;;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- -cow)
|
|
|
9ae3a8 |
- IMGFMT=cow
|
|
|
9ae3a8 |
- xpand=false
|
|
|
9ae3a8 |
- ;;
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
-cloop)
|
|
|
9ae3a8 |
IMGFMT=cloop
|
|
|
9ae3a8 |
IMGFMT_GENERIC=false
|
|
|
9ae3a8 |
diff --git a/ui/cocoa.m b/ui/cocoa.m
|
|
|
9ae3a8 |
index 1971d9c..0c35f25 100644
|
|
|
9ae3a8 |
--- a/ui/cocoa.m
|
|
|
9ae3a8 |
+++ b/ui/cocoa.m
|
|
|
9ae3a8 |
@@ -771,7 +771,7 @@ QemuCocoaView *cocoaView;
|
|
|
9ae3a8 |
NSOpenPanel *op = [[NSOpenPanel alloc] init];
|
|
|
9ae3a8 |
[op setPrompt:@"Boot image"];
|
|
|
9ae3a8 |
[op setMessage:@"Select the disk image you want to boot.\n\nHit the \"Cancel\" button to quit"];
|
|
|
9ae3a8 |
- [op beginSheetForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"img",@"iso",@"dmg",@"qcow",@"cow",@"cloop",@"vmdk",nil]
|
|
|
9ae3a8 |
+ [op beginSheetForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"img",@"iso",@"dmg",@"qcow",@"cloop",@"vmdk",nil]
|
|
|
9ae3a8 |
modalForWindow:normalWindow modalDelegate:self
|
|
|
9ae3a8 |
didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
2.1.0
|
|
|
9ae3a8 |
|