mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
block: vhdx - log parsing, replay, and flush support
This adds support for VHDX v0 logs, as specified in Microsoft's VHDX Specification Format v1.00: https://www.microsoft.com/en-us/download/details.aspx?id=34750 The following support is added: * Log parsing, and validation - validate that an existing log is correct. * Log search - search through an existing log, to find any valid sequence of entries. * Log replay and flush - replay an existing log, and flush/clear the log when complete. The VHDX log is a circular buffer, with elements (sectors) of 4KB. A log entry is a variably-length number of sectors, that is comprised of a header and 'descriptors', that describe each sector. A log may contain multiple entries, know as a log sequence. In a log sequence, each log entry immediately follows the previous entry, with an incrementing sequence number. There can only ever be one active and valid sequence in the log. Each log entry must match the file log GUID in order to be valid (along with other criteria). Once we have flushed all valid log entries, we marked the file log GUID to be zero, which indicates a buffer with no valid entries. Signed-off-by: Jeff Cody <jcody@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
committed by
Stefan Hajnoczi
parent
c46415afc2
commit
0a43a1b5d7
+1
-1
@@ -2,7 +2,7 @@ block-obj-y += raw_bsd.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o v
|
||||
block-obj-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
|
||||
block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
||||
block-obj-y += qed-check.o
|
||||
block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o
|
||||
block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
|
||||
block-obj-y += parallels.o blkdebug.o blkverify.o
|
||||
block-obj-y += snapshot.o qapi.o
|
||||
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+14
-51
@@ -735,58 +735,22 @@ exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Parse the replay log. Per the VHDX spec, if the log is present
|
||||
* it must be replayed prior to opening the file, even read-only.
|
||||
*
|
||||
* If read-only, we must replay the log in RAM (or refuse to open
|
||||
* a dirty VHDX file read-only */
|
||||
static int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
VHDXHeader *hdr;
|
||||
|
||||
hdr = s->headers[s->curr_header];
|
||||
|
||||
/* either the log guid, or log length is zero,
|
||||
* then a replay log is present */
|
||||
for (i = 0; i < sizeof(hdr->log_guid.data4); i++) {
|
||||
ret |= hdr->log_guid.data4[i];
|
||||
}
|
||||
if (hdr->log_guid.data1 == 0 &&
|
||||
hdr->log_guid.data2 == 0 &&
|
||||
hdr->log_guid.data3 == 0 &&
|
||||
ret == 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* per spec, only log version of 0 is supported */
|
||||
if (hdr->log_version != 0) {
|
||||
ret = -EINVAL;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (hdr->log_length == 0) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* We currently do not support images with logs to replay */
|
||||
ret = -ENOTSUP;
|
||||
|
||||
exit:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void vhdx_close(BlockDriverState *bs)
|
||||
{
|
||||
BDRVVHDXState *s = bs->opaque;
|
||||
qemu_vfree(s->headers[0]);
|
||||
s->headers[0] = NULL;
|
||||
qemu_vfree(s->headers[1]);
|
||||
s->headers[1] = NULL;
|
||||
qemu_vfree(s->bat);
|
||||
s->bat = NULL;
|
||||
qemu_vfree(s->parent_entries);
|
||||
s->parent_entries = NULL;
|
||||
migrate_del_blocker(s->migration_blocker);
|
||||
error_free(s->migration_blocker);
|
||||
qemu_vfree(s->log.hdr);
|
||||
s->log.hdr = NULL;
|
||||
}
|
||||
|
||||
static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
@@ -797,6 +761,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
uint32_t i;
|
||||
uint64_t signature;
|
||||
uint32_t data_blocks_cnt, bitmap_blocks_cnt;
|
||||
bool log_flushed = false;
|
||||
|
||||
|
||||
s->bat = NULL;
|
||||
@@ -820,24 +785,25 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
vhdx_guid_generate(&s->session_guid);
|
||||
|
||||
ret = vhdx_parse_header(bs, s);
|
||||
if (ret) {
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = vhdx_parse_log(bs, s);
|
||||
if (ret) {
|
||||
ret = vhdx_parse_log(bs, s, &log_flushed);
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = vhdx_open_region_tables(bs, s);
|
||||
if (ret) {
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = vhdx_parse_metadata(bs, s);
|
||||
if (ret) {
|
||||
if (ret < 0) {
|
||||
goto fail;
|
||||
}
|
||||
|
||||
s->block_size = s->params.block_size;
|
||||
|
||||
/* the VHDX spec dictates that virtual_disk_size is always a multiple of
|
||||
@@ -897,10 +863,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
return 0;
|
||||
fail:
|
||||
qemu_vfree(s->headers[0]);
|
||||
qemu_vfree(s->headers[1]);
|
||||
qemu_vfree(s->bat);
|
||||
qemu_vfree(s->parent_entries);
|
||||
vhdx_close(bs);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -326,7 +326,11 @@ typedef struct VHDXMetadataEntries {
|
||||
typedef struct VHDXLogEntries {
|
||||
uint64_t offset;
|
||||
uint64_t length;
|
||||
uint32_t head;
|
||||
uint32_t write;
|
||||
uint32_t read;
|
||||
VHDXLogEntryHeader *hdr;
|
||||
void *desc_buffer;
|
||||
uint64_t sequence;
|
||||
uint32_t tail;
|
||||
} VHDXLogEntries;
|
||||
|
||||
@@ -383,6 +387,7 @@ uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size,
|
||||
|
||||
bool vhdx_checksum_is_valid(uint8_t *buf, size_t size, int crc_offset);
|
||||
|
||||
int vhdx_parse_log(BlockDriverState *bs, BDRVVHDXState *s, bool *flushed);
|
||||
|
||||
static inline void leguid_to_cpus(MSGUID *guid)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user