]> git.proxmox.com Git - mirror_spl.git/blob - module/splat/splat-vnode.c
4ccf24f1ea136ff62ff9ba02cab052f945267af0
[mirror_spl.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_TEST5_ID 0x0905
46 #define SPLAT_VNODE_TEST5_NAME "vn_getattr"
47 #define SPLAT_VNODE_TEST5_DESC "Vn_getattr Test"
48
49 #define SPLAT_VNODE_TEST6_ID 0x0906
50 #define SPLAT_VNODE_TEST6_NAME "vn_sync"
51 #define SPLAT_VNODE_TEST6_DESC "Vn_sync Test"
52
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"
58
59 static int
60 splat_vnode_user_cmd(struct file *file, void *arg,
61 char *name, char *cmd)
62 {
63 char sh_path[] = "/bin/sh";
64 char *argv[] = { sh_path,
65 "-c",
66 cmd,
67 NULL };
68 char *envp[] = { "HOME=/",
69 "TERM=linux",
70 "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
71 NULL };
72 int rc;
73
74 rc = call_usermodehelper(sh_path, argv, envp, UMH_WAIT_PROC);
75 if (rc) {
76 splat_vprint(file, name,
77 "Failed command: %s %s %s (%d)\n",
78 argv[0], argv[1], cmd, rc);
79 return -EPERM;
80 }
81
82 return 0;
83 }
84
85 static int
86 splat_vnode_unlink_all(struct file *file, void *arg, char *name)
87 {
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,
91 NULL };
92 int i = 0, rc = 0;
93
94 while (cmds[i] != NULL) {
95 if ((rc = splat_vnode_user_cmd(file, arg, name, cmds[i])))
96 return rc;
97
98 i++;
99 }
100
101 return rc;
102 }
103
104 static int
105 splat_vnode_test1(struct file *file, void *arg)
106 {
107 vnode_t *vp;
108 int rc;
109
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);
115 return -rc;
116 }
117
118 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
119
120 if (rc) {
121 splat_vprint(file, SPLAT_VNODE_TEST1_NAME,
122 "Failed to vn_close test file: %s (%d)\n",
123 SPLAT_VNODE_TEST_FILE, rc);
124 return -rc;
125 }
126
127 splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully vn_open'ed "
128 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE);
129
130 return -rc;
131 } /* splat_vnode_test1() */
132
133 static int
134 splat_vnode_test2(struct file *file, void *arg)
135 {
136 vnode_t *vp;
137 int rc;
138
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);
144 return -rc;
145 }
146
147 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
148
149 if (rc) {
150 splat_vprint(file, SPLAT_VNODE_TEST2_NAME,
151 "Failed to vn_close test file: %s (%d)\n",
152 SPLAT_VNODE_TEST_FILE, rc);
153 return -rc;
154 }
155
156 splat_vprint(file, SPLAT_VNODE_TEST2_NAME, "Successfully vn_openat'ed "
157 "and vn_closed test file: %s\n", SPLAT_VNODE_TEST_FILE);
158
159 return -rc;
160 } /* splat_vnode_test2() */
161
162 static int
163 splat_vnode_test3(struct file *file, void *arg)
164 {
165 vnode_t *vp;
166 char buf1[32] = "SPL VNode Interface Test File\n";
167 char buf2[32] = "";
168 int rc;
169
170 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST3_NAME)))
171 return rc;
172
173 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
174 FWRITE | FREAD | FCREAT | FEXCL,
175 0644, &vp, 0, 0))) {
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);
179 return -rc;
180 }
181
182 rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
183 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
184 if (rc) {
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);
188 goto out;
189 }
190
191 rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
192 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
193 if (rc) {
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);
197 goto out;
198 }
199
200 if (strncmp(buf1, buf2, strlen(buf1))) {
201 rc = EINVAL;
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);
205 goto out;
206 }
207
208 rc = 0;
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);
214
215 out:
216 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
217
218 return -rc;
219 } /* splat_vnode_test3() */
220
221 static int
222 splat_vnode_test5(struct file *file, void *arg)
223 {
224 vnode_t *vp;
225 vattr_t vap;
226 int rc;
227
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);
233 return -rc;
234 }
235
236 rc = VOP_GETATTR(vp, &vap, 0, 0, NULL);
237 if (rc) {
238 splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
239 "Failed to vn_getattr test file: %s (%d)\n",
240 SPLAT_VNODE_TEST_FILE, rc);
241 goto out;
242 }
243
244 if (vap.va_type != VREG) {
245 rc = EINVAL;
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);
250 goto out;
251 }
252
253 splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully "
254 "vn_getattr'ed test file: %s\n", SPLAT_VNODE_TEST_FILE);
255
256 out:
257 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
258
259 return -rc;
260 } /* splat_vnode_test5() */
261
262 static int
263 splat_vnode_test6(struct file *file, void *arg)
264 {
265 vnode_t *vp;
266 char buf[32] = "SPL VNode Interface Test File\n";
267 int rc;
268
269 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))
270 return rc;
271
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);
277 return -rc;
278 }
279
280 rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,
281 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
282 if (rc) {
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);
286 goto out;
287 }
288
289 rc = vn_fsync(vp, 0, 0, 0);
290 if (rc) {
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);
294 goto out;
295 }
296
297 rc = 0;
298 splat_vprint(file, SPLAT_VNODE_TEST6_NAME, "Successfully "
299 "fsync'ed test file %s\n", SPLAT_VNODE_TEST_FILE_RW);
300 out:
301 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
302
303 return -rc;
304 } /* splat_vnode_test6() */
305
306 splat_subsystem_t *
307 splat_vnode_init(void)
308 {
309 splat_subsystem_t *sub;
310
311 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
312 if (sub == NULL)
313 return NULL;
314
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;
322
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);
333
334 return sub;
335 } /* splat_vnode_init() */
336
337 void
338 splat_vnode_fini(splat_subsystem_t *sub)
339 {
340 ASSERT(sub);
341
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);
347
348 kfree(sub);
349 } /* splat_vnode_fini() */
350
351 int
352 splat_vnode_id(void)
353 {
354 return SPLAT_SUBSYSTEM_VNODE;
355 } /* splat_vnode_id() */