qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
To: Kevin Wolf <kwolf@redhat.com>
Cc: aliguori@us.ibm.com, stefanha@gmail.com, qemu-devel@nongnu.org,
	Blue Swirl <blauwirbel@gmail.com>,
	pbonzini@redhat.com, eblake@redhat.com
Subject: Re: [Qemu-devel] [PATCH V2 1/6] libqblock API design
Date: Wed, 12 Sep 2012 17:21:04 +0800	[thread overview]
Message-ID: <50505400.4000300@linux.vnet.ibm.com> (raw)
In-Reply-To: <505045AA.2070705@redhat.com>

于 2012-9-12 16:19, Kevin Wolf 写道:
> Am 11.09.2012 22:28, schrieb Blue Swirl:
>> On Mon, Sep 10, 2012 at 8:26 AM, Wenchao Xia <xiawenc@linux.vnet.ibm.com> wrote:
>>>    This patch contains the major APIs in the library.
>>> Important APIs:
>>>    1 QBroker. These structure was used to retrieve errors, every thread must
>>> create one first, later maybe thread related staff could be added into it.
>>>    2 QBlockState. It stands for an block image object.
>>>    3 QBlockStaticInfo. It contains static information such as location, backing
>>> file, size.
>>>    4 ABI was kept with reserved members.
>>>    5 Sync I/O. It is similar to C file open, read, write and close operations.
>>>
>>> Signed-off-by: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
>>> ---
>>>   libqblock/libqblock.c | 1077 +++++++++++++++++++++++++++++++++++++++++++++++++
>>>   libqblock/libqblock.h |  292 +++++++++++++
>>>   2 files changed, 1369 insertions(+), 0 deletions(-)
>>>   create mode 100644 libqblock/libqblock.c
>>>   create mode 100644 libqblock/libqblock.h
>>>
>>> diff --git a/libqblock/libqblock.c b/libqblock/libqblock.c
>>> new file mode 100644
>>> index 0000000..133ac0f
>>> --- /dev/null
>>> +++ b/libqblock/libqblock.c
>>> @@ -0,0 +1,1077 @@
>>> +/*
>>> + * QEMU block layer library
>>> + *
>>> + * Copyright IBM, Corp. 2012
>>> + *
>>> + * Authors:
>>> + *  Wenchao Xia   <xiawenc@linux.vnet.ibm.com>
>>> + *
>>> + * 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.
>>> + *
>>> + */
>>> +
>>> +#include <unistd.h>
>>> +#include <stdarg.h>
>>> +
>>> +#include "libqblock.h"
>>> +#include "libqblock-internal.h"
>>> +
>>> +#include "qemu-aio.h"
>>> +
>>> +struct LibqblockGlobalData {
>>> +    int init_flag;
>>> +};
>>> +
>>> +struct LibqblockGlobalData g_libqblock_data;
>>> +
>>> +__attribute__((constructor))
>>> +static void libqblock_init(void)
>>> +{
>>> +    if (g_libqblock_data.init_flag == 0) {
>>> +        bdrv_init();
>>> +        qemu_init_main_loop();
>>> +    }
>>> +    g_libqblock_data.init_flag = 1;
>>> +}
>>> +
>>> +const char *qb_fmttype2str(enum QBlockFmtType fmt_type)
>>> +{
>>> +    const char *ret = NULL;
>>> +    switch (fmt_type) {
>>> +    case QB_FMT_COW:
>>> +        ret = "cow";
>>> +        break;
>>> +    case QB_FMT_QED:
>>> +        ret = "qed";
>>> +        break;
>>> +    case QB_FMT_QCOW:
>>> +        ret = "qcow";
>>> +        break;
>>> +    case QB_FMT_QCOW2:
>>> +        ret = "qcow2";
>>> +        break;
>>> +    case QB_FMT_RAW:
>>> +        ret = "raw";
>>> +        break;
>>> +    case QB_FMT_RBD:
>>> +        ret = "rbd";
>>> +        break;
>>> +    case QB_FMT_SHEEPDOG:
>>> +        ret = "sheepdog";
>>> +        break;
>>> +    case QB_FMT_VDI:
>>> +        ret = "vdi";
>>> +        break;
>>> +    case QB_FMT_VMDK:
>>> +        ret = "vmdk";
>>> +        break;
>>> +    case QB_FMT_VPC:
>>> +        ret = "vpc";
>>> +        break;
>>> +    default:
>>> +        break;
>>> +    }
>>> +    return ret;
>>> +}
>>> +
>>> +enum QBlockFmtType qb_str2fmttype(const char *fmt_str)
>>> +{
>>> +    enum QBlockFmtType ret = QB_FMT_NONE;
>>> +    if (0 == strcmp(fmt_str, "cow")) {
>>
>> This order is not common in QEMU.
>
> How about just changing the whole thing to a table that maps
> QBlockFmtType to strings, and then both conversion functions could just
> search that table?
>
   Good idea, will go this way.

>>
>>> +        ret = QB_FMT_COW;
>>> +    } else if (0 == strcmp(fmt_str, "qed")) {
>>> +        ret = QB_FMT_QED;
>>> +    } else if (0 == strcmp(fmt_str, "qcow")) {
>>> +        ret = QB_FMT_QCOW;
>>> +    } else if (0 == strcmp(fmt_str, "qcow2")) {
>>> +        ret = QB_FMT_QCOW2;
>>> +    } else if (0 == strcmp(fmt_str, "raw")) {
>>> +        ret = QB_FMT_RAW;
>>> +    } else if (0 == strcmp(fmt_str, "rbd")) {
>>> +        ret = QB_FMT_RBD;
>>> +    } else if (0 == strcmp(fmt_str, "sheepdog")) {
>>> +        ret = QB_FMT_SHEEPDOG;
>>> +    } else if (0 == strcmp(fmt_str, "vdi")) {
>>> +        ret = QB_FMT_VDI;
>>> +    } else if (0 == strcmp(fmt_str, "vmdk")) {
>>> +        ret = QB_FMT_VMDK;
>>> +    } else if (0 == strcmp(fmt_str, "vpc")) {
>>> +        ret = QB_FMT_VPC;
>>> +    }
>>> +    return ret;
>>> +}
>
> Kevin
>


-- 
Best Regards

Wenchao Xia

  reply	other threads:[~2012-09-12  9:22 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-10  8:26 [Qemu-devel] [PATCH V2 0/6] libqblock, qemu block layer library Wenchao Xia
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 1/6] libqblock API design Wenchao Xia
2012-09-10 21:07   ` Eric Blake
2012-09-11  3:16     ` Wenchao Xia
2012-09-14  2:03       ` Wenchao Xia
2012-09-11 20:28   ` Blue Swirl
2012-09-12  2:54     ` Wenchao Xia
2012-09-12  8:19     ` Kevin Wolf
2012-09-12  9:21       ` Wenchao Xia [this message]
2012-09-14 19:08       ` Blue Swirl
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 2/6] libqblock type and structure defines Wenchao Xia
2012-09-10 21:27   ` Eric Blake
2012-09-11  3:26     ` Wenchao Xia
2012-09-11  4:12       ` Eric Blake
2012-09-11 20:31   ` Blue Swirl
2012-09-11 22:52     ` Eric Blake
2012-09-12  3:05       ` Wenchao Xia
2012-09-12 12:59         ` Eric Blake
2012-09-13  3:24           ` Wenchao Xia
2012-09-13  3:33             ` Eric Blake
2012-09-13  3:49               ` Eric Blake
2012-09-14 18:11                 ` Blue Swirl
2012-09-17  2:23                   ` Wenchao Xia
2012-09-17 19:08                     ` Blue Swirl
2012-09-14 18:02       ` Blue Swirl
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 3/6] libqblock error handling Wenchao Xia
2012-09-10 21:33   ` Eric Blake
2012-09-11  4:36     ` Wenchao Xia
2012-09-11 20:32   ` Blue Swirl
2012-09-12  2:58     ` Wenchao Xia
2012-09-14 17:09       ` Blue Swirl
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 4/6] libqblock export some qemu block function Wenchao Xia
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 5/6] libqblock building system Wenchao Xia
2012-09-10  8:26 ` [Qemu-devel] [PATCH V2 6/6] libqblock test example Wenchao Xia

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50505400.4000300@linux.vnet.ibm.com \
    --to=xiawenc@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).