From: Jens Axboe Date: Thu, 17 Nov 2005 12:53:36 +0000 (+0100) Subject: [PATCH] fio: various fixes for using a bdev directly X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=c4c8f7b346daa7c4a47b24753b03636f70ed5f10;p=disktools.git [PATCH] fio: various fixes for using a bdev directly --- diff --git a/fio-ini.c b/fio-ini.c index 3018fc1..97f3807 100644 --- a/fio-ini.c +++ b/fio-ini.c @@ -153,12 +153,21 @@ static void put_job(struct thread_data *td) static int add_job(struct thread_data *td, const char *jobname, int prioclass, int prio) { + struct stat sb; int numjobs; if (td == &def_thread) return 0; - sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->thread_number); + td->filetype = FIO_TYPE_FILE; + if (!stat(jobname, &sb) && S_ISBLK(sb.st_mode)) + td->filetype = FIO_TYPE_BD; + + if (td->filetype == FIO_TYPE_FILE) + sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->thread_number); + else + strcpy(td->file_name, jobname); + sem_init(&td->mutex, 1, 0); td->ioprio = (prioclass << IOPRIO_CLASS_SHIFT) | prio; diff --git a/fio.c b/fio.c index 22db6fc..d6e40d5 100644 --- a/fio.c +++ b/fio.c @@ -1188,9 +1188,8 @@ static int file_exists(struct thread_data *td) return errno != ENOENT; } -static int get_file_size(struct thread_data *td) +static int file_size(struct thread_data *td) { - size_t bytes = 0; struct stat st; if (fstat(td->fd, &st) == -1) { @@ -1198,39 +1197,50 @@ static int get_file_size(struct thread_data *td) return 1; } - /* - * if block device, get size via BLKGETSIZE64 ioctl. try that as well - * if this is a link, fall back to st.st_size if it fails - */ - if (S_ISBLK(st.st_mode) || S_ISLNK(st.st_mode)) { - if (ioctl(td->fd, BLKGETSIZE64, &bytes)) { - if (S_ISBLK(st.st_mode)) { - td->error = errno; - return 1; - } else - bytes = st.st_size; - } - } else - bytes = st.st_size; - if (td_read(td)) { - if (!td->file_size) - td->file_size = bytes; - else if (td->file_size > bytes) - bytes = td->file_size; + if (!td->file_size || td->file_size > st.st_size) + td->file_size = st.st_size; } else { if (!td->file_size) td->file_size = 1024 * 1024 * 1024; + } + + return 0; +} + +static int bdev_size(struct thread_data *td) +{ + size_t bytes; - bytes = td->file_size; + if (ioctl(td->fd, BLKGETSIZE64, &bytes) < 0) { + td->error = errno; + return 1; } - if (td->file_offset > bytes) { + if (!td->file_size || (td->file_size > bytes)) + td->file_size = bytes; + + return 0; +} + +static int get_file_size(struct thread_data *td) +{ + int ret; + + if (td->filetype == FIO_TYPE_FILE) + ret = file_size(td); + else + ret = bdev_size(td); + + if (ret) + return ret; + + if (td->file_offset > td->file_size) { fprintf(stderr, "Client%d: offset larger than length\n", td->thread_number); return 1; } - td->io_size = bytes - td->file_offset; + td->io_size = td->file_size - td->file_offset; if (td->io_size == 0) { fprintf(stderr, "Client%d: no io blocks\n", td->thread_number); td->error = EINVAL; @@ -1772,8 +1782,7 @@ static void show_run_stats(void) td = &threads[i]; rs = &runstats[td->groupid]; - if (!td->error) - show_thread_status(td, rs); + show_thread_status(td, rs); } for (i = 0; i < groupid + 1; i++) diff --git a/fio.h b/fio.h index 1cdf049..81969d3 100644 --- a/fio.h +++ b/fio.h @@ -58,6 +58,7 @@ struct thread_data { pthread_t thread; int thread_number; int groupid; + int filetype; int error; int fd; pid_t pid; @@ -181,6 +182,11 @@ enum { MEM_SHM, }; +enum { + FIO_TYPE_FILE = 1, + FIO_TYPE_BD, +}; + #define td_read(td) ((td)->ddir == DDIR_READ) #define td_write(td) ((td)->ddir == DDIR_WRITE)