qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] qemu-io: Verify read data by patterns
@ 2009-04-14  9:17 Kevin Wolf
  2009-04-14 10:52 ` Christoph Hellwig
  2009-04-18 15:40 ` [Qemu-devel] " Anthony Liguori
  0 siblings, 2 replies; 3+ messages in thread
From: Kevin Wolf @ 2009-04-14  9:17 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, hch

This patch adds a -P option to read and readv which allows to compare the read
data to a given pattern. This can be used to verify data written by write -P.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 qemu-io.c |   44 ++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/qemu-io.c b/qemu-io.c
index 3e5c444..35b059b 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -192,6 +192,7 @@ read_help(void)
 " Reads a segment of the currently open file, optionally dumping it to the\n"
 " standard output stream (with -v option) for subsequent inspection.\n"
 " -p, -- use bdrv_pread to read the file\n"
+" -P, -- use a pattern to verify read data\n"
 " -C, -- report statistics in a machine parsable format\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quite mode, do not show I/O statistics\n"
@@ -207,8 +208,10 @@ read_f(int argc, char **argv)
 	char *buf;
 	int64_t offset;
 	int count, total;
+	int pattern = 0;
+	int Pflag = 0;
 
-	while ((c = getopt(argc, argv, "Cpqv")) != EOF) {
+	while ((c = getopt(argc, argv, "CpP:qv")) != EOF) {
 		switch (c) {
 		case 'C':
 			Cflag = 1;
@@ -216,6 +219,10 @@ read_f(int argc, char **argv)
 		case 'p':
 			pflag = 1;
 			break;
+		case 'P':
+			Pflag = 1;
+			pattern = atoi(optarg);
+			break;
 		case 'q':
 			qflag = 1;
 			break;
@@ -270,6 +277,17 @@ read_f(int argc, char **argv)
 		return 0;
 	}
 
+	if (Pflag) {
+		void* cmp_buf = malloc(count);
+		memset(cmp_buf, pattern, count);
+		if (memcmp(buf, cmp_buf, count)) {
+			printf("Pattern verification failed at offset %lld, "
+				"%d bytes\n",
+				(long long) offset, count);
+		}
+		free(cmp_buf);
+	}
+
 	if (qflag)
 		return 0;
 
@@ -291,7 +309,7 @@ static const cmdinfo_t read_cmd = {
 	.cfunc		= read_f,
 	.argmin		= 2,
 	.argmax		= -1,
-	.args		= "[-aCpqv] off len",
+	.args		= "[-aCpqv] [-P pattern ] off len",
 	.oneline	= "reads a number of bytes at a specified offset",
 	.help		= read_help,
 };
@@ -312,6 +330,7 @@ readv_help(void)
 " standard output stream (with -v option) for subsequent inspection.\n"
 " Uses multiple iovec buffers if more than one byte range is specified.\n"
 " -C, -- report statistics in a machine parsable format\n"
+" -P, -- use a pattern to verify read data\n"
 " -v, -- dump buffer to standard output\n"
 " -q, -- quite mode, do not show I/O statistics\n"
 "\n");
@@ -328,12 +347,18 @@ readv_f(int argc, char **argv)
 	int count = 0, total;
 	int nr_iov, i;
 	QEMUIOVector qiov;
+	int pattern = 0;
+	int Pflag = 0;
 
-	while ((c = getopt(argc, argv, "Cqv")) != EOF) {
+	while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
 		switch (c) {
 		case 'C':
 			Cflag = 1;
 			break;
+		case 'P':
+			Pflag = 1;
+			pattern = atoi(optarg);
+			break;
 		case 'q':
 			qflag = 1;
 			break;
@@ -406,6 +431,17 @@ readv_f(int argc, char **argv)
 		return 0;
 	}
 
+	if (Pflag) {
+		void* cmp_buf = malloc(count);
+		memset(cmp_buf, pattern, count);
+		if (memcmp(buf, cmp_buf, count)) {
+			printf("Pattern verification failed at offset %lld, "
+				"%d bytes\n",
+				(long long) offset, count);
+		}
+		free(cmp_buf);
+	}
+
 	if (qflag)
 		return 0;
 
@@ -426,7 +462,7 @@ static const cmdinfo_t readv_cmd = {
 	.cfunc		= readv_f,
 	.argmin		= 2,
 	.argmax		= -1,
-	.args		= "[-Cqv] off len [len..]",
+	.args		= "[-Cqv] [-P pattern ] off len [len..]",
 	.oneline	= "reads a number of bytes at a specified offset",
 	.help		= readv_help,
 };
-- 
1.6.0.6

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] qemu-io: Verify read data by patterns
  2009-04-14  9:17 [Qemu-devel] [PATCH v2] qemu-io: Verify read data by patterns Kevin Wolf
@ 2009-04-14 10:52 ` Christoph Hellwig
  2009-04-18 15:40 ` [Qemu-devel] " Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2009-04-14 10:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, hch

On Tue, Apr 14, 2009 at 11:17:06AM +0200, Kevin Wolf wrote:
> This patch adds a -P option to read and readv which allows to compare the read
> data to a given pattern. This can be used to verify data written by write -P.

Looks good to me.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] Re: [PATCH v2] qemu-io: Verify read data by patterns
  2009-04-14  9:17 [Qemu-devel] [PATCH v2] qemu-io: Verify read data by patterns Kevin Wolf
  2009-04-14 10:52 ` Christoph Hellwig
@ 2009-04-18 15:40 ` Anthony Liguori
  1 sibling, 0 replies; 3+ messages in thread
From: Anthony Liguori @ 2009-04-18 15:40 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel, hch

Kevin Wolf wrote:
> This patch adds a -P option to read and readv which allows to compare the read
> data to a given pattern. This can be used to verify data written by write -P.
>
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
>   

Applied.  Thanks.

-- 
Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-04-18 15:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-14  9:17 [Qemu-devel] [PATCH v2] qemu-io: Verify read data by patterns Kevin Wolf
2009-04-14 10:52 ` Christoph Hellwig
2009-04-18 15:40 ` [Qemu-devel] " Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).