#include "qemu/osdep.h"
#include <getopt.h>
-#include "qemu-common.h"
+#include "qemu/help-texts.h"
+#include "qemu/qemu-progress.h"
#include "qemu-version.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-block-core.h"
#include "qemu/module.h"
#include "qemu/sockets.h"
#include "qemu/units.h"
+#include "qemu/memalign.h"
#include "qom/object_interfaces.h"
#include "sysemu/block-backend.h"
#include "block/block_int.h"
printf(" %s", name);
}
-static void QEMU_NORETURN GCC_FMT_ATTR(1, 2) error_exit(const char *fmt, ...)
+static G_NORETURN G_GNUC_PRINTF(1, 2)
+void error_exit(const char *fmt, ...)
{
va_list ap;
exit(EXIT_FAILURE);
}
-static void QEMU_NORETURN missing_argument(const char *option)
+static G_NORETURN
+void missing_argument(const char *option)
{
error_exit("missing argument for option '%s'", option);
}
-static void QEMU_NORETURN unrecognized_option(const char *option)
+static G_NORETURN
+void unrecognized_option(const char *option)
{
error_exit("unrecognized option '%s'", option);
}
/* Please keep in synch with docs/tools/qemu-img.rst */
-static void QEMU_NORETURN help(void)
+static G_NORETURN
+void help(void)
{
const char *help_msg =
QEMU_IMG_VERSION
},
};
-static int GCC_FMT_ATTR(2, 3) qprintf(bool quiet, const char *fmt, ...)
+static int G_GNUC_PRINTF(2, 3) qprintf(bool quiet, const char *fmt, ...)
{
int ret = 0;
if (!quiet) {
static void run_block_job(BlockJob *job, Error **errp)
{
uint64_t progress_current, progress_total;
- AioContext *aio_context = blk_get_aio_context(job->blk);
+ AioContext *aio_context = block_job_get_aio_context(job);
int ret = 0;
aio_context_acquire(aio_context);
}
}
+ if (i == n) {
+ /*
+ * The whole buf is the same.
+ * No reason to split it into chunks, so return now.
+ */
+ *pnum = i;
+ return !is_zero;
+ }
+
tail = (sector_num + i) & (alignment - 1);
if (tail) {
if (is_zero && i <= tail) {
- /* treat unallocated areas which only consist
- * of a small tail as allocated. */
+ /*
+ * For sure next sector after i is data, and it will rewrite this
+ * tail anyway due to RMW. So, let's just write data now.
+ */
is_zero = false;
}
if (!is_zero) {
- /* align up end offset of allocated areas. */
+ /* If possible, align up end offset of allocated areas. */
i += alignment - tail;
i = MIN(i, n);
} else {
- /* align down end offset of zero areas. */
+ /*
+ * For sure next sector after i is data, and it will rewrite this
+ * tail anyway due to RMW. Better is avoid RMW and write zeroes up
+ * to aligned bound.
+ */
i -= tail;
}
}
int ret = 0;
int64_t idx;
- ret = blk_pread(blk, offset, buffer, bytes);
+ ret = blk_pread(blk, offset, bytes, buffer, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s",
offset, filename, strerror(-ret));
int64_t pnum;
chunk = MIN(chunk, IO_BUF_SIZE);
- ret = blk_pread(blk1, offset, buf1, chunk);
+ ret = blk_pread(blk1, offset, chunk, buf1, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s",
ret = 4;
goto out;
}
- ret = blk_pread(blk2, offset, buf2, chunk);
+ ret = blk_pread(blk2, offset, chunk, buf2, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s",
const char *src_node, const char *src_name,
Error **errp)
{
- BlockDirtyBitmapMergeSource *merge_src;
- BlockDirtyBitmapMergeSourceList *list = NULL;
+ BlockDirtyBitmapOrStr *merge_src;
+ BlockDirtyBitmapOrStrList *list = NULL;
- merge_src = g_new0(BlockDirtyBitmapMergeSource, 1);
+ merge_src = g_new0(BlockDirtyBitmapOrStr, 1);
merge_src->type = QTYPE_QDICT;
merge_src->u.external.node = g_strdup(src_node);
merge_src->u.external.name = g_strdup(src_name);
QAPI_LIST_PREPEND(list, merge_src);
qmp_block_dirty_bitmap_merge(dst_node, dst_name, list, errp);
- qapi_free_BlockDirtyBitmapMergeSourceList(list);
+ qapi_free_BlockDirtyBitmapOrStrList(list);
}
enum ImgConvertBlockStatus {
if (s->compressed && !s->ret) {
/* signal EOF to align */
- ret = blk_pwrite_compressed(s->target, 0, NULL, 0);
+ ret = blk_pwrite_compressed(s->target, 0, 0, NULL);
if (ret < 0) {
return ret;
}
char *filename, *snapshot_name = NULL;
int c, ret = 0, bdrv_oflags;
int action = 0;
- qemu_timeval tv;
bool quiet = false;
Error *err = NULL;
bool image_opts = false;
bool force_share = false;
+ int64_t rt;
bdrv_oflags = BDRV_O_RDWR;
/* Parse commandline parameters */
memset(&sn, 0, sizeof(sn));
pstrcpy(sn.name, sizeof(sn.name), snapshot_name);
- qemu_gettimeofday(&tv);
- sn.date_sec = tv.tv_sec;
- sn.date_nsec = tv.tv_usec * 1000;
+ rt = g_get_real_time();
+ sn.date_sec = rt / G_USEC_PER_SEC;
+ sn.date_nsec = (rt % G_USEC_PER_SEC) * 1000;
ret = bdrv_snapshot_create(bs, &sn);
if (ret) {
n = old_backing_size - offset;
}
- ret = blk_pread(blk_old_backing, offset, buf_old, n);
+ ret = blk_pread(blk_old_backing, offset, n, buf_old, 0);
if (ret < 0) {
error_report("error while reading from old backing file");
goto out;
n = new_backing_size - offset;
}
- ret = blk_pread(blk_new_backing, offset, buf_new, n);
+ ret = blk_pread(blk_new_backing, offset, n, buf_new, 0);
if (ret < 0) {
error_report("error while reading from new backing file");
goto out;
if (buf_old_is_zero) {
ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0);
} else {
- ret = blk_pwrite(blk, offset + written,
- buf_old + written, pnum, 0);
+ ret = blk_pwrite(blk, offset + written, pnum,
+ buf_old + written, 0);
}
if (ret < 0) {
error_report("Error while writing to COW image: %s",
in.buf = g_new(uint8_t, in.bsz);
for (out_pos = 0; in_pos < size; block_count++) {
- int in_ret, out_ret;
+ int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
- if (in_pos + in.bsz > size) {
- in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
- } else {
- in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
- }
- if (in_ret < 0) {
+ ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
+ if (ret < 0) {
error_report("error while reading from input image file: %s",
- strerror(-in_ret));
- ret = -1;
+ strerror(-ret));
goto out;
}
- in_pos += in_ret;
+ in_pos += bytes;
- out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
-
- if (out_ret < 0) {
+ ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0);
+ if (ret < 0) {
error_report("error while writing to output image file: %s",
- strerror(-out_ret));
- ret = -1;
+ strerror(-ret));
goto out;
}
- out_pos += out_ret;
+ out_pos += bytes;
}
out:
exit(1);
}
trace_init_file();
- qemu_set_log(LOG_TRACE);
+ qemu_set_log(LOG_TRACE, &error_fatal);
/* find the command */
for (cmd = img_cmds; cmd->name != NULL; cmd++) {