summaryrefslogtreecommitdiff
path: root/tests/fs/ffs/t_update_log.c
blob: bb83a566c57b159091594f3b8f20753616109a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*	$NetBSD: t_update_log.c,v 1.1 2017/03/22 21:33:53 jdolecek Exp $	*/

/*
 * Check log behaviour on mount updates
 */

#include <atf-c.h>

#define FSTEST_IMGSIZE (96 * 512)
#include "../common/h_fsmacros.h"

#include <sys/types.h>
#include <sys/mount.h>

#include <stdlib.h>

#include <ufs/ufs/ufsmount.h>

#include <rump/rump.h>
#include <rump/rump_syscalls.h>

#include "h_macros.h"

ATF_TC(updaterwtolog);
ATF_TC_HEAD(updaterwtolog, tc)
{

	atf_tc_set_md_var(tc, "descr", "mounts file system with "
	    "rw, then rw+log");
}

/*
 * PR kern/52056
 * This doesn't trigger panic with old, despite same operations triggering
 * it with live kernel.
 * Steps:
 * 1. boot singleuser
 * 2. mount -u /
 * 3. echo abc > abc
 * 4. mount -u -o log /
 * 5. echo abc >> abc
 *
 * Keeping around just in case.
 */
ATF_TC_BODY(updaterwtolog, tc)
{
	char buf[1024];
	struct ufs_args args;
	int n = 10, fd;
	const char *newfs_args = "-O2";
	const char teststring[] = "6c894efc21094525ca1f974c0189b3b0c4e1f28d";

        snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
            "%s %s", (n + 3), newfs_args, FSTEST_IMGNAME);
        if (system(buf) == -1)
                atf_tc_fail_errno("cannot create file system");

        rump_init();
        if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
                atf_tc_fail_errno("mount point create");

        rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);

        args.fspec = __UNCONST("/diskdev");

        if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_RDONLY,
            &args, sizeof(args)) == -1)
                atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);

	if (rump_sys_chdir(FSTEST_MNTNAME) == 1)
		atf_tc_fail_errno("chdir");

        if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_UPDATE,
            &args, sizeof(args)) == -1)
                atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);

	RL(fd = rump_sys_open("dummy", O_CREAT | O_RDWR, 0755));
	RL(rump_sys_write(fd, teststring, strlen(teststring)));
	rump_sys_close(fd);

        if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_LOG|MNT_UPDATE,
            &args, sizeof(args)) == -1)
                atf_tc_fail_errno("mount ffs rw log update %s", FSTEST_MNTNAME);

	RL(fd = rump_sys_open("dummy", O_APPEND | O_RDWR, 0755));
	RL(rump_sys_write(fd, teststring, strlen(teststring)));
	rump_sys_close(fd);

	/* otherwise we're do-ne */
}

ATF_TC(updaterwtolog_async);
ATF_TC_HEAD(updaterwtolog_async, tc)
{

	atf_tc_set_md_var(tc, "descr", "mounts file system with "
	    "rw+async, then rw+async+log");
}

/*
 * PR kern/52056
 */
ATF_TC_BODY(updaterwtolog_async, tc)
{
	char buf[1024];
	struct ufs_args args;
	int n = 10, fd;
	const char *newfs_args = "-O2";

        snprintf(buf, sizeof(buf), "newfs -q user -q group -F -s 4000 -n %d "
            "%s %s", (n + 3), newfs_args, FSTEST_IMGNAME);
        if (system(buf) == -1)
                atf_tc_fail_errno("cannot create file system");

        rump_init();
        if (rump_sys_mkdir(FSTEST_MNTNAME, 0777) == -1)
                atf_tc_fail_errno("mount point create");

        rump_pub_etfs_register("/diskdev", FSTEST_IMGNAME, RUMP_ETFS_BLK);

        args.fspec = __UNCONST("/diskdev");

        if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, 0,
            &args, sizeof(args)) == -1)
                atf_tc_fail_errno("mount ffs rw %s", FSTEST_MNTNAME);

	if (rump_sys_chdir(FSTEST_MNTNAME) == 1)
		atf_tc_fail_errno("chdir");

	RL(fd = rump_sys_open("dummy", O_CREAT | O_RDWR, 0755));
	sprintf(buf, "test file");
	RL(rump_sys_write(fd, buf, strlen(buf)));
	rump_sys_close(fd);

        if (rump_sys_mount(MOUNT_FFS, FSTEST_MNTNAME, MNT_LOG|MNT_ASYNC|MNT_UPDATE,
            &args, sizeof(args)) == -1)
                atf_tc_fail_errno("mount ffs rw log update %s", FSTEST_MNTNAME);

	/* otherwise we're do-ne */
}

ATF_TP_ADD_TCS(tp)
{
	ATF_TP_ADD_TC(tp, updaterwtolog);
	ATF_TP_ADD_TC(tp, updaterwtolog_async);

	return atf_no_error();
}