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