Skip to contentSkip to conversation

qemu-io: Fix handling of bdrv_is_allocated() return value

PATCH Superseded Kevin Wolf 2 participants 4 messages Apr 9, 2009

lore
Share & tools
lore

Kevin Wolf

author
#0 lore raw

PATCH 1/1 qemu-io: Fix handling of bdrv_is_allocated() return value

bdrv_is_allocated() returns a boolean which indicates if the offset is allocated, not 0 on success and everything else is an error.

---
 qemu-io.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
qemu-io.c +5 -7
index 466d22c..3e5c444 100644
@@ -794,6 +794,7 @@ alloc_f(int argc, char **argv)
 	char s1[64];
 	int num;
 	int ret;
+	const char *retstr;
 
 	offset = cvtnum(argv[1]);
 	if (offset & 0x1ff) {
@@ -808,18 +809,15 @@ alloc_f(int argc, char **argv)
 		nb_sectors = 1;
 
 	ret = bdrv_is_allocated(bs, offset >> 9, nb_sectors, &num);
-	if (ret) {
-		printf("is_allocated: %s", strerror(ret));
-		return 0;
-	}
 
 	cvtstr(offset, s1, sizeof(s1));
 
+	retstr = ret ? "allocated" : "not allocated";
 	if (nb_sectors == 1)
-		printf("sector allocated at offset %s\n", s1);
+		printf("sector %s at offset %s\n", retstr, s1);
 	else
-		printf("%d/%d sectors allocated at offset %s\n",
-			num, nb_sectors, s1);
+		printf("%d/%d sectors %s at offset %s\n",
+			num, nb_sectors, retstr, s1);
 	return 0;
 }
 
Signature · 1 line
1.6.0.6
#1 lore raw
Quoted 2 lines · Kevin Wolf

bdrv_is_allocated() returns a boolean which indicates if the offset is allocated, not 0 on success and everything else is an error.

Yeah, the handling wa wrong before. But a return value of 0 and *pnum = 0 seems to be a special error-ish value still which we might want to handle.

author
#2 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Kevin Wolf

bdrv_is_allocated() returns a boolean which indicates if the offset is allocated, not 0 on success and everything else is an error.

Yeah, the handling wa wrong before. But a return value of 0 and *pnum = 0 seems to be a special error-ish value still which we might want to handle.

The header comment of bdrv_is_allocated() doesn't specify error conditions. ;-)

You seem to be right that there is one place in block.c where *pnum = 0 is used as something like an error return value. This isn't consistent though, qcow and vmdk return non-zero values in *pnum under the same conditions.

Maybe another patch to change that and bring the error message back again on *pnum == 0?

Kevin

#3 lore raw
Quoted 2 lines · Kevin Wolf

Maybe another patch to change that and bring the error message back again on *pnum == 0?

Ok, let's put this one in first.

As for dealing with errors, maybe we should change it to allow it to return a negative error message for errors?