static int discard_f(int argc, char **argv) { struct timeval t1, t2; int Cflag = 0, qflag = 0; int c, ret; int64_t offset; int count; while ((c = getopt(argc, argv, "Cq")) != EOF) { switch (c) { case 'C': Cflag = 1; break; case 'q': qflag = 1; break; default: return command_usage(&discard_cmd); } } if (optind != argc - 2) { return command_usage(&discard_cmd); } offset = cvtnum(argv[optind]); if (offset < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } optind++; count = cvtnum(argv[optind]); if (count < 0) { printf("non-numeric length argument -- %s\n", argv[optind]); return 0; } gettimeofday(&t1, NULL); ret = bdrv_discard(bs, offset, count); gettimeofday(&t2, NULL); if (ret < 0) { printf("discard failed: %s\n", strerror(-ret)); goto out; } /* Finally, report back -- -C gives a parsable format */ if (!qflag) { t2 = tsub(t2, t1); print_report("discard", &t2, offset, count, count, 1, Cflag); } out: return 0; }
static int raw_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors) { return bdrv_discard(bs->file, sector_num, nb_sectors); }