Patchwork Fix block_resize command for ide disks.

login
register
mail settings
Submitter Eduardo Warszawski
Date April 22, 2013, 9:56 a.m.
Message ID <201304231308.r3ND8Evu017491@int-mx12.intmail.prod.int.phx2.redhat.com>
Download mbox | patch
Permalink /patch/239018/
State New
Headers show

Comments

Eduardo Warszawski - April 22, 2013, 9:56 a.m.
Add ide disk resize callback in order to update disk's nb_sectors
after resize.

rhbz #852348

Signed-off-by: Eduardo Warszawski <ewarszaw@redhat.com>
---
 hw/ide/core.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Patch

diff --git a/hw/ide/core.c b/hw/ide/core.c
index c7a8041..023abb1 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -871,6 +871,19 @@  static void ide_cfata_metadata_write(IDEState *s)
                                     s->nsector << 9), 0x200 - 2));
 }
 
+/* called when the disk size is changed. */
+static void ide_resize_cb(void *opaque)
+{
+    IDEState *s = opaque;
+    uint64_t nb_sectors;
+
+    bdrv_get_geometry(s->bs, &nb_sectors);
+    if (s->nb_sectors != nb_sectors) {
+        s->nb_sectors = nb_sectors;
+        s->identify_set = 0;
+    }
+}
+
 /* called when the inserted state of the media has changed */
 static void ide_cd_change_cb(void *opaque, bool load)
 {
@@ -1964,6 +1977,10 @@  static bool ide_cd_is_medium_locked(void *opaque)
     return ((IDEState *)opaque)->tray_locked;
 }
 
+static const BlockDevOps ide_hd_block_ops = {
+    .resize_cb = ide_resize_cb,
+};
+
 static const BlockDevOps ide_cd_block_ops = {
     .change_media_cb = ide_cd_change_cb,
     .eject_request_cb = ide_cd_eject_request_cb,
@@ -2007,6 +2024,7 @@  int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
             error_report("Can't use a read-only drive");
             return -1;
         }
+        bdrv_set_dev_ops(bs, &ide_hd_block_ops, s);
     }
     if (serial) {
         pstrcpy(s->drive_serial_str, sizeof(s->drive_serial_str), serial);