2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting LAyer Tests (SPLAT) Vnode Tests.
27 #include <sys/vnode.h>
28 #include "splat-internal.h"
30 #define SPLAT_VNODE_NAME "vnode"
31 #define SPLAT_VNODE_DESC "Kernel Vnode Tests"
33 #define SPLAT_VNODE_TEST1_ID 0x0901
34 #define SPLAT_VNODE_TEST1_NAME "vn_open"
35 #define SPLAT_VNODE_TEST1_DESC "Vn_open Test"
37 #define SPLAT_VNODE_TEST2_ID 0x0902
38 #define SPLAT_VNODE_TEST2_NAME "vn_openat"
39 #define SPLAT_VNODE_TEST2_DESC "Vn_openat Test"
41 #define SPLAT_VNODE_TEST3_ID 0x0903
42 #define SPLAT_VNODE_TEST3_NAME "vn_rdwr"
43 #define SPLAT_VNODE_TEST3_DESC "Vn_rdwrt Test"
45 #define SPLAT_VNODE_TEST5_ID 0x0905
46 #define SPLAT_VNODE_TEST5_NAME "vn_getattr"
47 #define SPLAT_VNODE_TEST5_DESC "Vn_getattr Test"
49 #define SPLAT_VNODE_TEST6_ID 0x0906
50 #define SPLAT_VNODE_TEST6_NAME "vn_sync"
51 #define SPLAT_VNODE_TEST6_DESC "Vn_sync Test"
53 #define SPLAT_VNODE_TEST_FILE "/etc/fstab"
54 #define SPLAT_VNODE_TEST_FILE_AT "etc/fstab"
55 #define SPLAT_VNODE_TEST_FILE_RW "/tmp/spl.vnode.tmp"
56 #define SPLAT_VNODE_TEST_FILE_RW1 "/tmp/spl.vnode.tmp.1"
57 #define SPLAT_VNODE_TEST_FILE_RW2 "/tmp/spl.vnode.tmp.2"
60 splat_vnode_user_cmd(struct file
*file
, void *arg
,
61 char *name
, char *cmd
)
63 char sh_path
[] = "/bin/sh";
64 char *argv
[] = { sh_path
,
68 char *envp
[] = { "HOME=/",
70 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
74 rc
= call_usermodehelper(sh_path
, argv
, envp
, UMH_WAIT_PROC
);
76 splat_vprint(file
, name
,
77 "Failed command: %s %s %s (%d)\n",
78 argv
[0], argv
[1], cmd
, rc
);
86 splat_vnode_unlink_all(struct file
*file
, void *arg
, char *name
)
88 char *cmds
[] = { "rm -f " SPLAT_VNODE_TEST_FILE_RW
,
89 "rm -f " SPLAT_VNODE_TEST_FILE_RW1
,
90 "rm -f " SPLAT_VNODE_TEST_FILE_RW2
,
94 while (cmds
[i
] != NULL
) {
95 if ((rc
= splat_vnode_user_cmd(file
, arg
, name
, cmds
[i
])))
105 splat_vnode_test1(struct file
*file
, void *arg
)
110 if ((rc
= vn_open(SPLAT_VNODE_TEST_FILE
, UIO_SYSSPACE
,
111 FREAD
, 0644, &vp
, 0, 0))) {
112 splat_vprint(file
, SPLAT_VNODE_TEST1_NAME
,
113 "Failed to vn_open test file: %s (%d)\n",
114 SPLAT_VNODE_TEST_FILE
, rc
);
118 rc
= VOP_CLOSE(vp
, 0, 0, 0, 0, 0);
121 splat_vprint(file
, SPLAT_VNODE_TEST1_NAME
,
122 "Failed to vn_close test file: %s (%d)\n",
123 SPLAT_VNODE_TEST_FILE
, rc
);
127 splat_vprint(file
, SPLAT_VNODE_TEST1_NAME
, "Successfully vn_open'ed "
128 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE
);
131 } /* splat_vnode_test1() */
134 splat_vnode_test2(struct file
*file
, void *arg
)
139 if ((rc
= vn_openat(SPLAT_VNODE_TEST_FILE_AT
, UIO_SYSSPACE
,
140 FREAD
, 0644, &vp
, 0, 0, rootdir
, 0))) {
141 splat_vprint(file
, SPLAT_VNODE_TEST2_NAME
,
142 "Failed to vn_openat test file: %s (%d)\n",
143 SPLAT_VNODE_TEST_FILE
, rc
);
147 rc
= VOP_CLOSE(vp
, 0, 0, 0, 0, 0);
150 splat_vprint(file
, SPLAT_VNODE_TEST2_NAME
,
151 "Failed to vn_close test file: %s (%d)\n",
152 SPLAT_VNODE_TEST_FILE
, rc
);
156 splat_vprint(file
, SPLAT_VNODE_TEST2_NAME
, "Successfully vn_openat'ed "
157 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE
);
160 } /* splat_vnode_test2() */
163 splat_vnode_test3(struct file
*file
, void *arg
)
166 char buf1
[32] = "SPL VNode Interface Test File\n";
170 if ((rc
= splat_vnode_unlink_all(file
, arg
, SPLAT_VNODE_TEST3_NAME
)))
173 if ((rc
= vn_open(SPLAT_VNODE_TEST_FILE_RW
, UIO_SYSSPACE
,
174 FWRITE
| FREAD
| FCREAT
| FEXCL
,
176 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
,
177 "Failed to vn_open test file: %s (%d)\n",
178 SPLAT_VNODE_TEST_FILE_RW
, rc
);
182 rc
= vn_rdwr(UIO_WRITE
, vp
, buf1
, strlen(buf1
), 0,
183 UIO_SYSSPACE
, 0, RLIM64_INFINITY
, 0, NULL
);
185 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
,
186 "Failed vn_rdwr write of test file: %s (%d)\n",
187 SPLAT_VNODE_TEST_FILE_RW
, rc
);
191 rc
= vn_rdwr(UIO_READ
, vp
, buf2
, strlen(buf1
), 0,
192 UIO_SYSSPACE
, 0, RLIM64_INFINITY
, 0, NULL
);
194 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
,
195 "Failed vn_rdwr read of test file: %s (%d)\n",
196 SPLAT_VNODE_TEST_FILE_RW
, rc
);
200 if (strncmp(buf1
, buf2
, strlen(buf1
))) {
202 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
,
203 "Failed strncmp data written does not match "
204 "data read\nWrote: %sRead: %s\n", buf1
, buf2
);
209 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
, "Wrote: %s", buf1
);
210 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
, "Read: %s", buf2
);
211 splat_vprint(file
, SPLAT_VNODE_TEST3_NAME
, "Successfully wrote and "
212 "read expected data pattern to test file: %s\n",
213 SPLAT_VNODE_TEST_FILE_RW
);
216 VOP_CLOSE(vp
, 0, 0, 0, 0, 0);
219 } /* splat_vnode_test3() */
222 splat_vnode_test5(struct file
*file
, void *arg
)
228 if ((rc
= vn_open(SPLAT_VNODE_TEST_FILE
, UIO_SYSSPACE
,
229 FREAD
, 0644, &vp
, 0, 0))) {
230 splat_vprint(file
, SPLAT_VNODE_TEST5_NAME
,
231 "Failed to vn_open test file: %s (%d)\n",
232 SPLAT_VNODE_TEST_FILE
, rc
);
236 rc
= VOP_GETATTR(vp
, &vap
, 0, 0, NULL
);
238 splat_vprint(file
, SPLAT_VNODE_TEST5_NAME
,
239 "Failed to vn_getattr test file: %s (%d)\n",
240 SPLAT_VNODE_TEST_FILE
, rc
);
244 if (vap
.va_type
!= VREG
) {
246 splat_vprint(file
, SPLAT_VNODE_TEST5_NAME
,
247 "Failed expected regular file type "
248 "(%d != VREG): %s (%d)\n", vap
.va_type
,
249 SPLAT_VNODE_TEST_FILE
, rc
);
253 splat_vprint(file
, SPLAT_VNODE_TEST1_NAME
, "Successfully "
254 "vn_getattr'ed test file: %s\n", SPLAT_VNODE_TEST_FILE
);
257 VOP_CLOSE(vp
, 0, 0, 0, 0, 0);
260 } /* splat_vnode_test5() */
263 splat_vnode_test6(struct file
*file
, void *arg
)
266 char buf
[32] = "SPL VNode Interface Test File\n";
269 if ((rc
= splat_vnode_unlink_all(file
, arg
, SPLAT_VNODE_TEST6_NAME
)))
272 if ((rc
= vn_open(SPLAT_VNODE_TEST_FILE_RW
, UIO_SYSSPACE
,
273 FWRITE
| FCREAT
| FEXCL
, 0644, &vp
, 0, 0))) {
274 splat_vprint(file
, SPLAT_VNODE_TEST6_NAME
,
275 "Failed to vn_open test file: %s (%d)\n",
276 SPLAT_VNODE_TEST_FILE_RW
, rc
);
280 rc
= vn_rdwr(UIO_WRITE
, vp
, buf
, strlen(buf
), 0,
281 UIO_SYSSPACE
, 0, RLIM64_INFINITY
, 0, NULL
);
283 splat_vprint(file
, SPLAT_VNODE_TEST6_NAME
,
284 "Failed vn_rdwr write of test file: %s (%d)\n",
285 SPLAT_VNODE_TEST_FILE_RW
, rc
);
289 rc
= vn_fsync(vp
, 0, 0, 0);
291 splat_vprint(file
, SPLAT_VNODE_TEST6_NAME
,
292 "Failed vn_fsync of test file: %s (%d)\n",
293 SPLAT_VNODE_TEST_FILE_RW
, rc
);
298 splat_vprint(file
, SPLAT_VNODE_TEST6_NAME
, "Successfully "
299 "fsync'ed test file %s\n", SPLAT_VNODE_TEST_FILE_RW
);
301 VOP_CLOSE(vp
, 0, 0, 0, 0, 0);
304 } /* splat_vnode_test6() */
307 splat_vnode_init(void)
309 splat_subsystem_t
*sub
;
311 sub
= kmalloc(sizeof(*sub
), GFP_KERNEL
);
315 memset(sub
, 0, sizeof(*sub
));
316 strncpy(sub
->desc
.name
, SPLAT_VNODE_NAME
, SPLAT_NAME_SIZE
);
317 strncpy(sub
->desc
.desc
, SPLAT_VNODE_DESC
, SPLAT_DESC_SIZE
);
318 INIT_LIST_HEAD(&sub
->subsystem_list
);
319 INIT_LIST_HEAD(&sub
->test_list
);
320 spin_lock_init(&sub
->test_lock
);
321 sub
->desc
.id
= SPLAT_SUBSYSTEM_VNODE
;
323 splat_test_init(sub
, SPLAT_VNODE_TEST1_NAME
, SPLAT_VNODE_TEST1_DESC
,
324 SPLAT_VNODE_TEST1_ID
, splat_vnode_test1
);
325 splat_test_init(sub
, SPLAT_VNODE_TEST2_NAME
, SPLAT_VNODE_TEST2_DESC
,
326 SPLAT_VNODE_TEST2_ID
, splat_vnode_test2
);
327 splat_test_init(sub
, SPLAT_VNODE_TEST3_NAME
, SPLAT_VNODE_TEST3_DESC
,
328 SPLAT_VNODE_TEST3_ID
, splat_vnode_test3
);
329 splat_test_init(sub
, SPLAT_VNODE_TEST5_NAME
, SPLAT_VNODE_TEST5_DESC
,
330 SPLAT_VNODE_TEST5_ID
, splat_vnode_test5
);
331 splat_test_init(sub
, SPLAT_VNODE_TEST6_NAME
, SPLAT_VNODE_TEST6_DESC
,
332 SPLAT_VNODE_TEST6_ID
, splat_vnode_test6
);
335 } /* splat_vnode_init() */
338 splat_vnode_fini(splat_subsystem_t
*sub
)
342 splat_test_fini(sub
, SPLAT_VNODE_TEST6_ID
);
343 splat_test_fini(sub
, SPLAT_VNODE_TEST5_ID
);
344 splat_test_fini(sub
, SPLAT_VNODE_TEST3_ID
);
345 splat_test_fini(sub
, SPLAT_VNODE_TEST2_ID
);
346 splat_test_fini(sub
, SPLAT_VNODE_TEST1_ID
);
349 } /* splat_vnode_fini() */
354 return SPLAT_SUBSYSTEM_VNODE
;
355 } /* splat_vnode_id() */