1 /* $NetBSD: t_basic.c,v 1.3 2010/06/09 08:37:16 pooka Exp $ */
15 #include <rump/rump.h>
16 #include <rump/rump_syscalls.h>
18 #include <miscfs/nullfs/null.h>
19 #include <fs/tmpfs/tmpfs_args.h>
21 #include "../../h_macros.h"
24 ATF_TC_HEAD(basic
, tc
)
26 atf_tc_set_md_var(tc
, "descr", "basic nullfs functionality");
29 #define MSTR "magic bus"
32 xput_tfile(const char *path
, const char *mstr
)
36 fd
= rump_sys_open(path
, O_CREAT
| O_RDWR
, 0777);
38 atf_tc_fail_errno("create %s", path
);
39 if (rump_sys_write(fd
, MSTR
, sizeof(MSTR
)) != sizeof(MSTR
))
40 atf_tc_fail_errno("write to testfile");
45 xread_tfile(const char *path
, const char *mstr
)
50 fd
= rump_sys_open(path
, O_RDONLY
);
53 if (rump_sys_read(fd
, buf
, sizeof(buf
)) == -1)
54 atf_tc_fail_errno("read tfile");
56 if (strcmp(buf
, MSTR
) == 0)
62 mountnull(const char *what
, const char *mp
, int flags
)
64 struct null_args nargs
;
66 memset(&nargs
, 0, sizeof(nargs
));
67 nargs
.nulla_target
= __UNCONST(what
);
68 if (rump_sys_mount(MOUNT_NULL
, mp
, flags
, &nargs
, sizeof(nargs
)) == -1)
69 atf_tc_fail_errno("could not mount nullfs");
73 ATF_TC_BODY(basic
, tc
)
75 struct tmpfs_args targs
;
80 if (rump_sys_mkdir("/td1", 0777) == -1)
81 atf_tc_fail_errno("mp1");
82 if (rump_sys_mkdir("/td2", 0777) == -1)
83 atf_tc_fail_errno("mp1");
85 /* use tmpfs because rumpfs doesn't support regular files */
86 memset(&targs
, 0, sizeof(targs
));
87 targs
.ta_version
= TMPFS_ARGS_VERSION
;
88 targs
.ta_root_mode
= 0777;
89 if (rump_sys_mount(MOUNT_TMPFS
, "/td1", 0, &targs
, sizeof(targs
)) == -1)
90 atf_tc_fail_errno("could not mount tmpfs td1");
92 mountnull("/td1", "/td2", 0);
94 /* test unnull -> null */
95 xput_tfile("/td1/tensti", "jeppe");
96 error
= xread_tfile("/td2/tensti", "jeppe");
98 atf_tc_fail("null compare failed: %d (%s)",
99 error
, strerror(error
));
101 /* test null -> unnull */
102 xput_tfile("/td2/kiekko", "keppi");
103 error
= xread_tfile("/td1/kiekko", "keppi");
105 atf_tc_fail("unnull compare failed: %d (%s)",
106 error
, strerror(error
));
108 /* test unnull -> null overwrite */
109 xput_tfile("/td1/tensti", "se oolannin sota");
110 error
= xread_tfile("/td2/tensti", "se oolannin sota");
112 atf_tc_fail("unnull compare failed: %d (%s)",
113 error
, strerror(error
));
115 /* test that /td2 is unaffected in "real life" */
116 if (rump_sys_unmount("/td2", 0) == -1)
117 atf_tc_fail_errno("cannot unmount nullfs");
118 if ((error
= rump_sys_stat("/td2/tensti", &sb
)) != -1
119 || errno
!= ENOENT
) {
120 atf_tc_fail("stat tensti should return ENOENT, got %d", error
);
122 if ((error
= rump_sys_stat("/td2/kiekko", &sb
)) != -1
123 || errno
!= ENOENT
) {
124 atf_tc_fail("stat kiekko should return ENOENT, got %d", error
);
131 ATF_TC_HEAD(twistymount
, tc
)
134 /* this is expected to fail until the PR is fixed */
135 atf_tc_set_md_var(tc
, "descr", "\"recursive\" mounts deadlock"
140 * Mapping to identifiers in kern/43439:
141 * /td = /home/current/pkgsrc
142 * /td/dist = /home/current/pkgsrc/distiles
144 * /mp/dist = /usr/pkgsrc/distfiles -- "created" by first null mount
147 ATF_TC_BODY(twistymount
, tc
)
153 if (rump_sys_mkdir("/td", 0777) == -1)
154 atf_tc_fail_errno("mkdir %d", mkd
++);
155 if (rump_sys_mkdir("/td/dist", 0777) == -1)
156 atf_tc_fail_errno("mkdir %d", mkd
++);
157 if (rump_sys_mkdir("/mp", 0777) == -1)
158 atf_tc_fail_errno("mkdir %d", mkd
++);
160 /* MNT_RDONLY doesn't matter, but just for compat with the PR */
161 mountnull("/td", "/mp", MNT_RDONLY
);
162 mountnull("/td/dist", "/mp/dist", 0);
164 /* if we didn't get a locking-against-meself panic, we passed */
170 ATF_TP_ADD_TC(tp
, basic
);
171 ATF_TP_ADD_TC(tp
, twistymount
);
173 return atf_no_error();