Skip to content

Commit

Permalink
block: Convert close calls to qemu_close
Browse files Browse the repository at this point in the history
This patch converts all block layer close calls, that correspond
to qemu_open calls, to qemu_close.

Signed-off-by: Corey Bryant <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
Corey Bryant authored and kevmw committed Aug 15, 2012
1 parent 6165f4d commit 2e1e79d
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
24 changes: 12 additions & 12 deletions block/raw-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ static int raw_open_common(BlockDriverState *bs, const char *filename,
out_free_buf:
qemu_vfree(s->aligned_buf);
out_close:
close(fd);
qemu_close(fd);
return -errno;
}

Expand Down Expand Up @@ -376,7 +376,7 @@ static void raw_close(BlockDriverState *bs)
{
BDRVRawState *s = bs->opaque;
if (s->fd >= 0) {
close(s->fd);
qemu_close(s->fd);
s->fd = -1;
if (s->aligned_buf != NULL)
qemu_vfree(s->aligned_buf);
Expand Down Expand Up @@ -580,7 +580,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
if (ftruncate(fd, total_size * BDRV_SECTOR_SIZE) != 0) {
result = -errno;
}
if (close(fd) != 0) {
if (qemu_close(fd) != 0) {
result = -errno;
}
}
Expand Down Expand Up @@ -850,7 +850,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
if (fd < 0) {
bsdPath[strlen(bsdPath)-1] = '1';
} else {
close(fd);
qemu_close(fd);
}
filename = bsdPath;
}
Expand Down Expand Up @@ -889,7 +889,7 @@ static int fd_open(BlockDriverState *bs)
last_media_present = (s->fd >= 0);
if (s->fd >= 0 &&
(get_clock() - s->fd_open_time) >= FD_OPEN_TIMEOUT) {
close(s->fd);
qemu_close(s->fd);
s->fd = -1;
#ifdef DEBUG_FLOPPY
printf("Floppy closed\n");
Expand Down Expand Up @@ -988,7 +988,7 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
else if (lseek(fd, 0, SEEK_END) < total_size * BDRV_SECTOR_SIZE)
ret = -ENOSPC;

close(fd);
qemu_close(fd);
return ret;
}

Expand Down Expand Up @@ -1038,7 +1038,7 @@ static int floppy_open(BlockDriverState *bs, const char *filename, int flags)
return ret;

/* close fd so that we can reopen it as needed */
close(s->fd);
qemu_close(s->fd);
s->fd = -1;
s->fd_media_changed = 1;

Expand Down Expand Up @@ -1072,7 +1072,7 @@ static int floppy_probe_device(const char *filename)
prio = 100;

outc:
close(fd);
qemu_close(fd);
out:
return prio;
}
Expand Down Expand Up @@ -1107,14 +1107,14 @@ static void floppy_eject(BlockDriverState *bs, bool eject_flag)
int fd;

if (s->fd >= 0) {
close(s->fd);
qemu_close(s->fd);
s->fd = -1;
}
fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK);
if (fd >= 0) {
if (ioctl(fd, FDEJECT, 0) < 0)
perror("FDEJECT");
close(fd);
qemu_close(fd);
}
}

Expand Down Expand Up @@ -1175,7 +1175,7 @@ static int cdrom_probe_device(const char *filename)
prio = 100;

outc:
close(fd);
qemu_close(fd);
out:
return prio;
}
Expand Down Expand Up @@ -1283,7 +1283,7 @@ static int cdrom_reopen(BlockDriverState *bs)
* FreeBSD seems to not notice sometimes...
*/
if (s->fd >= 0)
close(s->fd);
qemu_close(s->fd);
fd = qemu_open(bs->filename, s->open_flags, 0644);
if (fd < 0) {
s->fd = -1;
Expand Down
2 changes: 1 addition & 1 deletion block/raw-win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
return -EIO;
set_sparse(fd);
ftruncate(fd, total_size * 512);
close(fd);
qemu_close(fd);
return 0;
}

Expand Down
4 changes: 2 additions & 2 deletions block/vmdk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,

ret = 0;
exit:
close(fd);
qemu_close(fd);
return ret;
}

Expand Down Expand Up @@ -1506,7 +1506,7 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
}
ret = 0;
exit:
close(fd);
qemu_close(fd);
return ret;
}

Expand Down
2 changes: 1 addition & 1 deletion block/vpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options)
}

fail:
close(fd);
qemu_close(fd);
return ret;
}

Expand Down
12 changes: 6 additions & 6 deletions block/vvfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@ static inline void vvfat_close_current_file(BDRVVVFATState *s)
if(s->current_mapping) {
s->current_mapping = NULL;
if (s->current_fd) {
close(s->current_fd);
qemu_close(s->current_fd);
s->current_fd = 0;
}
}
Expand Down Expand Up @@ -2230,7 +2230,7 @@ static int commit_one_file(BDRVVVFATState* s,
}
if (offset > 0) {
if (lseek(fd, offset, SEEK_SET) != offset) {
close(fd);
qemu_close(fd);
g_free(cluster);
return -3;
}
Expand All @@ -2251,13 +2251,13 @@ static int commit_one_file(BDRVVVFATState* s,
(uint8_t*)cluster, (rest_size + 0x1ff) / 0x200);

if (ret < 0) {
close(fd);
qemu_close(fd);
g_free(cluster);
return ret;
}

if (write(fd, cluster, rest_size) < 0) {
close(fd);
qemu_close(fd);
g_free(cluster);
return -2;
}
Expand All @@ -2268,11 +2268,11 @@ static int commit_one_file(BDRVVVFATState* s,

if (ftruncate(fd, size)) {
perror("ftruncate()");
close(fd);
qemu_close(fd);
g_free(cluster);
return -4;
}
close(fd);
qemu_close(fd);
g_free(cluster);

return commit_mappings(s, first_cluster, dir_index);
Expand Down
5 changes: 5 additions & 0 deletions osdep.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ int qemu_open(const char *name, int flags, ...)
return ret;
}

int qemu_close(int fd)
{
return close(fd);
}

/*
* A variant of write(2) which handles partial write.
*
Expand Down
1 change: 1 addition & 0 deletions qemu-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ const char *path(const char *pathname);
void *qemu_oom_check(void *ptr);

int qemu_open(const char *name, int flags, ...);
int qemu_close(int fd);
ssize_t qemu_write_full(int fd, const void *buf, size_t count)
QEMU_WARN_UNUSED_RESULT;
ssize_t qemu_send_full(int fd, const void *buf, size_t count, int flags)
Expand Down
4 changes: 2 additions & 2 deletions savevm.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ static void qemu_fill_buffer(QEMUFile *f)
*
* Returns f->close() return value, or 0 if close function is not set.
*/
static int qemu_close(QEMUFile *f)
static int qemu_fclose_internal(QEMUFile *f)
{
int ret = 0;
if (f->close) {
Expand All @@ -535,7 +535,7 @@ int qemu_fclose(QEMUFile *f)
{
int ret;
qemu_fflush(f);
ret = qemu_close(f);
ret = qemu_fclose_internal(f);
/* If any error was spotted before closing, we should report it
* instead of the close() return value.
*/
Expand Down

0 comments on commit 2e1e79d

Please sign in to comment.