diff options
author | Avi Kivity <avi@redhat.com> | 2009-12-07 11:04:32 +0200 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2009-12-07 11:04:32 +0200 |
commit | 149d76049af52aa76f4665b6bc9bdbd5904a8588 (patch) | |
tree | e07c6dfe28f03438dff9bb07240a7534c010f990 /block | |
parent | Merge commit 'e9b2e81889d9877415710484b876ee57a42b0bcb' into upstream-merge (diff) | |
parent | Don't leak file descriptors (diff) | |
download | qemu-kvm-149d76049af52aa76f4665b6bc9bdbd5904a8588.tar.gz qemu-kvm-149d76049af52aa76f4665b6bc9bdbd5904a8588.tar.bz2 qemu-kvm-149d76049af52aa76f4665b6bc9bdbd5904a8588.zip |
Merge commit '40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4' into upstream-merge
* commit '40ff6d7e8dceca227e7f8a3e8e0d58b2c66d19b4':
Don't leak file descriptors
qemu-img: There is more than one host device driver
qcow2: Fix some more qemu_malloc fallout
qcow2: Store exact backing format length
virtio-blk: Implement rerror option
ide: Implement rerror option
Conflicts:
posix-aio-compat.c
Extended qemu_set_cloexec() to compatfd.c.
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'block')
-rw-r--r-- | block/qcow2-refcount.c | 22 | ||||
-rw-r--r-- | block/qcow2-snapshot.c | 7 | ||||
-rw-r--r-- | block/qcow2.c | 16 | ||||
-rw-r--r-- | block/raw-posix.c | 6 |
4 files changed, 35 insertions, 16 deletions
diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 30266786d..54b19f86d 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -513,7 +513,11 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, l1_size2 = l1_size * sizeof(uint64_t); l1_allocated = 0; if (l1_table_offset != s->l1_table_offset) { - l1_table = qemu_mallocz(align_offset(l1_size2, 512)); + if (l1_size2 != 0) { + l1_table = qemu_mallocz(align_offset(l1_size2, 512)); + } else { + l1_table = NULL; + } l1_allocated = 1; if (bdrv_pread(s->hd, l1_table_offset, l1_table, l1_size2) != l1_size2) @@ -769,12 +773,16 @@ static int check_refcounts_l1(BlockDriverState *bs, l1_table_offset, l1_size2); /* Read L1 table entries from disk */ - l1_table = qemu_malloc(l1_size2); - if (bdrv_pread(s->hd, l1_table_offset, - l1_table, l1_size2) != l1_size2) - goto fail; - for(i = 0;i < l1_size; i++) - be64_to_cpus(&l1_table[i]); + if (l1_size2 == 0) { + l1_table = NULL; + } else { + l1_table = qemu_malloc(l1_size2); + if (bdrv_pread(s->hd, l1_table_offset, + l1_table, l1_size2) != l1_size2) + goto fail; + for(i = 0;i < l1_size; i++) + be64_to_cpus(&l1_table[i]); + } /* Do the actual checks */ for(i = 0; i < l1_size; i++) { diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 94cb83806..d63c7e17d 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -266,7 +266,12 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info) sn->l1_table_offset = qcow2_alloc_clusters(bs, s->l1_size * sizeof(uint64_t)); sn->l1_size = s->l1_size; - l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + if (s->l1_size != 0) { + l1_table = qemu_malloc(s->l1_size * sizeof(uint64_t)); + } else { + l1_table = NULL; + } + for(i = 0; i < s->l1_size; i++) { l1_table[i] = cpu_to_be64(s->l1_table[i]); } diff --git a/block/qcow2.c b/block/qcow2.c index 3954cf139..984264b3e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -124,12 +124,12 @@ static int qcow_read_extensions(BlockDriverState *bs, uint64_t start_offset, #ifdef DEBUG_EXT printf("Qcow2: Got format extension %s\n", bs->backing_format); #endif - offset += ((ext.len + 7) & ~7); + offset = ((offset + ext.len + 7) & ~7); break; default: /* unknown magic -- just skip it */ - offset += ((ext.len + 7) & ~7); + offset = ((offset + ext.len + 7) & ~7); break; } } @@ -738,6 +738,7 @@ static int qcow_create2(const char *filename, int64_t total_size, int fd, header_size, backing_filename_len, l1_size, i, shift, l2_bits; int ref_clusters, backing_format_len = 0; + int rounded_ext_bf_len = 0; QCowHeader header; uint64_t tmp, offset; QCowCreateState s1, *s = &s1; @@ -759,8 +760,9 @@ static int qcow_create2(const char *filename, int64_t total_size, if (backing_format) { ext_bf.magic = QCOW_EXT_MAGIC_BACKING_FORMAT; backing_format_len = strlen(backing_format); - ext_bf.len = (backing_format_len + 7) & ~7; - header_size += ((sizeof(ext_bf) + ext_bf.len + 7) & ~7); + ext_bf.len = backing_format_len; + rounded_ext_bf_len = (sizeof(ext_bf) + ext_bf.len + 7) & ~7; + header_size += rounded_ext_bf_len; } header.backing_file_offset = cpu_to_be64(header_size); backing_filename_len = strlen(backing_file); @@ -828,15 +830,15 @@ static int qcow_create2(const char *filename, int64_t total_size, if (backing_file) { if (backing_format_len) { char zero[16]; - int d = ext_bf.len - backing_format_len; + int padding = rounded_ext_bf_len - (ext_bf.len + sizeof(ext_bf)); memset(zero, 0, sizeof(zero)); cpu_to_be32s(&ext_bf.magic); cpu_to_be32s(&ext_bf.len); write(fd, &ext_bf, sizeof(ext_bf)); write(fd, backing_format, backing_format_len); - if (d>0) { - write(fd, zero, d); + if (padding > 0) { + write(fd, zero, padding); } } write(fd, backing_file, backing_filename_len); diff --git a/block/raw-posix.c b/block/raw-posix.c index 7446ca931..6dcc65189 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -155,7 +155,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, s->open_flags |= O_DSYNC; s->fd = -1; - fd = open(filename, s->open_flags, 0644); + fd = qemu_open(filename, s->open_flags, 0644); if (fd < 0) { ret = -errno; if (ret == -EROFS) @@ -1016,6 +1016,7 @@ static BlockDriver bdrv_host_device = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1112,6 +1113,7 @@ static BlockDriver bdrv_host_floppy = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1194,6 +1196,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, @@ -1315,6 +1318,7 @@ static BlockDriver bdrv_host_cdrom = { .bdrv_close = raw_close, .bdrv_create = hdev_create, .create_options = raw_create_options, + .no_zero_init = 1, .bdrv_flush = raw_flush, .bdrv_aio_readv = raw_aio_readv, |