From patchwork Sat Sep 11 14:04:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 64516 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DB9C8B70A5 for ; Sun, 12 Sep 2010 00:08:29 +1000 (EST) Received: from localhost ([127.0.0.1]:58320 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuQkk-00043C-R7 for incoming@patchwork.ozlabs.org; Sat, 11 Sep 2010 10:08:26 -0400 Received: from [140.186.70.92] (port=36807 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OuQhU-0002PP-Pd for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OuQhT-0004yW-7i for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:04 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:48562) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OuQhT-0004yK-5W for qemu-devel@nongnu.org; Sat, 11 Sep 2010 10:05:03 -0400 Received: from d01relay01.pok.ibm.com (d01relay01.pok.ibm.com [9.56.227.233]) by e9.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id o8BDkKbQ029014 for ; Sat, 11 Sep 2010 09:46:20 -0400 Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by d01relay01.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id o8BE52si400780 for ; Sat, 11 Sep 2010 10:05:02 -0400 Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id o8BE52Yi017199 for ; Sat, 11 Sep 2010 10:05:02 -0400 Received: from localhost.localdomain (sig-9-65-48-245.mts.ibm.com [9.65.48.245]) by d01av04.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id o8BE4ulq016945; Sat, 11 Sep 2010 10:05:01 -0400 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Sat, 11 Sep 2010 09:04:56 -0500 Message-Id: <1284213896-12705-4-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> References: <1284213896-12705-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Juan Quintela Subject: [Qemu-devel] [PATCH 3/3] disk: don't read from disk until the guest starts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 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)