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:
Oron Peled 2013-09-29 13:20:38 +02:00 committed by Tzafrir Cohen
parent ce3f1f2650
commit 745118acb9
2 changed files with 29 additions and 2 deletions

View File

@ -24,6 +24,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/sched.h> #include <linux/sched.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#ifdef PROTOCOL_DEBUG #ifdef PROTOCOL_DEBUG
@ -937,6 +938,8 @@ static void xbus_free_ddev(xbus_t *xbus)
xbus->ddev = NULL; xbus->ddev = NULL;
} }
static DEFINE_MUTEX(dahdi_registration_mutex);
int xbus_register_dahdi_device(xbus_t *xbus) int xbus_register_dahdi_device(xbus_t *xbus)
{ {
int i; int i;
@ -944,6 +947,11 @@ int xbus_register_dahdi_device(xbus_t *xbus)
int ret; int ret;
XBUS_DBG(DEVICES, xbus, "Entering %s\n", __func__); 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)) { if (xbus_is_registered(xbus)) {
XBUS_ERR(xbus, "Already registered to DAHDI\n"); XBUS_ERR(xbus, "Already registered to DAHDI\n");
WARN_ON(1); WARN_ON(1);
@ -1008,17 +1016,26 @@ int xbus_register_dahdi_device(xbus_t *xbus)
xpd_dahdi_postregister(xpd); xpd_dahdi_postregister(xpd);
} }
} }
return 0; ret = 0;
out:
mutex_unlock(&dahdi_registration_mutex);
return ret;
err: err:
xbus_free_ddev(xbus); xbus_free_ddev(xbus);
return ret; goto out;
} }
void xbus_unregister_dahdi_device(xbus_t *xbus) void xbus_unregister_dahdi_device(xbus_t *xbus)
{ {
int i; int i;
int ret;
XBUS_NOTICE(xbus, "%s\n", __func__); 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++) { for (i = 0; i < MAX_XPDS; i++) {
xpd_t *xpd = xpd_of(xbus, i); xpd_t *xpd = xpd_of(xbus, i);
xpd_dahdi_preunregister(xpd); xpd_dahdi_preunregister(xpd);
@ -1033,6 +1050,7 @@ void xbus_unregister_dahdi_device(xbus_t *xbus)
xpd_t *xpd = xpd_of(xbus, i); xpd_t *xpd = xpd_of(xbus, i);
xpd_dahdi_postunregister(xpd); xpd_dahdi_postunregister(xpd);
} }
mutex_unlock(&dahdi_registration_mutex);
} }
/* /*

View File

@ -23,6 +23,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h> #include <linux/proc_fs.h>
#ifdef PROTOCOL_DEBUG #ifdef PROTOCOL_DEBUG
#include <linux/ctype.h> #include <linux/ctype.h>
@ -582,6 +583,8 @@ static DEVICE_ATTR_READER(span_show, dev, buf)
return len; return len;
} }
static DEFINE_MUTEX(span_store_mutex);
/* /*
* For backward compatibility with old dahdi-tools * For backward compatibility with old dahdi-tools
* Remove after dahdi_registration is upgraded * Remove after dahdi_registration is upgraded
@ -603,6 +606,11 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count)
return -ENODEV; return -ENODEV;
XPD_DBG(DEVICES, xpd, "%s -- deprecated (should use pinned-spans)\n", XPD_DBG(DEVICES, xpd, "%s -- deprecated (should use pinned-spans)\n",
(dahdi_reg) ? "register" : "unregister"); (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 (xbus_is_registered(xpd->xbus)) {
if (dahdi_reg) { if (dahdi_reg) {
XPD_DBG(DEVICES, xpd, XPD_DBG(DEVICES, xpd,
@ -620,6 +628,7 @@ static DEVICE_ATTR_WRITER(span_store, dev, buf, count)
xbus_register_dahdi_device(xpd->xbus); xbus_register_dahdi_device(xpd->xbus);
} }
} }
mutex_unlock(&span_store_mutex);
return count; return count;
} }