1 /* $NetBSD: h_fsmacros.h,v 1.36 2012/08/20 16:39:46 pooka Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Nicolas Joly. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef __H_FSMACROS_H_ 33 #define __H_FSMACROS_H_ 34 35 #include <sys/mount.h> 36 37 #include <atf-c.h> 38 #include <puffsdump.h> 39 #include <string.h> 40 41 #include <rump/rump.h> 42 43 #include "../../h_macros.h" 44 45 #define FSPROTOS(_fs_) \ 46 int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, \ 47 off_t, void *); \ 48 int _fs_##_fstest_delfs(const atf_tc_t *, void *); \ 49 int _fs_##_fstest_mount(const atf_tc_t *, void *, const char *, int); \ 50 int _fs_##_fstest_unmount(const atf_tc_t *, const char *, int); 51 52 FSPROTOS(ext2fs); 53 FSPROTOS(ffs); 54 FSPROTOS(ffslog); 55 FSPROTOS(lfs); 56 FSPROTOS(msdosfs); 57 FSPROTOS(nfs); 58 FSPROTOS(nfsro); 59 FSPROTOS(p2k_ffs); 60 FSPROTOS(puffs); 61 FSPROTOS(rumpfs); 62 FSPROTOS(sysvbfs); 63 FSPROTOS(tmpfs); 64 FSPROTOS(v7fs); 65 FSPROTOS(zfs); 66 67 #ifndef FSTEST_IMGNAME 68 #define FSTEST_IMGNAME "image.fs" 69 #endif 70 #ifndef FSTEST_IMGSIZE 71 #define FSTEST_IMGSIZE (10000 * 512) 72 #endif 73 #ifndef FSTEST_MNTNAME 74 #define FSTEST_MNTNAME "/mnt" 75 #endif 76 77 #define FSTEST_CONSTRUCTOR(_tc_, _fs_, _args_) \ 78 do { \ 79 if (_fs_##_fstest_newfs(_tc_, &_args_, \ 80 FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) \ 81 atf_tc_fail_errno("newfs failed"); \ 82 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \ 83 atf_tc_fail_errno("mount failed"); \ 84 } while (/*CONSTCOND*/0); 85 86 #define FSTEST_CONSTRUCTOR_FSPRIV(_tc_, _fs_, _args_, _privargs_) \ 87 do { \ 88 if (_fs_##_fstest_newfs(_tc_, &_args_, \ 89 FSTEST_IMGNAME, FSTEST_IMGSIZE, _privargs_) != 0) \ 90 atf_tc_fail_errno("newfs failed"); \ 91 if (_fs_##_fstest_mount(_tc_, _args_, FSTEST_MNTNAME, 0) != 0) \ 92 atf_tc_fail_errno("mount failed"); \ 93 } while (/*CONSTCOND*/0); 94 95 #define FSTEST_DESTRUCTOR(_tc_, _fs_, _args_) \ 96 do { \ 97 if (_fs_##_fstest_unmount(_tc_, FSTEST_MNTNAME, 0) != 0) { \ 98 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \ 99 atf_tc_fail_errno("unmount failed"); \ 100 } \ 101 if (_fs_##_fstest_delfs(_tc_, _args_) != 0) \ 102 atf_tc_fail_errno("delfs failed"); \ 103 } while (/*CONSTCOND*/0); 104 105 #define ATF_TC_FSADD(fs,type,func,desc) \ 106 ATF_TC(fs##_##func); \ 107 ATF_TC_HEAD(fs##_##func,tc) \ 108 { \ 109 atf_tc_set_md_var(tc, "descr", type " test for " desc); \ 110 atf_tc_set_md_var(tc, "X-fs.type", #fs); \ 111 atf_tc_set_md_var(tc, "X-fs.mntname", type); \ 112 } \ 113 void *fs##func##tmp; \ 114 \ 115 ATF_TC_BODY(fs##_##func,tc) \ 116 { \ 117 if (!atf_check_fstype(tc, #fs)) \ 118 atf_tc_skip("filesystem not selected"); \ 119 FSTEST_CONSTRUCTOR(tc,fs,fs##func##tmp); \ 120 func(tc,FSTEST_MNTNAME); \ 121 if (fs##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) { \ 122 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \ 123 atf_tc_fail_errno("unmount failed"); \ 124 } \ 125 } 126 127 #define ATF_TC_FSADD_RO(_fs_,_type_,_func_,_desc_,_gen_) \ 128 ATF_TC(_fs_##_##_func_); \ 129 ATF_TC_HEAD(_fs_##_##_func_,tc) \ 130 { \ 131 atf_tc_set_md_var(tc, "descr",_type_" test for "_desc_);\ 132 atf_tc_set_md_var(tc, "X-fs.type", #_fs_); \ 133 atf_tc_set_md_var(tc, "X-fs.mntname", _type_); \ 134 } \ 135 void *_fs_##_func_##tmp; \ 136 \ 137 ATF_TC_BODY(_fs_##_##_func_,tc) \ 138 { \ 139 if (!atf_check_fstype(tc, #_fs_)) \ 140 atf_tc_skip("filesystem not selected"); \ 141 FSTEST_CONSTRUCTOR(tc,_fs_,_fs_##_func_##tmp); \ 142 _gen_(tc,FSTEST_MNTNAME); \ 143 if (_fs_##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) \ 144 atf_tc_fail_errno("unmount r/w failed"); \ 145 if (_fs_##_fstest_mount(tc, _fs_##_func_##tmp, \ 146 FSTEST_MNTNAME, MNT_RDONLY) != 0) \ 147 atf_tc_fail_errno("mount ro failed"); \ 148 _func_(tc,FSTEST_MNTNAME); \ 149 if (_fs_##_fstest_unmount(tc, FSTEST_MNTNAME, 0) != 0) {\ 150 rump_pub_vfs_mount_print(FSTEST_MNTNAME, 1); \ 151 atf_tc_fail_errno("unmount failed"); \ 152 } \ 153 } 154 155 #define ATF_TP_FSADD(fs,func) \ 156 ATF_TP_ADD_TC(tp,fs##_##func) 157 158 #define ATF_TC_FSAPPLY_NOZFS(func,desc) \ 159 ATF_TC_FSADD(ext2fs,MOUNT_EXT2FS,func,desc) \ 160 ATF_TC_FSADD(ffs,MOUNT_FFS,func,desc) \ 161 ATF_TC_FSADD(ffslog,MOUNT_FFS,func,desc) \ 162 ATF_TC_FSADD(lfs,MOUNT_LFS,func,desc) \ 163 ATF_TC_FSADD(msdosfs,MOUNT_MSDOS,func,desc) \ 164 ATF_TC_FSADD(nfs,MOUNT_NFS,func,desc) \ 165 ATF_TC_FSADD(puffs,MOUNT_PUFFS,func,desc) \ 166 ATF_TC_FSADD(p2k_ffs,MOUNT_PUFFS,func,desc) \ 167 ATF_TC_FSADD(rumpfs,MOUNT_RUMPFS,func,desc) \ 168 ATF_TC_FSADD(sysvbfs,MOUNT_SYSVBFS,func,desc) \ 169 ATF_TC_FSADD(tmpfs,MOUNT_TMPFS,func,desc) \ 170 ATF_TC_FSADD(v7fs,MOUNT_V7FS,func,desc) 171 172 #define ATF_TP_FSAPPLY_NOZFS(func) \ 173 ATF_TP_FSADD(ext2fs,func); \ 174 ATF_TP_FSADD(ffs,func); \ 175 ATF_TP_FSADD(ffslog,func); \ 176 ATF_TP_FSADD(lfs,func); \ 177 ATF_TP_FSADD(msdosfs,func); \ 178 ATF_TP_FSADD(nfs,func); \ 179 ATF_TP_FSADD(puffs,func); \ 180 ATF_TP_FSADD(p2k_ffs,func); \ 181 ATF_TP_FSADD(rumpfs,func); \ 182 ATF_TP_FSADD(sysvbfs,func); \ 183 ATF_TP_FSADD(tmpfs,func); \ 184 ATF_TP_FSADD(v7fs,func); 185 186 /* XXX: this will not scale */ 187 #ifdef WANT_ZFS_TESTS 188 #define ATF_TC_FSAPPLY(func,desc) \ 189 ATF_TC_FSAPPLY_NOZFS(func,desc) \ 190 ATF_TC_FSADD(zfs,MOUNT_ZFS,func,desc) 191 #define ATF_TP_FSAPPLY(func) \ 192 ATF_TP_FSAPPLY_NOZFS(func) \ 193 ATF_TP_FSADD(zfs,func); 194 195 #else /* !WANT_ZFS_TESTS */ 196 197 #define ATF_TC_FSAPPLY(func,desc) \ 198 ATF_TC_FSAPPLY_NOZFS(func,desc) 199 #define ATF_TP_FSAPPLY(func) \ 200 ATF_TP_FSAPPLY_NOZFS(func) 201 202 #endif /* WANT_ZFS_TESTS */ 203 204 /* 205 * Same as above, but generate a file system image first and perform 206 * tests for a r/o mount. 207 * 208 * Missing the following file systems: 209 * + lfs (fstest_lfs routines cannot handle remount. FIXME!) 210 * + tmpfs (memory backend) 211 * + rumpfs (memory backend) 212 * + puffs (memory backend, but could be run in theory) 213 */ 214 215 #define ATF_TC_FSAPPLY_RO(func,desc,gen) \ 216 ATF_TC_FSADD_RO(ext2fs,MOUNT_EXT2FS,func,desc,gen) \ 217 ATF_TC_FSADD_RO(ffs,MOUNT_FFS,func,desc,gen) \ 218 ATF_TC_FSADD_RO(ffslog,MOUNT_FFS,func,desc,gen) \ 219 ATF_TC_FSADD_RO(msdosfs,MOUNT_MSDOS,func,desc,gen) \ 220 ATF_TC_FSADD_RO(nfs,MOUNT_NFS,func,desc,gen) \ 221 ATF_TC_FSADD_RO(nfsro,MOUNT_NFS,func,desc,gen) \ 222 ATF_TC_FSADD_RO(sysvbfs,MOUNT_SYSVBFS,func,desc,gen) \ 223 ATF_TC_FSADD_RO(v7fs,MOUNT_V7FS,func,desc,gen) 224 225 #define ATF_TP_FSAPPLY_RO(func) \ 226 ATF_TP_FSADD(ext2fs,func); \ 227 ATF_TP_FSADD(ffs,func); \ 228 ATF_TP_FSADD(ffslog,func); \ 229 ATF_TP_FSADD(msdosfs,func); \ 230 ATF_TP_FSADD(nfs,func); \ 231 ATF_TP_FSADD(nfsro,func); \ 232 ATF_TP_FSADD(sysvbfs,func); \ 233 ATF_TP_FSADD(v7fs,func); 234 235 #define ATF_FSAPPLY(func,desc) \ 236 ATF_TC_FSAPPLY(func,desc); \ 237 ATF_TP_ADD_TCS(tp) \ 238 { \ 239 ATF_TP_FSAPPLY(func); \ 240 return atf_no_error(); \ 241 } 242 243 static __inline bool 244 atf_check_fstype(const atf_tc_t *tc, const char *fs) 245 { 246 const char *fstype; 247 248 if (!atf_tc_has_config_var(tc, "fstype")) 249 return true; 250 251 fstype = atf_tc_get_config_var(tc, "fstype"); 252 if (strcmp(fstype, fs) == 0) 253 return true; 254 return false; 255 } 256 257 #define FSTYPE_EXT2FS(tc)\ 258 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "ext2fs") == 0) 259 #define FSTYPE_FFS(tc)\ 260 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "ffs") == 0) 261 #define FSTYPE_FFSLOG(tc)\ 262 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "ffslog") == 0) 263 #define FSTYPE_LFS(tc)\ 264 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "lfs") == 0) 265 #define FSTYPE_MSDOS(tc)\ 266 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "msdosfs") == 0) 267 #define FSTYPE_NFS(tc)\ 268 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "nfs") == 0) 269 #define FSTYPE_NFSRO(tc)\ 270 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "nfsro") == 0) 271 #define FSTYPE_P2K_FFS(tc)\ 272 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "p2k_ffs") == 0) 273 #define FSTYPE_PUFFS(tc)\ 274 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "puffs") == 0) 275 #define FSTYPE_RUMPFS(tc)\ 276 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "rumpfs") == 0) 277 #define FSTYPE_SYSVBFS(tc)\ 278 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "sysvbfs") == 0) 279 #define FSTYPE_TMPFS(tc)\ 280 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "tmpfs") == 0) 281 #define FSTYPE_V7FS(tc)\ 282 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "v7fs") == 0) 283 #define FSTYPE_ZFS(tc)\ 284 (strcmp(atf_tc_get_md_var(tc, "X-fs.type"), "zfs") == 0) 285 286 #define FSTEST_ENTER() \ 287 if (rump_sys_chdir(FSTEST_MNTNAME) == -1) \ 288 atf_tc_fail_errno("failed to cd into test mount") 289 290 #define FSTEST_EXIT() \ 291 if (rump_sys_chdir("/") == -1) \ 292 atf_tc_fail_errno("failed to cd out of test mount") 293 294 /* 295 * file system args structures 296 */ 297 298 struct nfstestargs { 299 pid_t ta_childpid; 300 char ta_ethername[MAXPATHLEN]; 301 }; 302 303 struct puffstestargs { 304 uint8_t *pta_pargs; 305 size_t pta_pargslen; 306 307 int pta_pflags; 308 pid_t pta_childpid; 309 310 int pta_rumpfd; 311 int pta_servfd; 312 313 char pta_dev[MAXPATHLEN]; 314 char pta_dir[MAXPATHLEN]; 315 316 int pta_mntflags; 317 318 int pta_vfs_toserv_ops[PUFFS_VFS_MAX]; 319 int pta_vn_toserv_ops[PUFFS_VN_MAX]; 320 }; 321 322 #endif /* __H_FSMACROS_H_ */ 323