From: Alex Bligh <alex@alex.org.uk>
To: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Cc: Ian Campbell <Ian.Campbell@citrix.com>,
George Dunlap <George.Dunlap@eu.citrix.com>,
Ian Jackson <Ian.Jackson@eu.citrix.com>,
qemu-devel@nongnu.org, xen-devel <xen-devel@lists.xen.org>,
Alex Bligh <alex@alex.org.uk>,
Anthony Liguori <anthony@codemonkey.ws>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCHv3 1/2] Xen PV backend: Move call to bdrv_new from blk_init to blk_connect
Date: Fri, 5 Apr 2013 16:42:16 +0100 [thread overview]
Message-ID: <1365176538-36833-1-git-send-email-alex@alex.org.uk> (raw)
In-Reply-To: <alpine.DEB.2.02.1304051516460.5078@kaball.uk.xensource.com>
This commit delays the point at which bdrv_new (and hence blk_open
on the underlying device) is called from blk_init to blk_connect.
This ensures that in an inbound live migrate, the block device is
not opened until it has been closed at the other end. This is in
preparation for supporting devices with open/close consistency
without using O_DIRECT. This commit does NOT itself change O_DIRECT
semantics.
Signed-off-by: Alex Bligh <alex@alex.org.uk>
---
hw/xen_disk.c | 72 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 40 insertions(+), 32 deletions(-)
diff --git a/hw/xen_disk.c b/hw/xen_disk.c
index 69e1d9d..c3c5904 100644
--- a/hw/xen_disk.c
+++ b/hw/xen_disk.c
@@ -701,7 +701,7 @@ static void blk_alloc(struct XenDevice *xendev)
static int blk_init(struct XenDevice *xendev)
{
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
- int index, qflags, info = 0;
+ int info = 0;
/* read xenstore entries */
if (blkdev->params == NULL) {
@@ -744,10 +744,7 @@ static int blk_init(struct XenDevice *xendev)
}
/* read-only ? */
- qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
- if (strcmp(blkdev->mode, "w") == 0) {
- qflags |= BDRV_O_RDWR;
- } else {
+ if (strcmp(blkdev->mode, "w")) {
info |= VDISK_READONLY;
}
@@ -756,6 +753,41 @@ static int blk_init(struct XenDevice *xendev)
info |= VDISK_CDROM;
}
+ blkdev->file_blk = BLOCK_SIZE;
+
+ /* fill info
+ * blk_connect supplies sector-size and sectors
+ */
+ xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1);
+ xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1);
+ xenstore_write_be_int(&blkdev->xendev, "info", info);
+ return 0;
+
+out_error:
+ g_free(blkdev->params);
+ blkdev->params = NULL;
+ g_free(blkdev->mode);
+ blkdev->mode = NULL;
+ g_free(blkdev->type);
+ blkdev->type = NULL;
+ g_free(blkdev->dev);
+ blkdev->dev = NULL;
+ g_free(blkdev->devtype);
+ blkdev->devtype = NULL;
+ return -1;
+}
+
+static int blk_connect(struct XenDevice *xendev)
+{
+ struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
+ int pers, index, qflags;
+
+ /* read-only ? */
+ qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
+ if (strcmp(blkdev->mode, "w") == 0) {
+ qflags |= BDRV_O_RDWR;
+ }
+
/* init qemu block driver */
index = (blkdev->xendev.dev - 202 * 256) / 16;
blkdev->dinfo = drive_get(IF_XEN, 0, index);
@@ -771,7 +803,7 @@ static int blk_init(struct XenDevice *xendev)
}
}
if (!blkdev->bs) {
- goto out_error;
+ return -1;
}
} else {
/* setup via qemu cmdline -> already setup for us */
@@ -779,7 +811,6 @@ static int blk_init(struct XenDevice *xendev)
blkdev->bs = blkdev->dinfo->bdrv;
}
bdrv_attach_dev_nofail(blkdev->bs, blkdev);
- blkdev->file_blk = BLOCK_SIZE;
blkdev->file_size = bdrv_getlength(blkdev->bs);
if (blkdev->file_size < 0) {
xen_be_printf(&blkdev->xendev, 1, "bdrv_getlength: %d (%s) | drv %s\n",
@@ -793,33 +824,10 @@ static int blk_init(struct XenDevice *xendev)
blkdev->type, blkdev->fileproto, blkdev->filename,
blkdev->file_size, blkdev->file_size >> 20);
- /* fill info */
- xenstore_write_be_int(&blkdev->xendev, "feature-flush-cache", 1);
- xenstore_write_be_int(&blkdev->xendev, "feature-persistent", 1);
- xenstore_write_be_int(&blkdev->xendev, "info", info);
- xenstore_write_be_int(&blkdev->xendev, "sector-size", blkdev->file_blk);
+ /* Fill in number of sector size and number of sectors */
+ xenstore_write_be_int(&blkdev->xendev, "sector-size", blkdev->file_blk);
xenstore_write_be_int(&blkdev->xendev, "sectors",
blkdev->file_size / blkdev->file_blk);
- return 0;
-
-out_error:
- g_free(blkdev->params);
- blkdev->params = NULL;
- g_free(blkdev->mode);
- blkdev->mode = NULL;
- g_free(blkdev->type);
- blkdev->type = NULL;
- g_free(blkdev->dev);
- blkdev->dev = NULL;
- g_free(blkdev->devtype);
- blkdev->devtype = NULL;
- return -1;
-}
-
-static int blk_connect(struct XenDevice *xendev)
-{
- struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
- int pers;
if (xenstore_read_fe_int(&blkdev->xendev, "ring-ref", &blkdev->ring_ref) == -1) {
return -1;
--
1.7.9.5
next prev parent reply other threads:[~2013-04-05 15:42 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-18 12:18 [Qemu-devel] [PATCHv3] QEMU(upstream): Disable xen's use of O_DIRECT by default as it results in crashes Alex Bligh
2013-03-18 13:03 ` Stefan Hajnoczi
2013-03-18 13:19 ` Alex Bligh
2013-03-18 13:32 ` Paolo Bonzini
2013-03-18 13:49 ` Alex Bligh
2013-03-18 14:05 ` Paolo Bonzini
2013-03-18 14:30 ` Alex Bligh
2013-03-18 14:49 ` Paolo Bonzini
2013-03-18 15:40 ` Alex Bligh
2013-03-18 16:19 ` Paolo Bonzini
2013-03-18 16:53 ` Alex Bligh
2013-03-18 17:38 ` George Dunlap
2013-03-18 17:47 ` Alex Bligh
2013-03-18 18:00 ` Paolo Bonzini
2013-03-19 10:06 ` [Qemu-devel] [Xen-devel] " George Dunlap
2013-03-19 10:43 ` Paolo Bonzini
2013-03-19 10:51 ` George Dunlap
2013-03-19 11:14 ` Paolo Bonzini
2013-03-19 11:21 ` George Dunlap
2013-03-19 15:12 ` George Dunlap
2013-03-19 15:29 ` George Dunlap
2013-03-19 19:15 ` Alex Bligh
2013-03-20 10:24 ` Stefano Stabellini
2013-03-20 10:37 ` George Dunlap
2013-03-20 11:08 ` Paolo Bonzini
2013-03-20 11:20 ` Alex Bligh
2013-03-20 11:57 ` David Scott
2013-03-19 11:44 ` Alex Bligh
2013-03-19 11:49 ` Paolo Bonzini
2013-03-19 15:13 ` Stefano Stabellini
2013-03-19 16:53 ` Paolo Bonzini
2013-03-19 17:03 ` Stefano Stabellini
2013-03-20 8:33 ` Alex Bligh
2013-03-20 9:26 ` Paolo Bonzini
2013-03-29 17:19 ` Stefano Stabellini
2013-03-31 19:53 ` Alex Bligh
2013-04-01 15:32 ` [Qemu-devel] [PATCH] [RFC] Xen PV backend: Move call to bdrv_new from blk_init to blk_connect Alex Bligh
2013-04-01 15:44 ` Stefano Stabellini
2013-04-01 20:56 ` Alex Bligh
2013-04-02 11:08 ` Stefano Stabellini
2013-04-05 10:31 ` [Qemu-devel] [PATCHv2 1/2] " Alex Bligh
2013-04-05 10:31 ` [Qemu-devel] [PATCHv2 2/2] Xen PV backend: Disable use of O_DIRECT by default as it results in crashes Alex Bligh
2013-04-05 14:22 ` [Qemu-devel] [PATCHv2 1/2] Xen PV backend: Move call to bdrv_new from blk_init to blk_connect Stefano Stabellini
2013-04-05 15:42 ` Alex Bligh [this message]
2013-04-05 15:42 ` [Qemu-devel] [PATCHv3 2/2] Xen PV backend: Disable use of O_DIRECT by default as it results in crashes Alex Bligh
2013-04-05 15:43 ` [Qemu-devel] [PATCHv2 1/2] Xen PV backend: Move call to bdrv_new from blk_init to blk_connect Alex Bligh
2013-04-05 10:32 ` [Qemu-devel] [PATCHv2 1/2] Xen PV backend (for qemu-upstream-4.2-testing): " Alex Bligh
2013-04-05 10:32 ` [Qemu-devel] [PATCHv2 2/2] Xen PV backend (for qemu-upstream-4.2-testing): Disable use of O_DIRECT by default as it results in crashes Alex Bligh
2013-04-05 10:34 ` [Qemu-devel] [PATCH] [RFC] Xen PV backend: Move call to bdrv_new from blk_init to blk_connect Alex Bligh
2013-04-01 16:35 ` [Qemu-devel] [Xen-devel] [PATCHv3] QEMU(upstream): Disable xen's use of O_DIRECT by default as it results in crashes Alex Bligh
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=1365176538-36833-1-git-send-email-alex@alex.org.uk \
--to=alex@alex.org.uk \
--cc=George.Dunlap@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=Stefano.Stabellini@eu.citrix.com \
--cc=anthony@codemonkey.ws \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=xen-devel@lists.xen.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).