Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into s…
Browse files Browse the repository at this point in the history
…taging

Block layer patches:

- qemu-storage-daemon: Enable object-add
- blockjob: Fix crash with IOthread when block commit after snapshot
- monitor: Shutdown fixes
- xen-block: fix reporting of discard feature
- qcow2: Remove half-initialised image file after failed image creation
- ahci: Fix DMA direction
- iotests fixes

# gpg: Signature made Mon 15 Feb 2021 14:58:47 GMT
# gpg:                using RSA key DC3DEB159A9AF95D3D7456FE7F09B272C88F2FD6
# gpg:                issuer "kwolf@redhat.com"
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>" [full]
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74  56FE 7F09 B272 C88F 2FD6

* remotes/kevin/tags/for-upstream:
  monitor/qmp: Stop processing requests when shutdown is requested
  monitor: Fix assertion failure on shutdown
  block: qcow2: remove the created file on initialization error
  block: add bdrv_co_delete_file_noerr
  crypto: luks: Fix tiny memory leak
  tests/qemu-iotests: Remove test 259 from the "auto" group
  xen-block: fix reporting of discard feature
  hw/ide/ahci: map cmd_fis as DMA_DIRECTION_TO_DEVICE
  blockjob: Fix crash with IOthread when block commit after snapshot
  iotests: Consistent $IMGOPTS boundary matching
  qemu-storage-daemon: Enable object-add

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Feb 15, 2021
2 parents 35f15ac + b248e61 commit 8ba4bca
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 34 deletions.
22 changes: 22 additions & 0 deletions block.c
Expand Up @@ -706,6 +706,28 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp)
return ret;
}

void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs)
{
Error *local_err = NULL;
int ret;

if (!bs) {
return;
}

ret = bdrv_co_delete_file(bs, &local_err);
/*
* ENOTSUP will happen if the block driver doesn't support
* the 'bdrv_co_delete_file' interface. This is a predictable
* scenario and shouldn't be reported back to the user.
*/
if (ret == -ENOTSUP) {
error_free(local_err);
} else if (ret < 0) {
error_report_err(local_err);
}
}

/**
* Try to get @bs's logical and physical block size.
* On success, store them in @bsz struct and return 0.
Expand Down
13 changes: 2 additions & 11 deletions block/crypto.c
Expand Up @@ -725,17 +725,8 @@ static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv,
* If an error occurred, delete 'filename'. Even if the file existed
* beforehand, it has been truncated and corrupted in the process.
*/
if (ret && bs) {
Error *local_delete_err = NULL;
int r_del = bdrv_co_delete_file(bs, &local_delete_err);
/*
* ENOTSUP will happen if the block driver doesn't support
* the 'bdrv_co_delete_file' interface. This is a predictable
* scenario and shouldn't be reported back to the user.
*/
if ((r_del < 0) && (r_del != -ENOTSUP)) {
error_report_err(local_delete_err);
}
if (ret) {
bdrv_co_delete_file_noerr(bs);
}

bdrv_unref(bs);
Expand Down
8 changes: 5 additions & 3 deletions block/qcow2.c
Expand Up @@ -3846,12 +3846,14 @@ static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv,

/* Create the qcow2 image (format layer) */
ret = qcow2_co_create(create_options, errp);
finish:
if (ret < 0) {
goto finish;
bdrv_co_delete_file_noerr(bs);
bdrv_co_delete_file_noerr(data_bs);
} else {
ret = 0;
}

ret = 0;
finish:
qobject_unref(qdict);
bdrv_unref(bs);
bdrv_unref(data_bs);
Expand Down
8 changes: 6 additions & 2 deletions blockjob.c
Expand Up @@ -212,15 +212,19 @@ int block_job_add_bdrv(BlockJob *job, const char *name, BlockDriverState *bs,
uint64_t perm, uint64_t shared_perm, Error **errp)
{
BdrvChild *c;
bool need_context_ops;

bdrv_ref(bs);
if (job->job.aio_context != qemu_get_aio_context()) {

need_context_ops = bdrv_get_aio_context(bs) != job->job.aio_context;

if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) {
aio_context_release(job->job.aio_context);
}
c = bdrv_root_attach_child(bs, name, &child_job, 0,
job->job.aio_context, perm, shared_perm, job,
errp);
if (job->job.aio_context != qemu_get_aio_context()) {
if (need_context_ops && job->job.aio_context != qemu_get_aio_context()) {
aio_context_acquire(job->job.aio_context);
}
if (c == NULL) {
Expand Down
1 change: 1 addition & 0 deletions hw/block/xen-block.c
Expand Up @@ -253,6 +253,7 @@ static void xen_block_realize(XenDevice *xendev, Error **errp)
xen_device_backend_printf(xendev, "feature-discard", "%u", 1);
xen_device_backend_printf(xendev, "discard-granularity", "%u",
conf->discard_granularity);
xen_device_backend_printf(xendev, "discard-alignment", "%u", 0);
}

xen_device_backend_printf(xendev, "feature-flush-cache", "%u", 1);
Expand Down
12 changes: 6 additions & 6 deletions hw/ide/ahci.c
Expand Up @@ -700,7 +700,7 @@ static void ahci_reset_port(AHCIState *s, int port)
}

/* Buffer pretty output based on a raw FIS structure. */
static char *ahci_pretty_buffer_fis(uint8_t *fis, int cmd_len)
static char *ahci_pretty_buffer_fis(const uint8_t *fis, int cmd_len)
{
int i;
GString *s = g_string_new("FIS:");
Expand Down Expand Up @@ -1100,11 +1100,11 @@ static void execute_ncq_command(NCQTransferState *ncq_tfs)
}


static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
static void process_ncq_command(AHCIState *s, int port, const uint8_t *cmd_fis,
uint8_t slot)
{
AHCIDevice *ad = &s->dev[port];
NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
const NCQFrame *ncq_fis = (NCQFrame *)cmd_fis;
uint8_t tag = ncq_fis->tag >> 3;
NCQTransferState *ncq_tfs = &ad->ncq_tfs[tag];
size_t size;
Expand Down Expand Up @@ -1185,7 +1185,7 @@ static AHCICmdHdr *get_cmd_header(AHCIState *s, uint8_t port, uint8_t slot)
}

static void handle_reg_h2d_fis(AHCIState *s, int port,
uint8_t slot, uint8_t *cmd_fis)
uint8_t slot, const uint8_t *cmd_fis)
{
IDEState *ide_state = &s->dev[port].port.ifs[0];
AHCICmdHdr *cmd = get_cmd_header(s, port, slot);
Expand Down Expand Up @@ -1301,7 +1301,7 @@ static int handle_cmd(AHCIState *s, int port, uint8_t slot)
tbl_addr = le64_to_cpu(cmd->tbl_addr);
cmd_len = 0x80;
cmd_fis = dma_memory_map(s->as, tbl_addr, &cmd_len,
DMA_DIRECTION_FROM_DEVICE);
DMA_DIRECTION_TO_DEVICE);
if (!cmd_fis) {
trace_handle_cmd_badfis(s, port);
return -1;
Expand All @@ -1326,7 +1326,7 @@ static int handle_cmd(AHCIState *s, int port, uint8_t slot)
}

out:
dma_memory_unmap(s->as, cmd_fis, cmd_len, DMA_DIRECTION_FROM_DEVICE,
dma_memory_unmap(s->as, cmd_fis, cmd_len, DMA_DIRECTION_TO_DEVICE,
cmd_len);

if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) {
Expand Down
1 change: 1 addition & 0 deletions include/block/block.h
Expand Up @@ -441,6 +441,7 @@ int bdrv_freeze_backing_chain(BlockDriverState *bs, BlockDriverState *base,
Error **errp);
void bdrv_unfreeze_backing_chain(BlockDriverState *bs, BlockDriverState *base);
int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp);
void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs);


typedef struct BdrvCheckResult {
Expand Down
25 changes: 15 additions & 10 deletions monitor/monitor.c
Expand Up @@ -618,16 +618,6 @@ void monitor_data_destroy(Monitor *mon)

void monitor_cleanup(void)
{
/*
* We need to explicitly stop the I/O thread (but not destroy it),
* clean up the monitor resources, then destroy the I/O thread since
* we need to unregister from chardev below in
* monitor_data_destroy(), and chardev is not thread-safe yet
*/
if (mon_iothread) {
iothread_stop(mon_iothread);
}

/*
* The dispatcher needs to stop before destroying the monitor and
* the I/O thread.
Expand All @@ -637,6 +627,11 @@ void monitor_cleanup(void)
* eventually terminates. qemu_aio_context is automatically
* polled by calling AIO_WAIT_WHILE on it, but we must poll
* iohandler_ctx manually.
*
* Letting the iothread continue while shutting down the dispatcher
* means that new requests may still be coming in. This is okay,
* we'll just leave them in the queue without sending a response
* and monitor_data_destroy() will free them.
*/
qmp_dispatcher_co_shutdown = true;
if (!qatomic_xchg(&qmp_dispatcher_co_busy, true)) {
Expand All @@ -647,6 +642,16 @@ void monitor_cleanup(void)
(aio_poll(iohandler_get_aio_context(), false),
qatomic_mb_read(&qmp_dispatcher_co_busy)));

/*
* We need to explicitly stop the I/O thread (but not destroy it),
* clean up the monitor resources, then destroy the I/O thread since
* we need to unregister from chardev below in
* monitor_data_destroy(), and chardev is not thread-safe yet
*/
if (mon_iothread) {
iothread_stop(mon_iothread);
}

/* Flush output buffers and destroy monitors */
qemu_mutex_lock(&monitor_lock);
monitor_destroyed = true;
Expand Down
5 changes: 5 additions & 0 deletions monitor/qmp.c
Expand Up @@ -227,6 +227,11 @@ void coroutine_fn monitor_qmp_dispatcher_co(void *data)
*/
qatomic_mb_set(&qmp_dispatcher_co_busy, false);

/* On shutdown, don't take any more requests from the queue */
if (qmp_dispatcher_co_shutdown) {
return;
}

while (!(req_obj = monitor_qmp_requests_pop_any_with_lock())) {
/*
* No more requests to process. Wait to be reentered from
Expand Down
2 changes: 2 additions & 0 deletions storage-daemon/qemu-storage-daemon.c
Expand Up @@ -144,6 +144,8 @@ static void init_qmp_commands(void)
qmp_init_marshal(&qmp_commands);
qmp_register_command(&qmp_commands, "query-qmp-schema",
qmp_query_qmp_schema, QCO_ALLOW_PRECONFIG);
qmp_register_command(&qmp_commands, "object-add", qmp_object_add,
QCO_NO_OPTIONS);

QTAILQ_INIT(&qmp_cap_negotiation_commands);
qmp_register_command(&qmp_cap_negotiation_commands, "qmp_capabilities",
Expand Down
2 changes: 1 addition & 1 deletion tests/qemu-iotests/259
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
# group: rw auto quick
# group: rw quick
#
# Test generic image creation fallback (by using NBD)
#
Expand Down
4 changes: 3 additions & 1 deletion tests/qemu-iotests/common.rc
Expand Up @@ -885,7 +885,9 @@ _unsupported_imgopts()
{
for bad_opt
do
if echo "$IMGOPTS" | grep -q 2>/dev/null "$bad_opt"
# Add a space so tests can match for whitespace that marks the
# end of an option (\b or \> are not portable)
if echo "$IMGOPTS " | grep -q 2>/dev/null "$bad_opt"
then
_notrun "not suitable for image option: $bad_opt"
fi
Expand Down

0 comments on commit 8ba4bca

Please sign in to comment.