--------------------- PatchSet 965 Date: 2000/12/19 15:27:28 Author: adri Branch: modio Tag: (none) Log: * Move the store client list into StoreEntry as a single client * Enforce a single client per StoreEntry * change around the clientcopy code in reply_internal.c The next task is to remove all the references to store_client and replace them with StoreEntry. store_client will become part of the StoreEntry. This won't be difficult, it'll just be longwinded .. Members: src/errorpage.c:1.2.2.5->1.2.2.6 src/reply_internal.c:1.1.2.2->1.1.2.3 src/stat.c:1.2.2.3->1.2.2.4 src/store.c:1.2.2.7->1.2.2.8 src/store_client.c:1.2.2.5->1.2.2.6 src/structs.h:1.2.2.6->1.2.2.7 src/typedefs.h:1.2.2.2->1.2.2.3 Index: squid/src/errorpage.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/errorpage.c,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -r1.2.2.5 -r1.2.2.6 --- squid/src/errorpage.c 16 Dec 2000 09:42:13 -0000 1.2.2.5 +++ squid/src/errorpage.c 19 Dec 2000 15:27:28 -0000 1.2.2.6 @@ -1,6 +1,6 @@ /* - * $Id: errorpage.c,v 1.2.2.5 2000/12/16 09:42:13 adri Exp $ + * $Id: errorpage.c,v 1.2.2.6 2000/12/19 15:27:28 adri Exp $ * * DEBUG: section 4 Error Generation * AUTHOR: Duane Wessels @@ -271,7 +271,7 @@ * error message */ assert(EBIT_TEST(entry->flags, ENTRY_ABORTED)); - assert(mem->nclients == 0); + assert(storePendingNClients(entry) == 0); errorStateFree(err); return; } Index: squid/src/reply_internal.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/reply_internal.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/reply_internal.c 19 Dec 2000 12:53:04 -0000 1.1.2.2 +++ squid/src/reply_internal.c 19 Dec 2000 15:27:28 -0000 1.1.2.3 @@ -22,8 +22,8 @@ MemPool *reply_internal_state_pool = NULL; /* Prototypes */ -static void reply_internal_clientcopy2(StoreEntry * e, store_client * sc); -static void reply_internal_clientcopy3(StoreEntry * e, store_client * sc); +static void reply_internal_clientcopy(StoreEntry * e); +static void reply_internal_clientcopy3(StoreEntry * e); @@ -109,26 +109,15 @@ static void reply_internal_flush(StoreEntry *e) { - int i = 0; - MemObject *mem = e->mem_obj; - store_client *sc; - dlink_node *nx = NULL; - dlink_node *node; - debug(20, 3) ("reply_internal_flush: %s\n", storeKeyText(e->hash.key)); /* walk the entire list looking for valid callbacks */ - for (node = mem->clients.head; node; node = nx) { - sc = node->data; - nx = node->next; - debug(20, 3) ("reply_internal_flush: checking client #%d\n", i++); - if (sc->callback_data == NULL) - continue; - if (sc->callback == NULL) - continue; - if (sc->flags.disk_io_pending) - continue; - reply_internal_clientcopy2(e, sc); - } + if (e->sc.callback_data == NULL) + return; + if (e->sc.callback == NULL) + return; + if (e->sc.flags.disk_io_pending) + return; + reply_internal_clientcopy3(e); } @@ -149,47 +138,14 @@ static void reply_internal_clientcopyevent(void *data) { - store_client *sc = data; + StoreEntry *e = data; debug(20, 3) ("reply_internal_clientcopyevent: Running\n"); - sc->flags.copy_event_pending = 0; - if (!sc->callback) + e->sc.flags.copy_event_pending = 0; + if (!e->sc.valid) return; - reply_internal_clientcopy2(sc->entry, sc); + reply_internal_clientcopy3(e); } -/* copy bytes requested by the client */ -static void -reply_internal_clientcopy(store_client * sc, - StoreEntry * e, - off_t seen_offset, - off_t copy_offset, - size_t size, - char *buf, - STCB * callback, - void *data) -{ - assert(!EBIT_TEST(e->flags, ENTRY_ABORTED)); - debug(20, 3) ("reply_internal_clientcopy: %s, seen %d, want %d, size %d, cb %p, cbdata %p\n", - storeKeyText(e->hash.key), - (int) seen_offset, - (int) copy_offset, - (int) size, - callback, - data); - assert(sc != NULL); -#if STORE_CLIENT_LIST_DEBUG - assert(sc == storeClientListSearch(e->mem_obj, data)); -#endif - assert(sc->callback == NULL); - assert(sc->entry == e); - sc->copy_offset = copy_offset; - sc->seen_offset = seen_offset; - sc->callback = callback; - sc->copy_buf = buf; - sc->copy_size = size; - sc->copy_offset = copy_offset; - reply_internal_clientcopy2(e, sc); -} /* * This function is used below to decide if we have any more data to @@ -210,24 +166,16 @@ return 1; } +/* copy bytes requested by the client */ static void -reply_internal_clientcopy2(StoreEntry * e, store_client * sc) +reply_internal_clientcopy(StoreEntry * e) { - if (sc->flags.copy_event_pending) - return; + store_client *sc = &e->sc; if (EBIT_TEST(e->flags, ENTRY_FWD_HDR_WAIT)) { - debug(20, 5) ("reply_internal_clientcopy2: returning because ENTRY_FWD_HDR_WAIT set\n"); + debug(20, 5) ("reply_internal_clientcopy: returning because ENTRY_FWD_HDR_WAIT set\n"); return; } - if (sc->flags.store_copying) { - sc->flags.copy_event_pending = 1; - debug(20, 3) ("reply_internal_clientcopy2: Queueing reply_internal_clientcopyevent()\n"); - eventAdd("reply_internal_clientcopyevent", reply_internal_clientcopyevent, sc, 0.0, 0); - return; - } - cbdataLock(sc); /* ick, prevent sc from getting freed */ - sc->flags.store_copying = 1; - debug(20, 3) ("reply_internal_clientcopy2: %s\n", storeKeyText(e->hash.key)); + debug(20, 3) ("reply_internal_clientcopy: %s\n", storeKeyText(e->hash.key)); assert(sc->callback != NULL); /* * We used to check for ENTRY_ABORTED here. But there were some @@ -236,27 +184,27 @@ * if the server-side aborts, we want to give the client(s) * everything we got before the abort condition occurred. */ - reply_internal_clientcopy3(e, sc); - sc->flags.store_copying = 0; - cbdataUnlock(sc); /* ick, allow sc to be freed */ + reply_internal_clientcopy3(e); } static void -reply_internal_clientcopy3(StoreEntry * e, store_client * sc) +reply_internal_clientcopy3(StoreEntry * e) { + store_client *sc = &e->sc; reply_internal_state_t *state = e->stdata; size_t sz; + sc->flags.store_copying = 1; if (reply_internal_clientnomoretosend(e, sc)) { /* There is no more to send! */ reply_internal_clientcallback(sc, 0); - return; + goto finish; } if ((e->store_status == STORE_PENDING) && (sc->seen_offset >= state->inmem_hi)) { /* client has already seen this, wait for more */ debug(20, 3) ("reply_internal_clientcopy3: Waiting for more\n"); - return; + goto finish; } if ((sc->copy_offset >= state->inmem_lo) && @@ -266,10 +214,13 @@ sz = stmemCopy(&state->data_hdr, sc->copy_offset, sc->copy_buf, sc->copy_size); reply_internal_clientcallback(sc, sz); - return; + goto finish; } /* We shouldn't ever get here! */ assert(1 == 0); + +finish: + sc->flags.store_copying = 0; } Index: squid/src/stat.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/stat.c,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -r1.2.2.3 -r1.2.2.4 --- squid/src/stat.c 18 Dec 2000 22:14:49 -0000 1.2.2.3 +++ squid/src/stat.c 19 Dec 2000 15:27:28 -0000 1.2.2.4 @@ -1,6 +1,6 @@ /* - * $Id: stat.c,v 1.2.2.3 2000/12/18 22:14:49 adri Exp $ + * $Id: stat.c,v 1.2.2.4 2000/12/19 15:27:28 adri Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -258,7 +258,6 @@ MemObject *mem = e->mem_obj; int i; struct _store_client *sc; - dlink_node *node; storeAppendPrintf(s, "KEY %s\n", storeKeyText(e->hash.key)); if (mem) storeAppendPrintf(s, "\t%s %s\n", @@ -275,10 +274,9 @@ if (mem != NULL) { storeAppendPrintf(s, "\tInMem_LoOffset: %d\n", (int) storeMemLoOffset(e)); storeAppendPrintf(s, "\tInMem_HiOffset: %d\n", (int) storeMemHiOffset(e)); - for (i = 0, node = mem->clients.head; node; node = node->next, i++) { - sc = (store_client *) node->data; - if (sc->callback_data == NULL) - continue; + + sc = &e->sc; + if (sc->valid) { storeAppendPrintf(s, "\tClient #%d, %p\n", i, sc->callback_data); storeAppendPrintf(s, "\t\tcopy_offset: %d\n", (int) sc->copy_offset); Index: squid/src/store.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store.c,v retrieving revision 1.2.2.7 retrieving revision 1.2.2.8 diff -u -r1.2.2.7 -r1.2.2.8 --- squid/src/store.c 19 Dec 2000 12:53:04 -0000 1.2.2.7 +++ squid/src/store.c 19 Dec 2000 15:27:28 -0000 1.2.2.8 @@ -1,6 +1,6 @@ /* - * $Id: store.c,v 1.2.2.7 2000/12/19 12:53:04 adri Exp $ + * $Id: store.c,v 1.2.2.8 2000/12/19 15:27:28 adri Exp $ * * DEBUG: section 20 Storage Manager * AUTHOR: Harvest Derived @@ -159,7 +159,7 @@ * There is no way to abort FD-less clients, so they might * still have mem->clients set if mem->fd == -1 */ - assert(mem->fd == -1 || mem->clients.head == NULL); + assert(mem->fd == -1 || e->sc.valid == 0); httpReplyDestroy(mem->reply); requestUnlink(mem->request); mem->request = NULL; @@ -624,7 +624,7 @@ * and there should be NO clients on this entry */ assert(EBIT_TEST(e->flags, ENTRY_ABORTED)); - assert(e->mem_obj->nclients == 0); + assert(e->sc.valid == 0); return; } e->mem_obj->object_sz = storeMemHiOffset(e); @@ -996,10 +996,6 @@ debug(20, 1) ("MemObject->start_ping: %d.%06d\n", (int) mem->start_ping.tv_sec, (int) mem->start_ping.tv_usec); - debug(20, 1) ("MemObject->clients: %p\n", - mem->clients); - debug(20, 1) ("MemObject->nclients: %d\n", - mem->nclients); debug(20, 1) ("MemObject->reply: %p\n", mem->reply); debug(20, 1) ("MemObject->request: %p\n", Index: squid/src/store_client.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/store_client.c,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -r1.2.2.5 -r1.2.2.6 --- squid/src/store_client.c 19 Dec 2000 12:53:04 -0000 1.2.2.5 +++ squid/src/store_client.c 19 Dec 2000 15:27:28 -0000 1.2.2.6 @@ -1,6 +1,6 @@ /* - * $Id: store_client.c,v 1.2.2.5 2000/12/19 12:53:04 adri Exp $ + * $Id: store_client.c,v 1.2.2.6 2000/12/19 15:27:28 adri Exp $ * * DEBUG: section 20 Storage Manager Client-Side Interface * AUTHOR: Duane Wessels @@ -40,9 +40,11 @@ * 'Body' refers to the swapfile body, which is the full * HTTP reply (including HTTP headers and body). */ +#if 0 static STRCB storeClientReadBody; static STRCB storeClientReadHeader; static void storeClientFileRead(store_client * sc); +#endif static int CheckQuickAbort2(StoreEntry * entry); static void CheckQuickAbort(StoreEntry * entry); @@ -51,59 +53,33 @@ int storeClientWaiting(const StoreEntry * e) { - MemObject *mem = e->mem_obj; - dlink_node *node; - store_client *sc; - for (node = mem->clients.head; node; node = node->next) { - sc = node->data; - if (sc->callback_data != NULL) + if (e->sc.callback_data != NULL) return 1; - } return 0; } -#if STORE_CLIENT_LIST_DEBUG -store_client * -storeClientListSearch(const MemObject * mem, void *data) -{ - dlink_node *node; - store_client *sc = NULL; - for (node = mem->clients.head; node; node = node->next) { - sc = node->data; - if (sc->callback_data == data) - return sc; - } - return NULL; -} -#endif /* add client with fd to client list */ store_client * storeClientListAdd(StoreEntry * e, void *data) { - MemObject *mem = e->mem_obj; - store_client *sc; - assert(mem); -#if STORE_CLIENT_LIST_DEBUG - if (storeClientListSearch(mem, data) != NULL) - assert(1 == 0); /* XXX die! */ -#endif e->refcount++; - assert(mem->nclients == 0); - mem->nclients++; - sc = memAllocate(MEM_STORE_CLIENT); - cbdataAdd(sc, memFree, MEM_STORE_CLIENT); /* sc is callback_data for file_read */ - cbdataLock(data); /* locked while we point to it */ - sc->callback_data = data; - sc->seen_offset = 0; - sc->copy_offset = 0; - sc->flags.disk_io_pending = 0; - sc->entry = e; - dlinkAdd(sc, &sc->node, &mem->clients); + + assert(e->sc.valid == 0); + e->sc.valid = 1; + e->sc.callback_data = data; + e->sc.seen_offset = 0; + e->sc.copy_offset = 0; + e->sc.flags.disk_io_pending = 0; + e->sc.entry = e; + + /* Lock the data that we're using .. */ + cbdataLock(data); + #if DELAY_POOLS - sc->delay_id = 0; + e->sc.delay_id = 0; #endif - return sc; + return &e->sc; } static void @@ -131,17 +107,32 @@ { assert(!EBIT_TEST(e->flags, ENTRY_ABORTED)); assert(sc != NULL); - e->stclientcopy(sc, e, seen_offset, copy_offset, size, buf, - callback, data); + + assert(!EBIT_TEST(e->flags, ENTRY_ABORTED)); + assert(sc == &e->sc); + debug(20, 3) ("storeClientCopy: %s, seen %d, want %d, size %d, cb %p, cbdata %p\n", storeKeyText(e->hash.key), + (int) seen_offset, + (int) copy_offset, + (int) size, + callback, + data); + + assert(sc->callback == NULL); + assert(sc->entry == e); + sc->copy_offset = copy_offset; + sc->seen_offset = seen_offset; + sc->callback = callback; + sc->copy_buf = buf; + sc->copy_size = size; + sc->copy_offset = copy_offset; + + e->stclientcopy(e); } int storeClientCopyPending(store_client * sc, StoreEntry * e, void *data) { -#if STORE_CLIENT_LIST_DEBUG - assert(sc == storeClientListSearch(e->mem_obj, data)); -#endif assert(sc->entry == e); if (sc == NULL) return 0; @@ -151,6 +142,7 @@ } +#if 0 static void storeClientFileRead(store_client * sc) { @@ -297,41 +289,29 @@ storeClientFileRead(sc); } +#endif + /* - * This routine hasn't been optimised to take advantage of the - * passed sc. Yet. + * Disassociate a client from a storeentry */ int storeUnregister(store_client * sc, StoreEntry * e, void *data) { MemObject *mem = e->mem_obj; -#if STORE_CLIENT_LIST_DEBUG - assert(sc == storeClientListSearch(e->mem_obj, data)); -#endif - if (mem == NULL) - return 0; + debug(20, 3) ("storeUnregister: called for '%s'\n", storeKeyText(e->hash.key)); + if (sc == NULL) return 0; - if (mem->clients.head == NULL) - return 0; - if (sc == mem->clients.head->data) { - /* - * If we are unregistering the _first_ client for this - * entry, then we have to reset the client FD to -1. - */ - mem->fd = -1; - } - dlinkDelete(&sc->node, &mem->clients); - mem->nclients--; - assert(mem->nclients == 0); - if (sc->swapin_sio) { - storeClose(sc->swapin_sio); - cbdataUnlock(sc->swapin_sio); - sc->swapin_sio = NULL; - statCounter.swap.ins++; - } + + assert(sc == &e->sc); + assert(mem != NULL); + assert(e->sc.valid == 1); + e->sc.valid = 0; + + mem->fd = -1; + if (NULL != sc->callback) { /* callback with ssize = -1 to indicate unexpected termination */ debug(20, 3) ("storeUnregister: store_client for %s has a callback\n", @@ -342,37 +322,17 @@ delayUnregisterDelayIdPtr(&sc->delay_id); #endif cbdataUnlock(sc->callback_data); /* we're done with it now */ - /*assert(!sc->flags.disk_io_pending); */ - cbdataFree(sc); assert(e->lock_count > 0); - if (mem->nclients == 0) - CheckQuickAbort(e); + CheckQuickAbort(e); return 1; } + +/* .. and this routine becomes meaningless.. :) */ off_t storeLowestMemReaderOffset(const StoreEntry * entry) { - const MemObject *mem = entry->mem_obj; - off_t lowest = storeMemHiOffset(entry) + 1; - store_client *sc; - dlink_node *nx = NULL; - dlink_node *node; - - for (node = mem->clients.head; node; node = nx) { - sc = node->data; - nx = node->next; - if (sc->callback_data == NULL) /* open slot */ - continue; - if (sc->type != STORE_MEM_CLIENT) - continue; - if (sc->type == STORE_DISK_CLIENT) - if (NULL != sc->swapin_sio) - continue; - if (sc->copy_offset < lowest) - lowest = sc->copy_offset; - } - return lowest; + return entry->sc.copy_offset; } /* Call handlers waiting for data to be appended to E. */ @@ -387,8 +347,9 @@ int storePendingNClients(const StoreEntry * e) { - MemObject *mem = e->mem_obj; - int npend = NULL == mem ? 0 : mem->nclients; + int npend = 0; + if (e->sc.valid) + npend = 1; debug(20, 3) ("storePendingNClients: returning %d\n", npend); return npend; } Index: squid/src/structs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/structs.h,v retrieving revision 1.2.2.6 retrieving revision 1.2.2.7 diff -u -r1.2.2.6 -r1.2.2.7 --- squid/src/structs.h 19 Dec 2000 12:53:04 -0000 1.2.2.6 +++ squid/src/structs.h 19 Dec 2000 15:27:29 -0000 1.2.2.7 @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.2.2.6 2000/12/19 12:53:04 adri Exp $ + * $Id: structs.h,v 1.2.2.7 2000/12/19 15:27:29 adri Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1228,6 +1228,7 @@ /* keep track each client receiving data from that particular StoreEntry */ struct _store_client { + int valid; int type; off_t copy_offset; off_t seen_offset; @@ -1286,8 +1287,6 @@ struct _MemObject { method_t method; char *url; - dlink_list clients; - int nclients; HttpReply *reply; request_t *request; struct timeval start_ping; @@ -1327,6 +1326,9 @@ store_status_t store_status:3; swap_status_t swap_status:3; + /* The request callback information */ + store_client sc; + /* The reply callback functions */ STRAPPEND *stappend; STRFLUSH *stflush; Index: squid/src/typedefs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/typedefs.h,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -r1.2.2.2 -r1.2.2.3 --- squid/src/typedefs.h 18 Dec 2000 19:10:58 -0000 1.2.2.2 +++ squid/src/typedefs.h 19 Dec 2000 15:27:29 -0000 1.2.2.3 @@ -1,6 +1,6 @@ /* - * $Id: typedefs.h,v 1.2.2.2 2000/12/18 19:10:58 adri Exp $ + * $Id: typedefs.h,v 1.2.2.3 2000/12/19 15:27:29 adri Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -275,8 +275,7 @@ typedef void STRFLUSH(StoreEntry *); typedef off_t STRMEMHI(const StoreEntry *); typedef off_t STRMEMLO(const StoreEntry *); -typedef void STRCLIENTCOPY(store_client *, StoreEntry *, off_t, off_t, - size_t, char *, STCB *, void *); +typedef void STRCLIENTCOPY(StoreEntry *); typedef void STRDONE(StoreEntry *); typedef double hbase_f(double);