t_quota2_remount.c revision 1.2 1 /* $NetBSD: t_quota2_remount.c,v 1.2 2011/03/06 17:08:40 bouyer 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 snprintf(buf, sizeof(buf), "fsck returned %d", res);
100 atf_tc_fail(buf);
101 }
102 }
103
104 #define DECL_TEST(nent, newops, name, descr, log) \
105 ATF_TC(quota_##name); \
106 \
107 ATF_TC_HEAD(quota_##name, tc) \
108 { \
109 char buf[1000]; \
110 snprintf(buf, sizeof(buf), "test filesystem remount with quotas, " \
111 descr); \
112 atf_tc_set_md_var(tc, "descr", buf); \
113 } \
114 \
115 ATF_TC_BODY(quota_##name, tc) \
116 { \
117 do_quota(tc, nent, newops, log); \
118 }
119
120 DECL_TEST(10, "-O1 -B le", 10_O1_le, "UFS1 little-endian", 0)
121 DECL_TEST(10, "-O1 -B be", 10_O1_be, "UFS1 big-endian", 0)
122
123 #if 0
124 /*
125 * this cause fsck to complain about summaries at the end.
126 * This sems to be related to -o log (reproductible on a fs with no
127 * quota enabled). not reproductible with a real kernel ...
128 */
129 DECL_TEST(10, "-O1", 10_O1_log, "UFS1 log", 1)
130 DECL_TEST(10, "-O2", 10_O2_log, "UFS2 log", 1)
131 #endif
132
133 ATF_TP_ADD_TCS(tp)
134 {
135
136 ATF_TP_ADD_TC(tp, quota_10_O1_le);
137 ATF_TP_ADD_TC(tp, quota_10_O1_be);
138 #if 0
139 ATF_TP_ADD_TC(tp, quota_10_O1_log);
140 ATF_TP_ADD_TC(tp, quota_10_O2_log);
141 #endif
142 return atf_no_error();
143 }
144