---------------------
PatchSet 3310 
Date: 2006/06/17 16:51:47
Author: serassio
Branch: nt
Tag: (none) 
Log:
Sync WinDiskThreads with latest DiskThreads changes

Members: 
	src/DiskIO/DiskThreads/async_io.cc:1.1.2.2->1.1.2.3 
	src/DiskIO/WinDiskThreads/WinDiskThreads.h:1.1.2.1->1.1.2.2 
	src/DiskIO/WinDiskThreads/WinDiskThreadsDiskFile.cc:1.1.2.2->1.1.2.3 
	src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.cc:1.1.2.1->1.1.2.2 
	src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.h:1.1.2.1->1.1.2.2 
	src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.cc:1.1.2.5->1.1.2.6 
	src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.h:1.1.2.2->1.1.2.3 
	src/DiskIO/WinDiskThreads/aiops.cc:1.1.2.6->1.1.2.7 

Index: squid3/src/DiskIO/DiskThreads/async_io.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/DiskThreads/async_io.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- squid3/src/DiskIO/DiskThreads/async_io.cc	23 Jul 2005 10:28:28 -0000	1.1.2.2
+++ squid3/src/DiskIO/DiskThreads/async_io.cc	17 Jun 2006 16:51:47 -0000	1.1.2.3
@@ -1,6 +1,6 @@
 
 /*
- * $Id: async_io.cc,v 1.1.2.2 2005/07/23 10:28:28 serassio Exp $
+ * $Id: async_io.cc,v 1.1.2.3 2006/06/17 16:51:47 serassio Exp $
  *
  * DEBUG: section 32    Asynchronous Disk I/O
  * AUTHOR: Pete Bentley <pete@demon.net>
@@ -228,6 +228,7 @@
 }				/* aioTruncate */
 
 #else
+
 void
 aioUnlink(const char *path, AIOCB * callback, void *callback_data)
 {
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreads.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreads.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreads.h	1 Jan 2005 18:54:31 -0000	1.1.2.1
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreads.h	17 Jun 2006 16:51:47 -0000	1.1.2.2
@@ -64,6 +64,8 @@
     dlink_node node;
 };
 
+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 *);
@@ -80,7 +82,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);
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskFile.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreadsDiskFile.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskFile.cc	5 Jan 2005 22:08:04 -0000	1.1.2.2
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskFile.cc	17 Jun 2006 16:51:47 -0000	1.1.2.3
@@ -1,6 +1,6 @@
 
 /*
- * $Id: WinDiskThreadsDiskFile.cc,v 1.1.2.2 2005/01/05 22:08:04 serassio Exp $
+ * $Id: WinDiskThreadsDiskFile.cc,v 1.1.2.3 2006/06/17 16:51:47 serassio Exp $
  *
  * DEBUG: section 79    Disk IO Routines
  * AUTHOR: Robert Collins
@@ -51,6 +51,12 @@
 {
     CBDATA_INIT_TYPE(WinDiskThreadsDiskFile);
     WinDiskThreadsDiskFile *result = cbdataAlloc(WinDiskThreadsDiskFile);
+    /*
+     * We used to call squidaio_init() here, but if the first transaction
+     * is to unlink a file (e.g., if Squid starts up over the disk space
+     * limit) then "squidaio" won't be initialized yet.
+     */
+
     return result;
 }
 
@@ -188,19 +194,27 @@
         fd_open(fd, FD_FILE, path_);
     }
 
-    debug(79, 3) ("WinDiskThreadsDiskFile::openDone: exiting\n");
-
     IORequestor::Pointer t = ioRequestor;
     --inProgressIOs;
     t->ioCompletedNotification();
+
+    debug(79, 3) ("WinDiskThreadsDiskFile::openDone: exiting\n");
 }
 
 void WinDiskThreadsDiskFile::doClose()
 {
     if (fd > -1) {
         statCounter.syscalls.disk.closes++;
+#if ASYNC_CLOSE
+
         aioClose(fd);
         fd_close(fd);
+#else
+
+        aioCancel(fd);
+        file_close(fd);
+#endif
+
         store_open_disk_fd--;
         fd = -1;
     }
@@ -213,8 +227,12 @@
 
     if (!ioInProgress()) {
         doClose();
-        assert (ioRequestor.getRaw());
+        assert (ioRequestor != NULL);
         ioRequestor->closeCompleted();
+        return;
+    } else {
+        debugs(79,0,HERE << "WinDiskThreadsDiskFile::close: " <<
+               "did NOT close because ioInProgress() is true.  now what?");
     }
 }
 
@@ -309,7 +327,7 @@
 void
 WinDiskThreadsDiskFile::
 #if ASYNC_WRITE
-WriteDone(int fd, void *my_data, int len, int errflag)
+WriteDone(int fd, void *my_data, const char *buf, int len, int errflag)
 #else
 WriteDone(int fd, int errflag, size_t len, void *my_data)
 #endif
@@ -325,20 +343,20 @@
 {
     assert (rvfd == fd);
     static int loop_detect = 0;
-    debug(79, 3) ("WinDiskThreadsDiskFile::writeDone: FD %d, len %ld, err=%d\n",
-                  fd, (long int) len, errflag);
 
 #if ASYNC_WRITE
     /* Translate from errno to Squid disk error */
-    errno = errflag;
 
     if (errflag)
-        errflag = errno == ENOSPC ? DISK_NO_SPACE_LEFT : DISK_ERROR;
+        errflag = errflag == ENOSPC ? DISK_NO_SPACE_LEFT : DISK_ERROR;
     else
         errflag = DISK_OK;
 
 #endif
 
+    debug(79, 3) ("WinDiskThreadsDiskFile::writeDone: FD %d, len %ld, err=%d\n",
+                  fd, (long int) len, errflag);
+
     assert(++loop_detect < 10);
 
     --inProgressIOs;
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreadsDiskIOModule.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.cc	1 Jan 2005 18:54:31 -0000	1.1.2.1
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.cc	17 Jun 2006 16:51:47 -0000	1.1.2.2
@@ -1,6 +1,6 @@
 
 /*
- * $Id: WinDiskThreadsDiskIOModule.cc,v 1.1.2.1 2005/01/01 18:54:31 serassio Exp $
+ * $Id: WinDiskThreadsDiskIOModule.cc,v 1.1.2.2 2006/06/17 16:51:47 serassio Exp $
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
  * ----------------------------------------------------------
@@ -54,6 +54,12 @@
 }
 
 void
+WinDiskThreadsDiskIOModule::registerWithCacheManager(CacheManager & manager)
+{
+    WinDiskThreadsIOStrategy::Instance.registerWithCacheManager(manager);
+}
+
+void
 WinDiskThreadsDiskIOModule::shutdown()
 {
     WinDiskThreadsIOStrategy::Instance.done();
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreadsDiskIOModule.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.h	1 Jan 2005 18:54:31 -0000	1.1.2.1
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsDiskIOModule.h	17 Jun 2006 16:51:47 -0000	1.1.2.2
@@ -1,6 +1,6 @@
 
 /*
- * $Id: WinDiskThreadsDiskIOModule.h,v 1.1.2.1 2005/01/01 18:54:31 serassio Exp $
+ * $Id: WinDiskThreadsDiskIOModule.h,v 1.1.2.2 2006/06/17 16:51:47 serassio Exp $
  *
  * SQUID Web Proxy Cache          http://www.squid-cache.org/
  * ----------------------------------------------------------
@@ -43,6 +43,7 @@
     static WinDiskThreadsDiskIOModule &GetInstance();
     WinDiskThreadsDiskIOModule();
     virtual void init();
+    virtual void registerWithCacheManager(CacheManager & manager);
     virtual void shutdown();
     virtual char const *type () const;
     virtual DiskIOStrategy* createStrategy();
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreadsIOStrategy.cc,v
retrieving revision 1.1.2.5
retrieving revision 1.1.2.6
diff -u -r1.1.2.5 -r1.1.2.6
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.cc	17 Jun 2006 15:49:30 -0000	1.1.2.5
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.cc	17 Jun 2006 16:51:47 -0000	1.1.2.6
@@ -1,6 +1,6 @@
 
 /*
- * $Id: WinDiskThreadsIOStrategy.cc,v 1.1.2.5 2006/06/17 15:49:30 serassio Exp $
+ * $Id: WinDiskThreadsIOStrategy.cc,v 1.1.2.6 2006/06/17 16:51:47 serassio Exp $
  *
  * DEBUG: section 79    Squid-side Disk I/O functions.
  * AUTHOR: Robert Collins
@@ -54,6 +54,12 @@
     squidaio_ctrl_pool = new MemAllocatorProxy("aio_ctrl", sizeof(squidaio_ctrl_t));
 
     initialised = true;
+
+    /*
+     * We'd like to call squidaio_init() here, but the configuration
+     * hasn't been parsed yet and we don't know how many cache_dirs
+     * there are, which means we don't know how many threads to start.
+     */
 }
 
 void
@@ -98,6 +104,8 @@
 
         case _AIO_OP_NONE:
 
+        case _AIO_OP_TRUNCATE:
+
         case _AIO_OP_OPENDIR:
             break;
 
@@ -117,8 +125,6 @@
             ++squidaio_counts.close_finish;
             break;
 
-        case _AIO_OP_TRUNCATE:
-
         case _AIO_OP_UNLINK:
             ++squidaio_counts.unlink_finish;
             break;
@@ -161,9 +167,6 @@
         if (ctrlp->operation == _AIO_READ)
             squidaio_xfree(ctrlp->bufp, ctrlp->len);
 
-        if (ctrlp->operation == _AIO_CLOSE)
-            aioFDWasClosed(ctrlp->fd);
-
         squidaio_ctrl_pool->free(ctrlp);
     }
 
@@ -206,13 +209,6 @@
     squidaio_stats(sentry);
 }
 
-void
-WinDiskThreadsIOStrategy::aioFDWasClosed(int fd)
-{
-    if (fd_table[fd].flags.closing)
-        fd_close(fd);
-}
-
 WinDiskThreadsIOStrategy WinDiskThreadsIOStrategy::Instance;
 bool
 WinDiskThreadsIOStrategy::shedLoad()
Index: squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.h
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/WinDiskThreadsIOStrategy.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.h	17 Jun 2006 15:49:30 -0000	1.1.2.2
+++ squid3/src/DiskIO/WinDiskThreads/WinDiskThreadsIOStrategy.h	17 Jun 2006 16:51:48 -0000	1.1.2.3
@@ -1,6 +1,6 @@
 
 /*
- * $Id: WinDiskThreadsIOStrategy.h,v 1.1.2.2 2006/06/17 15:49:30 serassio Exp $
+ * $Id: WinDiskThreadsIOStrategy.h,v 1.1.2.3 2006/06/17 16:51:48 serassio Exp $
  *
  * DEBUG: section 79    Squid-side Disk I/O functions.
  * AUTHOR: Robert Collins
@@ -68,7 +68,6 @@
 
 private:
     static void aioStats(StoreEntry * sentry);
-    void aioFDWasClosed(int fd);
 };
 
 #endif
Index: squid3/src/DiskIO/WinDiskThreads/aiops.cc
===================================================================
RCS file: /cvsroot/squid-sf//squid3/src/DiskIO/WinDiskThreads/Attic/aiops.cc,v
retrieving revision 1.1.2.6
retrieving revision 1.1.2.7
diff -u -r1.1.2.6 -r1.1.2.7
--- squid3/src/DiskIO/WinDiskThreads/aiops.cc	14 May 2006 17:11:06 -0000	1.1.2.6
+++ squid3/src/DiskIO/WinDiskThreads/aiops.cc	17 Jun 2006 16:51:48 -0000	1.1.2.7
@@ -1,5 +1,5 @@
 /*
- * $Id: aiops.cc,v 1.1.2.6 2006/05/14 17:11:06 serassio Exp $
+ * $Id: aiops.cc,v 1.1.2.7 2006/06/17 16:51:48 serassio Exp $
  *
  * DEBUG: section 43    AIOPS
  * AUTHOR: Stewart Forster <slf@connect.com.au>
@@ -109,7 +109,6 @@
     int volatile exit;
 };
 
-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 );
@@ -244,7 +243,7 @@
         xfree(str);
 }
 
-static void
+void
 squidaio_init(void)
 {
     int i;
@@ -370,6 +369,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 (NUMTHREADS, sizeof (HANDLE));
 
     threadp = threads;
@@ -727,8 +731,6 @@
         break;
 
     case _AIO_OP_WRITE:
-        squidaio_xfree(requestp->tmpbufp, requestp->buflen);
-
         break;
 
     default:
@@ -766,11 +768,9 @@
 int
 squidaio_open(const char *path, int oflag, mode_t mode, squidaio_result_t * resultp)
 {
+    squidaio_init();
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->path = (char *) squidaio_xstrdup(path);
@@ -806,9 +806,6 @@
 {
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->fd = fd;
@@ -861,16 +858,11 @@
 {
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->fd = fd;
 
-    requestp->tmpbufp = (char *) squidaio_xmalloc(bufs);
-
-    xmemcpy(requestp->tmpbufp, bufp, bufs);
+    requestp->bufferp = bufp;
 
     requestp->buflen = bufs;
 
@@ -897,14 +889,14 @@
 {
 #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
 
@@ -917,9 +909,6 @@
 {
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->fd = fd;
@@ -954,11 +943,9 @@
 
 squidaio_stat(const char *path, struct stat *sb, squidaio_result_t * resultp)
 {
+    squidaio_init();
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->path = (char *) squidaio_xstrdup(path);
@@ -993,11 +980,9 @@
 int
 squidaio_truncate(const char *path, off_t length, squidaio_result_t * resultp)
 {
+    squidaio_init();
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->path = (char *) squidaio_xstrdup(path);
@@ -1025,17 +1010,14 @@
     requestp->err = errno;
 }
 
-#else
-
 
+#else
 int
 squidaio_unlink(const char *path, squidaio_result_t * resultp)
 {
+    squidaio_init();
     squidaio_request_t *requestp;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = (squidaio_request_t *)squidaio_request_pool->alloc();
 
     requestp->path = squidaio_xstrdup(path);
@@ -1063,7 +1045,6 @@
 
 #endif
 
-
 #if AIO_OPENDIR
 /* XXX squidaio_opendir NOT implemented yet.. */
 
@@ -1073,9 +1054,6 @@
     squidaio_request_t *requestp;
     int len;
 
-    if (!squidaio_initialised)
-        squidaio_init();
-
     requestp = squidaio_request_pool->alloc();
 
     resultp->result_type = _AIO_OP_OPENDIR;
