From erik@smluc.org  Sun Apr 17 15:54:48 2005
Return-Path: <erik@smluc.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B6AEC16A4CF
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 17 Apr 2005 15:54:48 +0000 (GMT)
Received: from phoenix.smluc.org (phoenix.smluc.org [12.28.48.23])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 9F63543D58
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 17 Apr 2005 15:54:47 +0000 (GMT)
	(envelope-from erik@smluc.org)
Received: by phoenix.smluc.org (Postfix, from userid 1000)
	id 330AA1CE81; Sun, 17 Apr 2005 10:56:13 -0500 (CDT)
Message-Id: <20050417155613.330AA1CE81@phoenix.smluc.org>
Date: Sun, 17 Apr 2005 10:56:13 -0500 (CDT)
From: Erik Greenwald <erik@smluc.org>
Reply-To: Erik Greenwald <erik@smluc.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc: erik@math.smsu.edu
Subject: [Patch]  Remove insque/remque from kernel land
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         80031
>Category:       kern
>Synopsis:       [coda] [patch] Remove insque/remque from kernel land
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    rwatson
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 17 16:00:42 GMT 2005
>Closed-Date:    Sun Aug 03 16:15:32 UTC 2008
>Last-Modified:  Sun Aug 03 16:15:32 UTC 2008
>Originator:     Erik Greenwald
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
>Environment:
System: FreeBSD vidar.br0kenland.org 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Tue Apr 12 12:31:49 EDT 2005 erik@vidar.br0kenland.org:/usr/src/sys/i386/compile/VIDAR i386

>Description:

Remove insque and remque from the kernel...

The last remaining use was in 'coda', so I c&p'd the stuff in and 
prefixed it with coda_, then removed it from sys/queue.h

(testing has been very very light on this, as I'm not a real coda
user... if any coda/current users can put this through the ringer,
that'd be highly appreciated... thanks)

>How-To-Repeat:
>Fix:

--- coda.patch begins here ---
Index: sys/coda/coda_namecache.c
===================================================================
RCS file: /home/ncvs/src/sys/coda/coda_namecache.c,v
retrieving revision 1.21
diff -u -r1.21 coda_namecache.c
--- sys/coda/coda_namecache.c	5 Jan 2005 23:35:00 -0000	1.21
+++ sys/coda/coda_namecache.c	17 Apr 2005 15:42:21 -0000
@@ -129,6 +129,42 @@
 
 int coda_nc_initialized = 0;      /* Initially the cache has not been initialized */
 
+struct coda_quehead {
+        struct coda_quehead *qh_link;
+        struct coda_quehead *qh_rlink;
+};
+
+static void
+coda_insque(void *a, void *b)
+{
+        struct coda_quehead *element = (struct coda_quehead *)a,
+                 *head = (struct coda_quehead *)b;
+
+        element->qh_link = head->qh_link;
+        element->qh_rlink = head;
+        head->qh_link = element;
+        element->qh_link->qh_rlink = element;
+}
+
+static void
+coda_remque(void *a)
+{
+        struct coda_quehead *element = (struct coda_quehead *)a;
+
+        element->qh_link->qh_rlink = element->qh_rlink;
+        element->qh_rlink->qh_link = element->qh_link;
+        element->qh_rlink = 0;
+}
+
+#define CODA_NC_VALID(cncp)     (cncp->dcp != (struct cnode *)0)
+#define LRU_PART(cncp)                  (struct coda_cache *) ((char *)cncp + (2*sizeof(struct coda_cache *)))
+#define LRU_TOP(cncp)                           (struct coda_cache *) ((char *)cncp - (2*sizeof(struct coda_cache *)))
+#define DATA_PART(cncp)                         (struct coda_cache *) ((char *)cncp + (4*sizeof(struct coda_cache *)))
+#define DATA_SIZE       (sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
+
+#define CODA_NC_LRUINS(elem, pred)      coda_insque(LRU_PART(elem), LRU_PART(pred))
+#define CODA_NC_LRUGET(lruhead)         LRU_TOP((lruhead).lru_prev)
+
 void
 coda_nc_init(void)
 {
@@ -150,12 +186,12 @@
     
     for (i=0; i < coda_nc_size; i++) {	/* initialize the heap */
 	CODA_NC_LRUINS(&coda_nc_heap[i], &coda_nc_lru);
-	CODA_NC_HSHNUL(&coda_nc_heap[i]);
+	coda_nc_heap[i].hash_next = coda_nc_heap[i].hash_prev = &coda_nc_heap[i];
 	coda_nc_heap[i].cp = coda_nc_heap[i].dcp = (struct cnode *)0;
     }
     
     for (i=0; i < coda_nc_hashsize; i++) {	/* initialize the hashtable */
-	CODA_NC_HSHNUL((struct coda_cache *)&coda_nc_hash[i]);
+	((struct coda_cache *)&coda_nc_hash[i])->hash_next = ((struct coda_cache *)&coda_nc_hash[i])->hash_prev = ((struct coda_cache *)&coda_nc_hash[i]);
     }
     
     coda_nc_initialized++;
@@ -251,9 +287,9 @@
     coda_nc_stat.enters++;		/* record the enters statistic */
     
     /* Grab the next element in the lru chain */
-    cncp = CODA_NC_LRUGET(coda_nc_lru);
-    
-    CODA_NC_LRUREM(cncp);	/* remove it from the lists */
+    cncp = LRU_TOP(coda_nc_lru.lru_prev);
+
+    coda_remque(LRU_PART(cncp));	/* remove it from the lists */
     
     if (CODA_NC_VALID(cncp)) {
 	/* Seems really ugly, but we have to decrement the appropriate
@@ -262,7 +298,7 @@
 	coda_nc_hash[CODA_NC_HASH(cncp->name, cncp->namelen, cncp->dcp)].length--;
 	
 	coda_nc_stat.lru_rm++;	/* zapped a valid entry */
-	CODA_NC_HSHREM(cncp);
+	coda_remque(cncp);
 	vrele(CTOV(cncp->dcp)); 
 	vrele(CTOV(cncp->cp));
 	crfree(cncp->cred);
@@ -283,7 +319,7 @@
     /* Insert into the lru and hash chains. */
     
     CODA_NC_LRUINS(cncp, &coda_nc_lru);
-    CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
+    coda_insque(cncp, &coda_nc_hash[hash]);
     coda_nc_hash[hash].length++;                      /* Used for tuning */
     
     CODA_NC_DEBUG(CODA_NC_PRINTCODA_NC, print_coda_nc(); )
@@ -328,13 +364,13 @@
 	coda_nc_stat.hits++;
 
 	/* put this entry at the end of the LRU */
-	CODA_NC_LRUREM(cncp);
+	coda_remque(LRU_PART(cncp));
 	CODA_NC_LRUINS(cncp, &coda_nc_lru);
 
 	/* move it to the front of the hash chain */
 	/* don't need to change the hash bucket length */
-	CODA_NC_HSHREM(cncp);
-	CODA_NC_HSHINS(cncp, &coda_nc_hash[hash]);
+	coda_remque(cncp);
+	coda_insque(cncp, &coda_nc_hash[hash]);
 
 	CODA_NC_DEBUG(CODA_NC_LOOKUP, 
 		printf("lookup: dcp %p, name %s, cred %p = cp %p\n",
@@ -356,9 +392,9 @@
         CODA_NC_DEBUG(CODA_NC_REMOVE,
 		    myprintf(("coda_nc_remove %s from parent %s\n",
 			      cncp->name, coda_f2s(&cncp->dcp->c_fid))); )	
-  	CODA_NC_HSHREM(cncp);
+  	coda_remque(cncp);
 
-	CODA_NC_HSHNUL(cncp);		/* have it be a null chain */
+	(cncp)->hash_next = (cncp)->hash_prev = (cncp);		/* have it be a null chain */
 	if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->dcp)) == 1)) {
 		cncp->dcp->c_flags |= C_PURGING;
 	}
@@ -374,7 +410,7 @@
 
 	/* Put the null entry just after the least-recently-used entry */
 	/* LRU_TOP adjusts the pointer to point to the top of the structure. */
-	CODA_NC_LRUREM(cncp);
+	coda_remque(LRU_PART(cncp));
 	CODA_NC_LRUINS(cncp, LRU_TOP(coda_nc_lru.lru_prev));
 }
 
@@ -598,8 +634,8 @@
 	     cncp = CODA_NC_LRUGET(*cncp)) {
 		if (CODA_NC_VALID(cncp)) {
 
-			CODA_NC_HSHREM(cncp);	/* only zero valid nodes */
-			CODA_NC_HSHNUL(cncp);
+			coda_remque(cncp);	/* only zero valid nodes */
+			cncp->hash_next = cncp->hash_prev = cncp;
 			if ((dcstat == IS_DOWNCALL) 
 			    && (vrefcnt(CTOV(cncp->dcp)) == 1))
 			{
Index: sys/coda/coda_namecache.h
===================================================================
RCS file: /home/ncvs/src/sys/coda/coda_namecache.h,v
retrieving revision 1.10
diff -u -r1.10 coda_namecache.h
--- sys/coda/coda_namecache.h	5 Jan 2005 23:35:00 -0000	1.10
+++ sys/coda/coda_namecache.h	17 Apr 2005 15:42:21 -0000
@@ -76,31 +76,6 @@
 		 (bcmp(cp->name,name,namelen) == 0))
 
 /*
- * Functions to modify the hash and lru chains.
- * insque and remque assume that the pointers are the first thing
- * in the list node, thus the trickery for lru.
- */
-
-#define CODA_NC_HSHINS(elem, pred)	insque(elem,pred)
-#define CODA_NC_HSHREM(elem)		remque(elem)
-#define CODA_NC_HSHNUL(elem)		(elem)->hash_next = \
-					(elem)->hash_prev = (elem)
-
-#define CODA_NC_LRUINS(elem, pred)	insque(LRU_PART(elem), LRU_PART(pred))
-#define CODA_NC_LRUREM(elem)		remque(LRU_PART(elem));
-#define CODA_NC_LRUGET(lruhead)		LRU_TOP((lruhead).lru_prev)
-
-#define CODA_NC_VALID(cncp)	(cncp->dcp != (struct cnode *)0)
- 
-#define LRU_PART(cncp)			(struct coda_cache *) \
-				((char *)cncp + (2*sizeof(struct coda_cache *)))
-#define LRU_TOP(cncp)				(struct coda_cache *) \
-			((char *)cncp - (2*sizeof(struct coda_cache *)))
-#define DATA_PART(cncp)				(struct coda_cache *) \
-			((char *)cncp + (4*sizeof(struct coda_cache *)))
-#define DATA_SIZE	(sizeof(struct coda_cache)-(4*sizeof(struct coda_cache *)))
-
-/*
  * Structure for an element in the CODA Name Cache.
  * NOTE: I use the position of arguments and their size in the
  * implementation of the functions CODA_NC_LRUINS, CODA_NC_LRUREM, and
Index: sys/sys/queue.h
===================================================================
RCS file: /home/ncvs/src/sys/sys/queue.h,v
retrieving revision 1.60
diff -u -r1.60 queue.h
--- sys/sys/queue.h	2 Mar 2005 21:33:29 -0000	1.60
+++ sys/sys/queue.h	17 Apr 2005 15:42:21 -0000
@@ -504,50 +504,4 @@
 	QMD_TRACE_ELEM(&(elm)->field);					\
 } while (0)
 
-
-#ifdef _KERNEL
-
-/*
- * XXX insque() and remque() are an old way of handling certain queues.
- * They bogusly assumes that all queue heads look alike.
- */
-
-struct quehead {
-	struct quehead *qh_link;
-	struct quehead *qh_rlink;
-};
-
-#ifdef __CC_SUPPORTS___INLINE
-
-static __inline void
-insque(void *a, void *b)
-{
-	struct quehead *element = (struct quehead *)a,
-		 *head = (struct quehead *)b;
-
-	element->qh_link = head->qh_link;
-	element->qh_rlink = head;
-	head->qh_link = element;
-	element->qh_link->qh_rlink = element;
-}
-
-static __inline void
-remque(void *a)
-{
-	struct quehead *element = (struct quehead *)a;
-
-	element->qh_link->qh_rlink = element->qh_rlink;
-	element->qh_rlink->qh_link = element->qh_link;
-	element->qh_rlink = 0;
-}
-
-#else /* !__CC_SUPPORTS___INLINE */
-
-void	insque(void *a, void *b);
-void	remque(void *a);
-
-#endif /* __CC_SUPPORTS___INLINE */
-
-#endif /* _KERNEL */
-
 #endif /* !_SYS_QUEUE_H_ */
--- coda.patch ends here ---


>Release-Note:
>Audit-Trail:

From: Jan Harkes <jaharkes@cs.cmu.edu>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/80031: [coda] [patch] Remove insque/remque from kernel land
Date: Tue, 17 Jul 2007 16:23:08 -0400

 I tested this patch on FreeBSD-CURRENT and have not encountered any
 problems when running a Coda client.
 
 btw. sys/coda was moved to sys/fs/coda so the patch needs some path
 mangling before it applies.
 
 Jan
Responsible-Changed-From-To: freebsd-bugs->rwatson 
Responsible-Changed-By: rodrigc 
Responsible-Changed-When: Tue Jul 17 20:37:51 UTC 2007 
Responsible-Changed-Why:  
Assign to rwatson, who has committed some coda stuff recently. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80031 
State-Changed-From-To: open->analyzed 
State-Changed-By: rwatson 
State-Changed-When: Sat Jan 19 18:39:14 UTC 2008 
State-Changed-Why:  
I think this change is a good idea, but I can't help but wonder if a 
better idea would be to update the Coda namecache to use queue(9) 
instead of maintaining its use of the old interfaces.  I'll 
investigate doing this in the near future sometime. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=80031 
State-Changed-From-To: analyzed->patched 
State-Changed-By: rwatson 
State-Changed-When: Sun Feb 17 14:34:15 UTC 2008 
State-Changed-Why:  
Status update: 

(1) I've removed the Coda name cache in FreeBSD, preferring the FreeBSD name 
cache, eliminating all use of insque and remque in Coda. 

(2) I've replaced the coda_kernel.h queue macros, used to manage the request 
and reply queue to venus, with queue(9) macros. 

The only remaining portion of your patch is the bit that removes insque and 
friends from queue.h.  Unfortunately, they are still used in netipx, so that 
will also need fixing before they can be entirely removed. 

I've set the state to patched and will close the PR when the change is MFC'd 
in a month. 

... If you have tested IPX patches floating around to remove use of insque/ 
remqueue from there, please submit them as a further PR and I'll grab 
ownership of it :-). 

Thanks! 


http://www.freebsd.org/cgi/query-pr.cgi?pr=80031 
State-Changed-From-To: patched->closed 
State-Changed-By: rwatson 
State-Changed-When: Sun Aug 3 16:14:38 UTC 2008 
State-Changed-Why:  
Changes to Coda to remove the custom namecache and use the system cache 
have been MFC'd.  Thanks for the submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=80031 
>Unformatted:
