t_unmount.c revision 1.2 1 /* $NetBSD: t_unmount.c,v 1.2 2024/08/10 14:44:54 bad Exp $ */
2
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29 #include <sys/cdefs.h>
30 __COPYRIGHT("@(#) Copyright (c) 2024\
31 The NetBSD Foundation, inc. All rights reserved.");
32 __RCSID("$NetBSD: t_unmount.c,v 1.2 2024/08/10 14:44:54 bad Exp $");
33
34 #include <sys/types.h>
35 #include <sys/mount.h>
36 #include <sys/vnode.h>
37
38 #include <rump/rump.h>
39 #include <rump/rumpvnode_if.h>
40 #include <rump/rump_syscalls.h>
41
42 #include <fs/tmpfs/tmpfs_args.h>
43
44 #include <atf-c.h>
45 #include <errno.h>
46 #include <stdio.h>
47
48 #include "h_macros.h"
49
50 ATF_TC(async);
51 ATF_TC_HEAD(async, tc)
52 {
53 atf_tc_set_md_var(tc,
54 "descr", "failed unmount of async fs should stay async");
55 }
56
57 #define MP "/mnt"
58
59 ATF_TC_BODY(async, tc)
60 {
61 struct tmpfs_args args;
62 struct vnode *vp;
63 extern struct vnode *rumpns_rootvnode;
64
65 RZ(rump_init());
66
67 memset(&args, 0, sizeof(args));
68 args.ta_version = TMPFS_ARGS_VERSION;
69 args.ta_root_mode = 0777;
70
71 /* create mount point and mount a tmpfs on it */
72 RL(rump_sys_mkdir(MP, 0777));
73 RL(rump_sys_mount(MOUNT_TMPFS, MP, MNT_ASYNC, &args, sizeof(args)));
74
75 /* make sure the tmpfs is busy */
76 RL(rump_sys_chdir(MP));
77
78 /* need a stable lwp for componentname */
79 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG));
80
81 /* get vnode of MP, unlocked */
82 RZ(rump_pub_namei(RUMP_NAMEI_LOOKUP, 0, MP, NULL, &vp, NULL));
83
84 /* make sure we didn't just get the root vnode */
85 ATF_REQUIRE_MSG((rumpns_rootvnode != vp), "drat! got the root vnode");
86
87 printf("mnt_iflag & IMNT_ONWORKLIST == %d\n",
88 (vp->v_mount->mnt_iflag & IMNT_ONWORKLIST) != 0);
89
90 /* can't unmount a busy file system */
91 ATF_REQUIRE_ERRNO(EBUSY, rump_sys_unmount(MP, 0) == -1);
92
93 printf("mnt_iflag & IMNT_ONWORKLIST == %d\n",
94 (vp->v_mount->mnt_iflag & IMNT_ONWORKLIST) != 0);
95
96
97 atf_tc_expect_fail("mount point on syncer work list. PR kern/58564");
98 ATF_REQUIRE_MSG(((vp->v_mount->mnt_iflag & IMNT_ONWORKLIST) == 0),
99 "mount point on syncer work list");
100 }
101
102 ATF_TP_ADD_TCS(tp)
103 {
104 ATF_TP_ADD_TC(tp, async);
105
106 return atf_no_error();
107 }
108