--------------------- PatchSet 6532 Date: 2005/03/20 10:24:26 Author: serassio Branch: nt-2_5 Tag: (none) Log: Updated awin32 code with latest aufs changes Members: src/fs/awin32/aiops.c:1.1.62.16->1.1.62.17 src/fs/awin32/async_io.c:1.1.62.6->1.1.62.7 src/fs/awin32/store_asyncufs.h:1.1.62.7->1.1.62.8 src/fs/awin32/store_dir_aufs.c:1.1.62.16->1.1.62.17 src/fs/awin32/store_io_aufs.c:1.1.62.16->1.1.62.17 Index: squid/src/fs/awin32/aiops.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/aiops.c,v retrieving revision 1.1.62.16 retrieving revision 1.1.62.17 diff -u -r1.1.62.16 -r1.1.62.17 --- squid/src/fs/awin32/aiops.c 24 Jul 2004 12:50:27 -0000 1.1.62.16 +++ squid/src/fs/awin32/aiops.c 20 Mar 2005 10:24:26 -0000 1.1.62.17 @@ -1,5 +1,5 @@ /* - * $Id: aiops.c,v 1.1.62.16 2004/07/24 12:50:27 serassio Exp $ + * $Id: aiops.c,v 1.1.62.17 2005/03/20 10:24:26 serassio Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -85,7 +85,6 @@ mode_t mode; int fd; char *bufferp; - char *tmpbufp; int buflen; off_t offset; int whence; @@ -116,18 +115,6 @@ int volatile exit; }; -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 *); -int squidaio_write(int, char *, int, off_t, int, squidaio_result_t *); -int squidaio_close(int, squidaio_result_t *); -int squidaio_unlink(const char *, squidaio_result_t *); -int squidaio_truncate(const char *, off_t length, squidaio_result_t *); -int squidaio_opendir(const char *, squidaio_result_t *); -squidaio_result_t *squidaio_poll_done(); -int squidaio_sync(void); - -static void squidaio_init(void); static void squidaio_queue_request(squidaio_request_t *); static void squidaio_cleanup_request(squidaio_request_t *); static DWORD WINAPI squidaio_thread_loop( LPVOID lpParam ); @@ -261,7 +248,7 @@ commSetSelect(fd, COMM_SELECT_READ, squidaio_fdhandler, NULL, 0); } -static void +void squidaio_init(void) { int i; @@ -323,8 +310,8 @@ 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"); + 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); @@ -385,6 +372,11 @@ if (!squidaio_initialised) return; + /* This is the same as in squidaio_sync */ + do { + squidaio_poll_queues(); + } while (request_queue_len > 0); + hthreads = (HANDLE *) xcalloc (squidaio_nthreads, sizeof (HANDLE)); threadp = threads; for (i = 0; i < squidaio_nthreads; i++) { @@ -403,8 +395,12 @@ CloseHandle(hthreads[i]); } CloseHandle(main_thread); - squidaio_initialised = 0; xfree(hthreads); + + close(done_fd); + close(done_fd_read); + fd_close(done_fd); + fd_close(done_fd_read); } static DWORD WINAPI @@ -664,7 +660,6 @@ case _AIO_OP_READ: break; case _AIO_OP_WRITE: - squidaio_xfree(requestp->tmpbufp, requestp->buflen); break; default: break; @@ -699,8 +694,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->oflag = oflag; @@ -727,8 +720,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; requestp->bufferp = bufp; @@ -766,12 +757,9 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; - requestp->tmpbufp = (char *) squidaio_xmalloc(bufs); - xmemcpy(requestp->tmpbufp, bufp, bufs); + requestp->bufferp = bufp; requestp->buflen = bufs; requestp->offset = offset; requestp->whence = whence; @@ -788,13 +776,13 @@ squidaio_do_write(squidaio_request_t * requestp) { #ifdef _SQUID_MSWIN_ - if (!WriteFile((HANDLE)_get_osfhandle(requestp->fd), requestp->tmpbufp, + if (!WriteFile((HANDLE)_get_osfhandle(requestp->fd), requestp->bufferp, requestp->buflen, (LPDWORD)&requestp->ret, NULL)) { WIN32_maperror(GetLastError()); requestp->ret = -1; } #else - requestp->ret = write(requestp->fd, requestp->tmpbufp, requestp->buflen); + requestp->ret = write(requestp->fd, requestp->bufferp, requestp->buflen); #endif requestp->err = errno; } @@ -805,8 +793,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->fd = fd; requestp->resultp = resultp; @@ -834,8 +820,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->statp = sb; @@ -862,8 +846,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = squidaio_xstrdup(path); requestp->resultp = resultp; @@ -887,8 +869,6 @@ { squidaio_request_t *requestp; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); requestp->path = (char *) squidaio_xstrdup(path); requestp->offset = length; @@ -918,8 +898,6 @@ squidaio_request_t *requestp; int len; - if (!squidaio_initialised) - squidaio_init(); requestp = memPoolAlloc(squidaio_request_pool); return -1; } @@ -949,10 +927,6 @@ request_queue2.tailp = &request_queue2.head; } /* Give up the CPU to allow the threads to do their work */ - /* - * For Andres thoughts about yield(), see - * http://www.squid-cache.org/mail-archive/squid-dev/200012/0001.html - */ if (done_queue.head || request_queue.head) Sleep(0); /* poll done queue */ @@ -1070,9 +1044,6 @@ squidaio_thread_t *threadp; int i; - if (!squidaio_initialised) - return; - storeAppendPrintf(sentry, "\n\nThreads Status:\n"); storeAppendPrintf(sentry, "#\tID\t# Requests\n"); Index: squid/src/fs/awin32/async_io.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/async_io.c,v retrieving revision 1.1.62.6 retrieving revision 1.1.62.7 diff -u -r1.1.62.6 -r1.1.62.7 --- squid/src/fs/awin32/async_io.c 20 Jun 2004 20:28:48 -0000 1.1.62.6 +++ squid/src/fs/awin32/async_io.c 20 Mar 2005 10:24:27 -0000 1.1.62.7 @@ -1,6 +1,6 @@ /* - * $Id: async_io.c,v 1.1.62.6 2004/06/20 20:28:48 serassio Exp $ + * $Id: async_io.c,v 1.1.62.7 2005/03/20 10:24:27 serassio Exp $ * * DEBUG: section 32 Asynchronous Disk I/O * AUTHOR: Pete Bentley @@ -103,8 +103,6 @@ void aioDone(void) { - if (!initialised) - return; squidaio_shutdown(); memPoolDestroy(squidaio_ctrl_pool); initialised = 0; Index: squid/src/fs/awin32/store_asyncufs.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_asyncufs.h,v retrieving revision 1.1.62.7 retrieving revision 1.1.62.8 diff -u -r1.1.62.7 -r1.1.62.8 --- squid/src/fs/awin32/store_asyncufs.h 7 Aug 2003 07:56:07 -0000 1.1.62.7 +++ squid/src/fs/awin32/store_asyncufs.h 20 Mar 2005 10:24:27 -0000 1.1.62.8 @@ -41,6 +41,8 @@ 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 *); @@ -56,7 +58,6 @@ int squidaio_get_queue_len(void); void *squidaio_xmalloc(int size); void squidaio_xfree(void *p, int size); -void squidaio_shutdown(void); void squidaio_stats(StoreEntry *); void aioInit(void); @@ -88,8 +89,9 @@ unsigned int reading:1; unsigned int writing:1; unsigned int opening:1; +#if !ASYNC_WRITE unsigned int write_kicking:1; - unsigned int read_kicking:1; +#endif unsigned int inreaddone:1; } flags; char *read_buf; Index: squid/src/fs/awin32/store_dir_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_dir_aufs.c,v retrieving revision 1.1.62.16 retrieving revision 1.1.62.17 diff -u -r1.1.62.16 -r1.1.62.17 --- squid/src/fs/awin32/store_dir_aufs.c 28 Aug 2004 10:30:47 -0000 1.1.62.16 +++ squid/src/fs/awin32/store_dir_aufs.c 20 Mar 2005 10:24:27 -0000 1.1.62.17 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.c,v 1.1.62.16 2004/08/28 10:30:47 serassio Exp $ + * $Id: store_dir_aufs.c,v 1.1.62.17 2005/03/20 10:24:27 serassio Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -111,7 +111,6 @@ 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 *); @@ -335,10 +334,6 @@ } 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 @@ -351,10 +346,6 @@ 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 @@ -368,6 +359,7 @@ storeAufsDirInitBitmap(sd); if (storeAufsDirVerifyCacheDirs(sd) < 0) fatal(errmsg); + squidaio_init(); storeAufsDirOpenSwapLog(sd); storeAufsDirRebuild(sd); if (!started_clean_event) { @@ -1223,55 +1215,38 @@ static void storeAufsDirCleanEvent(void *unused) { - static int swap_index = 0; - int i; + 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. */ - assert(n_asyncufs_dirs); - if (NULL == asyncufs_dir_index) { + if (swap_index == -1) { 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 */ + 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); } -static int -storeAufsDirIs(SwapDir * sd) -{ - if (strncmp(sd->type, "awin32", 6) == 0) - return 1; - return 0; -} - /* * Does swapfile number 'fn' belong in cachedir #F0, * level1 dir #F1, level2 dir #F2? @@ -1685,6 +1660,9 @@ /* 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/fs/awin32/store_io_aufs.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/fs/awin32/Attic/store_io_aufs.c,v retrieving revision 1.1.62.16 retrieving revision 1.1.62.17 diff -u -r1.1.62.16 -r1.1.62.17 --- squid/src/fs/awin32/store_io_aufs.c 12 Jun 2004 09:54:30 -0000 1.1.62.16 +++ squid/src/fs/awin32/store_io_aufs.c 20 Mar 2005 10:24:28 -0000 1.1.62.17 @@ -1,6 +1,6 @@ /* - * $Id: store_io_aufs.c,v 1.1.62.16 2004/06/12 09:54:30 serassio Exp $ + * $Id: store_io_aufs.c,v 1.1.62.17 2005/03/20 10:24:28 serassio Exp $ * * DEBUG: section 79 Storage Manager awin32 Interface * AUTHOR: Robert Collins @@ -423,18 +423,29 @@ } sio->offset += len; #if ASYNC_WRITE - if (!storeAufsKickWriteQueue(sio)) + if (storeAufsKickWriteQueue(sio)) (void) 0; else if (aiostate->flags.close_request) storeAufsIOCallback(sio, errflag); #else + /* loop around storeAufsKickWriteQueue to break recursion stack + * overflow when large amounts of data has been queued for write. + * As writes are blocking here we immediately get called again + * without going via the I/O event loop.. + */ if (!aiostate->flags.write_kicking) { + /* cbdataLock to protect us from the storeAufsIOCallback on error above */ + cbdataLock(sio); aiostate->flags.write_kicking = 1; while (storeAufsKickWriteQueue(sio)) - (void) 0; - aiostate->flags.write_kicking = 0; - if (aiostate->flags.close_request) - storeAufsIOCallback(sio, errflag); + if (!cbdataValid(sio)) + break; + if (cbdataValid(sio)) { + aiostate->flags.write_kicking = 0; + if (aiostate->flags.close_request) + storeAufsIOCallback(sio, errflag); + } + cbdataUnlock(sio); } #endif loop_detect--; @@ -463,8 +474,13 @@ if (fd < 0) return; debug(79, 9) ("%s:%d\n", __FILE__, __LINE__); +#if ASYNC_CLOSE aioClose(fd); fd_close(fd); +#else + aioCancel(fd); + file_close(fd); +#endif store_open_disk_fd--; statCounter.syscalls.disk.closes++; debug(79, 9) ("%s:%d\n", __FILE__, __LINE__);