From patchwork Mon Sep 10 08:26:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wayne Xia X-Patchwork-Id: 182821 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 454372C0089 for ; Mon, 10 Sep 2012 18:29:27 +1000 (EST) Received: from localhost ([::1]:47240 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzMz-0000aW-C2 for incoming@patchwork.ozlabs.org; Mon, 10 Sep 2012 04:29:25 -0400 Received: from eggs.gnu.org ([208.118.235.92]:35867) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzLz-0006yU-Eu for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:28:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TAzLs-0007tW-Gg for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:28:23 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:56520) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TAzLr-0007t9-N1 for qemu-devel@nongnu.org; Mon, 10 Sep 2012 04:28:16 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 10 Sep 2012 18:26:49 +1000 Received: from d23relay04.au.ibm.com (202.81.31.246) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 10 Sep 2012 18:26:14 +1000 Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay04.au.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q8A8IWPp19398726 for ; Mon, 10 Sep 2012 18:18:32 +1000 Received: from d23av03.au.ibm.com (loopback [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q8A8Raq7027131 for ; Mon, 10 Sep 2012 18:27:37 +1000 Received: from RedHat62GAWSWenchao (wenchaox.cn.ibm.com [9.115.122.115]) by d23av03.au.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q8A8QiXN025911; Mon, 10 Sep 2012 18:27:35 +1000 From: Wenchao Xia To: qemu-devel@nongnu.org Date: Mon, 10 Sep 2012 16:26:22 +0800 Message-Id: <1347265586-17698-3-git-send-email-xiawenc@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1347265586-17698-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1347265586-17698-1-git-send-email-xiawenc@linux.vnet.ibm.com> x-cbid: 12091008-1618-0000-0000-000002724A40 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 202.81.31.143 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@gmail.com, blauwirbel@gmail.com, pbonzini@redhat.com, eblake@redhat.com, Wenchao Xia Subject: [Qemu-devel] [PATCH V2 2/6] libqblock type and structure defines 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 This patch contains type and defines used in APIs, one file for public usage by user, one for libqblock internal usage. Signed-off-by: Wenchao Xia --- libqblock/libqblock-internal.h | 50 ++++++++ libqblock/libqblock-types.h | 251 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 301 insertions(+), 0 deletions(-) create mode 100644 libqblock/libqblock-internal.h create mode 100644 libqblock/libqblock-types.h diff --git a/libqblock/libqblock-internal.h b/libqblock/libqblock-internal.h new file mode 100644 index 0000000..fa27ed4 --- /dev/null +++ b/libqblock/libqblock-internal.h @@ -0,0 +1,50 @@ +/* + * QEMU block layer library + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Wenchao Xia + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef LIBQBLOCK_INTERNAL +#define LIBQBLOCK_INTERNAL + +#include "block.h" +#include "block_int.h" + +#include "libqblock-types.h" + +/* this file contains defines and types used inside the library. */ + +#define FUNC_FREE free +#define FUNC_MALLOC malloc +#define FUNC_CALLOC calloc + +#define CLEAN_FREE(p) { \ + FUNC_FREE(p); \ + (p) = NULL; \ +} + +/* details should be hidden to user */ +struct QBlockState { + BlockDriverState *bdrvs; + /* internal used file name now, if it is not NULL, it means + image was opened. + */ + char *filename; +}; + +#define QB_ERR_STRING_SIZE (1024) +struct QBroker { + /* last error */ + char err_msg[QB_ERR_STRING_SIZE]; + int err_ret; /* last error return of libqblock. */ + int err_no; /* 2nd level of error, errno what below reports */ +}; + +#endif diff --git a/libqblock/libqblock-types.h b/libqblock/libqblock-types.h new file mode 100644 index 0000000..9d4e3fc --- /dev/null +++ b/libqblock/libqblock-types.h @@ -0,0 +1,251 @@ +/* + * QEMU block layer library + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Wenchao Xia + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef LIBQBLOCK_TYPES_H +#define LIBQBLOCK_TYPES_H + +#include +#include +#include + +#if __GNUC__ >= 4 + #ifdef LIBQB_BUILD + #define DLL_PUBLIC __attribute__((visibility("default"))) + #else + #define DLL_PUBLIC + #endif +#endif + +/* this library is designed around this core struct. */ +struct QBlockState; + +/* every thread would have a broker. */ +struct QBroker; + +/* flag used in open and create */ +#define LIBQBLOCK_O_RDWR 0x0002 +/* do not use the host page cache */ +#define LIBQBLOCK_O_NOCACHE 0x0020 +/* use write-back caching */ +#define LIBQBLOCK_O_CACHE_WB 0x0040 +/* don't open the backing file */ +#define LIBQBLOCK_O_NO_BACKING 0x0100 +/* disable flushing on this disk */ +#define LIBQBLOCK_O_NO_FLUSH 0x0200 + +#define LIBQBLOCK_O_CACHE_MASK \ + (LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | LIBQBLOCK_O_NO_FLUSH) + +#define LIBQBLOCK_O_VALID_MASK \ + (LIBQBLOCK_O_RDWR | LIBQBLOCK_O_NOCACHE | LIBQBLOCK_O_CACHE_WB | \ + LIBQBLOCK_O_NO_BACKING | LIBQBLOCK_O_NO_FLUSH) + +enum QBlockProtType { + QB_PROT_NONE = 0, + QB_PROT_FILE, + QB_PROT_MAX +}; + +struct QBlockProtOptionFile { + const char *filename; +}; + +#define QBLOCK_PROT_OPTIONS_UNION_SIZE (512) +union QBlockProtOptionsUnion { + struct QBlockProtOptionFile o_file; + uint8_t reserved[QBLOCK_PROT_OPTIONS_UNION_SIZE]; +}; + +/** + * struct QBlockProtInfo: contains information about how to find the image + * + * @prot_type: protocol type, now only support FILE. + * @prot_op: protocol related options. + */ +struct QBlockProtInfo { + enum QBlockProtType prot_type; + union QBlockProtOptionsUnion prot_op; +}; + + +/* format related options */ +enum QBlockFmtType { + QB_FMT_NONE = 0, + QB_FMT_COW, + QB_FMT_QED, + QB_FMT_QCOW, + QB_FMT_QCOW2, + QB_FMT_RAW, + QB_FMT_RBD, + QB_FMT_SHEEPDOG, + QB_FMT_VDI, + QB_FMT_VMDK, + QB_FMT_VPC, + QB_FMT_MAX +}; + +struct QBlockFmtOptionCow { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; +}; + +struct QBlockFmtOptionQed { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; + enum QBlockFmtType backing_fmt; + uint64_t cluster_size; /* unit is bytes */ + uint64_t table_size; /* unit is clusters */ +}; + +struct QBlockFmtOptionQcow { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; + bool encrypt; +}; + +/* "Compatibility level (0.10 or 1.1)" */ +enum QBlockFmtOptionQcow2CptLv { + QBO_FMT_QCOW2_CPT_NONE = 0, + QBO_FMT_QCOW2_CPT_V010, + QBO_FMT_QCOW2_CPT_V110, +}; + +/* off or metadata */ +enum QBlockFmtOptionQcow2PreAllocType { + QBO_FMT_QCOW2_PREALLOC_NONE = 0, + QBO_FMT_QCOW2_PREALLOC_OFF, + QBO_FMT_QCOW2_PREALLOC_METADATA, +}; + +struct QBlockFmtOptionQcow2 { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; + enum QBlockFmtType backing_fmt; + bool encrypt; + uint64_t cluster_size; /* unit is bytes */ + enum QBlockFmtOptionQcow2CptLv cpt_lv; + enum QBlockFmtOptionQcow2PreAllocType pre_mode; +}; + +struct QBlockFmtOptionRaw { + uint64_t virt_size; +}; + +struct QBlockFmtOptionRbd { + uint64_t virt_size; + uint64_t cluster_size; +}; + +/* off or full */ +enum QBlockFmtOptionSheepdogPreAllocType { + QBO_FMT_SD_PREALLOC_NONE = 0, + QBO_FMT_SD_PREALLOC_OFF, + QBO_FMT_SD_PREALLOC_FULL, +}; + +struct QBlockFmtOptionSheepdog { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; + enum QBlockFmtOptionSheepdogPreAllocType pre_mode; +}; + +enum QBlockFmtOptionVdiPreAllocType { + QBO_FMT_VDI_PREALLOC_NONE = 0, + QBO_FMT_VDI_PREALLOC_FALSE, + QBO_FMT_VDI_PREALLOC_TRUE, +}; + +struct QBlockFmtOptionVdi { + uint64_t virt_size; + uint64_t cluster_size; + enum QBlockFmtOptionVdiPreAllocType pre_mode; +}; + +/* whether compact to vmdk verion 6 */ +enum QBlockFmtOptionVmdkCptLv { + QBO_FMT_VMDK_CPT_NONE = 0, + QBO_FMT_VMDK_CPT_VMDKV6_FALSE, + QBO_FMT_VMDK_CPT_VMDKV6_TRUE, +}; + +/* vmdk flat extent format, values: +"{monolithicSparse (default) | monolithicFlat | twoGbMaxExtentSparse | +twoGbMaxExtentFlat | streamOptimized} */ +enum QBlockFmtOptionVmdkSubfmtType { + QBO_FMT_VMDK_SUBFMT_MONOLITHIC_NONE = 0, + QBO_FMT_VMDK_SUBFMT_MONOLITHIC_SPARSE, + QBO_FMT_VMDK_SUBFMT_MONOLITHIC_FLAT, + QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_SPARSE, + QBO_FMT_VMDK_SUBFMT_TWOGBMAX_EXTENT_FLAT, + QBO_FMT_VMDK_SUBFMT_STREAM_OPTIMIZED, +}; + +struct QBlockFmtOptionVmdk { + uint64_t virt_size; + struct QBlockProtInfo backing_loc; + enum QBlockFmtOptionVmdkCptLv cpt_lv; + enum QBlockFmtOptionVmdkSubfmtType subfmt; +}; + +/* "{dynamic (default) | fixed} " */ +enum QBlockFmtOptionVpcSubfmtType { + QBO_FMT_VPC_SUBFMT_NONE = 0, + QBO_FMT_VPC_SUBFMT_DYNAMIC, + QBO_FMT_VPC_SUBFMT_FIXED, +}; + +struct QBlockFmtOptionVpc { + uint64_t virt_size; + enum QBlockFmtOptionVpcSubfmtType subfmt; +}; + +#define QBLOCK_FMT_OPTIONS_UNION_SIZE (QBLOCK_PROT_OPTIONS_UNION_SIZE*2) +union QBlockFmtOptionsUnion { + struct QBlockFmtOptionCow o_cow; + struct QBlockFmtOptionQed o_qed; + struct QBlockFmtOptionQcow o_qcow; + struct QBlockFmtOptionQcow2 o_qcow2; + struct QBlockFmtOptionRaw o_raw; + struct QBlockFmtOptionRbd o_rbd; + struct QBlockFmtOptionSheepdog o_sheepdog; + struct QBlockFmtOptionVdi o_vdi; + struct QBlockFmtOptionVmdk o_vmdk; + struct QBlockFmtOptionVpc o_vpc; + uint8_t reserved[QBLOCK_FMT_OPTIONS_UNION_SIZE]; +}; + +struct QBlockFmtInfo { + enum QBlockFmtType fmt_type; + union QBlockFmtOptionsUnion fmt_op; +}; + +/** + * QBlockStaticInfo: information about the block image. + * + * @loc: location info. + * @fmt_type: format type. + * @virt_size: virtual size in bytes. + * @backing_loc: backing file location, its type is QB_PROT_NONE if not exist. + * @encrypt: encrypt flag. + * @sector_size: how many bytes in a sector, it is 512 usually. + */ +struct QBlockStaticInfo { + struct QBlockProtInfo loc; + enum QBlockFmtType fmt_type; + uint64_t virt_size; + /* advance info */ + struct QBlockProtInfo backing_loc; + bool encrypt; + int sector_size; +}; +#endif