aboutsummaryrefslogtreecommitdiff
path: root/block
diff options
context:
space:
mode:
Diffstat (limited to 'block')
-rw-r--r--block/nbd.c1
-rw-r--r--block/nfs.c1
-rw-r--r--block/qcow2.h2
-rw-r--r--block/raw-posix.c56
-rw-r--r--block/raw_bsd.c12
-rw-r--r--block/ssh.c5
6 files changed, 42 insertions, 35 deletions
diff --git a/block/nbd.c b/block/nbd.c
index 9cff839..35f24be 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -536,6 +536,7 @@ static void nbd_refresh_filename(BlockDriverState *bs, QDict *options)
ov = qobject_output_visitor_new(&saddr_qdict);
visit_type_SocketAddress(ov, NULL, &s->saddr, &error_abort);
visit_complete(ov, &saddr_qdict);
+ visit_free(ov);
assert(qobject_type(saddr_qdict) == QTYPE_QDICT);
qdict_put_obj(opts, "server", saddr_qdict);
diff --git a/block/nfs.c b/block/nfs.c
index 55c4e0b..d082783 100644
--- a/block/nfs.c
+++ b/block/nfs.c
@@ -676,6 +676,7 @@ static int nfs_file_create(const char *url, QemuOpts *opts, Error **errp)
ret = nfs_ftruncate(client->context, client->fh, total_size);
nfs_client_close(client);
out:
+ QDECREF(options);
g_free(client);
return ret;
}
diff --git a/block/qcow2.h b/block/qcow2.h
index 92203a8..1823414 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -473,8 +473,6 @@ static inline uint64_t refcount_diff(uint64_t r1, uint64_t r2)
return r1 > r2 ? r1 - r2 : r2 - r1;
}
-// FIXME Need qcow2_ prefix to global functions
-
/* qcow2.c functions */
int qcow2_backing_read1(BlockDriverState *bs, QEMUIOVector *qiov,
int64_t sector_num, int nb_sectors);
diff --git a/block/raw-posix.c b/block/raw-posix.c
index 247e47b..28b47d9 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -542,7 +542,7 @@ static int raw_reopen_prepare(BDRVReopenState *state,
BlockReopenQueue *queue, Error **errp)
{
BDRVRawState *s;
- BDRVRawReopenState *raw_s;
+ BDRVRawReopenState *rs;
int ret = 0;
Error *local_err = NULL;
@@ -552,15 +552,15 @@ static int raw_reopen_prepare(BDRVReopenState *state,
s = state->bs->opaque;
state->opaque = g_new0(BDRVRawReopenState, 1);
- raw_s = state->opaque;
+ rs = state->opaque;
if (s->type == FTYPE_CD) {
- raw_s->open_flags |= O_NONBLOCK;
+ rs->open_flags |= O_NONBLOCK;
}
- raw_parse_flags(state->flags, &raw_s->open_flags);
+ raw_parse_flags(state->flags, &rs->open_flags);
- raw_s->fd = -1;
+ rs->fd = -1;
int fcntl_flags = O_APPEND | O_NONBLOCK;
#ifdef O_NOATIME
@@ -569,35 +569,35 @@ static int raw_reopen_prepare(BDRVReopenState *state,
#ifdef O_ASYNC
/* Not all operating systems have O_ASYNC, and those that don't
- * will not let us track the state into raw_s->open_flags (typically
+ * will not let us track the state into rs->open_flags (typically
* you achieve the same effect with an ioctl, for example I_SETSIG
* on Solaris). But we do not use O_ASYNC, so that's fine.
*/
assert((s->open_flags & O_ASYNC) == 0);
#endif
- if ((raw_s->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {
+ if ((rs->open_flags & ~fcntl_flags) == (s->open_flags & ~fcntl_flags)) {
/* dup the original fd */
- raw_s->fd = qemu_dup(s->fd);
- if (raw_s->fd >= 0) {
- ret = fcntl_setfl(raw_s->fd, raw_s->open_flags);
+ rs->fd = qemu_dup(s->fd);
+ if (rs->fd >= 0) {
+ ret = fcntl_setfl(rs->fd, rs->open_flags);
if (ret) {
- qemu_close(raw_s->fd);
- raw_s->fd = -1;
+ qemu_close(rs->fd);
+ rs->fd = -1;
}
}
}
/* If we cannot use fcntl, or fcntl failed, fall back to qemu_open() */
- if (raw_s->fd == -1) {
+ if (rs->fd == -1) {
const char *normalized_filename = state->bs->filename;
ret = raw_normalize_devicepath(&normalized_filename);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not normalize device path");
} else {
- assert(!(raw_s->open_flags & O_CREAT));
- raw_s->fd = qemu_open(normalized_filename, raw_s->open_flags);
- if (raw_s->fd == -1) {
+ assert(!(rs->open_flags & O_CREAT));
+ rs->fd = qemu_open(normalized_filename, rs->open_flags);
+ if (rs->fd == -1) {
error_setg_errno(errp, errno, "Could not reopen file");
ret = -1;
}
@@ -606,11 +606,11 @@ static int raw_reopen_prepare(BDRVReopenState *state,
/* Fail already reopen_prepare() if we can't get a working O_DIRECT
* alignment with the new fd. */
- if (raw_s->fd != -1) {
- raw_probe_alignment(state->bs, raw_s->fd, &local_err);
+ if (rs->fd != -1) {
+ raw_probe_alignment(state->bs, rs->fd, &local_err);
if (local_err) {
- qemu_close(raw_s->fd);
- raw_s->fd = -1;
+ qemu_close(rs->fd);
+ rs->fd = -1;
error_propagate(errp, local_err);
ret = -EINVAL;
}
@@ -621,13 +621,13 @@ static int raw_reopen_prepare(BDRVReopenState *state,
static void raw_reopen_commit(BDRVReopenState *state)
{
- BDRVRawReopenState *raw_s = state->opaque;
+ BDRVRawReopenState *rs = state->opaque;
BDRVRawState *s = state->bs->opaque;
- s->open_flags = raw_s->open_flags;
+ s->open_flags = rs->open_flags;
qemu_close(s->fd);
- s->fd = raw_s->fd;
+ s->fd = rs->fd;
g_free(state->opaque);
state->opaque = NULL;
@@ -636,16 +636,16 @@ static void raw_reopen_commit(BDRVReopenState *state)
static void raw_reopen_abort(BDRVReopenState *state)
{
- BDRVRawReopenState *raw_s = state->opaque;
+ BDRVRawReopenState *rs = state->opaque;
/* nothing to do if NULL, we didn't get far enough */
- if (raw_s == NULL) {
+ if (rs == NULL) {
return;
}
- if (raw_s->fd >= 0) {
- qemu_close(raw_s->fd);
- raw_s->fd = -1;
+ if (rs->fd >= 0) {
+ qemu_close(rs->fd);
+ rs->fd = -1;
}
g_free(state->opaque);
state->opaque = NULL;
diff --git a/block/raw_bsd.c b/block/raw_bsd.c
index 7c9bebb..8a5b9b0 100644
--- a/block/raw_bsd.c
+++ b/block/raw_bsd.c
@@ -91,6 +91,14 @@ static int raw_read_options(QDict *options, BlockDriverState *bs,
}
s->offset = qemu_opt_get_size(opts, "offset", 0);
+ if (s->offset > real_size) {
+ error_setg(errp, "Offset (%" PRIu64 ") cannot be greater than "
+ "size of the containing file (%" PRId64 ")",
+ s->offset, real_size);
+ ret = -EINVAL;
+ goto end;
+ }
+
if (qemu_opt_find(opts, "size") != NULL) {
s->size = qemu_opt_get_size(opts, "size", 0);
s->has_size = true;
@@ -100,7 +108,7 @@ static int raw_read_options(QDict *options, BlockDriverState *bs,
}
/* Check size and offset */
- if (real_size < s->offset || (real_size - s->offset) < s->size) {
+ if ((real_size - s->offset) < s->size) {
error_setg(errp, "The sum of offset (%" PRIu64 ") and size "
"(%" PRIu64 ") has to be smaller or equal to the "
" actual size of the containing file (%" PRId64 ")",
@@ -111,7 +119,7 @@ static int raw_read_options(QDict *options, BlockDriverState *bs,
/* Make sure size is multiple of BDRV_SECTOR_SIZE to prevent rounding
* up and leaking out of the specified area. */
- if (!QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {
+ if (s->has_size && !QEMU_IS_ALIGNED(s->size, BDRV_SECTOR_SIZE)) {
error_setg(errp, "Specified size is not multiple of %llu",
BDRV_SECTOR_SIZE);
ret = -EINVAL;
diff --git a/block/ssh.c b/block/ssh.c
index ca071c5..15ed281 100644
--- a/block/ssh.c
+++ b/block/ssh.c
@@ -582,8 +582,7 @@ static bool ssh_process_legacy_socket_options(QDict *output_opts,
return true;
}
-static InetSocketAddress *ssh_config(BDRVSSHState *s, QDict *options,
- Error **errp)
+static InetSocketAddress *ssh_config(QDict *options, Error **errp)
{
InetSocketAddress *inet = NULL;
QDict *addr = NULL;
@@ -661,7 +660,7 @@ static int connect_to_ssh(BDRVSSHState *s, QDict *options,
}
/* Pop the config into our state object, Exit if invalid */
- s->inet = ssh_config(s, options, errp);
+ s->inet = ssh_config(options, errp);
if (!s->inet) {
ret = -EINVAL;
goto err;