13 #define KMSG_COMPONENT "vmlogrdr"
14 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
16 #include <linux/module.h>
18 #include <linux/slab.h>
19 #include <linux/errno.h>
20 #include <linux/types.h>
24 #include <asm/uaccess.h>
26 #include <asm/debug.h>
31 #include <linux/device.h>
32 #include <linux/string.h>
38 "system service records.");
49 #define NET_BUFFER_SIZE (PAGE_SIZE - sizeof(int) - sizeof(FENCE))
88 static int vmlogrdr_open(
struct inode *,
struct file *);
89 static int vmlogrdr_release(
struct inode *,
struct file *);
91 size_t count, loff_t * ppos);
95 .open = vmlogrdr_open,
96 .release = vmlogrdr_release,
97 .read = vmlogrdr_read,
104 static void vmlogrdr_iucv_message_pending(
struct iucv_path *,
109 .path_complete = vmlogrdr_iucv_path_complete,
110 .path_severed = vmlogrdr_iucv_path_severed,
111 .message_pending = vmlogrdr_iucv_message_pending,
126 { .system_service =
"*LOGREC ",
127 .internal_name =
"logrec",
128 .recording_name =
"EREP",
135 { .system_service =
"*ACCOUNT",
136 .internal_name =
"account",
137 .recording_name =
"ACCOUNT",
144 { .system_service =
"*SYMPTOM",
145 .internal_name =
"symptom",
146 .recording_name =
"SYMPTOM",
155 #define MAXMINOR (sizeof(sys_ser)/sizeof(struct vmlogrdr_priv_t))
157 static char FENCE[] = {
"EOR"};
158 static int vmlogrdr_major = 0;
159 static struct cdev *vmlogrdr_cdev =
NULL;
160 static int recording_class_AB;
179 pr_err(
"vmlogrdr: connection severed with reason %i\n", reason);
196 static void vmlogrdr_iucv_message_pending(
struct iucv_path *
path,
214 static int vmlogrdr_get_recording_class_AB(
void)
216 static const char cp_command[] =
"QUERY COMMAND RECORDING ";
217 char cp_response[80];
221 cpcmd(cp_command, cp_response,
sizeof(cp_response),
NULL);
222 len =
strnlen(cp_response,
sizeof(cp_response));
224 tail=
strnchr(cp_response,len,
'=');
236 for (i=tail-cp_response; i<len; i++)
237 if ( cp_response[i]==
'A' || cp_response[i]==
'B' )
248 char cp_response[160];
249 char *
onoff, *qid_string;
252 onoff = ((action == 1) ?
"ON" :
"OFF");
253 qid_string = ((recording_class_AB == 1) ?
" QID * " :
"");
262 if (purge && (action == 1)) {
263 memset(cp_command, 0x00,
sizeof(cp_command));
264 memset(cp_response, 0x00,
sizeof(cp_response));
265 snprintf(cp_command,
sizeof(cp_command),
266 "RECORDING %s PURGE %s",
269 cpcmd(cp_command, cp_response,
sizeof(cp_response),
NULL);
272 memset(cp_command, 0x00,
sizeof(cp_command));
273 memset(cp_response, 0x00,
sizeof(cp_response));
274 snprintf(cp_command,
sizeof(cp_command),
"RECORDING %s %s %s",
278 cpcmd(cp_command, cp_response,
sizeof(cp_response),
NULL);
285 if (
strstr(cp_response,
"Command complete"))
294 if (purge && (action == 0)) {
295 memset(cp_command, 0x00,
sizeof(cp_command));
296 memset(cp_response, 0x00,
sizeof(cp_response));
297 snprintf(cp_command,
sizeof(cp_command),
298 "RECORDING %s PURGE %s",
301 cpcmd(cp_command, cp_response,
sizeof(cp_response),
NULL);
315 dev_num = iminor(inode);
318 logptr = &sys_ser[dev_num];
341 filp->
f_op = &vmlogrdr_fops;
345 ret = vmlogrdr_recording(logptr,1,logptr->
autopurge);
348 "recording automatically\n");
355 connect_rc = iucv_path_connect(logptr->
path, &vmlogrdr_iucv_handler,
359 pr_err(
"vmlogrdr: iucv connection to %s "
360 "failed with rc %i \n",
378 vmlogrdr_recording(logptr,0,logptr->
autopurge);
388 static int vmlogrdr_release (
struct inode *inode,
struct file *filp)
398 ret = vmlogrdr_recording(logptr,0,logptr->
autopurge);
401 "recording automatically\n");
416 int user_data_count, iucv_data_count;
432 user_data_count =
sizeof(
int);
433 temp = (
int*)priv->
buffer;
434 *temp= iucv_data_count +
sizeof(
FENCE);
445 0, buffer, iucv_data_count,
461 user_data_count += iucv_data_count;
467 buffer = priv->
buffer + user_data_count;
469 user_data_count +=
sizeof(
FENCE);
479 size_t count, loff_t * ppos)
485 rc = vmlogrdr_receive_data(priv);
513 const char *
buf,
size_t count)
542 vmlogrdr_autopurge_store);
547 const char * buf,
size_t count)
551 char cp_response[80];
557 memset(cp_command, 0x00,
sizeof(cp_command));
558 memset(cp_response, 0x00,
sizeof(cp_response));
567 if (recording_class_AB)
568 snprintf(cp_command,
sizeof(cp_command),
569 "RECORDING %s PURGE QID * ",
572 snprintf(cp_command,
sizeof(cp_command),
573 "RECORDING %s PURGE ",
576 cpcmd(cp_command, cp_response,
sizeof(cp_response),
NULL);
585 static ssize_t vmlogrdr_autorecording_store(
struct device *dev,
587 const char *buf,
size_t count)
606 static ssize_t vmlogrdr_autorecording_show(
struct device *dev,
616 vmlogrdr_autorecording_store);
621 const char * buf,
size_t count)
628 ret = vmlogrdr_recording(priv,0,0);
631 ret = vmlogrdr_recording(priv,1,0);
651 static const char cp_command[] =
"QUERY RECORDING ";
658 static DRIVER_ATTR(recording_status, 0444, vmlogrdr_recording_status_show,
660 static struct attribute *vmlogrdr_drv_attrs[] = {
661 &driver_attr_recording_status.attr,
665 .attrs = vmlogrdr_drv_attrs,
668 &vmlogrdr_drv_attr_group,
672 static struct attribute *vmlogrdr_attrs[] = {
673 &dev_attr_autopurge.attr,
674 &dev_attr_purge.attr,
675 &dev_attr_autorecording.attr,
676 &dev_attr_recording.attr,
680 .attrs = vmlogrdr_attrs,
683 &vmlogrdr_attr_group,
687 static int vmlogrdr_pm_prepare(
struct device *dev)
700 pr_err(
"vmlogrdr: device %s is busy. Refuse to suspend.\n",
706 static const struct dev_pm_ops vmlogrdr_pm_ops = {
707 .prepare = vmlogrdr_pm_prepare,
710 static struct class *vmlogrdr_class;
714 .pm = &vmlogrdr_pm_ops,
715 .groups = vmlogrdr_drv_attr_groups,
718 static int vmlogrdr_register_driver(
void)
732 if (IS_ERR(vmlogrdr_class)) {
733 ret = PTR_ERR(vmlogrdr_class);
734 vmlogrdr_class =
NULL;
748 static void vmlogrdr_unregister_driver(
void)
751 vmlogrdr_class =
NULL;
767 dev->
driver = &vmlogrdr_driver;
768 dev->
groups = vmlogrdr_attr_groups;
787 MKDEV(vmlogrdr_major,
789 priv,
"%s", dev_name(dev));
812 static int vmlogrdr_register_cdev(
dev_t dev)
816 if (!vmlogrdr_cdev) {
820 vmlogrdr_cdev->
ops = &vmlogrdr_fops;
833 static void vmlogrdr_cleanup(
void)
842 vmlogrdr_unregister_device(&sys_ser[i]);
843 free_page((
unsigned long)sys_ser[i].buffer);
845 vmlogrdr_unregister_driver();
846 if (vmlogrdr_major) {
853 static int __init vmlogrdr_init(
void)
860 pr_err(
"not running under VM, driver not loaded.\n");
864 recording_class_AB = vmlogrdr_get_recording_class_AB();
869 vmlogrdr_major =
MAJOR(dev);
871 rc=vmlogrdr_register_driver();
877 if (!sys_ser[i].buffer) {
882 rc=vmlogrdr_register_device(&sys_ser[i]);
889 rc = vmlogrdr_register_cdev(dev);
900 static void __exit vmlogrdr_exit(
void)