55
printf("%s %s -- %s\n", ci->name, ci->args, ci->oneline);
56
}
57
58
-static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct)
58
+static int init_check_command(BlockBackend *blk, const cmdinfo_t *ct,
59
+ Error **errp)
60
{
61
if (ct->flags & CMD_FLAG_GLOBAL) {
62
return 1;
63
}
64
if (!(ct->flags & CMD_NOFILE_OK) && !blk) {
64
- fprintf(stderr, "no file open, try 'help open'\n");
65
+ error_setg(errp, "no file open, try 'help open'");
66
return 0;
67
}
68
return 1;
69
}
70
71
static int command(BlockBackend *blk, const cmdinfo_t *ct, int argc,
71
- char **argv)
72
+ char **argv, Error **errp)
73
{
74
char *cmd = argv[0];
75
75
- if (!init_check_command(blk, ct)) {
76
+ if (!init_check_command(blk, ct, errp)) {
77
return -EINVAL;
78
}
79
80
if (argc - 1 < ct->argmin || (ct->argmax != -1 && argc - 1 > ct->argmax)) {
81
if (ct->argmax == -1) {
81
- fprintf(stderr,
82
- "bad argument count %d to %s, expected at least %d arguments\n",
83
- argc-1, cmd, ct->argmin);
82
+ error_setg(errp,
83
+ "bad argument count %d to %s,"
84
+ " expected at least %d arguments",
85
+ argc - 1, cmd, ct->argmin);
86
} else if (ct->argmin == ct->argmax) {
85
- fprintf(stderr,
86
- "bad argument count %d to %s, expected %d arguments\n",
87
- argc-1, cmd, ct->argmin);
87
+ error_setg(errp,
88
+ "bad argument count %d to %s, expected %d arguments",
89
+ argc - 1, cmd, ct->argmin);
90
} else {
89
- fprintf(stderr,
90
- "bad argument count %d to %s, expected between %d and %d arguments\n",
91
- argc-1, cmd, ct->argmin, ct->argmax);
91
+ error_setg(errp,
92
+ "bad argument count %d to %s,"
93
+ " expected between %d and %d arguments",
94
+ argc - 1, cmd, ct->argmin, ct->argmax);
95
}
96
return -EINVAL;
97
}
115
116
if (ct->perm & ~orig_perm) {
117
uint64_t new_perm;
115
- Error *local_err = NULL;
118
int ret;
119
120
new_perm = orig_perm | ct->perm;
121
120
- ret = blk_set_perm(blk, new_perm, orig_shared_perm, &local_err);
122
+ ret = blk_set_perm(blk, new_perm, orig_shared_perm, errp);
123
if (ret < 0) {
122
- error_report_err(local_err);
124
return ret;
125
}
126
}
127
}
128
129
qemu_reset_optind();
129
- return ct->cfunc(blk, argc, argv);
130
+ return ct->cfunc(blk, argc, argv, errp);
131
}
132
133
static const cmdinfo_t *find_command(const char *cmd)
193
return value;
194
}
195
195
-static void print_cvtnum_err(int64_t rc, const char *arg)
196
+static void set_cvtnum_err(int64_t rc, const char *arg, Error **errp)
197
{
198
switch (rc) {
199
case -EINVAL:
199
- printf("Parsing error: non-numeric argument,"
200
- " or extraneous/unrecognized suffix -- %s\n", arg);
200
+ error_setg(errp, "Parsing error: non-numeric argument,"
201
+ " or extraneous/unrecognized suffix -- %s", arg);
202
break;
203
case -ERANGE:
203
- printf("Parsing error: argument too large -- %s\n", arg);
204
+ error_setg(errp, "Parsing error: argument too large -- %s", arg);
205
break;
206
default:
206
- printf("Parsing error: %s\n", arg);
207
+ error_setg(errp, "Parsing error: %s", arg);
208
}
209
}
210
317
* Because the pattern is used as an argument to memset it must evaluate
318
* to an unsigned integer that fits into a single byte.
319
*/
319
-static int parse_pattern(const char *arg)
320
+static int parse_pattern(const char *arg, Error **errp)
321
{
322
char *endptr = NULL;
323
long pattern;
324
325
pattern = strtol(arg, &endptr, 0);
326
if (pattern < 0 || pattern > UCHAR_MAX || *endptr != '\0') {
326
- printf("%s is not a valid pattern byte\n", arg);
327
+ error_setg(errp, "%s is not a valid pattern byte", arg);
328
return -1;
329
}
330
387
* NULL on error
388
*/
389
static void *qemu_io_alloc_from_file(BlockBackend *blk, size_t len,
389
- const char *file_name, bool register_buf)
390
+ const char *file_name, bool register_buf,
391
+ Error **errp)
392
{
393
size_t alloc_len = len + (qemuio_misalign ? MISALIGN_OFFSET : 0);
394
char *alloc_buf, *buf, *end;
396
int pattern_len;
397
398
if (!f) {
397
- perror(file_name);
399
+ error_setg_errno(errp, errno, "%s", file_name);
400
return NULL;
401
}
402
409
pattern_len = fread(buf, 1, len, f);
410
411
if (ferror(f)) {
410
- perror(file_name);
412
+ error_setg_errno(errp, errno, "%s", file_name);
413
goto error;
414
}
415
416
if (pattern_len == 0) {
415
- fprintf(stderr, "%s: file is empty\n", file_name);
417
+ error_setg(errp, "%s: file is empty", file_name);
418
goto error;
419
}
420
496
*/
497
static void *
498
create_iovec(BlockBackend *blk, QEMUIOVector *qiov, char **argv, int nr_iov,
497
- int pattern, bool register_buf)
499
+ int pattern, bool register_buf, Error **errp)
500
{
501
size_t *sizes = g_new0(size_t, nr_iov);
502
size_t count = 0;
510
511
len = cvtnum(arg);
512
if (len < 0) {
511
- print_cvtnum_err(len, arg);
513
+ set_cvtnum_err(len, arg, errp);
514
goto fail;
515
}
516
517
if (len > BDRV_REQUEST_MAX_BYTES) {
516
- printf("Argument '%s' exceeds maximum size %" PRIu64 "\n", arg,
517
- (uint64_t)BDRV_REQUEST_MAX_BYTES);
518
+ error_setg(errp, "Argument '%s' exceeds maximum size %" PRIu64,
519
+ arg, (uint64_t)BDRV_REQUEST_MAX_BYTES);
520
goto fail;
521
}
522
523
if (count > BDRV_REQUEST_MAX_BYTES - len) {
522
- printf("The total number of bytes exceed the maximum size %" PRIu64
523
- "\n", (uint64_t)BDRV_REQUEST_MAX_BYTES);
524
+ error_setg(errp,
525
+ "The total number of bytes exceed the maximum size %"
526
+ PRIu64, (uint64_t)BDRV_REQUEST_MAX_BYTES);
527
goto fail;
528
}
529
695
"\n");
696
}
697
695
-static int read_f(BlockBackend *blk, int argc, char **argv);
698
+static int read_f(BlockBackend *blk, int argc, char **argv, Error **errp);
699
700
static const cmdinfo_t read_cmd = {
701
.name = "read",
708
.help = read_help,
709
};
710
708
-static int read_f(BlockBackend *blk, int argc, char **argv)
711
+static int read_f(BlockBackend *blk, int argc, char **argv, Error **errp)
712
{
713
struct timespec t1, t2;
714
bool Cflag = false, qflag = false, vflag = false;
735
lflag = true;
736
pattern_count = cvtnum(optarg);
737
if (pattern_count < 0) {
735
- print_cvtnum_err(pattern_count, optarg);
738
+ set_cvtnum_err(pattern_count, optarg, errp);
739
return pattern_count;
740
}
741
break;
744
break;
745
case 'P':
746
Pflag = true;
744
- pattern = parse_pattern(optarg);
747
+ pattern = parse_pattern(optarg, errp);
748
if (pattern < 0) {
749
return -EINVAL;
750
}
759
sflag = true;
760
pattern_offset = cvtnum(optarg);
761
if (pattern_offset < 0) {
759
- print_cvtnum_err(pattern_offset, optarg);
762
+ set_cvtnum_err(pattern_offset, optarg, errp);
763
return pattern_offset;
764
}
765
break;
779
780
offset = cvtnum(argv[optind]);
781
if (offset < 0) {
779
- print_cvtnum_err(offset, argv[optind]);
782
+ set_cvtnum_err(offset, argv[optind], errp);
783
return offset;
784
}
785
786
optind++;
787
count = cvtnum(argv[optind]);
788
if (count < 0) {
786
- print_cvtnum_err(count, argv[optind]);
789
+ set_cvtnum_err(count, argv[optind], errp);
790
return count;
791
} else if (count > BDRV_REQUEST_MAX_BYTES) {
789
- printf("length cannot exceed %" PRIu64 ", given %s\n",
790
- (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
792
+ error_setg(errp, "length cannot exceed %" PRIu64 ", given %s",
793
+ (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
794
return -EINVAL;
795
}
796
804
}
805
806
if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {
804
- printf("pattern verification range exceeds end of read data\n");
807
+ error_setg(errp, "pattern verification range exceeds end of read data");
808
return -EINVAL;
809
}
810
811
if (bflag) {
812
if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
810
- printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
811
- offset);
813
+ error_setg(errp,
814
+ "%" PRId64 " is not a sector-aligned value for 'offset'",
815
+ offset);
816
return -EINVAL;
817
}
818
if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
815
- printf("%"PRId64" is not a sector-aligned value for 'count'\n",
816
- count);
819
+ error_setg(errp,
820
+ "%" PRId64 " is not a sector-aligned value for 'count'",
821
+ count);
822
return -EINVAL;
823
}
824
if (flags & BDRV_REQ_REGISTERED_BUF) {
820
- printf("I/O buffer registration is not supported when reading "
821
- "from vmstate\n");
825
+ error_setg(errp, "I/O buffer registration is not supported when"
826
+ " reading from vmstate");
827
return -EINVAL;
828
}
829
}
839
clock_gettime(CLOCK_MONOTONIC, &t2);
840
841
if (ret < 0) {
837
- printf("read failed: %s\n", strerror(-ret));
842
+ error_setg(errp, "read failed: %s", strerror(-ret));
843
goto out;
844
}
845
cnt = ret;
850
void *cmp_buf = g_malloc(pattern_count);
851
memset(cmp_buf, pattern, pattern_count);
852
if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
848
- printf("Pattern verification failed at offset %"
849
- PRId64 ", %"PRId64" bytes\n",
850
- offset + pattern_offset, pattern_count);
853
+ error_setg(errp, "Pattern verification failed at offset %"
854
+ PRId64 ", %" PRId64 " bytes",
855
+ offset + pattern_offset, pattern_count);
856
ret = -EINVAL;
857
}
858
g_free(cmp_buf);
895
"\n");
896
}
897
893
-static int readv_f(BlockBackend *blk, int argc, char **argv);
898
+static int readv_f(BlockBackend *blk, int argc, char **argv, Error **errp);
899
900
static const cmdinfo_t readv_cmd = {
901
.name = "readv",
907
.help = readv_help,
908
};
909
905
-static int readv_f(BlockBackend *blk, int argc, char **argv)
910
+static int readv_f(BlockBackend *blk, int argc, char **argv, Error **errp)
911
{
912
struct timespec t1, t2;
913
bool Cflag = false, qflag = false, vflag = false;
929
break;
930
case 'P':
931
Pflag = true;
927
- pattern = parse_pattern(optarg);
932
+ pattern = parse_pattern(optarg, errp);
933
if (pattern < 0) {
934
return -EINVAL;
935
}
957
958
offset = cvtnum(argv[optind]);
959
if (offset < 0) {
955
- print_cvtnum_err(offset, argv[optind]);
960
+ set_cvtnum_err(offset, argv[optind], errp);
961
return offset;
962
}
963
optind++;
964
965
nr_iov = argc - optind;
966
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, 0xab,
962
- flags & BDRV_REQ_REGISTERED_BUF);
967
+ flags & BDRV_REQ_REGISTERED_BUF, errp);
968
if (buf == NULL) {
969
return -EINVAL;
970
}
974
clock_gettime(CLOCK_MONOTONIC, &t2);
975
976
if (ret < 0) {
972
- printf("readv failed: %s\n", strerror(-ret));
977
+ error_setg(errp, "readv failed: %s", strerror(-ret));
978
goto out;
979
}
980
cnt = ret;
985
void *cmp_buf = g_malloc(qiov.size);
986
memset(cmp_buf, pattern, qiov.size);
987
if (memcmp(buf, cmp_buf, qiov.size)) {
983
- printf("Pattern verification failed at offset %"
984
- PRId64 ", %zu bytes\n", offset, qiov.size);
988
+ error_setg(errp, "Pattern verification failed at offset %"
989
+ PRId64 ", %zu bytes", offset, qiov.size);
990
ret = -EINVAL;
991
}
992
g_free(cmp_buf);
1036
"\n");
1037
}
1038
1034
-static int write_f(BlockBackend *blk, int argc, char **argv);
1039
+static int write_f(BlockBackend *blk, int argc, char **argv, Error **errp);
1040
1041
static const cmdinfo_t write_cmd = {
1042
.name = "write",
1050
.help = write_help,
1051
};
1052
1048
-static int write_f(BlockBackend *blk, int argc, char **argv)
1053
+static int write_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1054
{
1055
struct timespec t1, t2;
1056
bool Cflag = false, qflag = false, bflag = false;
1087
break;
1088
case 'P':
1089
Pflag = true;
1085
- pattern = parse_pattern(optarg);
1090
+ pattern = parse_pattern(optarg, errp);
1091
if (pattern < 0) {
1092
return -EINVAL;
1093
}
1120
}
1121
1122
if (bflag && zflag) {
1118
- printf("-b and -z cannot be specified at the same time\n");
1123
+ error_setg(errp, "-b and -z cannot be specified at the same time");
1124
return -EINVAL;
1125
}
1126
1127
if ((flags & BDRV_REQ_FUA) && (bflag || cflag)) {
1123
- printf("-f and -b or -c cannot be specified at the same time\n");
1128
+ error_setg(errp,
1129
+ "-f and -b or -c cannot be specified at the same time");
1130
return -EINVAL;
1131
}
1132
1133
if ((flags & BDRV_REQ_NO_FALLBACK) && !zflag) {
1128
- printf("-n requires -z to be specified\n");
1134
+ error_setg(errp, "-n requires -z to be specified");
1135
return -EINVAL;
1136
}
1137
1138
if ((flags & BDRV_REQ_MAY_UNMAP) && !zflag) {
1133
- printf("-u requires -z to be specified\n");
1139
+ error_setg(errp, "-u requires -z to be specified");
1140
return -EINVAL;
1141
}
1142
1143
if (zflag + Pflag + sflag > 1) {
1138
- printf("Only one of -z, -P, and -s "
1139
- "can be specified at the same time\n");
1144
+ error_setg(errp, "Only one of -z, -P, and -s "
1145
+ "can be specified at the same time");
1146
return -EINVAL;
1147
}
1148
1149
offset = cvtnum(argv[optind]);
1150
if (offset < 0) {
1145
- print_cvtnum_err(offset, argv[optind]);
1151
+ set_cvtnum_err(offset, argv[optind], errp);
1152
return offset;
1153
}
1154
1155
optind++;
1156
count = cvtnum(argv[optind]);
1157
if (count < 0) {
1152
- print_cvtnum_err(count, argv[optind]);
1158
+ set_cvtnum_err(count, argv[optind], errp);
1159
return count;
1160
} else if (count > BDRV_REQUEST_MAX_BYTES &&
1161
!(flags & BDRV_REQ_NO_FALLBACK)) {
1156
- printf("length cannot exceed %" PRIu64 " without -n, given %s\n",
1157
- (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
1162
+ error_setg(errp,
1163
+ "length cannot exceed %" PRIu64 " without -n, given %s",
1164
+ (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
1165
return -EINVAL;
1166
}
1167
1168
if (bflag || cflag) {
1169
if (!QEMU_IS_ALIGNED(offset, BDRV_SECTOR_SIZE)) {
1163
- printf("%" PRId64 " is not a sector-aligned value for 'offset'\n",
1164
- offset);
1170
+ error_setg(errp,
1171
+ "%" PRId64 " is not a sector-aligned value for 'offset'",
1172
+ offset);
1173
return -EINVAL;
1174
}
1175
1176
if (!QEMU_IS_ALIGNED(count, BDRV_SECTOR_SIZE)) {
1169
- printf("%"PRId64" is not a sector-aligned value for 'count'\n",
1170
- count);
1177
+ error_setg(errp,
1178
+ "%" PRId64 " is not a sector-aligned value for 'count'",
1179
+ count);
1180
return -EINVAL;
1181
}
1182
}
1183
1184
if (zflag) {
1185
if (flags & BDRV_REQ_REGISTERED_BUF) {
1177
- printf("cannot combine zero write with registered I/O buffer\n");
1186
+ error_setg(errp,
1187
+ "cannot combine zero write with registered I/O buffer");
1188
return -EINVAL;
1189
}
1190
} else {
1191
if (sflag) {
1192
buf = qemu_io_alloc_from_file(blk, count, file_name,
1183
- flags & BDRV_REQ_REGISTERED_BUF);
1193
+ flags & BDRV_REQ_REGISTERED_BUF,
1194
+ errp);
1195
if (!buf) {
1196
return -EINVAL;
1197
}
1214
clock_gettime(CLOCK_MONOTONIC, &t2);
1215
1216
if (ret < 0) {
1206
- printf("write failed: %s\n", strerror(-ret));
1217
+ error_setg(errp, "write failed: %s", strerror(-ret));
1218
goto out;
1219
}
1220
cnt = ret;
1256
"\n");
1257
}
1258
1248
-static int writev_f(BlockBackend *blk, int argc, char **argv);
1259
+static int writev_f(BlockBackend *blk, int argc, char **argv, Error **errp);
1260
1261
static const cmdinfo_t writev_cmd = {
1262
.name = "writev",
1269
.help = writev_help,
1270
};
1271
1261
-static int writev_f(BlockBackend *blk, int argc, char **argv)
1272
+static int writev_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1273
{
1274
struct timespec t1, t2;
1275
bool Cflag = false, qflag = false;
1298
flags |= BDRV_REQ_REGISTERED_BUF;
1299
break;
1300
case 'P':
1290
- pattern = parse_pattern(optarg);
1301
+ pattern = parse_pattern(optarg, errp);
1302
if (pattern < 0) {
1303
return -EINVAL;
1304
}
1316
1317
offset = cvtnum(argv[optind]);
1318
if (offset < 0) {
1308
- print_cvtnum_err(offset, argv[optind]);
1319
+ set_cvtnum_err(offset, argv[optind], errp);
1320
return offset;
1321
}
1322
optind++;
1323
1324
nr_iov = argc - optind;
1325
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern,
1315
- flags & BDRV_REQ_REGISTERED_BUF);
1326
+ flags & BDRV_REQ_REGISTERED_BUF, errp);
1327
if (buf == NULL) {
1328
return -EINVAL;
1329
}
1333
clock_gettime(CLOCK_MONOTONIC, &t2);
1334
1335
if (ret < 0) {
1325
- printf("writev failed: %s\n", strerror(-ret));
1336
+ error_setg(errp, "writev failed: %s", strerror(-ret));
1337
goto out;
1338
}
1339
cnt = ret;
1378
1379
1380
if (ret < 0) {
1370
- printf("aio_write failed: %s\n", strerror(-ret));
1381
+ error_report("aio_write failed: %s", strerror(-ret));
1382
block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct);
1383
goto out;
1384
}
1410
clock_gettime(CLOCK_MONOTONIC, &t2);
1411
1412
if (ret < 0) {
1402
- printf("readv failed: %s\n", strerror(-ret));
1413
+ error_report("readv failed: %s", strerror(-ret));
1414
block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct);
1415
goto out;
1416
}
1420
1421
memset(cmp_buf, ctx->pattern, ctx->qiov.size);
1422
if (memcmp(ctx->buf, cmp_buf, ctx->qiov.size)) {
1412
- printf("Pattern verification failed at offset %"
1413
- PRId64 ", %zu bytes\n", ctx->offset, ctx->qiov.size);
1423
+ error_report("Pattern verification failed at offset %"
1424
+ PRId64 ", %zu bytes", ctx->offset, ctx->qiov.size);
1425
}
1426
g_free(cmp_buf);
1427
}
1472
"\n");
1473
}
1474
1464
-static int aio_read_f(BlockBackend *blk, int argc, char **argv);
1475
+static int aio_read_f(BlockBackend *blk, int argc, char **argv, Error **errp);
1476
1477
static const cmdinfo_t aio_read_cmd = {
1478
.name = "aio_read",
1484
.help = aio_read_help,
1485
};
1486
1476
-static int aio_read_f(BlockBackend *blk, int argc, char **argv)
1487
+static int aio_read_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1488
{
1489
int nr_iov, c;
1490
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
1497
break;
1498
case 'P':
1499
ctx->Pflag = true;
1489
- ctx->pattern = parse_pattern(optarg);
1500
+ ctx->pattern = parse_pattern(optarg, errp);
1501
if (ctx->pattern < 0) {
1502
g_free(ctx);
1503
return -EINVAL;
1533
ctx->offset = cvtnum(argv[optind]);
1534
if (ctx->offset < 0) {
1535
int ret = ctx->offset;
1525
- print_cvtnum_err(ret, argv[optind]);
1536
+ set_cvtnum_err(ret, argv[optind], errp);
1537
g_free(ctx);
1538
return ret;
1539
}
1541
1542
nr_iov = argc - optind;
1543
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov, 0xab,
1533
- ctx->flags & BDRV_REQ_REGISTERED_BUF);
1544
+ ctx->flags & BDRV_REQ_REGISTERED_BUF, errp);
1545
if (ctx->buf == NULL) {
1546
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_READ);
1547
g_free(ctx);
1584
"\n");
1585
}
1586
1576
-static int aio_write_f(BlockBackend *blk, int argc, char **argv);
1587
+static int aio_write_f(BlockBackend *blk, int argc, char **argv, Error **errp);
1588
1589
static const cmdinfo_t aio_write_cmd = {
1590
.name = "aio_write",
1597
.help = aio_write_help,
1598
};
1599
1589
-static int aio_write_f(BlockBackend *blk, int argc, char **argv)
1600
+static int aio_write_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1601
{
1602
int nr_iov, c;
1603
int pattern = 0xcd;
1622
ctx->flags |= BDRV_REQ_MAY_UNMAP;
1623
break;
1624
case 'P':
1614
- pattern = parse_pattern(optarg);
1625
+ pattern = parse_pattern(optarg, errp);
1626
if (pattern < 0) {
1627
g_free(ctx);
1628
return -EINVAL;
1650
}
1651
1652
if (ctx->zflag && optind != argc - 2) {
1642
- printf("-z supports only a single length parameter\n");
1653
+ error_setg(errp, "-z supports only a single length parameter");
1654
g_free(ctx);
1655
return -EINVAL;
1656
}
1657
1658
if ((ctx->flags & BDRV_REQ_MAY_UNMAP) && !ctx->zflag) {
1648
- printf("-u requires -z to be specified\n");
1659
+ error_setg(errp, "-u requires -z to be specified");
1660
g_free(ctx);
1661
return -EINVAL;
1662
}
1663
1664
if (ctx->zflag && ctx->Pflag) {
1654
- printf("-z and -P cannot be specified at the same time\n");
1665
+ error_setg(errp, "-z and -P cannot be specified at the same time");
1666
g_free(ctx);
1667
return -EINVAL;
1668
}
1669
1670
if (ctx->zflag && (ctx->flags & BDRV_REQ_REGISTERED_BUF)) {
1660
- printf("cannot combine zero write with registered I/O buffer\n");
1671
+ error_setg(errp,
1672
+ "cannot combine zero write with registered I/O buffer");
1673
g_free(ctx);
1674
return -EINVAL;
1675
}
1677
ctx->offset = cvtnum(argv[optind]);
1678
if (ctx->offset < 0) {
1679
int ret = ctx->offset;
1668
- print_cvtnum_err(ret, argv[optind]);
1680
+ set_cvtnum_err(ret, argv[optind], errp);
1681
g_free(ctx);
1682
return ret;
1683
}
1686
if (ctx->zflag) {
1687
int64_t count = cvtnum(argv[optind]);
1688
if (count < 0) {
1677
- print_cvtnum_err(count, argv[optind]);
1689
+ set_cvtnum_err(count, argv[optind], errp);
1690
g_free(ctx);
1691
return count;
1692
}
1697
} else {
1698
nr_iov = argc - optind;
1699
ctx->buf = create_iovec(blk, &ctx->qiov, &argv[optind], nr_iov,
1688
- pattern, ctx->flags & BDRV_REQ_REGISTERED_BUF);
1700
+ pattern,
1701
+ ctx->flags & BDRV_REQ_REGISTERED_BUF, errp);
1702
if (ctx->buf == NULL) {
1703
block_acct_invalid(blk_get_stats(blk), BLOCK_ACCT_WRITE);
1704
g_free(ctx);
1716
return 0;
1717
}
1718
1706
-static int aio_flush_f(BlockBackend *blk, int argc, char **argv)
1719
+static int aio_flush_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1720
{
1721
BlockAcctCookie cookie;
1722
block_acct_start(blk_get_stats(blk), &cookie, 0, BLOCK_ACCT_FLUSH);
1731
.oneline = "completes all outstanding aio requests"
1732
};
1733
1721
-static int flush_f(BlockBackend *blk, int argc, char **argv)
1734
+static int flush_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1735
{
1736
return blk_flush(blk);
1737
}
1748
return bytes >> BDRV_SECTOR_BITS;
1749
}
1750
1738
-static int zone_report_f(BlockBackend *blk, int argc, char **argv)
1751
+static int zone_report_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1752
{
1753
int ret;
1754
int64_t offset;
1758
++optind;
1759
offset = cvtnum(argv[optind]);
1760
if (offset < 0) {
1748
- print_cvtnum_err(offset, argv[optind]);
1761
+ set_cvtnum_err(offset, argv[optind], errp);
1762
return offset;
1763
}
1764
++optind;
1765
val = cvtnum(argv[optind]);
1766
if (val < 0) {
1754
- print_cvtnum_err(val, argv[optind]);
1767
+ set_cvtnum_err(val, argv[optind], errp);
1768
return val;
1769
}
1770
if (val > UINT_MAX) {
1758
- printf("Number of zones must be less than 2^32\n");
1771
+ error_setg(errp, "Number of zones must be less than 2^32");
1772
return -ERANGE;
1773
}
1774
nr_zones = val;
1777
zones = g_new(BlockZoneDescriptor, nr_zones);
1778
ret = blk_zone_report(blk, offset, &nr_zones, zones);
1779
if (ret < 0) {
1767
- printf("zone report failed: %s\n", strerror(-ret));
1780
+ error_setg(errp, "zone report failed: %s", strerror(-ret));
1781
} else {
1782
for (int i = 0; i < nr_zones; ++i) {
1783
printf("start: 0x%" PRIx64 ", len 0x%" PRIx64 ", "
1801
.oneline = "report zone information",
1802
};
1803
1791
-static int zone_open_f(BlockBackend *blk, int argc, char **argv)
1804
+static int zone_open_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1805
{
1806
int ret;
1807
int64_t offset, len;
1808
++optind;
1809
offset = cvtnum(argv[optind]);
1810
if (offset < 0) {
1798
- print_cvtnum_err(offset, argv[optind]);
1811
+ set_cvtnum_err(offset, argv[optind], errp);
1812
return offset;
1813
}
1814
++optind;
1815
len = cvtnum(argv[optind]);
1816
if (len < 0) {
1804
- print_cvtnum_err(len, argv[optind]);
1817
+ set_cvtnum_err(len, argv[optind], errp);
1818
return len;
1819
}
1820
ret = blk_zone_mgmt(blk, BLK_ZO_OPEN, offset, len);
1821
if (ret < 0) {
1809
- printf("zone open failed: %s\n", strerror(-ret));
1822
+ error_setg(errp, "zone open failed: %s", strerror(-ret));
1823
}
1824
return ret;
1825
}
1834
.oneline = "explicit open a range of zones in zone block device",
1835
};
1836
1824
-static int zone_close_f(BlockBackend *blk, int argc, char **argv)
1837
+static int zone_close_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1838
{
1839
int ret;
1840
int64_t offset, len;
1841
++optind;
1842
offset = cvtnum(argv[optind]);
1843
if (offset < 0) {
1831
- print_cvtnum_err(offset, argv[optind]);
1844
+ set_cvtnum_err(offset, argv[optind], errp);
1845
return offset;
1846
}
1847
++optind;
1848
len = cvtnum(argv[optind]);
1849
if (len < 0) {
1837
- print_cvtnum_err(len, argv[optind]);
1850
+ set_cvtnum_err(len, argv[optind], errp);
1851
return len;
1852
}
1853
ret = blk_zone_mgmt(blk, BLK_ZO_CLOSE, offset, len);
1854
if (ret < 0) {
1842
- printf("zone close failed: %s\n", strerror(-ret));
1855
+ error_setg(errp, "zone close failed: %s", strerror(-ret));
1856
}
1857
return ret;
1858
}
1867
.oneline = "close a range of zones in zone block device",
1868
};
1869
1857
-static int zone_finish_f(BlockBackend *blk, int argc, char **argv)
1870
+static int zone_finish_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1871
{
1872
int ret;
1873
int64_t offset, len;
1874
++optind;
1875
offset = cvtnum(argv[optind]);
1876
if (offset < 0) {
1864
- print_cvtnum_err(offset, argv[optind]);
1877
+ set_cvtnum_err(offset, argv[optind], errp);
1878
return offset;
1879
}
1880
++optind;
1881
len = cvtnum(argv[optind]);
1882
if (len < 0) {
1870
- print_cvtnum_err(len, argv[optind]);
1883
+ set_cvtnum_err(len, argv[optind], errp);
1884
return len;
1885
}
1886
ret = blk_zone_mgmt(blk, BLK_ZO_FINISH, offset, len);
1887
if (ret < 0) {
1875
- printf("zone finish failed: %s\n", strerror(-ret));
1888
+ error_setg(errp, "zone finish failed: %s", strerror(-ret));
1889
}
1890
return ret;
1891
}
1900
.oneline = "finish a range of zones in zone block device",
1901
};
1902
1890
-static int zone_reset_f(BlockBackend *blk, int argc, char **argv)
1903
+static int zone_reset_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1904
{
1905
int ret;
1906
int64_t offset, len;
1907
++optind;
1908
offset = cvtnum(argv[optind]);
1909
if (offset < 0) {
1897
- print_cvtnum_err(offset, argv[optind]);
1910
+ set_cvtnum_err(offset, argv[optind], errp);
1911
return offset;
1912
}
1913
++optind;
1914
len = cvtnum(argv[optind]);
1915
if (len < 0) {
1903
- print_cvtnum_err(len, argv[optind]);
1916
+ set_cvtnum_err(len, argv[optind], errp);
1917
return len;
1918
}
1919
ret = blk_zone_mgmt(blk, BLK_ZO_RESET, offset, len);
1920
if (ret < 0) {
1908
- printf("zone reset failed: %s\n", strerror(-ret));
1921
+ error_setg(errp, "zone reset failed: %s", strerror(-ret));
1922
}
1923
return ret;
1924
}
1947
return async_ret < 0 ? async_ret : 1;
1948
}
1949
1937
-static int zone_append_f(BlockBackend *blk, int argc, char **argv)
1950
+static int zone_append_f(BlockBackend *blk, int argc, char **argv, Error **errp)
1951
{
1952
int ret;
1953
bool pflag = false;
1969
1970
offset = cvtnum(argv[optind]);
1971
if (offset < 0) {
1959
- print_cvtnum_err(offset, argv[optind]);
1972
+ set_cvtnum_err(offset, argv[optind], errp);
1973
return offset;
1974
}
1975
optind++;
1976
nr_iov = argc - optind;
1977
buf = create_iovec(blk, &qiov, &argv[optind], nr_iov, pattern,
1965
- flags & BDRV_REQ_REGISTERED_BUF);
1978
+ flags & BDRV_REQ_REGISTERED_BUF, errp);
1979
if (buf == NULL) {
1980
return -EINVAL;
1981
}
1982
ret = do_aio_zone_append(blk, &qiov, &offset, flags, &total);
1983
if (ret < 0) {
1971
- printf("zone append failed: %s\n", strerror(-ret));
1984
+ error_setg(errp, "zone append failed: %s", strerror(-ret));
1985
goto out;
1986
}
1987
2007
.oneline = "append write a number of bytes at a specified offset",
2008
};
2009
1997
-static int truncate_f(BlockBackend *blk, int argc, char **argv);
2010
+static int truncate_f(BlockBackend *blk, int argc, char **argv, Error **errp);
2011
static const cmdinfo_t truncate_cmd = {
2012
.name = "truncate",
2013
.altname = "t",
2019
.oneline = "truncates the current file at the given offset",
2020
};
2021
2009
-static int truncate_f(BlockBackend *blk, int argc, char **argv)
2022
+static int truncate_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2023
{
2011
- Error *local_err = NULL;
2024
int64_t offset;
2025
int c, ret;
2026
PreallocMode prealloc = PREALLOC_MODE_OFF;
2031
prealloc = qapi_enum_parse(&PreallocMode_lookup, optarg,
2032
PREALLOC_MODE__MAX, NULL);
2033
if (prealloc == PREALLOC_MODE__MAX) {
2022
- error_report("Invalid preallocation mode '%s'", optarg);
2034
+ error_setg(errp, "Invalid preallocation mode '%s'", optarg);
2035
return -EINVAL;
2036
}
2037
break;
2043
2044
offset = cvtnum(argv[optind]);
2045
if (offset < 0) {
2034
- print_cvtnum_err(offset, argv[1]);
2046
+ set_cvtnum_err(offset, argv[1], errp);
2047
return offset;
2048
}
2049
2052
* exact=true. It is better to err on the "emit more errors" side
2053
* than to be overly permissive.
2054
*/
2043
- ret = blk_truncate(blk, offset, false, prealloc, 0, &local_err);
2055
+ ret = blk_truncate(blk, offset, false, prealloc, 0, errp);
2056
if (ret < 0) {
2045
- error_report_err(local_err);
2057
return ret;
2058
}
2059
2060
return 0;
2061
}
2062
2052
-static int length_f(BlockBackend *blk, int argc, char **argv)
2063
+static int length_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2064
{
2065
int64_t size;
2066
char s1[64];
2067
2068
size = blk_getlength(blk);
2069
if (size < 0) {
2059
- printf("getlength: %s\n", strerror(-size));
2070
+ error_setg(errp, "getlength: %s", strerror(-size));
2071
return size;
2072
}
2073
2085
};
2086
2087
2077
-static int info_f(BlockBackend *blk, int argc, char **argv)
2088
+static int info_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2089
{
2090
+ ERRP_GUARD();
2091
BlockDriverState *bs = blk_bs(blk);
2092
BlockDriverInfo bdi;
2093
ImageInfoSpecific *spec_info;
2082
- Error *local_err = NULL;
2094
char s1[64], s2[64];
2095
int ret;
2096
2115
printf("cluster size: %s\n", s1);
2116
printf("vm state offset: %s\n", s2);
2117
2107
- spec_info = bdrv_get_specific_info(bs, &local_err);
2108
- if (local_err) {
2109
- error_report_err(local_err);
2118
+ spec_info = bdrv_get_specific_info(bs, errp);
2119
+ if (*errp) {
2120
return -EIO;
2121
}
2122
if (spec_info) {
2153
"\n");
2154
}
2155
2146
-static int discard_f(BlockBackend *blk, int argc, char **argv);
2156
+static int discard_f(BlockBackend *blk, int argc, char **argv, Error **errp);
2157
2158
static const cmdinfo_t discard_cmd = {
2159
.name = "discard",
2167
.help = discard_help,
2168
};
2169
2160
-static int discard_f(BlockBackend *blk, int argc, char **argv)
2170
+static int discard_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2171
{
2172
struct timespec t1, t2;
2173
bool Cflag = false, qflag = false;
2195
2196
offset = cvtnum(argv[optind]);
2197
if (offset < 0) {
2188
- print_cvtnum_err(offset, argv[optind]);
2198
+ set_cvtnum_err(offset, argv[optind], errp);
2199
return offset;
2200
}
2201
2202
optind++;
2203
bytes = cvtnum(argv[optind]);
2204
if (bytes < 0) {
2195
- print_cvtnum_err(bytes, argv[optind]);
2205
+ set_cvtnum_err(bytes, argv[optind], errp);
2206
return bytes;
2207
} else if (bytes > BDRV_REQUEST_MAX_BYTES) {
2198
- printf("length cannot exceed %"PRIu64", given %s\n",
2199
- (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
2208
+ error_setg(errp, "length cannot exceed %" PRIu64 ", given %s",
2209
+ (uint64_t)BDRV_REQUEST_MAX_BYTES, argv[optind]);
2210
return -EINVAL;
2211
}
2212
2215
clock_gettime(CLOCK_MONOTONIC, &t2);
2216
2217
if (ret < 0) {
2208
- printf("discard failed: %s\n", strerror(-ret));
2218
+ error_setg(errp, "discard failed: %s", strerror(-ret));
2219
return ret;
2220
}
2221
2248
"\n");
2249
}
2250
2241
-static int aio_discard_f(BlockBackend *blk, int argc, char **argv);
2251
+static int aio_discard_f(BlockBackend *blk, int argc, char **argv,
2252
+ Error **errp);
2253
2254
static const cmdinfo_t aio_discard_cmd = {
2255
.name = "aio_discard",
2270
clock_gettime(CLOCK_MONOTONIC, &t2);
2271
2272
if (ret < 0) {
2262
- printf("aio_discard failed: %s\n", strerror(-ret));
2273
+ error_report("aio_discard failed: %s", strerror(-ret));
2274
block_acct_failed(blk_get_stats(ctx->blk), &ctx->acct);
2275
goto out;
2276
}
2289
g_free(ctx);
2290
}
2291
2281
-static int aio_discard_f(BlockBackend *blk, int argc, char **argv)
2292
+static int aio_discard_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2293
{
2294
int c, ret;
2295
int64_t count;
2321
ctx->offset = cvtnum(argv[optind]);
2322
if (ctx->offset < 0) {
2323
ret = ctx->offset;
2313
- print_cvtnum_err(ret, argv[optind]);
2324
+ set_cvtnum_err(ret, argv[optind], errp);
2325
g_free(ctx);
2326
return ret;
2327
}
2329
2330
count = cvtnum(argv[optind]);
2331
if (count < 0) {
2321
- print_cvtnum_err(count, argv[optind]);
2332
+ set_cvtnum_err(count, argv[optind], errp);
2333
g_free(ctx);
2334
return count;
2335
}
2343
return 0;
2344
}
2345
2335
-static int alloc_f(BlockBackend *blk, int argc, char **argv)
2346
+static int alloc_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2347
{
2348
BlockDriverState *bs = blk_bs(blk);
2349
int64_t offset, start, remaining, count;
2353
2354
start = offset = cvtnum(argv[1]);
2355
if (offset < 0) {
2345
- print_cvtnum_err(offset, argv[1]);
2356
+ set_cvtnum_err(offset, argv[1], errp);
2357
return offset;
2358
}
2359
2360
if (argc == 3) {
2361
count = cvtnum(argv[2]);
2362
if (count < 0) {
2352
- print_cvtnum_err(count, argv[2]);
2363
+ set_cvtnum_err(count, argv[2], errp);
2364
return count;
2365
}
2366
} else {
2372
while (remaining) {
2373
ret = bdrv_is_allocated(bs, offset, remaining, &num);
2374
if (ret < 0) {
2364
- printf("is_allocated failed: %s\n", strerror(-ret));
2375
+ error_setg(errp, "is_allocated failed: %s", strerror(-ret));
2376
return ret;
2377
}
2378
offset += num;
2433
return firstret;
2434
}
2435
2425
-static int map_f(BlockBackend *blk, int argc, char **argv)
2436
+static int map_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2437
{
2438
int64_t offset, bytes;
2439
char s1[64], s2[64];
2444
offset = 0;
2445
bytes = blk_getlength(blk);
2446
if (bytes < 0) {
2436
- error_report("Failed to query image length: %s", strerror(-bytes));
2447
+ error_setg(errp, "Failed to query image length: %s", strerror(-bytes));
2448
return bytes;
2449
}
2450
2451
while (bytes) {
2452
ret = map_is_allocated(blk_bs(blk), offset, bytes, &num);
2453
if (ret < 0) {
2443
- error_report("Failed to get allocation status: %s", strerror(-ret));
2454
+ error_setg(errp, "Failed to get allocation status: %s",
2455
+ strerror(-ret));
2456
return ret;
2457
} else if (!num) {
2446
- error_report("Unexpected end of image");
2458
+ error_setg(errp, "Unexpected end of image");
2459
return -EIO;
2460
}
2461
2497
"\n");
2498
}
2499
2488
-static int reopen_f(BlockBackend *blk, int argc, char **argv);
2500
+static int reopen_f(BlockBackend *blk, int argc, char **argv, Error **errp);
2501
2502
static QemuOptsList reopen_opts = {
2503
.name = "reopen",
2519
.help = reopen_help,
2520
};
2521
2510
-static int reopen_f(BlockBackend *blk, int argc, char **argv)
2522
+static int reopen_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2523
{
2524
BlockDriverState *bs = blk_bs(blk);
2525
QemuOpts *qopts;
2529
bool writethrough = !blk_enable_write_cache(blk);
2530
bool has_rw_option = false;
2531
bool has_cache_option = false;
2520
- Error *local_err = NULL;
2532
2533
while ((c = getopt(argc, argv, "c:o:rw")) != -1) {
2534
switch (c) {
2535
case 'c':
2536
if (bdrv_parse_cache_mode(optarg, &flags, &writethrough) < 0) {
2526
- error_report("Invalid cache option: %s", optarg);
2537
+ error_setg(errp, "Invalid cache option: %s", optarg);
2538
return -EINVAL;
2539
}
2540
has_cache_option = true;
2547
break;
2548
case 'r':
2549
if (has_rw_option) {
2539
- error_report("Only one -r/-w option may be given");
2550
+ error_setg(errp, "Only one -r/-w option may be given");
2551
return -EINVAL;
2552
}
2553
flags &= ~BDRV_O_RDWR;
2555
break;
2556
case 'w':
2557
if (has_rw_option) {
2547
- error_report("Only one -r/-w option may be given");
2558
+ error_setg(errp, "Only one -r/-w option may be given");
2559
return -EINVAL;
2560
}
2561
flags |= BDRV_O_RDWR;
2577
if (!writethrough != blk_enable_write_cache(blk) &&
2578
blk_get_attached_dev(blk))
2579
{
2569
- error_report("Cannot change cache.writeback: Device attached");
2580
+ error_setg(errp, "Cannot change cache.writeback: Device attached");
2581
qemu_opts_reset(&reopen_opts);
2582
return -EBUSY;
2583
}
2600
2601
if (qdict_haskey(opts, BDRV_OPT_READ_ONLY)) {
2602
if (has_rw_option) {
2592
- error_report("Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY "'");
2603
+ error_setg(errp,
2604
+ "Cannot set both -r/-w and '" BDRV_OPT_READ_ONLY "'");
2605
qobject_unref(opts);
2606
return -EINVAL;
2607
}
2612
if (qdict_haskey(opts, BDRV_OPT_CACHE_DIRECT) ||
2613
qdict_haskey(opts, BDRV_OPT_CACHE_NO_FLUSH)) {
2614
if (has_cache_option) {
2603
- error_report("Cannot set both -c and the cache options");
2615
+ error_setg(errp, "Cannot set both -c and the cache options");
2616
qobject_unref(opts);
2617
return -EINVAL;
2618
}
2621
qdict_put_bool(opts, BDRV_OPT_CACHE_NO_FLUSH, flags & BDRV_O_NO_FLUSH);
2622
}
2623
2612
- bdrv_reopen(bs, opts, true, &local_err);
2613
-
2614
- if (local_err) {
2615
- error_report_err(local_err);
2624
+ if (bdrv_reopen(bs, opts, true, errp) < 0) {
2625
return -EINVAL;
2626
}
2627
2629
return 0;
2630
}
2631
2623
-static int break_f(BlockBackend *blk, int argc, char **argv)
2632
+static int break_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2633
{
2634
int ret;
2635
2636
ret = bdrv_debug_breakpoint(blk_bs(blk), argv[1], argv[2]);
2637
if (ret < 0) {
2629
- printf("Could not set breakpoint: %s\n", strerror(-ret));
2638
+ error_setg(errp, "Could not set breakpoint: %s", strerror(-ret));
2639
return ret;
2640
}
2641
2642
return 0;
2643
}
2644
2636
-static int remove_break_f(BlockBackend *blk, int argc, char **argv)
2645
+static int remove_break_f(BlockBackend *blk, int argc, char **argv,
2646
+ Error **errp)
2647
{
2648
int ret;
2649
2650
ret = bdrv_debug_remove_breakpoint(blk_bs(blk), argv[1]);
2651
if (ret < 0) {
2642
- printf("Could not remove breakpoint %s: %s\n", argv[1], strerror(-ret));
2652
+ error_setg(errp, "Could not remove breakpoint %s: %s",
2653
+ argv[1], strerror(-ret));
2654
return ret;
2655
}
2656
2676
.oneline = "remove a breakpoint by tag",
2677
};
2678
2668
-static int resume_f(BlockBackend *blk, int argc, char **argv)
2679
+static int resume_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2680
{
2681
int ret;
2682
2683
ret = bdrv_debug_resume(blk_bs(blk), argv[1]);
2684
if (ret < 0) {
2674
- printf("Could not resume request: %s\n", strerror(-ret));
2685
+ error_setg(errp, "Could not resume request: %s", strerror(-ret));
2686
return ret;
2687
}
2688
2698
.oneline = "resumes the request tagged as tag",
2699
};
2700
2690
-static int wait_break_f(BlockBackend *blk, int argc, char **argv)
2701
+static int wait_break_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2702
{
2703
while (!bdrv_debug_is_suspended(blk_bs(blk), argv[1])) {
2704
aio_poll(blk_get_aio_context(blk), true);
2715
.oneline = "waits for the suspension of a request",
2716
};
2717
2707
-static int abort_f(BlockBackend *blk, int argc, char **argv)
2718
+static int abort_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2719
{
2720
abort();
2721
}
2741
"\n", SIGTERM);
2742
}
2743
2733
-static int sigraise_f(BlockBackend *blk, int argc, char **argv);
2744
+static int sigraise_f(BlockBackend *blk, int argc, char **argv, Error **errp);
2745
2746
static const cmdinfo_t sigraise_cmd = {
2747
.name = "sigraise",
2754
.help = sigraise_help,
2755
};
2756
2746
-static int sigraise_f(BlockBackend *blk, int argc, char **argv)
2757
+static int sigraise_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2758
{
2759
int64_t sig = cvtnum(argv[1]);
2760
if (sig < 0) {
2750
- print_cvtnum_err(sig, argv[1]);
2761
+ set_cvtnum_err(sig, argv[1], errp);
2762
return sig;
2763
} else if (sig > NSIG) {
2753
- printf("signal argument '%s' is too large to be a valid signal\n",
2754
- argv[1]);
2764
+ error_setg(errp,
2765
+ "signal argument '%s' is too large to be a valid signal",
2766
+ argv[1]);
2767
return -EINVAL;
2768
}
2769
2784
*expired = true;
2785
}
2786
2775
-static int sleep_f(BlockBackend *blk, int argc, char **argv)
2787
+static int sleep_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2788
{
2789
char *endptr;
2790
long ms;
2793
2794
ms = strtol(argv[1], &endptr, 0);
2795
if (ms < 0 || *endptr != '\0') {
2784
- printf("%s is not a valid number\n", argv[1]);
2796
+ error_setg(errp, "%s is not a valid number", argv[1]);
2797
return -EINVAL;
2798
}
2799
2845
printf("\nUse 'help commandname' for extended help.\n");
2846
}
2847
2836
-static int help_f(BlockBackend *blk, int argc, char **argv)
2848
+static int help_f(BlockBackend *blk, int argc, char **argv, Error **errp)
2849
{
2850
const cmdinfo_t *ct;
2851
2856
2857
ct = find_command(argv[1]);
2858
if (ct == NULL) {
2847
- printf("command %s not found\n", argv[1]);
2859
+ error_setg(errp, "command %s not found", argv[1]);
2860
return -EINVAL;
2861
}
2862
2879
* Called with aio context of blk acquired. Or with qemu_get_aio_context()
2880
* context acquired if blk is NULL.
2881
*/
2870
-int qemuio_command(BlockBackend *blk, const char *cmd)
2882
+int qemuio_command(BlockBackend *blk, const char *cmd, Error **errp)
2883
{
2884
char *input;
2885
const cmdinfo_t *ct;
2892
if (c) {
2893
ct = find_command(v[0]);
2894
if (ct) {
2883
- ret = command(blk, ct, c, v);
2895
+ ret = command(blk, ct, c, v, errp);
2896
} else {
2885
- fprintf(stderr, "command \"%s\" not found\n", v[0]);
2897
+ error_setg(errp, "command \"%s\" not found", v[0]);
2898
ret = -EINVAL;
2899
}
2900
}