Home | History | Annotate | Line # | Download | only in ffs
t_quota2_remount.c revision 1.4
      1  1.4   joerg /*	$NetBSD: t_quota2_remount.c,v 1.4 2012/03/15 02:02:22 joerg Exp $	*/
      2  1.2  bouyer 
      3  1.2  bouyer /*
      4  1.2  bouyer  * Basic tests for quota2
      5  1.2  bouyer  */
      6  1.2  bouyer 
      7  1.2  bouyer #include <atf-c.h>
      8  1.2  bouyer 
      9  1.2  bouyer #include "../common/h_fsmacros.h"
     10  1.2  bouyer 
     11  1.2  bouyer #include <sys/types.h>
     12  1.2  bouyer #include <sys/mount.h>
     13  1.2  bouyer #include <sys/statvfs.h>
     14  1.2  bouyer 
     15  1.2  bouyer #include <stdlib.h>
     16  1.2  bouyer 
     17  1.2  bouyer #include <ufs/ufs/ufsmount.h>
     18  1.2  bouyer 
     19  1.2  bouyer #include <rump/rump.h>
     20  1.2  bouyer #include <rump/rump_syscalls.h>
     21  1.2  bouyer 
     22  1.2  bouyer #include "../../h_macros.h"
     23  1.2  bouyer 
     24  1.2  bouyer static void
     25  1.2  bouyer do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log)
     26  1.2  bouyer {
     27  1.2  bouyer 	int i;
     28  1.2  bouyer 	char buf[1024];
     29  1.2  bouyer 	int res;
     30  1.2  bouyer 	int fd;
     31  1.2  bouyer 	struct ufs_args uargs;
     32  1.2  bouyer 	struct statvfs fst;
     33  1.2  bouyer 
     34  1.2  bouyer 	snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
     35  1.2  bouyer 	    "%s %s", (n + 3),  newfs_opts, FSTEST_IMGNAME);
     36  1.2  bouyer         if (system(buf) == -1)
     37  1.2  bouyer                 atf_tc_fail_errno("cannot create file system");
     38  1.2  bouyer 
     39  1.2  bouyer 	rump_init();
     40  1.2  bouyer 	if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
     41  1.2  bouyer 		atf_tc_fail_errno("mount point create");
     42  1.2  bouyer 
     43  1.2  bouyer 	rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);
     44  1.2  bouyer 
     45  1.2  bouyer 	uargs.fspec = __UNCONST("/diskdev");
     46  1.2  bouyer 
     47  1.2  bouyer 	/* read-only doens't have quota enabled */
     48  1.2  bouyer 	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_RDONLY,
     49  1.2  bouyer 	    &uargs, sizeof(uargs)) == -1)
     50  1.2  bouyer 		atf_tc_fail_errno("mount ffs ro %s", FSTEST_MNTNAME);
     51  1.2  bouyer 
     52  1.2  bouyer 	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
     53  1.2  bouyer 		atf_tc_fail_errno("statbfs %s (1)", FSTEST_MNTNAME);
     54  1.2  bouyer 
     55  1.2  bouyer 	if ((fst.f_flag & ST_QUOTA) != 0)
     56  1.2  bouyer 		atf_tc_fail("R/O filesystem has quota");
     57  1.2  bouyer 
     58  1.2  bouyer 	/* updating to read-write enables quota */
     59  1.2  bouyer 	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
     60  1.2  bouyer 	    MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
     61  1.2  bouyer 		atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);
     62  1.2  bouyer 
     63  1.2  bouyer 	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
     64  1.2  bouyer 		atf_tc_fail_errno("statbfs %s (2)", FSTEST_MNTNAME);
     65  1.2  bouyer 
     66  1.2  bouyer 	if ((fst.f_flag & ST_QUOTA) == 0)
     67  1.2  bouyer 		atf_tc_fail("R/W filesystem has no quota");
     68  1.2  bouyer 
     69  1.2  bouyer 	/* we can update a second time  */
     70  1.2  bouyer 	if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME,
     71  1.2  bouyer 	    MNT_UPDATE | (log ? MNT_LOG : 0), &uargs, sizeof(uargs)) == -1)
     72  1.2  bouyer 		atf_tc_fail_errno("mount ffs rw(2) %s", FSTEST_MNTNAME);
     73  1.2  bouyer 
     74  1.2  bouyer 	if (rump_sys_statvfs1(FSTEST_MNTNAME, &fst, 0) != 0)
     75  1.2  bouyer 		atf_tc_fail_errno("statbfs %s (3)", FSTEST_MNTNAME);
     76  1.2  bouyer 
     77  1.2  bouyer 	if ((fst.f_flag & ST_QUOTA) == 0)
     78  1.2  bouyer 		atf_tc_fail("R/W filesystem has no quota");
     79  1.2  bouyer 
     80  1.2  bouyer 	/* create some files so fsck has something to check */
     81  1.2  bouyer 	FSTEST_ENTER();
     82  1.2  bouyer 	RL(rump_sys_chown(".", 0, 0));
     83  1.2  bouyer 	for (i = 0 ; i < n; i++) {
     84  1.2  bouyer 		sprintf(buf, "file%d", i);
     85  1.2  bouyer 		RL(fd = rump_sys_open(buf, O_CREAT | O_RDWR, 0755));
     86  1.2  bouyer 		sprintf(buf, "test file no %d", i);
     87  1.2  bouyer 		RL(rump_sys_write(fd, buf, strlen(buf)));
     88  1.2  bouyer 		RL(rump_sys_fchown(fd, i, i+80000));
     89  1.2  bouyer 		rump_sys_close(fd);
     90  1.2  bouyer 	}
     91  1.2  bouyer 	FSTEST_EXIT();
     92  1.2  bouyer 	if (rump_sys_unmount(FSTEST_MNTNAME, 0) != 0) {
     93  1.2  bouyer 		rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1);
     94  1.2  bouyer 		atf_tc_fail_errno("unmount failed");
     95  1.2  bouyer 	}
     96  1.2  bouyer 	snprintf(buf, 1024, "fsck_ffs -fn -F %s",  FSTEST_IMGNAME);
     97  1.2  bouyer 	res = system(buf);
     98  1.3   joerg 	if (res != 0)
     99  1.3   joerg 		atf_tc_fail("fsck returned %d", res);
    100  1.2  bouyer }
    101  1.2  bouyer 
    102  1.2  bouyer #define DECL_TEST(nent, newops, name, descr, log) \
    103  1.2  bouyer ATF_TC(quota_##name);							\
    104  1.2  bouyer 									\
    105  1.2  bouyer ATF_TC_HEAD(quota_##name, tc)						\
    106  1.2  bouyer {									\
    107  1.4   joerg 	atf_tc_set_md_var(tc, "descr", 					\
    108  1.4   joerg 	    "test filesystem remount with quotas, %s", descr);		\
    109  1.2  bouyer }									\
    110  1.2  bouyer 									\
    111  1.2  bouyer ATF_TC_BODY(quota_##name, tc)						\
    112  1.2  bouyer {									\
    113  1.2  bouyer 	do_quota(tc, nent, newops, log);				\
    114  1.2  bouyer }
    115  1.2  bouyer 
    116  1.2  bouyer DECL_TEST(10, "-O1 -B le", 10_O1_le, "UFS1 little-endian", 0)
    117  1.2  bouyer DECL_TEST(10, "-O1 -B be", 10_O1_be, "UFS1 big-endian", 0)
    118  1.2  bouyer 
    119  1.2  bouyer #if 0
    120  1.2  bouyer /*
    121  1.2  bouyer  * this cause fsck to complain about summaries at the end.
    122  1.2  bouyer  * This sems to be related to -o log (reproductible on a fs with no
    123  1.2  bouyer  * quota enabled). not reproductible with a real kernel ...
    124  1.2  bouyer  */
    125  1.2  bouyer DECL_TEST(10, "-O1", 10_O1_log, "UFS1 log", 1)
    126  1.2  bouyer DECL_TEST(10, "-O2", 10_O2_log, "UFS2 log", 1)
    127  1.2  bouyer #endif
    128  1.2  bouyer 
    129  1.2  bouyer ATF_TP_ADD_TCS(tp)
    130  1.2  bouyer {
    131  1.2  bouyer 
    132  1.2  bouyer 	ATF_TP_ADD_TC(tp, quota_10_O1_le);
    133  1.2  bouyer 	ATF_TP_ADD_TC(tp, quota_10_O1_be);
    134  1.2  bouyer #if 0
    135  1.2  bouyer 	ATF_TP_ADD_TC(tp, quota_10_O1_log);
    136  1.2  bouyer 	ATF_TP_ADD_TC(tp, quota_10_O2_log);
    137  1.2  bouyer #endif
    138  1.2  bouyer 	return atf_no_error();
    139  1.2  bouyer }
    140