--------------------- PatchSet 10331 Date: 2007/12/28 04:05:37 Author: adri Branch: s27_adri Tag: (none) Log: Flesh out a couple of macros to access the memnode references. The logic here is that I'll be pulling a bait-and-switch on the stmem pages in a sec - turning the whole thing into buf_t's rather than const char * buffers, and I'd like to not need to change the users of the code (that) much. Members: src/asn.c:1.22.10.1.4.1->1.22.10.1.4.2 src/client_side.c:1.202.2.9.4.22->1.202.2.9.4.23 src/defines.h:1.43.8.2->1.43.8.3 src/errormap.c:1.4.12.1.4.2->1.4.12.1.4.3 src/net_db.c:1.26.2.1.4.2->1.26.2.1.4.3 src/peer_digest.c:1.21.10.2.4.6->1.21.10.2.4.7 src/peer_monitor.c:1.6.2.1.4.1->1.6.2.1.4.2 src/store.c:1.49.4.3.4.8->1.49.4.3.4.9 src/store_update.c:1.2.4.3.4.6->1.2.4.3.4.7 src/urn.c:1.24.6.2.4.6->1.24.6.2.4.7 Index: squid/src/asn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/asn.c,v retrieving revision 1.22.10.1.4.1 retrieving revision 1.22.10.1.4.2 diff -u -r1.22.10.1.4.1 -r1.22.10.1.4.2 --- squid/src/asn.c 14 Dec 2007 13:07:12 -0000 1.22.10.1.4.1 +++ squid/src/asn.c 28 Dec 2007 04:05:37 -0000 1.22.10.1.4.2 @@ -1,6 +1,6 @@ /* - * $Id: asn.c,v 1.22.10.1.4.1 2007/12/14 13:07:12 adri Exp $ + * $Id: asn.c,v 1.22.10.1.4.2 2007/12/28 04:05:37 adri Exp $ * * DEBUG: section 53 AS Number handling * AUTHOR: Duane Wessels, Kostas Anagnostakis @@ -230,6 +230,7 @@ char *s; char *t; LOCAL_ARRAY(char, buf, SM_PAGE_SIZE); + assert(size <= MEMREF_LEN(nr)); debug(53, 3) ("asHandleReply: Called with size=%ld\n", (long int) size); if (EBIT_TEST(e->flags, ENTRY_ABORTED)) { @@ -253,8 +254,8 @@ asStateFree(asState); return; } - assert((nr.offset + size) < SM_PAGE_SIZE); - memcpy(buf, nr.node->data + nr.offset, size); + assert(size < SM_PAGE_SIZE); + memcpy(buf, MEMREF_BUF(nr), size); stmemNodeUnref(&nr); s = buf; Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.202.2.9.4.22 retrieving revision 1.202.2.9.4.23 diff -u -r1.202.2.9.4.22 -r1.202.2.9.4.23 --- squid/src/client_side.c 27 Dec 2007 14:25:57 -0000 1.202.2.9.4.22 +++ squid/src/client_side.c 28 Dec 2007 04:05:37 -0000 1.202.2.9.4.23 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.202.2.9.4.22 2007/12/27 14:25:57 adri Exp $ + * $Id: client_side.c,v 1.202.2.9.4.23 2007/12/28 04:05:37 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -3060,15 +3060,18 @@ stmemNodeUnref(&ref); return; } - assert(ref.node->data); - buf = ref.node->data + ref.offset; + assert(! MEMREF_ISNULL(ref)); + assert(MEMREF_LEN(ref) <= size); + buf = MEMREF_BUF(ref); if (!http->request->range && !http->request->flags.chunked_response) { /* Avoid copying to MemBuf for non-range requests */ http->out.offset += size; /* XXX eww - these refcounting semantics should be better adrian! fix it! */ http->nr = ref; + stmemNodeRef(&http->nr); comm_write(fd, buf, size, clientWriteBodyComplete, http, NULL); /* NULL because clientWriteBodyComplete frees it */ + stmemNodeUnref(&ref); return; } if (http->request->method == METHOD_HEAD) { Index: squid/src/defines.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/defines.h,v retrieving revision 1.43.8.2 retrieving revision 1.43.8.3 diff -u -r1.43.8.2 -r1.43.8.3 --- squid/src/defines.h 6 Dec 2007 06:34:40 -0000 1.43.8.2 +++ squid/src/defines.h 28 Dec 2007 04:05:40 -0000 1.43.8.3 @@ -1,6 +1,6 @@ /* - * $Id: defines.h,v 1.43.8.2 2007/12/06 06:34:40 adri Exp $ + * $Id: defines.h,v 1.43.8.3 2007/12/28 04:05:40 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -356,4 +356,8 @@ #define LOGFILE_SEQNO(n) ( (n)->sequence_number ) +#define MEMREF_BUF(r) ( (r).node->data + (r).offset ) +#define MEMREF_LEN(r) ( (r).node->len - (r).offset ) +#define MEMREF_ISNULL(r) ( (r).node == NULL ) + #endif /* SQUID_DEFINES_H */ Index: squid/src/errormap.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errormap.c,v retrieving revision 1.4.12.1.4.2 retrieving revision 1.4.12.1.4.3 diff -u -r1.4.12.1.4.2 -r1.4.12.1.4.3 --- squid/src/errormap.c 20 Dec 2007 03:22:37 -0000 1.4.12.1.4.2 +++ squid/src/errormap.c 28 Dec 2007 04:05:40 -0000 1.4.12.1.4.3 @@ -121,7 +121,8 @@ if (!cbdataValid(state->callback_data)) goto abort; - buf = nr.node->data + nr.offset; + assert(size <= MEMREF_LEN(nr)); + buf = MEMREF_BUF(nr); if ((hdr_size = headersEnd(buf, size))) { http_status status; Index: squid/src/net_db.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/net_db.c,v retrieving revision 1.26.2.1.4.2 retrieving revision 1.26.2.1.4.3 diff -u -r1.26.2.1.4.2 -r1.26.2.1.4.3 --- squid/src/net_db.c 22 Dec 2007 14:32:13 -0000 1.26.2.1.4.2 +++ squid/src/net_db.c 28 Dec 2007 04:05:40 -0000 1.26.2.1.4.3 @@ -1,6 +1,6 @@ /* - * $Id: net_db.c,v 1.26.2.1.4.2 2007/12/22 14:32:13 adri Exp $ + * $Id: net_db.c,v 1.26.2.1.4.3 2007/12/28 04:05:40 adri Exp $ * * DEBUG: section 38 Network Measurement Database * AUTHOR: Duane Wessels @@ -530,7 +530,7 @@ static void netdbExchangeHandleReply(void *data, mem_node_ref nr, ssize_t size) { - const char *buf = nr.node->data + nr.offset; + const char *buf = NULL; netdbExchangeState *ex = data; int rec_sz = 0; ssize_t o; @@ -542,7 +542,10 @@ HttpReply *rep; size_t hdr_sz; int nused = 0; - assert(size <= nr.node->len - nr.offset); + + /* XXX need to handle EOF / empty returns here */ + buf = MEMREF_BUF(nr); + assert(nr->size <= MEMREF_LEN(nr)); rec_sz = 0; rec_sz += 1 + sizeof(addr.s_addr); Index: squid/src/peer_digest.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_digest.c,v retrieving revision 1.21.10.2.4.6 retrieving revision 1.21.10.2.4.7 diff -u -r1.21.10.2.4.6 -r1.21.10.2.4.7 --- squid/src/peer_digest.c 22 Dec 2007 14:32:13 -0000 1.21.10.2.4.6 +++ squid/src/peer_digest.c 28 Dec 2007 04:05:41 -0000 1.21.10.2.4.7 @@ -1,6 +1,6 @@ /* - * $Id: peer_digest.c,v 1.21.10.2.4.6 2007/12/22 14:32:13 adri Exp $ + * $Id: peer_digest.c,v 1.21.10.2.4.7 2007/12/28 04:05:41 adri Exp $ * * DEBUG: section 72 Peer Digest Routines * AUTHOR: Alex Rousskov @@ -341,13 +341,16 @@ static void peerDigestFetchReply(void *data, mem_node_ref nr, ssize_t size) { - const char *buf = nr.node->data + nr.offset; + const char *buf; DigestFetchState *fetch = data; PeerDigest *pd = fetch->pd; size_t hdr_size; assert(pd && buf); assert(!fetch->offset); - assert(size <= nr.node->len - nr.offset); + assert(size <= MEMREF_LEN(nr)); + + /* XXX should really check for size == 0 and the existance of a node first! */ + buf = MEMREF_BUF(nr); if (peerDigestFetchedEnough(fetch, buf, size, "peerDigestFetchReply")) goto finish; @@ -418,10 +421,10 @@ peerDigestSwapInHeaders(void *data, mem_node_ref nr, ssize_t size) { - const char *buf = nr.node->data + nr.offset; + const char *buf = MEMREF_BUF(nr); DigestFetchState *fetch = data; size_t hdr_size; - assert(size <= nr.node->len - nr.offset); + assert(size <= MEMREF_LEN(nr)); if (peerDigestFetchedEnough(fetch, buf, size, "peerDigestSwapInHeaders")) goto finish; @@ -455,9 +458,9 @@ static void peerDigestSwapInCBlock(void *data, mem_node_ref nr, ssize_t size) { - const char *buf = nr.node->data + nr.offset; + const char *buf = MEMREF_BUF(nr); DigestFetchState *fetch = data; - assert(size <= nr.node->len - nr.offset); + assert(size <= MEMREF_LEN(nr)); if (peerDigestFetchedEnough(fetch, buf, size, "peerDigestSwapInCBlock")) goto finish; @@ -496,10 +499,10 @@ static void peerDigestSwapInMask(void *data, mem_node_ref nr, ssize_t size) { - const char *buf = nr.node->data + nr.offset; + const char *buf = MEMREF_BUF(nr); DigestFetchState *fetch = data; PeerDigest *pd; - assert(size <= nr.node->len - nr.offset); + assert(size <= MEMREF_LEN(nr)); /* XXX this used to be before peerDigestFetchedEnough() was called.. */ pd = fetch->pd; Index: squid/src/peer_monitor.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/peer_monitor.c,v retrieving revision 1.6.2.1.4.1 retrieving revision 1.6.2.1.4.2 diff -u -r1.6.2.1.4.1 -r1.6.2.1.4.2 --- squid/src/peer_monitor.c 14 Dec 2007 13:07:16 -0000 1.6.2.1.4.1 +++ squid/src/peer_monitor.c 28 Dec 2007 04:05:41 -0000 1.6.2.1.4.2 @@ -1,6 +1,6 @@ /* - * $Id: peer_monitor.c,v 1.6.2.1.4.1 2007/12/14 13:07:16 adri Exp $ + * $Id: peer_monitor.c,v 1.6.2.1.4.2 2007/12/28 04:05:41 adri Exp $ * * DEBUG: section ?? Peer monitoring * AUTHOR: Henrik Nordstrom @@ -80,7 +80,7 @@ pm->running.offset += size; storeClientRef(pm->running.sc, pm->running.e, pm->running.offset, pm->running.offset, SM_PAGE_SIZE, peerMonitorFetchReply, pm); } - stmemNodeFree(&nr); + stmemNodeUnref(&nr); } static void @@ -97,7 +97,8 @@ if (!cbdataValid(pm->peer)) goto completed; - buf = nr.node->data + nr.offset; + assert(size <= MEMREF_LEN(nr)); + buf = MEMREF_BUF(nr); if ((hdr_size = headersEnd(buf, size))) { http_status status; Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.49.4.3.4.8 retrieving revision 1.49.4.3.4.9 diff -u -r1.49.4.3.4.8 -r1.49.4.3.4.9 --- squid/src/store.c 22 Dec 2007 14:32:13 -0000 1.49.4.3.4.8 +++ squid/src/store.c 28 Dec 2007 04:05:41 -0000 1.49.4.3.4.9 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.49.4.3.4.8 2007/12/22 14:32:13 adri Exp $ + * $Id: store.c,v 1.49.4.3.4.9 2007/12/28 04:05:41 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -555,7 +555,8 @@ size_t l = size + state->buf_offset; char *e; char *p = state->buf; - const char *buf = nr.node->data + nr.offset; + const char *buf = MEMREF_BUF(nr); + assert(size <= MEMREF_LEN(nr)); debug(11, 3) ("storeAddVaryReadOld: %p seen_offset=%" PRINTF_OFF_T " buf_offset=%d size=%d\n", data, state->seen_offset, (int) state->buf_offset, (int) size); if (size <= 0) { @@ -564,11 +565,11 @@ cbdataFree(state); goto finish; } - assert(size <= nr.node->len); + assert(size <= MEMREF_LEN(nr)); /* size should never exceed what we asked for; just make sure first */ assert(size + state->buf_offset <= state->buf_size); /* Copy in the data before we do anything else */ - memcpy(state->buf + state->buf_offset, nr.node->data + nr.offset, size); + memcpy(state->buf + state->buf_offset, MEMREF_BUF(nr), size); if (EBIT_TEST(state->e->flags, ENTRY_ABORTED)) { debug(11, 1) ("storeAddVaryReadOld: New index aborted at %d (%d)\n", (int) state->seen_offset, (int) size); @@ -866,17 +867,17 @@ char *e; char *p = state->buf; size_t l = size + state->buf_offset; - const char *buf = nr.node->data; debug(11, 3) ("storeLocateVaryRead: %s %p seen_offset=%" PRINTF_OFF_T " buf_offset=%d size=%d\n", state->vary_data, data, state->seen_offset, (int) state->buf_offset, (int) size); if (size <= 0) { storeLocateVaryCallback(state); goto finish; } - assert(size <= nr.node->len); + assert(size <= MEMREF_LEN(nr)); /* size should never exceed what we asked for; just make sure first */ assert(size + state->buf_offset <= state->buf_size); /* Copy in the data before we do anything else */ - memcpy(state->buf + state->buf_offset, nr.node->data + nr.offset, size); + if (size > 0) + memcpy(state->buf + state->buf_offset, MEMREF_BUF(nr), size); state->seen_offset = state->seen_offset + size; while ((e = memchr(p, '\n', l)) != NULL) { @@ -941,7 +942,7 @@ if (l == 0) break; assert(l > 0); - assert(p < (buf + size)); + assert(p < (state->buf + size)); } state->buf_offset = l; if (l) @@ -967,7 +968,6 @@ state); finish: stmemNodeUnref(&nr); - buf = 0; } void Index: squid/src/store_update.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_update.c,v retrieving revision 1.2.4.3.4.6 retrieving revision 1.2.4.3.4.7 diff -u -r1.2.4.3.4.6 -r1.2.4.3.4.7 --- squid/src/store_update.c 22 Dec 2007 15:11:32 -0000 1.2.4.3.4.6 +++ squid/src/store_update.c 28 Dec 2007 04:05:41 -0000 1.2.4.3.4.7 @@ -1,6 +1,6 @@ /* - * $Id: store_update.c,v 1.2.4.3.4.6 2007/12/22 15:11:32 adri Exp $ + * $Id: store_update.c,v 1.2.4.3.4.7 2007/12/28 04:05:41 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Henrik Nordstrom @@ -107,8 +107,8 @@ goto finish; } if (size > 0) { - assert(size <= nr.node->len - nr.offset); - buf = nr.node->data + nr.offset; + assert(size <= MEMREF_LEN(nr)); + buf = MEMREF_BUF(nr); storeAppend(state->newentry, buf, size); if (EBIT_TEST(state->newentry->flags, ENTRY_ABORTED)) { debug(20, 1) ("storeUpdateCopy: Aborted on write at %d (%d)\n", (int) state->offset, (int) size); Index: squid/src/urn.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/urn.c,v retrieving revision 1.24.6.2.4.6 retrieving revision 1.24.6.2.4.7 diff -u -r1.24.6.2.4.6 -r1.24.6.2.4.7 --- squid/src/urn.c 22 Dec 2007 14:32:13 -0000 1.24.6.2.4.6 +++ squid/src/urn.c 28 Dec 2007 04:05:41 -0000 1.24.6.2.4.7 @@ -1,6 +1,6 @@ /* - * $Id: urn.c,v 1.24.6.2.4.6 2007/12/22 14:32:13 adri Exp $ + * $Id: urn.c,v 1.24.6.2.4.7 2007/12/28 04:05:41 adri Exp $ * * DEBUG: section 52 URN Parsing * AUTHOR: Kostas Anagnostakis @@ -200,7 +200,8 @@ stmemNodeUnref(&nr); return; } - buf = nr.node->data + nr.offset; + assert(size <= MEMREF_LEN(nr)); + buf = MEMREF_BUF(nr); if (urlres_e->store_status == STORE_PENDING && size < SM_PAGE_SIZE) { stmemNodeUnref(&nr); storeClientRef(urnState->sc, urlres_e,