Commit ed8e66ba authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] s390: z/VM monitor stream.

From: Martin Schwidefsky <schwidefsky@de.ibm.com>

Fix for z/VM monitor stream:
 - Add try_module_get and module_put to the [un]register functions.
 - Some code beautification.
parent 97de3ddf
...@@ -336,9 +336,9 @@ appldata_interval_handler(ctl_table *ctl, int write, struct file *filp, ...@@ -336,9 +336,9 @@ appldata_interval_handler(ctl_table *ctl, int write, struct file *filp,
P_ERROR("Timer CPU interval has to be > 0!\n"); P_ERROR("Timer CPU interval has to be > 0!\n");
return -EINVAL; return -EINVAL;
} }
per_cpu_interval = (u64) (interval*1000 / num_online_cpus()) * TOD_MICRO;
spin_lock(&appldata_timer_lock); spin_lock(&appldata_timer_lock);
per_cpu_interval = (u64) (interval*1000 / num_online_cpus()) * TOD_MICRO;
appldata_interval = interval; appldata_interval = interval;
if (appldata_timer_active) { if (appldata_timer_active) {
for (i = 0; i < num_online_cpus(); i++) { for (i = 0; i < num_online_cpus(); i++) {
...@@ -395,6 +395,10 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp, ...@@ -395,6 +395,10 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
spin_lock_bh(&appldata_ops_lock); spin_lock_bh(&appldata_ops_lock);
if ((buf[0] == '1') && (ops->active == 0)) { if ((buf[0] == '1') && (ops->active == 0)) {
if (!try_module_get(ops->owner)) {
spin_unlock_bh(&appldata_ops_lock);
return -ENODEV;
}
ops->active = 1; ops->active = 1;
ops->callback(ops->data); // init record ops->callback(ops->data); // init record
rc = appldata_diag(ops->record_nr, rc = appldata_diag(ops->record_nr,
...@@ -403,6 +407,7 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp, ...@@ -403,6 +407,7 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
if (rc != 0) { if (rc != 0) {
P_ERROR("START DIAG 0xDC for %s failed, " P_ERROR("START DIAG 0xDC for %s failed, "
"return code: %d\n", ops->name, rc); "return code: %d\n", ops->name, rc);
module_put(ops->owner);
ops->active = 0; ops->active = 0;
} else { } else {
P_INFO("Monitoring %s data enabled, " P_INFO("Monitoring %s data enabled, "
...@@ -419,6 +424,7 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp, ...@@ -419,6 +424,7 @@ appldata_generic_handler(ctl_table *ctl, int write, struct file *filp,
P_INFO("Monitoring %s data disabled, " P_INFO("Monitoring %s data disabled, "
"DIAG 0xDC stopped.\n", ops->name); "DIAG 0xDC stopped.\n", ops->name);
} }
module_put(ops->owner);
} }
spin_unlock_bh(&appldata_ops_lock); spin_unlock_bh(&appldata_ops_lock);
out: out:
...@@ -440,30 +446,26 @@ int appldata_register_ops(struct appldata_ops *ops) ...@@ -440,30 +446,26 @@ int appldata_register_ops(struct appldata_ops *ops)
{ {
struct list_head *lh; struct list_head *lh;
struct appldata_ops *tmp_ops; struct appldata_ops *tmp_ops;
int rc, i; int i;
rc = 0;
i = 0; i = 0;
if ((ops->size > APPLDATA_MAX_REC_SIZE) || if ((ops->size > APPLDATA_MAX_REC_SIZE) ||
(ops->size < 0)){ (ops->size < 0)){
P_ERROR("Invalid size of %s record = %i, maximum = %i!\n", P_ERROR("Invalid size of %s record = %i, maximum = %i!\n",
ops->name, ops->size, APPLDATA_MAX_REC_SIZE); ops->name, ops->size, APPLDATA_MAX_REC_SIZE);
rc = -ENOMEM; return -ENOMEM;
goto out;
} }
if ((ops->ctl_nr == CTL_APPLDATA) || if ((ops->ctl_nr == CTL_APPLDATA) ||
(ops->ctl_nr == CTL_APPLDATA_TIMER) || (ops->ctl_nr == CTL_APPLDATA_TIMER) ||
(ops->ctl_nr == CTL_APPLDATA_INTERVAL)) { (ops->ctl_nr == CTL_APPLDATA_INTERVAL)) {
P_ERROR("ctl_nr %i already in use!\n", ops->ctl_nr); P_ERROR("ctl_nr %i already in use!\n", ops->ctl_nr);
rc = -EBUSY; return -EBUSY;
goto out;
} }
ops->ctl_table = kmalloc(4*sizeof(struct ctl_table), GFP_KERNEL); ops->ctl_table = kmalloc(4*sizeof(struct ctl_table), GFP_KERNEL);
if (ops->ctl_table == NULL) { if (ops->ctl_table == NULL) {
P_ERROR("Not enough memory for %s ctl_table!\n", ops->name); P_ERROR("Not enough memory for %s ctl_table!\n", ops->name);
rc = -ENOMEM; return -ENOMEM;
goto out;
} }
memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table)); memset(ops->ctl_table, 0, 4*sizeof(struct ctl_table));
...@@ -477,18 +479,16 @@ int appldata_register_ops(struct appldata_ops *ops) ...@@ -477,18 +479,16 @@ int appldata_register_ops(struct appldata_ops *ops)
ops->ctl_nr); ops->ctl_nr);
if (strncmp(tmp_ops->name, ops->name, if (strncmp(tmp_ops->name, ops->name,
APPLDATA_PROC_NAME_LENGTH) == 0) { APPLDATA_PROC_NAME_LENGTH) == 0) {
spin_unlock_bh(&appldata_ops_lock);
P_ERROR("Name \"%s\" already registered!\n", ops->name); P_ERROR("Name \"%s\" already registered!\n", ops->name);
kfree(ops->ctl_table); kfree(ops->ctl_table);
rc = -EBUSY; spin_unlock_bh(&appldata_ops_lock);
goto out; return -EBUSY;
} }
if (tmp_ops->ctl_nr == ops->ctl_nr) { if (tmp_ops->ctl_nr == ops->ctl_nr) {
spin_unlock_bh(&appldata_ops_lock);
P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr); P_ERROR("ctl_nr %i already registered!\n", ops->ctl_nr);
kfree(ops->ctl_table); kfree(ops->ctl_table);
rc = -EBUSY; spin_unlock_bh(&appldata_ops_lock);
goto out; return -EBUSY;
} }
} }
list_add(&ops->list, &appldata_ops_list); list_add(&ops->list, &appldata_ops_list);
...@@ -512,9 +512,9 @@ int appldata_register_ops(struct appldata_ops *ops) ...@@ -512,9 +512,9 @@ int appldata_register_ops(struct appldata_ops *ops)
ops->sysctl_header = register_sysctl_table(ops->ctl_table,1); ops->sysctl_header = register_sysctl_table(ops->ctl_table,1);
ops->ctl_table[2].de->owner = ops->owner; ops->ctl_table[2].de->owner = ops->owner;
P_INFO("%s-ops registered!\n", ops->name); P_INFO("%s-ops registered!\n", ops->name);
out: return 0;
return rc;
} }
/* /*
...@@ -524,26 +524,11 @@ int appldata_register_ops(struct appldata_ops *ops) ...@@ -524,26 +524,11 @@ int appldata_register_ops(struct appldata_ops *ops)
*/ */
void appldata_unregister_ops(struct appldata_ops *ops) void appldata_unregister_ops(struct appldata_ops *ops)
{ {
int rc;
unregister_sysctl_table(ops->sysctl_header);
kfree(ops->ctl_table);
if (ops->active == 1) {
ops->active = 0;
rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
(unsigned long) ops->data, ops->size);
if (rc != 0) {
P_ERROR("STOP DIAG 0xDC for %s failed, "
"return code: %d\n", ops->name, rc);
} else {
P_INFO("Monitoring %s data disabled, "
"DIAG 0xDC stopped.\n", ops->name);
}
}
spin_lock_bh(&appldata_ops_lock); spin_lock_bh(&appldata_ops_lock);
list_del(&ops->list); list_del(&ops->list);
spin_unlock_bh(&appldata_ops_lock); spin_unlock_bh(&appldata_ops_lock);
unregister_sysctl_table(ops->sysctl_header);
kfree(ops->ctl_table);
P_INFO("%s-ops unregistered!\n", ops->name); P_INFO("%s-ops unregistered!\n", ops->name);
} }
/********************** module-ops management <END> **************************/ /********************** module-ops management <END> **************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment