xpp: Serialize dahdi registration
xpp: Serialize dahdi registration: Cause races under highly-parallel workloads (with dahdi_autoreg=0). Signed-off-by: Tzafrir Cohen <tzafrir.cohen@xorcom.com>
This commit is contained in:
parent
ce3f1f2650
commit
745118acb9
@ -24,6 +24,7 @@
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#include <linux/seq_file.h>
|
||||
#ifdef PROTOCOL_DEBUG
|
||||
@ -937,6 +938,8 @@ static void xbus_free_ddev(xbus_t *xbus)
|
||||
xbus->ddev = NULL;
|
||||
}
|
||||
|
||||
static DEFINE_MUTEX(dahdi_registration_mutex);
|
||||
|
||||
int xbus_register_dahdi_device(xbus_t *xbus)
|
||||
{
|
||||
int i;
|
||||
@ -944,6 +947,11 @@ int xbus_register_dahdi_device(xbus_t *xbus)
|
||||
int ret;
|
||||
|
||||
XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__);
|
||||
ret = mutex_lock_interruptible(&dahdi_registration_mutex);
|
||||
if (ret < 0) {
|
||||
XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n");
|
||||
goto err;
|
||||
}
|
||||
if (xbus_is_registered(xbus)) {
|
||||
XBUS_ERR(xbus, "Already registered to DAHDI\n");
|
||||
WARN_ON(1);
|
||||
@ -1008,17 +1016,26 @@ int xbus_register_dahdi_device(xbus_t *xbus)
|
||||
xpd_dahdi_postregister(xpd);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
ret = 0;
|
||||
out:
|
||||
mutex_unlock(&dahdi_registration_mutex);
|
||||
return ret;
|
||||
err:
|
||||
xbus_free_ddev(xbus);
|
||||
return ret;
|
||||
goto out;
|
||||
}
|
||||
|
||||
void xbus_unregister_dahdi_device(xbus_t *xbus)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
|
||||
XBUS_NOTICE(xbus, "%s\n", __func__);
|
||||
ret = mutex_lock_interruptible(&dahdi_registration_mutex);
|
||||
if (ret < 0) {
|
||||
XBUS_ERR(xbus, "dahdi_registration_mutex already taken\n");
|
||||
return;
|
||||
}
|
||||
for (i = 0; i < MAX_XPDS; i++) {
|
||||
xpd_t *xpd = xpd_of(xbus, i);
|
||||
xpd_dahdi_preunregister(xpd);
|
||||
@ -1033,6 +1050,7 @@ void xbus_unregister_dahdi_device(xbus_t *xbus)
|
||||
xpd_t *xpd = xpd_of(xbus, i);
|
||||
xpd_dahdi_postunregister(xpd);
|
||||
}
|
||||
mutex_unlock(&dahdi_registration_mutex);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/errno.h>
|
||||
#include <linux/mutex.h>
|
||||
#include <linux/proc_fs.h>
|
||||
#ifdef PROTOCOL_DEBUG
|
||||
#include <linux/ctype.h>
|
||||
@ -582,6 +583,8 @@ static DEVICE_ATTR_READER(span_show, dev, buf)
|
||||
return len;
|
||||
}
|
||||
|
||||
static DEFINE_MUTEX(span_store_mutex);
|
||||
|
||||
/*
|
||||
* For backward compatibility with old dahdi-tools
|
||||
* Remove after dahdi_registration is upgraded
|
||||
@ -603,6 +606,11 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count)
|
||||
return -ENODEV;
|
||||
XPD_DBG(DEVICES, xpd, "%s -- deprecated (should use pinned-spans)\n",
|
||||
(dahdi_reg) ? "register" : "unregister");
|
||||
ret = mutex_lock_interruptible(&span_store_mutex);
|
||||
if (ret < 0) {
|
||||
XBUS_ERR(xpd->xbus, "span_store_mutex already taken\n");
|
||||
return ret;
|
||||
}
|
||||
if (xbus_is_registered(xpd->xbus)) {
|
||||
if (dahdi_reg) {
|
||||
XPD_DBG(DEVICES, xpd,
|
||||
@ -620,6 +628,7 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count)
|
||||
xbus_register_dahdi_device(xpd->xbus);
|
||||
}
|
||||
}
|
||||
mutex_unlock(&span_store_mutex);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user