From patchwork Wed Aug 1 18:36:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Supriya Kannery X-Patchwork-Id: 174570 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 08BC92C0086 for ; Thu, 2 Aug 2012 04:37:33 +1000 (EST) Received: from localhost ([::1]:53102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwdnX-00062d-4w for incoming@patchwork.ozlabs.org; Wed, 01 Aug 2012 14:37:31 -0400 Received: from eggs.gnu.org ([208.118.235.92]:32797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwdnP-00061b-N7 for qemu-devel@nongnu.org; Wed, 01 Aug 2012 14:37:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SwdnN-0007w7-Px for qemu-devel@nongnu.org; Wed, 01 Aug 2012 14:37:23 -0400 Received: from e28smtp08.in.ibm.com ([122.248.162.8]:44118) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SwdnM-0007vS-UM for qemu-devel@nongnu.org; Wed, 01 Aug 2012 14:37:21 -0400 Received: from /spool/local by e28smtp08.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Aug 2012 00:07:14 +0530 Received: from d28relay03.in.ibm.com (9.184.220.60) by e28smtp08.in.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 2 Aug 2012 00:07:01 +0530 Received: from d28av01.in.ibm.com (d28av01.in.ibm.com [9.184.220.63]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q71Ib0Pt24772740 for ; Thu, 2 Aug 2012 00:07:00 +0530 Received: from d28av01.in.ibm.com (loopback [127.0.0.1]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7206XNa008355 for ; Thu, 2 Aug 2012 05:36:34 +0530 Received: from skannery.in.ibm.com ([9.79.203.91]) by d28av01.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q7206Xn5008315; Thu, 2 Aug 2012 05:36:33 +0530 Message-ID: <5019774A.1010406@linux.vnet.ibm.com> Date: Thu, 02 Aug 2012 00:06:58 +0530 From: Supriya Kannery User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.20) Gecko/20110817 Fedora/3.1.12-1.fc14 Thunderbird/3.1.12 MIME-Version: 1.0 To: qemu-devel@nongnu.org References: <20120730213409.21536.7589.sendpatchset@skannery.in.ibm.com> In-Reply-To: <20120730213409.21536.7589.sendpatchset@skannery.in.ibm.com> x-cbid: 12080118-2000-0000-0000-000008911F19 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 122.248.162.8 Cc: Kevin Wolf , Shrinidhi Joshi , Stefan Hajnoczi , Jeff Cody , Luiz Capitulino , Christoph Hellwig Subject: Re: [Qemu-devel] [v2 Patch 6/9]block: qcow image file reopen X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: supriyak@linux.vnet.ibm.com 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 qcow driver changes for bdrv_reopen_xx functions to safely reopen image files. Reopening of image files while changing hostcache dynamically is handled here. Signed-off-by: Shrinidhi Joshi Index: qemu/block/qcow.c =================================================================== --- qemu.orig/block/qcow.c +++ qemu/block/qcow.c @@ -78,7 +78,14 @@ typedef struct BDRVQcowState { Error *migration_blocker; } BDRVQcowState; +typedef struct BDRVQcowReopenState { + BDRVReopenState reopen_state; + BDRVQcowState *stash_s; +} BDRVQcowReopenState; + static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); +static void qcow_stash_state(BDRVQcowState *stash_s, BDRVQcowState *s); +static void qcow_revert_state(BDRVQcowState *s, BDRVQcowState *stash_s); static int qcow_probe(const uint8_t *buf, int buf_size, const char *filename) { @@ -197,6 +204,103 @@ static int qcow_open(BlockDriverState *b return ret; } +static int qcow_reopen_prepare(BlockDriverState *bs, BDRVReopenState **prs, + int flags) +{ + BDRVQcowReopenState *qcow_rs = g_malloc0(sizeof(BDRVQcowReopenState)); + int ret = 0; + BDRVQcowState *s = bs->opaque; + + qcow_rs->reopen_state.bs = bs; + qcow_rs->stash_s = g_malloc0(sizeof(BDRVQcowState)); + qcow_stash_state(qcow_rs->stash_s, s); + *prs = &(qcow_rs->reopen_state); + + ret = qcow_open(bs, flags); + return ret; +} + +static void qcow_reopen_commit(BlockDriverState *bs, BDRVReopenState *rs) +{ + BDRVQcowReopenState *qcow_rs; + + qcow_rs = container_of(rs, BDRVQcowReopenState, reopen_state); + g_free(qcow_rs->stash_s); + g_free(qcow_rs); +} + +static void qcow_reopen_abort(BlockDriverState *bs, BDRVReopenState *rs) +{ + BDRVQcowReopenState *qcow_rs; + BDRVQcowState *s = bs->opaque; + + qcow_rs = container_of(rs, BDRVQcowReopenState, reopen_state); + + /* revert to stashed state */ + qcow_revert_state(s, qcow_rs->stash_s); + + g_free(qcow_rs->stash_s); + g_free(qcow_rs); +} + +static void qcow_stash_state(BDRVQcowState *stash_s, BDRVQcowState *s) +{ + int i; + + stash_s->cluster_bits = s->cluster_bits; + stash_s->cluster_size = s->cluster_size; + stash_s->cluster_sectors = s->cluster_sectors; + stash_s->l2_bits = s->l2_bits; + stash_s->l2_size = s->l2_size; + stash_s->l1_size = s->l1_size; + stash_s->cluster_offset_mask = s->cluster_offset_mask; + stash_s->l1_table_offset = s->l1_table_offset; + stash_s->l1_table = s->l1_table; + stash_s->l2_cache = s->l2_cache; + for (i = 0; i < L2_CACHE_SIZE; i++) { + stash_s->l2_cache_offsets[i] = s->l2_cache_offsets[i]; + stash_s->l2_cache_counts[i] = s->l2_cache_counts[i]; + } + stash_s->cluster_cache = s->cluster_cache; + stash_s->cluster_data = s->cluster_data; + stash_s->cluster_cache_offset = s->cluster_cache_offset; + stash_s->crypt_method = s->crypt_method; + stash_s->crypt_method_header = s->crypt_method_header; + stash_s->aes_encrypt_key = s->aes_encrypt_key; + stash_s->aes_decrypt_key = s->aes_decrypt_key; + stash_s->lock = s->lock; + stash_s->migration_blocker = s->migration_blocker; +} + +static void qcow_revert_state(BDRVQcowState *s, BDRVQcowState *stash_s) +{ + int i; + + s->cluster_bits = stash_s->cluster_bits; + s->cluster_size = stash_s->cluster_size; + s->cluster_sectors = stash_s->cluster_sectors; + s->l2_bits = stash_s->l2_bits; + s->l2_size = stash_s->l2_size; + s->l1_size = stash_s->l1_size; + s->cluster_offset_mask = stash_s->cluster_offset_mask; + s->l1_table_offset = stash_s->l1_table_offset; + s->l1_table = stash_s->l1_table; + s->l2_cache = stash_s->l2_cache; + for (i = 0; i < L2_CACHE_SIZE; i++) { + s->l2_cache_offsets[i] = s->l2_cache_offsets[i]; + s->l2_cache_counts[i] = stash_s->l2_cache_counts[i]; + } + s->cluster_cache = stash_s->cluster_cache; + s->cluster_data = stash_s->cluster_data; + s->cluster_cache_offset = stash_s->cluster_cache_offset; + s->crypt_method = stash_s->crypt_method; + s->crypt_method_header = stash_s->crypt_method_header; + s->aes_encrypt_key = stash_s->aes_encrypt_key; + s->aes_decrypt_key = stash_s->aes_decrypt_key; + s->lock = stash_s->lock; + s->migration_blocker = stash_s->migration_blocker; +} + static int qcow_set_key(BlockDriverState *bs, const char *key) { BDRVQcowState *s = bs->opaque; @@ -870,6 +974,10 @@ static BlockDriver bdrv_qcow = { .bdrv_close = qcow_close, .bdrv_create = qcow_create, + .bdrv_reopen_prepare = qcow_reopen_prepare, + .bdrv_reopen_commit = qcow_reopen_commit, + .bdrv_reopen_abort = qcow_reopen_abort, + .bdrv_co_readv = qcow_co_readv, .bdrv_co_writev = qcow_co_writev, .bdrv_co_is_allocated = qcow_co_is_allocated,