From: Stefan Hajnoczi <stefanha@gmail.com>
To: Xiaodong Gong <gordongong0350@gmail.com>
Cc: kwolf@redhat.com, petrutlucian94@gmail.com,
brian.luohao@huawei.com, hahn@univention.de,
hutao@cn.fujitsu.com, jcody@redhat.com, cyliu@suse.com,
qemu-devel@nongnu.org, ssdxiao@163.com, arei.gonglei@huawei.com,
stefanha@redhat.com, Xiaodong Gong <gongxiaodong1@huawei.com>,
rudy.zhangmin@huawei.com
Subject: Re: [Qemu-devel] [PATCH RESEND] Support vhd type VHD_DIFFERENCING
Date: Wed, 26 Nov 2014 15:32:49 +0000 [thread overview]
Message-ID: <20141126153249.GA14288@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <1415285030-23278-1-git-send-email-gongxiaodong1@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 3471 bytes --]
On Thu, Nov 06, 2014 at 10:43:50PM +0800, Xiaodong Gong wrote:
> + } else if (platform == PLATFORM_W2RU) {
> + /* Must be UTF16-LE to ASCII */
> + char *out, *optr;
> + int j;
> +
> + optr = out = (char *) g_malloc(data_length + 1);
> + if (out == NULL) {
> + ret = -1;
> + return ret;
> + }
> +
> + for (j = 0; j < data_length + 1; j++) {
> + out[j] = bs->backing_file[2 * j];
> + }
> + out[data_length + 1] = '\0';
> +
> + while (*optr != '\0') {
> + if (*optr == '\\') {
> + *optr = '/';
> + }
> + optr++;
> + }
> +
> + strncpy(bs->backing_file, out, data_length + 1);
> +
> + g_free(out);
> + out = NULL;
> +
> + done = true;
> + }
Please convert from UTF-16 LE to the local file system character set:
https://developer.gnome.org/glib/stable/glib-Character-Set-Conversion.html
Also, using ->backing_file[] when the data is UTF-16 LE encoded is not
ideal since it halves the maximum size of the string! It would be
better to read into a temporary buffer that is 2 *
sizeof(backing_file[]) big before writing into ->backing_file[].
> @@ -286,6 +411,37 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
> s->free_data_block_offset =
> (s->bat_offset + (s->max_table_entries * 4) + 511) & ~511;
>
> + /* Read tdbatmap header by offset */
> + if (footer->version >= VHD_VERSION(1, 2)) {
Missing be32_to_cpu(footer->version)
> +static int vpc_write(BlockDriverState *bs, int64_t sector_num,
> + const uint8_t *buf, int nb_sectors)
> +{
> + BDRVVPCState *s = bs->opaque;
> + VHDFooter *footer = (VHDFooter *) s->footer_buf;
> + int64_t sectors_per_block = s->block_size >> BDRV_SECTOR_BITS;
> + int64_t offset, sectors;
> + bool diff = true;
> + int ret = 0;
> +
> + switch (be32_to_cpu(footer->type)) {
> + case VHD_FIXED:
> + return bdrv_write(bs->file, sector_num, buf, nb_sectors);
> + case VHD_DYNAMIC:
> + case VHD_DIFF:
> + if (be32_to_cpu(footer->type) == VHD_DYNAMIC) {
> + diff = false;
> }
This can be done with a fall-through case instead of checking
footer->type again:
case VHD_DYNAMIC:
diff = false;
/* fall-through */
case VHD_DIFF:
> + ret = bdrv_pwrite(bs->file, offset, buf,
> + sectors * BDRV_SECTOR_SIZE);
> + if (ret != sectors * BDRV_SECTOR_SIZE) {
> + return -1;
> + }
>
> - nb_sectors -= sectors;
> - sector_num += sectors;
> - buf += sectors * BDRV_SECTOR_SIZE;
> - }
> + if (diff) {
> + ret = write_bitmap(bs, sector_num, sectors);
> + if (ret < 0) {
> + return -1;
> + }
> + }
>
> - return 0;
> + nb_sectors -= sectors;
> + sector_num += sectors;
> + buf += sectors * BDRV_SECTOR_SIZE;
> + }
> + break;
> + default:
> + return -1;
> + }
> + return ret;
In the VHD_DYNAMIC case we must *not* return the number of bytes from
bdrv_pwrite(). Should this be return 0?
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2014-11-26 15:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-06 14:43 [Qemu-devel] [PATCH RESEND] Support vhd type VHD_DIFFERENCING Xiaodong Gong
2014-11-26 15:32 ` Stefan Hajnoczi [this message]
2015-02-08 12:19 ` Xiaodong Gong
2014-11-26 15:57 ` Stefan Hajnoczi
2015-02-08 13:24 ` Xiaodong Gong
-- strict thread matches above, loose matches on Subject: below --
2014-10-10 16:17 Xiaodong Gong
2014-10-11 1:02 ` Gonglei
2014-10-14 13:32 ` Xiaodong Gong
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=20141126153249.GA14288@stefanha-thinkpad.redhat.com \
--to=stefanha@gmail.com \
--cc=arei.gonglei@huawei.com \
--cc=brian.luohao@huawei.com \
--cc=cyliu@suse.com \
--cc=gongxiaodong1@huawei.com \
--cc=gordongong0350@gmail.com \
--cc=hahn@univention.de \
--cc=hutao@cn.fujitsu.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=petrutlucian94@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=rudy.zhangmin@huawei.com \
--cc=ssdxiao@163.com \
--cc=stefanha@redhat.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).