qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Wenchao Xia <xiawenc@linux.vnet.ibm.com>
Cc: kwolf@redhat.com, peter.maydell@linaro.org, aliguori@us.ibm.com,
	stefanha@gmail.com, qemu-devel@nongnu.org, blauwirbel@gmail.com,
	kraxel@redhat.com
Subject: Re: [Qemu-devel] [PATCH V10 6/7] libqblock API
Date: Tue, 20 Nov 2012 11:41:37 +0100	[thread overview]
Message-ID: <50AB5E61.9060303@redhat.com> (raw)
In-Reply-To: <1353404767-4495-7-git-send-email-xiawenc@linux.vnet.ibm.com>

Il 20/11/2012 10:46, Wenchao Xia ha scritto:
> diff --git a/libqblock/libqblock.h b/libqblock/libqblock.h
> index e69de29..8ca7d28 100644
> --- a/libqblock/libqblock.h
> +++ b/libqblock/libqblock.h

Please move the creation of this file to the previous patch.

I dislike QBlockState and would prefer something like QBlockImage...

Also, it would be nicer to use reference counting for QBlockImage,
rather than just a new/delete pair.

There are some spelling mistakes (openned->opened).

But overall we're converging, it's good work that you've done.  Thanks
for persisting!

> 
> +    byte_offset = offset & (~BDRV_SECTOR_MASK);
> +    if (byte_offset != 0) {
> +        /* the start sector is not alligned, need to read/write this sector. */
> +        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
> +        if (bd_ret < 0) {
> +            set_context_err(context, QB_ERR_INTERNAL_ERR,
> +                           "QEMU internal block error.");

These are I/O errors, not internal errors.

> 
> +    if (length > 0x1000000000000) {

What is this magic number?  I think, just remove the check.

> +        set_context_err(context, QB_ERR_INVALID_PARAM,
> +                       "length is too big.");
> +        goto out;
> +    }

...

> +            context->err_no = bd_ret;
> +            return context->err_ret;
> +        }
> +        cp_len = BDRV_SECTOR_SIZE - byte_offset;
> +        memcpy(p, temp_buf + byte_offset, cp_len);
> +
> +        remains -= cp_len;
> +        p += cp_len;
> +        sector_start++;
> +    }
> +
> +    /* now start position is alligned. */
> +    if (remains >= BDRV_SECTOR_SIZE) {
> +        sector_num = remains >> BDRV_SECTOR_BITS;
> +        bd_ret = bdrv_read(bs, sector_start, p, sector_num);
> +        if (bd_ret < 0) {
> +            set_context_err(context, QB_ERR_INTERNAL_ERR,
> +                           "QEMU internal block error.");
> +            context->err_no = bd_ret;
> +            return context->err_ret;
> +        }
> +        remains -= sector_num << BDRV_SECTOR_BITS;
> +        p += sector_num << BDRV_SECTOR_BITS;
> +        sector_start += sector_num;
> +    }
> +
> +    if (remains > 0) {
> +        /* there is some request remains, less than 1 sector */
> +        bd_ret = bdrv_read(bs, sector_start, temp_buf, 1);
> +        if (bd_ret < 0) {
> +            set_context_err(context, QB_ERR_INTERNAL_ERR,
> +                           "QEMU internal block error.");
> +            context->err_no = bd_ret;
> +            return context->err_ret;
> +        }
> +        memcpy(p, temp_buf, remains);
> +        remains -= remains;
> +    }
> +



> +int qb_info_image_static_get(QBlockContext *context,
> +                             QBlockState *qbs,
> +                             QBlockStaticInfo **info)
> +{
> +    int ret = 0;
> +    BlockDriverState *bs;
> +    QBlockStaticInfo *info_tmp;
> +    QBlockStaticInfoAddr *member_addr, addr;
> +    const char *fmt_str;
> +    uint64_t total_sectors;
> +    char backing_filename[LIBQB_FILENAME_MAX];
> +
> +    if (qbs->filename == NULL) {
> +        set_context_err(context, QB_ERR_INVALID_PARAM,
> +                       "Block Image was not openned.");
> +        ret = context->err_ret;
> +        goto out;
> +    }
> +
> +    info_tmp = FUNC_CALLOC(1, sizeof(QBlockStaticInfo));

Please rename info to p_info and info_tmp to info.

> +    bs = qbs->bdrvs;
> +
> +    ret = filename2loc(context,
> +                       &(info_tmp->loc),

Useless parentheses around & argument.  This is very common, please
remove them.

> +                       qbs->filename);
> +    if (ret < 0) {
> +        goto free;
> +    }
> +
> +    fmt_str = bdrv_get_format_name(bs);
> +    info_tmp->fmt.fmt_type = qb_str2fmttype(fmt_str);
> +    /* we got the format type and basic location info now, setup the struct
> +    pointer to the internal members */
> +    memset(&addr, 0, sizeof(QBlockStaticInfoAddr));

Please move these memsets to qb_setup_info_addr.

> +    member_addr = &addr;
> +    qb_setup_info_addr(info_tmp, member_addr);

Just use qb_setup_info_addr(info_tmp, &addr).

> +
> +    assert(member_addr->virt_size != NULL);
> +    bdrv_get_geometry(bs, &total_sectors);
> +    *(member_addr->virt_size) = total_sectors * BDRV_SECTOR_SIZE;

virt_size is always valid, please move it out of the unions and in the
main struct.

> +    if (member_addr->encrypt != NULL) {
> +        *(member_addr->encrypt) = bdrv_is_encrypted(bs);
> +    }
> +    bdrv_get_full_backing_filename(bs, backing_filename,
> +                                   sizeof(backing_filename));
> +    if (backing_filename[0] != '\0') {
> +        assert(member_addr->backing_loc != NULL);
> +        ret = filename2loc(context,
> +                           member_addr->backing_loc,
> +                           backing_filename);
> +        if (ret < 0) {
> +            goto free;
> +        }
> +    }
> +
> +    info_tmp->sector_size = BDRV_SECTOR_SIZE;
> +    *info = info_tmp;
> +
> + out:
> +    return ret;
> + free:
> +    qb_info_image_static_delete(context, &info_tmp);
> +    return ret;
> +}

  reply	other threads:[~2012-11-20 10:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-20  9:46 [Qemu-devel] [PATCH V10 0/7] libqblock qemu block layer library Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 1/7] Buildsystem fix distclean error for pixman Wenchao Xia
2012-11-21 22:54   ` Peter Maydell
2012-11-22  1:50     ` Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 2/7] Buildsystem clean tests directory clearly Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 3/7] block export function path_has_protocol Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 4/7] libqblock build system Wenchao Xia
2012-11-20 10:26   ` Paolo Bonzini
2012-11-21  3:03     ` Wenchao Xia
2012-11-21  7:56       ` Paolo Bonzini
2012-11-22  1:47         ` Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 5/7] libqblock type defines Wenchao Xia
2012-11-20 10:30   ` Paolo Bonzini
2012-11-21  3:12     ` Wenchao Xia
2012-11-21  8:05       ` Paolo Bonzini
2012-11-22  1:50         ` Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 6/7] libqblock API Wenchao Xia
2012-11-20 10:41   ` Paolo Bonzini [this message]
2012-11-21  3:40     ` Wenchao Xia
2012-11-21  8:04       ` Paolo Bonzini
2012-11-22  1:48         ` Wenchao Xia
2012-11-20  9:46 ` [Qemu-devel] [PATCH V10 7/7] 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=50AB5E61.9060303@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=xiawenc@linux.vnet.ibm.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).