block: New bdrv_set_buffer_alignment()

Device models should be able to set it without an unclean include of
block_int.h.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Markus Armbruster 2011-09-06 18:58:56 +02:00 committed by Kevin Wolf
parent fb0c61a5a5
commit 7b6f9300d5
5 changed files with 8 additions and 6 deletions

View File

@ -480,7 +480,6 @@ static int bdrv_open_common(BlockDriverState *bs, const char *filename,
bs->encrypted = 0;
bs->valid_key = 0;
bs->open_flags = flags;
/* buffer_alignment defaulted to 512, drivers can change this value */
bs->buffer_alignment = 512;
pstrcpy(bs->filename, sizeof(bs->filename), filename);
@ -3115,7 +3114,10 @@ BlockDriverAIOCB *bdrv_aio_ioctl(BlockDriverState *bs,
return NULL;
}
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align)
{
bs->buffer_alignment = align;
}
void *qemu_blockalign(BlockDriverState *bs, size_t size)
{

View File

@ -269,6 +269,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
const char *base_filename, const char *base_fmt,
char *options, uint64_t img_size, int flags);
void bdrv_set_buffer_alignment(BlockDriverState *bs, int align);
void *qemu_blockalign(BlockDriverState *bs, size_t size);
#define BDRV_SECTORS_PER_DIRTY_CHUNK 2048

View File

@ -1847,7 +1847,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
s->smart_selftest_count = 0;
if (kind == IDE_CD) {
bdrv_set_dev_ops(bs, &ide_cd_block_ops, s);
bs->buffer_alignment = 2048;
bdrv_set_buffer_alignment(bs, 2048);
} else {
if (!bdrv_is_inserted(s->bs)) {
error_report("Device needs media, but drive is empty");

View File

@ -1236,7 +1236,7 @@ static int scsi_initfn(SCSIDevice *dev, uint8_t scsi_type)
return -1;
}
s->cluster_size = s->qdev.blocksize / 512;
s->bs->buffer_alignment = s->qdev.blocksize;
bdrv_set_buffer_alignment(s->bs, s->qdev.blocksize);
s->qdev.type = scsi_type;
qemu_add_vm_change_state_handler(scsi_dma_restart_cb, s);

View File

@ -15,7 +15,6 @@
#include "qemu-error.h"
#include "trace.h"
#include "blockdev.h"
#include "block_int.h"
#include "virtio-blk.h"
#ifdef __linux__
# include <scsi/sg.h>
@ -601,7 +600,7 @@ VirtIODevice *virtio_blk_init(DeviceState *dev, BlockConf *conf,
register_savevm(dev, "virtio-blk", virtio_blk_id++, 2,
virtio_blk_save, virtio_blk_load, s);
bdrv_set_dev_ops(s->bs, &virtio_block_ops, s);
s->bs->buffer_alignment = conf->logical_block_size;
bdrv_set_buffer_alignment(s->bs, conf->logical_block_size);
add_boot_device_path(conf->bootindex, dev, "/disk@0,0");