mirror of
https://github.com/xemu-project/xemu.git
synced 2026-07-11 01:24:41 +02:00
Merge tag 'v9.2.0'
v9.2.0 release
This commit is contained in:
+421
-129
@@ -354,7 +354,8 @@ static int parse_pattern(const char *arg)
|
||||
*/
|
||||
|
||||
#define MISALIGN_OFFSET 16
|
||||
static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern)
|
||||
static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern,
|
||||
bool register_buf)
|
||||
{
|
||||
void *buf;
|
||||
|
||||
@@ -363,16 +364,24 @@ static void *qemu_io_alloc(BlockBackend *blk, size_t len, int pattern)
|
||||
}
|
||||
buf = blk_blockalign(blk, len);
|
||||
memset(buf, pattern, len);
|
||||
if (register_buf) {
|
||||
blk_register_buf(blk, buf, len, &error_abort);
|
||||
}
|
||||
if (qemuio_misalign) {
|
||||
buf += MISALIGN_OFFSET;
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void qemu_io_free(void *p)
|
||||
static void qemu_io_free(BlockBackend *blk, void *p, size_t len,
|
||||
bool unregister_buf)
|
||||
{
|
||||
if (qemuio_misalign) {
|
||||
p -= MISALIGN_OFFSET;
|
||||
len += MISALIGN_OFFSET;
|
||||
}
|
||||
if (unregister_buf) {
|
||||
blk_unregister_buf(blk, p, len);
|
||||
}
|
||||
qemu_vfree(p);
|
||||
}
|
||||
@@ -387,14 +396,16 @@ static void qemu_io_free(void *p)
|
||||
* @blk - the block backend where the buffer content is going to be written to
|
||||
* @len - the buffer length
|
||||
* @file_name - the file to read the content from
|
||||
* @register_buf - call blk_register_buf()
|
||||
*
|
||||
* Returns: the buffer pointer on success
|
||||
* NULL on error
|
||||
*/
|
||||
static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
|
||||
const char *file_name)
|
||||
const char *file_name, bool register_buf)
|
||||
{
|
||||
char *buf, *buf_origin;
|
||||
size_t alloc_len = len + (qemuio_misalign ? MISALIGN_OFFSET : 0);
|
||||
char *alloc_buf, *buf, *end;
|
||||
FILE *f = fopen(file_name, "r");
|
||||
int pattern_len;
|
||||
|
||||
@@ -403,19 +414,13 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (qemuio_misalign) {
|
||||
len += MISALIGN_OFFSET;
|
||||
}
|
||||
|
||||
buf_origin = buf = blk_blockalign(blk, len);
|
||||
alloc_buf = buf = blk_blockalign(blk, alloc_len);
|
||||
|
||||
if (qemuio_misalign) {
|
||||
buf_origin += MISALIGN_OFFSET;
|
||||
buf += MISALIGN_OFFSET;
|
||||
len -= MISALIGN_OFFSET;
|
||||
}
|
||||
|
||||
pattern_len = fread(buf_origin, 1, len, f);
|
||||
pattern_len = fread(buf, 1, len, f);
|
||||
|
||||
if (ferror(f)) {
|
||||
perror(file_name);
|
||||
@@ -430,24 +435,23 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
|
||||
fclose(f);
|
||||
f = NULL;
|
||||
|
||||
if (len > pattern_len) {
|
||||
len -= pattern_len;
|
||||
buf += pattern_len;
|
||||
|
||||
while (len > 0) {
|
||||
size_t len_to_copy = MIN(pattern_len, len);
|
||||
|
||||
memcpy(buf, buf_origin, len_to_copy);
|
||||
|
||||
len -= len_to_copy;
|
||||
buf += len_to_copy;
|
||||
}
|
||||
if (register_buf) {
|
||||
blk_register_buf(blk, alloc_buf, alloc_len, &error_abort);
|
||||
}
|
||||
|
||||
return buf_origin;
|
||||
end = buf + len;
|
||||
for (char *p = buf + pattern_len; p < end; p += pattern_len) {
|
||||
memcpy(p, buf, MIN(pattern_len, end - p));
|
||||
}
|
||||
|
||||
return buf;
|
||||
|
||||
error:
|
||||
qemu_io_free(buf_origin);
|
||||
/*
|
||||
* This code path is only taken before blk_register_buf() is called, so
|
||||
* hardcode the qemu_io_free() unregister_buf argument to false.
|
||||
*/
|
||||
qemu_io_free(blk, alloc_buf, alloc_len, false);
|
||||
if (f) {
|
||||
fclose(f);
|
||||
}
|
||||
@@ -506,7 +510,7 @@ static void print_report(const char *op, struct timespec *t, int64_t offset,
|
||||
*/
|
||||
static void *
|
||||
create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
|
||||
int pattern)
|
||||
int pattern, bool register_buf)
|
||||
{
|
||||
size_t *sizes = g_new0(size_t, nr_iov);
|
||||
size_t count = 0;
|
||||
@@ -542,7 +546,7 @@ create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
|
||||
|
||||
qemu_iovec_init(qiov, nr_iov);
|
||||
|
||||
buf = p = qemu_io_alloc(blk, count, pattern);
|
||||
buf = p = qemu_io_alloc(blk, count, pattern, register_buf);
|
||||
|
||||
for (i = 0; i < nr_iov; i++) {
|
||||
qemu_iovec_add(qiov, p, sizes[i]);
|
||||
@@ -555,7 +559,7 @@ fail:
|
||||
}
|
||||
|
||||
static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
|
||||
int64_t bytes, int64_t *total)
|
||||
int64_t bytes, BdrvRequestFlags flags, int64_t *total)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -563,7 +567,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, 0);
|
||||
ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, flags);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
@@ -572,7 +576,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
|
||||
}
|
||||
|
||||
static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
|
||||
int64_t bytes, int flags, int64_t *total)
|
||||
int64_t bytes, BdrvRequestFlags flags, int64_t *total)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -588,54 +592,18 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
BlockBackend *blk;
|
||||
int64_t offset;
|
||||
int64_t bytes;
|
||||
int64_t *total;
|
||||
int flags;
|
||||
int ret;
|
||||
bool done;
|
||||
} CoWriteZeroes;
|
||||
|
||||
static void coroutine_fn co_pwrite_zeroes_entry(void *opaque)
|
||||
static int do_pwrite_zeroes(BlockBackend *blk, int64_t offset,
|
||||
int64_t bytes, BdrvRequestFlags flags,
|
||||
int64_t *total)
|
||||
{
|
||||
CoWriteZeroes *data = opaque;
|
||||
int ret = blk_pwrite_zeroes(blk, offset, bytes,
|
||||
flags | BDRV_REQ_ZERO_WRITE);
|
||||
|
||||
data->ret = blk_co_pwrite_zeroes(data->blk, data->offset, data->bytes,
|
||||
data->flags);
|
||||
data->done = true;
|
||||
if (data->ret < 0) {
|
||||
*data->total = data->ret;
|
||||
return;
|
||||
}
|
||||
|
||||
*data->total = data->bytes;
|
||||
}
|
||||
|
||||
static int do_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
|
||||
int64_t bytes, int flags, int64_t *total)
|
||||
{
|
||||
Coroutine *co;
|
||||
CoWriteZeroes data = {
|
||||
.blk = blk,
|
||||
.offset = offset,
|
||||
.bytes = bytes,
|
||||
.total = total,
|
||||
.flags = flags,
|
||||
.done = false,
|
||||
};
|
||||
|
||||
co = qemu_coroutine_create(co_pwrite_zeroes_entry, &data);
|
||||
bdrv_coroutine_enter(blk_bs(blk), co);
|
||||
while (!data.done) {
|
||||
aio_poll(blk_get_aio_context(blk), true);
|
||||
}
|
||||
if (data.ret < 0) {
|
||||
return data.ret;
|
||||
} else {
|
||||
return 1;
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
*total = bytes;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
|
||||
@@ -690,11 +658,11 @@ static void aio_rw_done(void *opaque, int ret)
|
||||
}
|
||||
|
||||
static int do_aio_readv(BlockBackend *blk, QEMUIOVector *qiov,
|
||||
int64_t offset, int *total)
|
||||
int64_t offset, BdrvRequestFlags flags, int *total)
|
||||
{
|
||||
int async_ret = NOT_DONE;
|
||||
|
||||
blk_aio_preadv(blk, offset, qiov, 0, aio_rw_done, &async_ret);
|
||||
blk_aio_preadv(blk, offset, qiov, flags, aio_rw_done, &async_ret);
|
||||
while (async_ret == NOT_DONE) {
|
||||
main_loop_wait(false);
|
||||
}
|
||||
@@ -704,7 +672,7 @@ static int do_aio_readv(BlockBackend *blk, QEMUIOVector *qiov,
|
||||
}
|
||||
|
||||
static int do_aio_writev(BlockBackend *blk, QEMUIOVector *qiov,
|
||||
int64_t offset, int flags, int *total)
|
||||
int64_t offset, BdrvRequestFlags flags, int *total)
|
||||
{
|
||||
int async_ret = NOT_DONE;
|
||||
|
||||
@@ -734,6 +702,7 @@ static void read_help(void)
|
||||
" -p, -- ignored for backwards compatibility\n"
|
||||
" -P, -- use a pattern to verify read data\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
" -s, -- start offset for pattern verification (only with -P)\n"
|
||||
" -v, -- dump buffer to standard output\n"
|
||||
"\n");
|
||||
@@ -747,7 +716,7 @@ static const cmdinfo_t read_cmd = {
|
||||
.cfunc = read_f,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-abCqv] [-P pattern [-s off] [-l len]] off len",
|
||||
.args = "[-abCqrv] [-P pattern [-s off] [-l len]] off len",
|
||||
.oneline = "reads a number of bytes at a specified offset",
|
||||
.help = read_help,
|
||||
};
|
||||
@@ -765,8 +734,9 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
|
||||
int64_t total = 0;
|
||||
int pattern = 0;
|
||||
int64_t pattern_offset = 0, pattern_count = 0;
|
||||
BdrvRequestFlags flags = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != -1) {
|
||||
while ((c = getopt(argc, argv, "bCl:pP:qrs:v")) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
bflag = true;
|
||||
@@ -795,6 +765,9 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
|
||||
case 'q':
|
||||
qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 's':
|
||||
sflag = true;
|
||||
pattern_offset = cvtnum(optarg);
|
||||
@@ -859,15 +832,20 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
|
||||
count);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (flags & BDRV_REQ_REGISTERED_BUF) {
|
||||
printf("I/O buffer registration is not supported when reading "
|
||||
"from vmstate\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
buf = qemu_io_alloc(blk, count, 0xab);
|
||||
buf = qemu_io_alloc(blk, count, 0xab, flags & BDRV_REQ_REGISTERED_BUF);
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||
if (bflag) {
|
||||
ret = do_load_vmstate(blk, buf, offset, count, &total);
|
||||
} else {
|
||||
ret = do_pread(blk, buf, offset, count, &total);
|
||||
ret = do_pread(blk, buf, offset, count, flags, &total);
|
||||
}
|
||||
clock_gettime(CLOCK_MONOTONIC, &t2);
|
||||
|
||||
@@ -904,7 +882,7 @@ static int read_f(BlockBackend *blk, int argc, char **argv)
|
||||
print_report("read", &t2, offset, count, total, cnt, Cflag);
|
||||
|
||||
out:
|
||||
qemu_io_free(buf);
|
||||
qemu_io_free(blk, buf, count, flags & BDRV_REQ_REGISTERED_BUF);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -922,8 +900,9 @@ static void readv_help(void)
|
||||
" Uses multiple iovec buffers if more than one byte range is specified.\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -P, -- use a pattern to verify read data\n"
|
||||
" -v, -- dump buffer to standard output\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
" -v, -- dump buffer to standard output\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -934,7 +913,7 @@ static const cmdinfo_t readv_cmd = {
|
||||
.cfunc = readv_f,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-Cqv] [-P pattern] off len [len..]",
|
||||
.args = "[-Cqrv] [-P pattern] off len [len..]",
|
||||
.oneline = "reads a number of bytes at a specified offset",
|
||||
.help = readv_help,
|
||||
};
|
||||
@@ -952,8 +931,9 @@ static int readv_f(BlockBackend *blk, int argc, char **argv)
|
||||
QEMUIOVector qiov;
|
||||
int pattern = 0;
|
||||
bool Pflag = false;
|
||||
BdrvRequestFlags flags = 0;
|
||||
|
||||
while ((c = getopt(argc, argv, "CP:qv")) != -1) {
|
||||
while ((c = getopt(argc, argv, "CP:qrv")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
Cflag = true;
|
||||
@@ -968,6 +948,9 @@ static int readv_f(BlockBackend *blk, int argc, char **argv)
|
||||
case 'q':
|
||||
qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 'v':
|
||||
vflag = true;
|
||||
break;
|
||||
@@ -991,13 +974,14 @@ static int readv_f(BlockBackend *blk, int argc, char **argv)
|
||||
optind++;
|
||||
|
||||
nr_iov = argc - optind;
|
||||
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab);
|
||||
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (buf == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||
ret = do_aio_readv(blk, &qiov, offset, &total);
|
||||
ret = do_aio_readv(blk, &qiov, offset, flags, &total);
|
||||
clock_gettime(CLOCK_MONOTONIC, &t2);
|
||||
|
||||
if (ret < 0) {
|
||||
@@ -1032,8 +1016,8 @@ static int readv_f(BlockBackend *blk, int argc, char **argv)
|
||||
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
|
||||
|
||||
out:
|
||||
qemu_io_free(blk, buf, qiov.size, flags & BDRV_REQ_REGISTERED_BUF);
|
||||
qemu_iovec_destroy(&qiov);
|
||||
qemu_io_free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1050,15 +1034,16 @@ static void write_help(void)
|
||||
" filled with a set pattern (0xcdcdcdcd).\n"
|
||||
" -b, -- write to the VM state rather than the virtual disk\n"
|
||||
" -c, -- write compressed data with blk_write_compressed\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -f, -- use Force Unit Access semantics\n"
|
||||
" -n, -- with -z, don't allow slow fallback\n"
|
||||
" -p, -- ignored for backwards compatibility\n"
|
||||
" -P, -- use different pattern to fill file\n"
|
||||
" -s, -- use a pattern file to fill the write buffer\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
" -s, -- use a pattern file to fill the write buffer\n"
|
||||
" -u, -- with -z, allow unmapping\n"
|
||||
" -z, -- write zeroes using blk_co_pwrite_zeroes\n"
|
||||
" -z, -- write zeroes using blk_pwrite_zeroes\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -1071,7 +1056,7 @@ static const cmdinfo_t write_cmd = {
|
||||
.perm = BLK_PERM_WRITE,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-bcCfnquz] [-P pattern | -s source_file] off len",
|
||||
.args = "[-bcCfnqruz] [-P pattern | -s source_file] off len",
|
||||
.oneline = "writes a number of bytes at a specified offset",
|
||||
.help = write_help,
|
||||
};
|
||||
@@ -1081,7 +1066,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
struct timespec t1, t2;
|
||||
bool Cflag = false, qflag = false, bflag = false;
|
||||
bool Pflag = false, zflag = false, cflag = false, sflag = false;
|
||||
int flags = 0;
|
||||
BdrvRequestFlags flags = 0;
|
||||
int c, cnt, ret;
|
||||
char *buf = NULL;
|
||||
int64_t offset;
|
||||
@@ -1091,7 +1076,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
int pattern = 0xcd;
|
||||
const char *file_name = NULL;
|
||||
|
||||
while ((c = getopt(argc, argv, "bcCfnpP:qs:uz")) != -1) {
|
||||
while ((c = getopt(argc, argv, "bcCfnpP:qrs:uz")) != -1) {
|
||||
switch (c) {
|
||||
case 'b':
|
||||
bflag = true;
|
||||
@@ -1121,6 +1106,9 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
case 'q':
|
||||
qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 's':
|
||||
sflag = true;
|
||||
file_name = optarg;
|
||||
@@ -1200,14 +1188,21 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (!zflag) {
|
||||
if (zflag) {
|
||||
if (flags & BDRV_REQ_REGISTERED_BUF) {
|
||||
printf("cannot combine zero write with registered I/O buffer\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
if (sflag) {
|
||||
buf = qemu_io_alloc_from_file(blk, count, file_name);
|
||||
buf = qemu_io_alloc_from_file(blk, count, file_name,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (!buf) {
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
buf = qemu_io_alloc(blk, count, pattern);
|
||||
buf = qemu_io_alloc(blk, count, pattern,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1215,7 +1210,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
if (bflag) {
|
||||
ret = do_save_vmstate(blk, buf, offset, count, &total);
|
||||
} else if (zflag) {
|
||||
ret = do_co_pwrite_zeroes(blk, offset, count, flags, &total);
|
||||
ret = do_pwrite_zeroes(blk, offset, count, flags, &total);
|
||||
} else if (cflag) {
|
||||
ret = do_write_compressed(blk, buf, offset, count, &total);
|
||||
} else {
|
||||
@@ -1241,7 +1236,7 @@ static int write_f(BlockBackend *blk, int argc, char **argv)
|
||||
|
||||
out:
|
||||
if (!zflag) {
|
||||
qemu_io_free(buf);
|
||||
qemu_io_free(blk, buf, count, flags & BDRV_REQ_REGISTERED_BUF);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -1258,10 +1253,11 @@ writev_help(void)
|
||||
"\n"
|
||||
" Writes into a segment of the currently open file, using a buffer\n"
|
||||
" filled with a set pattern (0xcdcdcdcd).\n"
|
||||
" -P, -- use different pattern to fill file\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -f, -- use Force Unit Access semantics\n"
|
||||
" -P, -- use different pattern to fill file\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -1273,7 +1269,7 @@ static const cmdinfo_t writev_cmd = {
|
||||
.perm = BLK_PERM_WRITE,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-Cfq] [-P pattern] off len [len..]",
|
||||
.args = "[-Cfqr] [-P pattern] off len [len..]",
|
||||
.oneline = "writes a number of bytes at a specified offset",
|
||||
.help = writev_help,
|
||||
};
|
||||
@@ -1282,7 +1278,7 @@ static int writev_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
struct timespec t1, t2;
|
||||
bool Cflag = false, qflag = false;
|
||||
int flags = 0;
|
||||
BdrvRequestFlags flags = 0;
|
||||
int c, cnt, ret;
|
||||
char *buf;
|
||||
int64_t offset;
|
||||
@@ -1292,7 +1288,7 @@ static int writev_f(BlockBackend *blk, int argc, char **argv)
|
||||
int pattern = 0xcd;
|
||||
QEMUIOVector qiov;
|
||||
|
||||
while ((c = getopt(argc, argv, "CfqP:")) != -1) {
|
||||
while ((c = getopt(argc, argv, "CfP:qr")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
Cflag = true;
|
||||
@@ -1303,6 +1299,9 @@ static int writev_f(BlockBackend *blk, int argc, char **argv)
|
||||
case 'q':
|
||||
qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 'P':
|
||||
pattern = parse_pattern(optarg);
|
||||
if (pattern < 0) {
|
||||
@@ -1328,7 +1327,8 @@ static int writev_f(BlockBackend *blk, int argc, char **argv)
|
||||
optind++;
|
||||
|
||||
nr_iov = argc - optind;
|
||||
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern);
|
||||
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (buf == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -1353,8 +1353,8 @@ static int writev_f(BlockBackend *blk, int argc, char **argv)
|
||||
t2 = tsub(t2, t1);
|
||||
print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag);
|
||||
out:
|
||||
qemu_io_free(blk, buf, qiov.size, flags & BDRV_REQ_REGISTERED_BUF);
|
||||
qemu_iovec_destroy(&qiov);
|
||||
qemu_io_free(buf);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1370,6 +1370,7 @@ struct aio_ctx {
|
||||
bool zflag;
|
||||
BlockAcctCookie acct;
|
||||
int pattern;
|
||||
BdrvRequestFlags flags;
|
||||
struct timespec t1;
|
||||
};
|
||||
|
||||
@@ -1399,7 +1400,8 @@ static void aio_write_done(void *opaque, int ret)
|
||||
ctx->qiov.size, 1, ctx->Cflag);
|
||||
out:
|
||||
if (!ctx->zflag) {
|
||||
qemu_io_free(ctx->buf);
|
||||
qemu_io_free(ctx->blk, ctx->buf, ctx->qiov.size,
|
||||
ctx->flags & BDRV_REQ_REGISTERED_BUF);
|
||||
qemu_iovec_destroy(&ctx->qiov);
|
||||
}
|
||||
g_free(ctx);
|
||||
@@ -1444,7 +1446,8 @@ static void aio_read_done(void *opaque, int ret)
|
||||
print_report("read", &t2, ctx->offset, ctx->qiov.size,
|
||||
ctx->qiov.size, 1, ctx->Cflag);
|
||||
out:
|
||||
qemu_io_free(ctx->buf);
|
||||
qemu_io_free(ctx->blk, ctx->buf, ctx->qiov.size,
|
||||
ctx->flags & BDRV_REQ_REGISTERED_BUF);
|
||||
qemu_iovec_destroy(&ctx->qiov);
|
||||
g_free(ctx);
|
||||
}
|
||||
@@ -1466,10 +1469,11 @@ static void aio_read_help(void)
|
||||
" considered successful once the request is submitted, independently\n"
|
||||
" of potential I/O errors or pattern mismatches.\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -P, -- use a pattern to verify read data\n"
|
||||
" -i, -- treat request as invalid, for exercising stats\n"
|
||||
" -v, -- dump buffer to standard output\n"
|
||||
" -P, -- use a pattern to verify read data\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
" -v, -- dump buffer to standard output\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
@@ -1480,7 +1484,7 @@ static const cmdinfo_t aio_read_cmd = {
|
||||
.cfunc = aio_read_f,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-Ciqv] [-P pattern] off len [len..]",
|
||||
.args = "[-Ciqrv] [-P pattern] off len [len..]",
|
||||
.oneline = "asynchronously reads a number of bytes",
|
||||
.help = aio_read_help,
|
||||
};
|
||||
@@ -1491,7 +1495,7 @@ static int aio_read_f(BlockBackend *blk, int argc, char **argv)
|
||||
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
|
||||
|
||||
ctx->blk = blk;
|
||||
while ((c = getopt(argc, argv, "CP:iqv")) != -1) {
|
||||
while ((c = getopt(argc, argv, "CiP:qrv")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
ctx->Cflag = true;
|
||||
@@ -1512,6 +1516,9 @@ static int aio_read_f(BlockBackend *blk, int argc, char **argv)
|
||||
case 'q':
|
||||
ctx->qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
ctx->flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 'v':
|
||||
ctx->vflag = true;
|
||||
break;
|
||||
@@ -1538,7 +1545,8 @@ static int aio_read_f(BlockBackend *blk, int argc, char **argv)
|
||||
optind++;
|
||||
|
||||
nr_iov = argc - optind;
|
||||
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab);
|
||||
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab,
|
||||
ctx->flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (ctx->buf == NULL) {
|
||||
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ);
|
||||
g_free(ctx);
|
||||
@@ -1548,7 +1556,8 @@ static int aio_read_f(BlockBackend *blk, int argc, char **argv)
|
||||
clock_gettime(CLOCK_MONOTONIC, &ctx->t1);
|
||||
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
|
||||
BLOCK_ACCT_READ);
|
||||
blk_aio_preadv(blk, ctx->offset, &ctx->qiov, 0, aio_read_done, ctx);
|
||||
blk_aio_preadv(blk, ctx->offset, &ctx->qiov, ctx->flags, aio_read_done,
|
||||
ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1569,11 +1578,12 @@ static void aio_write_help(void)
|
||||
" Note that due to its asynchronous nature, this command will be\n"
|
||||
" considered successful once the request is submitted, independently\n"
|
||||
" of potential I/O errors or pattern mismatches.\n"
|
||||
" -P, -- use different pattern to fill file\n"
|
||||
" -C, -- report statistics in a machine parsable format\n"
|
||||
" -f, -- use Force Unit Access semantics\n"
|
||||
" -i, -- treat request as invalid, for exercising stats\n"
|
||||
" -P, -- use different pattern to fill file\n"
|
||||
" -q, -- quiet mode, do not show I/O statistics\n"
|
||||
" -r, -- register I/O buffer\n"
|
||||
" -u, -- with -z, allow unmapping\n"
|
||||
" -z, -- write zeroes using blk_aio_pwrite_zeroes\n"
|
||||
"\n");
|
||||
@@ -1587,7 +1597,7 @@ static const cmdinfo_t aio_write_cmd = {
|
||||
.perm = BLK_PERM_WRITE,
|
||||
.argmin = 2,
|
||||
.argmax = -1,
|
||||
.args = "[-Cfiquz] [-P pattern] off len [len..]",
|
||||
.args = "[-Cfiqruz] [-P pattern] off len [len..]",
|
||||
.oneline = "asynchronously writes a number of bytes",
|
||||
.help = aio_write_help,
|
||||
};
|
||||
@@ -1597,22 +1607,24 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||
int nr_iov, c;
|
||||
int pattern = 0xcd;
|
||||
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
|
||||
int flags = 0;
|
||||
|
||||
ctx->blk = blk;
|
||||
while ((c = getopt(argc, argv, "CfiqP:uz")) != -1) {
|
||||
while ((c = getopt(argc, argv, "CfiP:qruz")) != -1) {
|
||||
switch (c) {
|
||||
case 'C':
|
||||
ctx->Cflag = true;
|
||||
break;
|
||||
case 'f':
|
||||
flags |= BDRV_REQ_FUA;
|
||||
ctx->flags |= BDRV_REQ_FUA;
|
||||
break;
|
||||
case 'q':
|
||||
ctx->qflag = true;
|
||||
break;
|
||||
case 'r':
|
||||
ctx->flags |= BDRV_REQ_REGISTERED_BUF;
|
||||
break;
|
||||
case 'u':
|
||||
flags |= BDRV_REQ_MAY_UNMAP;
|
||||
ctx->flags |= BDRV_REQ_MAY_UNMAP;
|
||||
break;
|
||||
case 'P':
|
||||
pattern = parse_pattern(optarg);
|
||||
@@ -1648,7 +1660,7 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
|
||||
if ((ctx->flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
|
||||
printf("-u requires -z to be specified\n");
|
||||
g_free(ctx);
|
||||
return -EINVAL;
|
||||
@@ -1660,6 +1672,12 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (ctx->zflag && (ctx->flags & BDRV_REQ_REGISTERED_BUF)) {
|
||||
printf("cannot combine zero write with registered I/O buffer\n");
|
||||
g_free(ctx);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ctx->offset = cvtnum(argv[optind]);
|
||||
if (ctx->offset < 0) {
|
||||
int ret = ctx->offset;
|
||||
@@ -1678,12 +1696,12 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||
}
|
||||
|
||||
ctx->qiov.size = count;
|
||||
blk_aio_pwrite_zeroes(blk, ctx->offset, count, flags, aio_write_done,
|
||||
ctx);
|
||||
blk_aio_pwrite_zeroes(blk, ctx->offset, count, ctx->flags,
|
||||
aio_write_done, ctx);
|
||||
} else {
|
||||
nr_iov = argc - optind;
|
||||
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov,
|
||||
pattern);
|
||||
pattern, ctx->flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (ctx->buf == NULL) {
|
||||
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
|
||||
g_free(ctx);
|
||||
@@ -1694,8 +1712,8 @@ static int aio_write_f(BlockBackend *blk, int argc, char **argv)
|
||||
block_acct_start(blk_get_stats(blk), &ctx->acct, ctx->qiov.size,
|
||||
BLOCK_ACCT_WRITE);
|
||||
|
||||
blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, flags, aio_write_done,
|
||||
ctx);
|
||||
blk_aio_pwritev(blk, ctx->offset, &ctx->qiov, ctx->flags,
|
||||
aio_write_done, ctx);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1728,6 +1746,270 @@ static const cmdinfo_t flush_cmd = {
|
||||
.oneline = "flush all in-core file state to disk",
|
||||
};
|
||||
|
||||
static inline int64_t tosector(int64_t bytes)
|
||||
{
|
||||
return bytes >> BDRV_SECTOR_BITS;
|
||||
}
|
||||
|
||||
static int zone_report_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int64_t offset;
|
||||
int64_t val;
|
||||
unsigned int nr_zones;
|
||||
|
||||
++optind;
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
++optind;
|
||||
val = cvtnum(argv[optind]);
|
||||
if (val < 0) {
|
||||
print_cvtnum_err(val, argv[optind]);
|
||||
return val;
|
||||
}
|
||||
if (val > UINT_MAX) {
|
||||
printf("Number of zones must be less than 2^32\n");
|
||||
return -ERANGE;
|
||||
}
|
||||
nr_zones = val;
|
||||
|
||||
g_autofree BlockZoneDescriptor *zones = NULL;
|
||||
zones = g_new(BlockZoneDescriptor, nr_zones);
|
||||
ret = blk_zone_report(blk, offset, &nr_zones, zones);
|
||||
if (ret < 0) {
|
||||
printf("zone report failed: %s\n", strerror(-ret));
|
||||
} else {
|
||||
for (int i = 0; i < nr_zones; ++i) {
|
||||
printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", "
|
||||
"cap"" 0x%" PRIx64 ", wptr 0x%" PRIx64 ", "
|
||||
"zcond:%u, [type: %u]\n",
|
||||
tosector(zones[i].start), tosector(zones[i].length),
|
||||
tosector(zones[i].cap), tosector(zones[i].wp),
|
||||
zones[i].state, zones[i].type);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_report_cmd = {
|
||||
.name = "zone_report",
|
||||
.altname = "zrp",
|
||||
.cfunc = zone_report_f,
|
||||
.argmin = 2,
|
||||
.argmax = 2,
|
||||
.args = "offset number",
|
||||
.oneline = "report zone information",
|
||||
};
|
||||
|
||||
static int zone_open_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int64_t offset, len;
|
||||
++optind;
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
++optind;
|
||||
len = cvtnum(argv[optind]);
|
||||
if (len < 0) {
|
||||
print_cvtnum_err(len, argv[optind]);
|
||||
return len;
|
||||
}
|
||||
ret = blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len);
|
||||
if (ret < 0) {
|
||||
printf("zone open failed: %s\n", strerror(-ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_open_cmd = {
|
||||
.name = "zone_open",
|
||||
.altname = "zo",
|
||||
.cfunc = zone_open_f,
|
||||
.argmin = 2,
|
||||
.argmax = 2,
|
||||
.args = "offset len",
|
||||
.oneline = "explicit open a range of zones in zone block device",
|
||||
};
|
||||
|
||||
static int zone_close_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int64_t offset, len;
|
||||
++optind;
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
++optind;
|
||||
len = cvtnum(argv[optind]);
|
||||
if (len < 0) {
|
||||
print_cvtnum_err(len, argv[optind]);
|
||||
return len;
|
||||
}
|
||||
ret = blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len);
|
||||
if (ret < 0) {
|
||||
printf("zone close failed: %s\n", strerror(-ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_close_cmd = {
|
||||
.name = "zone_close",
|
||||
.altname = "zc",
|
||||
.cfunc = zone_close_f,
|
||||
.argmin = 2,
|
||||
.argmax = 2,
|
||||
.args = "offset len",
|
||||
.oneline = "close a range of zones in zone block device",
|
||||
};
|
||||
|
||||
static int zone_finish_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int64_t offset, len;
|
||||
++optind;
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
++optind;
|
||||
len = cvtnum(argv[optind]);
|
||||
if (len < 0) {
|
||||
print_cvtnum_err(len, argv[optind]);
|
||||
return len;
|
||||
}
|
||||
ret = blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len);
|
||||
if (ret < 0) {
|
||||
printf("zone finish failed: %s\n", strerror(-ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_finish_cmd = {
|
||||
.name = "zone_finish",
|
||||
.altname = "zf",
|
||||
.cfunc = zone_finish_f,
|
||||
.argmin = 2,
|
||||
.argmax = 2,
|
||||
.args = "offset len",
|
||||
.oneline = "finish a range of zones in zone block device",
|
||||
};
|
||||
|
||||
static int zone_reset_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
int64_t offset, len;
|
||||
++optind;
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
++optind;
|
||||
len = cvtnum(argv[optind]);
|
||||
if (len < 0) {
|
||||
print_cvtnum_err(len, argv[optind]);
|
||||
return len;
|
||||
}
|
||||
ret = blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len);
|
||||
if (ret < 0) {
|
||||
printf("zone reset failed: %s\n", strerror(-ret));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_reset_cmd = {
|
||||
.name = "zone_reset",
|
||||
.altname = "zrs",
|
||||
.cfunc = zone_reset_f,
|
||||
.argmin = 2,
|
||||
.argmax = 2,
|
||||
.args = "offset len",
|
||||
.oneline = "reset a zone write pointer in zone block device",
|
||||
};
|
||||
|
||||
static int do_aio_zone_append(BlockBackend *blk, QEMUIOVector *qiov,
|
||||
int64_t *offset, int flags, int *total)
|
||||
{
|
||||
int async_ret = NOT_DONE;
|
||||
|
||||
blk_aio_zone_append(blk, offset, qiov, flags, aio_rw_done, &async_ret);
|
||||
while (async_ret == NOT_DONE) {
|
||||
main_loop_wait(false);
|
||||
}
|
||||
|
||||
*total = qiov->size;
|
||||
return async_ret < 0 ? async_ret : 1;
|
||||
}
|
||||
|
||||
static int zone_append_f(BlockBackend *blk, int argc, char **argv)
|
||||
{
|
||||
int ret;
|
||||
bool pflag = false;
|
||||
int flags = 0;
|
||||
int total = 0;
|
||||
int64_t offset;
|
||||
char *buf;
|
||||
int c, nr_iov;
|
||||
int pattern = 0xcd;
|
||||
QEMUIOVector qiov;
|
||||
|
||||
if (optind > argc - 3) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if ((c = getopt(argc, argv, "p")) != -1) {
|
||||
pflag = true;
|
||||
}
|
||||
|
||||
offset = cvtnum(argv[optind]);
|
||||
if (offset < 0) {
|
||||
print_cvtnum_err(offset, argv[optind]);
|
||||
return offset;
|
||||
}
|
||||
optind++;
|
||||
nr_iov = argc - optind;
|
||||
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
if (buf == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
ret = do_aio_zone_append(blk, &qiov, &offset, flags, &total);
|
||||
if (ret < 0) {
|
||||
printf("zone append failed: %s\n", strerror(-ret));
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (pflag) {
|
||||
printf("After zap done, the append sector is 0x%" PRIx64 "\n",
|
||||
tosector(offset));
|
||||
}
|
||||
|
||||
out:
|
||||
qemu_io_free(blk, buf, qiov.size,
|
||||
flags & BDRV_REQ_REGISTERED_BUF);
|
||||
qemu_iovec_destroy(&qiov);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static const cmdinfo_t zone_append_cmd = {
|
||||
.name = "zone_append",
|
||||
.altname = "zap",
|
||||
.cfunc = zone_append_f,
|
||||
.argmin = 3,
|
||||
.argmax = 4,
|
||||
.args = "offset len [len..]",
|
||||
.oneline = "append write a number of bytes at a specified offset",
|
||||
};
|
||||
|
||||
static int truncate_f(BlockBackend *blk, int argc, char **argv);
|
||||
static const cmdinfo_t truncate_cmd = {
|
||||
.name = "truncate",
|
||||
@@ -1817,6 +2099,9 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
|
||||
char s1[64], s2[64];
|
||||
int ret;
|
||||
|
||||
GLOBAL_STATE_CODE();
|
||||
GRAPH_RDLOCK_GUARD_MAINLOOP();
|
||||
|
||||
if (bs->drv && bs->drv->format_name) {
|
||||
printf("format name: %s\n", bs->drv->format_name);
|
||||
}
|
||||
@@ -1841,8 +2126,9 @@ static int info_f(BlockBackend *blk, int argc, char **argv)
|
||||
return -EIO;
|
||||
}
|
||||
if (spec_info) {
|
||||
printf("Format specific information:\n");
|
||||
bdrv_image_info_specific_dump(spec_info);
|
||||
bdrv_image_info_specific_dump(spec_info,
|
||||
"Format specific information:\n",
|
||||
0);
|
||||
qapi_free_ImageInfoSpecific(spec_info);
|
||||
}
|
||||
|
||||
@@ -2520,6 +2806,12 @@ static void __attribute((constructor)) init_qemuio_commands(void)
|
||||
qemuio_add_command(&aio_write_cmd);
|
||||
qemuio_add_command(&aio_flush_cmd);
|
||||
qemuio_add_command(&flush_cmd);
|
||||
qemuio_add_command(&zone_report_cmd);
|
||||
qemuio_add_command(&zone_open_cmd);
|
||||
qemuio_add_command(&zone_close_cmd);
|
||||
qemuio_add_command(&zone_finish_cmd);
|
||||
qemuio_add_command(&zone_reset_cmd);
|
||||
qemuio_add_command(&zone_append_cmd);
|
||||
qemuio_add_command(&truncate_cmd);
|
||||
qemuio_add_command(&length_cmd);
|
||||
qemuio_add_command(&info_cmd);
|
||||
|
||||
Reference in New Issue
Block a user