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