Home | History | Annotate | Line # | Download | only in union
t_pr.c revision 1.10
      1 /*	$NetBSD: t_pr.c,v 1.10 2017/03/26 18:26:05 maya Exp $	*/
      2 
      3 #include <sys/types.h>
      4 #include <sys/mount.h>
      5 
      6 #include <atf-c.h>
      7 #include <err.h>
      8 #include <errno.h>
      9 #include <fcntl.h>
     10 #include <stdio.h>
     11 #include <unistd.h>
     12 #include <string.h>
     13 #include <stdlib.h>
     14 
     15 #include <rump/rump.h>
     16 #include <rump/rump_syscalls.h>
     17 
     18 #include <miscfs/union/union.h>
     19 
     20 #include "h_macros.h"
     21 
     22 ATF_TC(multilayer);
     23 ATF_TC_HEAD(multilayer, tc)
     24 {
     25 	atf_tc_set_md_var(tc, "descr", "mount_union -b twice");
     26 }
     27 
     28 ATF_TC_BODY(multilayer, tc)
     29 {
     30 	struct union_args unionargs;
     31 
     32 	rump_init();
     33 
     34 	if (rump_sys_mkdir("/Tunion", 0777) == -1)
     35 		atf_tc_fail_errno("mkdir mp1");
     36 	if (rump_sys_mkdir("/Tunion2", 0777) == -1)
     37 		atf_tc_fail_errno("mkdir mp2");
     38 	if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
     39 		atf_tc_fail_errno("mkdir A");
     40 	if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
     41 		atf_tc_fail_errno("mkdir B");
     42 
     43 	unionargs.target = __UNCONST("/Tunion2/A");
     44 	unionargs.mntflags = UNMNT_BELOW;
     45 
     46 	if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
     47 	    &unionargs, sizeof(unionargs)) == -1)
     48 		atf_tc_fail_errno("union mount");
     49 
     50 	unionargs.target = __UNCONST("/Tunion2/B");
     51 	unionargs.mntflags = UNMNT_BELOW;
     52 
     53 	rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
     54 }
     55 
     56 ATF_TC(multilayer2);
     57 ATF_TC_HEAD(multilayer2, tc)
     58 {
     59 	atf_tc_set_md_var(tc, "descr", "mount_union twice then unmount");
     60 }
     61 
     62 ATF_TC_BODY(multilayer2, tc)
     63 {
     64 	struct union_args unionargs;
     65 
     66 	rump_init();
     67 
     68 	if (rump_sys_mkdir("/Tunion", 0777) == -1)
     69 		atf_tc_fail_errno("mkdir mp1");
     70 	if (rump_sys_mkdir("/Tunion2", 0777) == -1)
     71 		atf_tc_fail_errno("mkdir mp2");
     72 	if (rump_sys_mkdir("/Tunion2/A", 0777) == -1)
     73 		atf_tc_fail_errno("mkdir A");
     74 	if (rump_sys_mkdir("/Tunion2/B", 0777) == -1)
     75 		atf_tc_fail_errno("mkdir B");
     76 
     77 	unionargs.target = __UNCONST("/Tunion2/A");
     78 	unionargs.mntflags = UNMNT_ABOVE;
     79 
     80 	if (rump_sys_mount(MOUNT_UNION, "/Tunion", 0,
     81 	    &unionargs, sizeof(unionargs)) == -1)
     82 		atf_tc_fail_errno("union mount");
     83 	if (rump_sys_mkdir("/Tunion2/A/A", 0777) == -1)
     84 		atf_tc_fail_errno("mkdir A/A");
     85 
     86 	unionargs.target = __UNCONST("/Tunion2/A/A");
     87 	unionargs.mntflags = UNMNT_ABOVE;
     88 
     89 	rump_sys_mount(MOUNT_UNION, "/Tunion", 0,&unionargs,sizeof(unionargs));
     90 
     91 	rump_sys_unmount("/Tunion/A", 0);
     92 }
     93 
     94 ATF_TC(cyclic);
     95 ATF_TC_HEAD(cyclic, tc)
     96 {
     97 	atf_tc_set_md_var(tc, "descr", "cyclic mount_union");
     98 }
     99 
    100 ATF_TC_BODY(cyclic, tc)
    101 {
    102 	struct union_args unionargs;
    103 
    104 	rump_init();
    105 
    106 	if (rump_sys_mkdir("/Tunion", 0777) == -1)
    107 		atf_tc_fail_errno("mkdir mp1");
    108 	if (rump_sys_mkdir("/Tunion/A", 0777) == -1)
    109 		atf_tc_fail_errno("mkdir mp2");
    110 
    111 	unionargs.target = __UNCONST("/Tunion/A");
    112 	unionargs.mntflags = UNMNT_ABOVE;
    113 
    114 	if (rump_sys_mount(MOUNT_UNION, "/Tunion/A", 0,
    115 	    &unionargs, sizeof(unionargs)) == -1)
    116 		atf_tc_fail_errno("union mount");
    117 
    118 	if (rump_sys_mkdir("/Tunion/A/A", 0777) == -1)
    119 		atf_tc_fail_errno("mkdir failed");
    120 }
    121 
    122 ATF_TC(cyclic2);
    123 ATF_TC_HEAD(cyclic2, tc)
    124 {
    125 	atf_tc_set_md_var(tc, "descr", "cyclic mount_union");
    126 }
    127 
    128 ATF_TC_BODY(cyclic2, tc)
    129 {
    130 	struct union_args unionargs;
    131 
    132 	rump_init();
    133 
    134 	if (rump_sys_mkdir("/Tunion", 0777) == -1)
    135 		atf_tc_fail_errno("mkdir mp1");
    136 	if (rump_sys_mkdir("/Tunion/A", 0777) == -1)
    137 		atf_tc_fail_errno("mkdir mp2");
    138 	if (rump_sys_mkdir("/Tunion/B", 0777) == -1)
    139 		atf_tc_fail_errno("mkdir mp3");
    140 
    141 	unionargs.target = __UNCONST("/Tunion/A");
    142 	unionargs.mntflags = UNMNT_ABOVE;
    143 
    144 	if (rump_sys_mount(MOUNT_UNION, "/Tunion/B", 0,
    145 	    &unionargs, sizeof(unionargs)) == -1)
    146 		atf_tc_fail_errno("union mount");
    147 
    148 	unionargs.target = __UNCONST("/Tunion/B");
    149 	unionargs.mntflags = UNMNT_ABOVE;
    150 
    151 	if (rump_sys_mount(MOUNT_UNION, "/Tunion/A", 0,
    152 	    &unionargs, sizeof(unionargs)) == -1)
    153 		atf_tc_fail_errno("union mount2");
    154 
    155 	if (rump_sys_mkdir("/Tunion/A/A", 0777) == -1)
    156 		atf_tc_fail_errno("mkdir failed");
    157 }
    158 
    159 ATF_TC(devnull1);
    160 ATF_TC_HEAD(devnull1, tc)
    161 {
    162 	atf_tc_set_md_var(tc, "descr", "mount_union -b and "
    163 	    "'echo x > /un/null'");
    164 }
    165 
    166 ATF_TC_BODY(devnull1, tc)
    167 {
    168 	struct union_args unionargs;
    169 	int fd, res;
    170 
    171 	rump_init();
    172 
    173 	if (rump_sys_mkdir("/mp", 0777) == -1)
    174 		atf_tc_fail_errno("mkdir mp");
    175 
    176 	unionargs.target = __UNCONST("/dev");
    177 	unionargs.mntflags = UNMNT_BELOW;
    178 
    179 	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
    180 	    &unionargs, sizeof(unionargs)) == -1)
    181 		atf_tc_fail_errno("union mount");
    182 
    183 	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_TRUNC);
    184 
    185 	if (fd == -1)
    186 		atf_tc_fail_errno("open");
    187 
    188 	res = rump_sys_write(fd, &fd, sizeof(fd));
    189 	if (res != sizeof(fd))
    190 		atf_tc_fail("write");
    191 }
    192 
    193 ATF_TC(devnull2);
    194 ATF_TC_HEAD(devnull2, tc)
    195 {
    196 	atf_tc_set_md_var(tc, "descr", "mount_union -b and "
    197 	    "'echo x >> /un/null'");
    198 }
    199 
    200 ATF_TC_BODY(devnull2, tc)
    201 {
    202 	struct union_args unionargs;
    203 	int fd, res;
    204 
    205 	rump_init();
    206 
    207 	if (rump_sys_mkdir("/mp", 0777) == -1)
    208 		atf_tc_fail_errno("mkdir mp");
    209 
    210 	unionargs.target = __UNCONST("/dev");
    211 	unionargs.mntflags = UNMNT_BELOW;
    212 
    213 	if (rump_sys_mount(MOUNT_UNION, "/mp", 0,
    214 	    &unionargs, sizeof(unionargs)) == -1)
    215 		atf_tc_fail_errno("union mount");
    216 
    217 	fd = rump_sys_open("/mp/null", O_WRONLY | O_CREAT | O_APPEND);
    218 	if (fd == -1)
    219 		atf_tc_fail_errno("open");
    220 
    221 	res = rump_sys_write(fd, &fd, sizeof(fd));
    222 	if (res != sizeof(fd))
    223 		atf_tc_fail("write");
    224 }
    225 
    226 ATF_TP_ADD_TCS(tp)
    227 {
    228 	ATF_TP_ADD_TC(tp, multilayer);
    229 	ATF_TP_ADD_TC(tp, multilayer2);
    230 	ATF_TP_ADD_TC(tp, cyclic);
    231 	ATF_TP_ADD_TC(tp, cyclic2);
    232 	ATF_TP_ADD_TC(tp, devnull1);
    233 	ATF_TP_ADD_TC(tp, devnull2);
    234 
    235 	return atf_no_error();
    236 }
    237