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;
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) {
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;
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++)