From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/2] drive_open: Add invalidate option for block devices
Date: Wed, 9 Nov 2011 20:16:43 +0100 [thread overview]
Message-ID: <8920a92ef9be3313494009853d25bae9cc5a1c54.1320865627.git.quintela@redhat.com> (raw)
In-Reply-To: <cover.1320865627.git.quintela@redhat.com>
In-Reply-To: <cover.1320865627.git.quintela@redhat.com>
Linux allows to invalidate block devices. This is needed for the incoming
migration part.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
block.h | 2 ++
block/raw-posix.c | 24 ++++++++++++++++++++++++
blockdev.c | 8 ++++----
3 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/block.h b/block.h
index 38cd748..517b446 100644
--- a/block.h
+++ b/block.h
@@ -61,6 +61,8 @@ typedef struct BlockDevOps {
#define BDRV_O_NATIVE_AIO 0x0080 /* use native AIO instead of the thread pool */
#define BDRV_O_NO_BACKING 0x0100 /* don't open the backing file */
#define BDRV_O_NO_FLUSH 0x0200 /* disable flushing on this disk */
+#define BDRV_O_INVALIDATE 0x0400 /* invalidate buffer cache for this device.
+ re-read things from server */
#define BDRV_O_CACHE_MASK (BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index a3de373..84303a0 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -52,6 +52,7 @@
#include <sys/param.h>
#include <linux/cdrom.h>
#include <linux/fd.h>
+#include <linux/fs.h>
#endif
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__)
#include <sys/disk.h>
@@ -218,6 +219,29 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
s->fd = fd;
s->aligned_buf = NULL;
+#ifdef __linux__
+ if ((bdrv_flags & BDRV_O_INVALIDATE)) {
+ struct stat buf;
+ int res;
+
+ res = fstat(fd, &buf);
+
+ if (res < 0) {
+ return -errno;
+ }
+
+ if (S_ISBLK(buf.st_mode)) {
+ printf("we are in a block device: %s\n", filename);
+ res = ioctl(fd, BLKFLSBUF, 0);
+ if (res < 0) {
+ fprintf(stderr, "qemu: buffer invalidation of %s"
+ " failed with error %d\n", filename, errno);
+ return -errno;
+ }
+ }
+ }
+#endif /* __linux__ */
+
if ((bdrv_flags & BDRV_O_NOCACHE)) {
/*
* Allocate a buffer for read/modify/write cycles. Chose the size
diff --git a/blockdev.c b/blockdev.c
index a10de7a..ea02ee7 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -217,10 +217,10 @@ static int parse_block_error_action(const char *buf, int is_read)
}
}
-static int drive_open(DriveInfo *dinfo)
+static int drive_open(DriveInfo *dinfo, int extra_flags)
{
int res = bdrv_open(dinfo->bdrv, dinfo->file,
- dinfo->bdrv_flags, dinfo->drv);
+ dinfo->bdrv_flags | extra_flags, dinfo->drv);
if (res < 0) {
fprintf(stderr, "qemu: could not open disk image %s: %s\n",
@@ -237,7 +237,7 @@ int drives_reinit(void)
if (dinfo->opened && !bdrv_is_read_only(dinfo->bdrv)) {
int res;
bdrv_close(dinfo->bdrv);
- res = drive_open(dinfo);
+ res = drive_open(dinfo, BDRV_O_INVALIDATE);
if (res) {
fprintf(stderr, "qemu: re-open of %s failed with error %d\n",
dinfo->file, res);
@@ -550,7 +550,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi)
dinfo->drv = drv;
dinfo->opened = 1;
- if (drive_open(dinfo) < 0) {
+ if (drive_open(dinfo, 0) < 0) {
goto err;
}
--
1.7.7
next prev parent reply other threads:[~2011-11-09 19:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-09 19:16 [Qemu-devel] [RFC PATCH 0/2] Fix migration with NFS & iscsi/Fiber channel Juan Quintela
2011-11-09 19:16 ` [Qemu-devel] [PATCH 1/2] Reopen files after migration Juan Quintela
2011-11-09 20:00 ` Anthony Liguori
2011-11-09 21:10 ` Juan Quintela
2011-11-09 21:16 ` Anthony Liguori
2011-11-10 11:30 ` Kevin Wolf
2011-11-09 23:30 ` Lucas Meneghel Rodrigues
2011-11-23 23:32 ` Anthony Liguori
2011-11-09 19:16 ` Juan Quintela [this message]
2011-11-10 11:33 ` [Qemu-devel] [PATCH 2/2] drive_open: Add invalidate option for block devices Kevin Wolf
2011-11-10 16:45 ` Juan Quintela
2011-11-10 10:34 ` [Qemu-devel] [RFC PATCH 0/2] Fix migration with NFS & iscsi/Fiber channel Stefan Hajnoczi
2011-11-23 15:46 ` Juan Quintela
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=8920a92ef9be3313494009853d25bae9cc5a1c54.1320865627.git.quintela@redhat.com \
--to=quintela@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).