Module Name:    src
Committed By:   bouyer
Date:           Sun Feb 13 20:58:28 UTC 2011

Modified Files:
        src/tests/fs/ffs [bouyer-quota2]: h_quota2_tests.c t_miscquota.sh

Log Message:
Add a test checking that an unlinked file cleaned by the log replay keeps
quotas up to date.


To generate a diff of this commit:
cvs rdiff -u -r1.1.2.4 -r1.1.2.5 src/tests/fs/ffs/h_quota2_tests.c
cvs rdiff -u -r1.1.2.3 -r1.1.2.4 src/tests/fs/ffs/t_miscquota.sh

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/fs/ffs/h_quota2_tests.c
diff -u src/tests/fs/ffs/h_quota2_tests.c:1.1.2.4 src/tests/fs/ffs/h_quota2_tests.c:1.1.2.5
--- src/tests/fs/ffs/h_quota2_tests.c:1.1.2.4	Sat Feb 12 21:49:08 2011
+++ src/tests/fs/ffs/h_quota2_tests.c	Sun Feb 13 20:58:28 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: h_quota2_tests.c,v 1.1.2.4 2011/02/12 21:49:08 bouyer Exp $	*/
+/*	$NetBSD: h_quota2_tests.c,v 1.1.2.5 2011/02/13 20:58:28 bouyer Exp $	*/
 
 /*
  * rump server for advanced quota tests
@@ -35,6 +35,7 @@
 	int fd;
 	int error;
 	rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+	rump_sys_chmod(".", 0777);
 	if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
 		error = errno;
 		perror("rump_sys_setegid");
@@ -67,6 +68,7 @@
 	int fd;
 	int error;
 	rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+	rump_sys_chmod(".", 0777);
 	if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
 		error = errno;
 		perror("rump_sys_setegid");
@@ -115,6 +117,7 @@
 	int error;
 	int i;
 	rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+	rump_sys_chmod(".", 0777);
 	if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
 		error = errno;
 		perror("rump_sys_setegid");
@@ -151,6 +154,7 @@
 	int error;
 	int i;
 	rump_sys_chown(".", TEST_NONROOT_ID, TEST_NONROOT_ID);
+	rump_sys_chmod(".", 0777);
 	if (rump_sys_setegid(TEST_NONROOT_ID) != 0) {
 		error = errno;
 		perror("rump_sys_setegid");
@@ -204,6 +208,8 @@
 	 * take an internal snapshot of the filesystem, and create a new
 	 * file with some data
 	 */
+	rump_sys_chown(".", 0, 0);
+	rump_sys_chmod(".", 0777);
 
 	for (i =0; testopts && i < strlen(testopts); i++) {
 		switch(testopts[i]) {
@@ -233,8 +239,10 @@
 	fss.fss_csize = 0;
 	if (rump_sys_ioctl(fssfd, FSSIOCSET, &fss) == -1)
 		err(1, "create snapshot");
-	if (unl)
-		rump_sys_unlink(FSTEST_MNTNAME "/le_snap");
+	if (unl) {
+		if (rump_sys_unlink(FSTEST_MNTNAME "/le_snap") == -1)
+			err(1, "unlink snapshot");
+	}
 
 	/* now create some extra files */
 
@@ -253,6 +261,63 @@
 	return 0;
 }
 
+static int
+quota_test5(const char *testopts)
+{
+	static char buf[512];
+	int fd;
+	int remount = 0;
+	int unlnk = 0;
+	int log = 0;
+	unsigned int i;
+
+	for (i =0; testopts && i < strlen(testopts); i++) {
+		switch(testopts[i]) {
+		case 'L':
+			log++;
+			break;
+		case 'R':
+			remount++;
+			break;
+		case 'U':
+			unlnk++;
+			break;
+		default:
+			errx(1, "test4: unknown option %c", testopts[i]);
+		}
+	}
+	if (remount) {
+		struct ufs_args uargs;
+		uargs.fspec = __UNCONST("/diskdev");
+		/* remount the fs read/write */
+		if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+		    MNT_UPDATE | (log ? MNT_LOG : 0),
+		    &uargs, sizeof(uargs)) == -1)
+			err(1, "mount ffs rw %s", FSTEST_MNTNAME);
+	}
+
+	if (unlnk) {
+		/*
+		 * open and unlink a file
+		 */
+
+		fd = rump_sys_open("unlinked_file",
+		    O_EXCL| O_CREAT | O_RDWR, 0644);
+		if (fd < 0)
+			err(1, "create %s", "unlinked_file");
+		sprintf(buf, "test unlinked_file");
+		rump_sys_write(fd, buf, strlen(buf));
+		if (rump_sys_unlink("unlinked_file") == -1)
+			err(1, "unlink unlinked_file");
+		if (rump_sys_fsync(fd) == -1) 
+			err(1, "fsync unlinked_file");
+		rump_sys_reboot(RUMP_RB_NOSYNC, NULL);
+		errx(1, "reboot failed");
+		return 1;
+	}
+	return 0;
+}
+
 struct quota_test {
 	int (*func)(const char *);
 	const char *desc;
@@ -264,6 +329,7 @@
 	{ quota_test2, "create file up to hard limit"},
 	{ quota_test3, "create file beyond the soft limit after grace time"},
 	{ quota_test4, "take a snapshot and add some data"},
+	{ quota_test5, "open and unlink a file"},
 };
 
 static void
@@ -307,16 +373,19 @@
 	const char *filename;
 	const char *serverurl;
 	const char *topts = NULL;
-	int log = 0;
+	int mntopts = 0;
 	int ch;
 
-	while ((ch = getopt(argc, argv, "blo:")) != -1) {
+	while ((ch = getopt(argc, argv, "blo:r")) != -1) {
 		switch(ch) {
 		case 'b':
 			background = 1;
 			break;
 		case 'l':
-			log = 1;
+			mntopts |= MNT_LOG;
+			break;
+		case 'r':
+			mntopts |= MNT_RDONLY;
 			break;
 		case 'o':
 			topts = optarg;
@@ -356,14 +425,12 @@
 		err(1, "mount point create");
 	rump_pub_etfs_register("/diskdev", filename, RUMP_ETFS_BLK);
 	uargs.fspec = __UNCONST("/diskdev");
-	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, (log) ? MNT_LOG : 0,
+	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, mntopts,
 	    &uargs, sizeof(uargs)) == -1)
 		die("mount ffs", errno);
 
 	if (rump_sys_chdir(FSTEST_MNTNAME) == -1)
 		err(1, "cd %s", FSTEST_MNTNAME);
-	rump_sys_chown(".", 0, 0);
-	rump_sys_chmod(".", 0777);
 	error = quota_tests[test].func(topts);
 	if (error) {
 		fprintf(stderr, " test %lu: %s returned %d: %s\n",

Index: src/tests/fs/ffs/t_miscquota.sh
diff -u src/tests/fs/ffs/t_miscquota.sh:1.1.2.3 src/tests/fs/ffs/t_miscquota.sh:1.1.2.4
--- src/tests/fs/ffs/t_miscquota.sh:1.1.2.3	Sat Feb 12 21:49:08 2011
+++ src/tests/fs/ffs/t_miscquota.sh	Sun Feb 13 20:58:28 2011
@@ -1,4 +1,4 @@
-# $NetBSD: t_miscquota.sh,v 1.1.2.3 2011/02/12 21:49:08 bouyer Exp $ 
+# $NetBSD: t_miscquota.sh,v 1.1.2.4 2011/02/13 20:58:28 bouyer Exp $ 
 #
 #  Copyright (c) 2011 Manuel Bouyer
 #  All rights reserved.
@@ -44,6 +44,14 @@
     "create a non-persistent shapshot of quota-enabled fs, and do some writes and unconf" \
     -boLC le 1 user
 
+test_case log_unlink quota_log \
+    "an unlinked file cleaned by the log replay should update quota" \
+    -l le 1 user
+
+test_case log_unlink_remount quota_log \
+    "an unlinked file cleaned by the log replay after remount" \
+    -oRL le 1 user
+
 
 quota_walk_list()
 {
@@ -118,3 +126,39 @@
 	#shutdown and check filesystem
 	rump_shutdown
 }
+
+quota_log()
+{
+	local srv2args=$1; shift
+	create_with_quotas $*
+	local q=$3
+	local expect
+
+	case ${q} in
+	user)
+		expect=u
+		fail=g
+		;;
+	group)
+		expect=g
+		fail=u
+		;;
+	*)
+		atf_fail "wrong quota type"
+		;;
+	esac
+
+	#start our server which create a file and unlink while keeping
+	# it open. The server halts itself without flush
+	atf_check -s exit:0 -o ignore \
+	    $(atf_get_srcdir)/h_quota2_tests -loU 5 ${IMG} ${RUMP_SERVER}
+	# we should have one unlinked file, but the log covers it.
+	atf_check -s exit:0 -o match:'3 files' -e ignore \
+	    fsck_ffs -nf -F ${IMG}
+	# have a kernel mount the fs again; it should cleanup the
+	# unlinked file
+	atf_check -o ignore -e ignore $(atf_get_srcdir)/h_quota2_tests \
+	    ${srv2args} -b 5 ${IMG} ${RUMP_SERVER}
+	#shutdown and check filesystem
+	rump_shutdown
+}

Reply via email to