kern/80031: [Patch] Remove insque/remque from kernel land
Erik Greenwald
erik at smluc.org
Sun Apr 17 09:00:43 PDT 2005
>Number: 80031
>Category: kern
>Synopsis: [Patch] Remove insque/remque from kernel land
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sun Apr 17 16:00:42 GMT 2005
>Closed-Date:
>Last-Modified:
>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 at 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:
>Unformatted:
More information about the freebsd-bugs
mailing list