Module Name: src
Committed By: pooka
Date: Wed Jan 12 21:13:27 UTC 2011
Modified Files:
src/tests/fs/union: Makefile
src/tests/fs/vfs: Makefile
Added Files:
src/tests/fs/vfs: t_union.c
Removed Files:
src/tests/fs/union: t_basic.c
Log Message:
Move basic unionfs test from fs/union to fs/vfs and make it test
all whiteout-supporting file systems with the file system in question
as the upper layer. Also, add an unlink to the test to see if
whiteouts are really working.
ffslog_basic is the test case for PR kern/44377
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/fs/union/Makefile
cvs rdiff -u -r1.6 -r0 src/tests/fs/union/t_basic.c
cvs rdiff -u -r1.14 -r1.15 src/tests/fs/vfs/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/fs/vfs/t_union.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/tests/fs/union/Makefile
diff -u src/tests/fs/union/Makefile:1.2 src/tests/fs/union/Makefile:1.3
--- src/tests/fs/union/Makefile:1.2 Tue Jun 29 15:25:28 2010
+++ src/tests/fs/union/Makefile Wed Jan 12 21:13:26 2011
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.2 2010/06/29 15:25:28 pooka Exp $
+# $NetBSD: Makefile,v 1.3 2011/01/12 21:13:26 pooka Exp $
#
TESTSDIR= ${TESTSBASE}/fs/union
WARNS= 4
-TESTS_C= t_basic t_pr
+TESTS_C= t_pr
LDADD+= -lrumpfs_union -lrumpvfs_layerfs -lrumpfs_ffs # fs drivers
LDADD+= -lrumpdev_disk -lrumpdev # disk device
Index: src/tests/fs/vfs/Makefile
diff -u src/tests/fs/vfs/Makefile:1.14 src/tests/fs/vfs/Makefile:1.15
--- src/tests/fs/vfs/Makefile:1.14 Thu Jan 6 15:19:10 2011
+++ src/tests/fs/vfs/Makefile Wed Jan 12 21:13:27 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.14 2011/01/06 15:19:10 njoly Exp $
+# $NetBSD: Makefile,v 1.15 2011/01/12 21:13:27 pooka Exp $
#
.include <bsd.own.mk>
@@ -11,6 +11,7 @@
TESTS_C+= t_renamerace
TESTS_C+= t_ro
TESTS_C+= t_rmdirrace
+TESTS_C+= t_union
TESTS_C+= t_unpriv
TESTS_C+= t_vfsops
TESTS_C+= t_vnops
@@ -23,6 +24,7 @@
LDADD+=-lrumpdev_putter -lrumpdev # \ putter
LDADD+=-lrumpfs_sysvbfs # sysvbfs
LDADD+=-lrumpfs_tmpfs # tmpfs
+LDADD+=-lrumpfs_union # union
LDADD+=-lrumpdev_disk -lrumpdev # disk device
Added files:
Index: src/tests/fs/vfs/t_union.c
diff -u /dev/null src/tests/fs/vfs/t_union.c:1.1
--- /dev/null Wed Jan 12 21:13:27 2011
+++ src/tests/fs/vfs/t_union.c Wed Jan 12 21:13:27 2011
@@ -0,0 +1,136 @@
+/* $NetBSD: t_union.c,v 1.1 2011/01/12 21:13:27 pooka Exp $ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#include <atf-c.h>
+#include <err.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <miscfs/union/union.h>
+
+#include "../../h_macros.h"
+#include "../common/h_fsmacros.h"
+
+#define MSTR "magic bus"
+
+#define HAS_WHITEOUT (FSTYPE_FFS(tc) || FSTYPE_FFSLOG(tc) || \
+ FSTYPE_LFS(tc) || FSTYPE_RUMPFS(tc))
+
+static void
+xput_tfile(const char *mp, const char *path)
+{
+ char pathb[MAXPATHLEN];
+ int fd;
+
+ strcpy(pathb, mp);
+ strcat(pathb, "/");
+ strcat(pathb, path);
+
+ RL(fd = rump_sys_open(pathb, O_CREAT | O_RDWR, 0777));
+ if (rump_sys_write(fd, MSTR, sizeof(MSTR)) != sizeof(MSTR))
+ atf_tc_fail_errno("write to testfile");
+ RL(rump_sys_close(fd));
+}
+
+static int
+xread_tfile(const char *mp, const char *path)
+{
+ char pathb[MAXPATHLEN];
+ char buf[128];
+ int fd;
+
+ strcpy(pathb, mp);
+ strcat(pathb, "/");
+ strcat(pathb, path);
+
+ fd = rump_sys_open(pathb, O_RDONLY);
+ if (fd == -1)
+ return errno;
+ if (rump_sys_read(fd, buf, sizeof(buf)) == -1)
+ atf_tc_fail_errno("read tfile");
+ RL(rump_sys_close(fd));
+ if (strcmp(buf, MSTR) == 0)
+ return 0;
+ return EPROGMISMATCH;
+}
+
+#define TFILE "tensti"
+static void
+basic(const atf_tc_t *tc, const char *mp)
+{
+ char lowerpath[MAXPATHLEN];
+ char dbuf[8192];
+ struct union_args unionargs;
+ struct stat sb;
+ struct dirent *dp;
+ int error, fd, dsize;
+
+ if (!HAS_WHITEOUT) {
+ atf_tc_skip("file system does not support VOP_WHITEOUT");
+ }
+
+ snprintf(lowerpath, sizeof(lowerpath), "%s.lower", mp);
+
+ RL(rump_sys_mkdir(lowerpath, 0777));
+
+ /* create a file in the lower layer */
+ xput_tfile(lowerpath, TFILE);
+
+ /* mount the union with our testfs as the upper layer */
+ memset(&unionargs, 0, sizeof(unionargs));
+ unionargs.target = lowerpath;
+ unionargs.mntflags = UNMNT_BELOW;
+
+ if (rump_sys_mount(MOUNT_UNION, mp, 0,
+ &unionargs, sizeof(unionargs)) == -1)
+ atf_tc_fail_errno("union mount");
+
+ /* first, test we can read the old file from the new namespace */
+ error = xread_tfile(mp, TFILE);
+ if (error != 0)
+ atf_tc_fail("union compare failed: %d (%s)",
+ error, strerror(error));
+
+ /* then, test upper layer writes don't affect the lower layer */
+ xput_tfile(mp, "kiekko");
+ if ((error = xread_tfile(lowerpath, "kiekko")) != ENOENT)
+ atf_tc_fail("invisibility failed: %d (%s)",
+ error, strerror(error));
+
+ /* check that we can whiteout stuff in the upper layer */
+ FSTEST_ENTER();
+ RL(rump_sys_unlink(TFILE));
+ ATF_REQUIRE_ERRNO(ENOENT, rump_sys_stat(TFILE, &sb) == -1);
+ FSTEST_EXIT();
+
+ /* check that the removed node is not in the directory listing */
+ RL(fd = rump_sys_open(mp, O_RDONLY));
+ RL(dsize = rump_sys_getdents(fd, dbuf, sizeof(dbuf)));
+ for (dp = (struct dirent *)dbuf;
+ (char *)dp < dbuf + dsize;
+ dp = _DIRENT_NEXT(dp)) {
+ if (strcmp(dp->d_name, TFILE) == 0 && dp->d_type != DT_WHT)
+ atf_tc_fail("removed file non-white-outed");
+ }
+ RL(rump_sys_close(fd));
+
+ RL(rump_sys_unmount(mp, 0));
+}
+
+ATF_TC_FSAPPLY(basic, "check basic union functionality");
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_FSAPPLY(basic);
+ return atf_no_error();
+}