aboutsummaryrefslogtreecommitdiff
path: root/tests/fs-tests/integrity
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-14 14:50:22 +0300
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2011-04-22 14:29:51 +0300
commit05737bf075032867dcade9690174dacaa77f663f (patch)
tree4962a8277b7e8c5e6f34be53d3bf90123e071283 /tests/fs-tests/integrity
parentbf77aa4a7bc3a2b97e22291bc9281c7263d48648 (diff)
fs-tests: integck: teach file_truncate return error code
Teach 'file_truncate()' return an error code in case of failure. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'tests/fs-tests/integrity')
-rw-r--r--tests/fs-tests/integrity/integck.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 4f39ce3..06e33b5 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -880,17 +880,27 @@ static void get_offset_and_size(struct file_info *file,
static void file_truncate_info(struct file_info *file, size_t new_length);
+/*
+ * Truncate a file to length 'new_length'. If there is no enough space to
+ * peform the operation, this function returns 1. Returns 0 on success and -1
+ * on failure.
+ */
static int file_ftruncate(struct file_info *file, int fd, off_t new_length)
{
if (ftruncate(fd, new_length) != 0) {
- CHECK(errno = ENOSPC);
- file->no_space_error = 1;
- /* Delete errored files */
- if (!fsinfo.nospc_size_ok)
- file_delete(file);
- return 0;
+ if (errno == ENOSPC) {
+ file->no_space_error = 1;
+ /* Delete errored files */
+ if (!fsinfo.nospc_size_ok)
+ file_delete(file);
+ return 1;
+ } else
+ pcv("cannot truncate file %s to %llu",
+ file->name, (unsigned long long)new_length);
+ return -1;
}
- return 1;
+
+ return 0;
}
static void file_mmap_write(struct file_info *file)
@@ -994,7 +1004,8 @@ static void file_write(struct file_info *file, int fd)
if (truncate) {
size_t new_length = offset + actual;
- if (file_ftruncate(file, fd, new_length))
+
+ if (!file_ftruncate(file, fd, new_length))
file_truncate_info(file, new_length);
}
}
@@ -1044,14 +1055,21 @@ static void file_truncate_info(struct file_info *file, size_t new_length)
file->length = new_length;
}
-static void file_truncate(struct file_info *file, int fd)
+/*
+ * Truncate an open file randomly.
+ */
+static int file_truncate(struct file_info *file, int fd)
{
- size_t new_length;
+ int ret;
+ size_t new_length = random_no(file->length);
- new_length = random_no(file->length);
- if (file_ftruncate(file, fd, new_length))
+ ret = file_ftruncate(file, fd, new_length);
+ if (ret == -1)
+ return -1;
+ if (!ret)
file_truncate_info(file, new_length);
+ return 0;
}
static void file_truncate_file(struct file_info *file)
@@ -1902,7 +1920,7 @@ static int operate_on_open_file(struct fd_info *fdi)
unsigned int r = random_no(1000);
if (shrink && r < 5)
- file_truncate(fdi->file, fdi->fd);
+ return file_truncate(fdi->file, fdi->fd);
else if (r < 21)
file_close(fdi);
else if (shrink && r < 121 && !fdi->file->deleted)