qemu-io: Fix formatting

Replaced tabs with spaces, 8 space indentations with 4 space
indentation, and other fixes to better adhere to CODING_STYLE

Signed-off-by: Devin Nakamura <devin122@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Devin Nakamura 2011-07-11 11:22:16 -04:00 committed by Kevin Wolf
parent a8e0fdd715
commit 43642b3803

260
qemu-io.c
View File

@ -59,24 +59,26 @@ static void *qemu_io_alloc(size_t len, int pattern)
{
void *buf;
if (misalign)
if (misalign) {
len += MISALIGN_OFFSET;
}
buf = qemu_blockalign(bs, len);
memset(buf, pattern, len);
if (misalign)
if (misalign) {
buf += MISALIGN_OFFSET;
}
return buf;
}
static void qemu_io_free(void *p)
{
if (misalign)
if (misalign) {
p -= MISALIGN_OFFSET;
}
qemu_vfree(p);
}
static void
dump_buffer(const void *buffer, int64_t offset, int len)
static void dump_buffer(const void *buffer, int64_t offset, int len)
{
int i, j;
const uint8_t *p;
@ -85,21 +87,22 @@ dump_buffer(const void *buffer, int64_t offset, int len)
const uint8_t *s = p;
printf("%08" PRIx64 ": ", offset + i);
for (j = 0; j < 16 && i + j < len; j++, p++)
for (j = 0; j < 16 && i + j < len; j++, p++) {
printf("%02x ", *p);
}
printf(" ");
for (j = 0; j < 16 && i + j < len; j++, s++) {
if (isalnum(*s))
if (isalnum(*s)) {
printf("%c", *s);
else
} else {
printf(".");
}
}
printf("\n");
}
}
static void
print_report(const char *op, struct timeval *t, int64_t offset,
static void print_report(const char *op, struct timeval *t, int64_t offset,
int count, int total, int cnt, int Cflag)
{
char s1[64], s2[64], ts[64];
@ -178,8 +181,9 @@ static int do_read(char *buf, int64_t offset, int count, int *total)
int ret;
ret = bdrv_read(bs, offset >> 9, (uint8_t *)buf, count >> 9);
if (ret < 0)
if (ret < 0) {
return ret;
}
*total = count;
return 1;
}
@ -189,8 +193,9 @@ static int do_write(char *buf, int64_t offset, int count, int *total)
int ret;
ret = bdrv_write(bs, offset >> 9, (uint8_t *)buf, count >> 9);
if (ret < 0)
if (ret < 0) {
return ret;
}
*total = count;
return 1;
}
@ -198,32 +203,36 @@ static int do_write(char *buf, int64_t offset, int count, int *total)
static int do_pread(char *buf, int64_t offset, int count, int *total)
{
*total = bdrv_pread(bs, offset, (uint8_t *)buf, count);
if (*total < 0)
if (*total < 0) {
return *total;
}
return 1;
}
static int do_pwrite(char *buf, int64_t offset, int count, int *total)
{
*total = bdrv_pwrite(bs, offset, (uint8_t *)buf, count);
if (*total < 0)
if (*total < 0) {
return *total;
}
return 1;
}
static int do_load_vmstate(char *buf, int64_t offset, int count, int *total)
{
*total = bdrv_load_vmstate(bs, (uint8_t *)buf, offset, count);
if (*total < 0)
if (*total < 0) {
return *total;
}
return 1;
}
static int do_save_vmstate(char *buf, int64_t offset, int count, int *total)
{
*total = bdrv_save_vmstate(bs, (uint8_t *)buf, offset, count);
if (*total < 0)
if (*total < 0) {
return *total;
}
return 1;
}
@ -240,11 +249,12 @@ static int do_aio_readv(QEMUIOVector *qiov, int64_t offset, int *total)
acb = bdrv_aio_readv(bs, offset >> 9, qiov, qiov->size >> 9,
aio_rw_done, &async_ret);
if (!acb)
if (!acb) {
return -EIO;
while (async_ret == NOT_DONE)
}
while (async_ret == NOT_DONE) {
qemu_aio_wait();
}
*total = qiov->size;
return async_ret < 0 ? async_ret : 1;
@ -257,11 +267,13 @@ static int do_aio_writev(QEMUIOVector *qiov, int64_t offset, int *total)
acb = bdrv_aio_writev(bs, offset >> 9, qiov, qiov->size >> 9,
aio_rw_done, &async_ret);
if (!acb)
if (!acb) {
return -EIO;
}
while (async_ret == NOT_DONE)
while (async_ret == NOT_DONE) {
qemu_aio_wait();
}
*total = qiov->size;
return async_ret < 0 ? async_ret : 1;
@ -309,8 +321,7 @@ static int do_aio_multiwrite(BlockRequest* reqs, int num_reqs, int *total)
return async_ret.error < 0 ? async_ret.error : 1;
}
static void
read_help(void)
static void read_help(void)
{
printf(
"\n"
@ -345,8 +356,7 @@ static const cmdinfo_t read_cmd = {
.help = read_help,
};
static int
read_f(int argc, char **argv)
static int read_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
@ -381,8 +391,9 @@ read_f(int argc, char **argv)
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
@ -403,8 +414,9 @@ read_f(int argc, char **argv)
}
}
if (optind != argc - 2)
if (optind != argc - 2) {
return command_usage(&read_cmd);
}
if (bflag && pflag) {
printf("-b and -p cannot be specified at the same time\n");
@ -442,23 +454,23 @@ read_f(int argc, char **argv)
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
if (count & 0x1ff) {
printf("count %d is not sector aligned\n",
count);
return 0;
}
}
buf = qemu_io_alloc(count, 0xab);
gettimeofday(&t1, NULL);
if (pflag)
if (pflag) {
cnt = do_pread(buf, offset, count, &total);
else if (bflag)
} else if (bflag) {
cnt = do_load_vmstate(buf, offset, count, &total);
else
} else {
cnt = do_read(buf, offset, count, &total);
}
gettimeofday(&t2, NULL);
if (cnt < 0) {
@ -467,7 +479,7 @@ read_f(int argc, char **argv)
}
if (Pflag) {
void* cmp_buf = malloc(pattern_count);
void *cmp_buf = malloc(pattern_count);
memset(cmp_buf, pattern, pattern_count);
if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
printf("Pattern verification failed at offset %"
@ -477,11 +489,13 @@ read_f(int argc, char **argv)
free(cmp_buf);
}
if (qflag)
if (qflag) {
goto out;
}
if (vflag)
if (vflag) {
dump_buffer(buf, offset, count);
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
@ -493,8 +507,7 @@ out:
return 0;
}
static void
readv_help(void)
static void readv_help(void)
{
printf(
"\n"
@ -525,8 +538,7 @@ static const cmdinfo_t readv_cmd = {
.help = readv_help,
};
static int
readv_f(int argc, char **argv)
static int readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
@ -548,8 +560,9 @@ readv_f(int argc, char **argv)
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
@ -562,8 +575,9 @@ readv_f(int argc, char **argv)
}
}
if (optind > argc - 2)
if (optind > argc - 2) {
return command_usage(&readv_cmd);
}
offset = cvtnum(argv[optind]);
@ -592,21 +606,22 @@ readv_f(int argc, char **argv)
}
if (Pflag) {
void* cmp_buf = malloc(qiov.size);
void *cmp_buf = malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %"
PRId64 ", %zd bytes\n",
offset, qiov.size);
PRId64 ", %zd bytes\n", offset, qiov.size);
}
free(cmp_buf);
}
if (qflag)
if (qflag) {
goto out;
}
if (vflag)
if (vflag) {
dump_buffer(buf, offset, qiov.size);
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
@ -617,8 +632,7 @@ out:
return 0;
}
static void
write_help(void)
static void write_help(void)
{
printf(
"\n"
@ -650,8 +664,7 @@ static const cmdinfo_t write_cmd = {
.help = write_help,
};
static int
write_f(int argc, char **argv)
static int write_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, bflag = 0;
@ -676,8 +689,9 @@ write_f(int argc, char **argv)
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
@ -687,8 +701,9 @@ write_f(int argc, char **argv)
}
}
if (optind != argc - 2)
if (optind != argc - 2) {
return command_usage(&write_cmd);
}
if (bflag && pflag) {
printf("-b and -p cannot be specified at the same time\n");
@ -725,12 +740,13 @@ write_f(int argc, char **argv)
buf = qemu_io_alloc(count, pattern);
gettimeofday(&t1, NULL);
if (pflag)
if (pflag) {
cnt = do_pwrite(buf, offset, count, &total);
else if (bflag)
} else if (bflag) {
cnt = do_save_vmstate(buf, offset, count, &total);
else
} else {
cnt = do_write(buf, offset, count, &total);
}
gettimeofday(&t2, NULL);
if (cnt < 0) {
@ -738,8 +754,9 @@ write_f(int argc, char **argv)
goto out;
}
if (qflag)
if (qflag) {
goto out;
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
@ -781,8 +798,7 @@ static const cmdinfo_t writev_cmd = {
.help = writev_help,
};
static int
writev_f(int argc, char **argv)
static int writev_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
@ -805,16 +821,18 @@ writev_f(int argc, char **argv)
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2)
if (optind > argc - 2) {
return command_usage(&writev_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
@ -841,8 +859,9 @@ writev_f(int argc, char **argv)
goto out;
}
if (qflag)
if (qflag) {
goto out;
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
@ -852,8 +871,7 @@ out:
return 0;
}
static void
multiwrite_help(void)
static void multiwrite_help(void)
{
printf(
"\n"
@ -885,8 +903,7 @@ static const cmdinfo_t multiwrite_cmd = {
.help = multiwrite_help,
};
static int
multiwrite_f(int argc, char **argv)
static int multiwrite_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
@ -912,16 +929,18 @@ multiwrite_f(int argc, char **argv)
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2)
if (optind > argc - 2) {
return command_usage(&writev_cmd);
}
nr_reqs = 1;
for (i = optind; i < argc; i++) {
@ -985,8 +1004,9 @@ multiwrite_f(int argc, char **argv)
goto out;
}
if (qflag)
if (qflag) {
goto out;
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
@ -1014,8 +1034,7 @@ struct aio_ctx {
struct timeval t1;
};
static void
aio_write_done(void *opaque, int ret)
static void aio_write_done(void *opaque, int ret)
{
struct aio_ctx *ctx = opaque;
struct timeval t2;
@ -1041,8 +1060,7 @@ out:
free(ctx);
}
static void
aio_read_done(void *opaque, int ret)
static void aio_read_done(void *opaque, int ret)
{
struct aio_ctx *ctx = opaque;
struct timeval t2;
@ -1060,8 +1078,7 @@ aio_read_done(void *opaque, int ret)
memset(cmp_buf, ctx->pattern, ctx->qiov.size);
if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) {
printf("Pattern verification failed at offset %"
PRId64 ", %zd bytes\n",
ctx->offset, ctx->qiov.size);
PRId64 ", %zd bytes\n", ctx->offset, ctx->qiov.size);
}
free(cmp_buf);
}
@ -1083,8 +1100,7 @@ out:
free(ctx);
}
static void
aio_read_help(void)
static void aio_read_help(void)
{
printf(
"\n"
@ -1116,8 +1132,7 @@ static const cmdinfo_t aio_read_cmd = {
.help = aio_read_help,
};
static int
aio_read_f(int argc, char **argv)
static int aio_read_f(int argc, char **argv)
{
int nr_iov, c;
struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
@ -1183,12 +1198,11 @@ aio_read_f(int argc, char **argv)
return 0;
}
static void
aio_write_help(void)
static void aio_write_help(void)
{
printf(
"\n"
" asynchronously writes a range of bytes from the given offset source \n"
" asynchronously writes a range of bytes from the given offset source\n"
" from multiple buffers\n"
"\n"
" Example:\n"
@ -1216,8 +1230,7 @@ static const cmdinfo_t aio_write_cmd = {
.help = aio_write_help,
};
static int
aio_write_f(int argc, char **argv)
static int aio_write_f(int argc, char **argv)
{
int nr_iov, c;
int pattern = 0xcd;
@ -1234,8 +1247,9 @@ aio_write_f(int argc, char **argv)
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
if (pattern < 0) {
return 0;
}
break;
default:
free(ctx);
@ -1278,8 +1292,7 @@ aio_write_f(int argc, char **argv)
return 0;
}
static int
aio_flush_f(int argc, char **argv)
static int aio_flush_f(int argc, char **argv)
{
qemu_aio_flush();
return 0;
@ -1291,8 +1304,7 @@ static const cmdinfo_t aio_flush_cmd = {
.oneline = "completes all outstanding aio requests"
};
static int
flush_f(int argc, char **argv)
static int flush_f(int argc, char **argv)
{
bdrv_flush(bs);
return 0;
@ -1305,8 +1317,7 @@ static const cmdinfo_t flush_cmd = {
.oneline = "flush all in-core file state to disk",
};
static int
truncate_f(int argc, char **argv)
static int truncate_f(int argc, char **argv)
{
int64_t offset;
int ret;
@ -1336,8 +1347,7 @@ static const cmdinfo_t truncate_cmd = {
.oneline = "truncates the current file at the given offset",
};
static int
length_f(int argc, char **argv)
static int length_f(int argc, char **argv)
{
int64_t size;
char s1[64];
@ -1362,21 +1372,23 @@ static const cmdinfo_t length_cmd = {
};
static int
info_f(int argc, char **argv)
static int info_f(int argc, char **argv)
{
BlockDriverInfo bdi;
char s1[64], s2[64];
int ret;
if (bs->drv && bs->drv->format_name)
if (bs->drv && bs->drv->format_name) {
printf("format name: %s\n", bs->drv->format_name);
if (bs->drv && bs->drv->protocol_name)
}
if (bs->drv && bs->drv->protocol_name) {
printf("format name: %s\n", bs->drv->protocol_name);
}
ret = bdrv_get_info(bs, &bdi);
if (ret)
if (ret) {
return 0;
}
cvtstr(bdi.cluster_size, s1, sizeof(s1));
cvtstr(bdi.vm_state_offset, s2, sizeof(s2));
@ -1396,8 +1408,7 @@ static const cmdinfo_t info_cmd = {
.oneline = "prints information about the current file",
};
static void
discard_help(void)
static void discard_help(void)
{
printf(
"\n"
@ -1425,8 +1436,7 @@ static const cmdinfo_t discard_cmd = {
.help = discard_help,
};
static int
discard_f(int argc, char **argv)
static int discard_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
@ -1465,7 +1475,8 @@ discard_f(int argc, char **argv)
}
gettimeofday(&t1, NULL);
ret = bdrv_discard(bs, offset >> BDRV_SECTOR_BITS, count >> BDRV_SECTOR_BITS);
ret = bdrv_discard(bs, offset >> BDRV_SECTOR_BITS,
count >> BDRV_SECTOR_BITS);
gettimeofday(&t2, NULL);
if (ret < 0) {
@ -1483,8 +1494,7 @@ out:
return 0;
}
static int
alloc_f(int argc, char **argv)
static int alloc_f(int argc, char **argv)
{
int64_t offset;
int nb_sectors, remaining;
@ -1499,10 +1509,11 @@ alloc_f(int argc, char **argv)
return 0;
}
if (argc == 3)
if (argc == 3) {
nb_sectors = cvtnum(argv[2]);
else
} else {
nb_sectors = 1;
}
remaining = nb_sectors;
sum_alloc = 0;
@ -1531,8 +1542,7 @@ static const cmdinfo_t alloc_cmd = {
.oneline = "checks if a sector is present in the file",
};
static int
map_f(int argc, char **argv)
static int map_f(int argc, char **argv)
{
int64_t offset;
int64_t nb_sectors;
@ -1554,7 +1564,7 @@ map_f(int argc, char **argv)
offset += num;
nb_sectors -= num;
} while(offset < bs->total_sectors);
} while (offset < bs->total_sectors);
return 0;
}
@ -1569,8 +1579,7 @@ static const cmdinfo_t map_cmd = {
};
static int
close_f(int argc, char **argv)
static int close_f(int argc, char **argv)
{
bdrv_close(bs);
bs = NULL;
@ -1609,8 +1618,7 @@ static int openfile(char *name, int flags, int growable)
return 0;
}
static void
open_help(void)
static void open_help(void)
{
printf(
"\n"
@ -1641,8 +1649,7 @@ static const cmdinfo_t open_cmd = {
.help = open_help,
};
static int
open_f(int argc, char **argv)
static int open_f(int argc, char **argv)
{
int flags = 0;
int readonly = 0;
@ -1672,28 +1679,27 @@ open_f(int argc, char **argv)
flags |= BDRV_O_RDWR;
}
if (optind != argc - 1)
if (optind != argc - 1) {
return command_usage(&open_cmd);
}
return openfile(argv[optind], flags, growable);
}
static int
init_args_command(
int index)
static int init_args_command(int index)
{
/* only one device allowed so far */
if (index >= 1)
if (index >= 1) {
return 0;
}
return ++index;
}
static int
init_check_command(
const cmdinfo_t *ct)
static int init_check_command(const cmdinfo_t *ct)
{
if (ct->flags & CMD_FLAG_GLOBAL)
if (ct->flags & CMD_FLAG_GLOBAL) {
return 1;
}
if (!(ct->flags & CMD_NOFILE_OK) && !bs) {
fprintf(stderr, "no file open, try 'help open'\n");
return 0;
@ -1816,8 +1822,9 @@ int main(int argc, char **argv)
flags |= BDRV_O_RDWR;
}
if ((argc - optind) == 1)
if ((argc - optind) == 1) {
openfile(argv[optind], flags, growable);
}
command_loop();
/*
@ -1825,7 +1832,8 @@ int main(int argc, char **argv)
*/
qemu_aio_flush();
if (bs)
if (bs) {
bdrv_close(bs);
}
return 0;
}