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