]> git.proxmox.com Git - mirror_spl.git/blame - modules/splat/splat-kobj.c
OK, some pretty substantial rework here. I've merged the spl-file
[mirror_spl.git] / modules / splat / splat-kobj.c
CommitLineData
9490c148 1#include "splat-internal.h"
2
4b171585 3#define SPLAT_SUBSYSTEM_KOBJ 0x0a00
9490c148 4#define SPLAT_KOBJ_NAME "kobj"
5d86345d 5#define SPLAT_KOBJ_DESC "Kernel Kobj Tests"
9490c148 6
4b171585 7#define SPLAT_KOBJ_TEST1_ID 0x0a01
8#define SPLAT_KOBJ_TEST1_NAME "open"
5d86345d 9#define SPLAT_KOBJ_TEST1_DESC "Kobj Open/Close Test"
9490c148 10
4b171585 11#define SPLAT_KOBJ_TEST2_ID 0x0a02
12#define SPLAT_KOBJ_TEST2_NAME "size/read"
5d86345d 13#define SPLAT_KOBJ_TEST2_DESC "Kobj Size/Read Test"
9490c148 14
15#define SPLAT_KOBJ_TEST_FILE "/etc/fstab"
16
17static int
18splat_kobj_test1(struct file *file, void *arg)
19{
20 struct _buf *f;
21
22 f = kobj_open_file(SPLAT_KOBJ_TEST_FILE);
23 if (f == (struct _buf *)-1) {
24 splat_vprint(file, SPLAT_KOBJ_TEST1_NAME, "Failed to open "
25 "test file: %s\n", SPLAT_KOBJ_TEST_FILE);
26 return -ENOENT;
27 }
28
29 kobj_close_file(f);
30 splat_vprint(file, SPLAT_KOBJ_TEST1_NAME, "Successfully opened and "
31 "closed test file: %s\n", SPLAT_KOBJ_TEST_FILE);
32
33 return 0;
34} /* splat_kobj_test1() */
35
36static int
37splat_kobj_test2(struct file *file, void *arg)
38{
39 struct _buf *f;
40 char *buf;
41 uint64_t size;
42 int rc;
43
44 f = kobj_open_file(SPLAT_KOBJ_TEST_FILE);
45 if (f == (struct _buf *)-1) {
46 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed to open "
47 "test file: %s\n", SPLAT_KOBJ_TEST_FILE);
48 return -ENOENT;
49 }
50
51 rc = kobj_get_filesize(f, &size);
52 if (rc) {
53 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed stat of "
54 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE, rc);
55 goto out;
56 }
57
e4f1d29f 58 buf = kmalloc(size + 1, GFP_KERNEL);
9490c148 59 if (!buf) {
60 rc = -ENOMEM;
61 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed to alloc "
62 "%lld bytes for tmp buffer (%d)\n", size, rc);
63 goto out;
64 }
65
e4f1d29f 66 memset(buf, 0, size + 1);
9490c148 67 rc = kobj_read_file(f, buf, size, 0);
68 if (rc < 0) {
69 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Failed read of "
70 "test file: %s (%d)\n", SPLAT_KOBJ_TEST_FILE, rc);
71 goto out2;
72 }
73
74 /* Validate we read as many bytes as expected based on the stat. This
75 * isn't a perfect test since we didn't create the file however it is
76 * pretty unlikely there are garbage characters in your /etc/fstab */
77 if (size != (uint64_t)strlen(buf)) {
e4f1d29f 78 rc = -EFBIG;
9490c148 79 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Stat'ed size "
80 "(%lld) does not match number of bytes read "
81 "(%lld)\n", size, (uint64_t)strlen(buf));
82 goto out2;
83 }
84
85 rc = 0;
86 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "\n%s\n", buf);
87 splat_vprint(file, SPLAT_KOBJ_TEST2_NAME, "Successfully stat'ed "
88 "and read expected number of bytes (%lld) from test "
89 "file: %s\n", size, SPLAT_KOBJ_TEST_FILE);
90out2:
91 kfree(buf);
92out:
93 kobj_close_file(f);
94
95 return rc;
96} /* splat_kobj_test2() */
97
98splat_subsystem_t *
99splat_kobj_init(void)
100{
101 splat_subsystem_t *sub;
102
103 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
104 if (sub == NULL)
105 return NULL;
106
107 memset(sub, 0, sizeof(*sub));
108 strncpy(sub->desc.name, SPLAT_KOBJ_NAME, SPLAT_NAME_SIZE);
109 strncpy(sub->desc.desc, SPLAT_KOBJ_DESC, SPLAT_DESC_SIZE);
110 INIT_LIST_HEAD(&sub->subsystem_list);
111 INIT_LIST_HEAD(&sub->test_list);
112 spin_lock_init(&sub->test_lock);
113 sub->desc.id = SPLAT_SUBSYSTEM_KOBJ;
114
115 SPLAT_TEST_INIT(sub, SPLAT_KOBJ_TEST1_NAME, SPLAT_KOBJ_TEST1_DESC,
116 SPLAT_KOBJ_TEST1_ID, splat_kobj_test1);
117 SPLAT_TEST_INIT(sub, SPLAT_KOBJ_TEST2_NAME, SPLAT_KOBJ_TEST2_DESC,
118 SPLAT_KOBJ_TEST2_ID, splat_kobj_test2);
119
120 return sub;
121} /* splat_kobj_init() */
122
123void
124splat_kobj_fini(splat_subsystem_t *sub)
125{
126 ASSERT(sub);
127
128 SPLAT_TEST_FINI(sub, SPLAT_KOBJ_TEST2_ID);
129 SPLAT_TEST_FINI(sub, SPLAT_KOBJ_TEST1_ID);
130
131 kfree(sub);
132} /* splat_kobj_fini() */
133
134int
135splat_kobj_id(void)
136{
137 return SPLAT_SUBSYSTEM_KOBJ;
138} /* splat_kobj_id() */