xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw.
@ 2012-05-30 13:45 Roger Pau Monne
  2012-05-30 13:45 ` [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given Roger Pau Monne
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roger Pau Monne @ 2012-05-30 13:45 UTC (permalink / raw)
  To: xen-devel

Both patches are already present in upstream qemu, this is only a 
backport.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given
  2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
@ 2012-05-30 13:45 ` Roger Pau Monne
  2012-05-30 13:45 ` [PATCH 2/2] qemu-xen-trad/block: get right partition size Roger Pau Monne
  2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
  2 siblings, 0 replies; 6+ messages in thread
From: Roger Pau Monne @ 2012-05-30 13:45 UTC (permalink / raw)
  To: xen-devel; +Cc: Kevin Wolf, Christoph Egger, Roger Pau Monne

On NetBSD a userland process is better with the character device
interface. In addition, a block device can't be opened twice; if a Xen
backend opens it, qemu can't and vice-versa.

This is a backport of 1de1ae0a7d956b3c87712bf2c09d277f99873f4c.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 block-raw-posix.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index 9a02d4f..e7d7457 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -116,11 +116,54 @@ static int posix_aio_init(void);
 
 static int fd_open(BlockDriverState *bs);
 
+#if defined(__NetBSD__)
+static int raw_normalize_devicepath(const char **filename)
+{
+    static char namebuf[PATH_MAX];
+    const char *dp, *fname;
+    struct stat sb;
+
+    fname = *filename;
+    dp = strrchr(fname, '/');
+    if (lstat(fname, &sb) < 0) {
+        fprintf(stderr, "%s: stat failed: %s\n",
+            fname, strerror(errno));
+        return -errno;
+    }
+
+    if (!S_ISBLK(sb.st_mode)) {
+        return 0;
+    }
+
+    if (dp == NULL) {
+        snprintf(namebuf, PATH_MAX, "r%s", fname);
+    } else {
+        snprintf(namebuf, PATH_MAX, "%.*s/r%s",
+            (int)(dp - fname), fname, dp + 1);
+    }
+    fprintf(stderr, "%s is a block device", fname);
+    *filename = namebuf;
+    fprintf(stderr, ", using %s\n", *filename);
+
+    return 0;
+}
+#else
+static int raw_normalize_devicepath(const char **filename)
+{
+    return 0;
+}
+#endif
+
 static int raw_open(BlockDriverState *bs, const char *filename, int flags)
 {
     BDRVRawState *s = bs->opaque;
     int fd, open_flags, ret;
 
+    ret = raw_normalize_devicepath(&filename);
+    if (ret != 0) {
+        return ret;
+    }
+
     posix_aio_init();
 
     s->lseek_err_cnt = 0;
-- 
1.7.7.5 (Apple Git-26)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] qemu-xen-trad/block: get right partition size
  2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
  2012-05-30 13:45 ` [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given Roger Pau Monne
@ 2012-05-30 13:45 ` Roger Pau Monne
  2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
  2 siblings, 0 replies; 6+ messages in thread
From: Roger Pau Monne @ 2012-05-30 13:45 UTC (permalink / raw)
  To: xen-devel; +Cc: Kevin Wolf, Christoph Egger, Roger Pau Monne

use the correct way to get the size of a disk device or partition

This this a backport of d1f6fd8d1400ab356aee776b1ecc3ed1e89dbeaa.

From: Adam Hamsik <haad@netbsd.org>
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 block-raw-posix.c |   33 ++++++++++++++++++++++++++++++++-
 1 files changed, 32 insertions(+), 1 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index e7d7457..795cd5b 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -60,6 +60,12 @@
 #include <signal.h>
 #include <sys/disk.h>
 #endif
+#ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#include <sys/disk.h>
+#endif
 
 #ifdef __OpenBSD__
 #include <sys/ioctl.h>
@@ -811,7 +817,32 @@ static int64_t raw_getlength(BlockDriverState *bs)
     } else
         return st.st_size;
 }
-#else /* !__OpenBSD__ */
+#elif defined(__NetBSD__)
+static int64_t raw_getlength(BlockDriverState *bs)
+{
+    BDRVRawState *s = bs->opaque;
+    int fd = s->fd;
+    struct stat st;
+
+    if (fstat(fd, &st))
+        return -1;
+    if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) {
+        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;
+        }
+    } else
+        return st.st_size;
+}
+#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] 6+ messages in thread

* Re: [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw.
  2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
  2012-05-30 13:45 ` [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given Roger Pau Monne
  2012-05-30 13:45 ` [PATCH 2/2] qemu-xen-trad/block: get right partition size Roger Pau Monne
@ 2012-05-30 13:50 ` Stefano Stabellini
  2012-05-30 16:13   ` Roger Pau Monne
  2012-06-07 18:39   ` Ian Jackson
  2 siblings, 2 replies; 6+ messages in thread
From: Stefano Stabellini @ 2012-05-30 13:50 UTC (permalink / raw)
  To: Roger Pau Monne; +Cc: xen-devel@lists.xen.org

On Wed, 30 May 2012, Roger Pau Monne wrote:
> Both patches are already present in upstream qemu, this is only a 
> backport.

Much better now thanks, I would consider them for 4.2

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw.
  2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
@ 2012-05-30 16:13   ` Roger Pau Monne
  2012-06-07 18:39   ` Ian Jackson
  1 sibling, 0 replies; 6+ messages in thread
From: Roger Pau Monne @ 2012-05-30 16:13 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel@lists.xen.org

Stefano Stabellini wrote:
> On Wed, 30 May 2012, Roger Pau Monne wrote:
>> Both patches are already present in upstream qemu, this is only a
>> backport.
>
> Much better now thanks, I would consider them for 4.2
>

Could you please also consider "[PATCH] qemu-xen-trad: fix sys-queue.h 
usage on BSD systems", I've forgot to add this one to the series.

Thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw.
  2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
  2012-05-30 16:13   ` Roger Pau Monne
@ 2012-06-07 18:39   ` Ian Jackson
  1 sibling, 0 replies; 6+ messages in thread
From: Ian Jackson @ 2012-06-07 18:39 UTC (permalink / raw)
  To: Stefano Stabellini
  Cc: Kevin Wolf, Adam Hamsik, Christoph Egger, xen-devel@lists.xen.org,
	Roger Pau Monne

Stefano Stabellini writes ("Re: [Xen-devel] [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw."):
> On Wed, 30 May 2012, Roger Pau Monne wrote:
> > Both patches are already present in upstream qemu, this is only a 
> > backport.
> 
> Much better now thanks, I would consider them for 4.2

I have applied both, thanks everyone.

Ian.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-06-07 18:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-30 13:45 [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Roger Pau Monne
2012-05-30 13:45 ` [PATCH 1/2] qemu-xen-trad/block: use a character device if a block device is given Roger Pau Monne
2012-05-30 13:45 ` [PATCH 2/2] qemu-xen-trad/block: get right partition size Roger Pau Monne
2012-05-30 13:50 ` [PATCH 0/2] qemu-xen-trad/block: fixes for NetBSD block-raw Stefano Stabellini
2012-05-30 16:13   ` Roger Pau Monne
2012-06-07 18:39   ` Ian Jackson

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).