Home | History | Annotate | Line # | Download | only in union
t_pr.c revision 1.4
      1  1.4  pooka /*	$NetBSD: t_pr.c,v 1.4 2010/07/03 12:08:37 pooka Exp $	*/
      2  1.1  pooka 
      3  1.1  pooka #include <sys/types.h>
      4  1.1  pooka #include <sys/mount.h>
      5  1.1  pooka 
      6  1.1  pooka #include <atf-c.h>
      7  1.1  pooka #include <err.h>
      8  1.1  pooka #include <errno.h>
      9  1.1  pooka #include <fcntl.h>
     10  1.1  pooka #include <stdio.h>
     11  1.1  pooka #include <unistd.h>
     12  1.1  pooka #include <string.h>
     13  1.1  pooka #include <stdlib.h>
     14  1.1  pooka 
     15  1.1  pooka #include <rump/rump.h>
     16  1.1  pooka #include <rump/rump_syscalls.h>
     17  1.1  pooka 
     18  1.1  pooka #include <miscfs/union/union.h>
     19  1.1  pooka #include <ufs/ufs/ufsmount.h>
     20  1.1  pooka 
     21  1.1  pooka #include "../../h_macros.h"
     22  1.1  pooka 
     23  1.1  pooka ATF_TC(multilayer);
     24  1.1  pooka ATF_TC_HEAD(multilayer, tc)
     25  1.1  pooka {
     26  1.1  pooka 	atf_tc_set_md_var(tc, "descr", "mount_union -b twice");
     27  1.1  pooka 	atf_tc_set_md_var(tc, "use.fs", "true");
     28  1.1  pooka }
     29  1.1  pooka 
     30  1.1  pooka #define IMG1 "atf1.img"
     31  1.1  pooka #define DEV1 "/dev/fs1"
     32  1.1  pooka #define newfs_base "newfs -F -s 10000 "
     33  1.1  pooka 
     34  1.1  pooka ATF_TC_BODY(multilayer, tc)
     35  1.1  pooka {
     36  1.1  pooka 	struct ufs_args args;
     37  1.1  pooka 	struct union_args unionargs;
     38  1.1  pooka 
     39  1.1  pooka 	if (system(newfs_base IMG1) == -1)
     40  1.1  pooka 		atf_tc_fail_errno("create img1");
     41  1.1  pooka 
     42  1.1  pooka 	rump_init();
     43  1.1  pooka         rump_pub_etfs_register(DEV1, IMG1, RUMP_ETFS_BLK);
     44  1.1  pooka 
     45  1.1  pooka 	memset(&args, 0, sizeof(args));
     46  1.1  pooka 	args.fspec = __UNCONST(DEV1);
     47  1.1  pooka 	if (rump_sys_mount(MOUNT_FFS, "/", 0, &args, sizeof(args)) == -1)
     48  1.1  pooka 		atf_tc_fail_errno("could not mount root");
     49  1.1  pooka 
     50  1.1  pooka 	if (rump_sys_mkdir("/Tunion", 0777) == -1)
     51  1.1  pooka 		atf_tc_fail_errno("mkdir mp1");
     52  1.1  pooka 	if (rump_sys_mkdir("/Tunion2", 0777) == -1)
     53  1.1  pooka 		atf_tc_fail_errno("mkdir mp2");
     54  1.1  pooka 	if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
     55  1.1  pooka 		atf_tc_fail_errno("mkdir A");
     56  1.1  pooka 	if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
     57  1.1  pooka 		atf_tc_fail_errno("mkdir B");
     58  1.1  pooka 
     59  1.1  pooka 	unionargs.target = __UNCONST("/Tunion2/A");
     60  1.1  pooka 	unionargs.mntflags = UNMNT_BELOW;
     61  1.1  pooka 
     62  1.1  pooka 	if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
     63  1.1  pooka 	    &unionargs, sizeof(unionargs)) == -1)
     64  1.1  pooka 		atf_tc_fail_errno("union mount");
     65  1.1  pooka 
     66  1.1  pooka 	unionargs.target = __UNCONST("/Tunion2/B");
     67  1.1  pooka 	unionargs.mntflags = UNMNT_BELOW;
     68  1.1  pooka 
     69  1.1  pooka 	/* BADABOOM */
     70  1.3   jmmv 	/* atf_tc_expect_signal(-1, "PR kern/23986"); */
     71  1.1  pooka 	rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
     72  1.1  pooka }
     73  1.1  pooka 
     74  1.4  pooka ATF_TC(devnull1);
     75  1.4  pooka ATF_TC_HEAD(devnull1, tc)
     76  1.4  pooka {
     77  1.4  pooka 	atf_tc_set_md_var(tc, "descr", "mount_union -b and "
     78  1.4  pooka 	    "'echo x > /un/null'");
     79  1.4  pooka }
     80  1.4  pooka 
     81  1.4  pooka ATF_TC_BODY(devnull1, tc)
     82  1.4  pooka {
     83  1.4  pooka 	struct union_args unionargs;
     84  1.4  pooka 	int fd;
     85  1.4  pooka 
     86  1.4  pooka 	rump_init();
     87  1.4  pooka 
     88  1.4  pooka 	if (rump_sys_mkdir("/mp", 0777) == -1)
     89  1.4  pooka 		atf_tc_fail_errno("mkdir mp");
     90  1.4  pooka 
     91  1.4  pooka 	unionargs.target = __UNCONST("/dev");
     92  1.4  pooka 	unionargs.mntflags = UNMNT_BELOW;
     93  1.4  pooka 
     94  1.4  pooka 	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
     95  1.4  pooka 	    &unionargs, sizeof(unionargs)) == -1)
     96  1.4  pooka 		atf_tc_fail_errno("union mount");
     97  1.4  pooka 
     98  1.4  pooka 	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
     99  1.4  pooka 
    100  1.4  pooka 	atf_tc_expect_fail("PR kern/43560");
    101  1.4  pooka 	if (fd == -1)
    102  1.4  pooka 		atf_tc_fail_errno("open");
    103  1.4  pooka }
    104  1.4  pooka 
    105  1.4  pooka ATF_TC(devnull2);
    106  1.4  pooka ATF_TC_HEAD(devnull2, tc)
    107  1.4  pooka {
    108  1.4  pooka 	atf_tc_set_md_var(tc, "descr", "mount_union -b and "
    109  1.4  pooka 	    "'echo x >> /un/null'");
    110  1.4  pooka }
    111  1.4  pooka 
    112  1.4  pooka ATF_TC_BODY(devnull2, tc)
    113  1.4  pooka {
    114  1.4  pooka 	struct union_args unionargs;
    115  1.4  pooka 	int fd;
    116  1.4  pooka 
    117  1.4  pooka 	rump_init();
    118  1.4  pooka 
    119  1.4  pooka 	if (rump_sys_mkdir("/mp", 0777) == -1)
    120  1.4  pooka 		atf_tc_fail_errno("mkdir mp");
    121  1.4  pooka 
    122  1.4  pooka 	unionargs.target = __UNCONST("/dev");
    123  1.4  pooka 	unionargs.mntflags = UNMNT_BELOW;
    124  1.4  pooka 
    125  1.4  pooka 	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
    126  1.4  pooka 	    &unionargs, sizeof(unionargs)) == -1)
    127  1.4  pooka 		atf_tc_fail_errno("union mount");
    128  1.4  pooka 
    129  1.4  pooka 	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
    130  1.4  pooka 	if (fd == -1)
    131  1.4  pooka 		atf_tc_fail_errno("open");
    132  1.4  pooka 
    133  1.4  pooka 	atf_tc_expect_signal(-1, "PR kern/43560");
    134  1.4  pooka 	rump_sys_write(fd, &fd, sizeof(fd));
    135  1.4  pooka }
    136  1.4  pooka 
    137  1.1  pooka ATF_TP_ADD_TCS(tp)
    138  1.1  pooka {
    139  1.1  pooka 	ATF_TP_ADD_TC(tp, multilayer);
    140  1.4  pooka 	ATF_TP_ADD_TC(tp, devnull1);
    141  1.4  pooka 	ATF_TP_ADD_TC(tp, devnull2);
    142  1.1  pooka 
    143  1.1  pooka 	return atf_no_error();
    144  1.1  pooka }
    145