From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [6702] block: Polish error handling of brdv_open2 (Jan Kiszka)
Date: Thu, 05 Mar 2009 23:00:38 +0000 [thread overview]
Message-ID: <E1LfMYQ-0000XM-Cy@cvs.savannah.gnu.org> (raw)
Revision: 6702
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6702
Author: aliguori
Date: 2009-03-05 23:00:29 +0000 (Thu, 05 Mar 2009)
Log Message:
-----------
block: Polish error handling of brdv_open2 (Jan Kiszka)
Make sure that we always delete temporary disk images on error, remove
obsolete malloc error checks and return proper error codes.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Modified Paths:
--------------
trunk/block.c
Modified: trunk/block.c
===================================================================
--- trunk/block.c 2009-03-05 23:00:02 UTC (rev 6701)
+++ trunk/block.c 2009-03-05 23:00:29 UTC (rev 6702)
@@ -311,8 +311,6 @@
int ret;
bs = bdrv_new("");
- if (!bs)
- return -ENOMEM;
ret = bdrv_open2(bs, filename, flags | BDRV_O_FILE, NULL);
if (ret < 0) {
bdrv_delete(bs);
@@ -349,12 +347,10 @@
/* if there is a backing file, use it */
bs1 = bdrv_new("");
- if (!bs1) {
- return -ENOMEM;
- }
- if (bdrv_open(bs1, filename, 0) < 0) {
+ ret = bdrv_open(bs1, filename, 0);
+ if (ret < 0) {
bdrv_delete(bs1);
- return -1;
+ return ret;
}
total_size = bdrv_getlength(bs1) >> SECTOR_BITS;
@@ -372,9 +368,10 @@
else
realpath(filename, backing_filename);
- if (bdrv_create(&bdrv_qcow2, tmp_filename,
- total_size, backing_filename, 0) < 0) {
- return -1;
+ ret = bdrv_create(&bdrv_qcow2, tmp_filename,
+ total_size, backing_filename, 0);
+ if (ret < 0) {
+ return ret;
}
filename = tmp_filename;
bs->is_temporary = 1;
@@ -383,15 +380,13 @@
pstrcpy(bs->filename, sizeof(bs->filename), filename);
if (flags & BDRV_O_FILE) {
drv = find_protocol(filename);
- if (!drv)
- return -ENOENT;
- } else {
- if (!drv) {
- drv = find_image_format(filename);
- if (!drv)
- return -1;
- }
+ } else if (!drv) {
+ drv = find_image_format(filename);
}
+ if (!drv) {
+ ret = -ENOENT;
+ goto unlink_and_fail;
+ }
bs->drv = drv;
bs->opaque = qemu_mallocz(drv->instance_size);
/* Note: for compatibility, we open disk image files as RDWR, and
@@ -409,6 +404,9 @@
qemu_free(bs->opaque);
bs->opaque = NULL;
bs->drv = NULL;
+ unlink_and_fail:
+ if (bs->is_temporary)
+ unlink(filename);
return ret;
}
if (drv->bdrv_getlength) {
@@ -422,15 +420,13 @@
if (bs->backing_file[0] != '\0') {
/* if there is a backing file, use it */
bs->backing_hd = bdrv_new("");
- if (!bs->backing_hd) {
- fail:
- bdrv_close(bs);
- return -ENOMEM;
- }
path_combine(backing_filename, sizeof(backing_filename),
filename, bs->backing_file);
- if (bdrv_open(bs->backing_hd, backing_filename, open_flags) < 0)
- goto fail;
+ ret = bdrv_open(bs->backing_hd, backing_filename, open_flags);
+ if (ret < 0) {
+ bdrv_close(bs);
+ return ret;
+ }
}
/* call the change callback */
reply other threads:[~2009-03-05 23:00 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=E1LfMYQ-0000XM-Cy@cvs.savannah.gnu.org \
--to=anthony@codemonkey.ws \
--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 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.