qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Christoph Egger <Christoph.Egger@amd.com>
Cc: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] block/raw-posix: get right size of	partition size
Date: Mon, 23 May 2011 13:06:15 +0200	[thread overview]
Message-ID: <20110523110615.GA15957@lst.de> (raw)
In-Reply-To: <4DDA383F.7080908@amd.com>

On Mon, May 23, 2011 at 12:34:39PM +0200, Christoph Egger wrote:
>
> This does 2 things:
> - use the correct way to get the size of a disk device or partition
>     (from haad@NetBSD.org)
> - if given a block device, use the character device instead.
>     (from bouyer@NetBSD.org)

Please split that into two independent patches.

> +    if (S_ISLNK(sb.st_mode)) {
> +        fprintf(stderr, "%s: symbolic link not supported\n", filename);
> +        return -EINVAL;
> +    }

Why not, it's a pretty clear regression from current code, and will
break various Linux setups where there are lots of symlinks under /dev,
as well as users using symlinks for their image files.

> +#if defined(__NetBSD__)
> +    if (S_ISBLK(sb.st_mode)) {
> +        static char namebuf[PATH_MAX];
> +        const char *dp = strrchr(filename, '/');
> +
> +        if (dp == NULL) {
> +            snprintf(namebuf, PATH_MAX, "r%s", filename);
> +        } else {
> +            snprintf(namebuf, PATH_MAX, "%.*s/r%s",
> +                (int)(dp - filename), filename, dp + 1);
> +        }
> +        fprintf(stderr, "%s is a block device", filename);
> +        filename = namebuf;
> +        fprintf(stderr, ", using %s\n", filename);
> +    }
> +#endif

Please split this out into a helper, which has a no-op version
for other operating systems.  It probably should also be enabled
for other operating systems having char and block nodes for disk
devices.  That's at least OpenBSD and Solaris, not sure about
Darwin.

> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) || defined(__NetBSD__)
>  static int64_t raw_getlength(BlockDriverState *bs)
>  {
>      BDRVRawState *s = bs->opaque;
> @@ -613,12 +645,22 @@ static int64_t raw_getlength(BlockDriverState *bs)
>      if (fstat(fd, &st))
>          return -1;
>      if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
> -        struct disklabel dl;
> +#if defined(__NetBSD__)
> +        struct dkwedge_info dkw;
>
> -        if (ioctl(fd, DIOCGDINFO, &dl))
> -            return -1;
> -        return (uint64_t)dl.d_secsize *
> -            dl.d_partitions[DISKPART(st.st_rdev)].p_size;
> +        if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) {
> +            return dkw.dkw_size * 512;
> +        } else {
> +#endif

Please provide a completely separate raw_getlength for NetBSD instead
of creating this ifdef mess for almost no shared code.

  reply	other threads:[~2011-05-23 11:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 10:05 [Qemu-devel] [PATCH] block/raw-posix: get right partition size Christoph Egger
2011-05-23 10:34 ` [Qemu-devel] [PATCH] block/raw-posix: get right size of " Christoph Egger
2011-05-23 11:06   ` Christoph Hellwig [this message]
2011-05-23 12:26     ` Christoph Egger

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=20110523110615.GA15957@lst.de \
    --to=hch@lst.de \
    --cc=Christoph.Egger@amd.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).