From patchwork Thu Apr 12 12:01:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 152067 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E21E0B7037 for ; Thu, 12 Apr 2012 23:35:59 +1000 (EST) Received: from localhost ([::1]:36822 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIIk2-0006bZ-Ne for incoming@patchwork.ozlabs.org; Thu, 12 Apr 2012 08:03:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51077) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIIjG-0005EF-D8 for qemu-devel@nongnu.org; Thu, 12 Apr 2012 08:02:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SIIj9-0005uV-Rl for qemu-devel@nongnu.org; Thu, 12 Apr 2012 08:02:21 -0400 Received: from mail-pz0-f46.google.com ([209.85.210.46]:48160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SIIj9-0005oO-IU for qemu-devel@nongnu.org; Thu, 12 Apr 2012 08:02:15 -0400 Received: by mail-pz0-f46.google.com with SMTP id z9so2767139dad.33 for ; Thu, 12 Apr 2012 05:02:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=yWKspvxtLlczxFSXW42OrXnhvcEBk+Kwb7ir3M2WU6g=; b=PU/dvFLaX+vzbDYRW3HtIJGZxxPXwbXk/72PymlsKI0y+o/DkmmhV57POg0n9IeSGb g4CAveYTqpZEBycHuF6WMQtfJxQlDGq9umP4zDr0QQ6FYUf4GGVLInoN7wlgS2IGa30V D7zr0ZjkgSbW8su7xNx7qOjr/rylbJ8LPs7cxeQg9gH/RilsJDfJqDD3DaOFj9+1nS+W xvQspsW0qrFlN3UcrwClmIj0im7FnOZMDzRMq2TCkX+iajVWxYwrIEjEbpB92HAuLYrt +MgGOpB21jQCpUQ2isCsBeOrZGWhwAZ09iTkn4DUFSvfb+qV7a9NcqUGCk9Y6y29sHEs NZRQ== Received: by 10.68.226.8 with SMTP id ro8mr2508642pbc.72.1334232134626; Thu, 12 Apr 2012 05:02:14 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-182-16.ip50.fastwebnet.it. [93.34.182.16]) by mx.google.com with ESMTPS id qu5sm5515368pbc.45.2012.04.12.05.02.11 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 12 Apr 2012 05:02:13 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 12 Apr 2012 14:01:00 +0200 Message-Id: <1334232076-19018-11-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.9.3 In-Reply-To: <1334232076-19018-1-git-send-email-pbonzini@redhat.com> References: <1334232076-19018-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.46 Cc: kwolf@redhat.com, stefanha@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 10/26] block: fix snapshot on QED 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 QED's opaque data includes a pointer back to the BlockDriverState. This breaks when bdrv_append shuffles data between bs_new and bs_top. To avoid this, add a "rebind" function that tells the driver about the new relationship between the BlockDriverState and its opaque. The patch also adds rebind to VVFAT for completeness, even though it is not used with live snapshots. Reviewed-by: Stefan Hajnoczi Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini --- block.c | 10 ++++++++++ block/qed.c | 7 +++++++ block/vvfat.c | 7 +++++++ block_int.h | 1 + 4 files changed, 25 insertions(+) diff --git a/block.c b/block.c index 33efa95..b1be146 100644 --- a/block.c +++ b/block.c @@ -906,6 +906,13 @@ void bdrv_make_anon(BlockDriverState *bs) bs->device_name[0] = '\0'; } +static void bdrv_rebind(BlockDriverState *bs) +{ + if (bs->drv && bs->drv->bdrv_rebind) { + bs->drv->bdrv_rebind(bs); + } +} + /* * Add new bs contents at the top of an image chain while the chain is * live, while keeping required fields on the top layer. @@ -994,6 +1001,9 @@ void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top) bs_new->slice_time = 0; bs_new->slice_start = 0; bs_new->slice_end = 0; + + bdrv_rebind(bs_new); + bdrv_rebind(bs_top); } void bdrv_delete(BlockDriverState *bs) diff --git a/block/qed.c b/block/qed.c index 366cde7..30a31f9 100644 --- a/block/qed.c +++ b/block/qed.c @@ -367,6 +367,12 @@ static void qed_cancel_need_check_timer(BDRVQEDState *s) qemu_del_timer(s->need_check_timer); } +static void bdrv_qed_rebind(BlockDriverState *bs) +{ + BDRVQEDState *s = bs->opaque; + s->bs = bs; +} + static int bdrv_qed_open(BlockDriverState *bs, int flags) { BDRVQEDState *s = bs->opaque; @@ -1550,6 +1556,7 @@ static BlockDriver bdrv_qed = { .create_options = qed_create_options, .bdrv_probe = bdrv_qed_probe, + .bdrv_rebind = bdrv_qed_rebind, .bdrv_open = bdrv_qed_open, .bdrv_close = bdrv_qed_close, .bdrv_create = bdrv_qed_create, diff --git a/block/vvfat.c b/block/vvfat.c index 9ef21dd..2dc9d50 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -982,6 +982,12 @@ static BDRVVVFATState *vvv = NULL; static int enable_write_target(BDRVVVFATState *s); static int is_consistent(BDRVVVFATState *s); +static void vvfat_rebind(BlockDriverState *bs) +{ + BDRVVVFATState *s = bs->opaque; + s->bs = bs; +} + static int vvfat_open(BlockDriverState *bs, const char* dirname, int flags) { BDRVVVFATState *s = bs->opaque; @@ -2855,6 +2861,7 @@ static BlockDriver bdrv_vvfat = { .format_name = "vvfat", .instance_size = sizeof(BDRVVVFATState), .bdrv_file_open = vvfat_open, + .bdrv_rebind = vvfat_rebind, .bdrv_read = vvfat_co_read, .bdrv_write = vvfat_co_write, .bdrv_close = vvfat_close, diff --git a/block_int.h b/block_int.h index 0e5a032..58e3eea 100644 --- a/block_int.h +++ b/block_int.h @@ -139,6 +139,7 @@ struct BlockDriver { int (*bdrv_write)(BlockDriverState *bs, int64_t sector_num, const uint8_t *buf, int nb_sectors); void (*bdrv_close)(BlockDriverState *bs); + void (*bdrv_rebind)(BlockDriverState *bs); int (*bdrv_create)(const char *filename, QEMUOptionParameter *options); int (*bdrv_set_key)(BlockDriverState *bs, const char *key); int (*bdrv_make_empty)(BlockDriverState *bs);