version 1.1.1.1, 2018/04/24 17:21:26
|
version 1.1.1.2, 2018/04/24 17:35:06
|
Line 28 static BlockDriverState *bs;
|
Line 28 static BlockDriverState *bs;
|
static int misalign; |
static int misalign; |
|
|
/* |
/* |
|
* Parse the pattern argument to various sub-commands. |
|
* |
|
* Because the pattern is used as an argument to memset it must evaluate |
|
* to an unsigned integer that fits into a single byte. |
|
*/ |
|
static int parse_pattern(const char *arg) |
|
{ |
|
char *endptr = NULL; |
|
long pattern; |
|
|
|
pattern = strtol(arg, &endptr, 0); |
|
if (pattern < 0 || pattern > UCHAR_MAX || *endptr != '\0') { |
|
printf("%s is not a valid pattern byte\n", arg); |
|
return -1; |
|
} |
|
|
|
return pattern; |
|
} |
|
|
|
/* |
* Memory allocation helpers. |
* Memory allocation helpers. |
* |
* |
* Make sure memory is aligned by default, or purposefully misaligned if |
* Make sure memory is aligned by default, or purposefully misaligned if |
Line 109 create_iovec(QEMUIOVector *qiov, char **
|
Line 129 create_iovec(QEMUIOVector *qiov, char **
|
{ |
{ |
size_t *sizes = calloc(nr_iov, sizeof(size_t)); |
size_t *sizes = calloc(nr_iov, sizeof(size_t)); |
size_t count = 0; |
size_t count = 0; |
void *buf, *p; |
void *buf = NULL; |
|
void *p; |
int i; |
int i; |
|
|
for (i = 0; i < nr_iov; i++) { |
for (i = 0; i < nr_iov; i++) { |
Line 119 create_iovec(QEMUIOVector *qiov, char **
|
Line 140 create_iovec(QEMUIOVector *qiov, char **
|
len = cvtnum(arg); |
len = cvtnum(arg); |
if (len < 0) { |
if (len < 0) { |
printf("non-numeric length argument -- %s\n", arg); |
printf("non-numeric length argument -- %s\n", arg); |
return NULL; |
goto fail; |
} |
} |
|
|
/* should be SIZE_T_MAX, but that doesn't exist */ |
/* should be SIZE_T_MAX, but that doesn't exist */ |
if (len > UINT_MAX) { |
if (len > UINT_MAX) { |
printf("too large length argument -- %s\n", arg); |
printf("too large length argument -- %s\n", arg); |
return NULL; |
goto fail; |
} |
} |
|
|
if (len & 0x1ff) { |
if (len & 0x1ff) { |
printf("length argument %lld is not sector aligned\n", |
printf("length argument %lld is not sector aligned\n", |
len); |
len); |
return NULL; |
goto fail; |
} |
} |
|
|
sizes[i] = len; |
sizes[i] = len; |
Line 147 create_iovec(QEMUIOVector *qiov, char **
|
Line 168 create_iovec(QEMUIOVector *qiov, char **
|
p += sizes[i]; |
p += sizes[i]; |
} |
} |
|
|
|
fail: |
free(sizes); |
free(sizes); |
return buf; |
return buf; |
} |
} |
Line 246 static int do_aio_writev(QEMUIOVector *q
|
Line 268 static int do_aio_writev(QEMUIOVector *q
|
} |
} |
|
|
|
|
static const cmdinfo_t read_cmd; |
|
|
|
static void |
static void |
read_help(void) |
read_help(void) |
{ |
{ |
Line 271 read_help(void)
|
Line 291 read_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int read_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t read_cmd = { |
|
.name = "read", |
|
.altname = "r", |
|
.cfunc = read_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len", |
|
.oneline = "reads a number of bytes at a specified offset", |
|
.help = read_help, |
|
}; |
|
|
static int |
static int |
read_f(int argc, char **argv) |
read_f(int argc, char **argv) |
{ |
{ |
Line 306 read_f(int argc, char **argv)
|
Line 339 read_f(int argc, char **argv)
|
break; |
break; |
case 'P': |
case 'P': |
Pflag = 1; |
Pflag = 1; |
pattern = atoi(optarg); |
pattern = parse_pattern(optarg); |
|
if (pattern < 0) |
|
return 0; |
break; |
break; |
case 'q': |
case 'q': |
qflag = 1; |
qflag = 1; |
Line 417 out:
|
Line 452 out:
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t read_cmd = { |
|
.name = "read", |
|
.altname = "r", |
|
.cfunc = read_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-abCpqv] [-P pattern [-s off] [-l len]] off len", |
|
.oneline = "reads a number of bytes at a specified offset", |
|
.help = read_help, |
|
}; |
|
|
|
static const cmdinfo_t readv_cmd; |
|
|
|
static void |
static void |
readv_help(void) |
readv_help(void) |
{ |
{ |
Line 450 readv_help(void)
|
Line 472 readv_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int readv_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t readv_cmd = { |
|
.name = "readv", |
|
.cfunc = readv_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cqv] [-P pattern ] off len [len..]", |
|
.oneline = "reads a number of bytes at a specified offset", |
|
.help = readv_help, |
|
}; |
|
|
static int |
static int |
readv_f(int argc, char **argv) |
readv_f(int argc, char **argv) |
{ |
{ |
Line 471 readv_f(int argc, char **argv)
|
Line 505 readv_f(int argc, char **argv)
|
break; |
break; |
case 'P': |
case 'P': |
Pflag = 1; |
Pflag = 1; |
pattern = atoi(optarg); |
pattern = parse_pattern(optarg); |
|
if (pattern < 0) |
|
return 0; |
break; |
break; |
case 'q': |
case 'q': |
qflag = 1; |
qflag = 1; |
Line 539 out:
|
Line 575 out:
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t readv_cmd = { |
|
.name = "readv", |
|
.cfunc = readv_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cqv] [-P pattern ] off len [len..]", |
|
.oneline = "reads a number of bytes at a specified offset", |
|
.help = readv_help, |
|
}; |
|
|
|
static const cmdinfo_t write_cmd; |
|
|
|
static void |
static void |
write_help(void) |
write_help(void) |
{ |
{ |
Line 571 write_help(void)
|
Line 595 write_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int write_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t write_cmd = { |
|
.name = "write", |
|
.altname = "w", |
|
.cfunc = write_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-abCpq] [-P pattern ] off len", |
|
.oneline = "writes a number of bytes at a specified offset", |
|
.help = write_help, |
|
}; |
|
|
static int |
static int |
write_f(int argc, char **argv) |
write_f(int argc, char **argv) |
{ |
{ |
Line 596 write_f(int argc, char **argv)
|
Line 633 write_f(int argc, char **argv)
|
pflag = 1; |
pflag = 1; |
break; |
break; |
case 'P': |
case 'P': |
pattern = atoi(optarg); |
pattern = parse_pattern(optarg); |
|
if (pattern < 0) |
|
return 0; |
break; |
break; |
case 'q': |
case 'q': |
qflag = 1; |
qflag = 1; |
Line 670 out:
|
Line 709 out:
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t write_cmd = { |
|
.name = "write", |
|
.altname = "w", |
|
.cfunc = write_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-abCpq] [-P pattern ] off len", |
|
.oneline = "writes a number of bytes at a specified offset", |
|
.help = write_help, |
|
}; |
|
|
|
static const cmdinfo_t writev_cmd; |
|
|
|
static void |
static void |
writev_help(void) |
writev_help(void) |
{ |
{ |
Line 701 writev_help(void)
|
Line 727 writev_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int writev_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t writev_cmd = { |
|
.name = "writev", |
|
.cfunc = writev_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cq] [-P pattern ] off len [len..]", |
|
.oneline = "writes a number of bytes at a specified offset", |
|
.help = writev_help, |
|
}; |
|
|
static int |
static int |
writev_f(int argc, char **argv) |
writev_f(int argc, char **argv) |
{ |
{ |
Line 723 writev_f(int argc, char **argv)
|
Line 761 writev_f(int argc, char **argv)
|
qflag = 1; |
qflag = 1; |
break; |
break; |
case 'P': |
case 'P': |
pattern = atoi(optarg); |
pattern = parse_pattern(optarg); |
|
if (pattern < 0) |
|
return 0; |
break; |
break; |
default: |
default: |
return command_usage(&writev_cmd); |
return command_usage(&writev_cmd); |
Line 769 out:
|
Line 809 out:
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t writev_cmd = { |
|
.name = "writev", |
|
.cfunc = writev_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cq] [-P pattern ] off len [len..]", |
|
.oneline = "writes a number of bytes at a specified offset", |
|
.help = writev_help, |
|
}; |
|
|
|
struct aio_ctx { |
struct aio_ctx { |
QEMUIOVector qiov; |
QEMUIOVector qiov; |
int64_t offset; |
int64_t offset; |
Line 818 out:
|
Line 848 out:
|
free(ctx); |
free(ctx); |
} |
} |
|
|
static const cmdinfo_t aio_read_cmd; |
|
|
|
static void |
static void |
aio_read_done(void *opaque, int ret) |
aio_read_done(void *opaque, int ret) |
{ |
{ |
Line 883 aio_read_help(void)
|
Line 911 aio_read_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int aio_read_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t aio_read_cmd = { |
|
.name = "aio_read", |
|
.cfunc = aio_read_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cqv] [-P pattern ] off len [len..]", |
|
.oneline = "asynchronously reads a number of bytes", |
|
.help = aio_read_help, |
|
}; |
|
|
static int |
static int |
aio_read_f(int argc, char **argv) |
aio_read_f(int argc, char **argv) |
{ |
{ |
Line 897 aio_read_f(int argc, char **argv)
|
Line 937 aio_read_f(int argc, char **argv)
|
break; |
break; |
case 'P': |
case 'P': |
ctx->Pflag = 1; |
ctx->Pflag = 1; |
ctx->pattern = atoi(optarg); |
ctx->pattern = parse_pattern(optarg); |
|
if (ctx->pattern < 0) |
|
return 0; |
break; |
break; |
case 'q': |
case 'q': |
ctx->qflag = 1; |
ctx->qflag = 1; |
Line 946 aio_read_f(int argc, char **argv)
|
Line 988 aio_read_f(int argc, char **argv)
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t aio_read_cmd = { |
|
.name = "aio_read", |
|
.cfunc = aio_read_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cqv] [-P pattern ] off len [len..]", |
|
.oneline = "asynchronously reads a number of bytes", |
|
.help = aio_read_help, |
|
}; |
|
|
|
static const cmdinfo_t aio_write_cmd; |
|
|
|
static void |
static void |
aio_write_help(void) |
aio_write_help(void) |
{ |
{ |
Line 979 aio_write_help(void)
|
Line 1009 aio_write_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
|
static int aio_write_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t aio_write_cmd = { |
|
.name = "aio_write", |
|
.cfunc = aio_write_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cq] [-P pattern ] off len [len..]", |
|
.oneline = "asynchronously writes a number of bytes", |
|
.help = aio_write_help, |
|
}; |
|
|
static int |
static int |
aio_write_f(int argc, char **argv) |
aio_write_f(int argc, char **argv) |
Line 997 aio_write_f(int argc, char **argv)
|
Line 1038 aio_write_f(int argc, char **argv)
|
ctx->qflag = 1; |
ctx->qflag = 1; |
break; |
break; |
case 'P': |
case 'P': |
pattern = atoi(optarg); |
pattern = parse_pattern(optarg); |
|
if (pattern < 0) |
|
return 0; |
break; |
break; |
default: |
default: |
free(ctx); |
free(ctx); |
Line 1040 aio_write_f(int argc, char **argv)
|
Line 1083 aio_write_f(int argc, char **argv)
|
return 0; |
return 0; |
} |
} |
|
|
static const cmdinfo_t aio_write_cmd = { |
|
.name = "aio_write", |
|
.cfunc = aio_write_f, |
|
.argmin = 2, |
|
.argmax = -1, |
|
.args = "[-Cq] [-P pattern ] off len [len..]", |
|
.oneline = "asynchronously writes a number of bytes", |
|
.help = aio_write_help, |
|
}; |
|
|
|
static int |
static int |
aio_flush_f(int argc, char **argv) |
aio_flush_f(int argc, char **argv) |
{ |
{ |
Line 1172 static int
|
Line 1205 static int
|
alloc_f(int argc, char **argv) |
alloc_f(int argc, char **argv) |
{ |
{ |
int64_t offset; |
int64_t offset; |
int nb_sectors; |
int nb_sectors, remaining; |
char s1[64]; |
char s1[64]; |
int num; |
int num, sum_alloc; |
int ret; |
int ret; |
const char *retstr; |
|
|
|
offset = cvtnum(argv[1]); |
offset = cvtnum(argv[1]); |
if (offset & 0x1ff) { |
if (offset & 0x1ff) { |
Line 1190 alloc_f(int argc, char **argv)
|
Line 1222 alloc_f(int argc, char **argv)
|
else |
else |
nb_sectors = 1; |
nb_sectors = 1; |
|
|
ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); |
remaining = nb_sectors; |
|
sum_alloc = 0; |
|
while (remaining) { |
|
ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num); |
|
remaining -= num; |
|
if (ret) { |
|
sum_alloc += num; |
|
} |
|
} |
|
|
cvtstr(offset, s1, sizeof(s1)); |
cvtstr(offset, s1, sizeof(s1)); |
|
|
retstr = ret ? "allocated" : "not allocated"; |
|
if (nb_sectors == 1) |
if (nb_sectors == 1) |
printf("sector %s at offset %s\n", retstr, s1); |
printf("sector allocated at offset %s\n", s1); |
else |
else |
printf("%d/%d sectors %s at offset %s\n", |
printf("%d/%d sectors allocated at offset %s\n", |
num, nb_sectors, retstr, s1); |
sum_alloc, nb_sectors, s1); |
return 0; |
return 0; |
} |
} |
|
|
Line 1274 open_help(void)
|
Line 1313 open_help(void)
|
"\n"); |
"\n"); |
} |
} |
|
|
static const cmdinfo_t open_cmd; |
static int open_f(int argc, char **argv); |
|
|
|
static const cmdinfo_t open_cmd = { |
|
.name = "open", |
|
.altname = "o", |
|
.cfunc = open_f, |
|
.argmin = 1, |
|
.argmax = -1, |
|
.flags = CMD_NOFILE_OK, |
|
.args = "[-Crsn] [path]", |
|
.oneline = "open the file specified by path", |
|
.help = open_help, |
|
}; |
|
|
static int |
static int |
open_f(int argc, char **argv) |
open_f(int argc, char **argv) |
Line 1317 open_f(int argc, char **argv)
|
Line 1368 open_f(int argc, char **argv)
|
return openfile(argv[optind], flags, growable); |
return openfile(argv[optind], flags, growable); |
} |
} |
|
|
static const cmdinfo_t open_cmd = { |
|
.name = "open", |
|
.altname = "o", |
|
.cfunc = open_f, |
|
.argmin = 1, |
|
.argmax = -1, |
|
.flags = CMD_NOFILE_OK, |
|
.args = "[-Crsn] [path]", |
|
.oneline = "open the file specified by path", |
|
.help = open_help, |
|
}; |
|
|
|
static int |
static int |
init_args_command( |
init_args_command( |
int index) |
int index) |
Line 1365 static void usage(const char *name)
|
Line 1404 static void usage(const char *name)
|
" -n, --nocache disable host cache\n" |
" -n, --nocache disable host cache\n" |
" -g, --growable allow file to grow (only applies to protocols)\n" |
" -g, --growable allow file to grow (only applies to protocols)\n" |
" -m, --misalign misalign allocations for O_DIRECT\n" |
" -m, --misalign misalign allocations for O_DIRECT\n" |
|
" -k, --native-aio use kernel AIO implementation (on Linux only)\n" |
" -h, --help display this help and exit\n" |
" -h, --help display this help and exit\n" |
" -V, --version output version information and exit\n" |
" -V, --version output version information and exit\n" |
"\n", |
"\n", |
Line 1376 int main(int argc, char **argv)
|
Line 1416 int main(int argc, char **argv)
|
{ |
{ |
int readonly = 0; |
int readonly = 0; |
int growable = 0; |
int growable = 0; |
const char *sopt = "hVc:Crsnmg"; |
const char *sopt = "hVc:Crsnmgk"; |
struct option lopt[] = { |
struct option lopt[] = { |
{ "help", 0, NULL, 'h' }, |
{ "help", 0, NULL, 'h' }, |
{ "version", 0, NULL, 'V' }, |
{ "version", 0, NULL, 'V' }, |
Line 1388 int main(int argc, char **argv)
|
Line 1428 int main(int argc, char **argv)
|
{ "nocache", 0, NULL, 'n' }, |
{ "nocache", 0, NULL, 'n' }, |
{ "misalign", 0, NULL, 'm' }, |
{ "misalign", 0, NULL, 'm' }, |
{ "growable", 0, NULL, 'g' }, |
{ "growable", 0, NULL, 'g' }, |
|
{ "native-aio", 0, NULL, 'k' }, |
{ NULL, 0, NULL, 0 } |
{ NULL, 0, NULL, 0 } |
}; |
}; |
int c; |
int c; |
Line 1419 int main(int argc, char **argv)
|
Line 1460 int main(int argc, char **argv)
|
case 'g': |
case 'g': |
growable = 1; |
growable = 1; |
break; |
break; |
|
case 'k': |
|
flags |= BDRV_O_NATIVE_AIO; |
|
break; |
case 'V': |
case 'V': |
printf("%s version %s\n", progname, VERSION); |
printf("%s version %s\n", progname, VERSION); |
exit(0); |
exit(0); |