All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value
@ 2009-04-09 13:05 Kevin Wolf
  2009-04-09 13:26 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2009-04-09 13:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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.

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

diff --git a/qemu-io.c b/qemu-io.c
index 466d22c..3e5c444 100644
--- a/qemu-io.c
+++ b/qemu-io.c
@@ -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;
 }
 
-- 
1.6.0.6

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

* Re: [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value
  2009-04-09 13:05 [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value Kevin Wolf
@ 2009-04-09 13:26 ` Christoph Hellwig
  2009-04-09 13:42   ` Kevin Wolf
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2009-04-09 13:26 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf

On Thu, Apr 09, 2009 at 03:05:27PM +0200, Kevin Wolf wrote:
> 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.

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

* Re: [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value
  2009-04-09 13:26 ` Christoph Hellwig
@ 2009-04-09 13:42   ` Kevin Wolf
  2009-04-09 15:28     ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Kevin Wolf @ 2009-04-09 13:42 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: qemu-devel

Christoph Hellwig schrieb:
> On Thu, Apr 09, 2009 at 03:05:27PM +0200, Kevin Wolf wrote:
>> 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

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

* Re: [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value
  2009-04-09 13:42   ` Kevin Wolf
@ 2009-04-09 15:28     ` Christoph Hellwig
  0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2009-04-09 15:28 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: Christoph Hellwig, qemu-devel

On Thu, Apr 09, 2009 at 03:42:22PM +0200, Kevin Wolf wrote:
> 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?

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

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

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-09 13:05 [Qemu-devel] [PATCH] qemu-io: Fix handling of bdrv_is_allocated() return value Kevin Wolf
2009-04-09 13:26 ` Christoph Hellwig
2009-04-09 13:42   ` Kevin Wolf
2009-04-09 15:28     ` Christoph Hellwig

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.