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>, hch@lst.de
Subject: [Qemu-devel] [PATCH] qemu-io: Implement bdrv_get_buffer/bdrv_put_buffer
Date: Tue,  7 Jul 2009 12:57:47 +0200	[thread overview]
Message-ID: <1246964267-6923-1-git-send-email-kwolf@redhat.com> (raw)

The get_buffer and put_buffer functions are implemented as a variation of the
normal read/write operation, enabled by the -b option. This is the same
mechanism as is used to switch from read/write to pread/pwrite.

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

diff --git a/qemu-io.c b/qemu-io.c
index 566ca79..a8d55fe 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -136,6 +136,22 @@ static int do_pwrite(char *buf, int64_t offset, int count, int *total)
 	return 1;
 }
 
+static int do_get_buffer(char *buf, int64_t offset, int count, int *total)
+{
+	*total = bdrv_get_buffer(bs, (uint8_t *)buf, offset, count);
+	if (*total < 0)
+		return *total;
+	return 1;
+}
+
+static int do_put_buffer(char *buf, int64_t offset, int count, int *total)
+{
+	*total = bdrv_put_buffer(bs, (uint8_t *)buf, offset, count);
+	if (*total < 0)
+		return *total;
+	return 1;
+}
+
 #define NOT_DONE 0x7fffffff
 static void aio_rw_done(void *opaque, int ret)
 {
@@ -191,6 +207,7 @@ 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"
+" -b, -- use bdrv_get_buffer to read the file\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"
@@ -206,7 +223,7 @@ 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 Pflag = 0, sflag = 0, lflag = 0, bflag = 0;
 	int c, cnt;
 	char *buf;
 	int64_t offset;
@@ -215,8 +232,11 @@ read_f(int argc, char **argv)
         int total = 0;
 	int pattern = 0, pattern_offset = 0, pattern_count = 0;
 
-	while ((c = getopt(argc, argv, "Cl:pP:qs:v")) != EOF) {
+	while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {
 		switch (c) {
+		case 'b':
+			bflag = 1;
+			break;
 		case 'C':
 			Cflag = 1;
 			break;
@@ -257,6 +277,11 @@ read_f(int argc, char **argv)
 	if (optind != argc - 2)
 		return command_usage(&read_cmd);
 
+	if (bflag && pflag) {
+		printf("-b and -p cannot be specified at the same time\n");
+		return 0;
+	}
+
 	offset = cvtnum(argv[optind]);
 	if (offset < 0) {
 		printf("non-numeric length argument -- %s\n", argv[optind]);
@@ -301,6 +326,8 @@ read_f(int argc, char **argv)
 	gettimeofday(&t1, NULL);
 	if (pflag)
 		cnt = do_pread(buf, offset, count, &total);
+	else if (bflag)
+		cnt = do_get_buffer(buf, offset, count, &total);
 	else
 		cnt = do_read(buf, offset, count, &total);
 	gettimeofday(&t2, NULL);
@@ -342,7 +369,7 @@ static const cmdinfo_t read_cmd = {
 	.cfunc		= read_f,
 	.argmin		= 2,
 	.argmax		= -1,
-	.args		= "[-aCpqv] [-P pattern [-s off] [-l len]] off len",
+	.args		= "[-abCpqv] [-P pattern [-s off] [-l len]] off len",
 	.oneline	= "reads a number of bytes at a specified offset",
 	.help		= read_help,
 };
@@ -514,6 +541,7 @@ write_help(void)
 "\n"
 " Writes into a segment of the currently open file, using a buffer\n"
 " filled with a set pattern (0xcdcdcdcd).\n"
+" -b, -- use bdrv_put_buffer to write the file\n"
 " -p, -- use bdrv_pwrite to write the file\n"
 " -P, -- use different pattern to fill file\n"
 " -C, -- report statistics in a machine parsable format\n"
@@ -525,7 +553,7 @@ static int
 write_f(int argc, char **argv)
 {
 	struct timeval t1, t2;
-	int Cflag = 0, pflag = 0, qflag = 0;
+	int Cflag = 0, pflag = 0, qflag = 0, bflag = 0;
 	int c, cnt;
 	char *buf;
 	int64_t offset;
@@ -534,8 +562,11 @@ write_f(int argc, char **argv)
         int total = 0;
 	int pattern = 0xcd;
 
-	while ((c = getopt(argc, argv, "CpP:q")) != EOF) {
+	while ((c = getopt(argc, argv, "bCpP:q")) != EOF) {
 		switch (c) {
+		case 'b':
+			bflag = 1;
+			break;
 		case 'C':
 			Cflag = 1;
 			break;
@@ -556,6 +587,11 @@ write_f(int argc, char **argv)
 	if (optind != argc - 2)
 		return command_usage(&write_cmd);
 
+	if (bflag && pflag) {
+		printf("-b and -p cannot be specified at the same time\n");
+		return 0;
+	}
+
 	offset = cvtnum(argv[optind]);
 	if (offset < 0) {
 		printf("non-numeric length argument -- %s\n", argv[optind]);
@@ -588,6 +624,8 @@ write_f(int argc, char **argv)
 	gettimeofday(&t1, NULL);
 	if (pflag)
 		cnt = do_pwrite(buf, offset, count, &total);
+	else if (bflag)
+		cnt = do_put_buffer(buf, offset, count, &total);
 	else
 		cnt = do_write(buf, offset, count, &total);
 	gettimeofday(&t2, NULL);
@@ -615,7 +653,7 @@ static const cmdinfo_t write_cmd = {
 	.cfunc		= write_f,
 	.argmin		= 2,
 	.argmax		= -1,
-	.args		= "[-aCpq] [-P pattern ] off len",
+	.args		= "[-abCpq] [-P pattern ] off len",
 	.oneline	= "writes a number of bytes at a specified offset",
 	.help		= write_help,
 };
-- 
1.6.0.6

             reply	other threads:[~2009-07-07 10:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-07 10:57 Kevin Wolf [this message]
2009-07-07 17:34 ` [Qemu-devel] [PATCH] qemu-io: Implement bdrv_get_buffer/bdrv_put_buffer Christoph Hellwig

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=1246964267-6923-1-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=hch@lst.de \
    --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).