xref: /freebsd/contrib/netbsd-tests/fs/vfs/t_full.c (revision 1a36faad54665288ed4eb839d2a4699ae2ead45e)
1*63d1fd59SEnji Cooper /*	$NetBSD: t_full.c,v 1.9 2017/01/13 21:30:40 christos Exp $	*/
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2010 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
857718be8SEnji Cooper  * modification, are permitted provided that the following conditions
957718be8SEnji Cooper  * are met:
1057718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1157718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1257718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1357718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1457718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1557718be8SEnji Cooper  *
1657718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1757718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1857718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1957718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2057718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2157718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2257718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2357718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2457718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2557718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2657718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
2757718be8SEnji Cooper  */
2857718be8SEnji Cooper 
2957718be8SEnji Cooper #include <sys/stat.h>
3057718be8SEnji Cooper #include <sys/statvfs.h>
3157718be8SEnji Cooper 
3257718be8SEnji Cooper #include <atf-c.h>
3357718be8SEnji Cooper #include <fcntl.h>
3457718be8SEnji Cooper #include <libgen.h>
3557718be8SEnji Cooper #include <stdlib.h>
3657718be8SEnji Cooper #include <unistd.h>
3757718be8SEnji Cooper 
3857718be8SEnji Cooper #include <rump/rump_syscalls.h>
3957718be8SEnji Cooper #include <rump/rump.h>
4057718be8SEnji Cooper 
4157718be8SEnji Cooper #include "../common/h_fsmacros.h"
42*63d1fd59SEnji Cooper #include "h_macros.h"
4357718be8SEnji Cooper 
4457718be8SEnji Cooper /*
4557718be8SEnji Cooper  * Write this much over the image size.  This is to force an NFS commit,
4657718be8SEnji Cooper  * since we might just stuff data into the cache and miss the problem.
4757718be8SEnji Cooper  */
4857718be8SEnji Cooper #define NFSBONUS (1<<16)
4957718be8SEnji Cooper 
5057718be8SEnji Cooper static void
fillfs(const atf_tc_t * tc,const char * mp)5157718be8SEnji Cooper fillfs(const atf_tc_t *tc, const char *mp)
5257718be8SEnji Cooper {
5357718be8SEnji Cooper 	char buf[8192];
5457718be8SEnji Cooper 	size_t written;
5557718be8SEnji Cooper 	ssize_t n = 0; /* xxxgcc */
5657718be8SEnji Cooper 	size_t bonus;
5757718be8SEnji Cooper 	int fd, i = 0;
5857718be8SEnji Cooper 
5957718be8SEnji Cooper 	if (FSTYPE_P2K_FFS(tc) || FSTYPE_PUFFS(tc) || FSTYPE_RUMPFS(tc)) {
6057718be8SEnji Cooper 		atf_tc_skip("fs does not support explicit block allocation "
6157718be8SEnji Cooper 		    "(GOP_ALLOC)");
6257718be8SEnji Cooper 	}
6357718be8SEnji Cooper 
6457718be8SEnji Cooper 	bonus = 0;
6557718be8SEnji Cooper 	if (FSTYPE_NFS(tc))
6657718be8SEnji Cooper 		bonus = NFSBONUS;
6757718be8SEnji Cooper 
6857718be8SEnji Cooper 	if (rump_sys_chdir(mp) == -1)
6957718be8SEnji Cooper 		atf_tc_fail_errno("chdir mountpoint");
7057718be8SEnji Cooper 	fd = rump_sys_open("afile", O_CREAT | O_RDWR);
7157718be8SEnji Cooper 	if (fd == -1)
7257718be8SEnji Cooper 		atf_tc_fail_errno("create file");
7357718be8SEnji Cooper 
7457718be8SEnji Cooper 	for (written = 0; written < FSTEST_IMGSIZE + bonus; written +=n) {
7557718be8SEnji Cooper 		memset(buf, i++, sizeof(buf)); /* known garbage */
7657718be8SEnji Cooper 		n = rump_sys_write(fd, buf, sizeof(buf));
7757718be8SEnji Cooper 		if (n == -1)
7857718be8SEnji Cooper 			break;
7957718be8SEnji Cooper 	}
8057718be8SEnji Cooper 	if (FSTYPE_ZFS(tc))
8157718be8SEnji Cooper 		atf_tc_expect_fail("PR kern/47656: Test known to be broken");
8257718be8SEnji Cooper 	if (n == -1) {
8357718be8SEnji Cooper 		if (errno != ENOSPC)
8457718be8SEnji Cooper 			atf_tc_fail_errno("write");
8557718be8SEnji Cooper 	} else {
8657718be8SEnji Cooper 		atf_tc_fail("filled file system over size limit");
8757718be8SEnji Cooper 	}
8857718be8SEnji Cooper 
8957718be8SEnji Cooper 	rump_sys_close(fd);
9057718be8SEnji Cooper 	rump_sys_chdir("/");
9157718be8SEnji Cooper }
9257718be8SEnji Cooper 
9357718be8SEnji Cooper ATF_TC_FSAPPLY(fillfs, "fills file system, expects ENOSPC");
9457718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)9557718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
9657718be8SEnji Cooper {
9757718be8SEnji Cooper 
9857718be8SEnji Cooper 	ATF_TP_FSAPPLY(fillfs);
9957718be8SEnji Cooper 
10057718be8SEnji Cooper 	return atf_no_error();
10157718be8SEnji Cooper }
102