void ffsb_deletefile(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *curfile = NULL; randdata_t *rd = ft_get_randdata(ft); struct timeval start, end; int need_stats = ft_needs_stats(ft, SYS_UNLINK) || fs_needs_stats(fs, SYS_UNLINK); curfile = choose_file_writer(bf, rd); remove_file(bf, curfile); if (need_stats) gettimeofday(&start, NULL); if (unlink(curfile->name) == -1) { printf("error deleting %s in deletefile\n", curfile->name); perror("deletefile"); exit(0); } if (need_stats) { gettimeofday(&end, NULL); do_stats(&start, &end, ft, fs, SYS_UNLINK); } rw_unlock_write(&curfile->lock); ft_incr_op(ft, opnum, 1, 0); }
/* Just like ffsb_readfile but we read the whole file from start to * finish regardless of file size. */ void ffsb_readall(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *curfile = NULL; int fd; uint64_t filesize; char *buf = ft_getbuf(ft); uint32_t read_blocksize = ft_get_read_blocksize(ft); struct randdata *rd = ft_get_randdata(ft); unsigned iterations = 0; curfile = choose_file_reader(bf, rd); fd = fhopenread(curfile->name, ft, fs); filesize = ffsb_get_filesize(curfile->name); iterations = readfile_helper(fd, filesize, read_blocksize, buf, ft, fs); unlock_file_reader(curfile); fhclose(fd, ft, fs); ft_incr_op(ft, opnum, iterations, filesize); ft_add_readbytes(ft, filesize); }
void ffsb_createfile_fsync(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { unsigned iterations; uint64_t filesize; iterations = ffsb_createfile_core(ft, fs, opnum, &filesize, 1); ft_incr_op(ft, opnum, iterations, filesize); ft_add_writebytes(ft, filesize); }
void ffsb_stat(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *curfile = NULL; randdata_t *rd = ft_get_randdata(ft); curfile = choose_file_reader(bf, rd); fhstat(curfile->name, ft, fs); unlock_file_reader(curfile); ft_incr_op(ft, opnum, 1, 0); }
void ffsb_metaops(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); randdata_t *rd = ft_get_randdata(ft); createdir(bf, rd); createdir(bf, rd); removedir(bf, rd); renamedir(bf, rd); ft_incr_op(ft, opnum, 1, 0); }
void ffsb_createdir(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *newdir; randdata_t *rd = ft_get_randdata(ft); newdir = add_dir(bf, 0, rd); if (mkdir(newdir->name, S_IRWXU) < 0) { perror("mkdir"); exit(1); } unlock_file_writer(newdir); ft_incr_op(ft, opnum, 1, 0); }
void ffsb_readfile(ffsb_thread_t *ft, ffsb_fs_t *fs, unsigned opnum) { struct benchfiles *bf = (struct benchfiles *)fs_get_opdata(fs, opnum); struct ffsb_file *curfile = NULL; int fd; uint64_t filesize; char *buf = ft_getbuf(ft); int read_random = ft_get_read_random(ft); uint64_t read_size = ft_get_read_size(ft); uint32_t read_blocksize = ft_get_read_blocksize(ft); uint32_t read_skipsize = ft_get_read_skipsize(ft); int skip_reads = ft_get_read_skip(ft); struct randdata *rd = ft_get_randdata(ft); uint64_t iterations = 0; curfile = choose_file_reader(bf, rd); fd = fhopenread(curfile->name, ft, fs); filesize = ffsb_get_filesize(curfile->name); assert(filesize >= read_size); /* Sequential read, starting at a random point */ if (!read_random) { uint64_t range = filesize - read_size; uint64_t offset = 0; /* Skip or "stride" reads option */ if (skip_reads) { unsigned i, last; uint64_t minfilesize; iterations = read_size / read_blocksize; last = read_size % read_blocksize; /* Double check that the user hasn't specified * a read_size that is too large when combined * with the seeks */ if (last) minfilesize = last + iterations * (read_blocksize + read_skipsize); else minfilesize = read_blocksize + iterations - 1 * (read_blocksize + read_skipsize); if (minfilesize > filesize) { printf("Error: read size %llu bytes too big " "w/ skipsize %u and blocksize %u," " for file of size %llu bytes\n" " aborting\n\n", read_size, read_skipsize, read_blocksize, filesize); printf("minimum file size must be at least " " %llu bytes\n", minfilesize); exit(1); } for (i = 0; i < iterations; i++) { fhread(fd, buf, read_blocksize, ft, fs); fhseek(fd, (uint64_t)read_skipsize, SEEK_CUR, ft, fs); } if (last) { fhread(fd, buf, (uint64_t)last, ft, fs); iterations++; } } else { /* Regular sequential reads */ if (range) { offset = get_random_offset(rd, range, fs_get_alignio(fs)); fhseek(fd, offset, SEEK_SET, ft, fs); } iterations = readfile_helper(fd, read_size, read_blocksize, buf, ft, fs); } } else { /* Randomized read */ uint64_t range = filesize - read_blocksize; int i; iterations = read_size / read_blocksize; for (i = 0; i < iterations; i++) { uint64_t offset = get_random_offset(rd, range, fs_get_alignio(fs)); fhseek(fd, offset, SEEK_SET, ft, fs); fhread(fd, buf, read_blocksize, ft, fs); } } unlock_file_reader(curfile); fhclose(fd, ft, fs); ft_incr_op(ft, opnum, iterations, read_size); ft_add_readbytes(ft, read_size); }