Loading async.c +16 −8 Original line number Diff line number Diff line Loading @@ -55,6 +55,9 @@ int qemu_bh_poll(void) { QEMUBH *bh, **bhp, *next; int ret; static int nesting = 0; nesting++; ret = 0; for (bh = first_bh; bh; bh = next) { Loading @@ -68,16 +71,21 @@ int qemu_bh_poll(void) } } nesting--; /* remove deleted bhs */ if (!nesting) { bhp = &first_bh; while (*bhp) { bh = *bhp; if (bh->deleted) { *bhp = bh->next; g_free(bh); } else } else { bhp = &bh->next; } } } return ret; } Loading block.c +56 −48 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <windows.h> #endif static void bdrv_dev_change_media_cb(BlockDriverState *bs); static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); Loading Loading @@ -688,10 +689,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, } if (!bdrv_key_required(bs)) { /* call the change callback */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } return 0; Loading Loading @@ -727,10 +725,7 @@ void bdrv_close(BlockDriverState *bs) bdrv_close(bs->file); } /* call the change callback */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } } Loading @@ -755,7 +750,7 @@ void bdrv_make_anon(BlockDriverState *bs) void bdrv_delete(BlockDriverState *bs) { assert(!bs->peer); assert(!bs->dev); /* remove from list, if necessary */ bdrv_make_anon(bs); Loading @@ -769,26 +764,58 @@ void bdrv_delete(BlockDriverState *bs) g_free(bs); } int bdrv_attach(BlockDriverState *bs, DeviceState *qdev) int bdrv_attach_dev(BlockDriverState *bs, void *dev) /* TODO change to DeviceState *dev when all users are qdevified */ { if (bs->peer) { if (bs->dev) { return -EBUSY; } bs->peer = qdev; bs->dev = dev; return 0; } void bdrv_detach(BlockDriverState *bs, DeviceState *qdev) /* TODO qdevified devices don't use this, remove when devices are qdevified */ void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev) { assert(bs->peer == qdev); bs->peer = NULL; bs->change_cb = NULL; bs->change_opaque = NULL; if (bdrv_attach_dev(bs, dev) < 0) { abort(); } } void bdrv_detach_dev(BlockDriverState *bs, void *dev) /* TODO change to DeviceState *dev when all users are qdevified */ { assert(bs->dev == dev); bs->dev = NULL; bs->dev_ops = NULL; bs->dev_opaque = NULL; } /* TODO change to return DeviceState * when all users are qdevified */ void *bdrv_get_attached_dev(BlockDriverState *bs) { return bs->dev; } DeviceState *bdrv_get_attached(BlockDriverState *bs) void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque) { return bs->peer; bs->dev_ops = ops; bs->dev_opaque = opaque; } static void bdrv_dev_change_media_cb(BlockDriverState *bs) { if (bs->dev_ops && bs->dev_ops->change_media_cb) { bs->dev_ops->change_media_cb(bs->dev_opaque); } } static void bdrv_dev_resize_cb(BlockDriverState *bs) { if (bs->dev_ops && bs->dev_ops->resize_cb) { bs->dev_ops->resize_cb(bs->dev_opaque); } } /* Loading Loading @@ -1261,9 +1288,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate(bs, offset); if (ret == 0) { ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); if (bs->change_cb) { bs->change_cb(bs->change_opaque, CHANGE_SIZE); } bdrv_dev_resize_cb(bs); } return ret; } Loading Loading @@ -1601,15 +1626,6 @@ int bdrv_enable_write_cache(BlockDriverState *bs) return bs->enable_write_cache; } /* XXX: no longer used */ void bdrv_set_change_cb(BlockDriverState *bs, void (*change_cb)(void *opaque, int reason), void *opaque) { bs->change_cb = change_cb; bs->change_opaque = opaque; } int bdrv_is_encrypted(BlockDriverState *bs) { if (bs->backing_hd && bs->backing_hd->encrypted) Loading Loading @@ -1647,9 +1663,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) } else if (!bs->valid_key) { bs->valid_key = 1; /* call the change callback now, we skipped it on open */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } return ret; } Loading Loading @@ -1739,8 +1753,7 @@ void bdrv_flush_all(void) BlockDriverState *bs; QTAILQ_FOREACH(bs, &bdrv_states, list) { if (bs->drv && !bdrv_is_read_only(bs) && (!bdrv_is_removable(bs) || bdrv_is_inserted(bs))) { if (!bdrv_is_read_only(bs) && bdrv_is_inserted(bs)) { bdrv_flush(bs); } } Loading Loading @@ -2084,7 +2097,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event) int bdrv_can_snapshot(BlockDriverState *bs) { BlockDriver *drv = bs->drv; if (!drv || bdrv_is_removable(bs) || bdrv_is_read_only(bs)) { if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { return 0; } Loading Loading @@ -3023,22 +3036,17 @@ int bdrv_is_inserted(BlockDriverState *bs) } /** * Return TRUE if the media changed since the last call to this * function. It is currently only used for floppy disks * Return whether the media changed since the last call to this * function, or -ENOTSUP if we don't know. Most drivers don't know. */ int bdrv_media_changed(BlockDriverState *bs) { BlockDriver *drv = bs->drv; int ret; if (!drv || !drv->bdrv_media_changed) ret = -ENOTSUP; else ret = drv->bdrv_media_changed(bs); if (ret == -ENOTSUP) ret = bs->media_changed; bs->media_changed = 0; return ret; if (drv && drv->bdrv_media_changed) { return drv->bdrv_media_changed(bs); } return -ENOTSUP; } /** Loading block.h +22 −6 Original line number Diff line number Diff line Loading @@ -28,6 +28,20 @@ typedef struct QEMUSnapshotInfo { uint64_t vm_clock_nsec; /* VM clock relative to boot */ } QEMUSnapshotInfo; /* Callbacks for block device models */ typedef struct BlockDevOps { /* * Runs when virtual media changed (monitor commands eject, change) * Beware: doesn't run when a host device's physical media * changes. Sure would be useful if it did. */ void (*change_media_cb)(void *opaque); /* * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); } BlockDevOps; #define BDRV_O_RDWR 0x0002 #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */ #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ Loading Loading @@ -74,9 +88,12 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); int bdrv_open(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv); void bdrv_close(BlockDriverState *bs); int bdrv_attach(BlockDriverState *bs, DeviceState *qdev); void bdrv_detach(BlockDriverState *bs, DeviceState *qdev); DeviceState *bdrv_get_attached(BlockDriverState *bs); int bdrv_attach_dev(BlockDriverState *bs, void *dev); void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev); void bdrv_detach_dev(BlockDriverState *bs, void *dev); void *bdrv_get_attached_dev(BlockDriverState *bs); void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num, Loading Loading @@ -192,9 +209,6 @@ int bdrv_media_changed(BlockDriverState *bs); int bdrv_is_locked(BlockDriverState *bs); void bdrv_set_locked(BlockDriverState *bs, int locked); int bdrv_eject(BlockDriverState *bs, int eject_flag); void bdrv_set_change_cb(BlockDriverState *bs, void (*change_cb)(void *opaque, int reason), void *opaque); void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size); BlockDriverState *bdrv_find(const char *name); BlockDriverState *bdrv_next(BlockDriverState *bs); Loading Loading @@ -244,6 +258,8 @@ 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 *qemu_blockalign(BlockDriverState *bs, size_t size); #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048 void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable); Loading block/qcow2.c +7 −5 Original line number Diff line number Diff line Loading @@ -526,13 +526,14 @@ static int qcow2_co_writev(BlockDriverState *bs, int n_end; int ret; int cur_nr_sectors; /* number of sectors in current iteration */ QCowL2Meta l2meta; uint64_t cluster_offset; QEMUIOVector hd_qiov; uint64_t bytes_done = 0; uint8_t *cluster_data = NULL; QCowL2Meta l2meta = { .nb_clusters = 0, }; l2meta.nb_clusters = 0; qemu_co_queue_init(&l2meta.dependent_requests); qemu_iovec_init(&hd_qiov, qiov->niov); Loading Loading @@ -592,13 +593,12 @@ static int qcow2_co_writev(BlockDriverState *bs, } ret = qcow2_alloc_cluster_link_l2(bs, &l2meta); run_dependent_requests(s, &l2meta); if (ret < 0) { goto fail; } run_dependent_requests(s, &l2meta); remaining_sectors -= cur_nr_sectors; sector_num += cur_nr_sectors; bytes_done += cur_nr_sectors * 512; Loading @@ -606,6 +606,8 @@ static int qcow2_co_writev(BlockDriverState *bs, ret = 0; fail: run_dependent_requests(s, &l2meta); qemu_co_mutex_unlock(&s->lock); qemu_iovec_destroy(&hd_qiov); Loading block/raw-posix.c +4 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,10 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, } #ifdef CONFIG_LINUX_AIO /* * Currently Linux do AIO only for files opened with O_DIRECT * specified so check NOCACHE flag too */ if ((bdrv_flags & (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) == (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) { Loading Loading
async.c +16 −8 Original line number Diff line number Diff line Loading @@ -55,6 +55,9 @@ int qemu_bh_poll(void) { QEMUBH *bh, **bhp, *next; int ret; static int nesting = 0; nesting++; ret = 0; for (bh = first_bh; bh; bh = next) { Loading @@ -68,16 +71,21 @@ int qemu_bh_poll(void) } } nesting--; /* remove deleted bhs */ if (!nesting) { bhp = &first_bh; while (*bhp) { bh = *bhp; if (bh->deleted) { *bhp = bh->next; g_free(bh); } else } else { bhp = &bh->next; } } } return ret; } Loading
block.c +56 −48 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ #include <windows.h> #endif static void bdrv_dev_change_media_cb(BlockDriverState *bs); static BlockDriverAIOCB *bdrv_aio_readv_em(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov, int nb_sectors, BlockDriverCompletionFunc *cb, void *opaque); Loading Loading @@ -688,10 +689,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, } if (!bdrv_key_required(bs)) { /* call the change callback */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } return 0; Loading Loading @@ -727,10 +725,7 @@ void bdrv_close(BlockDriverState *bs) bdrv_close(bs->file); } /* call the change callback */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } } Loading @@ -755,7 +750,7 @@ void bdrv_make_anon(BlockDriverState *bs) void bdrv_delete(BlockDriverState *bs) { assert(!bs->peer); assert(!bs->dev); /* remove from list, if necessary */ bdrv_make_anon(bs); Loading @@ -769,26 +764,58 @@ void bdrv_delete(BlockDriverState *bs) g_free(bs); } int bdrv_attach(BlockDriverState *bs, DeviceState *qdev) int bdrv_attach_dev(BlockDriverState *bs, void *dev) /* TODO change to DeviceState *dev when all users are qdevified */ { if (bs->peer) { if (bs->dev) { return -EBUSY; } bs->peer = qdev; bs->dev = dev; return 0; } void bdrv_detach(BlockDriverState *bs, DeviceState *qdev) /* TODO qdevified devices don't use this, remove when devices are qdevified */ void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev) { assert(bs->peer == qdev); bs->peer = NULL; bs->change_cb = NULL; bs->change_opaque = NULL; if (bdrv_attach_dev(bs, dev) < 0) { abort(); } } void bdrv_detach_dev(BlockDriverState *bs, void *dev) /* TODO change to DeviceState *dev when all users are qdevified */ { assert(bs->dev == dev); bs->dev = NULL; bs->dev_ops = NULL; bs->dev_opaque = NULL; } /* TODO change to return DeviceState * when all users are qdevified */ void *bdrv_get_attached_dev(BlockDriverState *bs) { return bs->dev; } DeviceState *bdrv_get_attached(BlockDriverState *bs) void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque) { return bs->peer; bs->dev_ops = ops; bs->dev_opaque = opaque; } static void bdrv_dev_change_media_cb(BlockDriverState *bs) { if (bs->dev_ops && bs->dev_ops->change_media_cb) { bs->dev_ops->change_media_cb(bs->dev_opaque); } } static void bdrv_dev_resize_cb(BlockDriverState *bs) { if (bs->dev_ops && bs->dev_ops->resize_cb) { bs->dev_ops->resize_cb(bs->dev_opaque); } } /* Loading Loading @@ -1261,9 +1288,7 @@ int bdrv_truncate(BlockDriverState *bs, int64_t offset) ret = drv->bdrv_truncate(bs, offset); if (ret == 0) { ret = refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); if (bs->change_cb) { bs->change_cb(bs->change_opaque, CHANGE_SIZE); } bdrv_dev_resize_cb(bs); } return ret; } Loading Loading @@ -1601,15 +1626,6 @@ int bdrv_enable_write_cache(BlockDriverState *bs) return bs->enable_write_cache; } /* XXX: no longer used */ void bdrv_set_change_cb(BlockDriverState *bs, void (*change_cb)(void *opaque, int reason), void *opaque) { bs->change_cb = change_cb; bs->change_opaque = opaque; } int bdrv_is_encrypted(BlockDriverState *bs) { if (bs->backing_hd && bs->backing_hd->encrypted) Loading Loading @@ -1647,9 +1663,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) } else if (!bs->valid_key) { bs->valid_key = 1; /* call the change callback now, we skipped it on open */ bs->media_changed = 1; if (bs->change_cb) bs->change_cb(bs->change_opaque, CHANGE_MEDIA); bdrv_dev_change_media_cb(bs); } return ret; } Loading Loading @@ -1739,8 +1753,7 @@ void bdrv_flush_all(void) BlockDriverState *bs; QTAILQ_FOREACH(bs, &bdrv_states, list) { if (bs->drv && !bdrv_is_read_only(bs) && (!bdrv_is_removable(bs) || bdrv_is_inserted(bs))) { if (!bdrv_is_read_only(bs) && bdrv_is_inserted(bs)) { bdrv_flush(bs); } } Loading Loading @@ -2084,7 +2097,7 @@ void bdrv_debug_event(BlockDriverState *bs, BlkDebugEvent event) int bdrv_can_snapshot(BlockDriverState *bs) { BlockDriver *drv = bs->drv; if (!drv || bdrv_is_removable(bs) || bdrv_is_read_only(bs)) { if (!drv || !bdrv_is_inserted(bs) || bdrv_is_read_only(bs)) { return 0; } Loading Loading @@ -3023,22 +3036,17 @@ int bdrv_is_inserted(BlockDriverState *bs) } /** * Return TRUE if the media changed since the last call to this * function. It is currently only used for floppy disks * Return whether the media changed since the last call to this * function, or -ENOTSUP if we don't know. Most drivers don't know. */ int bdrv_media_changed(BlockDriverState *bs) { BlockDriver *drv = bs->drv; int ret; if (!drv || !drv->bdrv_media_changed) ret = -ENOTSUP; else ret = drv->bdrv_media_changed(bs); if (ret == -ENOTSUP) ret = bs->media_changed; bs->media_changed = 0; return ret; if (drv && drv->bdrv_media_changed) { return drv->bdrv_media_changed(bs); } return -ENOTSUP; } /** Loading
block.h +22 −6 Original line number Diff line number Diff line Loading @@ -28,6 +28,20 @@ typedef struct QEMUSnapshotInfo { uint64_t vm_clock_nsec; /* VM clock relative to boot */ } QEMUSnapshotInfo; /* Callbacks for block device models */ typedef struct BlockDevOps { /* * Runs when virtual media changed (monitor commands eject, change) * Beware: doesn't run when a host device's physical media * changes. Sure would be useful if it did. */ void (*change_media_cb)(void *opaque); /* * Runs when the size changed (e.g. monitor command block_resize) */ void (*resize_cb)(void *opaque); } BlockDevOps; #define BDRV_O_RDWR 0x0002 #define BDRV_O_SNAPSHOT 0x0008 /* open the file read only and save writes in a snapshot */ #define BDRV_O_NOCACHE 0x0020 /* do not use the host page cache */ Loading Loading @@ -74,9 +88,12 @@ int bdrv_file_open(BlockDriverState **pbs, const char *filename, int flags); int bdrv_open(BlockDriverState *bs, const char *filename, int flags, BlockDriver *drv); void bdrv_close(BlockDriverState *bs); int bdrv_attach(BlockDriverState *bs, DeviceState *qdev); void bdrv_detach(BlockDriverState *bs, DeviceState *qdev); DeviceState *bdrv_get_attached(BlockDriverState *bs); int bdrv_attach_dev(BlockDriverState *bs, void *dev); void bdrv_attach_dev_nofail(BlockDriverState *bs, void *dev); void bdrv_detach_dev(BlockDriverState *bs, void *dev); void *bdrv_get_attached_dev(BlockDriverState *bs); void bdrv_set_dev_ops(BlockDriverState *bs, const BlockDevOps *ops, void *opaque); int bdrv_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_sectors); int bdrv_write(BlockDriverState *bs, int64_t sector_num, Loading Loading @@ -192,9 +209,6 @@ int bdrv_media_changed(BlockDriverState *bs); int bdrv_is_locked(BlockDriverState *bs); void bdrv_set_locked(BlockDriverState *bs, int locked); int bdrv_eject(BlockDriverState *bs, int eject_flag); void bdrv_set_change_cb(BlockDriverState *bs, void (*change_cb)(void *opaque, int reason), void *opaque); void bdrv_get_format(BlockDriverState *bs, char *buf, int buf_size); BlockDriverState *bdrv_find(const char *name); BlockDriverState *bdrv_next(BlockDriverState *bs); Loading Loading @@ -244,6 +258,8 @@ 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 *qemu_blockalign(BlockDriverState *bs, size_t size); #define BDRV_SECTORS_PER_DIRTY_CHUNK 2048 void bdrv_set_dirty_tracking(BlockDriverState *bs, int enable); Loading
block/qcow2.c +7 −5 Original line number Diff line number Diff line Loading @@ -526,13 +526,14 @@ static int qcow2_co_writev(BlockDriverState *bs, int n_end; int ret; int cur_nr_sectors; /* number of sectors in current iteration */ QCowL2Meta l2meta; uint64_t cluster_offset; QEMUIOVector hd_qiov; uint64_t bytes_done = 0; uint8_t *cluster_data = NULL; QCowL2Meta l2meta = { .nb_clusters = 0, }; l2meta.nb_clusters = 0; qemu_co_queue_init(&l2meta.dependent_requests); qemu_iovec_init(&hd_qiov, qiov->niov); Loading Loading @@ -592,13 +593,12 @@ static int qcow2_co_writev(BlockDriverState *bs, } ret = qcow2_alloc_cluster_link_l2(bs, &l2meta); run_dependent_requests(s, &l2meta); if (ret < 0) { goto fail; } run_dependent_requests(s, &l2meta); remaining_sectors -= cur_nr_sectors; sector_num += cur_nr_sectors; bytes_done += cur_nr_sectors * 512; Loading @@ -606,6 +606,8 @@ static int qcow2_co_writev(BlockDriverState *bs, ret = 0; fail: run_dependent_requests(s, &l2meta); qemu_co_mutex_unlock(&s->lock); qemu_iovec_destroy(&hd_qiov); Loading
block/raw-posix.c +4 −0 Original line number Diff line number Diff line Loading @@ -236,6 +236,10 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, } #ifdef CONFIG_LINUX_AIO /* * Currently Linux do AIO only for files opened with O_DIRECT * specified so check NOCACHE flag too */ if ((bdrv_flags & (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) == (BDRV_O_NOCACHE|BDRV_O_NATIVE_AIO)) { Loading