qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>
Subject: [Qemu-devel] [PATCH] qemu-io: Optionally verify only part of read data
Date: Thu, 23 Apr 2009 15:11:13 +0200	[thread overview]
Message-ID: <1240492273-27946-1-git-send-email-kwolf@redhat.com> (raw)

There are reasonable test cases where a read must span areas that are not
uniformly filled with one pattern but contains several parts. This makes -P
useless for them currently.

Introducing additional options which determine the part of the read data that
should be verified with the given pattern allows to check such reads.

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

diff --git a/qemu-io.c b/qemu-io.c
index 405b6c5..60464e6 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -191,11 +191,13 @@ read_help(void)
 "\n"
 " Reads a segment of the currently open file, optionally dumping it to the\n"
 " standard output stream (with -v option) for subsequent inspection.\n"
+" -C, -- report statistics in a machine parsable format\n"
+" -l, -- length for pattern verification (only with -P)\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"
+" -s, -- start offset for pattern verification (only with -P)\n"
+" -v, -- dump buffer to standard output\n"
 "\n");
 }
 
@@ -204,18 +206,26 @@ read_f(int argc, char **argv)
 {
 	struct timeval t1, t2;
 	int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
+	int Pflag = 0, sflag = 0, lflag = 0;
 	int c, cnt;
 	char *buf;
 	int64_t offset;
 	int count, total;
-	int pattern = 0;
-	int Pflag = 0;
+	int pattern = 0, pattern_offset = 0, pattern_count = 0;
 
-	while ((c = getopt(argc, argv, "CpP:qv")) != EOF) {
+	while ((c = getopt(argc, argv, "Cl:pP:qs:v")) != EOF) {
 		switch (c) {
 		case 'C':
 			Cflag = 1;
 			break;
+		case 'l':
+			lflag = 1;
+			pattern_count = cvtnum(optarg);
+			if (pattern_count < 0) {
+				printf("non-numeric length argument -- %s\n", optarg);
+				return 0;
+			}
+			break;
 		case 'p':
 			pflag = 1;
 			break;
@@ -226,6 +236,14 @@ read_f(int argc, char **argv)
 		case 'q':
 			qflag = 1;
 			break;
+		case 's':
+			sflag = 1;
+			pattern_offset = cvtnum(optarg);
+			if (pattern_offset < 0) {
+				printf("non-numeric length argument -- %s\n", optarg);
+				return 0;
+			}
+			break;
 		case 'v':
 			vflag = 1;
 			break;
@@ -250,6 +268,19 @@ read_f(int argc, char **argv)
 		return 0;
 	}
 
+    if (!Pflag && (lflag || sflag)) {
+        return command_usage(&read_cmd);
+    }
+
+    if (!lflag) {
+        pattern_count = count - pattern_offset;
+    }
+
+    if ((pattern_count < 0) || (pattern_count + pattern_offset > count))  {
+        printf("pattern verfication range exceeds end of read data\n");
+        return 0;
+    }
+
 	if (!pflag)
 		if (offset & 0x1ff) {
 			printf("offset %lld is not sector aligned\n",
@@ -278,12 +309,12 @@ read_f(int argc, char **argv)
 	}
 
 	if (Pflag) {
-		void* cmp_buf = malloc(count);
-		memset(cmp_buf, pattern, count);
-		if (memcmp(buf, cmp_buf, count)) {
+		void* cmp_buf = malloc(pattern_count);
+		memset(cmp_buf, pattern, pattern_count);
+		if (memcmp(buf + pattern_offset, cmp_buf, pattern_count)) {
 			printf("Pattern verification failed at offset %lld, "
 				"%d bytes\n",
-				(long long) offset, count);
+				(long long) offset + pattern_offset, pattern_count);
 		}
 		free(cmp_buf);
 	}
@@ -309,7 +340,7 @@ static const cmdinfo_t read_cmd = {
 	.cfunc		= read_f,
 	.argmin		= 2,
 	.argmax		= -1,
-	.args		= "[-aCpqv] [-P pattern ] off len",
+	.args		= "[-aCpqv] [-P pattern [-s off] [-l len]] off len",
 	.oneline	= "reads a number of bytes at a specified offset",
 	.help		= read_help,
 };
-- 
1.6.0.6

                 reply	other threads:[~2009-04-23 13:12 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1240492273-27946-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).