[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 3/3] disk: don't read from disk until the guest star
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 3/3] disk: don't read from disk until the guest starts |
Date: |
Sat, 11 Sep 2010 09:04:56 -0500 |
This fixes a couple nasty problems relating to live migration.
1) When dealing with shared storage with weak coherence (i.e. NFS), even if
we re-read, we may end up with undesired caching. By delaying any reads
until we absolutely have to, we decrease the likelihood of any undesirable
caching.
2) When dealing with copy-on-read, the local storage acts as a cache. We need
to make sure to avoid any reads to avoid polluting the local cache.
Signed-off-by: Anthony Liguori <address@hidden>
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 1e466d1..57d8db3 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -94,6 +94,33 @@ static void put_le16(uint16_t *p, unsigned int v)
*p = cpu_to_le16(v);
}
+static int guess_geometry(IDEState *s)
+{
+ int cylinders, heads, secs;
+
+ if (s->cylinders != 0) {
+ return -1;
+ }
+
+ bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+ if (cylinders < 1 || cylinders > 16383) {
+ error_report("cyls must be between 1 and 16383");
+ return -1;
+ }
+ if (heads < 1 || heads > 16) {
+ error_report("heads must be between 1 and 16");
+ return -1;
+ }
+ if (secs < 1 || secs > 63) {
+ error_report("secs must be between 1 and 63");
+ return -1;
+ }
+ s->cylinders = cylinders;
+ s->heads = heads;
+ s->sectors = secs;
+ return 0;
+}
+
static void ide_identify(IDEState *s)
{
uint16_t *p;
@@ -105,6 +132,8 @@ static void ide_identify(IDEState *s)
return;
}
+ guess_geometry(s);
+
memset(s->io_buffer, 0, 512);
p = (uint16_t *)s->io_buffer;
put_le16(p + 0, 0x0040);
@@ -2614,27 +2643,13 @@ void ide_bus_reset(IDEBus *bus)
int ide_init_drive(IDEState *s, BlockDriverState *bs,
const char *version, const char *serial)
{
- int cylinders, heads, secs;
uint64_t nb_sectors;
s->bs = bs;
- bdrv_get_geometry(bs, &nb_sectors);
- bdrv_guess_geometry(bs, &cylinders, &heads, &secs);
- if (cylinders < 1 || cylinders > 16383) {
- error_report("cyls must be between 1 and 16383");
- return -1;
- }
- if (heads < 1 || heads > 16) {
- error_report("heads must be between 1 and 16");
- return -1;
- }
- if (secs < 1 || secs > 63) {
- error_report("secs must be between 1 and 63");
- return -1;
- }
- s->cylinders = cylinders;
- s->heads = heads;
- s->sectors = secs;
+ bdrv_get_geometry(s->bs, &nb_sectors);
+ s->cylinders = 0;
+ s->heads = 0;
+ s->sectors = 0;
s->nb_sectors = nb_sectors;
/* The SMART values should be preserved across power cycles
but they aren't. */
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index bd6bbe6..0bf17ec 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -427,6 +427,10 @@ static void virtio_blk_update_config(VirtIODevice *vdev,
uint8_t *config)
bdrv_get_geometry(s->bs, &capacity);
bdrv_get_geometry_hint(s->bs, &cylinders, &heads, &secs);
+ if (cylinders == 0) {
+ bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
+ }
+
memset(&blkcfg, 0, sizeof(blkcfg));
stq_raw(&blkcfg.capacity, capacity);
stl_raw(&blkcfg.seg_max, 128 - 2);
@@ -501,7 +505,6 @@ static int virtio_blk_load(QEMUFile *f, void *opaque, int
version_id)
VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf)
{
VirtIOBlock *s;
- int cylinders, heads, secs;
static int virtio_blk_id;
DriveInfo *dinfo;
@@ -525,7 +528,6 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf
*conf)
s->conf = conf;
s->rq = NULL;
s->sector_mask = (s->conf->logical_block_size / BDRV_SECTOR_SIZE) - 1;
- bdrv_guess_geometry(s->bs, &cylinders, &heads, &secs);
/* NB: per existing s/n string convention the string is terminated
* by '\0' only when less than sizeof (s->sn)
--
1.7.0.4
[Qemu-devel] [PATCH 3/3] disk: don't read from disk until the guest starts,
Anthony Liguori <=
[Qemu-devel] Re: [PATCH 3/3] disk: don't read from disk until the guest starts, Juan Quintela, 2010/09/15
[Qemu-devel] Re: [PATCH 3/3] disk: don't read from disk until the guest starts, Kevin Wolf, 2010/09/13