]> git.proxmox.com Git - mirror_spl-debian.git/blame - module/splat/splat-vnode.c
New upstream version 0.7.2
[mirror_spl-debian.git] / module / splat / splat-vnode.c
CommitLineData
716154c5
BB
1/*****************************************************************************\
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>.
715f6251 6 * UCRL-CODE-235197
7 *
716154c5 8 * This file is part of the SPL, Solaris Porting Layer.
3d6af2dd 9 * For details, see <http://zfsonlinux.org/>.
716154c5
BB
10 *
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.
715f6251 15 *
716154c5 16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
715f6251 17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
716154c5
BB
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting LAyer Tests (SPLAT) Vnode Tests.
25\*****************************************************************************/
715f6251 26
df870a69 27#include <sys/vnode.h>
4b171585 28#include "splat-internal.h"
29
4b171585 30#define SPLAT_VNODE_NAME "vnode"
31#define SPLAT_VNODE_DESC "Kernel Vnode Tests"
32
33#define SPLAT_VNODE_TEST1_ID 0x0901
34#define SPLAT_VNODE_TEST1_NAME "vn_open"
35#define SPLAT_VNODE_TEST1_DESC "Vn_open Test"
36
37#define SPLAT_VNODE_TEST2_ID 0x0902
38#define SPLAT_VNODE_TEST2_NAME "vn_openat"
39#define SPLAT_VNODE_TEST2_DESC "Vn_openat Test"
40
41#define SPLAT_VNODE_TEST3_ID 0x0903
42#define SPLAT_VNODE_TEST3_NAME "vn_rdwr"
43#define SPLAT_VNODE_TEST3_DESC "Vn_rdwrt Test"
44
45#define SPLAT_VNODE_TEST4_ID 0x0904
46#define SPLAT_VNODE_TEST4_NAME "vn_rename"
47#define SPLAT_VNODE_TEST4_DESC "Vn_rename Test"
48
49#define SPLAT_VNODE_TEST5_ID 0x0905
50#define SPLAT_VNODE_TEST5_NAME "vn_getattr"
51#define SPLAT_VNODE_TEST5_DESC "Vn_getattr Test"
52
53#define SPLAT_VNODE_TEST6_ID 0x0906
54#define SPLAT_VNODE_TEST6_NAME "vn_sync"
55#define SPLAT_VNODE_TEST6_DESC "Vn_sync Test"
56
57#define SPLAT_VNODE_TEST_FILE "/etc/fstab"
58#define SPLAT_VNODE_TEST_FILE_AT "etc/fstab"
59#define SPLAT_VNODE_TEST_FILE_RW "/tmp/spl.vnode.tmp"
60#define SPLAT_VNODE_TEST_FILE_RW1 "/tmp/spl.vnode.tmp.1"
61#define SPLAT_VNODE_TEST_FILE_RW2 "/tmp/spl.vnode.tmp.2"
62
f60a5f52
BB
63static int
64splat_vnode_user_cmd(struct file *file, void *arg,
65 char *name, char *cmd)
66{
67 char sh_path[] = "/bin/sh";
68 char *argv[] = { sh_path,
69 "-c",
70 cmd,
71 NULL };
72 char *envp[] = { "HOME=/",
73 "TERM=linux",
74 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
75 NULL };
76 int rc;
77
8842263b 78 rc = call_usermodehelper(sh_path, argv, envp, UMH_WAIT_PROC);
f60a5f52
BB
79 if (rc) {
80 splat_vprint(file, name,
81 "Failed command: %s %s %s (%d)\n",
82 argv[0], argv[1], cmd, rc);
83 return -EPERM;
84 }
85
86 return 0;
87}
88
89static int
90splat_vnode_unlink_all(struct file *file, void *arg, char *name)
91{
92 char *cmds[] = { "rm -f " SPLAT_VNODE_TEST_FILE_RW,
93 "rm -f " SPLAT_VNODE_TEST_FILE_RW1,
94 "rm -f " SPLAT_VNODE_TEST_FILE_RW2,
95 NULL };
96 int i = 0, rc = 0;
97
98 while (cmds[i] != NULL) {
99 if ((rc = splat_vnode_user_cmd(file, arg, name, cmds[i])))
100 return rc;
101
102 i++;
103 }
104
105 return rc;
106}
107
4b171585 108static int
109splat_vnode_test1(struct file *file, void *arg)
110{
111 vnode_t *vp;
112 int rc;
113
114 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE, UIO_SYSSPACE,
115 FREAD, 0644, &vp, 0, 0))) {
116 splat_vprint(file, SPLAT_VNODE_TEST1_NAME,
117 "Failed to vn_open test file: %s (%d)\n",
118 SPLAT_VNODE_TEST_FILE, rc);
f60a5f52 119 return -rc;
4b171585 120 }
121
122 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 123
124 if (rc) {
125 splat_vprint(file, SPLAT_VNODE_TEST1_NAME,
126 "Failed to vn_close test file: %s (%d)\n",
127 SPLAT_VNODE_TEST_FILE, rc);
f60a5f52 128 return -rc;
4b171585 129 }
130
131 splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully vn_open'ed "
132 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE);
133
f60a5f52 134 return -rc;
4b171585 135} /* splat_vnode_test1() */
136
137static int
138splat_vnode_test2(struct file *file, void *arg)
139{
140 vnode_t *vp;
141 int rc;
142
143 if ((rc = vn_openat(SPLAT_VNODE_TEST_FILE_AT, UIO_SYSSPACE,
144 FREAD, 0644, &vp, 0, 0, rootdir, 0))) {
145 splat_vprint(file, SPLAT_VNODE_TEST2_NAME,
146 "Failed to vn_openat test file: %s (%d)\n",
147 SPLAT_VNODE_TEST_FILE, rc);
f60a5f52 148 return -rc;
4b171585 149 }
150
151 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 152
153 if (rc) {
154 splat_vprint(file, SPLAT_VNODE_TEST2_NAME,
155 "Failed to vn_close test file: %s (%d)\n",
156 SPLAT_VNODE_TEST_FILE, rc);
f60a5f52 157 return -rc;
4b171585 158 }
159
160 splat_vprint(file, SPLAT_VNODE_TEST2_NAME, "Successfully vn_openat'ed "
161 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE);
162
f60a5f52 163 return -rc;
4b171585 164} /* splat_vnode_test2() */
165
166static int
167splat_vnode_test3(struct file *file, void *arg)
168{
169 vnode_t *vp;
170 char buf1[32] = "SPL VNode Interface Test File\n";
171 char buf2[32] = "";
172 int rc;
173
f60a5f52
BB
174 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST3_NAME)))
175 return rc;
176
4b171585 177 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
178 FWRITE | FREAD | FCREAT | FEXCL,
179 0644, &vp, 0, 0))) {
180 splat_vprint(file, SPLAT_VNODE_TEST3_NAME,
181 "Failed to vn_open test file: %s (%d)\n",
182 SPLAT_VNODE_TEST_FILE_RW, rc);
f60a5f52 183 return -rc;
4b171585 184 }
185
186 rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
187 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 188 if (rc) {
4b171585 189 splat_vprint(file, SPLAT_VNODE_TEST3_NAME,
190 "Failed vn_rdwr write of test file: %s (%d)\n",
191 SPLAT_VNODE_TEST_FILE_RW, rc);
192 goto out;
193 }
194
195 rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
196 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 197 if (rc) {
4b171585 198 splat_vprint(file, SPLAT_VNODE_TEST3_NAME,
199 "Failed vn_rdwr read of test file: %s (%d)\n",
200 SPLAT_VNODE_TEST_FILE_RW, rc);
201 goto out;
202 }
203
204 if (strncmp(buf1, buf2, strlen(buf1))) {
f60a5f52 205 rc = EINVAL;
4b171585 206 splat_vprint(file, SPLAT_VNODE_TEST3_NAME,
207 "Failed strncmp data written does not match "
208 "data read\nWrote: %sRead: %s\n", buf1, buf2);
209 goto out;
210 }
211
212 rc = 0;
213 splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Wrote: %s", buf1);
214 splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Read: %s", buf2);
215 splat_vprint(file, SPLAT_VNODE_TEST3_NAME, "Successfully wrote and "
216 "read expected data pattern to test file: %s\n",
217 SPLAT_VNODE_TEST_FILE_RW);
218
219out:
220 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
2f5d55aa 221 vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
4b171585 222
f60a5f52 223 return -rc;
4b171585 224} /* splat_vnode_test3() */
225
f6188ddd 226#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
4b171585 227static int
228splat_vnode_test4(struct file *file, void *arg)
229{
230 vnode_t *vp;
231 char buf1[32] = "SPL VNode Interface Test File\n";
232 char buf2[32] = "";
233 int rc;
234
f60a5f52
BB
235 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST4_NAME)))
236 return rc;
237
4b171585 238 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE,
239 FWRITE | FREAD | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
240 splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
241 "Failed to vn_open test file: %s (%d)\n",
242 SPLAT_VNODE_TEST_FILE_RW1, rc);
243 goto out;
244 }
245
246 rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
247 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 248 if (rc) {
4b171585 249 splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
250 "Failed vn_rdwr write of test file: %s (%d)\n",
251 SPLAT_VNODE_TEST_FILE_RW1, rc);
252 goto out2;
253 }
254
255 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 256
257 rc = vn_rename(SPLAT_VNODE_TEST_FILE_RW1,SPLAT_VNODE_TEST_FILE_RW2,0);
258 if (rc) {
259 splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Failed vn_rename "
260 "%s -> %s (%d)\n",
261 SPLAT_VNODE_TEST_FILE_RW1,
262 SPLAT_VNODE_TEST_FILE_RW2, rc);
263 goto out;
264 }
265
266 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE,
267 FREAD | FEXCL, 0644, &vp, 0, 0))) {
268 splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
269 "Failed to vn_open test file: %s (%d)\n",
270 SPLAT_VNODE_TEST_FILE_RW2, rc);
271 goto out;
272 }
273
274 rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
275 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 276 if (rc) {
4b171585 277 splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
278 "Failed vn_rdwr read of test file: %s (%d)\n",
279 SPLAT_VNODE_TEST_FILE_RW2, rc);
280 goto out2;
281 }
282
283 if (strncmp(buf1, buf2, strlen(buf1))) {
284 rc = EINVAL;
285 splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
286 "Failed strncmp data written does not match "
287 "data read\nWrote: %sRead: %s\n", buf1, buf2);
288 goto out2;
289 }
290
291 rc = 0;
292 splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Wrote to %s: %s",
293 SPLAT_VNODE_TEST_FILE_RW1, buf1);
294 splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Read from %s: %s",
295 SPLAT_VNODE_TEST_FILE_RW2, buf2);
296 splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Successfully renamed "
297 "test file %s -> %s and verified data pattern\n",
298 SPLAT_VNODE_TEST_FILE_RW1, SPLAT_VNODE_TEST_FILE_RW2);
299out2:
300 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 301out:
2f5d55aa 302 vn_remove(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE, RMFILE);
303 vn_remove(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE, RMFILE);
4b171585 304
f60a5f52 305 return -rc;
4b171585 306} /* splat_vnode_test4() */
f6188ddd 307#endif
4b171585 308
309static int
310splat_vnode_test5(struct file *file, void *arg)
311{
312 vnode_t *vp;
313 vattr_t vap;
314 int rc;
315
316 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE, UIO_SYSSPACE,
317 FREAD, 0644, &vp, 0, 0))) {
318 splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
319 "Failed to vn_open test file: %s (%d)\n",
320 SPLAT_VNODE_TEST_FILE, rc);
f60a5f52 321 return -rc;
4b171585 322 }
323
324 rc = VOP_GETATTR(vp, &vap, 0, 0, NULL);
325 if (rc) {
326 splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
327 "Failed to vn_getattr test file: %s (%d)\n",
328 SPLAT_VNODE_TEST_FILE, rc);
329 goto out;
330 }
331
332 if (vap.va_type != VREG) {
f60a5f52 333 rc = EINVAL;
4b171585 334 splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
335 "Failed expected regular file type "
336 "(%d != VREG): %s (%d)\n", vap.va_type,
337 SPLAT_VNODE_TEST_FILE, rc);
338 goto out;
339 }
340
341 splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully "
342 "vn_getattr'ed test file: %s\n", SPLAT_VNODE_TEST_FILE);
343
344out:
345 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 346
f60a5f52 347 return -rc;
4b171585 348} /* splat_vnode_test5() */
349
350static int
351splat_vnode_test6(struct file *file, void *arg)
352{
353 vnode_t *vp;
354 char buf[32] = "SPL VNode Interface Test File\n";
355 int rc;
356
f60a5f52
BB
357 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))
358 return rc;
359
4b171585 360 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
728b9dd8 361 FWRITE | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
4b171585 362 splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
363 "Failed to vn_open test file: %s (%d)\n",
364 SPLAT_VNODE_TEST_FILE_RW, rc);
f60a5f52 365 return -rc;
4b171585 366 }
367
368 rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,
369 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 370 if (rc) {
4b171585 371 splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
372 "Failed vn_rdwr write of test file: %s (%d)\n",
373 SPLAT_VNODE_TEST_FILE_RW, rc);
374 goto out;
375 }
376
377 rc = vn_fsync(vp, 0, 0, 0);
378 if (rc) {
379 splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
380 "Failed vn_fsync of test file: %s (%d)\n",
381 SPLAT_VNODE_TEST_FILE_RW, rc);
382 goto out;
383 }
384
385 rc = 0;
386 splat_vprint(file, SPLAT_VNODE_TEST6_NAME, "Successfully "
387 "fsync'ed test file %s\n", SPLAT_VNODE_TEST_FILE_RW);
388out:
389 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
2f5d55aa 390 vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
4b171585 391
f60a5f52 392 return -rc;
e4f1d29f 393} /* splat_vnode_test6() */
394
4b171585 395splat_subsystem_t *
396splat_vnode_init(void)
397{
398 splat_subsystem_t *sub;
399
400 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
401 if (sub == NULL)
402 return NULL;
403
404 memset(sub, 0, sizeof(*sub));
405 strncpy(sub->desc.name, SPLAT_VNODE_NAME, SPLAT_NAME_SIZE);
406 strncpy(sub->desc.desc, SPLAT_VNODE_DESC, SPLAT_DESC_SIZE);
407 INIT_LIST_HEAD(&sub->subsystem_list);
408 INIT_LIST_HEAD(&sub->test_list);
409 spin_lock_init(&sub->test_lock);
410 sub->desc.id = SPLAT_SUBSYSTEM_VNODE;
411
ec06701b 412 splat_test_init(sub, SPLAT_VNODE_TEST1_NAME, SPLAT_VNODE_TEST1_DESC,
4b171585 413 SPLAT_VNODE_TEST1_ID, splat_vnode_test1);
ec06701b 414 splat_test_init(sub, SPLAT_VNODE_TEST2_NAME, SPLAT_VNODE_TEST2_DESC,
4b171585 415 SPLAT_VNODE_TEST2_ID, splat_vnode_test2);
ec06701b 416 splat_test_init(sub, SPLAT_VNODE_TEST3_NAME, SPLAT_VNODE_TEST3_DESC,
4b171585 417 SPLAT_VNODE_TEST3_ID, splat_vnode_test3);
f6188ddd 418#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
ec06701b 419 splat_test_init(sub, SPLAT_VNODE_TEST4_NAME, SPLAT_VNODE_TEST4_DESC,
4b171585 420 SPLAT_VNODE_TEST4_ID, splat_vnode_test4);
f6188ddd 421#endif
ec06701b 422 splat_test_init(sub, SPLAT_VNODE_TEST5_NAME, SPLAT_VNODE_TEST5_DESC,
4b171585 423 SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
ec06701b 424 splat_test_init(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
4b171585 425 SPLAT_VNODE_TEST6_ID, splat_vnode_test6);
426
427 return sub;
428} /* splat_vnode_init() */
429
430void
431splat_vnode_fini(splat_subsystem_t *sub)
432{
433 ASSERT(sub);
434
ec06701b
AX
435 splat_test_fini(sub, SPLAT_VNODE_TEST6_ID);
436 splat_test_fini(sub, SPLAT_VNODE_TEST5_ID);
f6188ddd 437#if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
ec06701b 438 splat_test_fini(sub, SPLAT_VNODE_TEST4_ID);
f6188ddd 439#endif
ec06701b
AX
440 splat_test_fini(sub, SPLAT_VNODE_TEST3_ID);
441 splat_test_fini(sub, SPLAT_VNODE_TEST2_ID);
442 splat_test_fini(sub, SPLAT_VNODE_TEST1_ID);
4b171585 443
444 kfree(sub);
445} /* splat_vnode_fini() */
446
447int
448splat_vnode_id(void)
449{
450 return SPLAT_SUBSYSTEM_VNODE;
451} /* splat_vnode_id() */