[svn-commits] tzafrir: linux/trunk r8913 - /linux/trunk/drivers/dahdi/xpp/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 13 14:38:16 CDT 2010


Author: tzafrir
Date: Tue Jul 13 14:38:13 2010
New Revision: 8913

URL: http://svnview.digium.com/svn/dahdi?view=rev&rev=8913
Log:
start migrating from xbus_num() to get_xbus()/put_xbus()

* Now get_xbus() receive and xbus number (not poiner) and uses xbus_num()
  internally to map it to an xbus pointer + refcount increment. (this is
  atomic)
* Migrate all obvious places that used xbus_num() to map bus number into a
  pointer, so now they use get_xbus() + put_xbus() to aquire and release an
  xbus.

Modified:
    linux/trunk/drivers/dahdi/xpp/xbus-core.c
    linux/trunk/drivers/dahdi/xpp/xbus-core.h
    linux/trunk/drivers/dahdi/xpp/xbus-pcm.c
    linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c

Modified: linux/trunk/drivers/dahdi/xpp/xbus-core.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-core.c?view=diff&rev=8913&r1=8912&r2=8913
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-core.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-core.c Tue Jul 13 14:38:13 2010
@@ -189,11 +189,19 @@
 	xbus_sysfs_remove(xbus);
 }
 
-xbus_t *get_xbus(const char *msg, xbus_t *xbus)
-{
-	XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n",
-		msg, refcount_xbus(xbus));
-	kref_get(&xbus->kref);
+xbus_t *get_xbus(const char *msg, uint num)
+{
+	unsigned long	flags;
+	xbus_t		*xbus;
+
+	spin_lock_irqsave(&xbuses_lock, flags);
+	xbus = xbus_num(num);
+	if (xbus != NULL) {
+		kref_get(&xbus->kref);
+		XBUS_DBG(DEVICES, xbus, "%s: refcount_xbus=%d\n",
+			msg, refcount_xbus(xbus));
+	}
+	spin_unlock_irqrestore(&xbuses_lock, flags);
 	return xbus;
 }
 
@@ -999,7 +1007,7 @@
 	int			ret = 0;
 
 	xbus = container_of(worker, xbus_t, worker);
-	xbus = get_xbus(__func__, xbus);	/* return in function end */
+	xbus = get_xbus(__func__, xbus->num);	/* return in function end */
 	XBUS_DBG(DEVICES, xbus, "Entering %s\n", __FUNCTION__);
 	spin_lock_irqsave(&worker->worker_lock, flags);
 	list_for_each_safe(card, next_card, &worker->card_list) {
@@ -1169,7 +1177,7 @@
 {
 	struct xbus_workqueue	*worker;
 
-	xbus = get_xbus(__func__, xbus);	/* return in worker_destroy() */
+	xbus = get_xbus(__func__, xbus->num);	/* return in worker_destroy() */
 	BUG_ON(!xbus);
 	BUG_ON(xbus->busname[0] == '\0');	/* No name? */
 	worker = &xbus->worker;
@@ -1337,6 +1345,7 @@
 	if(!xbus_setstate(xbus, XBUS_STATE_DEACTIVATING))
 		return;
 	xbus_request_sync(xbus, SYNC_MODE_NONE);	/* no more ticks */
+	elect_syncer("deactivate");
 	xbus_request_removal(xbus);
 	XBUS_DBG(DEVICES, xbus, "[%s] Waiting for queues\n", xbus->label);
 	xbus_command_queue_clean(xbus);
@@ -1344,7 +1353,6 @@
 	xbus_setstate(xbus, XBUS_STATE_DEACTIVATED);
 	worker_reset(xbus);
 	xbus_release_xpds(xbus);	/* taken in xpd_alloc() [kref_init] */
-	elect_syncer("deactivate");
 }
 
 void xbus_disconnect(xbus_t *xbus)
@@ -1585,7 +1593,8 @@
 	 * FIXME: worker is created before ?????
 	 * So by now it exists and initialized.
 	 */
-	xbus = get_xbus(__func__, xbus); /* until end of waitfor_xpds_show() */
+	/* until end of waitfor_xpds_show(): */
+	xbus = get_xbus(__func__, xbus->num);
 	if (!xbus)
 		return -ENODEV;
 	worker = &xbus->worker;
@@ -1663,10 +1672,9 @@
 	int			len = 0;
 	int			i = (int)((unsigned long)data);
 
-	xbus = xbus_num(i);
+	xbus = get_xbus(__func__, i);	/* until end of xbus_read_proc */
 	if(!xbus)
 		goto out;
-	xbus = get_xbus(__FUNCTION__, xbus);	/* until end of xbus_read_proc */
 	spin_lock_irqsave(&xbus->lock, flags);
 	worker = &xbus->worker;
 
@@ -1734,17 +1742,18 @@
 static int xbus_read_waitfor_xpds(char *page, char **start, off_t off, int count, int *eof, void *data)
 {
 	int			len = 0;
-	xbus_t			*xbus = data;
-
-	if(!xbus)
-		goto out;
-	XBUS_NOTICE(xbus, "%s: DEPRECATED: %s[%d] read from /proc interface instead of /sys\n",
-		__FUNCTION__, current->comm, current->tgid);
-	/* first handle special cases */
-	if(!count || off)
-		goto out;
-	len = waitfor_xpds(xbus, page);
-out:
+	int			i = (int)((unsigned long)data);
+	xbus_t			*xbus;
+
+	xbus = get_xbus(__func__, i);
+	if (xbus != NULL) {
+		XBUS_NOTICE(xbus, "%s: DEPRECATED: %s[%d] read from /proc interface instead of /sys\n",
+			__func__, current->comm, current->tgid);
+		/* first handle special cases */
+		if (count && !off)
+			len = waitfor_xpds(xbus, page);
+		put_xbus(__func__, xbus);
+	}
 	if (len <= off+count)
 		*eof = 1;
 	*start = page + off;
@@ -1841,12 +1850,10 @@
 static int read_proc_xbuses(char *page, char **start, off_t off, int count, int *eof, void *data)
 {
 	int len = 0;
-	unsigned long flags;
 	int i;
 
-	spin_lock_irqsave(&xbuses_lock, flags);
 	for(i = 0; i < MAX_BUSES; i++) {
-		xbus_t *xbus = xbus_num(i);
+		xbus_t *xbus = get_xbus(__func__, i);
 
 		if(xbus) {
 			len += sprintf(page + len, "%s: CONNECTOR=%s LABEL=[%s] STATUS=%s\n",
@@ -1855,12 +1862,12 @@
 					xbus->label,
 					(XBUS_FLAGS(xbus, CONNECTED)) ? "connected" : "missing"
 				      );
+			put_xbus(__func__, xbus);
 		}
 	}
 #if 0
 	len += sprintf(page + len, "<-- len=%d\n", len);
 #endif
-	spin_unlock_irqrestore(&xbuses_lock, flags);
 	if (len <= off+count)
 		*eof = 1;
 	*start = page + off;

Modified: linux/trunk/drivers/dahdi/xpp/xbus-core.h
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-core.h?view=diff&rev=8913&r1=8912&r2=8913
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-core.h (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-core.h Tue Jul 13 14:38:13 2010
@@ -158,10 +158,10 @@
 #define	FREE_SEND_XFRAME(xbus, xframe)	put_xframe(&(xbus)->send_pool, (xframe))
 #define	FREE_RECV_XFRAME(xbus, xframe)	put_xframe(&(xbus)->receive_pool, (xframe))
 
-xbus_t		*xbus_num(uint num);
-xbus_t		*get_xbus(const char *msg, xbus_t *xbus);
-void		put_xbus(const char *msg, xbus_t *xbus);
-int		refcount_xbus(xbus_t *xbus);
+xbus_t	*xbus_num(uint num);
+xbus_t	*get_xbus(const char *msg, uint num);
+void	put_xbus(const char *msg, xbus_t *xbus);
+int	refcount_xbus(xbus_t *xbus);
 
 /*
  * An xbus is a transport layer for Xorcom Protocol commands

Modified: linux/trunk/drivers/dahdi/xpp/xbus-pcm.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xbus-pcm.c?view=diff&rev=8913&r1=8912&r2=8913
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xbus-pcm.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xbus-pcm.c Tue Jul 13 14:38:13 2010
@@ -440,9 +440,9 @@
 
 	//DBG(SYNC, "%d\n", atomic_read(&xpp_tick_counter));
 	for(i = 0; i < MAX_BUSES; i++) {
-		xbus_t	*xbus = xbus_num(i);
-
-		if(!xbus)
+		xbus_t	*xbus = get_xbus(__func__, i);
+
+		if (xbus == NULL)
 			continue;
 		/*
 		 * Don't send to non self_ticking Astribanks:
@@ -459,6 +459,7 @@
 				CALL_PROTO(GLOBAL, RESET_SYNC_COUNTERS, xbus, NULL);
 			}
 		}
+		put_xbus(__func__, xbus);
 	}
 }
 
@@ -589,8 +590,8 @@
 	DBG(SYNC, "stop unwanted syncers\n");
 	/* Shut all down except the wanted sync master */
 	for(i = 0; i < MAX_BUSES; i++) {
-		xbus_t	*xbus = xbus_num(i);
-		if(!xbus)
+		xbus_t	*xbus = get_xbus(__func__, i);
+		if (xbus == NULL)
 			continue;
 		if(XBUS_FLAGS(xbus, CONNECTED) && xbus != new_syncer) {
 			if(xbus->self_ticking)
@@ -599,6 +600,7 @@
 			else
 				XBUS_DBG(SYNC, xbus, "Not self_ticking yet. Ignore\n");
 		}
+		put_xbus(__func__, xbus);
 	}
 }
 
@@ -612,9 +614,12 @@
 	unsigned long	flags;
 
 	spin_lock_irqsave(&elect_syncer_lock, flags);
+	DBG(SYNC, "%s: %s syncer=%s\n", __func__, msg,
+			(syncer) ? syncer->busname : "NULL");
 	for(i = 0; i < MAX_BUSES; i++) {
-		xbus_t	*xbus = xbus_num(i);
-		if(!xbus)
+		xbus_t	*xbus = get_xbus(__func__, i);
+
+		if (xbus == NULL)
 			continue;
 		if(XBUS_IS(xbus, READY)) {
 			if(!the_xbus)
@@ -638,6 +643,7 @@
 				}
 			}
 		}
+		put_xbus(__func__, xbus);
 	}
 	if(best_xpd) {
 		the_xbus = best_xpd->xbus;
@@ -1177,18 +1183,22 @@
 		update_sync_master(NULL, 1);
 	} else if(sscanf(buf, "SYNC=%d", &xbusno) == 1) {
 		DBG(SYNC, "SYNC=%d\n", xbusno);
-		if((xbus = xbus_num(xbusno)) == NULL) {
+		xbus = get_xbus(__func__, xbusno);
+		if (xbus == NULL) {
 			ERR("No bus %d exists\n", xbusno);
 			return -ENXIO;
 		}
 		update_sync_master(xbus, 0);
+		put_xbus(__func__, xbus);
 	} else if(sscanf(buf, "QUERY=%d", &xbusno) == 1) {
 		DBG(SYNC, "QUERY=%d\n", xbusno);
-		if((xbus = xbus_num(xbusno)) == NULL) {
+		xbus = get_xbus(__func__, xbusno);
+		if (xbus == NULL) {
 			ERR("No bus %d exists\n", xbusno);
 			return -ENXIO;
 		}
 		CALL_PROTO(GLOBAL, SYNC_SOURCE, xbus, NULL, SYNC_MODE_QUERY, 0);
+		put_xbus(__func__, xbus);
 	} else {
 		ERR("%s: cannot parse '%s'\n", __FUNCTION__, buf);
 		ret = -EINVAL;

Modified: linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c
URL: http://svnview.digium.com/svn/dahdi/linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c?view=diff&rev=8913&r1=8912&r2=8913
==============================================================================
--- linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c (original)
+++ linux/trunk/drivers/dahdi/xpp/xpp_dahdi.c Tue Jul 13 14:38:13 2010
@@ -571,8 +571,8 @@
 	 * This makes sure the xbus cannot be removed before this xpd
 	 * is removed in xpd_free()
 	 */
-	xbus = get_xbus(__FUNCTION__, xbus);	/* returned in xpd_free() */
-	xproto_get(type);			/* will be returned in xpd_free() */
+	xbus = get_xbus(__func__, xbus->num);	/* returned in xpd_free() */
+	xproto_get(type);		/* will be returned in xpd_free() */
 	return xpd;
 err:
 	if(xpd) {




More information about the svn-commits mailing list