Module Name:    src
Committed By:   bouyer
Date:           Wed Feb  9 20:53:10 UTC 2011

Modified Files:
        src/distrib/sets/lists/tests [bouyer-quota2]: mi
        src/tests/fs/ffs [bouyer-quota2]: Makefile
Added Files:
        src/tests/fs/ffs [bouyer-quota2]: t_quota2_remount.c

Log Message:
Check that upgrading a R/O to R/W mount will properly enable quota2.


To generate a diff of this commit:
cvs rdiff -u -r1.240.2.2 -r1.240.2.3 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.14.2.5 -r1.14.2.6 src/tests/fs/ffs/Makefile
cvs rdiff -u -r0 -r1.1.2.1 src/tests/fs/ffs/t_quota2_remount.c

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

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.240.2.2 src/distrib/sets/lists/tests/mi:1.240.2.3
--- src/distrib/sets/lists/tests/mi:1.240.2.2	Wed Feb  9 10:51:03 2011
+++ src/distrib/sets/lists/tests/mi	Wed Feb  9 20:53:10 2011
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.240.2.2 2011/02/09 10:51:03 bouyer Exp $
+# $NetBSD: mi,v 1.240.2.3 2011/02/09 20:53:10 bouyer Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1186,6 +1186,7 @@
 ./usr/tests/fs/ffs/t_clearquota			tests-fs-tests		atf
 ./usr/tests/fs/ffs/t_getquota			tests-fs-tests		atf
 ./usr/tests/fs/ffs/t_quota2_1			tests-fs-tests		atf
+./usr/tests/fs/ffs/t_quota2_remount		tests-fs-tests		atf
 ./usr/tests/fs/ffs/t_quotalimit			tests-fs-tests		atf
 ./usr/tests/fs/ffs/t_setquota			tests-fs-tests		atf
 ./usr/tests/fs/kernfs				tests-fs-tests

Index: src/tests/fs/ffs/Makefile
diff -u src/tests/fs/ffs/Makefile:1.14.2.5 src/tests/fs/ffs/Makefile:1.14.2.6
--- src/tests/fs/ffs/Makefile:1.14.2.5	Mon Feb  7 20:31:46 2011
+++ src/tests/fs/ffs/Makefile	Wed Feb  9 20:53:10 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.14.2.5 2011/02/07 20:31:46 bouyer Exp $
+#	$NetBSD: Makefile,v 1.14.2.6 2011/02/09 20:53:10 bouyer Exp $
 #
 
 .include <bsd.own.mk>
@@ -28,6 +28,7 @@
 TESTS_C+=	t_snapshot_v2
 TESTS_C+=	t_mount
 TESTS_C+=	t_quota2_1
+TESTS_C+=	t_quota2_remount
 
 LDADD+=-lrumpfs_ffs						# ffs
 LDADD+=-lrumpdev_fss						# snapshot dev

Added files:

Index: src/tests/fs/ffs/t_quota2_remount.c
diff -u /dev/null src/tests/fs/ffs/t_quota2_remount.c:1.1.2.1
--- /dev/null	Wed Feb  9 20:53:10 2011
+++ src/tests/fs/ffs/t_quota2_remount.c	Wed Feb  9 20:53:10 2011
@@ -0,0 +1,143 @@
+/*	$NetBSD: t_quota2_remount.c,v 1.1.2.1 2011/02/09 20:53:10 bouyer Exp $	*/
+
+/*
+ * Basic tests for quota2
+ */
+
+#include <atf-c.h>
+
+#include "../common/h_fsmacros.h"
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/statvfs.h>
+
+#include <stdlib.h>
+
+#include <ufs/ufs/ufsmount.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include "../../h_macros.h"
+
+static void
+do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
+{
+	int i;
+	char buf[1024];
+	int res;
+	int fd;
+	struct ufs_args uargs;
+	struct statvfs fst;
+	
+	snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
+	    "%s %s", (n + 3),  newfs_opts, FSTEST_IMGNAME);
+        if (system(buf) == -1)
+                atf_tc_fail_errno("cannot create file system");
+
+	rump_init();
+	if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
+		atf_tc_fail_errno("mount point create");
+
+	rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);
+
+	uargs.fspec = __UNCONST("/diskdev");
+
+	/* read-only doens't have quota enabled */
+	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_RDONLY,
+	    &uargs, sizeof(uargs)) == -1)
+		atf_tc_fail_errno("mount ffs ro %s", FSTEST_MNTNAME);
+
+	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+		atf_tc_fail_errno("statbfs %s (1)", FSTEST_MNTNAME);
+
+	if ((fst.f_flag & ST_QUOTA) != 0)
+		atf_tc_fail("R/O filesystem has quota");
+
+	/* updating to read-write enables quota */
+	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+	    MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
+		atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);
+	
+	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+		atf_tc_fail_errno("statbfs %s (2)", FSTEST_MNTNAME);
+
+	if ((fst.f_flag & ST_QUOTA) == 0)
+		atf_tc_fail("R/W filesystem has no quota");
+
+	/* we can update a second time  */
+	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
+	    MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
+		atf_tc_fail_errno("mount ffs rw(2) %s", FSTEST_MNTNAME);
+	
+	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
+		atf_tc_fail_errno("statbfs %s (3)", FSTEST_MNTNAME);
+
+	if ((fst.f_flag & ST_QUOTA) == 0)
+		atf_tc_fail("R/W filesystem has no quota");
+
+	/* create some files so fsck has something to check */
+	FSTEST_ENTER();
+	RL(rump_sys_chown(".", 0, 0));
+	for (i = 0 ; i < n; i++) {
+		sprintf(buf, "file%d", i);
+		RL(fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0755));
+		sprintf(buf, "test file no %d", i);
+		RL(rump_sys_write(fd, buf, strlen(buf)));
+		RL(rump_sys_fchown(fd, i, i+80000));
+		rump_sys_close(fd);
+	}
+	FSTEST_EXIT();
+	if (rump_sys_unmount(FSTEST_MNTNAME, 0) != 0) {
+		rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);
+		atf_tc_fail_errno("unmount failed");
+	}
+	snprintf(buf, 1024, "fsck_ffs -fn -F %s",  FSTEST_IMGNAME);
+	res = system(buf);
+	if (res != 0) {
+		snprintf(buf, sizeof(buf), "fsck returned %d", res);
+		atf_tc_fail(buf);
+	}
+}
+
+#define DECL_TEST(nent, newops, name, descr, log) \
+ATF_TC(quota_##name);							\
+									\
+ATF_TC_HEAD(quota_##name, tc)						\
+{									\
+	char buf[1000];							\
+	snprintf(buf, sizeof(buf), "test filesystem remount with quotas, " \
+	    descr);						\
+	atf_tc_set_md_var(tc, "descr", buf);				\
+}									\
+									\
+ATF_TC_BODY(quota_##name, tc)						\
+{									\
+	do_quota(tc, nent, newops, log);				\
+}
+
+DECL_TEST(10, "-O1 -B le", 10_O1_le, "UFS1 little-endian", 0)
+DECL_TEST(10, "-O1 -B be", 10_O1_be, "UFS1 big-endian", 0)
+
+#if 0
+/*
+ * this cause fsck to complain about summaries at the end.
+ * This sems to be related to -o log (reproductible on a fs with no
+ * quota enabled). not reproductible with a real kernel ...
+ */
+DECL_TEST(10, "-O1", 10_O1_log, "UFS1 log", 1)
+DECL_TEST(10, "-O2", 10_O2_log, "UFS2 log", 1)
+#endif
+
+ATF_TP_ADD_TCS(tp)
+{
+
+	ATF_TP_ADD_TC(tp, quota_10_O1_le);
+	ATF_TP_ADD_TC(tp, quota_10_O1_be);
+#if 0
+	ATF_TP_ADD_TC(tp, quota_10_O1_log);
+	ATF_TP_ADD_TC(tp, quota_10_O2_log);
+#endif
+	return atf_no_error();
+}

Reply via email to