fs-tests: integck: more power cut mode changes
cover fs-tests: integck: more power cut mode changes
Hi,
here are fre more integck fixes and improvements for the power cut testing mode.
Artem.
PATCH 3/5 fs-tests: integck: fix line number in CHECK() output
From: Artem Bityutskiy <[email protected]>
In 'check_failed()' use the file and line number provided by the CHECK() macro via the function parameters, rather than using __LINE__ directly. Otherwise the funtion prints its own line, instead of the line where the CHECK() failed.
--- tests/fs-tests/integrity/integck.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
tests/fs-tests/integrity/integck.c +1 -1
@@ -233,7 +233,7 @@ static void check_failed(const char *cond, const char *func, const char *file,fflush (stdout);errmsg ("condition '%s' failed in %s() at %s:%d" , - cond, func, __FILE__, __LINE__); + cond, func, file, line);normsg ("error %d (%s)" , error,strerror (error));/* * Note, to make this work well you need:
Signature · 1 line
1.7.2.3
PATCH 1/5 fs-tests: integck: introduce a helper for checking
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Introduce a 'check_tested_fs()' helper function.
--- tests/fs-tests/integrity/integck.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
tests/fs-tests/integrity/integck.c +9 -6
@@ -2505,6 +2505,13 @@ static int remount_tested_fs(void)return 0 ; } +static void check_tested_fs (void ) +{ + check_run_no +=1 ; +dir_check (top_dir); +check_deleted_files (); +} +/* * Perform the test. Returns zero on success and -1 on failure. */
@@ -2543,9 +2550,7 @@ static int integck(void)assert (!args.power_cut_mode);/* Check everything */ - check_run_no +=1 ; -dir_check (top_dir); -check_deleted_files (); +check_tested_fs ();for (rpt =0 ; args.repeat_cnt ==0 || rpt < args.repeat_cnt; ++rpt) { ret =update_test_data ();
@@ -2560,9 +2565,7 @@ static int integck(void) }/* Check everything */ - check_run_no +=1 ; -dir_check (top_dir); -check_deleted_files (); +check_tested_fs (); }/* Tidy up by removing everything */
Signature · 1 line
1.7.2.3
PATCH 2/5 fs-tests: integck: do not run checking when in power cut mode
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Do not check the file-system when we are in power cut mode. Currently we still check the FS if we did not encounter any error, and the test fails sometimes because meanwhile write-back encounters an error and drops pages. Disable the checking so far. It should be enabled when we implement the 'clean' flag for files.
--- tests/fs-tests/integrity/integck.c | 37 +++++++++++++++++++++++++---------- 1 files changed, 26 insertions(+), 11 deletions(-)
tests/fs-tests/integrity/integck.c +26 -11
@@ -2507,9 +2507,32 @@ static int remount_tested_fs(void)static void check_tested_fs (void ) { - check_run_no +=1 ; -dir_check (top_dir); -check_deleted_files (); +/* +* when we are in power cut mode we can only test files which have not +* been modified since the last successful 'fsync()'. this is not +* implemented yet. +* +* note, even if we have not encounter any error during the test, we +* cannot test the file-system. indeed, consider the situation when we +* have written data to file a. a lot of the data is currently cached +* and is waiting for write-back. when write-back happens, an emulated +* power cut may also happen and cause write-back to drop the errored +* pages. and if we start checking the file a after this, we'll fail as +* well. +* +* and even re-mounting will not help, because re-mounting will cause +* full sync which may fail and data pages will be dropped, but +* 'unmount()' will nevertheless succeed, and if we check the +* file-system after this - the check will fail. +* +* and 'sync()' will not help as well since it does not return an +* error. +*/ +if (!args.power_cut_mode) { + check_run_no +=1 ; +dir_check (top_dir); +check_deleted_files (); + } }/*
@@ -2985,14 +3008,6 @@ int main(int argc, char *argv[])* When testing emulated power cuts we have to be able * to re-mount the file-system to clean the EROFS * state. -* -* But there is also another reason. Imaging the test -* writes many files successfully, and decides to check -* them. But the test has done many modifications, so -* there will be write-back. And when write-back fails, -* Linux discards the dirty pages. So, if meanwhile FS -* write-back encounters emulated power cut error, the -* file checking will fail as well. */ errmsg ("power cut mode requers unmountable FS" ); goto out_free;
Signature · 1 line
1.7.2.3
PATCH 5/5 fs-tests: integck: fix falures with SIGBUS
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
The test sometimes dies due to SIGBUS because a power cut event happens when we are writing to an mmap()'ed area. SIGBUS is very difficult to ignore, so fix the issue simply by avoiding doing 'mmap()' operations when in power cut testing mode.
--- tests/fs-tests/integrity/integck.c | 20 +++++++++++++++++--- 1 files changed, 17 insertions(+), 3 deletions(-)
tests/fs-tests/integrity/integck.c +17 -3
@@ -213,7 +213,6 @@ static int full = 0; /* Flag that the file system is full */static uint64_t operation_count =0 ;/* Number of operations used to fill up the file system */ static unsigned int check_run_no; -static unsigned int random_seed;/*
@@ -1110,11 +1109,14 @@ static int file_mmap_write(struct file_info *file)uint64_t free_space;int fd; +assert (!args.power_cut_mode); +if (!file->links)return 0 ;get_fs_space (NULL , &free_space);if (!free_space)return 0 ; +/* Randomly pick a written area of the file */ if (!w)return 0 ;
@@ -1191,8 +1193,20 @@ static int file_write(struct file_info *file, int fd)unsigned int seed;int ret, truncate =0 ; -if (fsinfo.can_mmap && !full && file->link_count && -random_no (100 ) ==1 ) +/* +* Do not do 'mmap()' operations if: +* 1. we are in power cut testing mode, because an emulated power cut +* failure may cause SIGBUS when we are writing to the 'mmap()'ed +* area, and SIGBUS is not easy to ignore. +* 2. When the file-system is full, because again, writing to the +* 'mmap()'ed area may cause SIGBUS when the space allocation fails. +* This is not enough to guarantee we never get SIGBUS, though. For +* example, if we write a lot to a hole, this might require a lot of +* additional space, and we may fail here. But I do not know why we +* never observed this, probably this is just very unlikely. +*/ +if (!args.power_cut_mode && fsinfo.can_mmap && !full && + file->link_count &&random_no (100 ) ==1 )return file_mmap_write (file);get_offset_and_size (file, &offset, &size);
Signature · 1 line
1.7.2.3
PATCH 4/5 fs-tests: integck: ignore -e if in power cut mode
In reply to Artem BityutskiyFrom: Artem Bityutskiy <[email protected]>
Similarly to the previous commit, do not verify operations when in power-cut testing mode. Again, this is because write-back may fail meanwhile.
--- tests/fs-tests/integrity/integck.c | 38 ++++++++++++++++++++++------------- 1 files changed, 24 insertions(+), 14 deletions(-)
tests/fs-tests/integrity/integck.c +24 -14
@@ -543,7 +543,7 @@ static int dir_new(struct dir_info *parent, const char *name)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (path, &st) ==0 );
@@ -589,7 +589,7 @@ static int dir_remove(struct dir_info *dir)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (path, &st) ==-1 );
@@ -626,7 +626,7 @@ static int file_new(struct dir_info *parent, const char *name)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (path, &st) ==0 );
@@ -654,7 +654,7 @@ static int link_new(struct dir_info *parent, const char *name, path =dir_path (parent, name); target =dir_path (entry->parent, entry->name); -if (args.verify_ops) +if (args.verify_ops && !args.power_cut_mode)CHECK (lstat (target, &st1) ==0 ); ret =link (target, path);
@@ -670,7 +670,7 @@ static int link_new(struct dir_info *parent, const char *name,return ret; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {CHECK (lstat (path, &st2) ==0 );CHECK (S_ISREG (st2.st_mode));CHECK (st1.st_ino == st2.st_ino);
@@ -716,7 +716,7 @@ static int file_unlink(struct dir_entry_info *entry)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (path, &st) ==-1 );
@@ -923,7 +923,7 @@ static void file_write_info(struct file_info *file, int fd, off_t offset, w->random_seed = seed; file->raw_writes = w; -if (args.verify_ops) +if (args.verify_ops && !args.power_cut_mode)file_check_data (file, fd, new_write);/* Insert it into file->writes */
@@ -1090,7 +1090,7 @@ static int file_ftruncate(struct file_info *file, int fd, off_t new_length)return -1 ; } -if (args.verify_ops) +if (args.verify_ops && !args.power_cut_mode)CHECK (lseek (fd,0 ,SEEK_END ) == new_length);return 0 ;
@@ -1419,6 +1419,8 @@ static void file_check_data(struct file_info *file, int fd,char buf[IO_BUFFER_SIZE ];unsigned int seed = w->random_seed; +assert (!args.power_cut_mode); +for (r =0 ; r < w->random_offset; ++r)rand_r (&seed);CHECK (lseek (fd, w->offset,SEEK_SET ) != (off_t)-1 );
@@ -1453,6 +1455,9 @@ static void file_check(struct file_info *file, int fd)struct dir_entry_info *entry;struct stat st; +if (args.power_cut_mode) +return ; +/* Do not check files that have errored */ if (!fsinfo.nospc_size_ok && file->no_space_error)return ;
@@ -1528,6 +1533,9 @@ void symlink_check(const struct symlink_info *symlink)ssize_t len;int ret1, ret2; +if (args.power_cut_mode) +return ; + path =dir_path (symlink->entry->parent, symlink->entry->name);CHECK (lstat (path, &st1) ==0 );CHECK (S_ISLNK (st1.st_mode));
@@ -1591,6 +1599,8 @@ static void dir_check(struct dir_info *dir)int link_count =2 ;/* Parent and dot */ struct stat st; +assert (!args.power_cut_mode); +/* Create an array of entries */ sz =sizeof (struct dir_entry_info *); n = dir->number_of_entries;
@@ -1836,7 +1846,7 @@ static int rename_entry(struct dir_entry_info *entry)if (!path)return 0 ; -if (args.verify_ops) +if (args.verify_ops && !args.power_cut_mode)CHECK (lstat (path, &st1) ==0 ); ret =rename (path, to);
@@ -1854,7 +1864,7 @@ static int rename_entry(struct dir_entry_info *entry)return ret; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {CHECK (lstat (to, &st2) ==0 );CHECK (st1.st_ino == st2.st_ino); }
@@ -1996,7 +2006,7 @@ static int symlink_new(struct dir_info *dir, const char *nm)return ret; } -if (args.verify_ops) +if (args.verify_ops && !args.power_cut_mode)verify_symlink (target, path); s =add_dir_entry (dir,'s' , name,NULL );
@@ -2018,7 +2028,7 @@ static int symlink_remove(struct symlink_info *symlink)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (path, &st) ==-1 );
@@ -2359,7 +2369,7 @@ static int rm_minus_rf_dir(const char *dir_name)CHECK (chdir (buf) ==0 );CHECK (closedir (dir) ==0 ); -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) { dir =opendir (dir_name);CHECK (dir !=NULL ); do {
@@ -2379,7 +2389,7 @@ static int rm_minus_rf_dir(const char *dir_name)return -1 ; } -if (args.verify_ops) { +if (args.verify_ops && !args.power_cut_mode) {struct stat st;CHECK (lstat (dir_name, &st) ==-1 );
Signature · 1 line
1.7.2.3