]> git.proxmox.com Git - mirror_spl-debian.git/blob - module/splat/splat-vnode.c
bffcf492ff5dae3c607f7cb9a2c37f0feb30f406
[mirror_spl-debian.git] / module / splat / splat-vnode.c
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>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
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.
15 *
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
19 * for more details.
20 *
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.
25 \*****************************************************************************/
26
27 #include <sys/vnode.h>
28 #include "splat-internal.h"
29
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
63 static int
64 splat_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
78 rc = call_usermodehelper(sh_path, argv, envp, UMH_WAIT_PROC);
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
89 static int
90 splat_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
108 static int
109 splat_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);
119 return -rc;
120 }
121
122 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
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);
128 return -rc;
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
134 return -rc;
135 } /* splat_vnode_test1() */
136
137 static int
138 splat_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);
148 return -rc;
149 }
150
151 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
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);
157 return -rc;
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
163 return -rc;
164 } /* splat_vnode_test2() */
165
166 static int
167 splat_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
174 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST3_NAME)))
175 return rc;
176
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);
183 return -rc;
184 }
185
186 rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
187 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
188 if (rc) {
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);
197 if (rc) {
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))) {
205 rc = EINVAL;
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
219 out:
220 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
221 vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
222
223 return -rc;
224 } /* splat_vnode_test3() */
225
226 #if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
227 static int
228 splat_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
235 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST4_NAME)))
236 return rc;
237
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);
248 if (rc) {
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);
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);
276 if (rc) {
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);
299 out2:
300 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
301 out:
302 vn_remove(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE, RMFILE);
303 vn_remove(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE, RMFILE);
304
305 return -rc;
306 } /* splat_vnode_test4() */
307 #endif
308
309 static int
310 splat_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);
321 return -rc;
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) {
333 rc = EINVAL;
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
344 out:
345 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
346
347 return -rc;
348 } /* splat_vnode_test5() */
349
350 static int
351 splat_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
357 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))
358 return rc;
359
360 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
361 FWRITE | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
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);
365 return -rc;
366 }
367
368 rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,
369 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
370 if (rc) {
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);
388 out:
389 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
390 vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
391
392 return -rc;
393 } /* splat_vnode_test6() */
394
395 splat_subsystem_t *
396 splat_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
412 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST1_NAME, SPLAT_VNODE_TEST1_DESC,
413 SPLAT_VNODE_TEST1_ID, splat_vnode_test1);
414 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST2_NAME, SPLAT_VNODE_TEST2_DESC,
415 SPLAT_VNODE_TEST2_ID, splat_vnode_test2);
416 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST3_NAME, SPLAT_VNODE_TEST3_DESC,
417 SPLAT_VNODE_TEST3_ID, splat_vnode_test3);
418 #if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
419 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST4_NAME, SPLAT_VNODE_TEST4_DESC,
420 SPLAT_VNODE_TEST4_ID, splat_vnode_test4);
421 #endif
422 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST5_NAME, SPLAT_VNODE_TEST5_DESC,
423 SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
424 SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
425 SPLAT_VNODE_TEST6_ID, splat_vnode_test6);
426
427 return sub;
428 } /* splat_vnode_init() */
429
430 void
431 splat_vnode_fini(splat_subsystem_t *sub)
432 {
433 ASSERT(sub);
434
435 SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST6_ID);
436 SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST5_ID);
437 #if LINUX_VERSION_CODE <= KERNEL_VERSION(4,1,0)
438 SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST4_ID);
439 #endif
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);
443
444 kfree(sub);
445 } /* splat_vnode_fini() */
446
447 int
448 splat_vnode_id(void)
449 {
450 return SPLAT_SUBSYSTEM_VNODE;
451 } /* splat_vnode_id() */