mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-09-06 21:51:49 +00:00
kvm: Setup disk geometry if needed
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
This commit is contained in:
committed by
Will Deacon
parent
5a24a9f279
commit
ca7c891bfe
+9
-1
@@ -230,8 +230,16 @@ static struct pci_device_header blk_virtio_pci_device = {
|
||||
.irq_line = VIRTIO_BLK_IRQ,
|
||||
};
|
||||
|
||||
void blk_virtio__init(void)
|
||||
void blk_virtio__init(struct kvm *self)
|
||||
{
|
||||
/* update disk geometry */
|
||||
if (self->disk_image) {
|
||||
device.blk_config.capacity = self->disk_image->size;
|
||||
device.blk_config.geometry.cylinders = self->disk_image->cylinders;
|
||||
device.blk_config.geometry.heads = self->disk_image->heads;
|
||||
device.blk_config.geometry.sectors = self->disk_image->sectors;
|
||||
}
|
||||
|
||||
pci__register(&blk_virtio_pci_device, 1);
|
||||
|
||||
ioport__register(IOPORT_VIRTIO, &blk_virtio_io_ops, 256);
|
||||
|
||||
@@ -17,6 +17,7 @@ struct disk_image *disk_image__open(const char *filename)
|
||||
{
|
||||
struct disk_image *self;
|
||||
struct stat st;
|
||||
int cylinders, heads, sectors;
|
||||
|
||||
self = malloc(sizeof *self);
|
||||
if (!self)
|
||||
@@ -35,6 +36,36 @@ struct disk_image *disk_image__open(const char *filename)
|
||||
if (self->mmap == MAP_FAILED)
|
||||
goto failed_close_fd;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
info("block image geometry: sectors: %d heads: %d cylinders: %d",
|
||||
sectors, heads, cylinders);
|
||||
|
||||
return self;
|
||||
|
||||
failed_close_fd:
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef KVM__BLK_VIRTIO_H
|
||||
#define KVM__BLK_VIRTIO_H
|
||||
|
||||
void blk_virtio__init(void);
|
||||
struct kvm;
|
||||
|
||||
void blk_virtio__init(struct kvm *self);
|
||||
|
||||
#endif /* KVM__BLK_VIRTIO_H */
|
||||
|
||||
@@ -7,6 +7,10 @@ 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);
|
||||
|
||||
Reference in New Issue
Block a user