Home | History | Annotate | Line # | Download | only in vfs
t_vfsops.c revision 1.5
      1  1.5  pooka /*	$NetBSD: t_vfsops.c,v 1.5 2010/08/12 09:34:16 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  * All rights reserved.
      6  1.1  pooka  *
      7  1.1  pooka  * Redistribution and use in source and binary forms, with or without
      8  1.1  pooka  * modification, are permitted provided that the following conditions
      9  1.1  pooka  * are met:
     10  1.1  pooka  * 1. Redistributions of source code must retain the above copyright
     11  1.1  pooka  *    notice, this list of conditions and the following disclaimer.
     12  1.1  pooka  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  pooka  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  pooka  *    documentation and/or other materials provided with the distribution.
     15  1.1  pooka  *
     16  1.1  pooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  pooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  pooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  pooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  pooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  pooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  pooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  pooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  pooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  pooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  pooka  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  pooka  */
     28  1.1  pooka 
     29  1.1  pooka #include <sys/stat.h>
     30  1.1  pooka #include <sys/statvfs.h>
     31  1.1  pooka 
     32  1.1  pooka #include <atf-c.h>
     33  1.4  pooka #include <dirent.h>
     34  1.2  pooka #include <fcntl.h>
     35  1.4  pooka #include <stdlib.h>
     36  1.1  pooka #include <unistd.h>
     37  1.1  pooka 
     38  1.1  pooka #include <rump/rump_syscalls.h>
     39  1.1  pooka #include <rump/rump.h>
     40  1.1  pooka 
     41  1.1  pooka #include "../common/h_fsmacros.h"
     42  1.1  pooka #include "../../h_macros.h"
     43  1.1  pooka 
     44  1.1  pooka static void
     45  1.1  pooka tmount(const atf_tc_t *tc, const char *path)
     46  1.1  pooka {
     47  1.1  pooka 
     48  1.1  pooka 	return;
     49  1.1  pooka }
     50  1.1  pooka 
     51  1.1  pooka static void
     52  1.1  pooka tstatvfs(const atf_tc_t *tc, const char *path)
     53  1.1  pooka {
     54  1.3  njoly 	const char *fstype = atf_tc_get_md_var(tc, "X-fs.type");
     55  1.1  pooka 	struct statvfs svb;
     56  1.1  pooka 
     57  1.1  pooka 	if (rump_sys_statvfs1(path, &svb, ST_WAIT) == -1)
     58  1.1  pooka 		atf_tc_fail_errno("statvfs");
     59  1.3  njoly 
     60  1.3  njoly 	ATF_REQUIRE(svb.f_namemax > 0 && svb.f_namemax <= MAXNAMLEN);
     61  1.3  njoly 	if (!FSTYPE_PUFFS(tc))
     62  1.3  njoly 		ATF_REQUIRE_STREQ(svb.f_fstypename, fstype);
     63  1.3  njoly 	ATF_REQUIRE_STREQ(svb.f_mntonname, path);
     64  1.1  pooka }
     65  1.1  pooka 
     66  1.1  pooka static void
     67  1.1  pooka tsync(const atf_tc_t *tc, const char *path)
     68  1.1  pooka {
     69  1.1  pooka 
     70  1.1  pooka 	rump_sys_sync();
     71  1.1  pooka }
     72  1.1  pooka 
     73  1.1  pooka #define MAGICSTR "just a string, I like A"
     74  1.1  pooka static void
     75  1.1  pooka tfilehandle(const atf_tc_t *tc, const char *path)
     76  1.1  pooka {
     77  1.1  pooka 	char fpath[MAXPATHLEN];
     78  1.1  pooka 	char buf[sizeof(MAGICSTR)];
     79  1.1  pooka 	size_t fhsize;
     80  1.1  pooka 	void *fhp;
     81  1.1  pooka 	int fd;
     82  1.1  pooka 
     83  1.1  pooka 	sprintf(fpath, "%s/file", path);
     84  1.1  pooka 	fd = rump_sys_open(fpath, O_RDWR | O_CREAT, 0777);
     85  1.1  pooka 	if (fd == -1)
     86  1.1  pooka 		atf_tc_fail_errno("open");
     87  1.1  pooka 
     88  1.1  pooka 	if (rump_sys_write(fd, MAGICSTR, sizeof(MAGICSTR)) != sizeof(MAGICSTR))
     89  1.1  pooka 		atf_tc_fail("write to file");
     90  1.1  pooka 	rump_sys_close(fd);
     91  1.1  pooka 
     92  1.1  pooka 	/*
     93  1.1  pooka 	 * Get file handle size.
     94  1.1  pooka 	 * This also weeds out unsupported file systems.
     95  1.1  pooka 	 */
     96  1.1  pooka 	fhsize = 0;
     97  1.1  pooka 	if (rump_sys_getfh(fpath, NULL, &fhsize) == -1) {
     98  1.1  pooka 		if (errno == EOPNOTSUPP) {
     99  1.1  pooka 			atf_tc_skip("file handles not supported");
    100  1.1  pooka 		} else if (errno != E2BIG) {
    101  1.1  pooka 			atf_tc_fail_errno("getfh size");
    102  1.1  pooka 		}
    103  1.1  pooka 	}
    104  1.1  pooka 
    105  1.1  pooka 	fhp = malloc(fhsize);
    106  1.1  pooka 	if (rump_sys_getfh(fpath, fhp, &fhsize) == -1)
    107  1.1  pooka 		atf_tc_fail_errno("getfh");
    108  1.1  pooka 
    109  1.1  pooka 	/* open file based on file handle */
    110  1.1  pooka 	fd = rump_sys_fhopen(fhp, fhsize, O_RDONLY);
    111  1.1  pooka 	if (FSTYPE_TMPFS(tc)) {
    112  1.1  pooka 		atf_tc_expect_fail("PR kern/43605");
    113  1.1  pooka 		if (fd != -1 || errno != EINVAL)
    114  1.1  pooka 			atf_tc_expect_pass();
    115  1.1  pooka 	}
    116  1.1  pooka 	if (fd == -1) {
    117  1.1  pooka 		atf_tc_fail_errno("fhopen");
    118  1.1  pooka 	}
    119  1.1  pooka 
    120  1.1  pooka 	/* check that we got the same file */
    121  1.1  pooka 	if (rump_sys_read(fd, buf, sizeof(buf)) != sizeof(MAGICSTR))
    122  1.1  pooka 		atf_tc_fail("read fhopened file");
    123  1.1  pooka 
    124  1.1  pooka 	ATF_REQUIRE_STREQ(buf, MAGICSTR);
    125  1.1  pooka 
    126  1.1  pooka 	rump_sys_close(fd);
    127  1.1  pooka }
    128  1.1  pooka 
    129  1.5  pooka #define FNAME "a_file"
    130  1.5  pooka static void
    131  1.5  pooka tfhremove(const atf_tc_t *tc, const char *path)
    132  1.5  pooka {
    133  1.5  pooka 	size_t fhsize;
    134  1.5  pooka 	void *fhp;
    135  1.5  pooka 	int fd;
    136  1.5  pooka 
    137  1.5  pooka 	/* should repeat above, but ... */
    138  1.5  pooka 	if (FSTYPE_TMPFS(tc))
    139  1.5  pooka 		atf_tc_skip("file handles broken (PR kern/43605)");
    140  1.5  pooka 
    141  1.5  pooka 	RL(rump_sys_chdir(path));
    142  1.5  pooka 	RL(fd = rump_sys_open(FNAME, O_RDWR | O_CREAT, 0777));
    143  1.5  pooka 	RL(rump_sys_close(fd));
    144  1.5  pooka 
    145  1.5  pooka 	fhsize = 0;
    146  1.5  pooka 	if (rump_sys_getfh(FNAME, NULL, &fhsize) == -1) {
    147  1.5  pooka 		if (errno == EOPNOTSUPP) {
    148  1.5  pooka 			atf_tc_skip("file handles not supported");
    149  1.5  pooka 		} else if (errno != E2BIG) {
    150  1.5  pooka 			atf_tc_fail_errno("getfh size");
    151  1.5  pooka 		}
    152  1.5  pooka 	}
    153  1.5  pooka 
    154  1.5  pooka 	fhp = malloc(fhsize);
    155  1.5  pooka 	RL(rump_sys_getfh(FNAME, fhp, &fhsize));
    156  1.5  pooka 	RL(rump_sys_unlink(FNAME));
    157  1.5  pooka 
    158  1.5  pooka 	if (FSTYPE_MSDOS(tc) || FSTYPE_LFS(tc))
    159  1.5  pooka 		atf_tc_expect_fail("fhopen() for removed file succeeds (PR coming soon)");
    160  1.5  pooka 	ATF_REQUIRE_ERRNO(ESTALE, rump_sys_fhopen(fhp, fhsize, O_RDONLY) == -1);
    161  1.5  pooka 	atf_tc_expect_pass();
    162  1.5  pooka 
    163  1.5  pooka 	RL(rump_sys_chdir("/"));
    164  1.5  pooka }
    165  1.5  pooka #undef FNAME
    166  1.5  pooka 
    167  1.1  pooka ATF_TC_FSAPPLY(tmount, "mount/unmount");
    168  1.1  pooka ATF_TC_FSAPPLY(tstatvfs, "statvfs");
    169  1.1  pooka ATF_TC_FSAPPLY(tsync, "sync");
    170  1.1  pooka ATF_TC_FSAPPLY(tfilehandle, "file handles");
    171  1.5  pooka ATF_TC_FSAPPLY(tfhremove, "fhtovp for removed file");
    172  1.1  pooka 
    173  1.1  pooka ATF_TP_ADD_TCS(tp)
    174  1.1  pooka {
    175  1.1  pooka 
    176  1.1  pooka 	ATF_TP_FSAPPLY(tmount);
    177  1.1  pooka 	ATF_TP_FSAPPLY(tstatvfs);
    178  1.1  pooka 	ATF_TP_FSAPPLY(tsync);
    179  1.1  pooka 	ATF_TP_FSAPPLY(tfilehandle);
    180  1.5  pooka 	ATF_TP_FSAPPLY(tfhremove);
    181  1.1  pooka 
    182  1.1  pooka 	return atf_no_error();
    183  1.1  pooka }
    184