static blksize_t alloc_size;
int default_behavior = 0;
+int unwritten_extents = 0;
char *base_file_path;
static void get_file_system(int fd)
int ret;
ret = fallocate(fd, mode, offset, length);
- if (ret) {
- /* Don't warn about a filesystem w/o fallocate support */
- if (errno == EOPNOTSUPP)
- return ret;
+ if (ret)
fprintf(stderr, " ERROR %d: Failed to preallocate "
"space to %ld bytes\n", errno, (long) length);
- }
return ret;
}
int bufsz, filsz;
int ret = 0;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
if (pagesz < 4 * alloc_size) {
fprintf(stdout, "Test skipped as page size (%d) is less than "
"four times allocation size (%d).\n",
memset(buf, 'a', bufsz);
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
int bufsz = sysconf(_SC_PAGE_SIZE);
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
int bufsz = sysconf(_SC_PAGE_SIZE);
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
int bufsz = sysconf(_SC_PAGE_SIZE) * 14;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
int bufsz = sysconf(_SC_PAGE_SIZE) * 14;
int filsz = 4 << 20;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, 0);
if (ret)
int bufsz = alloc_size;
int filsz = bufsz * 100 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/*
* HOLE - unwritten DATA in dirty page - HOLE -
* unwritten DATA in writeback page
/* preallocate 8M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (!ret) {
int bufsz = alloc_size;
int filsz = bufsz * 10 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in writeback page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (ret)
int bufsz = alloc_size;
int filsz = bufsz * 10 + bufsz;
+ if (!unwritten_extents) {
+ fprintf(stdout, "Test skipped as fs doesn't support unwritten extents.\n");
+ goto out;
+ }
+
/* HOLE - unwritten DATA in dirty page */
/* Each unit is bufsz */
buf = do_malloc(bufsz);
/* preallocate 4M space to file */
ret = do_fallocate(fd, 0, filsz, 0);
- if (ret < 0) {
- /* Report success if fs doesn't support fallocate */
- if (errno == EOPNOTSUPP) {
- fprintf(stdout, "Test skipped as fs doesn't support fallocate.\n");
- ret = 0;
- }
+ if (ret < 0)
goto out;
- }
ret = do_pwrite(fd, buf, bufsz, bufsz * 10);
if (ret)
fprintf(stderr, "File system supports the default behavior.\n");
}
+ ftruncate(fd, 0);
+ if (fallocate(fd, 0, 0, alloc_size) == -1) {
+ if (errno == EOPNOTSUPP)
+ fprintf(stderr, "File system does not support fallocate.");
+ else {
+ fprintf(stderr, "ERROR %d: Failed to preallocate "
+ "space to %ld bytes. Aborting.\n", errno, (long) alloc_size);
+ ret = -1;
+ }
+ goto out;
+ }
+
+ pos = lseek(fd, 0, SEEK_DATA);
+ if (pos == 0) {
+ fprintf(stderr, "File system does not support unwritten extents.\n");
+ goto out;
+ }
+ unwritten_extents = 1;
+
printf("\n");
out: