virtio-blk: Leave disk geometry to compute in kernel

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
Cyrill Gorcunov
2015-06-01 16:39:41 +01:00
committed by Will Deacon
parent 6555ae851c
commit 1ef2738d03
3 changed files with 8 additions and 65 deletions
+8 -14
View File
@@ -52,9 +52,12 @@ static struct device device = {
/* VIRTIO_BLK_SIZE */
.blk_size = 4096,
},
.host_features = (1UL << VIRTIO_BLK_F_GEOMETRY)
| (1UL << VIRTIO_BLK_F_RO)
| (1UL << VIRTIO_BLK_F_BLK_SIZE),
/*
* Note we don't set VIRTIO_BLK_F_GEOMETRY here so the
* node kernel will compute disk geometry by own, the
* same applies to VIRTIO_BLK_F_BLK_SIZE
*/
.host_features = (1UL << VIRTIO_BLK_F_RO),
};
static bool virtio_blk_config_in(void *data, unsigned long offset, int size, uint32_t count)
@@ -232,17 +235,8 @@ static struct pci_device_header blk_virtio_pci_device = {
void blk_virtio__init(struct kvm *self)
{
/* update disk geometry */
if (self->disk_image) {
device.blk_config = (struct virtio_blk_config) {
.capacity = self->disk_image->size,
.geometry = (struct virtio_blk_geometry) {
.cylinders = self->disk_image->cylinders,
.heads = self->disk_image->heads,
.sectors = self->disk_image->sectors,
},
};
}
if (self->disk_image)
device.blk_config.capacity = self->disk_image->size;
pci__register(&blk_virtio_pci_device, 1);
-47
View File
@@ -14,48 +14,6 @@
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1UL << SECTOR_SHIFT)
static void setup_geometry(struct disk_image *self)
{
int cylinders, heads, sectors;
uint64_t total_sects;
/*
* Set the standart disk geometry of the image.
*
* Real disk example:
*
* Disk /dev/sda: 500.1 GB, 500107862016 bytes
* 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
*/
cylinders = (self->size >> SECTOR_SHIFT) / 16383;
if (cylinders > 16383)
cylinders = 16383;
else if (cylinders < 2)
cylinders = 2;
heads = (self->size >> SECTOR_SHIFT) / cylinders;
if (heads > 255)
heads = 255;
else if (heads < 1)
heads = 1;
sectors = (self->size >> SECTOR_SHIFT) / cylinders / heads;
if (sectors > 255)
sectors = 255;
else if (sectors < 1)
sectors = 1;
self->sectors = sectors;
self->heads = heads;
self->cylinders = cylinders;
total_sects = self->sectors * self->heads * self->cylinders;
if (total_sects != self->size >> SECTOR_SHIFT)
warning("Geometry information advertises %" PRIu64 " total sectors but raw image size has %" PRIu64 " sectors",
total_sects, self->size >> SECTOR_SHIFT);
}
struct disk_image *disk_image__open(const char *filename)
{
struct disk_image *self;
@@ -78,11 +36,6 @@ struct disk_image *disk_image__open(const char *filename)
if (self->mmap == MAP_FAILED)
goto failed_close_fd;
setup_geometry(self);
info("block image geometry: sectors: %d heads: %d cylinders: %d",
self->sectors, self->heads, self->cylinders);
return self;
failed_close_fd:
-4
View File
@@ -7,10 +7,6 @@ struct disk_image {
void *mmap;
int fd;
uint64_t size;
uint16_t cylinders;
uint8_t heads;
uint8_t sectors;
};
struct disk_image *disk_image__open(const char *filename);