From patchwork Fri Nov 8 10:12:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 289778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A221E2C007E for ; Fri, 8 Nov 2013 22:04:52 +1100 (EST) Received: from localhost ([::1]:44734 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VejJ5-0000mr-MA for incoming@patchwork.ozlabs.org; Fri, 08 Nov 2013 05:28:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vej98-0003a0-Mu for qemu-devel@nongnu.org; Fri, 08 Nov 2013 05:18:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vej92-0007Yr-NP for qemu-devel@nongnu.org; Fri, 08 Nov 2013 05:18:34 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22423) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vej92-0007Yn-FN for qemu-devel@nongnu.org; Fri, 08 Nov 2013 05:18:28 -0500 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rA8ADRKx000693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 8 Nov 2013 05:13:27 -0500 Received: from localhost (ovpn-112-38.ams2.redhat.com [10.36.112.38]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id rA8ADQRS012469; Fri, 8 Nov 2013 05:13:27 -0500 From: Stefan Hajnoczi To: Date: Fri, 8 Nov 2013 11:12:17 +0100 Message-Id: <1383905551-16411-24-git-send-email-stefanha@redhat.com> In-Reply-To: <1383905551-16411-1-git-send-email-stefanha@redhat.com> References: <1383905551-16411-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jeff Cody , Stefan Hajnoczi , Anthony Liguori Subject: [Qemu-devel] [PULL v2 23/37] block: vhdx - update log guid in header, and first write tracker X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jeff Cody Allow tracking of first file write in the VHDX image, as well as the ability to update the GUID in the header. This is in preparation for log support. Signed-off-by: Jeff Cody Signed-off-by: Stefan Hajnoczi --- block/vhdx.c | 30 ++++++++++++++++++++++++------ block/vhdx.h | 6 ++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/block/vhdx.c b/block/vhdx.c index 68663c6..241703a 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -230,7 +230,7 @@ static int vhdx_probe(const uint8_t *buf, int buf_size, const char *filename) * - non-current header is updated with largest sequence number */ static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, - bool generate_data_write_guid) + bool generate_data_write_guid, MSGUID *log_guid) { int ret = 0; int hdr_idx = 0; @@ -262,6 +262,11 @@ static int vhdx_update_header(BlockDriverState *bs, BDRVVHDXState *s, vhdx_guid_generate(&inactive_header->data_write_guid); } + /* update the log guid if present */ + if (log_guid) { + inactive_header->log_guid = *log_guid; + } + /* the header checksum is not over just the packed size of VHDXHeader, * but rather over the entire 'reserved' range for the header, which is * 4KB (VHDX_HEADER_SIZE). */ @@ -294,16 +299,16 @@ exit: * The VHDX spec calls for header updates to be performed twice, so that both * the current and non-current header have valid info */ -static int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, - bool generate_data_write_guid) +int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, + bool generate_data_write_guid, MSGUID *log_guid) { int ret; - ret = vhdx_update_header(bs, s, generate_data_write_guid); + ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid); if (ret < 0) { return ret; } - ret = vhdx_update_header(bs, s, generate_data_write_guid); + ret = vhdx_update_header(bs, s, generate_data_write_guid, log_guid); return ret; } @@ -784,6 +789,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, s->bat = NULL; + s->first_visible_write = true; qemu_co_mutex_init(&s->lock); @@ -864,7 +870,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags, } if (flags & BDRV_O_RDWR) { - ret = vhdx_update_headers(bs, s, false); + ret = vhdx_update_headers(bs, s, false, NULL); if (ret < 0) { goto fail; } @@ -1010,6 +1016,18 @@ exit: +/* Per the spec, on the first write of guest-visible data to the file the + * data write guid must be updated in the header */ +int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s) +{ + int ret = 0; + if (s->first_visible_write) { + s->first_visible_write = false; + ret = vhdx_update_headers(bs, s, true, NULL); + } + return ret; +} + static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { diff --git a/block/vhdx.h b/block/vhdx.h index 23028af..6c35737 100644 --- a/block/vhdx.h +++ b/block/vhdx.h @@ -361,6 +361,7 @@ typedef struct BDRVVHDXState { VHDXBatEntry *bat; uint64_t bat_offset; + bool first_visible_write; MSGUID session_guid; VHDXLogEntries log; @@ -373,6 +374,9 @@ typedef struct BDRVVHDXState { void vhdx_guid_generate(MSGUID *guid); +int vhdx_update_headers(BlockDriverState *bs, BDRVVHDXState *s, bool rw, + MSGUID *log_guid); + uint32_t vhdx_update_checksum(uint8_t *buf, size_t size, int crc_offset); uint32_t vhdx_checksum_calc(uint32_t crc, uint8_t *buf, size_t size, int crc_offset); @@ -402,4 +406,6 @@ void vhdx_log_data_le_export(VHDXLogDataSector *d); void vhdx_log_entry_hdr_le_import(VHDXLogEntryHeader *hdr); void vhdx_log_entry_hdr_le_export(VHDXLogEntryHeader *hdr); +int vhdx_user_visible_write(BlockDriverState *bs, BDRVVHDXState *s); + #endif