return 0;
}
-static int create_file(struct thread_data *td)
+static int create_file(struct thread_data *td, unsigned long long size,
+ int extend)
{
unsigned long long left;
unsigned int bs;
+ int r, oflags;
char *b;
- int r;
/*
* unless specifically asked for overwrite, let normal io extend it
if (td_write(td) && !td->overwrite)
return 0;
- if (!td->file_size) {
+ if (!size) {
fprintf(stderr, "Need size for create\n");
td->error = EINVAL;
return 1;
}
- printf("Client%d: Laying out IO file\n", td->thread_number);
+ if (!extend) {
+ oflags = O_CREAT | O_TRUNC;
+ printf("Client%d: Laying out IO file (%LuMiB)\n", td->thread_number, size >> 20);
+ } else {
+ oflags = O_APPEND;
+ printf("Client%d: Extending IO file (%Lu -> %LuMiB)\n", td->thread_number, (td->file_size - size) >> 20, td->file_size >> 20);
+ }
- td->fd = open(td->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ td->fd = open(td->file_name, O_WRONLY | oflags, 0644);
if (td->fd < 0) {
td->error = errno;
return 1;
}
- if (ftruncate(td->fd, td->file_size) == -1) {
+ if (!extend && ftruncate(td->fd, td->file_size) == -1) {
td->error = errno;
return 1;
}
b = malloc(td->max_bs);
memset(b, 0, td->max_bs);
- left = td->file_size;
+ left = size;
while (left && !td->terminate) {
bs = td->max_bs;
if (bs > left)
return 0;
}
-static int file_exists(struct thread_data *td)
-{
- struct stat st;
-
- if (stat(td->file_name, &st) != -1)
- return 1;
-
- return errno != ENOENT;
-}
-
static int file_size(struct thread_data *td)
{
struct stat st;
static int setup_file(struct thread_data *td)
{
+ struct stat st;
int flags = 0;
- if (!file_exists(td)) {
+ if (stat(td->file_name, &st) == -1) {
+ if (errno != ENOENT) {
+ td->error = errno;
+ return 1;
+ }
if (!td->create_file) {
td->error = ENOENT;
return 1;
}
- if (create_file(td))
+ if (create_file(td, td->file_size, 0))
+ return 1;
+ } else if (st.st_size < td->file_size) {
+ if (create_file(td, td->file_size - st.st_size, 1))
return 1;
}