1 /* $NetBSD: t_vnops.c,v 1.13 2011/01/31 10:01:26 pooka 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 CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #include <sys/stat.h> 30 #include <sys/statvfs.h> 31 32 #include <assert.h> 33 #include <atf-c.h> 34 #include <fcntl.h> 35 #include <libgen.h> 36 #include <stdlib.h> 37 #include <string.h> 38 #include <unistd.h> 39 40 #include <rump/rump_syscalls.h> 41 #include <rump/rump.h> 42 43 #include "../common/h_fsmacros.h" 44 #include "../../h_macros.h" 45 46 #define TESTFILE "afile" 47 48 #define USES_DIRS \ 49 if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("dirs not supported by file system") 50 51 #define USES_SYMLINKS \ 52 if (FSTYPE_SYSVBFS(tc) || FSTYPE_MSDOS(tc)) \ 53 atf_tc_skip("symlinks not supported by file system") 54 55 static char * 56 md(char *buf, const char *base, const char *tail) 57 { 58 59 sprintf(buf, "%s/%s", base, tail); 60 return buf; 61 } 62 63 static void 64 lookup_simple(const atf_tc_t *tc, const char *mountpath) 65 { 66 char pb[MAXPATHLEN], final[MAXPATHLEN]; 67 struct stat sb1, sb2; 68 69 strcpy(final, mountpath); 70 sprintf(pb, "%s/../%s", mountpath, basename(final)); 71 if (rump_sys_stat(pb, &sb1) == -1) 72 atf_tc_fail_errno("stat 1"); 73 74 sprintf(pb, "%s/./../%s", mountpath, basename(final)); 75 if (rump_sys_stat(pb, &sb2) == -1) 76 atf_tc_fail_errno("stat 2"); 77 78 ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0); 79 } 80 81 static void 82 lookup_complex(const atf_tc_t *tc, const char *mountpath) 83 { 84 char pb[MAXPATHLEN]; 85 struct stat sb1, sb2; 86 87 USES_DIRS; 88 89 sprintf(pb, "%s/dir", mountpath); 90 if (rump_sys_mkdir(pb, 0777) == -1) 91 atf_tc_fail_errno("mkdir"); 92 if (rump_sys_stat(pb, &sb1) == -1) 93 atf_tc_fail_errno("stat 1"); 94 95 sprintf(pb, "%s/./dir/../././dir/.", mountpath); 96 if (rump_sys_stat(pb, &sb2) == -1) 97 atf_tc_fail_errno("stat 2"); 98 99 ATF_REQUIRE(memcmp(&sb1, &sb2, sizeof(sb1)) == 0); 100 } 101 102 static void 103 dir_simple(const atf_tc_t *tc, const char *mountpath) 104 { 105 char pb[MAXPATHLEN]; 106 struct stat sb; 107 108 USES_DIRS; 109 110 /* check we can create directories */ 111 sprintf(pb, "%s/dir", mountpath); 112 if (rump_sys_mkdir(pb, 0777) == -1) 113 atf_tc_fail_errno("mkdir"); 114 if (rump_sys_stat(pb, &sb) == -1) 115 atf_tc_fail_errno("stat new directory"); 116 117 /* check we can remove then and that it makes them unreachable */ 118 if (rump_sys_rmdir(pb) == -1) 119 atf_tc_fail_errno("rmdir"); 120 if (rump_sys_stat(pb, &sb) != -1 || errno != ENOENT) 121 atf_tc_fail("ENOENT expected from stat"); 122 } 123 124 static void 125 dir_notempty(const atf_tc_t *tc, const char *mountpath) 126 { 127 char pb[MAXPATHLEN], pb2[MAXPATHLEN]; 128 int fd, rv; 129 130 USES_DIRS; 131 132 /* check we can create directories */ 133 sprintf(pb, "%s/dir", mountpath); 134 if (rump_sys_mkdir(pb, 0777) == -1) 135 atf_tc_fail_errno("mkdir"); 136 137 sprintf(pb2, "%s/dir/file", mountpath); 138 fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777); 139 if (fd == -1) 140 atf_tc_fail_errno("create file"); 141 rump_sys_close(fd); 142 143 rv = rump_sys_rmdir(pb); 144 if (rv != -1 || errno != ENOTEMPTY) 145 atf_tc_fail("non-empty directory removed succesfully"); 146 147 if (rump_sys_unlink(pb2) == -1) 148 atf_tc_fail_errno("cannot remove dir/file"); 149 150 if (rump_sys_rmdir(pb) == -1) 151 atf_tc_fail_errno("remove directory"); 152 } 153 154 static void 155 checkfile(const char *path, struct stat *refp) 156 { 157 char buf[MAXPATHLEN]; 158 struct stat sb; 159 static int n = 1; 160 161 md(buf, path, "file"); 162 if (rump_sys_stat(buf, &sb) == -1) 163 atf_tc_fail_errno("cannot stat file %d (%s)", n, buf); 164 if (memcmp(&sb, refp, sizeof(sb)) != 0) 165 atf_tc_fail("stat mismatch %d", n); 166 n++; 167 } 168 169 static void 170 rename_dir(const atf_tc_t *tc, const char *mp) 171 { 172 char pb1[MAXPATHLEN], pb2[MAXPATHLEN], pb3[MAXPATHLEN]; 173 struct stat ref; 174 175 if (FSTYPE_MSDOS(tc)) 176 atf_tc_skip("test fails in some setups, reason unknown"); 177 178 if (FSTYPE_RUMPFS(tc)) 179 atf_tc_skip("rename not supported by fs"); 180 181 USES_DIRS; 182 183 md(pb1, mp, "dir1"); 184 if (rump_sys_mkdir(pb1, 0777) == -1) 185 atf_tc_fail_errno("mkdir 1"); 186 187 md(pb2, mp, "dir2"); 188 if (rump_sys_mkdir(pb2, 0777) == -1) 189 atf_tc_fail_errno("mkdir 2"); 190 md(pb2, mp, "dir2/subdir"); 191 if (rump_sys_mkdir(pb2, 0777) == -1) 192 atf_tc_fail_errno("mkdir 3"); 193 194 md(pb3, mp, "dir1/file"); 195 if (rump_sys_mknod(pb3, S_IFREG | 0777, -1) == -1) 196 atf_tc_fail_errno("create file"); 197 if (rump_sys_stat(pb3, &ref) == -1) 198 atf_tc_fail_errno("stat of file"); 199 200 /* 201 * First try ops which should succeed. 202 */ 203 204 /* rename within directory */ 205 md(pb3, mp, "dir3"); 206 if (rump_sys_rename(pb1, pb3) == -1) 207 atf_tc_fail_errno("rename 1"); 208 checkfile(pb3, &ref); 209 210 /* rename directory onto itself (two ways, should fail) */ 211 md(pb1, mp, "dir3/."); 212 if (rump_sys_rename(pb1, pb3) != -1 || errno != EINVAL) 213 atf_tc_fail_errno("rename 2"); 214 if (rump_sys_rename(pb3, pb1) != -1 || errno != EISDIR) 215 atf_tc_fail_errno("rename 3"); 216 217 checkfile(pb3, &ref); 218 219 /* rename father of directory into directory */ 220 md(pb1, mp, "dir2/dir"); 221 md(pb2, mp, "dir2"); 222 if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL) 223 atf_tc_fail_errno("rename 4"); 224 225 /* same for grandfather */ 226 md(pb1, mp, "dir2/subdir/dir2"); 227 if (rump_sys_rename(pb2, pb1) != -1 || errno != EINVAL) 228 atf_tc_fail("rename 5"); 229 230 checkfile(pb3, &ref); 231 232 /* rename directory over a non-empty directory */ 233 if (rump_sys_rename(pb2, pb3) != -1 || errno != ENOTEMPTY) 234 atf_tc_fail("rename 6"); 235 236 /* cross-directory rename */ 237 md(pb1, mp, "dir3"); 238 md(pb2, mp, "dir2/somedir"); 239 if (rump_sys_rename(pb1, pb2) == -1) 240 atf_tc_fail_errno("rename 7"); 241 checkfile(pb2, &ref); 242 243 /* move to parent directory */ 244 md(pb1, mp, "dir2/somedir/../../dir3"); 245 if (rump_sys_rename(pb2, pb1) == -1) 246 atf_tc_fail_errno("rename 8"); 247 md(pb1, mp, "dir2/../dir3"); 248 checkfile(pb1, &ref); 249 250 /* finally, atomic cross-directory rename */ 251 md(pb3, mp, "dir2/subdir"); 252 if (rump_sys_rename(pb1, pb3) == -1) 253 atf_tc_fail_errno("rename 9"); 254 checkfile(pb3, &ref); 255 } 256 257 static void 258 rename_dotdot(const atf_tc_t *tc, const char *mp) 259 { 260 261 if (FSTYPE_RUMPFS(tc)) 262 atf_tc_skip("rename not supported by fs"); 263 264 USES_DIRS; 265 266 if (rump_sys_chdir(mp) == -1) 267 atf_tc_fail_errno("chdir mountpoint"); 268 269 if (rump_sys_mkdir("dir1", 0777) == -1) 270 atf_tc_fail_errno("mkdir 1"); 271 if (rump_sys_mkdir("dir2", 0777) == -1) 272 atf_tc_fail_errno("mkdir 2"); 273 274 if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL) 275 atf_tc_fail_errno("self-dotdot to"); 276 277 if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL) 278 atf_tc_fail_errno("self-dotdot from"); 279 atf_tc_expect_pass(); 280 281 if (FSTYPE_TMPFS(tc)) { 282 atf_tc_expect_fail("PR kern/43617"); 283 } 284 if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL) 285 atf_tc_fail("other-dotdot"); 286 287 rump_sys_chdir("/"); 288 } 289 290 static void 291 rename_reg_nodir(const atf_tc_t *tc, const char *mp) 292 { 293 bool haslinks; 294 struct stat sb; 295 ino_t f1ino, f2ino; 296 297 if (FSTYPE_RUMPFS(tc)) 298 atf_tc_skip("rename not supported by fs"); 299 300 if (FSTYPE_MSDOS(tc)) 301 atf_tc_skip("test fails in some setups, reason unknown"); 302 303 if (rump_sys_chdir(mp) == -1) 304 atf_tc_fail_errno("chdir mountpoint"); 305 306 if (FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc)) 307 haslinks = false; 308 else 309 haslinks = true; 310 311 if (rump_sys_mknod("file1", S_IFREG | 0777, -1) == -1) 312 atf_tc_fail_errno("create file"); 313 if (rump_sys_mknod("file2", S_IFREG | 0777, -1) == -1) 314 atf_tc_fail_errno("create file"); 315 316 if (rump_sys_stat("file1", &sb) == -1) 317 atf_tc_fail_errno("stat"); 318 f1ino = sb.st_ino; 319 320 if (haslinks) { 321 if (rump_sys_link("file1", "file_link") == -1) 322 atf_tc_fail_errno("link"); 323 if (rump_sys_stat("file_link", &sb) == -1) 324 atf_tc_fail_errno("stat"); 325 ATF_REQUIRE_EQ(sb.st_ino, f1ino); 326 ATF_REQUIRE_EQ(sb.st_nlink, 2); 327 } 328 329 if (rump_sys_stat("file2", &sb) == -1) 330 atf_tc_fail_errno("stat"); 331 f2ino = sb.st_ino; 332 333 if (rump_sys_rename("file1", "file3") == -1) 334 atf_tc_fail_errno("rename 1"); 335 if (rump_sys_stat("file3", &sb) == -1) 336 atf_tc_fail_errno("stat 1"); 337 if (haslinks) { 338 ATF_REQUIRE_EQ(sb.st_ino, f1ino); 339 } 340 if (rump_sys_stat("file1", &sb) != -1 || errno != ENOENT) 341 atf_tc_fail_errno("source 1"); 342 343 if (rump_sys_rename("file3", "file2") == -1) 344 atf_tc_fail_errno("rename 2"); 345 if (rump_sys_stat("file2", &sb) == -1) 346 atf_tc_fail_errno("stat 2"); 347 if (haslinks) { 348 ATF_REQUIRE_EQ(sb.st_ino, f1ino); 349 } 350 351 if (rump_sys_stat("file3", &sb) != -1 || errno != ENOENT) 352 atf_tc_fail_errno("source 2"); 353 354 if (haslinks) { 355 if (rump_sys_rename("file2", "file_link") == -1) 356 atf_tc_fail_errno("rename hardlink"); 357 if (rump_sys_stat("file2", &sb) != -1 || errno != ENOENT) 358 atf_tc_fail_errno("source 3"); 359 if (rump_sys_stat("file_link", &sb) == -1) 360 atf_tc_fail_errno("stat 2"); 361 ATF_REQUIRE_EQ(sb.st_ino, f1ino); 362 ATF_REQUIRE_EQ(sb.st_nlink, 1); 363 } 364 365 rump_sys_chdir("/"); 366 } 367 368 static void 369 create_nametoolong(const atf_tc_t *tc, const char *mp) 370 { 371 char *name; 372 int fd; 373 long val; 374 size_t len; 375 376 if (rump_sys_chdir(mp) == -1) 377 atf_tc_fail_errno("chdir mountpoint"); 378 379 val = rump_sys_pathconf(".", _PC_NAME_MAX); 380 if (val == -1) 381 atf_tc_fail_errno("pathconf"); 382 383 len = val + 1; 384 name = malloc(len+1); 385 if (name == NULL) 386 atf_tc_fail_errno("malloc"); 387 388 memset(name, 'a', len); 389 *(name+len) = '\0'; 390 391 val = rump_sys_pathconf(".", _PC_NO_TRUNC); 392 if (val == -1) 393 atf_tc_fail_errno("pathconf"); 394 395 if (FSTYPE_MSDOS(tc)) 396 atf_tc_expect_fail("PR kern/43670"); 397 fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666); 398 if (val != 0 && (fd != -1 || errno != ENAMETOOLONG)) 399 atf_tc_fail_errno("open"); 400 401 if (val == 0 && rump_sys_close(fd) == -1) 402 atf_tc_fail_errno("close"); 403 if (val == 0 && rump_sys_unlink(name) == -1) 404 atf_tc_fail_errno("unlink"); 405 406 free(name); 407 408 rump_sys_chdir("/"); 409 } 410 411 static void 412 rename_nametoolong(const atf_tc_t *tc, const char *mp) 413 { 414 char *name; 415 int res, fd; 416 long val; 417 size_t len; 418 419 if (FSTYPE_RUMPFS(tc)) 420 atf_tc_skip("rename not supported by fs"); 421 422 if (rump_sys_chdir(mp) == -1) 423 atf_tc_fail_errno("chdir mountpoint"); 424 425 val = rump_sys_pathconf(".", _PC_NAME_MAX); 426 if (val == -1) 427 atf_tc_fail_errno("pathconf"); 428 429 len = val + 1; 430 name = malloc(len+1); 431 if (name == NULL) 432 atf_tc_fail_errno("malloc"); 433 434 memset(name, 'a', len); 435 *(name+len) = '\0'; 436 437 fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666); 438 if (fd == -1) 439 atf_tc_fail_errno("open"); 440 if (rump_sys_close(fd) == -1) 441 atf_tc_fail_errno("close"); 442 443 val = rump_sys_pathconf(".", _PC_NO_TRUNC); 444 if (val == -1) 445 atf_tc_fail_errno("pathconf"); 446 447 if (FSTYPE_MSDOS(tc)) 448 atf_tc_expect_fail("PR kern/43670"); 449 res = rump_sys_rename("dummy", name); 450 if (val != 0 && (res != -1 || errno != ENAMETOOLONG)) 451 atf_tc_fail_errno("rename"); 452 453 if (val == 0 && rump_sys_unlink(name) == -1) 454 atf_tc_fail_errno("unlink"); 455 456 free(name); 457 458 rump_sys_chdir("/"); 459 } 460 461 static void 462 symlink_zerolen(const atf_tc_t *tc, const char *mp) 463 { 464 465 USES_SYMLINKS; 466 467 RL(rump_sys_chdir(mp)); 468 469 if (FSTYPE_TMPFS(tc)) { 470 atf_tc_expect_signal(SIGABRT, "PR kern/43843"); 471 } 472 473 RL(rump_sys_symlink("", "afile")); 474 RL(rump_sys_chdir("/")); 475 } 476 477 static void 478 attrs(const atf_tc_t *tc, const char *mp) 479 { 480 struct stat sb, sb2; 481 struct timeval tv[2]; 482 int fd; 483 484 FSTEST_ENTER(); 485 RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); 486 RL(rump_sys_close(fd)); 487 RL(rump_sys_stat(TESTFILE, &sb)); 488 if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { 489 RL(rump_sys_chown(TESTFILE, 1, 2)); 490 sb.st_uid = 1; 491 sb.st_gid = 2; 492 RL(rump_sys_chmod(TESTFILE, 0123)); 493 sb.st_mode = (sb.st_mode & ~ACCESSPERMS) | 0123; 494 } 495 496 tv[0].tv_sec = 1000000000; /* need something >1980 for msdosfs */ 497 tv[0].tv_usec = 1; 498 tv[1].tv_sec = 1000000002; /* need even seconds for msdosfs */ 499 tv[1].tv_usec = 3; 500 RL(rump_sys_utimes(TESTFILE, tv)); 501 RL(rump_sys_utimes(TESTFILE, tv)); /* XXX: utimes & birthtime */ 502 sb.st_atimespec.tv_sec = 1000000000; 503 sb.st_atimespec.tv_nsec = 1000; 504 sb.st_mtimespec.tv_sec = 1000000002; 505 sb.st_mtimespec.tv_nsec = 3000; 506 507 RL(rump_sys_stat(TESTFILE, &sb2)); 508 #define CHECK(a) ATF_REQUIRE_EQ(sb.a, sb2.a) 509 if (!(FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { 510 CHECK(st_uid); 511 CHECK(st_gid); 512 CHECK(st_mode); 513 } 514 if (!FSTYPE_MSDOS(tc)) { 515 /* msdosfs has only access date, not time */ 516 CHECK(st_atimespec.tv_sec); 517 } 518 CHECK(st_mtimespec.tv_sec); 519 if (!(FSTYPE_EXT2FS(tc) || FSTYPE_MSDOS(tc) || FSTYPE_SYSVBFS(tc))) { 520 CHECK(st_atimespec.tv_nsec); 521 CHECK(st_mtimespec.tv_nsec); 522 } 523 #undef CHECK 524 525 FSTEST_EXIT(); 526 } 527 528 static void 529 fcntl_lock(const atf_tc_t *tc, const char *mp) 530 { 531 int fd, fd2; 532 struct flock l; 533 struct lwp *lwp1, *lwp2; 534 535 FSTEST_ENTER(); 536 l.l_pid = 0; 537 l.l_start = l.l_len = 1024; 538 l.l_type = F_RDLCK | F_WRLCK; 539 l.l_whence = SEEK_END; 540 541 lwp1 = rump_pub_lwproc_curlwp(); 542 RL(fd = rump_sys_open(TESTFILE, O_RDWR | O_CREAT, 0755)); 543 RL(rump_sys_ftruncate(fd, 8192)); 544 545 /* PR kern/43321 */ 546 RL(rump_sys_fcntl(fd, F_SETLK, &l)); 547 548 /* Next, we fork and try to lock the same area */ 549 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); 550 lwp2 = rump_pub_lwproc_curlwp(); 551 RL(fd2 = rump_sys_open(TESTFILE, O_RDWR, 0)); 552 ATF_REQUIRE_ERRNO(EAGAIN, rump_sys_fcntl(fd2, F_SETLK, &l)); 553 554 /* Switch back and unlock... */ 555 rump_pub_lwproc_switch(lwp1); 556 l.l_type = F_UNLCK; 557 RL(rump_sys_fcntl(fd, F_SETLK, &l)); 558 559 /* ... and try to lock again */ 560 rump_pub_lwproc_switch(lwp2); 561 l.l_type = F_RDLCK | F_WRLCK; 562 RL(rump_sys_fcntl(fd2, F_SETLK, &l)); 563 564 RL(rump_sys_close(fd2)); 565 rump_pub_lwproc_releaselwp(); 566 567 RL(rump_sys_close(fd)); 568 569 FSTEST_EXIT(); 570 } 571 572 static int 573 flock_compare(const void *p, const void *q) 574 { 575 int a = ((const struct flock *)p)->l_start; 576 int b = ((const struct flock *)q)->l_start; 577 return a < b ? -1 : (a > b ? 1 : 0); 578 } 579 580 static void 581 fcntl_getlock_pids(const atf_tc_t *tc, const char *mp) 582 { 583 /* test non-overlaping ranges */ 584 struct flock expect[4]; 585 const struct flock lock[4] = { 586 { 0, 2, 0, F_WRLCK, SEEK_SET }, 587 { 2, 1, 0, F_WRLCK, SEEK_SET }, 588 { 7, 5, 0, F_WRLCK, SEEK_SET }, 589 { 4, 3, 0, F_WRLCK, SEEK_SET }, 590 }; 591 592 int fd[4]; 593 struct lwp *lwp[4]; 594 pid_t prevpid = 0; 595 596 unsigned int i, j; 597 const off_t sz = 8192; 598 int omode = 0755; 599 int oflags = O_RDWR | O_CREAT; 600 601 memcpy(expect, lock, sizeof(lock)); 602 qsort(expect, __arraycount(expect), sizeof(expect[0]), &flock_compare); 603 604 FSTEST_ENTER(); 605 606 /* 607 * First, we create 4 processes and let each lock a range of the 608 * file. Note that the third and fourth processes lock in 609 * "reverse" order, i.e. the greater pid locks a range before 610 * the lesser pid. 611 */ 612 for(i = 0; i < __arraycount(lwp); i++) { 613 RZ(rump_pub_lwproc_rfork(RUMP_RFCFDG)); 614 615 lwp[i] = rump_pub_lwproc_curlwp(); 616 assert(rump_sys_getpid() > prevpid); 617 prevpid = rump_sys_getpid(); 618 619 RL(fd[i] = rump_sys_open(TESTFILE, oflags, omode)); 620 oflags = O_RDWR; 621 omode = 0; 622 623 RL(rump_sys_ftruncate(fd[i], sz)); 624 RL(rump_sys_fcntl(fd[i], F_SETLK, &lock[i])); 625 } 626 627 atf_tc_expect_fail("PR kern/44494"); 628 /* 629 * In the context of each pid , do GETLK for a readlock from 630 * i = [0,__arraycount(locks)]. If we try to lock from the same 631 * start offset as the lock our current process holds, check 632 * that we fail on the offset of the next lock ("else if" branch). 633 * Otherwise, expect to get a lock for the current offset 634 * ("if" branch). The "else" branch is purely for the last 635 * process where we expect no blocking locks. 636 */ 637 for(i = 0; i < __arraycount(lwp); i++) { 638 rump_pub_lwproc_switch(lwp[i]); 639 640 for(j = 0; j < __arraycount(lwp); j++) { 641 struct flock l; 642 l = expect[j]; 643 l.l_len = sz; 644 l.l_type = F_RDLCK; 645 646 RL(rump_sys_fcntl(fd[i], F_GETLK, &l)); 647 648 if(expect[j].l_start != lock[i].l_start) { 649 /* 650 * lock set by another process 651 */ 652 ATF_CHECK(l.l_type != F_UNLCK); 653 ATF_CHECK_EQ(l.l_start, expect[j].l_start); 654 ATF_CHECK_EQ(l.l_len, expect[j].l_len); 655 } else if (j != __arraycount(lwp) - 1) { 656 /* 657 * lock set by the current process 658 */ 659 ATF_CHECK(l.l_type != F_UNLCK); 660 ATF_CHECK_EQ(l.l_start, expect[j+1].l_start); 661 ATF_CHECK_EQ(l.l_len, expect[j+1].l_len); 662 } else { 663 /* 664 * there are no other locks after the 665 * current process lock 666 */ 667 ATF_CHECK_EQ(l.l_type, F_UNLCK); 668 ATF_CHECK_EQ(l.l_start, expect[j].l_start); 669 ATF_CHECK_EQ(l.l_len, sz); 670 ATF_CHECK_EQ(l.l_pid, expect[j].l_pid); 671 ATF_CHECK_EQ(l.l_whence, expect[j].l_whence); 672 } 673 } 674 } 675 676 /* 677 * Release processes. This also releases the fds and locks 678 * making fs unmount possible 679 */ 680 for(i = 0; i < __arraycount(lwp); i++) { 681 rump_pub_lwproc_switch(lwp[i]); 682 rump_pub_lwproc_releaselwp(); 683 } 684 685 FSTEST_EXIT(); 686 } 687 688 ATF_TC_FSAPPLY(lookup_simple, "simple lookup (./.. on root)"); 689 ATF_TC_FSAPPLY(lookup_complex, "lookup of non-dot entries"); 690 ATF_TC_FSAPPLY(dir_simple, "mkdir/rmdir"); 691 ATF_TC_FSAPPLY(dir_notempty, "non-empty directories cannot be removed"); 692 ATF_TC_FSAPPLY(rename_dir, "exercise various directory renaming ops"); 693 ATF_TC_FSAPPLY(rename_dotdot, "rename dir .."); 694 ATF_TC_FSAPPLY(rename_reg_nodir, "rename regular files, no subdirectories"); 695 ATF_TC_FSAPPLY(create_nametoolong, "create file with name too long"); 696 ATF_TC_FSAPPLY(rename_nametoolong, "rename to file with name too long"); 697 ATF_TC_FSAPPLY(symlink_zerolen, "symlink with 0-len target"); 698 ATF_TC_FSAPPLY(attrs, "check setting attributes works"); 699 ATF_TC_FSAPPLY(fcntl_lock, "check fcntl F_SETLK"); 700 ATF_TC_FSAPPLY(fcntl_getlock_pids,"fcntl F_GETLK w/ many procs, PR kern/44494"); 701 702 ATF_TP_ADD_TCS(tp) 703 { 704 705 ATF_TP_FSAPPLY(lookup_simple); 706 ATF_TP_FSAPPLY(lookup_complex); 707 ATF_TP_FSAPPLY(dir_simple); 708 ATF_TP_FSAPPLY(dir_notempty); 709 ATF_TP_FSAPPLY(rename_dir); 710 ATF_TP_FSAPPLY(rename_dotdot); 711 ATF_TP_FSAPPLY(rename_reg_nodir); 712 ATF_TP_FSAPPLY(create_nametoolong); 713 ATF_TP_FSAPPLY(rename_nametoolong); 714 ATF_TP_FSAPPLY(symlink_zerolen); 715 ATF_TP_FSAPPLY(attrs); 716 ATF_TP_FSAPPLY(fcntl_lock); 717 ATF_TP_FSAPPLY(fcntl_getlock_pids); 718 719 return atf_no_error(); 720 } 721