From patchwork Sat Mar 11 11:54:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashijeet Acharya X-Patchwork-Id: 9618583 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A8F10604A9 for ; Sat, 11 Mar 2017 11:55:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96D452878E for ; Sat, 11 Mar 2017 11:55:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 881E8287B8; Sat, 11 Mar 2017 11:55:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA5F42878E for ; Sat, 11 Mar 2017 11:55:55 +0000 (UTC) Received: from localhost ([::1]:42940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmfcp-0005fk-0g for patchwork-qemu-devel@patchwork.kernel.org; Sat, 11 Mar 2017 06:55:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41342) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmfaz-0004ZF-Ng for qemu-devel@nongnu.org; Sat, 11 Mar 2017 06:54:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmfay-00080A-KY for qemu-devel@nongnu.org; Sat, 11 Mar 2017 06:54:01 -0500 Received: from mail-pg0-x243.google.com ([2607:f8b0:400e:c05::243]:35539) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmfay-000801-Co; Sat, 11 Mar 2017 06:54:00 -0500 Received: by mail-pg0-x243.google.com with SMTP id g2so8570376pge.2; Sat, 11 Mar 2017 03:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1gkADd7mtL+YKD28WdKWVXAUoBx9jK2MJSPSlth7y3s=; b=PjWxuhRhGbemGvlefSeQitgsIpFNQzZR7fa//fU/KSVLORMQNDRmIjzpwqzrn7OrQT dtrxgLNBSOjaGGHC77XabtlugSRdxgC/TioDhkiPRC1xvr3KxlxcAucOhCelSskU6Hce 0Y4HsPbQSpnaR2GAxM8UpPfayEEogAmMBfHGIn4rRCYm2iFHMYwUWwsRm80Dg2O+n2nQ ETrEeLIWf6EypBZcaDoZAeV3z5M10xYBZYYxI9/MsOmCL6l8+h1GE5aK2pRY7bxFexOO NXuxAqJXa9dUqq+/dxnicUkNAHUK9mQdTPHLc9/IplJ5OGYCGWOhVupwmXzSMtoePXtt iMVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1gkADd7mtL+YKD28WdKWVXAUoBx9jK2MJSPSlth7y3s=; b=UPDqprHEyE/+fmymslUmLmVH3zS1P/QkAGRZiGWR4h/ThDD/amwZ4v0UrisxRd9Iym Q2OXPlMlqZC7TA2aPjpbLvIq2T2WKPlLw3eDI7BxTNOEk79GlmQgTRmRS7cvgSHWZ/6B hQvUP9623EnVMCSxRGX90L3qC2AW2XrtUnzJUo0eo6mYfK8Br+KlyiO6304VVXOhgZK5 94WtE+c/mNU1GukMDN9xNizqDRbYJP9FctIOY/kLtrtZi2BhAqxK4rY005mh6s2GVpTv LYDbNv8CpJI9uaND66OA+PzeHCUQR9HTPEBk5Wub/aQGg5W9v8/tjoYDblEFYomrZQQI ljtA== X-Gm-Message-State: AMke39ku9mRoZagbUhZyqnu4ZqirHcaDfkk7KokZ++Nn+4UMv0GD1nC7FvakHekWGwMQGA== X-Received: by 10.84.216.81 with SMTP id f17mr32744268plj.170.1489233239413; Sat, 11 Mar 2017 03:53:59 -0800 (PST) Received: from linux.local ([47.247.6.223]) by smtp.gmail.com with ESMTPSA id s21sm24015676pgg.65.2017.03.11.03.53.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Mar 2017 03:53:58 -0800 (PST) From: Ashijeet Acharya To: famz@redhat.com Date: Sat, 11 Mar 2017 17:24:05 +0530 Message-Id: <1489233245-27057-3-git-send-email-ashijeetacharya@gmail.com> X-Mailer: git-send-email 2.6.2 In-Reply-To: <1489233245-27057-1-git-send-email-ashijeetacharya@gmail.com> References: <1489233245-27057-1-git-send-email-ashijeetacharya@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c05::243 Subject: [Qemu-devel] [PATCH 2/2] vmdk: Update metadata for multiple clusters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, mreitz@redhat.com, Ashijeet Acharya , jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Include a next pointer in VmdkMetaData struct to point to the previous allocated L2 table. Modify vmdk_L2update to start updating metadata for allocation of multiple clusters at once. Signed-off-by: Ashijeet Acharya --- block/vmdk.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 102 insertions(+), 29 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 3dc178b..62ea46f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -137,6 +137,8 @@ typedef struct VmdkMetaData { int valid; uint32_t *l2_cache_entry; uint32_t nb_clusters; + uint32_t offset; + struct VmdkMetaData *next; } VmdkMetaData; typedef struct VmdkGrainMarker { @@ -1037,29 +1039,81 @@ static void vmdk_refresh_limits(BlockDriverState *bs, Error **errp) } } -static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, - uint32_t offset) +static int vmdk_alloc_cluster_link_l2(VmdkExtent *extent, + VmdkMetaData *m_data, bool zeroed) { - offset = cpu_to_le32(offset); + int i; + uint32_t offset, temp_offset; + + if (zeroed) { + temp_offset = VMDK_GTE_ZEROED; + } else { + temp_offset = m_data->offset; + } + + temp_offset = cpu_to_le32(temp_offset); + /* update L2 table */ - if (bdrv_pwrite_sync(extent->file, + offset = temp_offset; + for (i = 0; i < m_data->nb_clusters; i++) { + if (bdrv_pwrite_sync(extent->file, ((int64_t)m_data->l2_offset * 512) - + (m_data->l2_index * sizeof(offset)), - &offset, sizeof(offset)) < 0) { - return VMDK_ERROR; + + ((m_data->l2_index + i) * sizeof(offset)), + &(offset), sizeof(offset)) < 0) { + return VMDK_ERROR; + } + if (!zeroed) { + offset += 128; + } } + /* update backup L2 table */ + offset = temp_offset; if (extent->l1_backup_table_offset != 0) { m_data->l2_offset = extent->l1_backup_table[m_data->l1_index]; - if (bdrv_pwrite_sync(extent->file, - ((int64_t)m_data->l2_offset * 512) - + (m_data->l2_index * sizeof(offset)), - &offset, sizeof(offset)) < 0) { - return VMDK_ERROR; + for (i = 0; i < m_data->nb_clusters; i++) { + if (bdrv_pwrite_sync(extent->file, + ((int64_t)m_data->l2_offset * 512) + + ((m_data->l2_index + i) * sizeof(offset)), + &(offset), sizeof(offset)) < 0) { + return VMDK_ERROR; + } + if (!zeroed) { + offset += 128; + } } } + + offset = temp_offset; if (m_data->l2_cache_entry) { - *m_data->l2_cache_entry = offset; + for (i = 0; i < m_data->nb_clusters; i++) { + *m_data->l2_cache_entry = offset; + m_data->l2_cache_entry++; + + if (!zeroed) { + offset += 128; + } + } + } + + return VMDK_OK; +} + +static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, + bool zeroed) +{ + int ret; + + while (m_data->next != NULL) { + VmdkMetaData *next; + + ret = vmdk_alloc_cluster_link_l2(extent, m_data, zeroed); + if (ret < 0) { + return ret; + } + + next = m_data->next; + m_data = next; } return VMDK_OK; @@ -1271,7 +1325,7 @@ exit: */ static int handle_alloc(BlockDriverState *bs, VmdkExtent *extent, uint64_t offset, uint64_t *cluster_offset, - int64_t *bytes, VmdkMetaData *m_data, + int64_t *bytes, VmdkMetaData **m_data, bool allocate, uint32_t *total_alloc_clusters) { int l1_index, l2_offset, l2_index; @@ -1280,6 +1334,7 @@ static int handle_alloc(BlockDriverState *bs, VmdkExtent *extent, uint32_t nb_clusters; bool zeroed = false; uint64_t skip_start_bytes, skip_end_bytes; + VmdkMetaData *old_m_data; int ret; ret = get_cluster_table(extent, offset, &l1_index, &l2_offset, @@ -1331,13 +1386,21 @@ static int handle_alloc(BlockDriverState *bs, VmdkExtent *extent, if (ret < 0) { return ret; } - if (m_data) { - m_data->valid = 1; - m_data->l1_index = l1_index; - m_data->l2_index = l2_index; - m_data->l2_offset = l2_offset; - m_data->l2_cache_entry = &l2_table[l2_index]; - m_data->nb_clusters = nb_clusters; + + if (*m_data) { + old_m_data = *m_data; + *m_data = g_malloc0(sizeof(**m_data)); + + **m_data = (VmdkMetaData) { + .valid = 1, + .l1_index = l1_index, + .l2_index = l2_index, + .l2_offset = l2_offset, + .l2_cache_entry = &l2_table[l2_index], + .nb_clusters = nb_clusters, + .offset = cluster_sector, + .next = old_m_data, + }; } } *cluster_offset = cluster_sector << BDRV_SECTOR_BITS; @@ -1366,7 +1429,7 @@ static int handle_alloc(BlockDriverState *bs, VmdkExtent *extent, */ static int vmdk_alloc_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, - VmdkMetaData *m_data, uint64_t offset, + VmdkMetaData **m_data, uint64_t offset, bool allocate, uint64_t *cluster_offset, int64_t bytes, uint32_t *total_alloc_clusters) @@ -1386,8 +1449,8 @@ static int vmdk_alloc_cluster_offset(BlockDriverState *bs, new_cluster_offset = 0; *cluster_offset = 0; n_bytes = 0; - if (m_data) { - m_data->valid = 0; + if (*m_data) { + (*m_data)->valid = 0; } /* due to L2 table margins all bytes may not get allocated at once */ @@ -1769,9 +1832,11 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t cluster_offset; uint64_t bytes_done = 0; uint64_t extent_size; - VmdkMetaData m_data; + VmdkMetaData *m_data; uint32_t total_alloc_clusters = 0; + m_data = g_malloc0(sizeof(*m_data)); + if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=0x%" PRIx64 " total_sectors=0x%" PRIx64, @@ -1780,6 +1845,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, } while (bytes > 0) { + m_data->next = NULL; extent = find_extent(s, offset >> BDRV_SECTOR_BITS, extent); if (!extent) { return -EIO; @@ -1826,7 +1892,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, total_alloc_clusters; if (!zero_dry_run) { /* update L2 tables */ - if (vmdk_L2update(extent, &m_data, VMDK_GTE_ZEROED) + if (vmdk_L2update(extent, m_data, zeroed) != VMDK_OK) { return -EIO; } @@ -1840,10 +1906,9 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, if (ret) { return ret; } - if (m_data.valid) { + if (m_data->valid) { /* update L2 tables */ - if (vmdk_L2update(extent, &m_data, - cluster_offset >> BDRV_SECTOR_BITS) + if (vmdk_L2update(extent, m_data, zeroed) != VMDK_OK) { return -EIO; } @@ -1853,6 +1918,13 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, offset += n_bytes; bytes_done += n_bytes; + while (m_data->next != NULL) { + VmdkMetaData *next; + next = m_data->next; + g_free(m_data); + m_data = next; + } + /* update CID on the first write every time the virtual disk is * opened */ if (!s->cid_updated) { @@ -1863,6 +1935,7 @@ static int vmdk_pwritev(BlockDriverState *bs, uint64_t offset, s->cid_updated = true; } } + g_free(m_data); return 0; }