block: Convert open calls to qemu_open

This patch converts all block layer open calls to qemu_open.

Note that this adds the O_CLOEXEC flag to the changed open paths
when the O_CLOEXEC macro is defined.

Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Corey Bryant 2012-08-14 16:43:45 -04:00 committed by Kevin Wolf
parent e174082835
commit 6165f4d85d
6 changed files with 26 additions and 28 deletions

View File

@ -572,8 +572,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
options++; options++;
} }
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644); 0644);
if (fd < 0) { if (fd < 0) {
result = -errno; result = -errno;
} else { } else {
@ -846,7 +846,7 @@ static int hdev_open(BlockDriverState *bs, const char *filename, int flags)
if ( bsdPath[ 0 ] != '\0' ) { if ( bsdPath[ 0 ] != '\0' ) {
strcat(bsdPath,"s0"); strcat(bsdPath,"s0");
/* some CDs don't have a partition 0 */ /* some CDs don't have a partition 0 */
fd = open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE); fd = qemu_open(bsdPath, O_RDONLY | O_BINARY | O_LARGEFILE);
if (fd < 0) { if (fd < 0) {
bsdPath[strlen(bsdPath)-1] = '1'; bsdPath[strlen(bsdPath)-1] = '1';
} else { } else {
@ -903,7 +903,7 @@ static int fd_open(BlockDriverState *bs)
#endif #endif
return -EIO; return -EIO;
} }
s->fd = open(bs->filename, s->open_flags & ~O_NONBLOCK); s->fd = qemu_open(bs->filename, s->open_flags & ~O_NONBLOCK);
if (s->fd < 0) { if (s->fd < 0) {
s->fd_error_time = get_clock(); s->fd_error_time = get_clock();
s->fd_got_error = 1; s->fd_got_error = 1;
@ -977,7 +977,7 @@ static int hdev_create(const char *filename, QEMUOptionParameter *options)
options++; options++;
} }
fd = open(filename, O_WRONLY | O_BINARY); fd = qemu_open(filename, O_WRONLY | O_BINARY);
if (fd < 0) if (fd < 0)
return -errno; return -errno;
@ -1057,7 +1057,7 @@ static int floppy_probe_device(const char *filename)
prio = 50; prio = 50;
} }
fd = open(filename, O_RDONLY | O_NONBLOCK); fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
if (fd < 0) { if (fd < 0) {
goto out; goto out;
} }
@ -1110,7 +1110,7 @@ static void floppy_eject(BlockDriverState *bs, bool eject_flag)
close(s->fd); close(s->fd);
s->fd = -1; s->fd = -1;
} }
fd = open(bs->filename, s->open_flags | O_NONBLOCK); fd = qemu_open(bs->filename, s->open_flags | O_NONBLOCK);
if (fd >= 0) { if (fd >= 0) {
if (ioctl(fd, FDEJECT, 0) < 0) if (ioctl(fd, FDEJECT, 0) < 0)
perror("FDEJECT"); perror("FDEJECT");
@ -1160,7 +1160,7 @@ static int cdrom_probe_device(const char *filename)
int prio = 0; int prio = 0;
struct stat st; struct stat st;
fd = open(filename, O_RDONLY | O_NONBLOCK); fd = qemu_open(filename, O_RDONLY | O_NONBLOCK);
if (fd < 0) { if (fd < 0) {
goto out; goto out;
} }
@ -1284,7 +1284,7 @@ static int cdrom_reopen(BlockDriverState *bs)
*/ */
if (s->fd >= 0) if (s->fd >= 0)
close(s->fd); close(s->fd);
fd = open(bs->filename, s->open_flags, 0644); fd = qemu_open(bs->filename, s->open_flags, 0644);
if (fd < 0) { if (fd < 0) {
s->fd = -1; s->fd = -1;
return -EIO; return -EIO;

View File

@ -255,8 +255,8 @@ static int raw_create(const char *filename, QEMUOptionParameter *options)
options++; options++;
} }
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
0644); 0644);
if (fd < 0) if (fd < 0)
return -EIO; return -EIO;
set_sparse(fd); set_sparse(fd);

View File

@ -653,8 +653,9 @@ static int vdi_create(const char *filename, QEMUOptionParameter *options)
options++; options++;
} }
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, fd = qemu_open(filename,
0644); O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
0644);
if (fd < 0) { if (fd < 0) {
return -errno; return -errno;
} }

View File

@ -1161,10 +1161,9 @@ static int vmdk_create_extent(const char *filename, int64_t filesize,
VMDK4Header header; VMDK4Header header;
uint32_t tmp, magic, grains, gd_size, gt_size, gt_count; uint32_t tmp, magic, grains, gd_size, gt_size, gt_count;
fd = open( fd = qemu_open(filename,
filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644);
0644);
if (fd < 0) { if (fd < 0) {
return -errno; return -errno;
} }
@ -1484,15 +1483,13 @@ static int vmdk_create(const char *filename, QEMUOptionParameter *options)
(flags & BLOCK_FLAG_COMPAT6 ? 6 : 4), (flags & BLOCK_FLAG_COMPAT6 ? 6 : 4),
total_size / (int64_t)(63 * 16 * 512)); total_size / (int64_t)(63 * 16 * 512));
if (split || flat) { if (split || flat) {
fd = open( fd = qemu_open(filename,
filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE,
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_LARGEFILE, 0644);
0644);
} else { } else {
fd = open( fd = qemu_open(filename,
filename, O_WRONLY | O_BINARY | O_LARGEFILE,
O_WRONLY | O_BINARY | O_LARGEFILE, 0644);
0644);
} }
if (fd < 0) { if (fd < 0) {
return -errno; return -errno;

View File

@ -678,7 +678,7 @@ static int vpc_create(const char *filename, QEMUOptionParameter *options)
} }
/* Create the file */ /* Create the file */
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); fd = qemu_open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644);
if (fd < 0) { if (fd < 0) {
return -EIO; return -EIO;
} }

View File

@ -1162,7 +1162,7 @@ static int open_file(BDRVVVFATState* s,mapping_t* mapping)
if(!s->current_mapping || if(!s->current_mapping ||
strcmp(s->current_mapping->path,mapping->path)) { strcmp(s->current_mapping->path,mapping->path)) {
/* open file */ /* open file */
int fd = open(mapping->path, O_RDONLY | O_BINARY | O_LARGEFILE); int fd = qemu_open(mapping->path, O_RDONLY | O_BINARY | O_LARGEFILE);
if(fd<0) if(fd<0)
return -1; return -1;
vvfat_close_current_file(s); vvfat_close_current_file(s);
@ -2221,7 +2221,7 @@ static int commit_one_file(BDRVVVFATState* s,
for (i = s->cluster_size; i < offset; i += s->cluster_size) for (i = s->cluster_size; i < offset; i += s->cluster_size)
c = modified_fat_get(s, c); c = modified_fat_get(s, c);
fd = open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666); fd = qemu_open(mapping->path, O_RDWR | O_CREAT | O_BINARY, 0666);
if (fd < 0) { if (fd < 0) {
fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path, fprintf(stderr, "Could not open %s... (%s, %d)\n", mapping->path,
strerror(errno), errno); strerror(errno), errno);