Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add test for read/write to readonly update mount.



details:   https://anonhg.NetBSD.org/src/rev/bc9964cc76a2
branches:  trunk
changeset: 350927:bc9964cc76a2
user:      hannken <hannken%NetBSD.org@localhost>
date:      Fri Jan 27 10:45:11 2017 +0000

description:
Add test for read/write to readonly update mount.

diffstat:

 distrib/sets/lists/debug/mi |    3 +-
 distrib/sets/lists/tests/mi |    3 +-
 tests/fs/vfs/Makefile       |    4 +-
 tests/fs/vfs/t_rwtoro.c     |  233 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 240 insertions(+), 3 deletions(-)

diffs (296 lines):

diff -r 9577221f159d -r bc9964cc76a2 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Fri Jan 27 10:21:16 2017 +0000
+++ b/distrib/sets/lists/debug/mi       Fri Jan 27 10:45:11 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.192 2017/01/16 08:18:11 ozaki-r Exp $
+# $NetBSD: mi,v 1.193 2017/01/27 10:45:11 hannken Exp $
 ./etc/mtree/set.debug                           comp-sys-root
 ./usr/lib                                      comp-sys-usr            compatdir
 ./usr/lib/i18n/libBIG5_g.a                     comp-c-debuglib         debuglib,compatfile
@@ -1642,6 +1642,7 @@
 ./usr/libdata/debug/usr/tests/fs/vfs/t_renamerace.debug                        tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/vfs/t_rmdirrace.debug                 tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/vfs/t_ro.debug                        tests-fs-debug          debug,atf,rump
+./usr/libdata/debug/usr/tests/fs/vfs/t_rwtoro.debug                    tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/vfs/t_union.debug                     tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/vfs/t_unpriv.debug                    tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/vfs/t_vfsops.debug                    tests-fs-debug          debug,atf,rump
diff -r 9577221f159d -r bc9964cc76a2 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Fri Jan 27 10:21:16 2017 +0000
+++ b/distrib/sets/lists/tests/mi       Fri Jan 27 10:45:11 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.714 2017/01/14 01:44:13 christos Exp $
+# $NetBSD: mi,v 1.715 2017/01/27 10:45:11 hannken Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1549,6 +1549,7 @@
 ./usr/tests/fs/vfs/t_renamerace                                tests-fs-tests          atf,rump
 ./usr/tests/fs/vfs/t_rmdirrace                         tests-fs-tests          atf,rump
 ./usr/tests/fs/vfs/t_ro                                        tests-fs-tests          atf,rump
+./usr/tests/fs/vfs/t_rwtoro                            tests-fs-tests          atf,rump
 ./usr/tests/fs/vfs/t_union                             tests-fs-tests          atf,rump
 ./usr/tests/fs/vfs/t_unpriv                            tests-fs-tests          atf,rump
 ./usr/tests/fs/vfs/t_vfsops                            tests-fs-tests          atf,rump
diff -r 9577221f159d -r bc9964cc76a2 tests/fs/vfs/Makefile
--- a/tests/fs/vfs/Makefile     Fri Jan 27 10:21:16 2017 +0000
+++ b/tests/fs/vfs/Makefile     Fri Jan 27 10:45:11 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.22 2016/08/27 08:38:58 christos Exp $
+#      $NetBSD: Makefile,v 1.23 2017/01/27 10:45:11 hannken Exp $
 #
 
 .include <bsd.own.mk>
@@ -11,6 +11,7 @@
 TESTS_C+=      t_renamerace
 TESTS_C+=      t_ro
 TESTS_C+=      t_rmdirrace
+TESTS_C+=      t_rwtoro
 TESTS_C+=      t_union
 TESTS_C+=      t_unpriv
 TESTS_C+=      t_vfsops
@@ -30,6 +31,7 @@
 LDADD+=-lrumpfs_union                                          # union
 LDADD+=-lrumpfs_v7fs                                           # v7fs
 LDADD+=-lrumpdev_disk -lrumpdev                                        # disk device
+LDADD+=-lrumpfs_null -lrumpvfs_layerfs                         # nullfs
 
 
 VFSTESTDIR != cd ${.CURDIR}/../common && ${PRINTOBJDIR}
diff -r 9577221f159d -r bc9964cc76a2 tests/fs/vfs/t_rwtoro.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fs/vfs/t_rwtoro.c   Fri Jan 27 10:45:11 2017 +0000
@@ -0,0 +1,233 @@
+/*     $NetBSD: t_rwtoro.c,v 1.1 2017/01/27 10:45:11 hannken Exp $     */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+
+#include <atf-c.h>
+#include <fcntl.h>
+#include <libgen.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <rump/rump_syscalls.h>
+#include <rump/rump.h>
+
+#include <miscfs/nullfs/null.h>
+#include <fs/tmpfs/tmpfs_args.h>
+
+#include "../common/h_fsmacros.h"
+#include "../../h_macros.h"
+
+static const char *unsupported = "fs does not support r/o remount";
+static char file_path[MAXPATHLEN];
+static int file_fd;
+
+/*
+ * Remount the filesystem read-only and test errno.
+ * Skip filesystems that don't implement read-write -> read-only.
+ */
+static void
+remount_ro(const atf_tc_t *tc, const char *mp, int expected_errno)
+{
+       int error;
+       union {
+               struct tmpfs_args tmpfs;
+               char data[4095];
+       } mount_args;
+       int mount_args_length;
+       struct statvfs sbuf;
+
+       if (FSTYPE_ZFS(tc))
+               atf_tc_skip("%s", unsupported);
+
+       /* Prepare mount arguments. */
+       RL(rump_sys_statvfs1(mp, &sbuf, ST_WAIT));
+       mount_args_length = sizeof(mount_args);
+       memset(&mount_args, 0, mount_args_length);
+       if (FSTYPE_TMPFS(tc))
+               mount_args.tmpfs.ta_version = TMPFS_ARGS_VERSION;
+       mount_args_length = rump_sys_mount(sbuf.f_fstypename, mp, MNT_GETARGS,
+           &mount_args, mount_args_length);
+       ATF_CHECK(mount_args_length >= 0);
+
+       /* Remount and test result. */
+       error = rump_sys_mount(sbuf.f_fstypename, mp, MNT_UPDATE | MNT_RDONLY,
+           &mount_args, mount_args_length);
+       if (errno == EOPNOTSUPP)
+               atf_tc_skip("%s", unsupported);
+       if (expected_errno == 0)
+               ATF_CHECK(error == 0);
+       else
+               ATF_CHECK_ERRNO(expected_errno, error == -1);
+}
+
+static void
+open_file_ro(const char *prefix)
+{
+
+       snprintf(file_path, sizeof(file_path), "%s/file", prefix);
+       RL(file_fd = rump_sys_open(file_path, O_CREAT | O_RDWR, 0777));
+       RL(rump_sys_close(file_fd));
+       RL(file_fd = rump_sys_open(file_path, O_RDONLY));
+}
+
+static void
+open_file_ro_unlink(const char *prefix)
+{
+
+       snprintf(file_path, sizeof(file_path), "%s/file", prefix);
+       RL(file_fd = rump_sys_open(file_path, O_CREAT | O_RDWR, 0777));
+       RL(rump_sys_close(file_fd));
+       RL(file_fd = rump_sys_open(file_path, O_RDONLY));
+       RL(rump_sys_unlink(file_path));
+}
+
+static void
+open_file_rw(const char *prefix)
+{
+
+       snprintf(file_path, sizeof(file_path), "%s/file", prefix);
+       RL(file_fd = rump_sys_open(file_path, O_CREAT | O_RDWR, 0777));
+}
+
+static void
+close_file(const char *unused)
+{
+
+       RL(rump_sys_close(file_fd));
+}
+
+static void
+basic_test(const atf_tc_t *tc, const char *mp, int expected_errno,
+    bool use_layer, void (*pre)(const char *), void (*post)(const char *))
+{
+       const char *null_mount = "/nullm";
+       struct null_args nargs;
+
+       if (use_layer) {
+               RL(rump_sys_mkdir(null_mount, 0777));
+               memset(&nargs, 0, sizeof(nargs));
+               nargs.nulla_target = __UNCONST(mp);;
+               RL(rump_sys_mount(MOUNT_NULL, null_mount, 0,
+                   &nargs, sizeof(nargs)));
+       }
+       if (pre)
+               (*pre)(use_layer ? null_mount : mp);
+       remount_ro(tc, mp, expected_errno);
+       if (post)
+               (*post)(use_layer ? null_mount : mp);
+       if (use_layer)
+               RL(rump_sys_unmount(null_mount, 0));
+}
+
+static void
+noneopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, 0, false, NULL, NULL);
+}
+
+static void
+readopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, 0, false, open_file_ro, close_file);
+}
+
+static void
+writeopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, EBUSY, false, open_file_rw, close_file);
+}
+
+static void
+read_unlinked(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, EBUSY, false, open_file_ro_unlink, close_file);
+}
+
+static void
+layer_noneopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, 0, true, NULL, NULL);
+}
+
+static void
+layer_readopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, 0, true, open_file_ro, close_file);
+}
+
+static void
+layer_writeopen(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, EBUSY, true, open_file_rw, close_file);
+}
+
+static void
+layer_read_unlinked(const atf_tc_t *tc, const char *mp)
+{
+
+       basic_test(tc, mp, EBUSY, true, open_file_ro_unlink, close_file);
+}
+
+ATF_TC_FSAPPLY(noneopen, "remount r/o with no file open");
+ATF_TC_FSAPPLY(readopen, "remount r/o with file open for reading");
+ATF_TC_FSAPPLY(writeopen, "remount r/o with file open for writing");
+ATF_TC_FSAPPLY(read_unlinked,
+    "remount r/o with unlinked file open for reading");
+ATF_TC_FSAPPLY(layer_noneopen, "remount r/o with no file open on layer");
+ATF_TC_FSAPPLY(layer_readopen,
+    "remount r/o with file open for reading on layer");
+ATF_TC_FSAPPLY(layer_writeopen,
+    "remount r/o with file open for writing on layer");
+ATF_TC_FSAPPLY(layer_read_unlinked,
+    "remount r/o with unlinked file open for reading on layer");
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_FSAPPLY(noneopen);
+       ATF_TP_FSAPPLY(readopen);
+       ATF_TP_FSAPPLY(writeopen);
+       ATF_TP_FSAPPLY(read_unlinked);
+       ATF_TP_FSAPPLY(layer_noneopen);
+       ATF_TP_FSAPPLY(layer_readopen);
+       ATF_TP_FSAPPLY(layer_writeopen);
+       ATF_TP_FSAPPLY(layer_read_unlinked);
+
+       return atf_no_error();
+}



Home | Main Index | Thread Index | Old Index