From patchwork Tue Aug 23 04:27:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Devin Nakamura X-Patchwork-Id: 111040 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 76363B7210 for ; Tue, 23 Aug 2011 15:09:06 +1000 (EST) Received: from localhost ([::1]:42929 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvibf-000642-KL for incoming@patchwork.ozlabs.org; Tue, 23 Aug 2011 00:28:55 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46112) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvib9-0004j5-M3 for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qvib8-0007WC-2L for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:23 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:42417) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qvib7-0007Se-EU for qemu-devel@nongnu.org; Tue, 23 Aug 2011 00:28:21 -0400 Received: by mail-yx0-f173.google.com with SMTP id 3so4715948yxt.4 for ; Mon, 22 Aug 2011 21:28:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=hqJYnR7We6aS4WtOpwQbKUA+PVq11BkzRU9mw0y5vw0=; b=x9wWRo6eB8GQOMpIrFsh3U3OvY2yk1IZkybOxG8xHh41e5XVgERm4auXIzjboeO9ez duOYTW1k/FL0405igIX/as+U4C1k0ZwV+w2sajJF+itDWqYA9HbUP5MvaPRzumfpRR0F 1kmzMIHNfRz62UDOObvi7rqQJBewDXmjVcpJw= Received: by 10.236.78.104 with SMTP id f68mr19581490yhe.47.1314073701111; Mon, 22 Aug 2011 21:28:21 -0700 (PDT) Received: from localhost.localdomain (d72-39-252-38.home1.cgocable.net [72.39.252.38]) by mx.google.com with ESMTPS id o2sm369474yhl.71.2011.08.22.21.28.20 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 22 Aug 2011 21:28:20 -0700 (PDT) From: Devin Nakamura To: qemu-devel@nongnu.org Date: Tue, 23 Aug 2011 00:27:43 -0400 Message-Id: <1314073663-32691-8-git-send-email-devin122@gmail.com> X-Mailer: git-send-email 1.7.6.rc1 In-Reply-To: <1314073663-32691-1-git-send-email-devin122@gmail.com> References: <1314073663-32691-1-git-send-email-devin122@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.213.173 Cc: kwolf@redhat.com, Devin Nakamura Subject: [Qemu-devel] [PATCH V4 7/7] block: add bdrv_copy_header() 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 Signed-off-by: Devin Nakamura --- block.c | 41 +++++++++++++++++++++++++++++++++++++++++ block.h | 2 ++ 2 files changed, 43 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index aff1d34..76bd2e9 100644 --- a/block.c +++ b/block.c @@ -3349,3 +3349,44 @@ int bdrv_map(BlockDriverState *bs, uint64_t guest_offset, return drv->bdrv_map(bs, guest_offset, host_offset, contiguous_bytes); } + +/** + * Copies out the header of a conversion target + * + * Saves the current header for the image in a temporary file and overwrites + * it with the header for the new format (at the moment the header is + * assumed to be 1 sector) + * + * A filename can be specified by using filename. On entry if + * filename = NULL , or filename points to an empty string, a random file + * name will be generated. + * + * If a random filename was generated it will be returned to the user by + * copying it to the location pointed at by filename. Filename must already + * be allocated to a size of at least PATH_MAX + * + * @param bs Usualy opened with bdrv_open_conversion_target() + * @param filename[in,out] On entry is the optional filename to be used. On + * exit it will be the filename used (assuming + * filename != NULL at entry) + * @return Returns non-zero on failure + */ +int bdrv_copy_header(BlockDriverState *bs, char *filename) +{ + BlockDriver *drv = bs->drv; + char tmp_filename[PATH_MAX] = ""; + + if (!drv) { + return -ENOMEDIUM; + } + if (!drv->bdrv_copy_header) { + return -ENOTSUP; + } + if (!filename) { + filename = tmp_filename; + } + if (!filename[0]) { + get_tmp_filename(filename, PATH_MAX); + } + return drv->bdrv_copy_header(bs, filename); +} diff --git a/block.h b/block.h index 558b9b8..2fc546a 100644 --- a/block.h +++ b/block.h @@ -268,6 +268,8 @@ int bdrv_get_mapping(BlockDriverState *bs, uint64_t guest_offset, uint64_t *host_offset, uint64_t *contiguous_bytes); int bdrv_map(BlockDriverState *bs, uint64_t guest_offset, uint64_t host_offset, uint64_t contiguous_bytes); +int bdrv_copy_header(BlockDriverState *bs, char *filename); + typedef enum { BLKDBG_L1_UPDATE,