From patchwork Mon Dec 18 11:09:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 10118779 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 44DA0603FA for ; Mon, 18 Dec 2017 11:14:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392E02881B for ; Mon, 18 Dec 2017 11:14:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DADF28B13; Mon, 18 Dec 2017 11:14:22 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 8752D2881B for ; Mon, 18 Dec 2017 11:14:21 +0000 (UTC) Received: from localhost ([::1]:57949 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtNE-0006yG-Hp for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Dec 2017 06:14:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57257) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eQtIR-000387-Cu for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eQtIL-0007Ya-9m for qemu-devel@nongnu.org; Mon, 18 Dec 2017 06:09:23 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:4540 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eQtIK-0007XJ-Qe; Mon, 18 Dec 2017 06:09:17 -0500 Received: from iris.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBHC7I6w013555; Sun, 17 Dec 2017 15:07:18 +0300 (MSK) From: "Denis V. Lunev" To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 18 Dec 2017 14:09:09 +0300 Message-Id: <1513595351-5899-4-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1513595351-5899-1-git-send-email-den@openvz.org> References: <1513595351-5899-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 3/5] block/parallels: move some structures into header 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: Klim Kireev , Stefan Hajnoczi , "Denis V . Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Klim Kireev To implement xml format, some defines and structures from parallels.c are required. Signed-off-by: Klim Kireev Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi --- block/parallels.h | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ block/parallels.c | 53 +---------------------------------- 2 files changed, 84 insertions(+), 52 deletions(-) create mode 100644 block/parallels.h diff --git a/block/parallels.h b/block/parallels.h new file mode 100644 index 0000000..7d0fb73 --- /dev/null +++ b/block/parallels.h @@ -0,0 +1,83 @@ +/* +* Block driver for Parallels disk image format +* +* Copyright (c) 2016-2017 Klim S. Kireev +* Copyright (c) 2015 Denis V. Lunev +* +* This code was originally based on comparing different disk images created +* by Parallels. Currently it is based on opened OpenVZ sources +* available at +* https://github.com/OpenVZ/ploop +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ +#ifndef BLOCK_PARALLELS_H +#define BLOCK_PARALLELS_H +#include "qemu/module.h" + +#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ + +/* always little-endian */ +typedef struct ParallelsHeader { + char magic[16]; /* "WithoutFreeSpace" */ + uint32_t version; + uint32_t heads; + uint32_t cylinders; + uint32_t tracks; + uint32_t bat_entries; + uint64_t nb_sectors; + uint32_t inuse; + uint32_t data_off; + char padding[12]; +} QEMU_PACKED ParallelsHeader; + +typedef enum ParallelsPreallocMode { + PRL_PREALLOC_MODE_FALLOCATE = 0, + PRL_PREALLOC_MODE_TRUNCATE = 1, + PRL_PREALLOC_MODE__MAX = 2, +} ParallelsPreallocMode; + +typedef struct BDRVParallelsState { + /** Locking is conservative, the lock protects + * - image file extending (truncate, fallocate) + * - any access to block allocation table + */ + CoMutex lock; + + ParallelsHeader *header; + uint32_t header_size; + bool header_unclean; + + unsigned long *bat_dirty_bmap; + unsigned int bat_dirty_block; + + uint32_t *bat_bitmap; + unsigned int bat_size; + + int64_t data_end; + uint64_t prealloc_size; + ParallelsPreallocMode prealloc_mode; + + unsigned int tracks; + + unsigned int off_multiplier; + Error *migration_blocker; +} BDRVParallelsState; + +#endif diff --git a/block/parallels.c b/block/parallels.c index 9545761..f9a3b99 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -36,6 +36,7 @@ #include "qemu/bswap.h" #include "qemu/bitmap.h" #include "migration/blocker.h" +#include "parallels.h" /**************************************************************/ @@ -45,30 +46,6 @@ #define HEADER_INUSE_MAGIC (0x746F6E59) #define MAX_PARALLELS_IMAGE_FACTOR (1ull << 32) -#define DEFAULT_CLUSTER_SIZE 1048576 /* 1 MiB */ - - -// always little-endian -typedef struct ParallelsHeader { - char magic[16]; // "WithoutFreeSpace" - uint32_t version; - uint32_t heads; - uint32_t cylinders; - uint32_t tracks; - uint32_t bat_entries; - uint64_t nb_sectors; - uint32_t inuse; - uint32_t data_off; - char padding[12]; -} QEMU_PACKED ParallelsHeader; - - -typedef enum ParallelsPreallocMode { - PRL_PREALLOC_MODE_FALLOCATE = 0, - PRL_PREALLOC_MODE_TRUNCATE = 1, - PRL_PREALLOC_MODE__MAX = 2, -} ParallelsPreallocMode; - static QEnumLookup prealloc_mode_lookup = { .array = (const char *const[]) { "falloc", @@ -77,34 +54,6 @@ static QEnumLookup prealloc_mode_lookup = { .size = PRL_PREALLOC_MODE__MAX }; -typedef struct BDRVParallelsState { - /** Locking is conservative, the lock protects - * - image file extending (truncate, fallocate) - * - any access to block allocation table - */ - CoMutex lock; - - ParallelsHeader *header; - uint32_t header_size; - bool header_unclean; - - unsigned long *bat_dirty_bmap; - unsigned int bat_dirty_block; - - uint32_t *bat_bitmap; - unsigned int bat_size; - - int64_t data_end; - uint64_t prealloc_size; - ParallelsPreallocMode prealloc_mode; - - unsigned int tracks; - - unsigned int off_multiplier; - Error *migration_blocker; -} BDRVParallelsState; - - #define PARALLELS_OPT_PREALLOC_MODE "prealloc-mode" #define PARALLELS_OPT_PREALLOC_SIZE "prealloc-size"