~ubuntu-branches/ubuntu/wily/spl-linux/wily

« back to all changes in this revision

Viewing changes to module/splat/splat-vnode.c

  • Committer: Package Import Robot
  • Author(s): Aron Xu
  • Date: 2013-04-02 01:03:05 UTC
  • Revision ID: package-import@ubuntu.com-20130402010305-bt9to0tn48joen5q
Tags: upstream-0.6.1
ImportĀ upstreamĀ versionĀ 0.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
static int
 
227
splat_vnode_test4(struct file *file, void *arg)
 
228
{
 
229
        vnode_t *vp;
 
230
        char buf1[32] = "SPL VNode Interface Test File\n";
 
231
        char buf2[32] = "";
 
232
        int rc;
 
233
 
 
234
        if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST4_NAME)))
 
235
                return rc;
 
236
 
 
237
        if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE,
 
238
                          FWRITE | FREAD | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
 
239
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
 
240
                             "Failed to vn_open test file: %s (%d)\n",
 
241
                             SPLAT_VNODE_TEST_FILE_RW1, rc);
 
242
                goto out;
 
243
        }
 
244
 
 
245
        rc = vn_rdwr(UIO_WRITE, vp, buf1, strlen(buf1), 0,
 
246
                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
 
247
        if (rc) {
 
248
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
 
249
                             "Failed vn_rdwr write of test file: %s (%d)\n",
 
250
                             SPLAT_VNODE_TEST_FILE_RW1, rc);
 
251
                goto out2;
 
252
        }
 
253
 
 
254
        VOP_CLOSE(vp, 0, 0, 0, 0, 0);
 
255
 
 
256
        rc = vn_rename(SPLAT_VNODE_TEST_FILE_RW1,SPLAT_VNODE_TEST_FILE_RW2,0);
 
257
        if (rc) {
 
258
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Failed vn_rename "
 
259
                             "%s -> %s (%d)\n",
 
260
                             SPLAT_VNODE_TEST_FILE_RW1,
 
261
                             SPLAT_VNODE_TEST_FILE_RW2, rc);
 
262
                goto out;
 
263
        }
 
264
 
 
265
        if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE,
 
266
                          FREAD | FEXCL, 0644, &vp, 0, 0))) {
 
267
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
 
268
                             "Failed to vn_open test file: %s (%d)\n",
 
269
                             SPLAT_VNODE_TEST_FILE_RW2, rc);
 
270
                goto out;
 
271
        }
 
272
 
 
273
        rc = vn_rdwr(UIO_READ, vp, buf2, strlen(buf1), 0,
 
274
                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
 
275
        if (rc) {
 
276
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
 
277
                             "Failed vn_rdwr read of test file: %s (%d)\n",
 
278
                             SPLAT_VNODE_TEST_FILE_RW2, rc);
 
279
                goto out2;
 
280
        }
 
281
 
 
282
        if (strncmp(buf1, buf2, strlen(buf1))) {
 
283
                rc = EINVAL;
 
284
                splat_vprint(file, SPLAT_VNODE_TEST4_NAME,
 
285
                             "Failed strncmp data written does not match "
 
286
                             "data read\nWrote: %sRead:  %s\n", buf1, buf2);
 
287
                goto out2;
 
288
        }
 
289
 
 
290
        rc = 0;
 
291
        splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Wrote to %s:  %s",
 
292
                     SPLAT_VNODE_TEST_FILE_RW1, buf1);
 
293
        splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Read from %s: %s",
 
294
                     SPLAT_VNODE_TEST_FILE_RW2, buf2);
 
295
        splat_vprint(file, SPLAT_VNODE_TEST4_NAME, "Successfully renamed "
 
296
                     "test file %s -> %s and verified data pattern\n",
 
297
                     SPLAT_VNODE_TEST_FILE_RW1, SPLAT_VNODE_TEST_FILE_RW2);
 
298
out2:
 
299
        VOP_CLOSE(vp, 0, 0, 0, 0, 0);
 
300
out:
 
301
        vn_remove(SPLAT_VNODE_TEST_FILE_RW1, UIO_SYSSPACE, RMFILE);
 
302
        vn_remove(SPLAT_VNODE_TEST_FILE_RW2, UIO_SYSSPACE, RMFILE);
 
303
 
 
304
        return -rc;
 
305
} /* splat_vnode_test4() */
 
306
 
 
307
static int
 
308
splat_vnode_test5(struct file *file, void *arg)
 
309
{
 
310
        vnode_t *vp;
 
311
        vattr_t vap;
 
312
        int rc;
 
313
 
 
314
        if ((rc = vn_open(SPLAT_VNODE_TEST_FILE, UIO_SYSSPACE,
 
315
                          FREAD, 0644, &vp, 0, 0))) {
 
316
                splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
 
317
                             "Failed to vn_open test file: %s (%d)\n",
 
318
                             SPLAT_VNODE_TEST_FILE, rc);
 
319
                return -rc;
 
320
        }
 
321
 
 
322
        rc = VOP_GETATTR(vp, &vap, 0, 0, NULL);
 
323
        if (rc) {
 
324
                splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
 
325
                             "Failed to vn_getattr test file: %s (%d)\n",
 
326
                             SPLAT_VNODE_TEST_FILE, rc);
 
327
                goto out;
 
328
        }
 
329
 
 
330
        if (vap.va_type != VREG) {
 
331
                rc = EINVAL;
 
332
                splat_vprint(file, SPLAT_VNODE_TEST5_NAME,
 
333
                             "Failed expected regular file type "
 
334
                             "(%d != VREG): %s (%d)\n", vap.va_type,
 
335
                             SPLAT_VNODE_TEST_FILE, rc);
 
336
                goto out;
 
337
        }
 
338
 
 
339
        splat_vprint(file, SPLAT_VNODE_TEST1_NAME, "Successfully "
 
340
                     "vn_getattr'ed test file: %s\n", SPLAT_VNODE_TEST_FILE);
 
341
 
 
342
out:
 
343
        VOP_CLOSE(vp, 0, 0, 0, 0, 0);
 
344
 
 
345
        return -rc;
 
346
} /* splat_vnode_test5() */
 
347
 
 
348
static int
 
349
splat_vnode_test6(struct file *file, void *arg)
 
350
{
 
351
        vnode_t *vp;
 
352
        char buf[32] = "SPL VNode Interface Test File\n";
 
353
        int rc;
 
354
 
 
355
        if ((rc = splat_vnode_unlink_all(file, arg, SPLAT_VNODE_TEST6_NAME)))
 
356
                return rc;
 
357
 
 
358
        if ((rc = vn_open(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE,
 
359
                          FWRITE | FCREAT | FEXCL, 0644, &vp, 0, 0))) {
 
360
                splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
 
361
                             "Failed to vn_open test file: %s (%d)\n",
 
362
                             SPLAT_VNODE_TEST_FILE_RW, rc);
 
363
                return -rc;
 
364
        }
 
365
 
 
366
        rc = vn_rdwr(UIO_WRITE, vp, buf, strlen(buf), 0,
 
367
                     UIO_SYSSPACE, 0, RLIM64_INFINITY, 0, NULL);
 
368
        if (rc) {
 
369
                splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
 
370
                             "Failed vn_rdwr write of test file: %s (%d)\n",
 
371
                             SPLAT_VNODE_TEST_FILE_RW, rc);
 
372
                goto out;
 
373
        }
 
374
 
 
375
        rc = vn_fsync(vp, 0, 0, 0);
 
376
        if (rc) {
 
377
                splat_vprint(file, SPLAT_VNODE_TEST6_NAME,
 
378
                             "Failed vn_fsync of test file: %s (%d)\n",
 
379
                             SPLAT_VNODE_TEST_FILE_RW, rc);
 
380
                goto out;
 
381
        }
 
382
 
 
383
        rc = 0;
 
384
        splat_vprint(file, SPLAT_VNODE_TEST6_NAME, "Successfully "
 
385
                     "fsync'ed test file %s\n", SPLAT_VNODE_TEST_FILE_RW);
 
386
out:
 
387
        VOP_CLOSE(vp, 0, 0, 0, 0, 0);
 
388
        vn_remove(SPLAT_VNODE_TEST_FILE_RW, UIO_SYSSPACE, RMFILE);
 
389
 
 
390
        return -rc;
 
391
} /* splat_vnode_test6() */
 
392
 
 
393
splat_subsystem_t *
 
394
splat_vnode_init(void)
 
395
{
 
396
        splat_subsystem_t *sub;
 
397
 
 
398
        sub = kmalloc(sizeof(*sub), GFP_KERNEL);
 
399
        if (sub == NULL)
 
400
                return NULL;
 
401
 
 
402
        memset(sub, 0, sizeof(*sub));
 
403
        strncpy(sub->desc.name, SPLAT_VNODE_NAME, SPLAT_NAME_SIZE);
 
404
        strncpy(sub->desc.desc, SPLAT_VNODE_DESC, SPLAT_DESC_SIZE);
 
405
        INIT_LIST_HEAD(&sub->subsystem_list);
 
406
        INIT_LIST_HEAD(&sub->test_list);
 
407
        spin_lock_init(&sub->test_lock);
 
408
        sub->desc.id = SPLAT_SUBSYSTEM_VNODE;
 
409
 
 
410
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST1_NAME, SPLAT_VNODE_TEST1_DESC,
 
411
                        SPLAT_VNODE_TEST1_ID, splat_vnode_test1);
 
412
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST2_NAME, SPLAT_VNODE_TEST2_DESC,
 
413
                        SPLAT_VNODE_TEST2_ID, splat_vnode_test2);
 
414
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST3_NAME, SPLAT_VNODE_TEST3_DESC,
 
415
                        SPLAT_VNODE_TEST3_ID, splat_vnode_test3);
 
416
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST4_NAME, SPLAT_VNODE_TEST4_DESC,
 
417
                        SPLAT_VNODE_TEST4_ID, splat_vnode_test4);
 
418
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST5_NAME, SPLAT_VNODE_TEST5_DESC,
 
419
                        SPLAT_VNODE_TEST5_ID, splat_vnode_test5);
 
420
        SPLAT_TEST_INIT(sub, SPLAT_VNODE_TEST6_NAME, SPLAT_VNODE_TEST6_DESC,
 
421
                        SPLAT_VNODE_TEST6_ID, splat_vnode_test6);
 
422
 
 
423
        return sub;
 
424
} /* splat_vnode_init() */
 
425
 
 
426
void
 
427
splat_vnode_fini(splat_subsystem_t *sub)
 
428
{
 
429
        ASSERT(sub);
 
430
 
 
431
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST6_ID);
 
432
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST5_ID);
 
433
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST4_ID);
 
434
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST3_ID);
 
435
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST2_ID);
 
436
        SPLAT_TEST_FINI(sub, SPLAT_VNODE_TEST1_ID);
 
437
 
 
438
        kfree(sub);
 
439
} /* splat_vnode_fini() */
 
440
 
 
441
int
 
442
splat_vnode_id(void)
 
443
{
 
444
        return SPLAT_SUBSYSTEM_VNODE;
 
445
} /* splat_vnode_id() */