Home | History | Annotate | Line # | Download | only in nfs
t_mountd.c revision 1.3
      1 /*	$NetBSD: t_mountd.c,v 1.3 2010/11/07 17:51:18 jmmv Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #include <sys/types.h>
     29 #include <sys/mount.h>
     30 
     31 #include <atf-c.h>
     32 #include <errno.h>
     33 #include <fcntl.h>
     34 #include <pthread.h>
     35 #include <stdio.h>
     36 #include <stdlib.h>
     37 #include <unistd.h>
     38 #include <string.h>
     39 
     40 #include <rump/rump.h>
     41 #include <rump/rump_syscalls.h>
     42 
     43 #include "../../h_macros.h"
     44 #include "../common/h_fsmacros.h"
     45 
     46 ATF_TC(mountdhup);
     47 ATF_TC_HEAD(mountdhup, tc)
     48 {
     49 
     50 	atf_tc_set_md_var(tc, "descr", "test for service interrupt while "
     51 	    "mountd handles SIGHUP");
     52 }
     53 
     54 static volatile int quit;
     55 
     56 static void *
     57 wrkwrkwrk(void *unused)
     58 {
     59 	int fd, fail;
     60 
     61 	rump_sys_chdir(FSTEST_MNTNAME);
     62 	while (!quit) {
     63 		fd = rump_sys_open("file", O_RDWR | O_CREAT);
     64 		if (fd == -1) {
     65 			if (errno == EACCES) {
     66 				fail++;
     67 				break;
     68 			}
     69 		}
     70 		rump_sys_close(fd);
     71 		if (rump_sys_unlink("file") == -1) {
     72 			if (errno == EACCES) {
     73 				fail++;
     74 				break;
     75 			}
     76 		}
     77 	}
     78 	rump_sys_chdir("/");
     79 	quit = 1;
     80 
     81 	return fail ? &fail : NULL;
     82 }
     83 
     84 ATF_TC_BODY(mountdhup, tc)
     85 {
     86 	pthread_t pt;
     87 	struct nfstestargs *nfsargs;
     88 	void *voidargs;
     89 	int attempts;
     90 	void *fail;
     91 
     92 	FSTEST_CONSTRUCTOR(tc, nfs, voidargs);
     93 	nfsargs = voidargs;
     94 
     95 	pthread_create(&pt, NULL, wrkwrkwrk, NULL);
     96 	for (attempts = 100; attempts && !quit; attempts--) {
     97 		usleep(100000);
     98 		kill(nfsargs->ta_childpid, SIGHUP);
     99 	}
    100 	quit = 1;
    101 	pthread_join(pt, &fail);
    102 
    103 	FSTEST_DESTRUCTOR(tc, nfs, voidargs);
    104 
    105 	atf_tc_expect_fail("PR kern/5844");
    106 	if (fail)
    107 		atf_tc_fail("op failed with EACCES");
    108 	else
    109 		atf_tc_fail("race did not trigger this time");
    110 }
    111 
    112 ATF_TP_ADD_TCS(tp)
    113 {
    114 
    115 	ATF_TP_ADD_TC(tp, mountdhup);
    116 
    117 	return atf_no_error();
    118 }
    119