Revision edff5db1

b/qemu-io.c
1394 1394
	.oneline	= "prints information about the current file",
1395 1395
};
1396 1396

  
1397
static void
1398
discard_help(void)
1399
{
1400
	printf(
1401
"\n"
1402
" discards a range of bytes from the given offset\n"
1403
"\n"
1404
" Example:\n"
1405
" 'discard 512 1k' - discards 1 kilobyte from 512 bytes into the file\n"
1406
"\n"
1407
" Discards a segment of the currently open file.\n"
1408
" -C, -- report statistics in a machine parsable format\n"
1409
" -q, -- quite mode, do not show I/O statistics\n"
1410
"\n");
1411
}
1412

  
1413
static int discard_f(int argc, char **argv);
1414

  
1415
static const cmdinfo_t discard_cmd = {
1416
	.name		= "discard",
1417
	.altname	= "d",
1418
	.cfunc		= discard_f,
1419
	.argmin		= 2,
1420
	.argmax		= -1,
1421
	.args		= "[-Cq] off len",
1422
	.oneline	= "discards a number of bytes at a specified offset",
1423
	.help		= discard_help,
1424
};
1425

  
1426
static int
1427
discard_f(int argc, char **argv)
1428
{
1429
	struct timeval t1, t2;
1430
	int Cflag = 0, qflag = 0;
1431
	int c, ret;
1432
	int64_t offset;
1433
	int count;
1434

  
1435
	while ((c = getopt(argc, argv, "Cq")) != EOF) {
1436
		switch (c) {
1437
		case 'C':
1438
			Cflag = 1;
1439
			break;
1440
		case 'q':
1441
			qflag = 1;
1442
			break;
1443
		default:
1444
			return command_usage(&discard_cmd);
1445
		}
1446
	}
1447

  
1448
	if (optind != argc - 2) {
1449
		return command_usage(&discard_cmd);
1450
	}
1451

  
1452
	offset = cvtnum(argv[optind]);
1453
	if (offset < 0) {
1454
		printf("non-numeric length argument -- %s\n", argv[optind]);
1455
		return 0;
1456
	}
1457

  
1458
	optind++;
1459
	count = cvtnum(argv[optind]);
1460
	if (count < 0) {
1461
		printf("non-numeric length argument -- %s\n", argv[optind]);
1462
		return 0;
1463
	}
1464

  
1465
	gettimeofday(&t1, NULL);
1466
	ret = bdrv_discard(bs, offset, count);
1467
	gettimeofday(&t2, NULL);
1468

  
1469
	if (ret < 0) {
1470
		printf("discard failed: %s\n", strerror(-ret));
1471
		goto out;
1472
	}
1473

  
1474
	/* Finally, report back -- -C gives a parsable format */
1475
	if (!qflag) {
1476
		t2 = tsub(t2, t1);
1477
		print_report("discard", &t2, offset, count, count, 1, Cflag);
1478
	}
1479

  
1480
out:
1481
	return 0;
1482
}
1483

  
1397 1484
static int
1398 1485
alloc_f(int argc, char **argv)
1399 1486
{
......
1715 1802
	add_command(&truncate_cmd);
1716 1803
	add_command(&length_cmd);
1717 1804
	add_command(&info_cmd);
1805
	add_command(&discard_cmd);
1718 1806
	add_command(&alloc_cmd);
1719 1807
	add_command(&map_cmd);
1720 1808

  

Also available in: Unified diff