If using raw block devices, we would leak the fd from the bdev_size()
function. Also add some debug triggers to catch this in the future.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
}
f->real_file_size = bytes;
}
f->real_file_size = bytes;
+ td->io_ops->close_file(td, f);
return 0;
err:
td->io_ops->close_file(td, f);
return 0;
err:
td->io_ops->close_file(td, f);
- td_io_close_file(td, f);
+ if (fio_file_open(f))
+ td_io_close_file(td, f);
+
remove_file_hash(f);
sfree(f->file_name);
remove_file_hash(f);
sfree(f->file_name);
dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references);
dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references);
+ if (!fio_file_open(f)) {
+ assert(f->fd == -1);
assert(f->references);
if (--f->references)
assert(f->references);
if (--f->references)
td->nr_open_files--;
fio_file_clear_open(f);
td->nr_open_files--;
fio_file_clear_open(f);
log_err("fio: smalloc OOM\n");
assert(0);
}
log_err("fio: smalloc OOM\n");
assert(0);
}
if (f->file_name) {
__f->file_name = smalloc_strdup(f->file_name);
if (f->file_name) {
__f->file_name = smalloc_strdup(f->file_name);
* its own files. so close them, if we opened them
* for creation
*/
* its own files. so close them, if we opened them
* for creation
*/
- for_each_file(td, f, i)
- td_io_close_file(td, f);
+ for_each_file(td, f, i) {
+ if (fio_file_open(f))
+ td_io_close_file(td, f);
+ else
+ assert(f->fd == -1);
+ }
int td_io_open_file(struct thread_data *td, struct fio_file *f)
{
int td_io_open_file(struct thread_data *td, struct fio_file *f)
{
+ assert(!fio_file_open(f));
+ assert(f->fd == -1);
+
if (td->io_ops->open_file(td, f)) {
if (td->error == EINVAL && td->o.odirect)
log_err("fio: destination does not support O_DIRECT\n");
if (td->io_ops->open_file(td, f)) {
if (td->error == EINVAL && td->o.odirect)
log_err("fio: destination does not support O_DIRECT\n");
+ assert(f->fd == -1);
+ assert(!fio_file_open(f));
- if (f->file_map)
- memset(f->file_map, 0, f->num_maps * sizeof(int));
-
#ifdef FIO_OS_DIRECTIO
/*
* Some OS's have a distinct call to mark the file non-buffered,
#ifdef FIO_OS_DIRECTIO
/*
* Some OS's have a distinct call to mark the file non-buffered,
int td_io_close_file(struct thread_data *td, struct fio_file *f)
{
int td_io_close_file(struct thread_data *td, struct fio_file *f)
{
+ assert(f->references);
+
if (!fio_file_closing(f))
log_file(td, f, FIO_LOG_CLOSE_FILE);
if (!fio_file_closing(f))
log_file(td, f, FIO_LOG_CLOSE_FILE);