diff options
author | Melissa Howland <melissah@us.ibm.com> | 2006-09-20 09:59:34 -0400 |
---|---|---|
committer | Martin Schwidefsky <schwidefsky@de.ibm.com> | 2006-09-20 09:59:34 -0400 |
commit | 31b58088292c7f00f0b81088bfb557285b0b6247 (patch) | |
tree | 7ce82a49cbf3ad0c28feb63d15b35a6c97d668a0 /drivers/s390 | |
parent | e620c4940002348417e8d317d65bc7b152646493 (diff) |
[S390] Linux API for writing z/VM APPLDATA Monitor records.
This patch delivers a new Linux API in the form of a misc char
device that is useable from user space and allows write access
to the z/VM APPLDATA Monitor Records collected by the *MONITOR
System Service of z/VM.
Signed-off-by: Melissa Howland <melissah@us.ibm.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Diffstat (limited to 'drivers/s390')
-rw-r--r-- | drivers/s390/Kconfig | 6 | ||||
-rw-r--r-- | drivers/s390/char/Makefile | 1 | ||||
-rw-r--r-- | drivers/s390/char/monwriter.c | 292 |
3 files changed, 299 insertions, 0 deletions
diff --git a/drivers/s390/Kconfig b/drivers/s390/Kconfig index bc4261e8b606..ae89b9b88743 100644 --- a/drivers/s390/Kconfig +++ b/drivers/s390/Kconfig | |||
@@ -213,6 +213,12 @@ config MONREADER | |||
213 | help | 213 | help |
214 | Character device driver for reading z/VM monitor service records | 214 | Character device driver for reading z/VM monitor service records |
215 | 215 | ||
216 | config MONWRITER | ||
217 | tristate "API for writing z/VM monitor service records" | ||
218 | default "m" | ||
219 | help | ||
220 | Character device driver for writing z/VM monitor service records | ||
221 | |||
216 | endmenu | 222 | endmenu |
217 | 223 | ||
218 | menu "Cryptographic devices" | 224 | menu "Cryptographic devices" |
diff --git a/drivers/s390/char/Makefile b/drivers/s390/char/Makefile index 0c0162ff6c0c..c3e97b4fc186 100644 --- a/drivers/s390/char/Makefile +++ b/drivers/s390/char/Makefile | |||
@@ -28,3 +28,4 @@ obj-$(CONFIG_S390_TAPE) += tape.o tape_class.o | |||
28 | obj-$(CONFIG_S390_TAPE_34XX) += tape_34xx.o | 28 | obj-$(CONFIG_S390_TAPE_34XX) += tape_34xx.o |
29 | obj-$(CONFIG_S390_TAPE_3590) += tape_3590.o | 29 | obj-$(CONFIG_S390_TAPE_3590) += tape_3590.o |
30 | obj-$(CONFIG_MONREADER) += monreader.o | 30 | obj-$(CONFIG_MONREADER) += monreader.o |
31 | obj-$(CONFIG_MONWRITER) += monwriter.o | ||
diff --git a/drivers/s390/char/monwriter.c b/drivers/s390/char/monwriter.c new file mode 100644 index 000000000000..1e3939aeb8ab --- /dev/null +++ b/drivers/s390/char/monwriter.c | |||
@@ -0,0 +1,292 @@ | |||
1 | /* | ||
2 | * drivers/s390/char/monwriter.c | ||
3 | * | ||
4 | * Character device driver for writing z/VM *MONITOR service records. | ||
5 | * | ||
6 | * Copyright (C) IBM Corp. 2006 | ||
7 | * | ||
8 | * Author(s): Melissa Howland <Melissa.Howland@us.ibm.com> | ||
9 | */ | ||
10 | |||
11 | #include <linux/module.h> | ||
12 | #include <linux/moduleparam.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/errno.h> | ||
15 | #include <linux/types.h> | ||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/miscdevice.h> | ||
18 | #include <linux/ctype.h> | ||
19 | #include <linux/poll.h> | ||
20 | #include <asm/uaccess.h> | ||
21 | #include <asm/ebcdic.h> | ||
22 | #include <asm/io.h> | ||
23 | #include <asm/appldata.h> | ||
24 | #include <asm/monwriter.h> | ||
25 | |||
26 | #define MONWRITE_MAX_DATALEN 4024 | ||
27 | |||
28 | static int mon_max_bufs = 255; | ||
29 | |||
30 | struct mon_buf { | ||
31 | struct list_head list; | ||
32 | struct monwrite_hdr hdr; | ||
33 | int diag_done; | ||
34 | char *data; | ||
35 | }; | ||
36 | |||
37 | struct mon_private { | ||
38 | struct list_head list; | ||
39 | struct monwrite_hdr hdr; | ||
40 | size_t hdr_to_read; | ||
41 | size_t data_to_read; | ||
42 | struct mon_buf *current_buf; | ||
43 | int mon_buf_count; | ||
44 | }; | ||
45 | |||
46 | /* | ||
47 | * helper functions | ||
48 | */ | ||
49 | |||
50 | static int monwrite_diag(struct monwrite_hdr *myhdr, char *buffer, int fcn) | ||
51 | { | ||
52 | struct appldata_product_id id; | ||
53 | int rc; | ||
54 | |||
55 | strcpy(id.prod_nr, "LNXAPPL"); | ||
56 | id.prod_fn = myhdr->applid; | ||
57 | id.record_nr = myhdr->record_num; | ||
58 | id.version_nr = myhdr->version; | ||
59 | id.release_nr = myhdr->release; | ||
60 | id.mod_lvl = myhdr->mod_level; | ||
61 | rc = appldata_asm(&id, fcn, (void *) buffer, myhdr->datalen); | ||
62 | if (rc <= 0) | ||
63 | return rc; | ||
64 | if (rc == 5) | ||
65 | return -EPERM; | ||
66 | printk("DIAG X'DC' error with return code: %i\n", rc); | ||
67 | return -EINVAL; | ||
68 | } | ||
69 | |||
70 | static inline struct mon_buf *monwrite_find_hdr(struct mon_private *monpriv, | ||
71 | struct monwrite_hdr *monhdr) | ||
72 | { | ||
73 | struct mon_buf *entry, *next; | ||
74 | |||
75 | list_for_each_entry_safe(entry, next, &monpriv->list, list) | ||
76 | if (entry->hdr.applid == monhdr->applid && | ||
77 | entry->hdr.record_num == monhdr->record_num && | ||
78 | entry->hdr.version == monhdr->version && | ||
79 | entry->hdr.release == monhdr->release && | ||
80 | entry->hdr.mod_level == monhdr->mod_level) | ||
81 | return entry; | ||
82 | return NULL; | ||
83 | } | ||
84 | |||
85 | static int monwrite_new_hdr(struct mon_private *monpriv) | ||
86 | { | ||
87 | struct monwrite_hdr *monhdr = &monpriv->hdr; | ||
88 | struct mon_buf *monbuf; | ||
89 | int rc; | ||
90 | |||
91 | if (monhdr->datalen > MONWRITE_MAX_DATALEN || | ||
92 | monhdr->mon_function > MONWRITE_START_CONFIG || | ||
93 | monhdr->hdrlen != sizeof(struct monwrite_hdr)) | ||
94 | return -EINVAL; | ||
95 | monbuf = monwrite_find_hdr(monpriv, monhdr); | ||
96 | if (monbuf) { | ||
97 | if (monhdr->mon_function == MONWRITE_STOP_INTERVAL) { | ||
98 | monhdr->datalen = monbuf->hdr.datalen; | ||
99 | rc = monwrite_diag(monhdr, monbuf->data, | ||
100 | APPLDATA_STOP_REC); | ||
101 | list_del(&monbuf->list); | ||
102 | monpriv->mon_buf_count--; | ||
103 | kfree(monbuf->data); | ||
104 | kfree(monbuf); | ||
105 | monbuf = NULL; | ||
106 | } | ||
107 | } else { | ||
108 | if (monpriv->mon_buf_count >= mon_max_bufs) | ||
109 | return -ENOSPC; | ||
110 | monbuf = kzalloc(sizeof(struct mon_buf), GFP_KERNEL); | ||
111 | if (!monbuf) | ||
112 | return -ENOMEM; | ||
113 | monbuf->data = kzalloc(monbuf->hdr.datalen, | ||
114 | GFP_KERNEL | GFP_DMA); | ||
115 | if (!monbuf->data) { | ||
116 | kfree(monbuf); | ||
117 | return -ENOMEM; | ||
118 | } | ||
119 | monbuf->hdr = *monhdr; | ||
120 | list_add_tail(&monbuf->list, &monpriv->list); | ||
121 | monpriv->mon_buf_count++; | ||
122 | } | ||
123 | monpriv->current_buf = monbuf; | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static int monwrite_new_data(struct mon_private *monpriv) | ||
128 | { | ||
129 | struct monwrite_hdr *monhdr = &monpriv->hdr; | ||
130 | struct mon_buf *monbuf = monpriv->current_buf; | ||
131 | int rc = 0; | ||
132 | |||
133 | switch (monhdr->mon_function) { | ||
134 | case MONWRITE_START_INTERVAL: | ||
135 | if (!monbuf->diag_done) { | ||
136 | rc = monwrite_diag(monhdr, monbuf->data, | ||
137 | APPLDATA_START_INTERVAL_REC); | ||
138 | monbuf->diag_done = 1; | ||
139 | } | ||
140 | break; | ||
141 | case MONWRITE_START_CONFIG: | ||
142 | if (!monbuf->diag_done) { | ||
143 | rc = monwrite_diag(monhdr, monbuf->data, | ||
144 | APPLDATA_START_CONFIG_REC); | ||
145 | monbuf->diag_done = 1; | ||
146 | } | ||
147 | break; | ||
148 | case MONWRITE_GEN_EVENT: | ||
149 | rc = monwrite_diag(monhdr, monbuf->data, | ||
150 | APPLDATA_GEN_EVENT_REC); | ||
151 | list_del(&monpriv->current_buf->list); | ||
152 | kfree(monpriv->current_buf->data); | ||
153 | kfree(monpriv->current_buf); | ||
154 | monpriv->current_buf = NULL; | ||
155 | break; | ||
156 | default: | ||
157 | /* monhdr->mon_function is checked in monwrite_new_hdr */ | ||
158 | BUG(); | ||
159 | } | ||
160 | return rc; | ||
161 | } | ||
162 | |||
163 | /* | ||
164 | * file operations | ||
165 | */ | ||
166 | |||
167 | static int monwrite_open(struct inode *inode, struct file *filp) | ||
168 | { | ||
169 | struct mon_private *monpriv; | ||
170 | |||
171 | monpriv = kzalloc(sizeof(struct mon_private), GFP_KERNEL); | ||
172 | if (!monpriv) | ||
173 | return -ENOMEM; | ||
174 | INIT_LIST_HEAD(&monpriv->list); | ||
175 | monpriv->hdr_to_read = sizeof(monpriv->hdr); | ||
176 | filp->private_data = monpriv; | ||
177 | return nonseekable_open(inode, filp); | ||
178 | } | ||
179 | |||
180 | static int monwrite_close(struct inode *inode, struct file *filp) | ||
181 | { | ||
182 | struct mon_private *monpriv = filp->private_data; | ||
183 | struct mon_buf *entry, *next; | ||
184 | |||
185 | list_for_each_entry_safe(entry, next, &monpriv->list, list) { | ||
186 | if (entry->hdr.mon_function != MONWRITE_GEN_EVENT) | ||
187 | monwrite_diag(&entry->hdr, entry->data, | ||
188 | APPLDATA_STOP_REC); | ||
189 | monpriv->mon_buf_count--; | ||
190 | list_del(&entry->list); | ||
191 | kfree(entry->data); | ||
192 | kfree(entry); | ||
193 | } | ||
194 | kfree(monpriv); | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static ssize_t monwrite_write(struct file *filp, const char __user *data, | ||
199 | size_t count, loff_t *ppos) | ||
200 | { | ||
201 | struct mon_private *monpriv = filp->private_data; | ||
202 | size_t len, written; | ||
203 | void *to; | ||
204 | int rc; | ||
205 | |||
206 | for (written = 0; written < count; ) { | ||
207 | if (monpriv->hdr_to_read) { | ||
208 | len = min(count - written, monpriv->hdr_to_read); | ||
209 | to = (char *) &monpriv->hdr + | ||
210 | sizeof(monpriv->hdr) - monpriv->hdr_to_read; | ||
211 | if (copy_from_user(to, data + written, len)) { | ||
212 | rc = -EFAULT; | ||
213 | goto out_error; | ||
214 | } | ||
215 | monpriv->hdr_to_read -= len; | ||
216 | written += len; | ||
217 | if (monpriv->hdr_to_read > 0) | ||
218 | continue; | ||
219 | rc = monwrite_new_hdr(monpriv); | ||
220 | if (rc) | ||
221 | goto out_error; | ||
222 | monpriv->data_to_read = monpriv->current_buf ? | ||
223 | monpriv->current_buf->hdr.datalen : 0; | ||
224 | } | ||
225 | |||
226 | if (monpriv->data_to_read) { | ||
227 | len = min(count - written, monpriv->data_to_read); | ||
228 | to = monpriv->current_buf->data + | ||
229 | monpriv->hdr.datalen - monpriv->data_to_read; | ||
230 | if (copy_from_user(to, data + written, len)) { | ||
231 | rc = -EFAULT; | ||
232 | goto out_error; | ||
233 | } | ||
234 | monpriv->data_to_read -= len; | ||
235 | written += len; | ||
236 | if (monpriv->data_to_read > 0) | ||
237 | continue; | ||
238 | rc = monwrite_new_data(monpriv); | ||
239 | if (rc) | ||
240 | goto out_error; | ||
241 | } | ||
242 | monpriv->hdr_to_read = sizeof(monpriv->hdr); | ||
243 | } | ||
244 | return written; | ||
245 | |||
246 | out_error: | ||
247 | monpriv->data_to_read = 0; | ||
248 | monpriv->hdr_to_read = sizeof(struct monwrite_hdr); | ||
249 | return rc; | ||
250 | } | ||
251 | |||
252 | static struct file_operations monwrite_fops = { | ||
253 | .owner = THIS_MODULE, | ||
254 | .open = &monwrite_open, | ||
255 | .release = &monwrite_close, | ||
256 | .write = &monwrite_write, | ||
257 | }; | ||
258 | |||
259 | static struct miscdevice mon_dev = { | ||
260 | .name = "monwriter", | ||
261 | .fops = &monwrite_fops, | ||
262 | .minor = MISC_DYNAMIC_MINOR, | ||
263 | }; | ||
264 | |||
265 | /* | ||
266 | * module init/exit | ||
267 | */ | ||
268 | |||
269 | static int __init mon_init(void) | ||
270 | { | ||
271 | if (MACHINE_IS_VM) | ||
272 | return misc_register(&mon_dev); | ||
273 | else | ||
274 | return -ENODEV; | ||
275 | } | ||
276 | |||
277 | static void __exit mon_exit(void) | ||
278 | { | ||
279 | WARN_ON(misc_deregister(&mon_dev) != 0); | ||
280 | } | ||
281 | |||
282 | module_init(mon_init); | ||
283 | module_exit(mon_exit); | ||
284 | |||
285 | module_param_named(max_bufs, mon_max_bufs, int, 0644); | ||
286 | MODULE_PARM_DESC(max_bufs, "Maximum number of sample monitor data buffers" | ||
287 | "that can be active at one time"); | ||
288 | |||
289 | MODULE_AUTHOR("Melissa Howland <Melissa.Howland@us.ibm.com>"); | ||
290 | MODULE_DESCRIPTION("Character device driver for writing z/VM " | ||
291 | "APPLDATA monitor records."); | ||
292 | MODULE_LICENSE("GPL"); | ||