[Ocfs2-test-devel] [PATCH 1/1] Ocfs2-test: Add testcase to ocfs2-test to verify refcount after truncating.
Tristan Ye
tristan.ye at oracle.com
Mon Feb 1 23:25:43 PST 2010
It's similar to the former patch I posted for verifying refcount after
punching holes, I thought my truncate testcase in reflink_test has already
verified the CoW at the very beginning, while it was not actually, existing
truncate testcase only verify the data-consistency of original file.
This testcase also was dedicated to do reflink's verification after partial
zeroing of one cluster happened during truncating.
Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
programs/reflink_tests/reflink_test.c | 130 +++++++++++++++++++++++++++-
programs/reflink_tests/reflink_test.h | 1 +
programs/reflink_tests/reflink_test_run.sh | 34 ++++++--
3 files changed, 156 insertions(+), 9 deletions(-)
diff --git a/programs/reflink_tests/reflink_test.c b/programs/reflink_tests/reflink_test.c
index 49c5990..6de95fb 100755
--- a/programs/reflink_tests/reflink_test.c
+++ b/programs/reflink_tests/reflink_test.c
@@ -108,7 +108,7 @@ static void usage(void)
printf("Usage: reflink_tests [-i iteration] <-n ref_counts> "
"<-p refcount_tree_pairs> <-l file_size> <-d disk> "
"<-w workplace> -f -b [-c conc_procs] -m -s -r [-x xattr_nums]"
- " [-h holes_num] [-o holes_filling_log] -O -D <child_nums> -I\n\n"
+ " [-h holes_num] [-o holes_filling_log] -O -D <child_nums> -I -H -T\n\n"
"-f enable basic feature test.\n"
"-b enable boundary test.\n"
"-c enable concurrent tests with conc_procs processes.\n"
@@ -118,7 +118,8 @@ static void usage(void)
"-O enable O_DIRECT test.\n"
"-D enable destructive test.\n"
"-v enable verification for destructive test.\n"
- "-H enable CoW verification test for punching holse.\n"
+ "-H enable CoW verification test for punching holes.\n"
+ "-T enable CoW verification test for truncating.\n"
"-I enable inline-data test.\n"
"-x enable combination test with xattr.\n"
"-h enable holes punching and filling tests.\n"
@@ -142,7 +143,7 @@ static int parse_opts(int argc, char **argv)
while (1) {
c = getopt(argc, argv,
- "i:d:w:IOfFbBsSrRHmMW:n:N:"
+ "i:d:w:IOfFbBsSrRHTmMW:n:N:"
"l:L:c:C:p:x:X:h:o:v:a:P:D:");
if (c == -1)
break;
@@ -227,6 +228,9 @@ static int parse_opts(int argc, char **argv)
port = atol(optarg);
case 'H':
test_flags |= PUNH_TEST;
+ case 'T':
+ test_flags |= TRUC_TEST;
+
default:
break;
}
@@ -2362,6 +2366,123 @@ bail:
return ret;
}
+static int verify_truncate_cow_test(void)
+{
+ int ret = 0, fd;
+ int sub_testno = 1;
+ char *write_pattern = NULL;
+ char *read_pattern = NULL;
+
+ unsigned long i;
+ unsigned long long offset, read_size, new_size, len, trunc_size;
+ char dest[PATH_MAX];
+
+ printf("Test %d: Verify cow for truncating.\n", testno++);
+
+ snprintf(orig_path, PATH_MAX, "%s/original_verify_cow_truncate_"
+ "refile", workplace);
+
+ write_pattern = malloc(clustersize);
+ read_pattern = malloc(clustersize);
+
+ get_rand_buf(write_pattern, clustersize);
+ memset(read_pattern, 0, clustersize);
+
+ printf(" *SubTest %d: Prepare file.\n", sub_testno++);
+ ret = prep_orig_file_with_pattern(orig_path, file_size, clustersize,
+ write_pattern, 0);
+ if (ret < 0)
+ goto bail;
+
+ printf(" *SubTest %d: Do %ld reflinks.\n", sub_testno++, ref_counts);
+ ret = do_reflinks(orig_path, orig_path, ref_counts, 0);
+ if (ret < 0)
+ goto bail;
+
+ printf(" *SubTest %d: Truncating original file.\n",
+ sub_testno++);
+
+ fd = open_file(orig_path, O_RDWR);
+ if (fd < 0)
+ goto bail;
+
+ new_size = file_size;
+
+ while (new_size >= 0) {
+
+ ret = ftruncate(fd, new_size);
+ if (ret < 0) {
+ fprintf(stderr, "failed to truncate file %d to %llu\n",
+ orig_path, new_size);
+ close(fd);
+ goto bail;
+ }
+
+ if (new_size == 0)
+ break;
+
+ trunc_size = get_rand(0, new_size);
+
+ new_size -= trunc_size;
+
+ }
+
+ close(fd);
+
+ printf(" *SubTest %d: Verify reflinks after punching holes.\n",
+ sub_testno++);
+
+ for (i = 0; i < ref_counts; i++) {
+ snprintf(dest, PATH_MAX, "%sr%ld", orig_path, i);
+ fd = open_file(dest, O_RDONLY);
+ if (fd < 0)
+ goto bail;
+
+ offset = 0;
+ while (offset < file_size) {
+ if ((offset + clustersize) > file_size)
+ read_size = file_size - offset;
+ else
+ read_size = clustersize;
+ ret = read_at(fd, read_pattern, read_size, offset);
+ if (ret < 0) {
+ close(fd);
+ goto bail;
+ }
+ if (memcmp(read_pattern, write_pattern, read_size)) {
+ fprintf(stderr, "Corrupted chunk found on "
+ "reflink %s: from %llu to %llu\n",
+ dest, offset, offset + read_size);
+ ret = -1;
+ close(fd);
+ goto bail;
+ }
+ offset += read_size;
+ }
+
+ close(fd);
+
+ }
+
+ printf(" *SubTest %d: Unlinking reflinks and original file.\n",
+ sub_testno++);
+
+ ret = do_unlinks(orig_path, ref_counts);
+ if (ret < 0)
+ goto bail;
+
+ ret = do_unlink(orig_path);
+
+bail:
+ if (write_pattern)
+ free(write_pattern);
+
+ if (read_pattern)
+ free(read_pattern);
+
+ return ret;
+}
+
static void run_test(void)
{
int i;
@@ -2409,6 +2530,9 @@ static void run_test(void)
if (test_flags & PUNH_TEST)
verify_punch_hole_cow_test();
+ if (test_flags & TRUC_TEST)
+ verify_truncate_cow_test();
+
}
}
diff --git a/programs/reflink_tests/reflink_test.h b/programs/reflink_tests/reflink_test.h
index 2117cda..5f864f2 100755
--- a/programs/reflink_tests/reflink_test.h
+++ b/programs/reflink_tests/reflink_test.h
@@ -78,6 +78,7 @@
#define DSCV_TEST 0x00001000
#define VERI_TEST 0x00002000
#define PUNH_TEST 0x00004000
+#define TRUC_TEST 0x00008000
#define MPI_RET_SUCCESS 0
#define MPI_RET_FAILED 1
diff --git a/programs/reflink_tests/reflink_test_run.sh b/programs/reflink_tests/reflink_test_run.sh
index 840f7a2..69ce4d3 100755
--- a/programs/reflink_tests/reflink_test_run.sh
+++ b/programs/reflink_tests/reflink_test_run.sh
@@ -14,18 +14,22 @@
# 3. Mmap test
#
# 4. DirectIO test
+#
+# 5. CoW test on punching holes
+#
+# 6. CoW test on truncating
#
-# 5. Concurrent test
+# 7. Concurrent test
#
-# 6. Boundary test
+# 8. Boundary test
#
-# 7. Stress test
+# 9. Stress test
#
-# 8. Inline-data test
+# 10. Inline-data test
#
-# 9. Xattr combination test
+# 11. Xattr combination test
#
-# 10. OracleVM simulation test
+# 12. OracleVM simulation test
#
#
# Author: Tristan Ye, tristan.ye at oracle.com
@@ -551,6 +555,24 @@ ${WORK_PLACE} -H >>${LOG_FILE} 2>&1
f_exit_or_not ${RET}
((TEST_NO++))
+ f_LogRunMsg ${RUN_LOG_FILE} "[${TEST_NO}] Verificationl CoW Test On \
+Truncating:"
+ f_LogMsg ${LOG_FILE} "[${TEST_NO}] Verification CoW Test On Truncating\
+, CMD:${SUDO} ${REFLINK_TEST_BIN} -i 1 -n 100 -l 3276800 -d ${DEVICE} \
+-w ${WORK_PLACE} -T "
+ ${SUDO} ${REFLINK_TEST_BIN} -i 1 -n 100 -l 3276800 -d ${DEVICE} -w \
+${WORK_PLACE} -T >>${LOG_FILE} 2>&1
+ RET=$?
+ f_echo_status ${RET} | tee -a ${RUN_LOG_FILE}
+ f_exit_or_not ${RET}
+ ((TEST_PASS++))
+ f_LogMsg ${LOG_FILE} "Cleanup working place"
+ ${SUDO} ${CHMOD_BIN} -R 777 ${MOUNT_POINT} >>${LOG_FILE} 2>&1
+ ${RM_BIN} -rf ${WORK_PLACE}/* >>${LOG_FILE} 2>&1
+ RET=$?
+ f_exit_or_not ${RET}
+
+ ((TEST_NO++))
f_LogRunMsg ${RUN_LOG_FILE} "[${TEST_NO}] Bash & Tools Utility Test:"
f_reflink_bash_utils_test 100 104857600 >>${LOG_FILE} 2>&1
RET=$?
--
1.5.5
More information about the Ocfs2-test-devel
mailing list