From: Stefan Hajnoczi <stefanha@gmail.com>
To: Fam Zheng <famcool@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-devel@nongnu.org, Christoph Hellwig <hch@lst.de>
Subject: Re: [Qemu-devel] [PATCH 04/12] VMDK: separate vmdk_open by format version
Date: Sat, 18 Jun 2011 14:59:41 +0100 [thread overview]
Message-ID: <BANLkTimHkfy+GuL+uFimk-_t=f2Ev73E6w@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=7D5bbfGwiyj7vEHnDL5eKuARr5A@mail.gmail.com>
On Sat, Jun 4, 2011 at 1:41 AM, Fam Zheng <famcool@gmail.com> wrote:
> +static int vmdk_open_vmdk4(BlockDriverState *bs, int flags)
> +{
> + uint32_t magic;
> + VMDK4Header header;
> + BDRVVmdkState *s = bs->opaque;
> + VmdkExtent *extent;
> +
> + s->extents = qemu_mallocz(sizeof(VmdkExtent));
> + s->num_extents = 1;
> + if (bdrv_pread(bs->file, sizeof(magic), &header, sizeof(header))
> + != sizeof(header)) {
> + goto fail;
> + }
> + extent = s->extents;
> + extent->file = bs->file;
> + extent->sectors = le64_to_cpu(header.capacity);
> + extent->cluster_sectors = le64_to_cpu(header.granularity);
> + extent->l2_size = le32_to_cpu(header.num_gtes_per_gte);
> + extent->l1_entry_sectors = extent->l2_size * extent->cluster_sectors;
> + if (extent->l1_entry_sectors <= 0) {
> + goto fail;
> + }
> + extent->l1_size = (extent->sectors + extent->l1_entry_sectors - 1)
> + / extent->l1_entry_sectors;
> + extent->l1_table_offset = le64_to_cpu(header.rgd_offset) << 9;
> + extent->l1_backup_table_offset = le64_to_cpu(header.gd_offset) << 9;
> +
> + // try to open parent images, if exist
> + if (vmdk_parent_open(bs) != 0) {
> + goto fail;
> + }
> + // write the CID once after the image creation
This comment is from vmdk_create() and can be removed?
> + extent->parent_cid = vmdk_read_cid(bs,1);
> + bs->total_sectors = extent->sectors;
> + if (vmdk_init_tables(bs, extent)) {
> + goto fail;
> }
> + return 0;
> + fail:
> + qemu_free(s->extents);
> return -1;
> }
>
> +static int vmdk_open(BlockDriverState *bs, int flags)
> +{
> + uint32_t magic;
> +
> + if (bdrv_pread(bs->file, 0, &magic, sizeof(magic)) != sizeof(magic)) {
> + return -1;
> + }
> +
> + magic = be32_to_cpu(magic);
> + if (magic == VMDK3_MAGIC) {
> + return vmdk_open_vmdk3(bs, flags);
> + } else if (magic == VMDK4_MAGIC) {
> + return vmdk_open_vmdk4(bs, flags);
> + } else {
> + return -1;
> + }
This is a good opportunity to use -errno instead of -1. If you look
at qcow2 or qed they return appropriate error numbers and not just -1.
(Also remember -1 is -EPERM so callers that interpret the return
value as an error will print junk error messages if -1 is returned.)
Stefan
prev parent reply other threads:[~2011-06-18 13:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-04 0:41 [Qemu-devel] [PATCH 04/12] VMDK: separate vmdk_open by format version Fam Zheng
2011-06-18 13:59 ` Stefan Hajnoczi [this message]
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='BANLkTimHkfy+GuL+uFimk-_t=f2Ev73E6w@mail.gmail.com' \
--to=stefanha@gmail.com \
--cc=famcool@gmail.com \
--cc=hch@lst.de \
--cc=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).