提交 6f712ee0 编写于 作者: E Eric Blake 提交者: Kevin Wolf

vvfat: React to bdrv_is_allocated() errors

If bdrv_is_allocated() fails, we should react to that failure.
For 2 of the 3 callers, reporting the error was easy.  But in
cluster_was_modified() and its lone caller
get_cluster_count_for_direntry(), it's rather invasive to update
the logic to pass the error back; so there, I went with merely
documenting the issue by changing the return type to bool (in
all likelihood, treating the cluster as modified will then
trigger a read which will also fail, and eventually get to an
error - but given the appalling number of abort() calls in this
code, I'm not making it any worse).
Signed-off-by: NEric Blake <eblake@redhat.com>
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
上级 666a9543
...@@ -1394,7 +1394,13 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num, ...@@ -1394,7 +1394,13 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
return -1; return -1;
if (s->qcow) { if (s->qcow) {
int n; int n;
if (bdrv_is_allocated(s->qcow->bs, sector_num, nb_sectors-i, &n)) { int ret;
ret = bdrv_is_allocated(s->qcow->bs, sector_num,
nb_sectors - i, &n);
if (ret < 0) {
return ret;
}
if (ret) {
DLOG(fprintf(stderr, "sectors %d+%d allocated\n", DLOG(fprintf(stderr, "sectors %d+%d allocated\n",
(int)sector_num, n)); (int)sector_num, n));
if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, n)) { if (bdrv_read(s->qcow, sector_num, buf + i * 0x200, n)) {
...@@ -1668,7 +1674,8 @@ static inline uint32_t modified_fat_get(BDRVVVFATState* s, ...@@ -1668,7 +1674,8 @@ static inline uint32_t modified_fat_get(BDRVVVFATState* s,
} }
} }
static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num) static inline bool cluster_was_modified(BDRVVVFATState *s,
uint32_t cluster_num)
{ {
int was_modified = 0; int was_modified = 0;
int i, dummy; int i, dummy;
...@@ -1683,7 +1690,13 @@ static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num) ...@@ -1683,7 +1690,13 @@ static inline int cluster_was_modified(BDRVVVFATState* s, uint32_t cluster_num)
1, &dummy); 1, &dummy);
} }
return was_modified; /*
* Note that this treats failures to learn allocation status the
* same as if an allocation has occurred. It's as safe as
* anything else, given that a failure to learn allocation status
* will probably result in more failures.
*/
return !!was_modified;
} }
static const char* get_basename(const char* path) static const char* get_basename(const char* path)
...@@ -1833,6 +1846,9 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, ...@@ -1833,6 +1846,9 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
int res; int res;
res = bdrv_is_allocated(s->qcow->bs, offset + i, 1, &dummy); res = bdrv_is_allocated(s->qcow->bs, offset + i, 1, &dummy);
if (res < 0) {
return -1;
}
if (!res) { if (!res) {
res = vvfat_read(s->bs, offset, s->cluster_buffer, 1); res = vvfat_read(s->bs, offset, s->cluster_buffer, 1);
if (res) { if (res) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册