1/* $NetBSD: t_update_log.c,v 1.1 2017/03/22 21:33:53 jdolecek Exp $ */ 2 3/* 4 * Check log behaviour on mount updates 5 */ 6 7#include <atf-c.h> 8 9#define FSTEST_IMGSIZE (96 * 512) 10#include "../common/h_fsmacros.h" 11 12#include <sys/types.h> 13#include <sys/mount.h> 14 15#include <stdlib.h> 16 17#include <ufs/ufs/ufsmount.h> 18 19#include <rump/rump.h> 20#include <rump/rump_syscalls.h> 21 22#include "h_macros.h" 23 24ATF_TC(updaterwtolog); 25ATF_TC_HEAD(updaterwtolog, tc) 26{ 27 28 atf_tc_set_md_var(tc, "descr", "mounts file system with " 29 "rw, then rw+log"); 30} 31 32/* 33 * PR kern/52056 34 * This doesn't trigger panic with old, despite same operations triggering 35 * it with live kernel. 36 * Steps: 37 * 1. boot singleuser 38 * 2. mount -u / 39 * 3. echo abc > abc 40 * 4. mount -u -o log / 41 * 5. echo abc >> abc 42 * 43 * Keeping around just in case. 44 */ 45ATF_TC_BODY(updaterwtolog, tc) 46{ 47 char buf[1024]; 48 struct ufs_args args; 49 int n = 10, fd; 50 const char *newfs_args = "-O2"; 51 const char teststring[] = "6c894efc21094525ca1f974c0189b3b0c4e1f28d"; 52 53 snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d " 54 "%s %s", (n + 3), newfs_args, FSTEST_IMGNAME); 55 if (system(buf) == -1) 56 atf_tc_fail_errno("cannot create file system"); 57 58 rump_init(); 59 if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1) 60 atf_tc_fail_errno("mount point create"); 61 62 rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK); 63 64 args.fspec = __UNCONST("/diskdev"); 65 66 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_RDONLY, 67 &args, sizeof(args)) == -1) 68 atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME); 69 70 if (rump_sys_chdir(FSTEST_MNTNAME) == 1) 71 atf_tc_fail_errno("chdir"); 72 73 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_UPDATE, 74 &args, sizeof(args)) == -1) 75 atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME); 76 77 RL(fd = rump_sys_open("dummy", O_CREAT | O_RDWR, 0755)); 78 RL(rump_sys_write(fd, teststring, strlen(teststring))); 79 rump_sys_close(fd); 80 81 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_LOG|MNT_UPDATE, 82 &args, sizeof(args)) == -1) 83 atf_tc_fail_errno("mount ffs rw log update %s", FSTEST_MNTNAME); 84 85 RL(fd = rump_sys_open("dummy", O_APPEND | O_RDWR, 0755)); 86 RL(rump_sys_write(fd, teststring, strlen(teststring))); 87 rump_sys_close(fd); 88 89 /* otherwise we're do-ne */ 90} 91 92ATF_TC(updaterwtolog_async); 93ATF_TC_HEAD(updaterwtolog_async, tc) 94{ 95 96 atf_tc_set_md_var(tc, "descr", "mounts file system with " 97 "rw+async, then rw+async+log"); 98} 99 100/* 101 * PR kern/52056 102 */ 103ATF_TC_BODY(updaterwtolog_async, tc) 104{ 105 char buf[1024]; 106 struct ufs_args args; 107 int n = 10, fd; 108 const char *newfs_args = "-O2"; 109 110 snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d " 111 "%s %s", (n + 3), newfs_args, FSTEST_IMGNAME); 112 if (system(buf) == -1) 113 atf_tc_fail_errno("cannot create file system"); 114 115 rump_init(); 116 if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1) 117 atf_tc_fail_errno("mount point create"); 118 119 rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK); 120 121 args.fspec = __UNCONST("/diskdev"); 122 123 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, 0, 124 &args, sizeof(args)) == -1) 125 atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME); 126 127 if (rump_sys_chdir(FSTEST_MNTNAME) == 1) 128 atf_tc_fail_errno("chdir"); 129 130 RL(fd = rump_sys_open("dummy", O_CREAT | O_RDWR, 0755)); 131 sprintf(buf, "test file"); 132 RL(rump_sys_write(fd, buf, strlen(buf))); 133 rump_sys_close(fd); 134 135 if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_LOG|MNT_ASYNC|MNT_UPDATE, 136 &args, sizeof(args)) == -1) 137 atf_tc_fail_errno("mount ffs rw log update %s", FSTEST_MNTNAME); 138 139 /* otherwise we're do-ne */ 140} 141 142ATF_TP_ADD_TCS(tp) 143{ 144 ATF_TP_ADD_TC(tp, updaterwtolog); 145 ATF_TP_ADD_TC(tp, updaterwtolog_async); 146 147 return atf_no_error(); 148} 149