Patchwork [09/35] fs-tests: integck: handle all failures in operate_on_open_file

login
register
mail settings
Submitter Artem Bityutskiy
Date April 20, 2011, 10:18 a.m.
Message ID <1303294748-5492-10-git-send-email-dedekind1@gmail.com>
Download mbox | patch
Permalink /patch/92160/
State Accepted
Commit 6254515b631a4f7ca21c1ef26b0749388086faa9
Headers show

Comments

Artem Bityutskiy - April 20, 2011, 10:18 a.m.
From: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>

Make 'operate_on_open_file()' to handle possible 'fsync()' and 'fdatasync()'
errors by returning -1 up to the caller.

Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
---
 tests/fs-tests/integrity/integck.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)

Patch

diff --git a/tests/fs-tests/integrity/integck.c b/tests/fs-tests/integrity/integck.c
index 7ccbcb1..7348e14 100644
--- a/tests/fs-tests/integrity/integck.c
+++ b/tests/fs-tests/integrity/integck.c
@@ -1947,26 +1947,33 @@  static int operate_on_dir(struct dir_info *dir)
  */
 static int operate_on_open_file(struct fd_info *fdi)
 {
+	int ret = 0;
 	unsigned int r = random_no(1000);
 
 	if (shrink && r < 5)
-		return file_truncate(fdi->file, fdi->fd);
+		ret = file_truncate(fdi->file, fdi->fd);
 	else if (r < 21)
 		file_close(fdi);
 	else if (shrink && r < 121 && !fdi->file->deleted)
-		return file_delete(fdi->file);
+		ret = file_delete(fdi->file);
 	else {
-		if (file_write(fdi->file, fdi->fd))
-			return -1;
-		if (r >= 999) {
-			if (random_no(100) >= 50)
-				CHECK(fsync(fdi->fd) == 0);
-			else
-				CHECK(fdatasync(fdi->fd) == 0);
+		ret = file_write(fdi->file, fdi->fd);
+		if (!ret && r >= 999) {
+			if (random_no(100) >= 50) {
+				ret = fsync(fdi->fd);
+				if (ret)
+					pcv("fsync failed for %s",
+					    fdi->file->name);
+			} else {
+				ret = fdatasync(fdi->fd);
+				if (ret)
+					pcv("fdatasync failed for %s",
+					    fdi->file->name);
+			}
 		}
 	}
 
-	return 0;
+	return ret;
 }
 
 /*