提交 32b8bb3b 编写于 作者: S Stefan Weil 提交者: Anthony Liguori

block: Use error codes from lower levels for error message

"No such file or directory" is a misleading error message
when a user tries to open a file with wrong permissions.

Cc: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: NStefan Weil <weil@mail.berlios.de>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
(cherry picked from commit c98ac35d)
Signed-off-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 cc12b5c7
...@@ -330,7 +330,7 @@ BlockDriver *bdrv_find_protocol(const char *filename) ...@@ -330,7 +330,7 @@ BlockDriver *bdrv_find_protocol(const char *filename)
return NULL; return NULL;
} }
static BlockDriver *find_image_format(const char *filename) static int find_image_format(const char *filename, BlockDriver **pdrv)
{ {
int ret, score, score_max; int ret, score, score_max;
BlockDriver *drv1, *drv; BlockDriver *drv1, *drv;
...@@ -338,19 +338,27 @@ static BlockDriver *find_image_format(const char *filename) ...@@ -338,19 +338,27 @@ static BlockDriver *find_image_format(const char *filename)
BlockDriverState *bs; BlockDriverState *bs;
ret = bdrv_file_open(&bs, filename, 0); ret = bdrv_file_open(&bs, filename, 0);
if (ret < 0) if (ret < 0) {
return NULL; *pdrv = NULL;
return ret;
}
/* Return the raw BlockDriver * to scsi-generic devices or empty drives */ /* Return the raw BlockDriver * to scsi-generic devices or empty drives */
if (bs->sg || !bdrv_is_inserted(bs)) { if (bs->sg || !bdrv_is_inserted(bs)) {
bdrv_delete(bs); bdrv_delete(bs);
return bdrv_find_format("raw"); drv = bdrv_find_format("raw");
if (!drv) {
ret = -ENOENT;
}
*pdrv = drv;
return ret;
} }
ret = bdrv_pread(bs, 0, buf, sizeof(buf)); ret = bdrv_pread(bs, 0, buf, sizeof(buf));
bdrv_delete(bs); bdrv_delete(bs);
if (ret < 0) { if (ret < 0) {
return NULL; *pdrv = NULL;
return ret;
} }
score_max = 0; score_max = 0;
...@@ -364,7 +372,11 @@ static BlockDriver *find_image_format(const char *filename) ...@@ -364,7 +372,11 @@ static BlockDriver *find_image_format(const char *filename)
} }
} }
} }
return drv; if (!drv) {
ret = -ENOENT;
}
*pdrv = drv;
return ret;
} }
/** /**
...@@ -571,12 +583,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, ...@@ -571,12 +583,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,
/* Find the right image format driver */ /* Find the right image format driver */
if (!drv) { if (!drv) {
drv = find_image_format(filename); ret = find_image_format(filename, &drv);
probed = 1; probed = 1;
} }
if (!drv) { if (!drv) {
ret = -ENOENT;
goto unlink_and_fail; goto unlink_and_fail;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册