t_pr.c revision 1.4 1 /* $NetBSD: t_pr.c,v 1.4 2010/07/03 12:08:37 pooka Exp $ */
2
3 #include <sys/types.h>
4 #include <sys/mount.h>
5
6 #include <atf-c.h>
7 #include <err.h>
8 #include <errno.h>
9 #include <fcntl.h>
10 #include <stdio.h>
11 #include <unistd.h>
12 #include <string.h>
13 #include <stdlib.h>
14
15 #include <rump/rump.h>
16 #include <rump/rump_syscalls.h>
17
18 #include <miscfs/union/union.h>
19 #include <ufs/ufs/ufsmount.h>
20
21 #include "../../h_macros.h"
22
23 ATF_TC(multilayer);
24 ATF_TC_HEAD(multilayer, tc)
25 {
26 atf_tc_set_md_var(tc, "descr", "mount_union -b twice");
27 atf_tc_set_md_var(tc, "use.fs", "true");
28 }
29
30 #define IMG1 "atf1.img"
31 #define DEV1 "/dev/fs1"
32 #define newfs_base "newfs -F -s 10000 "
33
34 ATF_TC_BODY(multilayer, tc)
35 {
36 struct ufs_args args;
37 struct union_args unionargs;
38
39 if (system(newfs_base IMG1) == -1)
40 atf_tc_fail_errno("create img1");
41
42 rump_init();
43 rump_pub_etfs_register(DEV1, IMG1, RUMP_ETFS_BLK);
44
45 memset(&args, 0, sizeof(args));
46 args.fspec = __UNCONST(DEV1);
47 if (rump_sys_mount(MOUNT_FFS, "/", 0, &args, sizeof(args)) == -1)
48 atf_tc_fail_errno("could not mount root");
49
50 if (rump_sys_mkdir("/Tunion", 0777) == -1)
51 atf_tc_fail_errno("mkdir mp1");
52 if (rump_sys_mkdir("/Tunion2", 0777) == -1)
53 atf_tc_fail_errno("mkdir mp2");
54 if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
55 atf_tc_fail_errno("mkdir A");
56 if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
57 atf_tc_fail_errno("mkdir B");
58
59 unionargs.target = __UNCONST("/Tunion2/A");
60 unionargs.mntflags = UNMNT_BELOW;
61
62 if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
63 &unionargs, sizeof(unionargs)) == -1)
64 atf_tc_fail_errno("union mount");
65
66 unionargs.target = __UNCONST("/Tunion2/B");
67 unionargs.mntflags = UNMNT_BELOW;
68
69 /* BADABOOM */
70 /* atf_tc_expect_signal(-1, "PR kern/23986"); */
71 rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
72 }
73
74 ATF_TC(devnull1);
75 ATF_TC_HEAD(devnull1, tc)
76 {
77 atf_tc_set_md_var(tc, "descr", "mount_union -b and "
78 "'echo x > /un/null'");
79 }
80
81 ATF_TC_BODY(devnull1, tc)
82 {
83 struct union_args unionargs;
84 int fd;
85
86 rump_init();
87
88 if (rump_sys_mkdir("/mp", 0777) == -1)
89 atf_tc_fail_errno("mkdir mp");
90
91 unionargs.target = __UNCONST("/dev");
92 unionargs.mntflags = UNMNT_BELOW;
93
94 if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
95 &unionargs, sizeof(unionargs)) == -1)
96 atf_tc_fail_errno("union mount");
97
98 fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
99
100 atf_tc_expect_fail("PR kern/43560");
101 if (fd == -1)
102 atf_tc_fail_errno("open");
103 }
104
105 ATF_TC(devnull2);
106 ATF_TC_HEAD(devnull2, tc)
107 {
108 atf_tc_set_md_var(tc, "descr", "mount_union -b and "
109 "'echo x >> /un/null'");
110 }
111
112 ATF_TC_BODY(devnull2, tc)
113 {
114 struct union_args unionargs;
115 int fd;
116
117 rump_init();
118
119 if (rump_sys_mkdir("/mp", 0777) == -1)
120 atf_tc_fail_errno("mkdir mp");
121
122 unionargs.target = __UNCONST("/dev");
123 unionargs.mntflags = UNMNT_BELOW;
124
125 if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
126 &unionargs, sizeof(unionargs)) == -1)
127 atf_tc_fail_errno("union mount");
128
129 fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
130 if (fd == -1)
131 atf_tc_fail_errno("open");
132
133 atf_tc_expect_signal(-1, "PR kern/43560");
134 rump_sys_write(fd, &fd, sizeof(fd));
135 }
136
137 ATF_TP_ADD_TCS(tp)
138 {
139 ATF_TP_ADD_TC(tp, multilayer);
140 ATF_TP_ADD_TC(tp, devnull1);
141 ATF_TP_ADD_TC(tp, devnull2);
142
143 return atf_no_error();
144 }
145