Index: squid/src/fs/aufs/aiops.c diff -c squid/src/fs/aufs/aiops.c:1.12.2.9 squid/src/fs/aufs/aiops.c:1.12.2.10 *** squid/src/fs/aufs/aiops.c:1.12.2.9 Fri Mar 18 17:01:52 2005 --- squid/src/fs/aufs/aiops.c Sat Mar 19 16:02:29 2005 *************** *** 120,126 **** unsigned long requests; }; - static void squidaio_init(void); static void squidaio_queue_request(squidaio_request_t *); static void squidaio_cleanup_request(squidaio_request_t *); static void *squidaio_thread_loop(void *); --- 120,125 ---- *************** *** 255,261 **** commSetSelect(fd, COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); } ! static void squidaio_init(void) { int i; --- 254,260 ---- commSetSelect(fd, COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); } ! void squidaio_init(void) { int i; *************** *** 307,314 **** pipe(done_pipe); done_fd = done_pipe[1]; done_fd_read = done_pipe[0]; ! fd_open(done_pipe[0], FD_PIPE, "async-io completetion event: main"); ! fd_open(done_pipe[1], FD_PIPE, "async-io completetion event: threads"); commSetNonBlocking(done_pipe[0]); commSetNonBlocking(done_pipe[1]); commSetSelect(done_pipe[0], COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); --- 306,313 ---- pipe(done_pipe); done_fd = done_pipe[1]; done_fd_read = done_pipe[0]; ! fd_open(done_fd_read, FD_PIPE, "async-io completion event: main"); ! fd_open(done_fd, FD_PIPE, "async-io completion event: threads"); commSetNonBlocking(done_pipe[0]); commSetNonBlocking(done_pipe[1]); commSetSelect(done_pipe[0], COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); *************** *** 351,356 **** --- 350,372 ---- squidaio_initialised = 1; } + void + squidaio_shutdown(void) + { + if (!squidaio_initialised) + return; + + /* This is the same as in squidaio_sync */ + do { + squidaio_poll_queues(); + } while (request_queue_len> 0); + + close(done_fd); + close(done_fd_read); + fd_close(done_fd); + fd_close(done_fd_read); + } + static void * squidaio_thread_loop(void *ptr) *************** *** 606,613 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->oflag = oflag; --- 622,627 ---- *************** *** 634,641 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; requestp->bufferp = bufp; --- 648,653 ---- *************** *** 665,672 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; requestp->bufferp = bufp; --- 677,682 ---- *************** *** 695,702 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; requestp->resultp = resultp; --- 705,710 ---- *************** *** 721,728 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->statp = sb; --- 729,734 ---- *************** *** 749,756 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = squidaio_xstrdup(path); requestp->resultp = resultp; --- 755,760 ---- *************** *** 774,781 **** { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->offset = length; --- 778,783 ---- *************** *** 805,812 **** squidaio_request_t *requestp; int len; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); return -1; } --- 807,812 ---- Index: squid/src/fs/aufs/async_io.c diff -c squid/src/fs/aufs/async_io.c:1.10.2.5 squid/src/fs/aufs/async_io.c:1.10.2.6 *** squid/src/fs/aufs/async_io.c:1.10.2.5 Fri Jan 3 18:19:42 2003 --- squid/src/fs/aufs/async_io.c Sat Mar 19 16:02:29 2005 *************** *** 103,108 **** --- 103,109 ---- void aioDone(void) { + squidaio_shutdown(); memPoolDestroy(squidaio_ctrl_pool); initialised = 0; } Index: squid/src/fs/aufs/store_asyncufs.h diff -c squid/src/fs/aufs/store_asyncufs.h:1.9.2.3 squid/src/fs/aufs/store_asyncufs.h:1.9.2.4 *** squid/src/fs/aufs/store_asyncufs.h:1.9.2.3 Fri Mar 18 17:01:52 2005 --- squid/src/fs/aufs/store_asyncufs.h Sat Mar 19 16:02:29 2005 *************** *** 41,46 **** --- 41,48 ---- typedef void AIOCB(int fd, void *cbdata, const char *buf, int aio_return, int aio_errno); + void squidaio_init(void); + void squidaio_shutdown(void); int squidaio_cancel(squidaio_result_t *); int squidaio_open(const char *, int, mode_t, squidaio_result_t *); int squidaio_read(int, char *, int, off_t, int, squidaio_result_t *); Index: squid/src/fs/aufs/store_dir_aufs.c diff -c squid/src/fs/aufs/store_dir_aufs.c:1.40.2.9 squid/src/fs/aufs/store_dir_aufs.c:1.40.2.11 *** squid/src/fs/aufs/store_dir_aufs.c:1.40.2.9 Wed Aug 25 15:07:25 2004 --- squid/src/fs/aufs/store_dir_aufs.c Sat Mar 19 16:43:10 2005 *************** *** 111,117 **** static QS rev_int_sort; static int storeAufsDirClean(int swap_index); static EVH storeAufsDirCleanEvent; - static int storeAufsDirIs(SwapDir * sd); static int storeAufsFilenoBelongsHere(int fn, int F0, int F1, int F2); static int storeAufsCleanupDoubleCheck(SwapDir *, StoreEntry *); static void storeAufsDirStats(SwapDir *, StoreEntry *); --- 111,116 ---- *************** *** 331,340 **** } debug(50, 3) ("Cache Dir #%d log opened on FD %d\n", sd->index, fd); aioinfo->swaplog_fd = fd; - if (0 == n_asyncufs_dirs) - assert(NULL == asyncufs_dir_index); - n_asyncufs_dirs++; - assert(n_asyncufs_dirs <= Config.cacheSwap.n_configured); } static void --- 330,335 ---- *************** *** 347,356 **** debug(47, 3) ("Cache Dir #%d log closed on FD %d\n", sd->index, aioinfo->swaplog_fd); aioinfo->swaplog_fd = -1; - n_asyncufs_dirs--; - assert(n_asyncufs_dirs>= 0); - if (0 == n_asyncufs_dirs) - safe_free(asyncufs_dir_index); } static void --- 342,347 ---- *************** *** 364,369 **** --- 355,361 ---- storeAufsDirInitBitmap(sd); if (storeAufsDirVerifyCacheDirs(sd) < 0) fatal(errmsg); + squidaio_init(); storeAufsDirOpenSwapLog(sd); storeAufsDirRebuild(sd); if (!started_clean_event) { *************** *** 1227,1281 **** static void storeAufsDirCleanEvent(void *unused) { ! static int swap_index = 0; ! int i; int j = 0; int n = 0; /* * Assert that there are AUFS cache_dirs configured, otherwise * we should never be called. */ ! assert(n_asyncufs_dirs); ! if (NULL == asyncufs_dir_index) { SwapDir *sd; squidaioinfo_t *aioinfo; /* - * Initialize the little array that translates AUFS cache_dir - * number into the Config.cacheSwap.swapDirs array index. - */ - asyncufs_dir_index = xcalloc(n_asyncufs_dirs, sizeof(*asyncufs_dir_index)); - for (i = 0, n = 0; i < Config.cacheSwap.n_configured; i++) { - sd = &Config.cacheSwap.swapDirs[i]; - if (!storeAufsDirIs(sd)) - continue; - asyncufs_dir_index[n++] = i; - aioinfo = (squidaioinfo_t *) sd->fsdata; - j += (aioinfo->l1 * aioinfo->l2); - } - assert(n == n_asyncufs_dirs); - /* * Start the storeAufsDirClean() swap_index with a random * value. j equals the total number of AUFS level 2 * swap directories */ swap_index = (int) (squid_random() % j); } if (0 == store_dirs_rebuilding) { n = storeAufsDirClean(swap_index); swap_index++; } eventAdd("storeDirClean", storeAufsDirCleanEvent, NULL, 15.0 * exp(-0.25 * n), 1); } - static int - storeAufsDirIs(SwapDir * sd) - { - if (strncmp(sd->type, "aufs", 4) == 0) - return 1; - return 0; - } - /* * Does swapfile number 'fn' belong in cachedir #F0, * level1 dir #F1, level2 dir #F2? --- 1219,1256 ---- static void storeAufsDirCleanEvent(void *unused) { ! static int swap_index = -1; int j = 0; int n = 0; /* * Assert that there are AUFS cache_dirs configured, otherwise * we should never be called. */ ! if (swap_index == -1) { SwapDir *sd; squidaioinfo_t *aioinfo; /* * Start the storeAufsDirClean() swap_index with a random * value. j equals the total number of AUFS level 2 * swap directories */ + for (n = 0; n < n_asyncufs_dirs; n++) { + sd = &Config.cacheSwap.swapDirs[asyncufs_dir_index[n]]; + aioinfo = (squidaioinfo_t *) sd->fsdata; + j += (aioinfo->l1 * aioinfo->l2); + } swap_index = (int) (squid_random() % j); } if (0 == store_dirs_rebuilding) { n = storeAufsDirClean(swap_index); swap_index++; + if (swap_index < 0) + swap_index = 0; } eventAdd("storeDirClean", storeAufsDirCleanEvent, NULL, 15.0 * exp(-0.25 * n), 1); } /* * Does swapfile number 'fn' belong in cachedir #F0, * level1 dir #F1, level2 dir #F2? *************** *** 1689,1694 **** --- 1664,1672 ---- /* Initialise replacement policy stuff */ sd->repl = createRemovalPolicy(Config.replPolicy); + + asyncufs_dir_index = realloc(asyncufs_dir_index, (n_asyncufs_dirs + 1) * sizeof(*asyncufs_dir_index)); + asyncufs_dir_index[n_asyncufs_dirs++] = index; } /* Index: squid/src/main.c diff -c squid/src/main.c:1.345.2.21 squid/src/main.c:1.345.2.22 *** squid/src/main.c:1.345.2.21 Sat Mar 19 15:46:28 2005 --- squid/src/main.c Sat Mar 19 16:56:23 2005 *************** *** 988,995 **** fwdUninit(); #endif storeDirSync(); /* Flush log close */ - #if PURIFY || XMALLOC_TRACE storeFsDone(); configFreeMemory(); storeFreeMemory(); /*stmemFreeMemory(); */ --- 988,995 ---- fwdUninit(); #endif storeDirSync(); /* Flush log close */ storeFsDone(); + #if PURIFY || XMALLOC_TRACE configFreeMemory(); storeFreeMemory(); /*stmemFreeMemory(); */