* [PATCH] qemu-xen-trad/block: add support for NetBSD phy interfaces
@ 2012-05-30 11:52 Roger Pau Monne
2012-05-30 13:15 ` Stefano Stabellini
0 siblings, 1 reply; 2+ messages in thread
From: Roger Pau Monne @ 2012-05-30 11:52 UTC (permalink / raw)
To: xen-devel; +Cc: Roger Pau Monne
Add support for NetBSD to get the correct size for phy block devices,
and use character devices instead of block devices.
This has been in pkgsrc tree for a long time, and is present in upstream qemu.
It is not pretty, but I'm fairly confident that it doesn't break anything on
the Linux side.
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
block-raw-posix.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/block-raw-posix.c b/block-raw-posix.c
index 9a02d4f..7429c7b 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -66,6 +66,13 @@
#include <sys/disklabel.h>
#include <sys/dkio.h>
#endif
+#if defined(__NetBSD__)
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#define SLIST_ENTRY(x) int /*XXXX !*/
+#include <sys/disk.h>
+#endif
//#define DEBUG_FLOPPY
@@ -120,6 +127,33 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
{
BDRVRawState *s = bs->opaque;
int fd, open_flags, ret;
+#ifdef __NetBSD__
+ struct stat sb;
+ static char namebuf[MAXPATHLEN];
+ const char *dp;
+
+ if (lstat(filename, &sb) < 0) {
+ fprintf(stderr, "%s: stat failed: %s\n", filename, strerror(errno));
+ return -errno;
+ }
+ if (S_ISLNK(sb.st_mode)) {
+ fprintf(stderr, "%s: symolink links not supported by qemu-dm\n",
+ filename);
+ return -EINVAL;
+ }
+ if (S_ISBLK(sb.st_mode)) {
+ dp = strrchr(filename, '/');
+ if (dp == NULL) {
+ snprintf(namebuf, MAXPATHLEN, "r%s", filename);
+ } else {
+ snprintf(namebuf, MAXPATHLEN, "%.*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
posix_aio_init();
@@ -749,7 +783,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
return 0;
}
-#ifdef __OpenBSD__
+#if defined(__OpenBSD__) || defined(__NetBSD__)
static int64_t raw_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
@@ -759,16 +793,29 @@ static int64_t raw_getlength(BlockDriverState *bs)
if (fstat(fd, &st))
return -1;
if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
+#if defined(__OpenBSD__)
struct disklabel dl;
if (ioctl(fd, DIOCGDINFO, &dl))
return -1;
return (uint64_t)dl.d_secsize *
dl.d_partitions[DISKPART(st.st_rdev)].p_size;
+#else
+ struct dkwedge_info dkw;
+ if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) {
+ return dkw.dkw_size * 512;
+ } else {
+ struct disklabel dl;
+ if(ioctl(fd, DIOCGDINFO, &dl))
+ return -1;
+ return (uint64_t)dl.d_secsize *
+ dl.d_partitions[DISKPART(st.st_rdev)].p_size;
+ }
+#endif
} else
return st.st_size;
}
-#else /* !__OpenBSD__ */
+#else /* !__OpenBSD__ && ! __NetBSD__ */
static int64_t raw_getlength(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
--
1.7.7.5 (Apple Git-26)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] qemu-xen-trad/block: add support for NetBSD phy interfaces
2012-05-30 11:52 [PATCH] qemu-xen-trad/block: add support for NetBSD phy interfaces Roger Pau Monne
@ 2012-05-30 13:15 ` Stefano Stabellini
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Stabellini @ 2012-05-30 13:15 UTC (permalink / raw)
To: Roger Pau Monne; +Cc: xen-devel@lists.xen.org
On Wed, 30 May 2012, Roger Pau Monne wrote:
> Add support for NetBSD to get the correct size for phy block devices,
> and use character devices instead of block devices.
>
> This has been in pkgsrc tree for a long time, and is present in upstream qemu.
Could you please include the upstream QEMU commit id in the description
of this patch?
> It is not pretty, but I'm fairly confident that it doesn't break anything on
> the Linux side.
>
> Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
> ---
> block-raw-posix.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++--
> 1 files changed, 49 insertions(+), 2 deletions(-)
>
> diff --git a/block-raw-posix.c b/block-raw-posix.c
> index 9a02d4f..7429c7b 100644
> --- a/block-raw-posix.c
> +++ b/block-raw-posix.c
> @@ -66,6 +66,13 @@
> #include <sys/disklabel.h>
> #include <sys/dkio.h>
> #endif
> +#if defined(__NetBSD__)
> +#include <sys/ioctl.h>
> +#include <sys/disklabel.h>
> +#include <sys/dkio.h>
> +#define SLIST_ENTRY(x) int /*XXXX !*/
> +#include <sys/disk.h>
> +#endif
>
> //#define DEBUG_FLOPPY
>
> @@ -120,6 +127,33 @@ static int raw_open(BlockDriverState *bs, const char *filename, int flags)
> {
> BDRVRawState *s = bs->opaque;
> int fd, open_flags, ret;
> +#ifdef __NetBSD__
> + struct stat sb;
> + static char namebuf[MAXPATHLEN];
> + const char *dp;
> +
> + if (lstat(filename, &sb) < 0) {
> + fprintf(stderr, "%s: stat failed: %s\n", filename, strerror(errno));
> + return -errno;
> + }
> + if (S_ISLNK(sb.st_mode)) {
> + fprintf(stderr, "%s: symolink links not supported by qemu-dm\n",
> + filename);
> + return -EINVAL;
> + }
> + if (S_ISBLK(sb.st_mode)) {
> + dp = strrchr(filename, '/');
> + if (dp == NULL) {
> + snprintf(namebuf, MAXPATHLEN, "r%s", filename);
> + } else {
> + snprintf(namebuf, MAXPATHLEN, "%.*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
maybe you could refactor it in a separate raw_normalize_devicepath
function, like in upstream QEMU
> posix_aio_init();
>
> @@ -749,7 +783,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset)
> return 0;
> }
>
> -#ifdef __OpenBSD__
> +#if defined(__OpenBSD__) || defined(__NetBSD__)
> static int64_t raw_getlength(BlockDriverState *bs)
> {
> BDRVRawState *s = bs->opaque;
> @@ -759,16 +793,29 @@ static int64_t raw_getlength(BlockDriverState *bs)
> if (fstat(fd, &st))
> return -1;
> if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
> +#if defined(__OpenBSD__)
> struct disklabel dl;
>
> if (ioctl(fd, DIOCGDINFO, &dl))
> return -1;
> return (uint64_t)dl.d_secsize *
> dl.d_partitions[DISKPART(st.st_rdev)].p_size;
> +#else
> + struct dkwedge_info dkw;
> + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) {
> + return dkw.dkw_size * 512;
> + } else {
> + struct disklabel dl;
> + if(ioctl(fd, DIOCGDINFO, &dl))
> + return -1;
> + return (uint64_t)dl.d_secsize *
> + dl.d_partitions[DISKPART(st.st_rdev)].p_size;
> + }
> +#endif
similarly this could be in a separate raw_getlength function
> } else
> return st.st_size;
> }
> -#else /* !__OpenBSD__ */
> +#else /* !__OpenBSD__ && ! __NetBSD__ */
> static int64_t raw_getlength(BlockDriverState *bs)
> {
> BDRVRawState *s = bs->opaque;
> --
> 1.7.7.5 (Apple Git-26)
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-05-30 13:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-30 11:52 [PATCH] qemu-xen-trad/block: add support for NetBSD phy interfaces Roger Pau Monne
2012-05-30 13:15 ` Stefano Stabellini
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).