[Ocfs2-test-devel] [PATCH 3/8] Ocfs2-test: Protect file verification from verifying chunks after EOF.
Tristan Ye
tristan.ye at oracle.com
Fri Apr 15 02:01:47 PDT 2011
In the case of destructive testcase, it's possible that file's i_size
is less than what we expected since the file creation didn't get finished
yet, therefore, we'd handle this case to prevent verification process to
do useless check.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
programs/libocfs2test/file_verify.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/programs/libocfs2test/file_verify.c b/programs/libocfs2test/file_verify.c
index e940be1..94e0876 100644
--- a/programs/libocfs2test/file_verify.c
+++ b/programs/libocfs2test/file_verify.c
@@ -132,8 +132,8 @@ int get_i_size(char *filename, unsigned long *size, int flags)
struct stat stat;
int ret = 0, fd;
- fd = open_file(filename, O_RDONLY);
- if (fd)
+ fd = open_file(filename, O_RDONLY | flags);
+ if (fd < 0)
return fd;
ret = fstat(fd, &stat);
@@ -432,7 +432,7 @@ int verify_file(int is_remote, FILE *logfile, struct write_unit *remote_wus,
{
int fd = 0, ret = 0;
struct write_unit *wus, wu, ewu;
- unsigned long num_chunks = filesize / chunksize;
+ unsigned long num_chunks = filesize / chunksize, i_size;
unsigned long i, t_bytes = sizeof(struct write_unit) * num_chunks;
char arg1[100], arg2[100], arg3[100], arg4[100], *tmp_pattern;
@@ -444,6 +444,10 @@ int verify_file(int is_remote, FILE *logfile, struct write_unit *remote_wus,
wus = (struct write_unit *)malloc(t_bytes);
memset(wus, 0, t_bytes);
+ ret = get_i_size(filename, &i_size, 0);
+ if (ret)
+ return ret;
+
if (is_remote) {
memcpy(wus, remote_wus, t_bytes);
goto verify_body;
@@ -497,7 +501,14 @@ verify_body:
* - verify write records.
* - verify pattern of chunks absent from write records.
*/
-
+ memset(&wu, 0, sizeof(struct write_unit));
+
+ /*
+ * verfication ends up touching the EOF of file.
+ */
+ if (i * chunksize >= i_size)
+ break;
+
ret = do_read_chunk(fd, i, chunksize, &wu);
if (ret < 0)
return ret;
--
1.6.5.2
More information about the Ocfs2-test-devel
mailing list