]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
experimental OPTIMISTIC IO patch
authorwessels <>
Wed, 19 Aug 1998 04:42:17 +0000 (04:42 +0000)
committerwessels <>
Wed, 19 Aug 1998 04:42:17 +0000 (04:42 +0000)
src/comm.cc
src/disk.cc
src/http.cc
src/store.cc
src/store_client.cc
src/structs.h

index 4dde1626cb65159e404e34c625fe48dfa9c0cdf7..8ed96164b708dea806825892f7199506419e069f 100644 (file)
@@ -1,7 +1,7 @@
 
 
 /*
- * $Id: comm.cc,v 1.283 1998/08/18 19:13:59 wessels Exp $
+ * $Id: comm.cc,v 1.284 1998/08/18 22:42:17 wessels Exp $
  *
  * DEBUG: section 5     Socket Functions
  * AUTHOR: Harvest Derived
@@ -834,7 +834,11 @@ comm_write(int fd, char *buf, int size, CWCB * handler, void *handler_data, FREE
     state->handler_data = handler_data;
     state->free_func = free_func;
     cbdataLock(handler_data);
+#ifdef OPTIMISTIC_IO
+    commHandleWrite(fd, state);
+#else
     commSetSelect(fd, COMM_SELECT_WRITE, commHandleWrite, state, 0);
+#endif
 }
 
 /* a wrapper around comm_write to allow for MemBuf to be comm_written in a snap */
index 5185780b8f450e6ab45a12a9a241b573865d52d5..4cfdb7554a1f59d7daa3bb3edff5c362b59fca6e 100644 (file)
@@ -1,7 +1,7 @@
 
 
 /*
- * $Id: disk.cc,v 1.127 1998/08/18 21:15:43 wessels Exp $
+ * $Id: disk.cc,v 1.128 1998/08/18 22:42:18 wessels Exp $
  *
  * DEBUG: section 6     Disk I/O Routines
  * AUTHOR: Harvest Derived
@@ -166,6 +166,9 @@ diskHandleWrite(int fd, void *notused)
     struct _fde_disk *fdd = &F->disk;
     if (!fdd->write_q)
        return;
+#ifdef OPTIMISTIC_IO
+    assert(!F->flags.calling_io_handler);
+#endif
     debug(6, 3) ("diskHandleWrite: FD %d\n", fd);
     /* We need to combine subsequent write requests after the first */
     /* But only if we don't need to seek() in between them, ugh! */
@@ -329,11 +332,17 @@ diskHandleWriteComplete(int fd, void *data, int len, int errcode)
        if (fdd->wrt_handle_data != NULL)
            cbdataUnlock(fdd->wrt_handle_data);
        if (do_callback) {
+#ifdef OPTIMISTIC_IO
+           F->flags.calling_io_handler = 1;
+#endif
            fdd->wrt_handle(fd, status, len, fdd->wrt_handle_data);
            /*
             * NOTE, this callback can close the FD, so we must
             * not touch 'F', 'fdd', etc. after this.
             */
+#ifdef OPTIMISTIC_IO
+           F->flags.calling_io_handler = 0;
+#endif
            return;
        }
     }
@@ -381,9 +390,18 @@ file_write(int fd,
 #if USE_ASYNC_IO
        diskHandleWrite(fd, NULL);
 #else
+#ifdef OPTIMISTIC_IO
+    if (F->flags.calling_io_handler)
+#endif
        commSetSelect(fd, COMM_SELECT_WRITE, diskHandleWrite, NULL, 0);
+#ifdef OPTIMISTIC_IO
+    else
+        diskHandleWrite(fd, NULL);
+#endif
 #endif
+#ifndef OPTIMISTIC_IO
        F->flags.write_daemon = 1;
+#endif
     }
 }
 
@@ -406,6 +424,9 @@ diskHandleRead(int fd, void *data)
     fde *F = &fd_table[fd];
     int len;
 #endif
+#ifdef OPTIMISTIC_IO
+    assert(!F->flags.calling_io_handler);
+#endif /* OPTIMISTIC_IO */
 #if USE_ASYNC_IO
     aioRead(fd,
        ctrl_dat->offset,
@@ -432,6 +453,9 @@ diskHandleReadComplete(int fd, void *data, int len, int errcode)
 {
     dread_ctrl *ctrl_dat = data;
     int rc = DISK_OK;
+#ifdef OPTIMISTIC_IO
+    fde *F = &fd_table[fd];
+#endif /* OPTIMISTIC_IO */
     errno = errcode;
     if (len == -2 && errcode == -2) {  /* Read cancelled - cleanup */
        cbdataUnlock(ctrl_dat->client_data);
@@ -450,8 +474,14 @@ diskHandleReadComplete(int fd, void *data, int len, int errcode)
     } else if (len == 0) {
        rc = DISK_EOF;
     }
+#ifdef OPTIMISTIC_IO
+    F->flags.calling_io_handler = 1;
+#endif /* OPTIMISTIC_IO */
     if (cbdataValid(ctrl_dat->client_data))
        ctrl_dat->handler(fd, ctrl_dat->buf, len, rc, ctrl_dat->client_data);
+#ifdef OPTIMISTIC_IO
+    F->flags.calling_io_handler = 0;
+#endif /* OPTIMISTIC_IO */
     cbdataUnlock(ctrl_dat->client_data);
     memFree(MEM_DREAD_CTRL, ctrl_dat);
 }
@@ -465,6 +495,9 @@ int
 file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *client_data)
 {
     dread_ctrl *ctrl_dat;
+#ifdef OPTIMISTIC_IO
+    fde *F = &fd_table[fd];
+#endif /* OPTIMISTIC_IO */
     assert(fd >= 0);
     ctrl_dat = memAllocate(MEM_DREAD_CTRL);
     ctrl_dat->fd = fd;
@@ -478,11 +511,18 @@ file_read(int fd, char *buf, int req_len, off_t offset, DRCB * handler, void *cl
 #if USE_ASYNC_IO
     diskHandleRead(fd, ctrl_dat);
 #else
+#ifndef OPTIMISTIC_IO
     commSetSelect(fd,
        COMM_SELECT_READ,
        diskHandleRead,
        ctrl_dat,
        0);
+#else
+    if (F->flags.calling_io_handler)
+       commSetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0);
+    else
+        diskHandleRead(fd, ctrl_dat);
+#endif /* OPTIMISTIC_IO */
 #endif
     return DISK_OK;
 }
index f87a9c0d4cebafc7b2dc4b17117cdd53b4eb962f..4d8f6950f4898a1250f0a198f3dc3ef83ffa09c2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: http.cc,v 1.307 1998/08/17 16:44:07 wessels Exp $
+ * $Id: http.cc,v 1.308 1998/08/18 22:42:19 wessels Exp $
  *
  * DEBUG: section 11    Hypertext Transfer Protocol (HTTP)
  * AUTHOR: Harvest Derived
@@ -433,6 +433,16 @@ httpReadReply(int fd, void *data)
        if (httpState->reply_hdr_state < 2)
            httpProcessReplyHeader(httpState, buf, len);
        storeAppend(entry, buf, len);
+#ifdef OPTIMISTIC_IO
+       if (entry->store_status == STORE_ABORTED) {
+           /*
+            * the above storeAppend() call could ABORT this entry,
+            * in that case, the server FD should already be closed.
+            * there's nothing for us to do.
+            */
+           (void) 0;
+       } else
+#endif
        if (httpPconnTransferDone(httpState)) {
            /* yes we have to clear all these! */
            commSetDefer(fd, NULL, NULL);
index 68178a8ababb915a4b8f73ed3583c278eef8f72e..2b1c97f9d5b0bb4e87b453720db75c5c774bc96e 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store.cc,v 1.444 1998/08/18 18:36:10 wessels Exp $
+ * $Id: store.cc,v 1.445 1998/08/18 22:42:21 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager
  * AUTHOR: Harvest Derived
@@ -385,8 +385,14 @@ storeAppend(StoreEntry * e, const char *buf, int len)
     }
     if (EBIT_TEST(e->flag, DELAY_SENDING))
        return;
+#ifdef OPTIMISTIC_IO
+    storeLockObject(e);
+#endif
     InvokeHandlers(e);
     storeCheckSwapOut(e);
+#ifdef OPTIMISTIC_IO
+    storeUnlockObject(e);
+#endif
 }
 
 #ifdef __STDC__
index c24332bb719cecc82ede021c97c5bd7088433b81..9cf7e75b4ffb02753e69ba3126c3649e84ea1080 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_client.cc,v 1.36 1998/08/18 03:04:35 wessels Exp $
+ * $Id: store_client.cc,v 1.37 1998/08/18 22:42:22 wessels Exp $
  *
  * DEBUG: section 20    Storage Manager Client-Side Interface
  * AUTHOR: Duane Wessels
@@ -271,14 +271,23 @@ storeClientFileRead(store_client * sc)
 {
     MemObject *mem = sc->entry->mem_obj;
     assert(sc->callback != NULL);
+#ifndef OPTIMISTIC_IO
     if (mem->swap_hdr_sz == 0)
+#else
+    sc->flags.disk_io_pending = 1;
+    if (mem->swap_hdr_sz == 0) {
+#endif
        file_read(sc->swapin_fd,
            sc->copy_buf,
            sc->copy_size,
            0,
            storeClientReadHeader,
            sc);
+#ifndef OPTIMISTIC_IO
     else {
+#else
+    } else {
+#endif
        if (sc->entry->swap_status == SWAPOUT_WRITING)
            assert(mem->swapout.done_offset > sc->copy_offset + mem->swap_hdr_sz);
        file_read(sc->swapin_fd,
@@ -288,7 +297,9 @@ storeClientFileRead(store_client * sc)
            storeClientReadBody,
            sc);
     }
+#ifndef OPTIMISTIC_IO
     sc->flags.disk_io_pending = 1;
+#endif
 }
 
 static void
index 0c6982e8f4266309e01949036b0ef52fd8ea7aad..daf596c34a36a362681bb6f7bcd19fc18fa65d2b 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: structs.h,v 1.204 1998/08/18 20:48:52 wessels Exp $
+ * $Id: structs.h,v 1.205 1998/08/18 22:42:23 wessels Exp $
  *
  *
  * SQUID Internet Object Cache  http://squid.nlanr.net/Squid/
@@ -495,6 +495,9 @@ struct _fde {
        int nolinger:1;
        int nonblocking:1;
        int ipc:1;
+#ifdef OPTIMISTIC_IO
+       int calling_io_handler:1;
+#endif
     } flags;
     int bytes_read;
     int bytes_written;