Author: adrian.chadd
Date: Mon Mar 30 13:11:56 2009
New Revision: 13892

Modified:
    branches/LUSCA_HEAD/libiapp/comm.h
    branches/LUSCA_HEAD/libiapp/disk.c
    branches/LUSCA_HEAD/libiapp/disk.h
    branches/LUSCA_HEAD/libiapp/mainloop.c
    branches/LUSCA_HEAD/src/main.c

Log:
Separate out the legacy blocking disk code from the comm code a little more.

* Migrate the disk definitions out from libiapp/comm.h and put them into  
libiapp/disk.h
* Create a private per-fd array in libiapp/disk.c which stores -just- the  
legacy disk
   related stuff in it.

The eventual aim is to try and unify the sync and async disk IO methods,  
including
async scatter-gather IO support.

This code hasn't (yet) been very thoroughly tested!



Modified: branches/LUSCA_HEAD/libiapp/comm.h
==============================================================================
--- branches/LUSCA_HEAD/libiapp/comm.h  (original)
+++ branches/LUSCA_HEAD/libiapp/comm.h  Mon Mar 30 13:11:56 2009
@@ -2,20 +2,6 @@
  #define       __LIBIAPP_COMM_H__

  /*
- * Macro to find file access mode
- */
-#ifdef O_ACCMODE
-#define FILE_MODE(x) ((x)&O_ACCMODE)
-#else
-#define FILE_MODE(x) ((x)&(O_RDONLY|O_WRONLY|O_RDWR))
-#endif
-
-#define DISK_OK                   (0)
-#define DISK_ERROR               (-1)
-#define DISK_EOF                 (-2)
-#define DISK_NO_SPACE_LEFT       (-6)
-
-/*
   * Hey dummy, don't be tempted to move this to lib/config.h.in
   * again.  O_NONBLOCK will not be defined there because you didn't
   * #include <fcntl.h> yet.
@@ -45,9 +31,6 @@

  typedef struct _close_handler close_handler;

-typedef struct _dread_ctrl dread_ctrl;
-typedef struct _dwrite_q dwrite_q;
-
  typedef void PF(int, void *);
  typedef void CWCB(int fd, char *, size_t size, int flag, void *data);
  typedef void CRCB(int fd, int size, int flag, int xerrno, void *data);
@@ -57,40 +40,12 @@
  typedef int WRITE_HANDLER(int, const char *, int);
  typedef void CBCB(char *buf, ssize_t size, void *data);

-/* disk.c / diskd.c callback typedefs */
-typedef void DRCB(int, const char *buf, int size, int errflag, void *data);
-                                                        /* Disk read CB */
-typedef void DWCB(int, int, size_t, void *);    /* disk write CB */
-typedef void DOCB(int, int errflag, void *data);        /* disk open CB */
-typedef void DCCB(int, int errflag, void *data);        /* disk close CB */
-typedef void DUCB(int errflag, void *data);     /* disk unlink CB */
-typedef void DTCB(int errflag, void *data);     /* disk trunc CB */
-
  struct _close_handler {
      PF *handler;
      void *data;
      close_handler *next;
  };

-struct _dread_ctrl {
-    int fd;
-    off_t file_offset;
-    size_t req_len;
-    char *buf;
-    int end_of_file;
-    DRCB *handler;
-    void *client_data;
-};
-
-struct _dwrite_q {
-    off_t file_offset;
-    char *buf;
-    size_t len;
-    size_t buf_offset;
-    dwrite_q *next;
-    FREE *free_func;
-};
-
  struct _CommWriteStateData {
      int valid;
      char *buf;
@@ -134,13 +89,6 @@
      squid_off_t bytes_read;
      squid_off_t bytes_written;
      int uses;                   /* ie # req's over persistent conn */
-    struct _fde_disk {
-        DWCB *wrt_handle;
-        void *wrt_handle_data;
-        dwrite_q *write_q;
-        dwrite_q *write_q_tail;
-        off_t offset;
-    } disk;
      struct {
        struct {
                char *buf;

Modified: branches/LUSCA_HEAD/libiapp/disk.c
==============================================================================
--- branches/LUSCA_HEAD/libiapp/disk.c  (original)
+++ branches/LUSCA_HEAD/libiapp/disk.c  Mon Mar 30 13:11:56 2009
@@ -63,7 +63,11 @@

  #include "../libsqinet/sqinet.h"

-/* XXX at some point, comm.h should be split to disk, fd and comm includes  
*/
+/*
+ * XXX this stuff should be properly decoupled from the comm code; but
+ * XXX unfortunately right now a whole lot of stuff still lives
+ * XXX in the comm routines rather than the disk routines.
+ */
  #include "iapp_ssl.h"
  #include "fd_types.h"
  #include "comm_types.h"
@@ -76,6 +80,8 @@
  static MemPool * pool_dread_ctrl;
  static MemPool * pool_dwrite_q;

+struct _fde_disk *fde_disk = NULL;
+
  #if defined(_SQUID_WIN32_) || defined(_SQUID_OS2_)
  static int
  diskWriteIsComplete(int fd)
@@ -94,7 +100,7 @@
  void
  disk_init(void)
  {
-    (void) 0;
+       fde_disk = xcalloc(Squid_MaxFD, sizeof(struct _fde_disk));
  }

  /*
@@ -220,7 +226,7 @@
  {
      int len = 0;
      fde *F = &fd_table[fd];
-    struct _fde_disk *fdd = &F->disk;
+    struct _fde_disk *fdd = &fde_disk[fd];
      dwrite_q *q = fdd->write_q;
      int status = DISK_OK;
      int do_callback;
@@ -351,6 +357,7 @@
  {
      dwrite_q *wq = NULL;
      fde *F = &fd_table[fd];
+    struct _fde_disk *fdd = &fde_disk[fd];
      assert(fd >= 0);
      assert(F->flags.open);
      /* if we got here. Caller is eligible to write. */
@@ -361,18 +368,18 @@
      wq->buf_offset = 0;
      wq->next = NULL;
      wq->free_func = free_func;
-    F->disk.wrt_handle = handle;
-    F->disk.wrt_handle_data = handle_data;
+    fdd->wrt_handle = handle;
+    fdd->wrt_handle_data = handle_data;
      /* add to queue */
-    if (F->disk.write_q == NULL) {
+    if (fdd->write_q == NULL) {
        /* empty queue */
-       F->disk.write_q = F->disk.write_q_tail = wq;
+       fdd->write_q = fdd->write_q_tail = wq;
      } else {
-       F->disk.write_q_tail->next = wq;
-       F->disk.write_q_tail = wq;
+       fdd->write_q_tail->next = wq;
+       fdd->write_q_tail = wq;
      }
-    if (!F->flags.write_daemon) {
-       cbdataLock(F->disk.wrt_handle_data);
+    if (!fdd->flags.write_daemon) {
+       cbdataLock(fdd->wrt_handle_data);
        diskHandleWrite(fd, NULL);
      }
  }
@@ -392,7 +399,7 @@
  diskHandleRead(int fd, void *data)
  {
      dread_ctrl *ctrl_dat = data;
-    fde *F = &fd_table[fd];
+    struct _fde_disk *fdd = &fde_disk[fd];
      int len;
      int rc = DISK_OK;
      /*
@@ -403,17 +410,17 @@
        memPoolFree(pool_dread_ctrl, ctrl_dat);
        return;
      }
-    if (F->disk.offset != ctrl_dat->file_offset) {
+    if (fdd->offset != ctrl_dat->file_offset) {
        debug(6, 3) ("diskHandleRead: FD %d seeking to offset %d\n",
            fd, (int) ctrl_dat->file_offset);
        lseek(fd, ctrl_dat->file_offset, SEEK_SET);     /* XXX ignore return? */
        CommStats.syscalls.disk.seeks++;
-       F->disk.offset = ctrl_dat->file_offset;
+       fdd->offset = ctrl_dat->file_offset;
      }
      errno = 0;
      len = FD_READ_METHOD(fd, ctrl_dat->buf, ctrl_dat->req_len);
      if (len > 0)
-       F->disk.offset += len;
+       fdd->offset += len;
      CommStats.syscalls.disk.reads++;
      fd_bytes(fd, len, FD_READ);
      if (len < 0) {

Modified: branches/LUSCA_HEAD/libiapp/disk.h
==============================================================================
--- branches/LUSCA_HEAD/libiapp/disk.h  (original)
+++ branches/LUSCA_HEAD/libiapp/disk.h  Mon Mar 30 13:11:56 2009
@@ -1,6 +1,62 @@
  #ifndef       __LIBIAPP_DISK_H__
  #define       __LIBIAPP_DISK_H__

+#define DISK_OK                   (0)
+#define DISK_ERROR               (-1)
+#define DISK_EOF                 (-2)
+#define DISK_NO_SPACE_LEFT       (-6)
+
+/*
+ * Macro to find file access mode
+ */
+#ifdef O_ACCMODE
+#define FILE_MODE(x) ((x)&O_ACCMODE)
+#else
+#define FILE_MODE(x) ((x)&(O_RDONLY|O_WRONLY|O_RDWR))
+#endif
+
+typedef struct _dread_ctrl dread_ctrl;
+typedef struct _dwrite_q dwrite_q;
+
+/* disk.c / diskd.c callback typedefs */
+typedef void DRCB(int, const char *buf, int size, int errflag, void *data);
+                                                        /* Disk read CB */
+typedef void DWCB(int, int, size_t, void *);    /* disk write CB */
+typedef void DOCB(int, int errflag, void *data);        /* disk open CB */
+typedef void DCCB(int, int errflag, void *data);        /* disk close CB */
+typedef void DUCB(int errflag, void *data);     /* disk unlink CB */
+typedef void DTCB(int errflag, void *data);     /* disk trunc CB */
+
+struct _dread_ctrl {
+    int fd;
+    off_t file_offset;
+    size_t req_len;
+    char *buf;
+    int end_of_file;
+    DRCB *handler;
+    void *client_data;
+};
+
+struct _dwrite_q {
+    off_t file_offset;
+    char *buf;
+    size_t len;
+    size_t buf_offset;
+    dwrite_q *next;
+    FREE *free_func;
+};
+
+struct _fde_disk {
+       DWCB *wrt_handle;
+       void *wrt_handle_data;
+       dwrite_q *write_q;
+       dwrite_q *write_q_tail;
+       off_t offset;
+       struct {
+               int write_daemon:1;
+       } flags;
+};
+
  extern int file_open(const char *path, int mode);
  extern void file_close(int fd);
  extern void file_write(int, off_t, void *, size_t len, DWCB *, void *,  
FREE *);

Modified: branches/LUSCA_HEAD/libiapp/mainloop.c
==============================================================================
--- branches/LUSCA_HEAD/libiapp/mainloop.c      (original)
+++ branches/LUSCA_HEAD/libiapp/mainloop.c      Mon Mar 30 13:11:56 2009
@@ -50,6 +50,7 @@
        cbdataInit();
        eventInit();
        comm_init();
+       disk_init();
        comm_select_init();
  }


Modified: branches/LUSCA_HEAD/src/main.c
==============================================================================
--- branches/LUSCA_HEAD/src/main.c      (original)
+++ branches/LUSCA_HEAD/src/main.c      Mon Mar 30 13:11:56 2009
@@ -856,6 +856,7 @@

  #if TEST_ACCESS
      comm_init();
+    disk_init();
      comm_select_init();
      mainInitialize();
      test_access();

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to