Skip to content

Commit

Permalink
Merge remote branch 'kwolf/for-anthony' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Liguori committed Nov 30, 2010
2 parents 9233da7 + b76876e commit 09fa35e
Show file tree
Hide file tree
Showing 23 changed files with 234 additions and 245 deletions.
14 changes: 5 additions & 9 deletions block-migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ static int bmds_aio_inflight(BlkMigDevState *bmds, int64_t sector)
{
int64_t chunk = sector / (int64_t)BDRV_SECTORS_PER_DIRTY_CHUNK;

if (bmds->aio_bitmap &&
(sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
if ((sector << BDRV_SECTOR_BITS) < bdrv_getlength(bmds->bs)) {
return !!(bmds->aio_bitmap[chunk / (sizeof(unsigned long) * 8)] &
(1UL << (chunk % (sizeof(unsigned long) * 8))));
} else {
Expand All @@ -169,13 +168,9 @@ static void bmds_set_aio_inflight(BlkMigDevState *bmds, int64_t sector_num,
bit = start % (sizeof(unsigned long) * 8);
val = bmds->aio_bitmap[idx];
if (set) {
if (!(val & (1UL << bit))) {
val |= 1UL << bit;
}
val |= 1UL << bit;
} else {
if (val & (1UL << bit)) {
val &= ~(1UL << bit);
}
val &= ~(1UL << bit);
}
bmds->aio_bitmap[idx] = val;
}
Expand Down Expand Up @@ -385,8 +380,9 @@ static int mig_save_device_dirty(Monitor *mon, QEMUFile *f,
int nr_sectors;

for (sector = bmds->cur_dirty; sector < bmds->total_sectors;) {
if (bmds_aio_inflight(bmds, sector))
if (bmds_aio_inflight(bmds, sector)) {
qemu_aio_flush();
}
if (bdrv_get_dirty(bmds->bs, sector)) {

if (total_sectors - sector < BDRV_SECTORS_PER_DIRTY_CHUNK) {
Expand Down
1 change: 0 additions & 1 deletion block/qcow.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ typedef struct QCowHeader {
#define L2_CACHE_SIZE 16

typedef struct BDRVQcowState {
BlockDriverState *hd;
int cluster_bits;
int cluster_size;
int cluster_sectors;
Expand Down
1 change: 0 additions & 1 deletion block/qcow2.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ typedef struct QCowSnapshot {
} QCowSnapshot;

typedef struct BDRVQcowState {
BlockDriverState *hd;
int cluster_bits;
int cluster_size;
int cluster_sectors;
Expand Down
2 changes: 1 addition & 1 deletion block/raw-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ static int raw_pwrite(BlockDriverState *bs, int64_t offset,
count -= ret;
sum += ret;
}
/* here, count < 512 because (count & ~sector_mask) == 0 */
/* here, count < sector_size because (count & ~sector_mask) == 0 */
if (count) {
ret = raw_pread_aligned(bs, offset, s->aligned_buf,
bs->buffer_alignment);
Expand Down
1 change: 0 additions & 1 deletion block/vdi.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ typedef struct {
} VdiHeader;

typedef struct {
BlockDriverState *hd;
/* The block map entries are little endian (even in memory). */
uint32_t *bmap;
/* Size of block (bytes). */
Expand Down
1 change: 0 additions & 1 deletion block/vmdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ typedef struct {
#define L2_CACHE_SIZE 16

typedef struct BDRVVmdkState {
BlockDriverState *hd;
int64_t l1_table_offset;
int64_t l1_backup_table_offset;
uint32_t *l1_table;
Expand Down
2 changes: 0 additions & 2 deletions block/vpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,6 @@ struct vhd_dyndisk_header {
};

typedef struct BDRVVPCState {
BlockDriverState *hd;

uint8_t footer_buf[HEADER_SIZE];
uint64_t free_data_block_offset;
int max_table_entries;
Expand Down
39 changes: 39 additions & 0 deletions blockdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "qemu-option.h"
#include "qemu-config.h"
#include "sysemu.h"
#include "hw/qdev.h"
#include "block_int.h"

static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);

Expand Down Expand Up @@ -597,3 +599,40 @@ int do_change_block(Monitor *mon, const char *device,
}
return monitor_read_bdrv_key_start(mon, bs, NULL, NULL);
}

int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const char *id = qdict_get_str(qdict, "id");
BlockDriverState *bs;
BlockDriverState **ptr;
Property *prop;

bs = bdrv_find(id);
if (!bs) {
qerror_report(QERR_DEVICE_NOT_FOUND, id);
return -1;
}

/* quiesce block driver; prevent further io */
qemu_aio_flush();
bdrv_flush(bs);
bdrv_close(bs);

/* clean up guest state from pointing to host resource by
* finding and removing DeviceState "drive" property */
for (prop = bs->peer->info->props; prop && prop->name; prop++) {
if (prop->info->type == PROP_TYPE_DRIVE) {
ptr = qdev_get_prop_ptr(bs->peer, prop);
if ((*ptr) == bs) {
bdrv_detach(bs, bs->peer);
*ptr = NULL;
break;
}
}
}

/* clean up host side */
drive_uninit(drive_get_by_blockdev(bs));

return 0;
}
3 changes: 2 additions & 1 deletion blockdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct DriveInfo {
};

#define MAX_IDE_DEVS 2
#define MAX_SCSI_DEVS 7
#define MAX_SCSI_DEVS 255

DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
int drive_get_max_bus(BlockInterfaceType type);
Expand All @@ -51,5 +51,6 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_change_block(Monitor *mon, const char *device,
const char *filename, const char *fmt);
int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);

#endif
18 changes: 18 additions & 0 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ STEXI
@item eject [-f] @var{device}
@findex eject
Eject a removable medium (use -f to force it).
ETEXI

{
.name = "drive_del",
.args_type = "id:s",
.params = "device",
.help = "remove host block device",
.user_print = monitor_user_noop,
.mhandler.cmd_new = do_drive_del,
},

STEXI
@item drive_del @var{device}
@findex drive_del
Remove host block device. The result is that guest generated IO is no longer
submitted against the host device underlying the disk. Once a drive has
been deleted, the QEMU Block layer returns -EIO which results in IO
errors in the guest for applications that are reading/writing to the device.
ETEXI

{
Expand Down
8 changes: 2 additions & 6 deletions hw/ide/cmd646.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,8 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,
register_ioport_read(addr, 4, 1, bmdma_readb_1, d);
}

register_ioport_write(addr + 4, 4, 1, bmdma_addr_writeb, bm);
register_ioport_read(addr + 4, 4, 1, bmdma_addr_readb, bm);
register_ioport_write(addr + 4, 4, 2, bmdma_addr_writew, bm);
register_ioport_read(addr + 4, 4, 2, bmdma_addr_readw, bm);
register_ioport_write(addr + 4, 4, 4, bmdma_addr_writel, bm);
register_ioport_read(addr + 4, 4, 4, bmdma_addr_readl, bm);
iorange_init(&bm->addr_ioport, &bmdma_addr_ioport_ops, addr + 4, 4);
ioport_register(&bm->addr_ioport);
addr += 8;
}
}
Expand Down
31 changes: 15 additions & 16 deletions hw/ide/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,21 @@ static void dma_buf_commit(IDEState *s, int is_write)
qemu_sglist_destroy(&s->sg);
}

static void ide_dma_set_inactive(BMDMAState *bm)
{
bm->status &= ~BM_STATUS_DMAING;
bm->dma_cb = NULL;
bm->unit = -1;
bm->aiocb = NULL;
}

void ide_dma_error(IDEState *s)
{
ide_transfer_stop(s);
s->error = ABRT_ERR;
s->status = READY_STAT | ERR_STAT;
ide_dma_set_inactive(s->bus->bmdma);
s->bus->bmdma->status |= BM_STATUS_INT;
ide_set_irq(s->bus);
}

Expand Down Expand Up @@ -587,11 +597,8 @@ static void ide_read_dma_cb(void *opaque, int ret)
s->status = READY_STAT | SEEK_STAT;
ide_set_irq(s->bus);
eot:
bm->status &= ~BM_STATUS_DMAING;
bm->status |= BM_STATUS_INT;
bm->dma_cb = NULL;
bm->unit = -1;
bm->aiocb = NULL;
ide_dma_set_inactive(bm);
return;
}

Expand Down Expand Up @@ -733,11 +740,8 @@ static void ide_write_dma_cb(void *opaque, int ret)
s->status = READY_STAT | SEEK_STAT;
ide_set_irq(s->bus);
eot:
bm->status &= ~BM_STATUS_DMAING;
bm->status |= BM_STATUS_INT;
bm->dma_cb = NULL;
bm->unit = -1;
bm->aiocb = NULL;
ide_dma_set_inactive(bm);
return;
}

Expand Down Expand Up @@ -1061,11 +1065,8 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
s->nsector = (s->nsector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
ide_set_irq(s->bus);
eot:
bm->status &= ~BM_STATUS_DMAING;
bm->status |= BM_STATUS_INT;
bm->dma_cb = NULL;
bm->unit = -1;
bm->aiocb = NULL;
ide_dma_set_inactive(bm);
return;
}

Expand Down Expand Up @@ -2954,12 +2955,10 @@ void ide_dma_cancel(BMDMAState *bm)
printf("aio_cancel\n");
#endif
bdrv_aio_cancel(bm->aiocb);
bm->aiocb = NULL;
}
bm->status &= ~BM_STATUS_DMAING;

/* cancel DMA request */
bm->unit = -1;
bm->dma_cb = NULL;
ide_dma_set_inactive(bm);
}
}

Expand Down
2 changes: 2 additions & 0 deletions hw/ide/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#include <hw/ide.h>
#include "block_int.h"
#include "iorange.h"

/* debug IDE devices */
//#define DEBUG_IDE
Expand Down Expand Up @@ -496,6 +497,7 @@ struct BMDMAState {
QEMUIOVector qiov;
int64_t sector_num;
uint32_t nsector;
IORange addr_ioport;
QEMUBH *bh;
};

Expand Down
Loading

0 comments on commit 09fa35e

Please sign in to comment.