Source-Changes-HG archive

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

[src/trunk]: src/tests/fs/lfs Add skipped test for in-kernel roll-forward agent



details:   https://anonhg.NetBSD.org/src/rev/4069d47200e2
branches:  trunk
changeset: 974958:4069d47200e2
user:      perseant <perseant%NetBSD.org@localhost>
date:      Tue Aug 18 03:02:50 2020 +0000

description:
Add skipped test for in-kernel roll-forward agent

diffstat:

 distrib/sets/lists/debug/mi |    3 +-
 distrib/sets/lists/tests/mi |    3 +-
 tests/fs/lfs/Makefile       |    4 +-
 tests/fs/lfs/t_rfw.c        |  272 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 278 insertions(+), 4 deletions(-)

diffs (truncated from 328 to 300 lines):

diff -r 8a1bd4f4043e -r 4069d47200e2 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi       Tue Aug 18 02:53:25 2020 +0000
+++ b/distrib/sets/lists/debug/mi       Tue Aug 18 03:02:50 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.327 2020/08/14 00:53:16 riastradh Exp $
+# $NetBSD: mi,v 1.328 2020/08/18 03:02:50 perseant 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
@@ -1666,6 +1666,7 @@
 ./usr/libdata/debug/usr/tests/fs/hfs/t_pathconvert.debug               tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/kernfs/t_basic.debug                  tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/lfs/t_pr.debug                                tests-fs-debug          debug,atf,rump
+./usr/libdata/debug/usr/tests/fs/lfs/t_rfw.debug                       tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/msdosfs/t_snapshot.debug              tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/nfs/nfsservice/rumpnfsd.debug                 tests-fs-debug          debug,atf,rump
 ./usr/libdata/debug/usr/tests/fs/nfs/t_mountd.debug                    tests-fs-debug          debug,atf,rump
diff -r 8a1bd4f4043e -r 4069d47200e2 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Tue Aug 18 02:53:25 2020 +0000
+++ b/distrib/sets/lists/tests/mi       Tue Aug 18 03:02:50 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.892 2020/08/16 20:43:01 rillig Exp $
+# $NetBSD: mi,v 1.893 2020/08/18 03:02:50 perseant Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -1501,6 +1501,7 @@
 ./usr/tests/fs/lfs/Atffile                             tests-fs-tests          atf,rump
 ./usr/tests/fs/lfs/Kyuafile                            tests-fs-tests          atf,rump,kyua
 ./usr/tests/fs/lfs/t_pr                                        tests-fs-tests          atf,rump
+./usr/tests/fs/lfs/t_rfw                               tests-fs-tests          atf,rump
 ./usr/tests/fs/msdosfs                                 tests-fs-tests          compattestfile,atf
 ./usr/tests/fs/msdosfs/Atffile                         tests-fs-tests          atf,rump
 ./usr/tests/fs/msdosfs/Kyuafile                                tests-fs-tests          atf,rump,kyua
diff -r 8a1bd4f4043e -r 4069d47200e2 tests/fs/lfs/Makefile
--- a/tests/fs/lfs/Makefile     Tue Aug 18 02:53:25 2020 +0000
+++ b/tests/fs/lfs/Makefile     Tue Aug 18 03:02:50 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.2 2020/03/01 18:08:13 christos Exp $
+#      $NetBSD: Makefile,v 1.3 2020/08/18 03:02:50 perseant Exp $
 #
 
 .include <bsd.own.mk>
@@ -6,7 +6,7 @@
 TESTSDIR=      ${TESTSBASE}/fs/lfs
 WARNS=         4
 
-TESTS_C=       t_pr
+TESTS_C=       t_pr t_rfw
 
 LDADD+=-lrumpfs_lfs -lrumpfs_ffs                               # fs drivers
 LDADD+=-lrumpdev_disk -lrumpdev                                        # disk device
diff -r 8a1bd4f4043e -r 4069d47200e2 tests/fs/lfs/t_rfw.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/fs/lfs/t_rfw.c      Tue Aug 18 03:02:50 2020 +0000
@@ -0,0 +1,272 @@
+/*     $NetBSD: t_rfw.c,v 1.1 2020/08/18 03:02:50 perseant Exp $       */
+
+#include <sys/types.h>
+#include <sys/mount.h>
+#include <sys/sysctl.h>
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <rump/rump.h>
+#include <rump/rump_syscalls.h>
+
+#include <ufs/ufs/ufsmount.h>
+#include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_extern.h>
+
+#include "h_macros.h"
+
+/* Debugging conditions */
+/* #define FORCE_SUCCESS */ /* Don't actually revert, everything worked */
+/* #define FORCE_SYSCTL */ /* Don't check - necessary for FORCE_SUCCESS */
+
+/* Write a well-known byte pattern into a file, appending if it exists */
+int write_file(const char *, int);
+
+/* Check the byte pattern and size of the file */
+int check_file(const char *, int);
+
+ATF_TC(rfw);
+ATF_TC_HEAD(rfw, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+               "LFS roll-forward creates an inconsistent filesystem");
+       atf_tc_set_md_var(tc, "timeout", "20");
+}
+
+#define IMGNAME "disk.img"
+#define FAKEBLK "/dev/blk"
+#define LOGFILE "newfs.log"
+#define SBLOCK0_COPY "sb0.dd"
+#define SBLOCK1_COPY "sb1.dd"
+#define MAXLINE 132
+#define CHUNKSIZE 300
+ATF_TC_BODY(rfw, tc)
+{
+       struct ufs_args args;
+       FILE *pipe;
+#if (!defined FORCE_SUCCESS && !defined FORCE_SYSCTL)
+       int o_sysctl_rfw;
+       int n_sysctl_rfw;
+       int mib[3];
+       size_t len;
+#endif
+       char buf[MAXLINE];
+       long long sb0addr = -1, sb1addr = -1;
+
+       /*
+        * Initialize.
+        */
+#if (!defined FORCE_SUCCESS && !defined FORCE_SYSCTL)
+       /* Set sysctl to allow roll-forward */
+       fprintf(stderr, "* Set sysctl\n");
+       mib[0] = CTL_VFS;
+       mib[1] = 5; /* LFS */
+       mib[2] = LFS_DO_RFW;
+       len = sizeof(o_sysctl_rfw);
+       if (sysctl(mib, 3, &o_sysctl_rfw, &len,
+               &n_sysctl_rfw, sizeof(n_sysctl_rfw)) < 0)
+               atf_tc_skip("roll-forward not enabled in kernel");
+#endif /* !FORCE_SUCCESS && !FORCE_SYSCTL */
+
+       /* Create filesystem */
+       fprintf(stderr, "* Create file system\n");
+       if (system("newfs_lfs -D -F -s 10000 ./" IMGNAME " > " LOGFILE) == -1)
+               atf_tc_fail_errno("newfs failed");
+       pipe = fopen(LOGFILE, "r");
+       if (pipe == NULL)
+               atf_tc_fail_errno("newfs failed to execute");
+       while (fgets(buf, MAXLINE, pipe) != NULL) {
+               if (sscanf(buf, "%lld,%lld", &sb0addr, &sb1addr) == 2)
+                       break;
+       }
+       while (fgets(buf, MAXLINE, pipe) != NULL)
+               ;
+       fclose(pipe);
+       if (sb0addr < 0 || sb1addr < 0)
+               atf_tc_fail("superblock not found");
+       fprintf(stderr, "* Superblocks at %lld and %lld\n",
+               sb0addr, sb1addr);
+
+       /* Set up rump */
+       rump_init();
+       if (rump_sys_mkdir("/mp", 0777) == -1)
+               atf_tc_fail_errno("cannot create mountpoint");
+       rump_pub_etfs_register(FAKEBLK, IMGNAME, RUMP_ETFS_BLK);
+
+       /*
+        * Create initial filesystem state, from which
+        * we will attempt to roll forward.
+        */
+
+       /* Mount filesystem */
+       fprintf(stderr, "* Mount fs [1]\n");
+       memset(&args, 0, sizeof(args));
+       args.fspec = __UNCONST(FAKEBLK);
+       if (rump_sys_mount(MOUNT_LFS, "/mp", 0, &args, sizeof(args)) == -1)
+               atf_tc_fail_errno("rump_sys_mount failed");
+
+       /* Payload */
+       fprintf(stderr, "* Initial payload\n");
+       write_file("/mp/to_be_deleted", CHUNKSIZE);
+       write_file("/mp/to_be_appended", CHUNKSIZE);
+
+       /* Unmount */
+       rump_sys_unmount("/mp", 0);
+
+       /* Make copies of superblocks */
+       sprintf(buf, "dd if=%s of=%s bs=512 iseek=%lld count=16 conv=sync",
+               IMGNAME, SBLOCK0_COPY, sb0addr);
+       system(buf);
+       sprintf(buf, "dd if=%s of=%s bs=512 iseek=%lld count=16 conv=sync",
+               IMGNAME, SBLOCK1_COPY, sb1addr);
+       system(buf);
+
+       /*
+        * Make changes which we will attempt to roll forward.
+        */
+
+       /* Reconfigure and mount filesystem again */
+       fprintf(stderr, "* Mount fs [2]\n");
+       if (rump_sys_mount(MOUNT_LFS, "/mp", 0, &args, sizeof(args)) == -1)
+               atf_tc_fail_errno("rump_sys_mount failed [2]");
+
+       /* Add new file */
+       write_file("/mp/newly_created", CHUNKSIZE);
+
+       /* Append to existing file */
+       write_file("/mp/to_be_appended", CHUNKSIZE);
+
+       /* Delete file */
+       rump_sys_unlink("/mp/to_be_deleted");
+
+       /* Done with payload, unmount fs */
+       rump_sys_unmount("/mp", 0);
+
+#ifndef FORCE_SUCCESS
+       /*
+        * Copy back old superblocks, reverting FS to old state
+        */
+       sprintf(buf, "dd of=%s if=%s bs=512 oseek=%lld count=16 conv=sync,notrunc",
+               IMGNAME, SBLOCK0_COPY, sb0addr);
+       system(buf);
+       sprintf(buf, "dd of=%s if=%s bs=512 oseek=%lld count=16 conv=sync,notrunc",
+               IMGNAME, SBLOCK1_COPY, sb1addr);
+       system(buf);
+
+       if (system("fsck_lfs -n -f " IMGNAME))
+               atf_tc_fail_errno("fsck found errors with old superblocks");
+#endif
+
+       /*
+        * Roll forward.
+        */
+
+       /* Mount filesystem; this will roll forward. */
+       fprintf(stderr, "* Mount fs [3]\n");
+       if (rump_sys_mount(MOUNT_LFS, "/mp", 0, &args, sizeof(args)) == -1)
+               atf_tc_fail_errno("rump_sys_mount failed [3]");
+
+       /* Unmount filesystem */
+       rump_sys_unmount("/mp", 0);
+
+       /*
+        * Use fsck_lfs to look for consistency errors
+        */
+
+       if (system("fsck_lfs -n -f " IMGNAME))
+               atf_tc_fail_errno("fsck found errors");
+
+       /*
+        * Check file system contents
+        */
+
+       /* Mount filesystem one last time */
+       fprintf(stderr, "* Mount fs [4]\n");
+       if (rump_sys_mount(MOUNT_LFS, "/mp", 0, &args, sizeof(args)) == -1)
+               atf_tc_fail_errno("rump_sys_mount failed [4]");
+
+       if (check_file("/mp/newly_created", CHUNKSIZE) != 0)
+               atf_tc_fail("Newly added file differs");
+
+       if (check_file("/mp/to_be_appended", 2 * CHUNKSIZE) != 0)
+               atf_tc_fail("Appended file differs");
+
+       if (rump_sys_access("/mp/to_be_deleted", F_OK) == 0)
+               atf_tc_fail("Removed file still present");
+
+       /* Umount filesystem, test completed */
+       rump_sys_unmount("/mp", 0);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, rfw);
+       return atf_no_error();
+}
+
+/* Write some data into a file */
+int write_file(const char *filename, int add)
+{
+       int fd, size, i;
+       struct stat statbuf;
+       unsigned char b;
+       int flags = O_CREAT|O_WRONLY;
+
+       if (rump_sys_stat(filename, &statbuf) < 0)
+               size = 0;
+       else {
+               size = statbuf.st_size;
+               flags |= O_APPEND;
+       }
+
+       fd = rump_sys_open(filename, flags);
+
+       for (i = 0; i < add; i++) {
+               b = (size + i) & 0xff;
+               rump_sys_write(fd, &b, 1);
+       }
+       rump_sys_close(fd);
+
+       return 0;
+}
+
+/* Check file's existence, size and contents */
+int check_file(const char *filename, int size)
+{



Home | Main Index | Thread Index | Old Index