Skip to contentSkip to conversation

geometry: Call backend function to detect geometry and blocksize

PATCH Superseded Ekaterina Tumanova 1 participant 1 message Nov 18, 2014 1 message not in the archive

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH v2 5/6 geometry: Call backend function to detect geometry and blocksize

copying to mail list

-------- Forwarded Message --------
Subject: [PATCH v2 5/6] geometry: Call backend function to detect geometry and blocksize
Date: Tue, 18 Nov 2014 17:10:00 +0100
From: Ekaterina Tumanova <[email protected]>
To: [email protected], [email protected], [email protected], [email protected]
CC: [email protected], [email protected], [email protected], [email protected], Ekaterina Tumanova <[email protected]>

hd_geometry_guess function autodetects the drive geometry. This patch adds a block backend call, that probes the backing device geometry. If the inner driver method is implemented and succeeds (currently only DASDs), the blkconf_geometry will pass-through the backing device geometry.

---
 hw/block/block.c         | 11 +++++++++++
 hw/block/hd-geometry.c   |  9 +++++++++
 hw/block/virtio-blk.c    |  1 +
 include/hw/block/block.h |  1 +
 4 files changed, 22 insertions(+)
hw/block/block.c +11 -0
index a625773..f1d29bc 100644
@@ -25,6 +25,17 @@ void blkconf_serial(BlockConf *conf, char **serial)
     }
 }
 
+void blkconf_blocksizes(BlockConf *conf)
+{
+    BlockBackend *blk = conf->blk;
+    struct ProbeBlockSize blocksize = blk_probe_blocksizes(blk);
+
+    if (blocksize.rc == 0) {
+        conf->physical_block_size = blocksize.size.phys;
+        conf->logical_block_size = blocksize.size.log;
+    }
+}
+
 void blkconf_geometry(BlockConf *conf, int *ptrans,
                       unsigned cyls_max, unsigned heads_max, unsigned 

secs_max,
Error **errp)

hw/block/hd-geometry.c +9 -0
index 6fcf74d..4972114 100644
@@ -121,6 +121,14 @@ void hd_geometry_guess(BlockBackend *blk,
                        int *ptrans)
 {
     int cylinders, heads, secs, translation;
+    struct ProbeGeometry geometry = blk_probe_geometry(blk);
+
+    if (geometry.rc == 0) {
+        *pcyls = geometry.geo.cylinders;
+        *psecs = geometry.geo.sectors;
+        *pheads = geometry.geo.heads;
+        goto done;
+    }
 
     if (guess_disk_lchs(blk, &cylinders, &heads, &secs) < 0) {
         /* no LCHS guess: use a standard physical disk geometry  */
@@ -143,6 +151,7 @@ void hd_geometry_guess(BlockBackend *blk,
            the logical geometry */
         translation = BIOS_ATA_TRANSLATION_NONE;
     }
+done:
     if (ptrans) {
         *ptrans = translation;
     }
hw/block/virtio-blk.c +1 -0
index b19b102..6f01565 100644
@@ -745,6 +745,7 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
         error_propagate(errp, err);
         return;
     }
+    blkconf_blocksizes(&conf->conf);
 
     virtio_init(vdev, "virtio-blk", VIRTIO_ID_BLOCK,
                 sizeof(struct virtio_blk_config));
include/hw/block/block.h +0 -0
index 0d0ce9a..856bf75 100644
@@ -63,6 +63,7 @@ void blkconf_serial(BlockConf *conf, char **serial);
 void blkconf_geometry(BlockConf *conf, int *trans,
                       unsigned cyls_max, unsigned heads_max, unsigned 

secs_max,

                       Error **errp);

+void blkconf_blocksizes(BlockConf *conf);

/* Hard disk geometry */

Signature · 1 line
1.8.5.5