2017-11-15 01:38:03 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* character device driver for reading z/VM system service records
|
|
|
|
*
|
|
|
|
*
|
2009-06-16 16:30:38 +08:00
|
|
|
* Copyright IBM Corp. 2004, 2009
|
2005-04-17 06:20:36 +08:00
|
|
|
* character device driver for reading z/VM system service records,
|
|
|
|
* Version 1.0
|
|
|
|
* Author(s): Xenia Tkatschow <xenia@us.ibm.com>
|
|
|
|
* Stefan Weinhuber <wein@de.ibm.com>
|
|
|
|
*
|
|
|
|
*/
|
2008-12-25 20:39:52 +08:00
|
|
|
|
|
|
|
#define KMSG_COMPONENT "vmlogrdr"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/spinlock.h>
|
2011-07-27 07:09:06 +08:00
|
|
|
#include <linux/atomic.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/cpcmd.h>
|
|
|
|
#include <asm/debug.h>
|
|
|
|
#include <asm/ebcdic.h>
|
2007-02-09 05:40:41 +08:00
|
|
|
#include <net/iucv/iucv.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/kmod.h>
|
|
|
|
#include <linux/cdev.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
|
|
|
|
MODULE_AUTHOR
|
|
|
|
("(C) 2004 IBM Corporation by Xenia Tkatschow (xenia@us.ibm.com)\n"
|
|
|
|
" Stefan Weinhuber (wein@de.ibm.com)");
|
|
|
|
MODULE_DESCRIPTION ("Character device driver for reading z/VM "
|
|
|
|
"system service records.");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The size of the buffer for iucv data transfer is one page,
|
|
|
|
* but in addition to the data we read from iucv we also
|
|
|
|
* place an integer and some characters into that buffer,
|
|
|
|
* so the maximum size for record data is a little less then
|
|
|
|
* one page.
|
|
|
|
*/
|
|
|
|
#define NET_BUFFER_SIZE (PAGE_SIZE - sizeof(int) - sizeof(FENCE))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The elements that are concurrently accessed by bottom halves are
|
|
|
|
* connection_established, iucv_path_severed, local_interrupt_buffer
|
|
|
|
* and receive_ready. The first three can be protected by
|
|
|
|
* priv_lock. receive_ready is atomic, so it can be incremented and
|
|
|
|
* decremented without holding a lock.
|
|
|
|
* The variable dev_in_use needs to be protected by the lock, since
|
|
|
|
* it's a flag used by open to make sure that the device is opened only
|
|
|
|
* by one user at the same time.
|
|
|
|
*/
|
|
|
|
struct vmlogrdr_priv_t {
|
|
|
|
char system_service[8];
|
|
|
|
char internal_name[8];
|
|
|
|
char recording_name[8];
|
2007-02-09 05:40:41 +08:00
|
|
|
struct iucv_path *path;
|
2005-04-17 06:20:36 +08:00
|
|
|
int connection_established;
|
|
|
|
int iucv_path_severed;
|
2007-02-09 05:40:41 +08:00
|
|
|
struct iucv_message local_interrupt_buffer;
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_t receive_ready;
|
|
|
|
int minor_num;
|
|
|
|
char * buffer;
|
|
|
|
char * current_position;
|
|
|
|
int remaining;
|
|
|
|
ulong residual_length;
|
|
|
|
int buffer_free;
|
|
|
|
int dev_in_use; /* 1: already opened, 0: not opened*/
|
|
|
|
spinlock_t priv_lock;
|
|
|
|
struct device *device;
|
2007-10-22 18:52:42 +08:00
|
|
|
struct device *class_device;
|
2005-04-17 06:20:36 +08:00
|
|
|
int autorecording;
|
|
|
|
int autopurge;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File operation structure for vmlogrdr devices
|
|
|
|
*/
|
|
|
|
static int vmlogrdr_open(struct inode *, struct file *);
|
|
|
|
static int vmlogrdr_release(struct inode *, struct file *);
|
2006-07-12 22:41:55 +08:00
|
|
|
static ssize_t vmlogrdr_read (struct file *filp, char __user *data,
|
|
|
|
size_t count, loff_t * ppos);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
static const struct file_operations vmlogrdr_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = vmlogrdr_open,
|
|
|
|
.release = vmlogrdr_release,
|
|
|
|
.read = vmlogrdr_read,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = no_llseek,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-09-18 22:06:52 +08:00
|
|
|
static void vmlogrdr_iucv_path_complete(struct iucv_path *, u8 *ipuser);
|
|
|
|
static void vmlogrdr_iucv_path_severed(struct iucv_path *, u8 *ipuser);
|
2007-02-09 05:40:41 +08:00
|
|
|
static void vmlogrdr_iucv_message_pending(struct iucv_path *,
|
|
|
|
struct iucv_message *);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static struct iucv_handler vmlogrdr_iucv_handler = {
|
|
|
|
.path_complete = vmlogrdr_iucv_path_complete,
|
|
|
|
.path_severed = vmlogrdr_iucv_path_severed,
|
|
|
|
.message_pending = vmlogrdr_iucv_message_pending,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-06 04:16:47 +08:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(conn_wait_queue);
|
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(read_wait_queue);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* pointer to system service private structure
|
|
|
|
* minor number 0 --> logrec
|
|
|
|
* minor number 1 --> account
|
|
|
|
* minor number 2 --> symptom
|
|
|
|
*/
|
|
|
|
|
|
|
|
static struct vmlogrdr_priv_t sys_ser[] = {
|
|
|
|
{ .system_service = "*LOGREC ",
|
|
|
|
.internal_name = "logrec",
|
|
|
|
.recording_name = "EREP",
|
|
|
|
.minor_num = 0,
|
|
|
|
.buffer_free = 1,
|
2007-04-27 22:02:01 +08:00
|
|
|
.priv_lock = __SPIN_LOCK_UNLOCKED(sys_ser[0].priv_lock),
|
2005-04-17 06:20:36 +08:00
|
|
|
.autorecording = 1,
|
|
|
|
.autopurge = 1,
|
|
|
|
},
|
|
|
|
{ .system_service = "*ACCOUNT",
|
|
|
|
.internal_name = "account",
|
|
|
|
.recording_name = "ACCOUNT",
|
|
|
|
.minor_num = 1,
|
|
|
|
.buffer_free = 1,
|
2007-04-27 22:02:01 +08:00
|
|
|
.priv_lock = __SPIN_LOCK_UNLOCKED(sys_ser[1].priv_lock),
|
2005-04-17 06:20:36 +08:00
|
|
|
.autorecording = 1,
|
|
|
|
.autopurge = 1,
|
|
|
|
},
|
|
|
|
{ .system_service = "*SYMPTOM",
|
|
|
|
.internal_name = "symptom",
|
|
|
|
.recording_name = "SYMPTOM",
|
|
|
|
.minor_num = 2,
|
|
|
|
.buffer_free = 1,
|
2007-04-27 22:02:01 +08:00
|
|
|
.priv_lock = __SPIN_LOCK_UNLOCKED(sys_ser[2].priv_lock),
|
2005-04-17 06:20:36 +08:00
|
|
|
.autorecording = 1,
|
|
|
|
.autopurge = 1,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAXMINOR (sizeof(sys_ser)/sizeof(struct vmlogrdr_priv_t))
|
|
|
|
|
|
|
|
static char FENCE[] = {"EOR"};
|
|
|
|
static int vmlogrdr_major = 0;
|
|
|
|
static struct cdev *vmlogrdr_cdev = NULL;
|
|
|
|
static int recording_class_AB;
|
|
|
|
|
|
|
|
|
2015-09-18 22:06:52 +08:00
|
|
|
static void vmlogrdr_iucv_path_complete(struct iucv_path *path, u8 *ipuser)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 05:40:41 +08:00
|
|
|
struct vmlogrdr_priv_t * logptr = path->private;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&logptr->priv_lock);
|
|
|
|
logptr->connection_established = 1;
|
|
|
|
spin_unlock(&logptr->priv_lock);
|
|
|
|
wake_up(&conn_wait_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-18 22:06:52 +08:00
|
|
|
static void vmlogrdr_iucv_path_severed(struct iucv_path *path, u8 *ipuser)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 05:40:41 +08:00
|
|
|
struct vmlogrdr_priv_t * logptr = path->private;
|
|
|
|
u8 reason = (u8) ipuser[8];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-12-25 20:39:52 +08:00
|
|
|
pr_err("vmlogrdr: connection severed with reason %i\n", reason);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
iucv_path_sever(path, NULL);
|
|
|
|
kfree(path);
|
|
|
|
logptr->path = NULL;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock(&logptr->priv_lock);
|
|
|
|
logptr->connection_established = 0;
|
|
|
|
logptr->iucv_path_severed = 1;
|
|
|
|
spin_unlock(&logptr->priv_lock);
|
|
|
|
|
|
|
|
wake_up(&conn_wait_queue);
|
|
|
|
/* just in case we're sleeping waiting for a record */
|
|
|
|
wake_up_interruptible(&read_wait_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static void vmlogrdr_iucv_message_pending(struct iucv_path *path,
|
|
|
|
struct iucv_message *msg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2007-02-09 05:40:41 +08:00
|
|
|
struct vmlogrdr_priv_t * logptr = path->private;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is the bottom half so it should be quick.
|
|
|
|
* Copy the external interrupt data into our local eib and increment
|
|
|
|
* the usage count
|
|
|
|
*/
|
|
|
|
spin_lock(&logptr->priv_lock);
|
2007-02-09 05:40:41 +08:00
|
|
|
memcpy(&logptr->local_interrupt_buffer, msg, sizeof(*msg));
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_inc(&logptr->receive_ready);
|
|
|
|
spin_unlock(&logptr->priv_lock);
|
|
|
|
wake_up_interruptible(&read_wait_queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_get_recording_class_AB(void)
|
|
|
|
{
|
2010-10-25 22:10:20 +08:00
|
|
|
static const char cp_command[] = "QUERY COMMAND RECORDING ";
|
2005-04-17 06:20:36 +08:00
|
|
|
char cp_response[80];
|
|
|
|
char *tail;
|
|
|
|
int len,i;
|
|
|
|
|
2005-06-26 05:55:32 +08:00
|
|
|
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
len = strnlen(cp_response,sizeof(cp_response));
|
|
|
|
// now the parsing
|
|
|
|
tail=strnchr(cp_response,len,'=');
|
|
|
|
if (!tail)
|
|
|
|
return 0;
|
|
|
|
tail++;
|
|
|
|
if (!strncmp("ANY",tail,3))
|
|
|
|
return 1;
|
|
|
|
if (!strncmp("NONE",tail,4))
|
|
|
|
return 0;
|
|
|
|
/*
|
|
|
|
* expect comma separated list of classes here, if one of them
|
|
|
|
* is A or B return 1 otherwise 0
|
|
|
|
*/
|
|
|
|
for (i=tail-cp_response; i<len; i++)
|
|
|
|
if ( cp_response[i]=='A' || cp_response[i]=='B' )
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_recording(struct vmlogrdr_priv_t * logptr,
|
|
|
|
int action, int purge)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
char cp_command[80];
|
|
|
|
char cp_response[160];
|
|
|
|
char *onoff, *qid_string;
|
2010-11-10 17:05:54 +08:00
|
|
|
int rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-11-10 17:05:54 +08:00
|
|
|
onoff = ((action == 1) ? "ON" : "OFF");
|
2005-04-17 06:20:36 +08:00
|
|
|
qid_string = ((recording_class_AB == 1) ? " QID * " : "");
|
|
|
|
|
2010-11-10 17:05:54 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* The recording commands needs to be called with option QID
|
|
|
|
* for guests that have previlege classes A or B.
|
|
|
|
* Purging has to be done as separate step, because recording
|
|
|
|
* can't be switched on as long as records are on the queue.
|
|
|
|
* Doing both at the same time doesn't work.
|
|
|
|
*/
|
2010-11-10 17:05:54 +08:00
|
|
|
if (purge && (action == 1)) {
|
|
|
|
memset(cp_command, 0x00, sizeof(cp_command));
|
|
|
|
memset(cp_response, 0x00, sizeof(cp_response));
|
2005-04-17 06:20:36 +08:00
|
|
|
snprintf(cp_command, sizeof(cp_command),
|
|
|
|
"RECORDING %s PURGE %s",
|
|
|
|
logptr->recording_name,
|
|
|
|
qid_string);
|
2005-06-26 05:55:32 +08:00
|
|
|
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
memset(cp_command, 0x00, sizeof(cp_command));
|
|
|
|
memset(cp_response, 0x00, sizeof(cp_response));
|
|
|
|
snprintf(cp_command, sizeof(cp_command), "RECORDING %s %s %s",
|
|
|
|
logptr->recording_name,
|
|
|
|
onoff,
|
|
|
|
qid_string);
|
2005-06-26 05:55:32 +08:00
|
|
|
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* The recording command will usually answer with 'Command complete'
|
|
|
|
* on success, but when the specific service was never connected
|
|
|
|
* before then there might be an additional informational message
|
|
|
|
* 'HCPCRC8072I Recording entry not found' before the
|
2010-11-10 17:05:54 +08:00
|
|
|
* 'Command complete'. So I use strstr rather then the strncmp.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
if (strstr(cp_response,"Command complete"))
|
2010-11-10 17:05:54 +08:00
|
|
|
rc = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-11-10 17:05:54 +08:00
|
|
|
rc = -EIO;
|
|
|
|
/*
|
|
|
|
* If we turn recording off, we have to purge any remaining records
|
|
|
|
* afterwards, as a large number of queued records may impact z/VM
|
|
|
|
* performance.
|
|
|
|
*/
|
|
|
|
if (purge && (action == 0)) {
|
|
|
|
memset(cp_command, 0x00, sizeof(cp_command));
|
|
|
|
memset(cp_response, 0x00, sizeof(cp_response));
|
|
|
|
snprintf(cp_command, sizeof(cp_command),
|
|
|
|
"RECORDING %s PURGE %s",
|
|
|
|
logptr->recording_name,
|
|
|
|
qid_string);
|
|
|
|
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-11-10 17:05:54 +08:00
|
|
|
return rc;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_open (struct inode *inode, struct file *filp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int dev_num = 0;
|
|
|
|
struct vmlogrdr_priv_t * logptr = NULL;
|
|
|
|
int connect_rc = 0;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_num = iminor(inode);
|
2013-10-14 20:26:08 +08:00
|
|
|
if (dev_num >= MAXMINOR)
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
logptr = &sys_ser[dev_num];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* only allow for blocking reads to be open
|
|
|
|
*/
|
|
|
|
if (filp->f_flags & O_NONBLOCK)
|
2012-09-06 23:35:00 +08:00
|
|
|
return -EOPNOTSUPP;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Besure this device hasn't already been opened */
|
|
|
|
spin_lock_bh(&logptr->priv_lock);
|
|
|
|
if (logptr->dev_in_use) {
|
|
|
|
spin_unlock_bh(&logptr->priv_lock);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
2007-02-09 05:40:41 +08:00
|
|
|
logptr->dev_in_use = 1;
|
|
|
|
logptr->connection_established = 0;
|
|
|
|
logptr->iucv_path_severed = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
atomic_set(&logptr->receive_ready, 0);
|
|
|
|
logptr->buffer_free = 1;
|
2007-02-09 05:40:41 +08:00
|
|
|
spin_unlock_bh(&logptr->priv_lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* set the file options */
|
|
|
|
filp->private_data = logptr;
|
|
|
|
|
|
|
|
/* start recording for this service*/
|
2007-02-09 05:40:41 +08:00
|
|
|
if (logptr->autorecording) {
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = vmlogrdr_recording(logptr,1,logptr->autopurge);
|
2007-02-09 05:40:41 +08:00
|
|
|
if (ret)
|
2016-03-04 12:49:57 +08:00
|
|
|
pr_warn("vmlogrdr: failed to start recording automatically\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create connection to the system service */
|
2007-02-09 05:40:41 +08:00
|
|
|
logptr->path = iucv_path_alloc(10, 0, GFP_KERNEL);
|
|
|
|
if (!logptr->path)
|
|
|
|
goto out_dev;
|
|
|
|
connect_rc = iucv_path_connect(logptr->path, &vmlogrdr_iucv_handler,
|
|
|
|
logptr->system_service, NULL, NULL,
|
|
|
|
logptr);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (connect_rc) {
|
2008-12-25 20:39:52 +08:00
|
|
|
pr_err("vmlogrdr: iucv connection to %s "
|
|
|
|
"failed with rc %i \n",
|
|
|
|
logptr->system_service, connect_rc);
|
2007-02-09 05:40:41 +08:00
|
|
|
goto out_path;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We've issued the connect and now we must wait for a
|
|
|
|
* ConnectionComplete or ConnectinSevered Interrupt
|
|
|
|
* before we can continue to process.
|
|
|
|
*/
|
|
|
|
wait_event(conn_wait_queue, (logptr->connection_established)
|
|
|
|
|| (logptr->iucv_path_severed));
|
2007-02-09 05:40:41 +08:00
|
|
|
if (logptr->iucv_path_severed)
|
|
|
|
goto out_record;
|
2009-12-07 19:52:23 +08:00
|
|
|
nonseekable_open(inode, filp);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
out_record:
|
2005-04-17 06:20:36 +08:00
|
|
|
if (logptr->autorecording)
|
|
|
|
vmlogrdr_recording(logptr,0,logptr->autopurge);
|
2007-02-09 05:40:41 +08:00
|
|
|
out_path:
|
|
|
|
kfree(logptr->path); /* kfree(NULL) is ok. */
|
|
|
|
logptr->path = NULL;
|
|
|
|
out_dev:
|
2005-04-17 06:20:36 +08:00
|
|
|
logptr->dev_in_use = 0;
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_release (struct inode *inode, struct file *filp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
struct vmlogrdr_priv_t * logptr = filp->private_data;
|
|
|
|
|
2007-04-27 22:01:52 +08:00
|
|
|
iucv_path_sever(logptr->path, NULL);
|
|
|
|
kfree(logptr->path);
|
|
|
|
logptr->path = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (logptr->autorecording) {
|
|
|
|
ret = vmlogrdr_recording(logptr,0,logptr->autopurge);
|
|
|
|
if (ret)
|
2016-03-04 12:49:57 +08:00
|
|
|
pr_warn("vmlogrdr: failed to stop recording automatically\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
logptr->dev_in_use = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_receive_data(struct vmlogrdr_priv_t *priv)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc, *temp;
|
|
|
|
/* we need to keep track of two data sizes here:
|
|
|
|
* The number of bytes we need to receive from iucv and
|
|
|
|
* the total number of bytes we actually write into the buffer.
|
|
|
|
*/
|
|
|
|
int user_data_count, iucv_data_count;
|
|
|
|
char * buffer;
|
|
|
|
|
|
|
|
if (atomic_read(&priv->receive_ready)) {
|
|
|
|
spin_lock_bh(&priv->priv_lock);
|
|
|
|
if (priv->residual_length){
|
|
|
|
/* receive second half of a record */
|
|
|
|
iucv_data_count = priv->residual_length;
|
|
|
|
user_data_count = 0;
|
|
|
|
buffer = priv->buffer;
|
|
|
|
} else {
|
|
|
|
/* receive a new record:
|
|
|
|
* We need to return the total length of the record
|
|
|
|
* + size of FENCE in the first 4 bytes of the buffer.
|
|
|
|
*/
|
2007-02-09 05:40:41 +08:00
|
|
|
iucv_data_count = priv->local_interrupt_buffer.length;
|
2005-04-17 06:20:36 +08:00
|
|
|
user_data_count = sizeof(int);
|
|
|
|
temp = (int*)priv->buffer;
|
|
|
|
*temp= iucv_data_count + sizeof(FENCE);
|
|
|
|
buffer = priv->buffer + sizeof(int);
|
|
|
|
}
|
|
|
|
/*
|
2008-10-17 01:02:37 +08:00
|
|
|
* If the record is bigger than our buffer, we receive only
|
2005-04-17 06:20:36 +08:00
|
|
|
* a part of it. We can get the rest later.
|
|
|
|
*/
|
|
|
|
if (iucv_data_count > NET_BUFFER_SIZE)
|
|
|
|
iucv_data_count = NET_BUFFER_SIZE;
|
2007-02-09 05:40:41 +08:00
|
|
|
rc = iucv_message_receive(priv->path,
|
|
|
|
&priv->local_interrupt_buffer,
|
|
|
|
0, buffer, iucv_data_count,
|
|
|
|
&priv->residual_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_bh(&priv->priv_lock);
|
2008-10-17 01:02:37 +08:00
|
|
|
/* An rc of 5 indicates that the record was bigger than
|
2005-04-17 06:20:36 +08:00
|
|
|
* the buffer, which is OK for us. A 9 indicates that the
|
|
|
|
* record was purged befor we could receive it.
|
|
|
|
*/
|
|
|
|
if (rc == 5)
|
|
|
|
rc = 0;
|
|
|
|
if (rc == 9)
|
|
|
|
atomic_set(&priv->receive_ready, 0);
|
|
|
|
} else {
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
if (!rc) {
|
|
|
|
priv->buffer_free = 0;
|
|
|
|
user_data_count += iucv_data_count;
|
|
|
|
priv->current_position = priv->buffer;
|
|
|
|
if (priv->residual_length == 0){
|
|
|
|
/* the whole record has been captured,
|
|
|
|
* now add the fence */
|
|
|
|
atomic_dec(&priv->receive_ready);
|
|
|
|
buffer = priv->buffer + user_data_count;
|
|
|
|
memcpy(buffer, FENCE, sizeof(FENCE));
|
|
|
|
user_data_count += sizeof(FENCE);
|
|
|
|
}
|
|
|
|
priv->remaining = user_data_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_read(struct file *filp, char __user *data,
|
|
|
|
size_t count, loff_t * ppos)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct vmlogrdr_priv_t * priv = filp->private_data;
|
|
|
|
|
|
|
|
while (priv->buffer_free) {
|
|
|
|
rc = vmlogrdr_receive_data(priv);
|
|
|
|
if (rc) {
|
|
|
|
rc = wait_event_interruptible(read_wait_queue,
|
|
|
|
atomic_read(&priv->receive_ready));
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* copy only up to end of record */
|
|
|
|
if (count > priv->remaining)
|
|
|
|
count = priv->remaining;
|
|
|
|
|
|
|
|
if (copy_to_user(data, priv->current_position, count))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
*ppos += count;
|
|
|
|
priv->current_position += count;
|
|
|
|
priv->remaining -= count;
|
|
|
|
|
|
|
|
/* if all data has been transferred, set buffer free */
|
|
|
|
if (priv->remaining == 0)
|
|
|
|
priv->buffer_free = 1;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_autopurge_store(struct device * dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char * buf, size_t count)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret = count;
|
|
|
|
|
|
|
|
switch (buf[0]) {
|
|
|
|
case '0':
|
|
|
|
priv->autopurge=0;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
priv->autopurge=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_autopurge_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return sprintf(buf, "%u\n", priv->autopurge);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DEVICE_ATTR(autopurge, 0644, vmlogrdr_autopurge_show,
|
|
|
|
vmlogrdr_autopurge_store);
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_purge_store(struct device * dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char * buf, size_t count)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
char cp_command[80];
|
|
|
|
char cp_response[80];
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (buf[0] != '1')
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
memset(cp_command, 0x00, sizeof(cp_command));
|
|
|
|
memset(cp_response, 0x00, sizeof(cp_response));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The recording command needs to be called with option QID
|
|
|
|
* for guests that have previlege classes A or B.
|
|
|
|
* Other guests will not recognize the command and we have to
|
|
|
|
* issue the same command without the QID parameter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (recording_class_AB)
|
|
|
|
snprintf(cp_command, sizeof(cp_command),
|
|
|
|
"RECORDING %s PURGE QID * ",
|
|
|
|
priv->recording_name);
|
|
|
|
else
|
|
|
|
snprintf(cp_command, sizeof(cp_command),
|
|
|
|
"RECORDING %s PURGE ",
|
|
|
|
priv->recording_name);
|
|
|
|
|
2005-06-26 05:55:32 +08:00
|
|
|
cpcmd(cp_command, cp_response, sizeof(cp_response), NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DEVICE_ATTR(purge, 0200, NULL, vmlogrdr_purge_store);
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_autorecording_store(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char *buf, size_t count)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret = count;
|
|
|
|
|
|
|
|
switch (buf[0]) {
|
|
|
|
case '0':
|
|
|
|
priv->autorecording=0;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
priv->autorecording=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_autorecording_show(struct device *dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return sprintf(buf, "%u\n", priv->autorecording);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DEVICE_ATTR(autorecording, 0644, vmlogrdr_autorecording_show,
|
|
|
|
vmlogrdr_autorecording_store);
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static ssize_t vmlogrdr_recording_store(struct device * dev,
|
|
|
|
struct device_attribute *attr,
|
|
|
|
const char * buf, size_t count)
|
|
|
|
{
|
2009-05-05 03:40:54 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
ssize_t ret;
|
|
|
|
|
|
|
|
switch (buf[0]) {
|
|
|
|
case '0':
|
|
|
|
ret = vmlogrdr_recording(priv,0,0);
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
ret = vmlogrdr_recording(priv,1,0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
else
|
|
|
|
return count;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static DEVICE_ATTR(recording, 0200, NULL, vmlogrdr_recording_store);
|
|
|
|
|
|
|
|
|
2017-06-09 17:03:13 +08:00
|
|
|
static ssize_t recording_status_show(struct device_driver *driver, char *buf)
|
2007-02-09 05:40:41 +08:00
|
|
|
{
|
2010-10-25 22:10:20 +08:00
|
|
|
static const char cp_command[] = "QUERY RECORDING ";
|
2005-04-17 06:20:36 +08:00
|
|
|
int len;
|
|
|
|
|
2005-06-26 05:55:32 +08:00
|
|
|
cpcmd(cp_command, buf, 4096, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
len = strlen(buf);
|
|
|
|
return len;
|
|
|
|
}
|
2017-06-09 17:03:13 +08:00
|
|
|
static DRIVER_ATTR_RO(recording_status);
|
2012-06-05 01:33:09 +08:00
|
|
|
static struct attribute *vmlogrdr_drv_attrs[] = {
|
|
|
|
&driver_attr_recording_status.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
static struct attribute_group vmlogrdr_drv_attr_group = {
|
|
|
|
.attrs = vmlogrdr_drv_attrs,
|
|
|
|
};
|
|
|
|
static const struct attribute_group *vmlogrdr_drv_attr_groups[] = {
|
|
|
|
&vmlogrdr_drv_attr_group,
|
|
|
|
NULL,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct attribute *vmlogrdr_attrs[] = {
|
|
|
|
&dev_attr_autopurge.attr,
|
|
|
|
&dev_attr_purge.attr,
|
|
|
|
&dev_attr_autorecording.attr,
|
|
|
|
&dev_attr_recording.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
2012-06-05 01:32:13 +08:00
|
|
|
static struct attribute_group vmlogrdr_attr_group = {
|
|
|
|
.attrs = vmlogrdr_attrs,
|
|
|
|
};
|
|
|
|
static const struct attribute_group *vmlogrdr_attr_groups[] = {
|
|
|
|
&vmlogrdr_attr_group,
|
|
|
|
NULL,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-16 16:30:38 +08:00
|
|
|
static int vmlogrdr_pm_prepare(struct device *dev)
|
|
|
|
{
|
|
|
|
int rc;
|
2009-06-22 18:08:19 +08:00
|
|
|
struct vmlogrdr_priv_t *priv = dev_get_drvdata(dev);
|
2009-06-16 16:30:38 +08:00
|
|
|
|
|
|
|
rc = 0;
|
|
|
|
if (priv) {
|
|
|
|
spin_lock_bh(&priv->priv_lock);
|
|
|
|
if (priv->dev_in_use)
|
|
|
|
rc = -EBUSY;
|
|
|
|
spin_unlock_bh(&priv->priv_lock);
|
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
pr_err("vmlogrdr: device %s is busy. Refuse to suspend.\n",
|
|
|
|
dev_name(dev));
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-15 10:00:08 +08:00
|
|
|
static const struct dev_pm_ops vmlogrdr_pm_ops = {
|
2009-06-16 16:30:38 +08:00
|
|
|
.prepare = vmlogrdr_pm_prepare,
|
|
|
|
};
|
|
|
|
|
2005-03-24 02:01:41 +08:00
|
|
|
static struct class *vmlogrdr_class;
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct device_driver vmlogrdr_driver = {
|
|
|
|
.name = "vmlogrdr",
|
|
|
|
.bus = &iucv_bus,
|
2009-06-16 16:30:38 +08:00
|
|
|
.pm = &vmlogrdr_pm_ops,
|
2012-06-05 01:33:09 +08:00
|
|
|
.groups = vmlogrdr_drv_attr_groups,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_register_driver(void)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
/* Register with iucv driver */
|
|
|
|
ret = iucv_register(&vmlogrdr_iucv_handler, 1);
|
2008-07-14 15:59:37 +08:00
|
|
|
if (ret)
|
2007-02-09 05:40:41 +08:00
|
|
|
goto out;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = driver_register(&vmlogrdr_driver);
|
2008-07-14 15:59:37 +08:00
|
|
|
if (ret)
|
2007-02-09 05:40:41 +08:00
|
|
|
goto out_iucv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-03-24 02:01:41 +08:00
|
|
|
vmlogrdr_class = class_create(THIS_MODULE, "vmlogrdr");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (IS_ERR(vmlogrdr_class)) {
|
2007-02-09 05:40:41 +08:00
|
|
|
ret = PTR_ERR(vmlogrdr_class);
|
|
|
|
vmlogrdr_class = NULL;
|
2012-06-05 01:33:09 +08:00
|
|
|
goto out_driver;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
out_driver:
|
2005-04-17 06:20:36 +08:00
|
|
|
driver_unregister(&vmlogrdr_driver);
|
2007-02-09 05:40:41 +08:00
|
|
|
out_iucv:
|
|
|
|
iucv_unregister(&vmlogrdr_iucv_handler, 1);
|
|
|
|
out:
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static void vmlogrdr_unregister_driver(void)
|
|
|
|
{
|
2005-03-24 02:01:41 +08:00
|
|
|
class_destroy(vmlogrdr_class);
|
2005-04-17 06:20:36 +08:00
|
|
|
vmlogrdr_class = NULL;
|
|
|
|
driver_unregister(&vmlogrdr_driver);
|
2007-02-09 05:40:41 +08:00
|
|
|
iucv_unregister(&vmlogrdr_iucv_handler, 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_register_device(struct vmlogrdr_priv_t *priv)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
struct device *dev;
|
|
|
|
int ret;
|
|
|
|
|
2006-03-24 19:15:31 +08:00
|
|
|
dev = kzalloc(sizeof(struct device), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (dev) {
|
2014-06-11 01:46:20 +08:00
|
|
|
dev_set_name(dev, "%s", priv->internal_name);
|
2005-04-17 06:20:36 +08:00
|
|
|
dev->bus = &iucv_bus;
|
|
|
|
dev->parent = iucv_root;
|
|
|
|
dev->driver = &vmlogrdr_driver;
|
2012-06-05 01:32:13 +08:00
|
|
|
dev->groups = vmlogrdr_attr_groups;
|
2009-06-22 18:08:19 +08:00
|
|
|
dev_set_drvdata(dev, priv);
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* The release function could be called after the
|
|
|
|
* module has been unloaded. It's _only_ task is to
|
|
|
|
* free the struct. Therefore, we specify kfree()
|
|
|
|
* directly here. (Probably a little bit obfuscating
|
|
|
|
* but legitime ...).
|
|
|
|
*/
|
|
|
|
dev->release = (void (*)(struct device *))kfree;
|
|
|
|
} else
|
|
|
|
return -ENOMEM;
|
|
|
|
ret = device_register(dev);
|
2009-09-11 16:28:38 +08:00
|
|
|
if (ret) {
|
|
|
|
put_device(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
2009-09-11 16:28:38 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-22 11:03:34 +08:00
|
|
|
priv->class_device = device_create(vmlogrdr_class, dev,
|
|
|
|
MKDEV(vmlogrdr_major,
|
|
|
|
priv->minor_num),
|
|
|
|
priv, "%s", dev_name(dev));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (IS_ERR(priv->class_device)) {
|
|
|
|
ret = PTR_ERR(priv->class_device);
|
|
|
|
priv->class_device=NULL;
|
|
|
|
device_unregister(dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
priv->device = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_unregister_device(struct vmlogrdr_priv_t *priv)
|
|
|
|
{
|
2007-10-22 18:52:42 +08:00
|
|
|
device_destroy(vmlogrdr_class, MKDEV(vmlogrdr_major, priv->minor_num));
|
2005-04-17 06:20:36 +08:00
|
|
|
if (priv->device != NULL) {
|
|
|
|
device_unregister(priv->device);
|
|
|
|
priv->device=NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static int vmlogrdr_register_cdev(dev_t dev)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc = 0;
|
|
|
|
vmlogrdr_cdev = cdev_alloc();
|
|
|
|
if (!vmlogrdr_cdev) {
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
vmlogrdr_cdev->owner = THIS_MODULE;
|
|
|
|
vmlogrdr_cdev->ops = &vmlogrdr_fops;
|
2017-09-18 17:13:13 +08:00
|
|
|
rc = cdev_add(vmlogrdr_cdev, dev, MAXMINOR);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!rc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// cleanup: cdev is not fully registered, no cdev_del here!
|
|
|
|
kobject_put(&vmlogrdr_cdev->kobj);
|
|
|
|
vmlogrdr_cdev=NULL;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-09 05:40:41 +08:00
|
|
|
static void vmlogrdr_cleanup(void)
|
|
|
|
{
|
2005-04-17 06:20:36 +08:00
|
|
|
int i;
|
2007-02-09 05:40:41 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (vmlogrdr_cdev) {
|
|
|
|
cdev_del(vmlogrdr_cdev);
|
|
|
|
vmlogrdr_cdev=NULL;
|
|
|
|
}
|
|
|
|
for (i=0; i < MAXMINOR; ++i ) {
|
|
|
|
vmlogrdr_unregister_device(&sys_ser[i]);
|
|
|
|
free_page((unsigned long)sys_ser[i].buffer);
|
|
|
|
}
|
|
|
|
vmlogrdr_unregister_driver();
|
|
|
|
if (vmlogrdr_major) {
|
|
|
|
unregister_chrdev_region(MKDEV(vmlogrdr_major, 0), MAXMINOR);
|
|
|
|
vmlogrdr_major=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-10 17:24:22 +08:00
|
|
|
static int __init vmlogrdr_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
int i;
|
|
|
|
dev_t dev;
|
|
|
|
|
|
|
|
if (! MACHINE_IS_VM) {
|
2008-12-25 20:39:52 +08:00
|
|
|
pr_err("not running under VM, driver not loaded.\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
recording_class_AB = vmlogrdr_get_recording_class_AB();
|
|
|
|
|
|
|
|
rc = alloc_chrdev_region(&dev, 0, MAXMINOR, "vmlogrdr");
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
vmlogrdr_major = MAJOR(dev);
|
|
|
|
|
|
|
|
rc=vmlogrdr_register_driver();
|
|
|
|
if (rc)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
for (i=0; i < MAXMINOR; ++i ) {
|
2016-11-21 19:13:58 +08:00
|
|
|
sys_ser[i].buffer = (char *) get_zeroed_page(GFP_KERNEL | GFP_DMA);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!sys_ser[i].buffer) {
|
2008-05-15 22:52:32 +08:00
|
|
|
rc = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sys_ser[i].current_position = sys_ser[i].buffer;
|
|
|
|
rc=vmlogrdr_register_device(&sys_ser[i]);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (rc)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
rc = vmlogrdr_register_cdev(dev);
|
|
|
|
if (rc)
|
|
|
|
goto cleanup;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
vmlogrdr_cleanup();
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-07-10 17:24:22 +08:00
|
|
|
static void __exit vmlogrdr_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
vmlogrdr_cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(vmlogrdr_init);
|
|
|
|
module_exit(vmlogrdr_exit);
|