[Sheepdog] [PATCH 2/5] collie vdi read: make offset and length arguments optional

Chris Webb chris at arachsys.com
Sat Aug 13 12:56:19 CEST 2011


Usage:
  collie vdi read <vdiname> [<offset> [<len>]] [-s snapshot] [-a address] [-p port] [-h]

If <len> is not specified, we read from <offset> to the end of the vdi.
If <offset> is also not specified, we read the entire vdi.

Signed-off-by: Chris Webb <chris at arachsys.com>
---
 collie/vdi.c |   27 +++++++++++----------------
 1 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index e6c32fc..204e13a 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -970,25 +970,20 @@ static int vdi_read(int argc, char **argv)
 	uint32_t vid;
 	int ret, idx;
 	struct sheepdog_inode *inode = NULL;
-	uint64_t offset, oid, done = 0, total;
+	uint64_t offset = 0, oid, done = 0, total = (uint64_t) -1;
 	unsigned int len;
 	char *buf = NULL;
 
-	if (!argv[optind]) {
-		fprintf(stderr, "please specify a start offset\n");
-		return EXIT_USAGE;
-	}
-	ret = parse_option_size(argv[optind++], &offset);
-	if (ret < 0)
-		return EXIT_USAGE;
-
-	if (!argv[optind]) {
-		fprintf(stderr, "please specify a length to read\n");
-		return EXIT_USAGE;
+	if (argv[optind]) {
+		ret = parse_option_size(argv[optind++], &offset);
+		if (ret < 0)
+			return EXIT_USAGE;
+		if (argv[optind]) {
+			ret = parse_option_size(argv[optind++], &total);
+			if (ret < 0)
+				return EXIT_USAGE;
+		}
 	}
-	ret = parse_option_size(argv[optind], &total);
-	if (ret < 0)
-		return EXIT_USAGE;
 
 	inode = malloc(sizeof(*inode));
 	buf = malloc(SD_DATA_OBJ_SIZE);
@@ -1183,7 +1178,7 @@ static struct subcommand vdi_cmd[] = {
 	 SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_getattr},
 	{"resize", "<vdiname> <new size>", "aph", "resize a image",
 	 SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_resize},
-	{"read", "<vdiname> <offset> <len>", "saph", "read data from a image",
+	{"read", "<vdiname> [<offset> [<len>]]", "saph", "read data from a image",
 	 SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_read},
 	{"write", "<vdiname> <offset> <len>", "aph", "write data to a image",
 	 SUBCMD_FLAG_NEED_NODELIST|SUBCMD_FLAG_NEED_THIRD_ARG, vdi_write},
-- 
1.7.5.4




More information about the sheepdog mailing list