mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches # gpg: Signature made Wed 30 Mar 2016 11:57:54 BST using RSA key ID C88F2FD6 # gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" * remotes/kevin/tags/for-upstream: (48 commits) iotests: Test qemu-img convert -S 0 behavior block/null-{co,aio}: Implement get_block_status() block/null-{co,aio}: Allow reading zeroes qemu-img: Fix preallocation with -S 0 for convert block: Remove bdrv_(set_)enable_write_cache() block: Remove BDRV_O_CACHE_WB block: Remove bdrv_parse_cache_flags() qemu-io: Use bdrv_parse_cache_mode() in reopen_f() block: Use bdrv_parse_cache_mode() in drive_init() raw: Support BDRV_REQ_FUA nbd: Support BDRV_REQ_FUA iscsi: Support BDRV_REQ_FUA block: Introduce bdrv_co_writev_flags() block/qapi: Use blk_enable_write_cache() block: Move enable_write_cache to BB level block: Handle flush error in bdrv_pwrite_sync() block: Always set writeback mode in blk_new_open() block: blockdev_init(): Call blk_set_enable_write_cache() explicitly xen_disk: Call blk_set_enable_write_cache() explicitly qemu-img: Call blk_set_enable_write_cache() explicitly ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
@@ -289,6 +289,11 @@ static int bdrv_is_whitelisted(BlockDriver *drv, bool read_only)
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool bdrv_uses_whitelist(void)
|
||||
{
|
||||
return use_bdrv_whitelist;
|
||||
}
|
||||
|
||||
typedef struct CreateCo {
|
||||
BlockDriver *drv;
|
||||
char *filename;
|
||||
@@ -640,21 +645,23 @@ int bdrv_parse_discard_flags(const char *mode, int *flags)
|
||||
*
|
||||
* Return 0 on success, -1 if the cache mode was invalid.
|
||||
*/
|
||||
int bdrv_parse_cache_flags(const char *mode, int *flags)
|
||||
int bdrv_parse_cache_mode(const char *mode, int *flags, bool *writethrough)
|
||||
{
|
||||
*flags &= ~BDRV_O_CACHE_MASK;
|
||||
|
||||
if (!strcmp(mode, "off") || !strcmp(mode, "none")) {
|
||||
*flags |= BDRV_O_NOCACHE | BDRV_O_CACHE_WB;
|
||||
*writethrough = false;
|
||||
*flags |= BDRV_O_NOCACHE;
|
||||
} else if (!strcmp(mode, "directsync")) {
|
||||
*writethrough = true;
|
||||
*flags |= BDRV_O_NOCACHE;
|
||||
} else if (!strcmp(mode, "writeback")) {
|
||||
*flags |= BDRV_O_CACHE_WB;
|
||||
*writethrough = false;
|
||||
} else if (!strcmp(mode, "unsafe")) {
|
||||
*flags |= BDRV_O_CACHE_WB;
|
||||
*writethrough = false;
|
||||
*flags |= BDRV_O_NO_FLUSH;
|
||||
} else if (!strcmp(mode, "writethrough")) {
|
||||
/* this is the default */
|
||||
*writethrough = true;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
@@ -673,7 +680,6 @@ static void bdrv_temp_snapshot_options(int *child_flags, QDict *child_options,
|
||||
*child_flags = (parent_flags & ~BDRV_O_SNAPSHOT) | BDRV_O_TEMPORARY;
|
||||
|
||||
/* For temporary files, unconditional cache=unsafe is fine */
|
||||
qdict_set_default_str(child_options, BDRV_OPT_CACHE_WB, "on");
|
||||
qdict_set_default_str(child_options, BDRV_OPT_CACHE_DIRECT, "off");
|
||||
qdict_set_default_str(child_options, BDRV_OPT_CACHE_NO_FLUSH, "on");
|
||||
}
|
||||
@@ -698,11 +704,11 @@ static void bdrv_inherited_options(int *child_flags, QDict *child_options,
|
||||
/* Our block drivers take care to send flushes and respect unmap policy,
|
||||
* so we can default to enable both on lower layers regardless of the
|
||||
* corresponding parent options. */
|
||||
qdict_set_default_str(child_options, BDRV_OPT_CACHE_WB, "on");
|
||||
flags |= BDRV_O_UNMAP;
|
||||
|
||||
/* Clear flags that only apply to the top layer */
|
||||
flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ);
|
||||
flags &= ~(BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING | BDRV_O_COPY_ON_READ |
|
||||
BDRV_O_NO_IO);
|
||||
|
||||
*child_flags = flags;
|
||||
}
|
||||
@@ -722,7 +728,7 @@ static void bdrv_inherited_fmt_options(int *child_flags, QDict *child_options,
|
||||
child_file.inherit_options(child_flags, child_options,
|
||||
parent_flags, parent_options);
|
||||
|
||||
*child_flags &= ~BDRV_O_PROTOCOL;
|
||||
*child_flags &= ~(BDRV_O_PROTOCOL | BDRV_O_NO_IO);
|
||||
}
|
||||
|
||||
const BdrvChildRole child_format = {
|
||||
@@ -738,8 +744,8 @@ static void bdrv_backing_options(int *child_flags, QDict *child_options,
|
||||
{
|
||||
int flags = parent_flags;
|
||||
|
||||
/* The cache mode is inherited unmodified for backing files */
|
||||
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_WB);
|
||||
/* The cache mode is inherited unmodified for backing files; except WCE,
|
||||
* which is only applied on the top level (BlockBackend) */
|
||||
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_DIRECT);
|
||||
qdict_copy_default(child_options, parent_options, BDRV_OPT_CACHE_NO_FLUSH);
|
||||
|
||||
@@ -758,7 +764,7 @@ static const BdrvChildRole child_backing = {
|
||||
|
||||
static int bdrv_open_flags(BlockDriverState *bs, int flags)
|
||||
{
|
||||
int open_flags = flags | BDRV_O_CACHE_WB;
|
||||
int open_flags = flags;
|
||||
|
||||
/*
|
||||
* Clear flags that are internal to the block layer before opening the
|
||||
@@ -780,11 +786,6 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
|
||||
{
|
||||
*flags &= ~BDRV_O_CACHE_MASK;
|
||||
|
||||
assert(qemu_opt_find(opts, BDRV_OPT_CACHE_WB));
|
||||
if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_WB, false)) {
|
||||
*flags |= BDRV_O_CACHE_WB;
|
||||
}
|
||||
|
||||
assert(qemu_opt_find(opts, BDRV_OPT_CACHE_NO_FLUSH));
|
||||
if (qemu_opt_get_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, false)) {
|
||||
*flags |= BDRV_O_NO_FLUSH;
|
||||
@@ -798,10 +799,6 @@ static void update_flags_from_options(int *flags, QemuOpts *opts)
|
||||
|
||||
static void update_options_from_flags(QDict *options, int flags)
|
||||
{
|
||||
if (!qdict_haskey(options, BDRV_OPT_CACHE_WB)) {
|
||||
qdict_put(options, BDRV_OPT_CACHE_WB,
|
||||
qbool_from_bool(flags & BDRV_O_CACHE_WB));
|
||||
}
|
||||
if (!qdict_haskey(options, BDRV_OPT_CACHE_DIRECT)) {
|
||||
qdict_put(options, BDRV_OPT_CACHE_DIRECT,
|
||||
qbool_from_bool(flags & BDRV_O_NOCACHE));
|
||||
@@ -863,11 +860,6 @@ static QemuOptsList bdrv_runtime_opts = {
|
||||
.type = QEMU_OPT_STRING,
|
||||
.help = "Block driver to use for the node",
|
||||
},
|
||||
{
|
||||
.name = BDRV_OPT_CACHE_WB,
|
||||
.type = QEMU_OPT_BOOL,
|
||||
.help = "Enable writeback mode",
|
||||
},
|
||||
{
|
||||
.name = BDRV_OPT_CACHE_DIRECT,
|
||||
.type = QEMU_OPT_BOOL,
|
||||
@@ -974,7 +966,6 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
|
||||
|
||||
/* Apply cache mode options */
|
||||
update_flags_from_options(&bs->open_flags, opts);
|
||||
bdrv_set_enable_write_cache(bs, bs->open_flags & BDRV_O_CACHE_WB);
|
||||
|
||||
/* Open the image, either directly or using a protocol */
|
||||
open_flags = bdrv_open_flags(bs, bs->open_flags);
|
||||
@@ -1004,13 +995,6 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
if (bs->encrypted) {
|
||||
error_report("Encrypted images are deprecated");
|
||||
error_printf("Support for them will be removed in a future release.\n"
|
||||
"You can use 'qemu-img convert' to convert your image"
|
||||
" to an unencrypted one.\n");
|
||||
}
|
||||
|
||||
ret = refresh_total_sectors(bs, bs->total_sectors);
|
||||
if (ret < 0) {
|
||||
error_setg_errno(errp, -ret, "Could not refresh total sector count");
|
||||
@@ -2004,17 +1988,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue,
|
||||
|
||||
update_flags_from_options(&reopen_state->flags, opts);
|
||||
|
||||
/* If a guest device is attached, it owns WCE */
|
||||
if (reopen_state->bs->blk && blk_get_attached_dev(reopen_state->bs->blk)) {
|
||||
bool old_wce = bdrv_enable_write_cache(reopen_state->bs);
|
||||
bool new_wce = (reopen_state->flags & BDRV_O_CACHE_WB);
|
||||
if (old_wce != new_wce) {
|
||||
error_setg(errp, "Cannot change cache.writeback: Device attached");
|
||||
ret = -EINVAL;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
/* node-name and driver must be unchanged. Put them back into the QDict, so
|
||||
* that they are checked at the end of this function. */
|
||||
value = qemu_opt_get(opts, "node-name");
|
||||
@@ -2114,8 +2087,6 @@ void bdrv_reopen_commit(BDRVReopenState *reopen_state)
|
||||
|
||||
reopen_state->bs->explicit_options = reopen_state->explicit_options;
|
||||
reopen_state->bs->open_flags = reopen_state->flags;
|
||||
reopen_state->bs->enable_write_cache = !!(reopen_state->flags &
|
||||
BDRV_O_CACHE_WB);
|
||||
reopen_state->bs->read_only = !(reopen_state->flags & BDRV_O_RDWR);
|
||||
|
||||
bdrv_refresh_limits(reopen_state->bs, NULL);
|
||||
@@ -2242,29 +2213,11 @@ void bdrv_close_all(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* make a BlockDriverState anonymous by removing from graph_bdrv_state list.
|
||||
* Also, NULL terminate the device_name to prevent double remove */
|
||||
void bdrv_make_anon(BlockDriverState *bs)
|
||||
{
|
||||
if (bs->node_name[0] != '\0') {
|
||||
QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list);
|
||||
}
|
||||
bs->node_name[0] = '\0';
|
||||
}
|
||||
|
||||
/* Fields that need to stay with the top-level BDS */
|
||||
static void bdrv_move_feature_fields(BlockDriverState *bs_dest,
|
||||
BlockDriverState *bs_src)
|
||||
{
|
||||
/* move some fields that need to stay attached to the device */
|
||||
|
||||
/* dev info */
|
||||
bs_dest->copy_on_read = bs_src->copy_on_read;
|
||||
|
||||
bs_dest->enable_write_cache = bs_src->enable_write_cache;
|
||||
|
||||
/* dirty bitmap */
|
||||
bs_dest->dirty_bitmaps = bs_src->dirty_bitmaps;
|
||||
}
|
||||
|
||||
static void change_parent_backing_link(BlockDriverState *from,
|
||||
@@ -2381,8 +2334,9 @@ static void bdrv_delete(BlockDriverState *bs)
|
||||
bdrv_close(bs);
|
||||
|
||||
/* remove from list, if necessary */
|
||||
bdrv_make_anon(bs);
|
||||
|
||||
if (bs->node_name[0] != '\0') {
|
||||
QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list);
|
||||
}
|
||||
QTAILQ_REMOVE(&all_bdrv_states, bs, bs_list);
|
||||
|
||||
g_free(bs);
|
||||
@@ -2741,23 +2695,6 @@ int bdrv_is_sg(BlockDriverState *bs)
|
||||
return bs->sg;
|
||||
}
|
||||
|
||||
int bdrv_enable_write_cache(BlockDriverState *bs)
|
||||
{
|
||||
return bs->enable_write_cache;
|
||||
}
|
||||
|
||||
void bdrv_set_enable_write_cache(BlockDriverState *bs, bool wce)
|
||||
{
|
||||
bs->enable_write_cache = wce;
|
||||
|
||||
/* so a reopen() will preserve wce */
|
||||
if (wce) {
|
||||
bs->open_flags |= BDRV_O_CACHE_WB;
|
||||
} else {
|
||||
bs->open_flags &= ~BDRV_O_CACHE_WB;
|
||||
}
|
||||
}
|
||||
|
||||
int bdrv_is_encrypted(BlockDriverState *bs)
|
||||
{
|
||||
if (bs->backing && bs->backing->bs->encrypted) {
|
||||
@@ -2899,7 +2836,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(Error **errp)
|
||||
|
||||
list = NULL;
|
||||
QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) {
|
||||
BlockDeviceInfo *info = bdrv_block_device_info(bs, errp);
|
||||
BlockDeviceInfo *info = bdrv_block_device_info(NULL, bs, errp);
|
||||
if (!info) {
|
||||
qapi_free_BlockDeviceInfoList(list);
|
||||
return NULL;
|
||||
@@ -3608,8 +3545,8 @@ void bdrv_img_create(const char *filename, const char *fmt,
|
||||
}
|
||||
|
||||
/* backing files always opened read-only */
|
||||
back_flags =
|
||||
flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
|
||||
back_flags = flags;
|
||||
back_flags &= ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BACKING);
|
||||
|
||||
if (backing_fmt) {
|
||||
backing_options = qdict_new();
|
||||
|
||||
+3
-1
@@ -4,7 +4,7 @@ block-obj-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
|
||||
block-obj-y += qed-check.o
|
||||
block-obj-$(CONFIG_VHDX) += vhdx.o vhdx-endian.o vhdx-log.o
|
||||
block-obj-y += quorum.o
|
||||
block-obj-y += parallels.o blkdebug.o blkverify.o
|
||||
block-obj-y += parallels.o blkdebug.o blkverify.o blkreplay.o
|
||||
block-obj-y += block-backend.o snapshot.o qapi.o
|
||||
block-obj-$(CONFIG_WIN32) += raw-win32.o win32-aio.o
|
||||
block-obj-$(CONFIG_POSIX) += raw-posix.o
|
||||
@@ -23,6 +23,8 @@ block-obj-$(CONFIG_LIBSSH2) += ssh.o
|
||||
block-obj-y += accounting.o dirty-bitmap.o
|
||||
block-obj-y += write-threshold.o
|
||||
|
||||
block-obj-y += crypto.o
|
||||
|
||||
common-obj-y += stream.o
|
||||
common-obj-y += commit.o
|
||||
common-obj-y += backup.o
|
||||
|
||||
@@ -404,7 +404,6 @@ static void coroutine_fn backup_run(void *opaque)
|
||||
|
||||
job->done_bitmap = bitmap_new(end);
|
||||
|
||||
bdrv_set_enable_write_cache(target, true);
|
||||
if (target->blk) {
|
||||
blk_set_on_error(target->blk, on_target_error, on_target_error);
|
||||
blk_iostatus_enable(target->blk);
|
||||
|
||||
Executable
+160
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Block protocol for record/replay
|
||||
*
|
||||
* Copyright (c) 2010-2016 Institute for System Programming
|
||||
* of the Russian Academy of Sciences.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
||||
* See the COPYING file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "block/block_int.h"
|
||||
#include "sysemu/replay.h"
|
||||
#include "qapi/error.h"
|
||||
|
||||
typedef struct Request {
|
||||
Coroutine *co;
|
||||
QEMUBH *bh;
|
||||
} Request;
|
||||
|
||||
/* Next request id.
|
||||
This counter is global, because requests from different
|
||||
block devices should not get overlapping ids. */
|
||||
static uint64_t request_id;
|
||||
|
||||
static int blkreplay_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
Error **errp)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
/* Open the image file */
|
||||
bs->file = bdrv_open_child(NULL, options, "image",
|
||||
bs, &child_file, false, &local_err);
|
||||
if (local_err) {
|
||||
ret = -EINVAL;
|
||||
error_propagate(errp, local_err);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
fail:
|
||||
if (ret < 0) {
|
||||
bdrv_unref_child(bs, bs->file);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void blkreplay_close(BlockDriverState *bs)
|
||||
{
|
||||
}
|
||||
|
||||
static int64_t blkreplay_getlength(BlockDriverState *bs)
|
||||
{
|
||||
return bdrv_getlength(bs->file->bs);
|
||||
}
|
||||
|
||||
/* This bh is used for synchronization of return from coroutines.
|
||||
It continues yielded coroutine which then finishes its execution.
|
||||
BH is called adjusted to some replay checkpoint, therefore
|
||||
record and replay will always finish coroutines deterministically.
|
||||
*/
|
||||
static void blkreplay_bh_cb(void *opaque)
|
||||
{
|
||||
Request *req = opaque;
|
||||
qemu_coroutine_enter(req->co, NULL);
|
||||
qemu_bh_delete(req->bh);
|
||||
g_free(req);
|
||||
}
|
||||
|
||||
static void block_request_create(uint64_t reqid, BlockDriverState *bs,
|
||||
Coroutine *co)
|
||||
{
|
||||
Request *req = g_new(Request, 1);
|
||||
*req = (Request) {
|
||||
.co = co,
|
||||
.bh = aio_bh_new(bdrv_get_aio_context(bs), blkreplay_bh_cb, req),
|
||||
};
|
||||
replay_block_event(req->bh, reqid);
|
||||
}
|
||||
|
||||
static int coroutine_fn blkreplay_co_readv(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
|
||||
{
|
||||
uint64_t reqid = request_id++;
|
||||
int ret = bdrv_co_readv(bs->file->bs, sector_num, nb_sectors, qiov);
|
||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn blkreplay_co_writev(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, QEMUIOVector *qiov)
|
||||
{
|
||||
uint64_t reqid = request_id++;
|
||||
int ret = bdrv_co_writev(bs->file->bs, sector_num, nb_sectors, qiov);
|
||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn blkreplay_co_write_zeroes(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors, BdrvRequestFlags flags)
|
||||
{
|
||||
uint64_t reqid = request_id++;
|
||||
int ret = bdrv_co_write_zeroes(bs->file->bs, sector_num, nb_sectors, flags);
|
||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn blkreplay_co_discard(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
{
|
||||
uint64_t reqid = request_id++;
|
||||
int ret = bdrv_co_discard(bs->file->bs, sector_num, nb_sectors);
|
||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs)
|
||||
{
|
||||
uint64_t reqid = request_id++;
|
||||
int ret = bdrv_co_flush(bs->file->bs);
|
||||
block_request_create(reqid, bs, qemu_coroutine_self());
|
||||
qemu_coroutine_yield();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BlockDriver bdrv_blkreplay = {
|
||||
.format_name = "blkreplay",
|
||||
.protocol_name = "blkreplay",
|
||||
.instance_size = 0,
|
||||
|
||||
.bdrv_file_open = blkreplay_open,
|
||||
.bdrv_close = blkreplay_close,
|
||||
.bdrv_getlength = blkreplay_getlength,
|
||||
|
||||
.bdrv_co_readv = blkreplay_co_readv,
|
||||
.bdrv_co_writev = blkreplay_co_writev,
|
||||
|
||||
.bdrv_co_write_zeroes = blkreplay_co_write_zeroes,
|
||||
.bdrv_co_discard = blkreplay_co_discard,
|
||||
.bdrv_co_flush = blkreplay_co_flush,
|
||||
};
|
||||
|
||||
static void bdrv_blkreplay_init(void)
|
||||
{
|
||||
bdrv_register(&bdrv_blkreplay);
|
||||
}
|
||||
|
||||
block_init(bdrv_blkreplay_init);
|
||||
+25
-37
@@ -47,6 +47,8 @@ struct BlockBackend {
|
||||
* can be used to restore those options in the new BDS on insert) */
|
||||
BlockBackendRootState root_state;
|
||||
|
||||
bool enable_write_cache;
|
||||
|
||||
/* I/O stats (display with "info blockstats"). */
|
||||
BlockAcctStats stats;
|
||||
|
||||
@@ -160,6 +162,8 @@ BlockBackend *blk_new_open(const char *filename, const char *reference,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
blk_set_enable_write_cache(blk, true);
|
||||
|
||||
return blk;
|
||||
}
|
||||
|
||||
@@ -371,23 +375,6 @@ BlockDriverState *blk_bs(BlockBackend *blk)
|
||||
return blk->root ? blk->root->bs : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Changes the BlockDriverState attached to @blk
|
||||
*/
|
||||
void blk_set_bs(BlockBackend *blk, BlockDriverState *bs)
|
||||
{
|
||||
bdrv_ref(bs);
|
||||
|
||||
if (blk->root) {
|
||||
blk->root->bs->blk = NULL;
|
||||
bdrv_root_unref_child(blk->root);
|
||||
}
|
||||
assert(bs->blk == NULL);
|
||||
|
||||
blk->root = bdrv_root_attach_child(bs, "root", &child_root);
|
||||
bs->blk = blk;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return @blk's DriveInfo if any, else null.
|
||||
*/
|
||||
@@ -712,11 +699,17 @@ static int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
|
||||
unsigned int bytes, QEMUIOVector *qiov,
|
||||
BdrvRequestFlags flags)
|
||||
{
|
||||
int ret = blk_check_byte_request(blk, offset, bytes);
|
||||
int ret;
|
||||
|
||||
ret = blk_check_byte_request(blk, offset, bytes);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!blk->enable_write_cache) {
|
||||
flags |= BDRV_REQ_FUA;
|
||||
}
|
||||
|
||||
return bdrv_co_do_pwritev(blk_bs(blk), offset, bytes, qiov, flags);
|
||||
}
|
||||
|
||||
@@ -1223,28 +1216,12 @@ int blk_is_sg(BlockBackend *blk)
|
||||
|
||||
int blk_enable_write_cache(BlockBackend *blk)
|
||||
{
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
|
||||
if (bs) {
|
||||
return bdrv_enable_write_cache(bs);
|
||||
} else {
|
||||
return !!(blk->root_state.open_flags & BDRV_O_CACHE_WB);
|
||||
}
|
||||
return blk->enable_write_cache;
|
||||
}
|
||||
|
||||
void blk_set_enable_write_cache(BlockBackend *blk, bool wce)
|
||||
{
|
||||
BlockDriverState *bs = blk_bs(blk);
|
||||
|
||||
if (bs) {
|
||||
bdrv_set_enable_write_cache(bs, wce);
|
||||
} else {
|
||||
if (wce) {
|
||||
blk->root_state.open_flags |= BDRV_O_CACHE_WB;
|
||||
} else {
|
||||
blk->root_state.open_flags &= ~BDRV_O_CACHE_WB;
|
||||
}
|
||||
}
|
||||
blk->enable_write_cache = wce;
|
||||
}
|
||||
|
||||
void blk_invalidate_cache(BlockBackend *blk, Error **errp)
|
||||
@@ -1505,11 +1482,22 @@ int blk_discard(BlockBackend *blk, int64_t sector_num, int nb_sectors)
|
||||
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
|
||||
int64_t pos, int size)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!blk_is_available(blk)) {
|
||||
return -ENOMEDIUM;
|
||||
}
|
||||
|
||||
return bdrv_save_vmstate(blk_bs(blk), buf, pos, size);
|
||||
ret = bdrv_save_vmstate(blk_bs(blk), buf, pos, size);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (ret == size && !blk->enable_write_cache) {
|
||||
ret = bdrv_flush(blk_bs(blk));
|
||||
}
|
||||
|
||||
return ret < 0 ? ret : size;
|
||||
}
|
||||
|
||||
int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size)
|
||||
|
||||
+586
File diff suppressed because it is too large
Load Diff
+20
-4
@@ -747,9 +747,9 @@ int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* No flush needed for cache modes that already do it */
|
||||
if (bs->enable_write_cache) {
|
||||
bdrv_flush(bs);
|
||||
ret = bdrv_flush(bs);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -844,6 +844,7 @@ static int coroutine_fn bdrv_aligned_preadv(BlockDriverState *bs,
|
||||
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
|
||||
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
|
||||
assert(!qiov || bytes == qiov->size);
|
||||
assert((bs->open_flags & BDRV_O_NO_IO) == 0);
|
||||
|
||||
/* Handle Copy on Read and associated serialisation */
|
||||
if (flags & BDRV_REQ_COPY_ON_READ) {
|
||||
@@ -1130,6 +1131,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
|
||||
assert((offset & (BDRV_SECTOR_SIZE - 1)) == 0);
|
||||
assert((bytes & (BDRV_SECTOR_SIZE - 1)) == 0);
|
||||
assert(!qiov || bytes == qiov->size);
|
||||
assert((bs->open_flags & BDRV_O_NO_IO) == 0);
|
||||
|
||||
waited = wait_serialising_requests(req);
|
||||
assert(!waited || !req->serialising);
|
||||
@@ -1152,13 +1154,20 @@ static int coroutine_fn bdrv_aligned_pwritev(BlockDriverState *bs,
|
||||
} else if (flags & BDRV_REQ_ZERO_WRITE) {
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_ZERO);
|
||||
ret = bdrv_co_do_write_zeroes(bs, sector_num, nb_sectors, flags);
|
||||
} else if (drv->bdrv_co_writev_flags) {
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV);
|
||||
ret = drv->bdrv_co_writev_flags(bs, sector_num, nb_sectors, qiov,
|
||||
flags);
|
||||
} else {
|
||||
assert(drv->supported_write_flags == 0);
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV);
|
||||
ret = drv->bdrv_co_writev(bs, sector_num, nb_sectors, qiov);
|
||||
}
|
||||
bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE);
|
||||
|
||||
if (ret == 0 && !bs->enable_write_cache) {
|
||||
if (ret == 0 && (flags & BDRV_REQ_FUA) &&
|
||||
!(drv->supported_write_flags & BDRV_REQ_FUA))
|
||||
{
|
||||
ret = bdrv_co_flush(bs);
|
||||
}
|
||||
|
||||
@@ -2331,6 +2340,13 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs)
|
||||
}
|
||||
|
||||
tracked_request_begin(&req, bs, 0, 0, BDRV_TRACKED_FLUSH);
|
||||
|
||||
/* Write back all layers by calling one driver function */
|
||||
if (bs->drv->bdrv_co_flush) {
|
||||
ret = bs->drv->bdrv_co_flush(bs);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Write back cached data to the OS even with cache=unsafe */
|
||||
BLKDBG_EVENT(bs->file, BLKDBG_FLUSH_TO_OS);
|
||||
if (bs->drv->bdrv_co_flush_to_os) {
|
||||
|
||||
+14
-16
@@ -70,7 +70,6 @@ typedef struct IscsiLun {
|
||||
bool lbprz;
|
||||
bool dpofua;
|
||||
bool has_write_same;
|
||||
bool force_next_flush;
|
||||
bool request_timed_out;
|
||||
} IscsiLun;
|
||||
|
||||
@@ -84,7 +83,6 @@ typedef struct IscsiTask {
|
||||
QEMUBH *bh;
|
||||
IscsiLun *iscsilun;
|
||||
QEMUTimer retry_timer;
|
||||
bool force_next_flush;
|
||||
int err_code;
|
||||
} IscsiTask;
|
||||
|
||||
@@ -282,8 +280,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status,
|
||||
}
|
||||
iTask->err_code = iscsi_translate_sense(&task->sense);
|
||||
error_report("iSCSI Failure: %s", iscsi_get_error(iscsi));
|
||||
} else {
|
||||
iTask->iscsilun->force_next_flush |= iTask->force_next_flush;
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -452,15 +448,15 @@ static void iscsi_allocationmap_clear(IscsiLun *iscsilun, int64_t sector_num,
|
||||
}
|
||||
}
|
||||
|
||||
static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *iov)
|
||||
static int coroutine_fn
|
||||
iscsi_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *iov, int flags)
|
||||
{
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct IscsiTask iTask;
|
||||
uint64_t lba;
|
||||
uint32_t num_sectors;
|
||||
int fua;
|
||||
bool fua;
|
||||
|
||||
if (!is_request_lun_aligned(sector_num, nb_sectors, iscsilun)) {
|
||||
return -EINVAL;
|
||||
@@ -476,8 +472,7 @@ static int coroutine_fn iscsi_co_writev(BlockDriverState *bs,
|
||||
num_sectors = sector_qemu2lun(nb_sectors, iscsilun);
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
retry:
|
||||
fua = iscsilun->dpofua && !bs->enable_write_cache;
|
||||
iTask.force_next_flush = !fua;
|
||||
fua = iscsilun->dpofua && (flags & BDRV_REQ_FUA);
|
||||
if (iscsilun->use_16_for_rw) {
|
||||
iTask.task = iscsi_write16_task(iscsilun->iscsi, iscsilun->lun, lba,
|
||||
NULL, num_sectors * iscsilun->block_size,
|
||||
@@ -518,6 +513,13 @@ retry:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
iscsi_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *iov)
|
||||
{
|
||||
return iscsi_co_writev_flags(bs, sector_num, nb_sectors, iov, 0);
|
||||
}
|
||||
|
||||
|
||||
static bool iscsi_allocationmap_is_allocated(IscsiLun *iscsilun,
|
||||
int64_t sector_num, int nb_sectors)
|
||||
@@ -715,11 +717,6 @@ static int coroutine_fn iscsi_co_flush(BlockDriverState *bs)
|
||||
IscsiLun *iscsilun = bs->opaque;
|
||||
struct IscsiTask iTask;
|
||||
|
||||
if (!iscsilun->force_next_flush) {
|
||||
return 0;
|
||||
}
|
||||
iscsilun->force_next_flush = false;
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
retry:
|
||||
if (iscsi_synchronizecache10_task(iscsilun->iscsi, iscsilun->lun, 0, 0, 0,
|
||||
@@ -1019,7 +1016,6 @@ coroutine_fn iscsi_co_write_zeroes(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
iscsi_co_init_iscsitask(iscsilun, &iTask);
|
||||
iTask.force_next_flush = true;
|
||||
retry:
|
||||
if (use_16_for_ws) {
|
||||
iTask.task = iscsi_writesame16_task(iscsilun->iscsi, iscsilun->lun, lba,
|
||||
@@ -1852,6 +1848,8 @@ static BlockDriver bdrv_iscsi = {
|
||||
.bdrv_co_write_zeroes = iscsi_co_write_zeroes,
|
||||
.bdrv_co_readv = iscsi_co_readv,
|
||||
.bdrv_co_writev = iscsi_co_writev,
|
||||
.bdrv_co_writev_flags = iscsi_co_writev_flags,
|
||||
.supported_write_flags = BDRV_REQ_FUA,
|
||||
.bdrv_co_flush_to_disk = iscsi_co_flush,
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
@@ -856,7 +856,6 @@ static void mirror_start_job(BlockDriverState *bs, BlockDriverState *target,
|
||||
|
||||
bdrv_op_block_all(s->target, s->common.blocker);
|
||||
|
||||
bdrv_set_enable_write_cache(s->target, true);
|
||||
if (s->target->blk) {
|
||||
blk_set_on_error(s->target->blk, on_target_error, on_target_error);
|
||||
blk_iostatus_enable(s->target->blk);
|
||||
|
||||
+7
-6
@@ -243,15 +243,15 @@ static int nbd_co_readv_1(BlockDriverState *bs, int64_t sector_num,
|
||||
|
||||
static int nbd_co_writev_1(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov,
|
||||
int offset)
|
||||
int offset, int *flags)
|
||||
{
|
||||
NbdClientSession *client = nbd_get_client_session(bs);
|
||||
struct nbd_request request = { .type = NBD_CMD_WRITE };
|
||||
struct nbd_reply reply;
|
||||
ssize_t ret;
|
||||
|
||||
if (!bdrv_enable_write_cache(bs) &&
|
||||
(client->nbdflags & NBD_FLAG_SEND_FUA)) {
|
||||
if ((*flags & BDRV_REQ_FUA) && (client->nbdflags & NBD_FLAG_SEND_FUA)) {
|
||||
*flags &= ~BDRV_REQ_FUA;
|
||||
request.type |= NBD_CMD_FLAG_FUA;
|
||||
}
|
||||
|
||||
@@ -291,12 +291,13 @@ int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov)
|
||||
int nb_sectors, QEMUIOVector *qiov, int *flags)
|
||||
{
|
||||
int offset = 0;
|
||||
int ret;
|
||||
while (nb_sectors > NBD_MAX_SECTORS) {
|
||||
ret = nbd_co_writev_1(bs, sector_num, NBD_MAX_SECTORS, qiov, offset);
|
||||
ret = nbd_co_writev_1(bs, sector_num, NBD_MAX_SECTORS, qiov, offset,
|
||||
flags);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -304,7 +305,7 @@ int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
sector_num += NBD_MAX_SECTORS;
|
||||
nb_sectors -= NBD_MAX_SECTORS;
|
||||
}
|
||||
return nbd_co_writev_1(bs, sector_num, nb_sectors, qiov, offset);
|
||||
return nbd_co_writev_1(bs, sector_num, nb_sectors, qiov, offset, flags);
|
||||
}
|
||||
|
||||
int nbd_client_co_flush(BlockDriverState *bs)
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ int nbd_client_co_discard(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors);
|
||||
int nbd_client_co_flush(BlockDriverState *bs);
|
||||
int nbd_client_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov);
|
||||
int nb_sectors, QEMUIOVector *qiov, int *flags);
|
||||
int nbd_client_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov);
|
||||
|
||||
|
||||
+26
-1
@@ -355,10 +355,29 @@ static int nbd_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
return nbd_client_co_readv(bs, sector_num, nb_sectors, qiov);
|
||||
}
|
||||
|
||||
static int nbd_co_writev_flags(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = nbd_client_co_writev(bs, sector_num, nb_sectors, qiov, &flags);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* The flag wasn't sent to the server, so we need to emulate it with an
|
||||
* explicit flush */
|
||||
if (flags & BDRV_REQ_FUA) {
|
||||
ret = nbd_client_co_flush(bs);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int nbd_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov)
|
||||
{
|
||||
return nbd_client_co_writev(bs, sector_num, nb_sectors, qiov);
|
||||
return nbd_co_writev_flags(bs, sector_num, nb_sectors, qiov, 0);
|
||||
}
|
||||
|
||||
static int nbd_co_flush(BlockDriverState *bs)
|
||||
@@ -458,6 +477,8 @@ static BlockDriver bdrv_nbd = {
|
||||
.bdrv_file_open = nbd_open,
|
||||
.bdrv_co_readv = nbd_co_readv,
|
||||
.bdrv_co_writev = nbd_co_writev,
|
||||
.bdrv_co_writev_flags = nbd_co_writev_flags,
|
||||
.supported_write_flags = BDRV_REQ_FUA,
|
||||
.bdrv_close = nbd_close,
|
||||
.bdrv_co_flush_to_os = nbd_co_flush,
|
||||
.bdrv_co_discard = nbd_co_discard,
|
||||
@@ -476,6 +497,8 @@ static BlockDriver bdrv_nbd_tcp = {
|
||||
.bdrv_file_open = nbd_open,
|
||||
.bdrv_co_readv = nbd_co_readv,
|
||||
.bdrv_co_writev = nbd_co_writev,
|
||||
.bdrv_co_writev_flags = nbd_co_writev_flags,
|
||||
.supported_write_flags = BDRV_REQ_FUA,
|
||||
.bdrv_close = nbd_close,
|
||||
.bdrv_co_flush_to_os = nbd_co_flush,
|
||||
.bdrv_co_discard = nbd_co_discard,
|
||||
@@ -494,6 +517,8 @@ static BlockDriver bdrv_nbd_unix = {
|
||||
.bdrv_file_open = nbd_open,
|
||||
.bdrv_co_readv = nbd_co_readv,
|
||||
.bdrv_co_writev = nbd_co_writev,
|
||||
.bdrv_co_writev_flags = nbd_co_writev_flags,
|
||||
.supported_write_flags = BDRV_REQ_FUA,
|
||||
.bdrv_close = nbd_close,
|
||||
.bdrv_co_flush_to_os = nbd_co_flush,
|
||||
.bdrv_co_discard = nbd_co_discard,
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
#include "block/block_int.h"
|
||||
|
||||
#define NULL_OPT_LATENCY "latency-ns"
|
||||
#define NULL_OPT_ZEROES "read-zeroes"
|
||||
|
||||
typedef struct {
|
||||
int64_t length;
|
||||
int64_t latency_ns;
|
||||
bool read_zeroes;
|
||||
} BDRVNullState;
|
||||
|
||||
static QemuOptsList runtime_opts = {
|
||||
@@ -41,6 +43,11 @@ static QemuOptsList runtime_opts = {
|
||||
.help = "nanoseconds (approximated) to wait "
|
||||
"before completing request",
|
||||
},
|
||||
{
|
||||
.name = NULL_OPT_ZEROES,
|
||||
.type = QEMU_OPT_BOOL,
|
||||
.help = "return zeroes when read",
|
||||
},
|
||||
{ /* end of list */ }
|
||||
},
|
||||
};
|
||||
@@ -62,6 +69,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
error_setg(errp, "latency-ns is invalid");
|
||||
ret = -EINVAL;
|
||||
}
|
||||
s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false);
|
||||
qemu_opts_del(opts);
|
||||
return ret;
|
||||
}
|
||||
@@ -91,6 +99,12 @@ static coroutine_fn int null_co_readv(BlockDriverState *bs,
|
||||
int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *qiov)
|
||||
{
|
||||
BDRVNullState *s = bs->opaque;
|
||||
|
||||
if (s->read_zeroes) {
|
||||
qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE);
|
||||
}
|
||||
|
||||
return null_co_common(bs);
|
||||
}
|
||||
|
||||
@@ -160,6 +174,12 @@ static BlockAIOCB *null_aio_readv(BlockDriverState *bs,
|
||||
BlockCompletionFunc *cb,
|
||||
void *opaque)
|
||||
{
|
||||
BDRVNullState *s = bs->opaque;
|
||||
|
||||
if (s->read_zeroes) {
|
||||
qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE);
|
||||
}
|
||||
|
||||
return null_aio_common(bs, cb, opaque);
|
||||
}
|
||||
|
||||
@@ -185,6 +205,24 @@ static int null_reopen_prepare(BDRVReopenState *reopen_state,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int64_t coroutine_fn null_co_get_block_status(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
int nb_sectors, int *pnum,
|
||||
BlockDriverState **file)
|
||||
{
|
||||
BDRVNullState *s = bs->opaque;
|
||||
off_t start = sector_num * BDRV_SECTOR_SIZE;
|
||||
|
||||
*pnum = nb_sectors;
|
||||
*file = bs;
|
||||
|
||||
if (s->read_zeroes) {
|
||||
return BDRV_BLOCK_OFFSET_VALID | start | BDRV_BLOCK_ZERO;
|
||||
} else {
|
||||
return BDRV_BLOCK_OFFSET_VALID | start;
|
||||
}
|
||||
}
|
||||
|
||||
static BlockDriver bdrv_null_co = {
|
||||
.format_name = "null-co",
|
||||
.protocol_name = "null-co",
|
||||
@@ -198,6 +236,8 @@ static BlockDriver bdrv_null_co = {
|
||||
.bdrv_co_writev = null_co_writev,
|
||||
.bdrv_co_flush_to_disk = null_co_flush,
|
||||
.bdrv_reopen_prepare = null_reopen_prepare,
|
||||
|
||||
.bdrv_co_get_block_status = null_co_get_block_status,
|
||||
};
|
||||
|
||||
static BlockDriver bdrv_null_aio = {
|
||||
@@ -213,6 +253,8 @@ static BlockDriver bdrv_null_aio = {
|
||||
.bdrv_aio_writev = null_aio_writev,
|
||||
.bdrv_aio_flush = null_aio_flush,
|
||||
.bdrv_reopen_prepare = null_reopen_prepare,
|
||||
|
||||
.bdrv_co_get_block_status = null_co_get_block_status,
|
||||
};
|
||||
|
||||
static void bdrv_null_init(void)
|
||||
|
||||
+1
-2
@@ -480,8 +480,7 @@ static int parallels_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
file = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (file == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
|
||||
+37
-38
@@ -34,7 +34,8 @@
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "qemu/cutils.h"
|
||||
|
||||
BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
|
||||
BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
|
||||
BlockDriverState *bs, Error **errp)
|
||||
{
|
||||
ImageInfo **p_image_info;
|
||||
BlockDriverState *bs0;
|
||||
@@ -48,7 +49,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
|
||||
|
||||
info->cache = g_new(BlockdevCacheInfo, 1);
|
||||
*info->cache = (BlockdevCacheInfo) {
|
||||
.writeback = bdrv_enable_write_cache(bs),
|
||||
.writeback = blk ? blk_enable_write_cache(blk) : true,
|
||||
.direct = !!(bs->open_flags & BDRV_O_NOCACHE),
|
||||
.no_flush = !!(bs->open_flags & BDRV_O_NO_FLUSH),
|
||||
};
|
||||
@@ -343,7 +344,7 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
|
||||
|
||||
if (bs && bs->drv) {
|
||||
info->has_inserted = true;
|
||||
info->inserted = bdrv_block_device_info(bs, errp);
|
||||
info->inserted = bdrv_block_device_info(blk, bs, errp);
|
||||
if (info->inserted == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -360,50 +361,47 @@ static BlockStats *bdrv_query_stats(BlockBackend *blk,
|
||||
const BlockDriverState *bs,
|
||||
bool query_backing);
|
||||
|
||||
static void bdrv_query_blk_stats(BlockStats *s, BlockBackend *blk)
|
||||
static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
|
||||
{
|
||||
BlockAcctStats *stats = blk_get_stats(blk);
|
||||
BlockAcctTimedStats *ts = NULL;
|
||||
|
||||
s->has_device = true;
|
||||
s->device = g_strdup(blk_name(blk));
|
||||
ds->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ];
|
||||
ds->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE];
|
||||
ds->rd_operations = stats->nr_ops[BLOCK_ACCT_READ];
|
||||
ds->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE];
|
||||
|
||||
s->stats->rd_bytes = stats->nr_bytes[BLOCK_ACCT_READ];
|
||||
s->stats->wr_bytes = stats->nr_bytes[BLOCK_ACCT_WRITE];
|
||||
s->stats->rd_operations = stats->nr_ops[BLOCK_ACCT_READ];
|
||||
s->stats->wr_operations = stats->nr_ops[BLOCK_ACCT_WRITE];
|
||||
ds->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ];
|
||||
ds->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE];
|
||||
ds->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH];
|
||||
|
||||
s->stats->failed_rd_operations = stats->failed_ops[BLOCK_ACCT_READ];
|
||||
s->stats->failed_wr_operations = stats->failed_ops[BLOCK_ACCT_WRITE];
|
||||
s->stats->failed_flush_operations = stats->failed_ops[BLOCK_ACCT_FLUSH];
|
||||
|
||||
s->stats->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ];
|
||||
s->stats->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE];
|
||||
s->stats->invalid_flush_operations =
|
||||
ds->invalid_rd_operations = stats->invalid_ops[BLOCK_ACCT_READ];
|
||||
ds->invalid_wr_operations = stats->invalid_ops[BLOCK_ACCT_WRITE];
|
||||
ds->invalid_flush_operations =
|
||||
stats->invalid_ops[BLOCK_ACCT_FLUSH];
|
||||
|
||||
s->stats->rd_merged = stats->merged[BLOCK_ACCT_READ];
|
||||
s->stats->wr_merged = stats->merged[BLOCK_ACCT_WRITE];
|
||||
s->stats->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH];
|
||||
s->stats->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE];
|
||||
s->stats->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ];
|
||||
s->stats->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH];
|
||||
ds->rd_merged = stats->merged[BLOCK_ACCT_READ];
|
||||
ds->wr_merged = stats->merged[BLOCK_ACCT_WRITE];
|
||||
ds->flush_operations = stats->nr_ops[BLOCK_ACCT_FLUSH];
|
||||
ds->wr_total_time_ns = stats->total_time_ns[BLOCK_ACCT_WRITE];
|
||||
ds->rd_total_time_ns = stats->total_time_ns[BLOCK_ACCT_READ];
|
||||
ds->flush_total_time_ns = stats->total_time_ns[BLOCK_ACCT_FLUSH];
|
||||
|
||||
s->stats->has_idle_time_ns = stats->last_access_time_ns > 0;
|
||||
if (s->stats->has_idle_time_ns) {
|
||||
s->stats->idle_time_ns = block_acct_idle_time_ns(stats);
|
||||
ds->has_idle_time_ns = stats->last_access_time_ns > 0;
|
||||
if (ds->has_idle_time_ns) {
|
||||
ds->idle_time_ns = block_acct_idle_time_ns(stats);
|
||||
}
|
||||
|
||||
s->stats->account_invalid = stats->account_invalid;
|
||||
s->stats->account_failed = stats->account_failed;
|
||||
ds->account_invalid = stats->account_invalid;
|
||||
ds->account_failed = stats->account_failed;
|
||||
|
||||
while ((ts = block_acct_interval_next(stats, ts))) {
|
||||
BlockDeviceTimedStatsList *timed_stats =
|
||||
g_malloc0(sizeof(*timed_stats));
|
||||
BlockDeviceTimedStats *dev_stats = g_malloc0(sizeof(*dev_stats));
|
||||
timed_stats->next = s->stats->timed_stats;
|
||||
timed_stats->next = ds->timed_stats;
|
||||
timed_stats->value = dev_stats;
|
||||
s->stats->timed_stats = timed_stats;
|
||||
ds->timed_stats = timed_stats;
|
||||
|
||||
TimedAverage *rd = &ts->latency[BLOCK_ACCT_READ];
|
||||
TimedAverage *wr = &ts->latency[BLOCK_ACCT_WRITE];
|
||||
@@ -462,7 +460,9 @@ static BlockStats *bdrv_query_stats(BlockBackend *blk,
|
||||
s->stats = g_malloc0(sizeof(*s->stats));
|
||||
|
||||
if (blk) {
|
||||
bdrv_query_blk_stats(s, blk);
|
||||
s->has_device = true;
|
||||
s->device = g_strdup(blk_name(blk));
|
||||
bdrv_query_blk_stats(s->stats, blk);
|
||||
}
|
||||
if (bs) {
|
||||
bdrv_query_bds_stats(s, bs, query_backing);
|
||||
@@ -652,9 +652,8 @@ static void dump_qlist(fprintf_function func_fprintf, void *f, int indentation,
|
||||
for (entry = qlist_first(list); entry; entry = qlist_next(entry), i++) {
|
||||
QType type = qobject_type(entry->value);
|
||||
bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
|
||||
const char *format = composite ? "%*s[%i]:\n" : "%*s[%i]: ";
|
||||
|
||||
func_fprintf(f, format, indentation * 4, "", i);
|
||||
func_fprintf(f, "%*s[%i]:%c", indentation * 4, "", i,
|
||||
composite ? '\n' : ' ');
|
||||
dump_qobject(func_fprintf, f, indentation + 1, entry->value);
|
||||
if (!composite) {
|
||||
func_fprintf(f, "\n");
|
||||
@@ -670,8 +669,7 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
|
||||
for (entry = qdict_first(dict); entry; entry = qdict_next(dict, entry)) {
|
||||
QType type = qobject_type(entry->value);
|
||||
bool composite = (type == QTYPE_QDICT || type == QTYPE_QLIST);
|
||||
const char *format = composite ? "%*s%s:\n" : "%*s%s: ";
|
||||
char key[strlen(entry->key) + 1];
|
||||
char *key = g_malloc(strlen(entry->key) + 1);
|
||||
int i;
|
||||
|
||||
/* replace dashes with spaces in key (variable) names */
|
||||
@@ -679,12 +677,13 @@ static void dump_qdict(fprintf_function func_fprintf, void *f, int indentation,
|
||||
key[i] = entry->key[i] == '-' ? ' ' : entry->key[i];
|
||||
}
|
||||
key[i] = 0;
|
||||
|
||||
func_fprintf(f, format, indentation * 4, "", key);
|
||||
func_fprintf(f, "%*s%s:%c", indentation * 4, "", key,
|
||||
composite ? '\n' : ' ');
|
||||
dump_qobject(func_fprintf, f, indentation + 1, entry->value);
|
||||
if (!composite) {
|
||||
func_fprintf(f, "\n");
|
||||
}
|
||||
g_free(key);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-2
@@ -24,6 +24,7 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "block/block_int.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "qemu/module.h"
|
||||
@@ -158,6 +159,14 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
s->crypt_method_header = header.crypt_method;
|
||||
if (s->crypt_method_header) {
|
||||
if (bdrv_uses_whitelist() &&
|
||||
s->crypt_method_header == QCOW_CRYPT_AES) {
|
||||
error_report("qcow built-in AES encryption is deprecated");
|
||||
error_printf("Support for it will be removed in a future release.\n"
|
||||
"You can use 'qemu-img convert' to switch to an\n"
|
||||
"unencrypted qcow image, or a LUKS raw image.\n");
|
||||
}
|
||||
|
||||
bs->encrypted = 1;
|
||||
}
|
||||
s->cluster_bits = header.cluster_bits;
|
||||
@@ -795,8 +804,7 @@ static int qcow_create(const char *filename, QemuOpts *opts, Error **errp)
|
||||
}
|
||||
|
||||
qcow_blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (qcow_blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
|
||||
+11
-6
@@ -965,6 +965,14 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
}
|
||||
s->crypt_method_header = header.crypt_method;
|
||||
if (s->crypt_method_header) {
|
||||
if (bdrv_uses_whitelist() &&
|
||||
s->crypt_method_header == QCOW_CRYPT_AES) {
|
||||
error_report("qcow2 built-in AES encryption is deprecated");
|
||||
error_printf("Support for it will be removed in a future release.\n"
|
||||
"You can use 'qemu-img convert' to switch to an\n"
|
||||
"unencrypted qcow2 image, or a LUKS raw image.\n");
|
||||
}
|
||||
|
||||
bs->encrypted = 1;
|
||||
}
|
||||
|
||||
@@ -2160,8 +2168,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
@@ -2225,8 +2232,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str("qcow2"));
|
||||
blk = blk_new_open(filename, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_NO_FLUSH, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
@@ -2287,8 +2293,7 @@ static int qcow2_create2(const char *filename, int64_t total_size,
|
||||
options = qdict_new();
|
||||
qdict_put(options, "driver", qstring_from_str("qcow2"));
|
||||
blk = blk_new_open(filename, NULL, options,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_BACKING,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_NO_BACKING, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
ret = -EIO;
|
||||
|
||||
+1
-2
@@ -576,8 +576,7 @@ static int qed_create(const char *filename, uint32_t cluster_size,
|
||||
}
|
||||
|
||||
blk = blk_new_open(filename, NULL, NULL,
|
||||
BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_PROTOCOL,
|
||||
&local_err);
|
||||
BDRV_O_RDWR | BDRV_O_PROTOCOL, &local_err);
|
||||
if (blk == NULL) {
|
||||
error_propagate(errp, local_err);
|
||||
return -EIO;
|
||||
|
||||
+125
-38
@@ -45,6 +45,7 @@
|
||||
#include <IOKit/storage/IOMedia.h>
|
||||
#include <IOKit/storage/IOCDMedia.h>
|
||||
//#include <IOKit/storage/IOCDTypes.h>
|
||||
#include <IOKit/storage/IODVDMedia.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
@@ -1966,33 +1967,47 @@ BlockDriver bdrv_file = {
|
||||
/* host device */
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
static kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator );
|
||||
static kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
CFIndex maxPathSize, int flags);
|
||||
kern_return_t FindEjectableCDMedia( io_iterator_t *mediaIterator )
|
||||
static char *FindEjectableOpticalMedia(io_iterator_t *mediaIterator)
|
||||
{
|
||||
kern_return_t kernResult;
|
||||
kern_return_t kernResult = KERN_FAILURE;
|
||||
mach_port_t masterPort;
|
||||
CFMutableDictionaryRef classesToMatch;
|
||||
const char *matching_array[] = {kIODVDMediaClass, kIOCDMediaClass};
|
||||
char *mediaType = NULL;
|
||||
|
||||
kernResult = IOMasterPort( MACH_PORT_NULL, &masterPort );
|
||||
if ( KERN_SUCCESS != kernResult ) {
|
||||
printf( "IOMasterPort returned %d\n", kernResult );
|
||||
}
|
||||
|
||||
classesToMatch = IOServiceMatching( kIOCDMediaClass );
|
||||
if ( classesToMatch == NULL ) {
|
||||
printf( "IOServiceMatching returned a NULL dictionary.\n" );
|
||||
} else {
|
||||
CFDictionarySetValue( classesToMatch, CFSTR( kIOMediaEjectableKey ), kCFBooleanTrue );
|
||||
}
|
||||
kernResult = IOServiceGetMatchingServices( masterPort, classesToMatch, mediaIterator );
|
||||
if ( KERN_SUCCESS != kernResult )
|
||||
{
|
||||
printf( "IOServiceGetMatchingServices returned %d\n", kernResult );
|
||||
}
|
||||
int index;
|
||||
for (index = 0; index < ARRAY_SIZE(matching_array); index++) {
|
||||
classesToMatch = IOServiceMatching(matching_array[index]);
|
||||
if (classesToMatch == NULL) {
|
||||
error_report("IOServiceMatching returned NULL for %s",
|
||||
matching_array[index]);
|
||||
continue;
|
||||
}
|
||||
CFDictionarySetValue(classesToMatch, CFSTR(kIOMediaEjectableKey),
|
||||
kCFBooleanTrue);
|
||||
kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch,
|
||||
mediaIterator);
|
||||
if (kernResult != KERN_SUCCESS) {
|
||||
error_report("Note: IOServiceGetMatchingServices returned %d",
|
||||
kernResult);
|
||||
continue;
|
||||
}
|
||||
|
||||
return kernResult;
|
||||
/* If a match was found, leave the loop */
|
||||
if (*mediaIterator != 0) {
|
||||
DPRINTF("Matching using %s\n", matching_array[index]);
|
||||
mediaType = g_strdup(matching_array[index]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return mediaType;
|
||||
}
|
||||
|
||||
kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
@@ -2024,7 +2039,46 @@ kern_return_t GetBSDPath(io_iterator_t mediaIterator, char *bsdPath,
|
||||
return kernResult;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* Sets up a real cdrom for use in QEMU */
|
||||
static bool setup_cdrom(char *bsd_path, Error **errp)
|
||||
{
|
||||
int index, num_of_test_partitions = 2, fd;
|
||||
char test_partition[MAXPATHLEN];
|
||||
bool partition_found = false;
|
||||
|
||||
/* look for a working partition */
|
||||
for (index = 0; index < num_of_test_partitions; index++) {
|
||||
snprintf(test_partition, sizeof(test_partition), "%ss%d", bsd_path,
|
||||
index);
|
||||
fd = qemu_open(test_partition, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||
if (fd >= 0) {
|
||||
partition_found = true;
|
||||
qemu_close(fd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if a working partition on the device was not found */
|
||||
if (partition_found == false) {
|
||||
error_setg(errp, "Failed to find a working partition on disc");
|
||||
} else {
|
||||
DPRINTF("Using %s as optical disc\n", test_partition);
|
||||
pstrcpy(bsd_path, MAXPATHLEN, test_partition);
|
||||
}
|
||||
return partition_found;
|
||||
}
|
||||
|
||||
/* Prints directions on mounting and unmounting a device */
|
||||
static void print_unmounting_directions(const char *file_name)
|
||||
{
|
||||
error_report("If device %s is mounted on the desktop, unmount"
|
||||
" it first before using it in QEMU", file_name);
|
||||
error_report("Command to unmount device: diskutil unmountDisk %s",
|
||||
file_name);
|
||||
error_report("Command to mount device: diskutil mountDisk %s", file_name);
|
||||
}
|
||||
|
||||
#endif /* defined(__APPLE__) && defined(__MACH__) */
|
||||
|
||||
static int hdev_probe_device(const char *filename)
|
||||
{
|
||||
@@ -2115,33 +2169,57 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
const char *filename = qdict_get_str(options, "filename");
|
||||
char bsd_path[MAXPATHLEN] = "";
|
||||
bool error_occurred = false;
|
||||
|
||||
if (strstart(filename, "/dev/cdrom", NULL)) {
|
||||
kern_return_t kernResult;
|
||||
io_iterator_t mediaIterator;
|
||||
char bsdPath[ MAXPATHLEN ];
|
||||
int fd;
|
||||
/* If using a real cdrom */
|
||||
if (strcmp(filename, "/dev/cdrom") == 0) {
|
||||
char *mediaType = NULL;
|
||||
kern_return_t ret_val;
|
||||
io_iterator_t mediaIterator = 0;
|
||||
|
||||
kernResult = FindEjectableCDMedia( &mediaIterator );
|
||||
kernResult = GetBSDPath(mediaIterator, bsdPath, sizeof(bsdPath),
|
||||
flags);
|
||||
if ( bsdPath[ 0 ] != '\0' ) {
|
||||
strcat(bsdPath,"s0");
|
||||
/* some CDs don't have a partition 0 */
|
||||
fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
|
||||
if (fd < 0) {
|
||||
bsdPath[strlen(bsdPath)-1] = '1';
|
||||
} else {
|
||||
qemu_close(fd);
|
||||
}
|
||||
filename = bsdPath;
|
||||
qdict_put(options, "filename", qstring_from_str(filename));
|
||||
mediaType = FindEjectableOpticalMedia(&mediaIterator);
|
||||
if (mediaType == NULL) {
|
||||
error_setg(errp, "Please make sure your CD/DVD is in the optical"
|
||||
" drive");
|
||||
error_occurred = true;
|
||||
goto hdev_open_Mac_error;
|
||||
}
|
||||
|
||||
if ( mediaIterator )
|
||||
IOObjectRelease( mediaIterator );
|
||||
ret_val = GetBSDPath(mediaIterator, bsd_path, sizeof(bsd_path), flags);
|
||||
if (ret_val != KERN_SUCCESS) {
|
||||
error_setg(errp, "Could not get BSD path for optical drive");
|
||||
error_occurred = true;
|
||||
goto hdev_open_Mac_error;
|
||||
}
|
||||
|
||||
/* If a real optical drive was not found */
|
||||
if (bsd_path[0] == '\0') {
|
||||
error_setg(errp, "Failed to obtain bsd path for optical drive");
|
||||
error_occurred = true;
|
||||
goto hdev_open_Mac_error;
|
||||
}
|
||||
|
||||
/* If using a cdrom disc and finding a partition on the disc failed */
|
||||
if (strncmp(mediaType, kIOCDMediaClass, 9) == 0 &&
|
||||
setup_cdrom(bsd_path, errp) == false) {
|
||||
print_unmounting_directions(bsd_path);
|
||||
error_occurred = true;
|
||||
goto hdev_open_Mac_error;
|
||||
}
|
||||
|
||||
qdict_put(options, "filename", qstring_from_str(bsd_path));
|
||||
|
||||
hdev_open_Mac_error:
|
||||
g_free(mediaType);
|
||||
if (mediaIterator) {
|
||||
IOObjectRelease(mediaIterator);
|
||||
}
|
||||
if (error_occurred) {
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endif /* defined(__APPLE__) && defined(__MACH__) */
|
||||
|
||||
s->type = FTYPE_FILE;
|
||||
|
||||
@@ -2150,6 +2228,15 @@ static int hdev_open(BlockDriverState *bs, QDict *options, int flags,
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
}
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
if (*bsd_path) {
|
||||
filename = bsd_path;
|
||||
}
|
||||
/* if a physical device experienced an error while being opened */
|
||||
if (strncmp(filename, "/dev/", 5) == 0) {
|
||||
print_unmounting_directions(filename);
|
||||
}
|
||||
#endif /* defined(__APPLE__) && defined(__MACH__) */
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+14
-3
@@ -57,8 +57,9 @@ static int coroutine_fn raw_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||
return bdrv_co_readv(bs->file->bs, sector_num, nb_sectors, qiov);
|
||||
}
|
||||
|
||||
static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
int nb_sectors, QEMUIOVector *qiov)
|
||||
static int coroutine_fn
|
||||
raw_co_writev_flags(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *qiov, int flags)
|
||||
{
|
||||
void *buf = NULL;
|
||||
BlockDriver *drv;
|
||||
@@ -104,7 +105,8 @@ static int coroutine_fn raw_co_writev(BlockDriverState *bs, int64_t sector_num,
|
||||
}
|
||||
|
||||
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
|
||||
ret = bdrv_co_writev(bs->file->bs, sector_num, nb_sectors, qiov);
|
||||
ret = bdrv_co_do_pwritev(bs->file->bs, sector_num * BDRV_SECTOR_SIZE,
|
||||
nb_sectors * BDRV_SECTOR_SIZE, qiov, flags);
|
||||
|
||||
fail:
|
||||
if (qiov == &local_qiov) {
|
||||
@@ -114,6 +116,13 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int coroutine_fn
|
||||
raw_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors,
|
||||
QEMUIOVector *qiov)
|
||||
{
|
||||
return raw_co_writev_flags(bs, sector_num, nb_sectors, qiov, 0);
|
||||
}
|
||||
|
||||
static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs,
|
||||
int64_t sector_num,
|
||||
int nb_sectors, int *pnum,
|
||||
@@ -248,6 +257,8 @@ BlockDriver bdrv_raw = {
|
||||
.bdrv_create = &raw_create,
|
||||
.bdrv_co_readv = &raw_co_readv,
|
||||
.bdrv_co_writev = &raw_co_writev,
|
||||
.bdrv_co_writev_flags = &raw_co_writev_flags,
|
||||
.supported_write_flags = BDRV_REQ_FUA,
|
||||
.bdrv_co_write_zeroes = &raw_co_write_zeroes,
|
||||
.bdrv_co_discard = &raw_co_discard,
|
||||
.bdrv_co_get_block_status = &raw_co_get_block_status,
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user