qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V2 2/6] libqblock type and structure defines


From: Blue Swirl
Subject: Re: [Qemu-devel] [PATCH V2 2/6] libqblock type and structure defines
Date: Tue, 11 Sep 2012 20:31:00 +0000

On Mon, Sep 10, 2012 at 8:26 AM, Wenchao Xia <address@hidden> wrote:
>   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 <address@hidden>
> ---
>  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   <address@hidden>
> + *
> + * 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   <address@hidden>
> + *
> + * 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 <sys/types.h>
> +#include <stdint.h>
> +#include <stdbool.h>
> +
> +#if __GNUC__ >= 4

#if defined(__GNUC__) && __GNUC__ ...

> +    #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;

typedefs missing

> +
> +/* 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
> --
> 1.7.1
>
>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]