s390/appldata: reuse generic proc handler functions
Simplify appldata proc handlers by reusing generic proc handler functions. Tested-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Reviewed-by: Gerald Schaefer <gerald.schaefer@de.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
Родитель
71e33a1dd7
Коммит
6c8021503f
|
@ -206,34 +206,28 @@ static int
|
||||||
appldata_timer_handler(struct ctl_table *ctl, int write,
|
appldata_timer_handler(struct ctl_table *ctl, int write,
|
||||||
void __user *buffer, size_t *lenp, loff_t *ppos)
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
int timer_active = appldata_timer_active;
|
||||||
char buf[2];
|
int zero = 0;
|
||||||
|
int one = 1;
|
||||||
|
int rc;
|
||||||
|
struct ctl_table ctl_entry = {
|
||||||
|
.procname = ctl->procname,
|
||||||
|
.data = &timer_active,
|
||||||
|
.maxlen = sizeof(int),
|
||||||
|
.extra1 = &zero,
|
||||||
|
.extra2 = &one,
|
||||||
|
};
|
||||||
|
|
||||||
|
rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
||||||
|
if (rc < 0 || !write)
|
||||||
|
return rc;
|
||||||
|
|
||||||
if (!*lenp || *ppos) {
|
|
||||||
*lenp = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (!write) {
|
|
||||||
memcpy(buf, appldata_timer_active ? "1\n" : "0\n", ARRAY_SIZE(buf));
|
|
||||||
len = strnlen(buf, ARRAY_SIZE(buf));
|
|
||||||
if (len > *lenp)
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_to_user(buffer, buf, len))
|
|
||||||
return -EFAULT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len))
|
|
||||||
return -EFAULT;
|
|
||||||
spin_lock(&appldata_timer_lock);
|
spin_lock(&appldata_timer_lock);
|
||||||
if (buf[0] == '1')
|
if (timer_active)
|
||||||
__appldata_vtimer_setup(APPLDATA_ADD_TIMER);
|
__appldata_vtimer_setup(APPLDATA_ADD_TIMER);
|
||||||
else if (buf[0] == '0')
|
else
|
||||||
__appldata_vtimer_setup(APPLDATA_DEL_TIMER);
|
__appldata_vtimer_setup(APPLDATA_DEL_TIMER);
|
||||||
spin_unlock(&appldata_timer_lock);
|
spin_unlock(&appldata_timer_lock);
|
||||||
out:
|
|
||||||
*lenp = len;
|
|
||||||
*ppos += len;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,37 +241,24 @@ static int
|
||||||
appldata_interval_handler(struct ctl_table *ctl, int write,
|
appldata_interval_handler(struct ctl_table *ctl, int write,
|
||||||
void __user *buffer, size_t *lenp, loff_t *ppos)
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
||||||
{
|
{
|
||||||
unsigned int len;
|
int interval = appldata_interval;
|
||||||
int interval;
|
int one = 1;
|
||||||
char buf[16];
|
int rc;
|
||||||
|
struct ctl_table ctl_entry = {
|
||||||
|
.procname = ctl->procname,
|
||||||
|
.data = &interval,
|
||||||
|
.maxlen = sizeof(int),
|
||||||
|
.extra1 = &one,
|
||||||
|
};
|
||||||
|
|
||||||
if (!*lenp || *ppos) {
|
rc = proc_dointvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
||||||
*lenp = 0;
|
if (rc < 0 || !write)
|
||||||
return 0;
|
return rc;
|
||||||
}
|
|
||||||
if (!write) {
|
|
||||||
len = sprintf(buf, "%i\n", appldata_interval);
|
|
||||||
if (len > *lenp)
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_to_user(buffer, buf, len))
|
|
||||||
return -EFAULT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_from_user(buf, buffer, len > sizeof(buf) ? sizeof(buf) : len))
|
|
||||||
return -EFAULT;
|
|
||||||
interval = 0;
|
|
||||||
sscanf(buf, "%i", &interval);
|
|
||||||
if (interval <= 0)
|
|
||||||
return -EINVAL;
|
|
||||||
|
|
||||||
spin_lock(&appldata_timer_lock);
|
spin_lock(&appldata_timer_lock);
|
||||||
appldata_interval = interval;
|
appldata_interval = interval;
|
||||||
__appldata_vtimer_setup(APPLDATA_MOD_TIMER);
|
__appldata_vtimer_setup(APPLDATA_MOD_TIMER);
|
||||||
spin_unlock(&appldata_timer_lock);
|
spin_unlock(&appldata_timer_lock);
|
||||||
out:
|
|
||||||
*lenp = len;
|
|
||||||
*ppos += len;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,10 +273,17 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
|
||||||
void __user *buffer, size_t *lenp, loff_t *ppos)
|
void __user *buffer, size_t *lenp, loff_t *ppos)
|
||||||
{
|
{
|
||||||
struct appldata_ops *ops = NULL, *tmp_ops;
|
struct appldata_ops *ops = NULL, *tmp_ops;
|
||||||
unsigned int len;
|
|
||||||
int rc, found;
|
|
||||||
char buf[2];
|
|
||||||
struct list_head *lh;
|
struct list_head *lh;
|
||||||
|
int rc, found;
|
||||||
|
int active;
|
||||||
|
int zero = 0;
|
||||||
|
int one = 1;
|
||||||
|
struct ctl_table ctl_entry = {
|
||||||
|
.data = &active,
|
||||||
|
.maxlen = sizeof(int),
|
||||||
|
.extra1 = &zero,
|
||||||
|
.extra2 = &one,
|
||||||
|
};
|
||||||
|
|
||||||
found = 0;
|
found = 0;
|
||||||
mutex_lock(&appldata_ops_mutex);
|
mutex_lock(&appldata_ops_mutex);
|
||||||
|
@ -316,31 +304,15 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
|
||||||
}
|
}
|
||||||
mutex_unlock(&appldata_ops_mutex);
|
mutex_unlock(&appldata_ops_mutex);
|
||||||
|
|
||||||
if (!*lenp || *ppos) {
|
active = ops->active;
|
||||||
*lenp = 0;
|
rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
||||||
|
if (rc < 0 || !write) {
|
||||||
module_put(ops->owner);
|
module_put(ops->owner);
|
||||||
return 0;
|
return rc;
|
||||||
}
|
|
||||||
if (!write) {
|
|
||||||
memcpy(buf, ops->active ? "1\n" : "0\n", ARRAY_SIZE(buf));
|
|
||||||
len = strnlen(buf, ARRAY_SIZE(buf));
|
|
||||||
if (len > *lenp)
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_to_user(buffer, buf, len)) {
|
|
||||||
module_put(ops->owner);
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
len = *lenp;
|
|
||||||
if (copy_from_user(buf, buffer,
|
|
||||||
len > sizeof(buf) ? sizeof(buf) : len)) {
|
|
||||||
module_put(ops->owner);
|
|
||||||
return -EFAULT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mutex_lock(&appldata_ops_mutex);
|
mutex_lock(&appldata_ops_mutex);
|
||||||
if ((buf[0] == '1') && (ops->active == 0)) {
|
if (active && (ops->active == 0)) {
|
||||||
// protect work queue callback
|
// protect work queue callback
|
||||||
if (!try_module_get(ops->owner)) {
|
if (!try_module_get(ops->owner)) {
|
||||||
mutex_unlock(&appldata_ops_mutex);
|
mutex_unlock(&appldata_ops_mutex);
|
||||||
|
@ -358,7 +330,7 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
|
||||||
module_put(ops->owner);
|
module_put(ops->owner);
|
||||||
} else
|
} else
|
||||||
ops->active = 1;
|
ops->active = 1;
|
||||||
} else if ((buf[0] == '0') && (ops->active == 1)) {
|
} else if (!active && (ops->active == 1)) {
|
||||||
ops->active = 0;
|
ops->active = 0;
|
||||||
rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
|
rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
|
||||||
(unsigned long) ops->data, ops->size,
|
(unsigned long) ops->data, ops->size,
|
||||||
|
@ -369,9 +341,6 @@ appldata_generic_handler(struct ctl_table *ctl, int write,
|
||||||
module_put(ops->owner);
|
module_put(ops->owner);
|
||||||
}
|
}
|
||||||
mutex_unlock(&appldata_ops_mutex);
|
mutex_unlock(&appldata_ops_mutex);
|
||||||
out:
|
|
||||||
*lenp = len;
|
|
||||||
*ppos += len;
|
|
||||||
module_put(ops->owner);
|
module_put(ops->owner);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче