From 3f11723d7dd278329a3721bfc9c36835119f3a81 Mon Sep 17 00:00:00 2001 From: Konrad Rzeszutek Wilk Date: Mon, 11 Mar 2013 15:47:33 -0400 Subject: [PATCH] discard_io: Little tool to send DISCARD commands. Signed-off-by: Konrad Rzeszutek Wilk --- root_image/Makefile | 1 + root_image/tools/Makefile | 1 + root_image/tools/discard_io/Makefile | 25 +++++++++++++++++++ root_image/tools/discard_io/discard_io.c | 31 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+) create mode 100644 root_image/tools/discard_io/Makefile create mode 100644 root_image/tools/discard_io/discard_io.c diff --git a/root_image/Makefile b/root_image/Makefile index d152930..1d01231 100644 --- a/root_image/Makefile +++ b/root_image/Makefile @@ -941,6 +941,7 @@ xtt-tools-install: $(INSTALL_PROG) tools/debug/fb_test userspace/usr/bin/ $(INSTALL_PROG) tools/crashme/crashme userspace/usr/bin/ $(INSTALL_PROG) tools/eatmem/eatmem userspace/usr/bin/ + $(INSTALL_PROG) tools/discard_io/discard_io userspace/usr/bin/ fio/fio: fio/fio $(MAKE) -j$$(($(NCPUS) * 2)) -C fio diff --git a/root_image/tools/Makefile b/root_image/tools/Makefile index bf40b67..da5eeee 100644 --- a/root_image/tools/Makefile +++ b/root_image/tools/Makefile @@ -5,6 +5,7 @@ SUBDIRS += debug SUBDIRS += eatmem SUBDIRS += crashme SUBDIRS += read_intr +SUBDIRS += discard_io .PHONY: all all: diff --git a/root_image/tools/discard_io/Makefile b/root_image/tools/discard_io/Makefile new file mode 100644 index 0000000..a75bbf7 --- /dev/null +++ b/root_image/tools/discard_io/Makefile @@ -0,0 +1,25 @@ +TARGETS-y := discard_io +TARGETS := $(TARGETS-y) + +INSTALL_BIN-y := discard_io +INSTALL_BIN := $(INSTALL_BIN-y) + + +.PHONY: all +all: build + +.PHONY: build +build: $(TARGETS) + +.PHONY: install +install: build + $(INSTALL_DIR) $(DESTDIR)$(BINDIR) + $(INSTALL_DIR) $(DESTDIR)$(SBINDIR) + +.PHONY: clean +clean: + $(RM) *.o $(TARGETS) *~ $(DEPS) + +%.o: %.c $(HDRS) Makefile + $(CC) -c $(CFLAGS) -o $@ $< + diff --git a/root_image/tools/discard_io/discard_io.c b/root_image/tools/discard_io/discard_io.c new file mode 100644 index 0000000..b10562c --- /dev/null +++ b/root_image/tools/discard_io/discard_io.c @@ -0,0 +1,31 @@ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include + + +int main(int argc, char *argv[]) +{ + char *name = "/dev/xvda"; + int disk; + unsigned long range[2]; + int rc; + + if (argc >= 1) + name = argv[1]; + + disk = open(name, O_RDWR | O_EXCL | O_LARGEFILE); + if (disk == -1) { + fprintf(stderr,"Cannot open %s [%s]\n", name, strerror(errno)); + return errno; + } + range[0] = 0; + range[1] = (-1ULL); + rc = ioctl(disk, BLKDISCARD, &range); + close(disk); + return rc; +} -- 2.39.5