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