From patchwork Mon Dec 15 08:27:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 421020 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 74DF41400D2 for ; Mon, 15 Dec 2014 20:14:04 +1100 (AEDT) Received: from localhost ([::1]:38576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0Rj8-0005Mc-9G for incoming@patchwork.ozlabs.org; Mon, 15 Dec 2014 04:14:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47829) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0Rfx-0007vO-RU for qemu-devel@nongnu.org; Mon, 15 Dec 2014 04:10:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y0Rfs-0005bs-F9 for qemu-devel@nongnu.org; Mon, 15 Dec 2014 04:10:45 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:27462 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y0Rfr-0004kT-WD for qemu-devel@nongnu.org; Mon, 15 Dec 2014 04:10:40 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id sBF8RAUP012492; Mon, 15 Dec 2014 12:27:34 +0400 (MSK) From: "Denis V. Lunev" To: Date: Mon, 15 Dec 2014 11:27:58 +0300 Message-Id: <1418632081-20667-14-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418632081-20667-1-git-send-email-den@openvz.org> References: <1418632081-20667-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , "Denis V. Lunev" , Jeff Cody , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 13/16] block/parallels: read disk size from XML if DiskDescriptor.xml is passed 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 as an image filename. This is preparational commit to read snapshot information from XML. This is the only global parameter which will be kept in BDRVParallelsState, the rest should be layered down into snapshots information structure. Signed-off-by: Denis V. Lunev CC: Jeff Cody CC: Kevin Wolf CC: Stefan Hajnoczi --- block/parallels.c | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index 718274b..0c0e669 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -107,6 +107,7 @@ static int parallels_open_image(BlockDriverState *bs, Error **errp) int i; struct parallels_header ph; int ret; + int64_t total_sectors; bs->read_only = 1; // no write support yet @@ -115,20 +116,35 @@ static int parallels_open_image(BlockDriverState *bs, Error **errp) goto fail; } - bs->total_sectors = le64_to_cpu(ph.nb_sectors); + total_sectors = le64_to_cpu(ph.nb_sectors); if (le32_to_cpu(ph.version) != HEADER_VERSION) { goto fail_format; } if (!memcmp(ph.magic, HEADER_MAGIC, 16)) { s->off_multiplier = 1; - bs->total_sectors = 0xffffffff & bs->total_sectors; + total_sectors = 0xffffffff & total_sectors; } else if (!memcmp(ph.magic, HEADER_MAGIC2, 16)) { s->off_multiplier = le32_to_cpu(ph.tracks); } else { goto fail_format; } + if (total_sectors == 0) { + error_setg(errp, "Invalid image: zero total sectors"); + ret = -EINVAL; + goto fail; + } + if (bs->total_sectors == 0) { + /* no descriptor file, standalone image opened */ + bs->total_sectors = total_sectors; + } + if (bs->total_sectors != total_sectors) { + error_setg(errp, "Invalid image: wrong total sectors"); + ret = -EINVAL; + goto fail; + } + s->tracks = le32_to_cpu(ph.tracks); if (s->tracks == 0) { error_setg(errp, "Invalid image: Zero sectors per track"); @@ -234,7 +250,7 @@ static int parallels_open_xml(BlockDriverState *bs, int flags, Error **errp) int size, ret; xmlDoc *doc = NULL; xmlNode *root, *image; - char *xml = NULL; + char *xml = NULL, *endptr; const char *data; char image_path[PATH_MAX]; Error *local_err = NULL; @@ -271,7 +287,6 @@ static int parallels_open_xml(BlockDriverState *bs, int flags, Error **errp) data = xml_get_text(root, "Disk_Parameters", "Padding", NULL); if (data != NULL) { - char *endptr; unsigned long pad; pad = strtoul(data, &endptr, 0); @@ -281,6 +296,16 @@ static int parallels_open_xml(BlockDriverState *bs, int flags, Error **errp) s->padding = (uint32_t)pad; } + data = xml_get_text(root, "Disk_Parameters", "Disk_size", NULL); + if (data == NULL) { + goto fail; + } else { + bs->total_sectors = strtoull(data, &endptr, 0); + if (endptr != NULL && *endptr != '\0') { + goto fail; + } + } + image = xml_seek(root, "StorageData", "Storage", "Image", NULL); data = ""; /* make gcc happy */ for (size = 0; image != NULL; image = image->next) {