Move more file stuff to file.h
[fio.git] / file.h
CommitLineData
d6aed795
JA
1#ifndef FIO_FILE_H
2#define FIO_FILE_H
3
4#include "io_ddir.h"
5
6/*
7 * The type of object we are working on
8 */
9enum fio_filetype {
10 FIO_TYPE_FILE = 1, /* plain file */
11 FIO_TYPE_BD, /* block device */
12 FIO_TYPE_CHAR, /* character device */
13 FIO_TYPE_PIPE, /* pipe */
14};
15
16enum fio_file_flags {
17 FIO_FILE_open = 1 << 0, /* file is open */
18 FIO_FILE_closing = 1 << 1, /* file being closed */
19 FIO_FILE_extend = 1 << 2, /* needs extend */
20 FIO_FILE_done = 1 << 3, /* io completed to this file */
21 FIO_FILE_size_known = 1 << 4, /* size has been set */
22 FIO_FILE_hashed = 1 << 5, /* file is on hash */
23};
24
25enum file_lock_mode {
26 FILE_LOCK_NONE,
27 FILE_LOCK_EXCLUSIVE,
28 FILE_LOCK_READWRITE,
29};
30
31/*
32 * Each thread_data structure has a number of files associated with it,
33 * this structure holds state information for a single file.
34 */
35struct fio_file {
36 struct flist_head hash_list;
37 enum fio_filetype filetype;
38
39 /*
40 * A file may not be a file descriptor, let the io engine decide
41 */
42 union {
43 unsigned long file_data;
44 int fd;
45 };
46
47 /*
48 * filename and possible memory mapping
49 */
50 char *file_name;
51 unsigned int major, minor;
52
53 void *mmap_ptr;
54 size_t mmap_sz;
55 off_t mmap_off;
56
57 /*
58 * size of the file, offset into file, and io size from that offset
59 */
60 unsigned long long real_file_size;
61 unsigned long long file_offset;
62 unsigned long long io_size;
63
64 unsigned long long last_pos;
65
66 /*
67 * if io is protected by a semaphore, this is set
68 */
69 struct fio_mutex *lock;
70 void *lock_owner;
71 unsigned int lock_batch;
72 enum fio_ddir lock_ddir;
73
74 /*
75 * block map for random io
76 */
77 unsigned int *file_map;
78 unsigned int num_maps;
79 unsigned int last_free_lookup;
80
81 int references;
82 enum fio_file_flags flags;
83
84 struct disk_util *du;
85};
86
87#define FILE_FLAG_FNS(name) \
88static inline void fio_file_set_##name(struct fio_file *f) \
89{ \
90 (f)->flags |= FIO_FILE_##name; \
91} \
92static inline void fio_file_clear_##name(struct fio_file *f) \
93{ \
94 (f)->flags &= ~FIO_FILE_##name; \
95} \
96static inline int fio_file_##name(struct fio_file *f) \
97{ \
98 return ((f)->flags & FIO_FILE_##name) != 0; \
99}
100
101FILE_FLAG_FNS(open);
102FILE_FLAG_FNS(closing);
103FILE_FLAG_FNS(extend);
104FILE_FLAG_FNS(done);
105FILE_FLAG_FNS(size_known);
106FILE_FLAG_FNS(hashed);
107#undef FILE_FLAG_FNS
108
4cd02b3f
JA
109/*
110 * File setup/shutdown
111 */
112struct thread_data;
113extern void close_files(struct thread_data *);
114extern void close_and_free_files(struct thread_data *);
115extern int __must_check setup_files(struct thread_data *);
116extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *);
117extern int __must_check generic_open_file(struct thread_data *, struct fio_file *);
118extern int __must_check generic_close_file(struct thread_data *, struct fio_file *);
119extern int __must_check generic_get_file_size(struct thread_data *, struct fio_file *);
120extern int __must_check pre_read_files(struct thread_data *);
121extern int add_file(struct thread_data *, const char *);
122extern void get_file(struct fio_file *);
123extern int __must_check put_file(struct thread_data *, struct fio_file *);
124extern void lock_file(struct thread_data *, struct fio_file *, enum fio_ddir);
125extern void unlock_file(struct thread_data *, struct fio_file *);
126extern void unlock_file_all(struct thread_data *, struct fio_file *);
127extern int add_dir_files(struct thread_data *, const char *);
128extern int init_random_map(struct thread_data *);
129extern void dup_files(struct thread_data *, struct thread_data *);
130extern int get_fileno(struct thread_data *, const char *);
131extern void free_release_files(struct thread_data *);
132
d6aed795 133#endif