]> git.proxmox.com Git - mirror_spl.git/blame - module/splat/splat-vnode.c
Remove vn_rename and vn_remove
[mirror_spl.git] / module / splat / splat-vnode.c
CommitLineData
4b393c50 1/*
716154c5
BB
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.
4b393c50 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
4b171585 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
f60a5f52
BB
59static int
60splat_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
8842263b 74 rc = call_usermodehelper(sh_path, argv, envp, UMH_WAIT_PROC);
f60a5f52
BB
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
85static int
86splat_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
4b171585 104static int
105splat_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);
f60a5f52 115 return -rc;
4b171585 116 }
117
118 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 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);
f60a5f52 124 return -rc;
4b171585 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
f60a5f52 130 return -rc;
4b171585 131} /* splat_vnode_test1() */
132
133static int
134splat_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);
f60a5f52 144 return -rc;
4b171585 145 }
146
147 rc = VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 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);
f60a5f52 153 return -rc;
4b171585 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
f60a5f52 159 return -rc;
4b171585 160} /* splat_vnode_test2() */
161
162static int
163splat_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
f60a5f52
BB
170 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST3_NAME)))
171 return rc;
172
4b171585 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);
f60a5f52 179 return -rc;
4b171585 180 }
181
182 rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
183 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 184 if (rc) {
4b171585 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);
f60a5f52 193 if (rc) {
4b171585 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))) {
f60a5f52 201 rc = EINVAL;
4b171585 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
215out:
216 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 217
f60a5f52 218 return -rc;
4b171585 219} /* splat_vnode_test3() */
220
4b171585 221static int
222splat_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);
f60a5f52 233 return -rc;
4b171585 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) {
f60a5f52 245 rc = EINVAL;
4b171585 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
256out:
257 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 258
f60a5f52 259 return -rc;
4b171585 260} /* splat_vnode_test5() */
261
262static int
263splat_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
f60a5f52
BB
269 if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))
270 return rc;
271
4b171585 272 if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
728b9dd8 273 FWRITE | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
4b171585 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);
f60a5f52 277 return -rc;
4b171585 278 }
279
280 rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,
281 UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
f60a5f52 282 if (rc) {
4b171585 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);
300out:
301 VOP_CLOSE(vp, 0, 0, 0, 0, 0);
4b171585 302
f60a5f52 303 return -rc;
e4f1d29f 304} /* splat_vnode_test6() */
305
4b171585 306splat_subsystem_t *
307splat_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
9c9ad845 323 splat_test_init(sub, SPLAT_VNODE_TEST1_NAME, SPLAT_VNODE_TEST1_DESC,
4b171585 324 SPLAT_VNODE_TEST1_ID, splat_vnode_test1);
9c9ad845 325 splat_test_init(sub, SPLAT_VNODE_TEST2_NAME, SPLAT_VNODE_TEST2_DESC,
4b171585 326 SPLAT_VNODE_TEST2_ID, splat_vnode_test2);
9c9ad845 327 splat_test_init(sub, SPLAT_VNODE_TEST3_NAME, SPLAT_VNODE_TEST3_DESC,
4b171585 328 SPLAT_VNODE_TEST3_ID, splat_vnode_test3);
9c9ad845 329 splat_test_init(sub, SPLAT_VNODE_TEST5_NAME, SPLAT_VNODE_TEST5_DESC,
4b171585 330 SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
9c9ad845 331 splat_test_init(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
4b171585 332 SPLAT_VNODE_TEST6_ID, splat_vnode_test6);
333
334 return sub;
335} /* splat_vnode_init() */
336
337void
338splat_vnode_fini(splat_subsystem_t *sub)
339{
340 ASSERT(sub);
341
9c9ad845
CC
342 splat_test_fini(sub, SPLAT_VNODE_TEST6_ID);
343 splat_test_fini(sub, SPLAT_VNODE_TEST5_ID);
9c9ad845
CC
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);
4b171585 347
348 kfree(sub);
349} /* splat_vnode_fini() */
350
351int
352splat_vnode_id(void)
353{
354 return SPLAT_SUBSYSTEM_VNODE;
355} /* splat_vnode_id() */