]> xenbits.xensource.com Git - xentesttools/bootstrap.git/commitdiff
discard_io: Little tool to send DISCARD commands.
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 11 Mar 2013 19:47:33 +0000 (15:47 -0400)
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Mon, 11 Mar 2013 19:51:33 +0000 (15:51 -0400)
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
root_image/Makefile
root_image/tools/Makefile
root_image/tools/discard_io/Makefile [new file with mode: 0644]
root_image/tools/discard_io/discard_io.c [new file with mode: 0644]

index d152930a73684f5f5926289cb8e11bdb1b574ae7..1d01231fc526850a7775068fe40aeb9f6c93659d 100644 (file)
@@ -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
index bf40b6766d99f897ec6c05f9532df0ca8e561ebe..da5eeee3d32b230034fb0208821e2964e3ebf208 100644 (file)
@@ -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 (file)
index 0000000..a75bbf7
--- /dev/null
@@ -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 (file)
index 0000000..b10562c
--- /dev/null
@@ -0,0 +1,31 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <errno.h>
+#include <string.h>
+
+
+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;
+}