]> arthur.barton.de Git - netatalk.git/commitdiff
Decrease read/write chunks to 8192 again, new option dsireadbuf
authorFrank Lahm <franklahm@googlemail.com>
Fri, 1 Apr 2011 12:17:09 +0000 (14:17 +0200)
committerFrank Lahm <franklahm@googlemail.com>
Fri, 1 Apr 2011 12:17:09 +0000 (14:17 +0200)
etc/afpd/afp_config.c
etc/afpd/afp_dsi.c
etc/afpd/afp_options.c
etc/afpd/auth.c
etc/afpd/globals.h
include/atalk/dsi.h
libatalk/dsi/dsi_opensess.c
libatalk/dsi/dsi_stream.c

index 52592564cb84b1d9769f68696a5f015a32a581c8..790ee2fffbf9e7b0e0c9afa98ae2de32444fb544 100644 (file)
@@ -362,6 +362,7 @@ static AFPConfig *DSIConfigInit(const struct afp_options *options,
         free(config);
         return NULL;
     }
+    dsi->dsireadbuf = options->dsireadbuf;
 
     if (options->flags & OPTION_PROXY) {
         LOG(log_note, logtype_afpd, "AFP/TCP proxy initialized for %s:%d (%s)",
index 11e901f159bb6a9995e77e1da5a8e792c1635e53..2d0da9f26a096df9991bae7a8a997bceb755d317 100644 (file)
@@ -284,7 +284,7 @@ static void alarm_handler(int sig _U_)
 
     if (dsi->flags & DSI_SLEEPING) {
         if (dsi->tickle > AFPobj->options.sleep) {
-            LOG(log_error, logtype_afpd, "afp_alarm: sleep time ended");
+            LOG(log_note, logtype_afpd, "afp_alarm: sleep time ended");
             afp_dsi_die(EXITERR_CLNT);
         }
         return;
@@ -292,7 +292,7 @@ static void alarm_handler(int sig _U_)
 
     if (dsi->flags & DSI_DISCONNECTED) {
         if (dsi->tickle > AFPobj->options.disconnected) {
-            LOG(log_error, logtype_afpd, "afp_alarm: no reconnect within 10 minutes, goodbye");
+            LOG(log_error, logtype_afpd, "afp_alarm: reconnect timer expired, goodbye");
             afp_dsi_die(EXITERR_CLNT);
         }
         return;
index 7283d136fa1542bf63b1db29fa1e3a05fa1c70f0..f3724c13cdbd6d05f8403b6a753839e9c1f207c0 100644 (file)
@@ -188,6 +188,7 @@ void afp_options_init(struct afp_options *options)
     options->flags |= OPTION_UUID;
     options->tcp_sndbuf = 0;    /* 0 means don't change OS default */
     options->tcp_rcvbuf = 0;    /* 0 means don't change OS default */
+    options->dsireadbuf = 12;
 }
 
 /* parse an afpd.conf line. i'm doing it this way because it's
@@ -323,6 +324,12 @@ int afp_options_parseline(char *buf, struct afp_options *options)
         }
     }
 
+    if ((c = getoption(buf, "-dsireadbuf"))) {
+        options->dsireadbuf = atoi(c);
+        if (options->dsireadbuf < 6)
+            options->dsireadbuf = 6;
+    }
+
     if ((c = getoption(buf, "-server_quantum")))
         options->server_quantum = strtoul(c, NULL, 0);
 
index 2b659e2ba53744b1aac8d8a6bc0426240e0d2cf3..5226f7b379cdd3c2b8012292de6da1fc8be84d6f 100644 (file)
@@ -457,17 +457,17 @@ int afp_zzz(AFPObj *obj, char *ibuf, size_t ibuflen _U_, char *rbuf, size_t *rbu
     if (data & AFPZZZ_EXT_WAKEUP) {
         /* wakeup request from exetended sleep */
         if (dsi->flags & DSI_EXTSLEEP) {
-            LOG(log_debug, logtype_afpd, "afp_zzz: waking up from extended sleep");
+            LOG(log_note, logtype_afpd, "afp_zzz: waking up from extended sleep");
             dsi->flags &= ~(DSI_SLEEPING | DSI_EXTSLEEP);
         }
     } else {
         /* sleep request */
         dsi->flags |= DSI_SLEEPING;
         if (data & AFPZZZ_EXT_SLEEP) {
-            LOG(log_debug, logtype_afpd, "afp_zzz: entering extended sleep");
+            LOG(log_note, logtype_afpd, "afp_zzz: entering extended sleep");
             dsi->flags |= DSI_EXTSLEEP;
         } else {
-            LOG(log_debug, logtype_afpd, "afp_zzz: entering normal sleep");
+            LOG(log_note, logtype_afpd, "afp_zzz: entering normal sleep");
         }
     }
     /*
index 67fd4607eef1fd71a237e1061145f2a84207c3e8..02dcf8b56b58abd1dd00d02dbe44452a2c19a3e4 100644 (file)
@@ -68,6 +68,7 @@ struct afp_options {
     unsigned int tcp_sndbuf, tcp_rcvbuf;
     unsigned char passwdbits, passwdminlen, loginmaxfail;
     u_int32_t server_quantum;
+    int dsireadbuf; /* scale factor for sizefof(dsi->buffer) = server_quantum * dsireadbuf */
     char hostname[MAXHOSTNAMELEN + 1], *server, *ipaddr, *port, *configfile;
     struct at_addr ddpaddr;
     char *uampath, *fqdn;
index 63e722215f5583c511c1db4d31daefe520f31e56..4d48190045bac14792df3071368dd7b436c30259 100644 (file)
@@ -54,7 +54,7 @@ struct dsi_block {
 };
 
 #define DSI_CMDSIZ        8192 
-#define DSI_DATASIZ       65536
+#define DSI_DATASIZ       8192
 
 /* child and parent processes might interpret a couple of these
  * differently. */
@@ -96,13 +96,12 @@ typedef struct DSI {
   int zeroconf_registered;
 #endif
 
-  /* buffer for OSX deadlock */
+  /* DSI readahead buffer used for buffered reads in dsi_peek */
+  size_t dsireadbuf; /* size of the DSI readahead buffer used in dsi_peek() */
   char *buffer;
   char *start;
   char *eof;
   char *end;
-  int  maxsize;
-
 } DSI;
   
 /* DSI flags */
index 38382c7c938bbf25f421779d5740a2e20518ff0f..2d7fd23b84c947789f060dfe7b89b3e3ab41f398 100644 (file)
 
 static void dsi_init_buffer(DSI *dsi)
 {
-    dsi->maxsize = 64 * dsi->server_quantum;
-    if (!dsi->maxsize)
-        dsi->maxsize = 64 * DSI_SERVQUANT_DEF;
-    if ((dsi->buffer = malloc(dsi->maxsize)) == NULL) {
+    size_t quantum = dsi->server_quantum ? dsi->server_quantum : DSI_SERVQUANT_DEF;
+
+    /* default is 12 * 300k = 3,6 MB (Apr 2011) */
+    if ((dsi->buffer = malloc(dsi->dsireadbuf * quantum)) == NULL) {
         LOG(log_error, logtype_dsi, "dsi_init_buffer: OOM");
         AFP_PANIC("OOM in dsi_init_buffer");
     }
     dsi->start = dsi->buffer;
     dsi->eof = dsi->buffer;
-    dsi->end = dsi->buffer + dsi->maxsize;
+    dsi->end = dsi->buffer + (dsi->dsireadbuf * quantum);
 }
 
 /* OpenSession. set up the connection */
index 119d28ea4c95df415e5472d7da17a3c8e8c5dc91..5cd34a5815f67b5b8f654c41a754ed777a84f87e 100644 (file)
 #define MSG_DONTWAIT 0x40
 #endif
 
-/* ---------------------- 
-   afpd is sleeping too much while trying to send something.
-   May be there's no reader or the reader is also sleeping in write,
-   look if there's some data for us to read, hopefully it will wake up
-   the reader so we can write again.
-*/
+/*
+ * afpd is sleeping too much while trying to send something.
+ * May be there's no reader or the reader is also sleeping in write,
+ * look if there's some data for us to read, hopefully it will wake up
+ * the reader so we can write again.
+ *
+ * @returns 0 when is possible to send again, -1 on error
+ */
 static int dsi_peek(DSI *dsi)
 {
+    static int warned = 0;
     fd_set readfds, writefds;
     int    len;
     int    maxfd;
@@ -56,14 +59,26 @@ static int dsi_peek(DSI *dsi)
 
     LOG(log_debug, logtype_dsi, "dsi_peek");
 
-    FD_ZERO(&readfds);
-    FD_ZERO(&writefds);
-    FD_SET( dsi->socket, &readfds);
-    FD_SET( dsi->socket, &writefds);
-    maxfd = dsi->socket +1;
+    maxfd = dsi->socket + 1;
 
     while (1) {
-        FD_SET( dsi->socket, &readfds);
+        FD_ZERO(&readfds);
+        FD_ZERO(&writefds);
+
+        if (dsi->eof < dsi->end) {
+            /* space in read buffer */
+            FD_SET( dsi->socket, &readfds);
+        } else {
+            if (!warned) {
+                warned = 1;
+                LOG(log_note, logtype_dsi, "dsi_peek: readahead buffer is full, possibly increase -dsireadbuf option");
+                LOG(log_note, logtype_dsi, "dsi_peek: dsireadbuf: %d, DSI quantum: %d, effective buffer size: %d",
+                    dsi->dsireadbuf,
+                    dsi->server_quantum ? dsi->server_quantum : DSI_SERVQUANT_DEF,
+                    dsi->end - dsi->buffer);
+            }
+        }
+
         FD_SET( dsi->socket, &writefds);
 
         /* No timeout: if there's nothing to read nor nothing to write,
@@ -78,17 +93,15 @@ static int dsi_peek(DSI *dsi)
             return -1;
         }
 
+        if (FD_ISSET(dsi->socket, &writefds)) {
+            /* we can write again */
+            LOG(log_debug, logtype_dsi, "dsi_peek: can write again");
+            break;
+        }
+
         /* Check if there's sth to read, hopefully reading that will unblock the client */
         if (FD_ISSET(dsi->socket, &readfds)) {
-            len = dsi->end - dsi->eof;
-            LOG(log_note, logtype_dsi, "dsi_peek: used read buffer space: %d bytes", dsi->eof - dsi->buffer);
-
-            if (len <= 0) {
-                /* ouch, our buffer is full ! fall back to blocking IO 
-                 * could block and disconnect but it's better than a cpu hog */
-                LOG(log_warning, logtype_dsi, "dsi_peek: read buffer is full");
-                break;
-            }
+            len = dsi->end - dsi->eof; /* it's ensured above that there's space */
 
             if ((len = read(dsi->socket, dsi->eof, len)) <= 0) {
                 if (len == 0) {
@@ -104,12 +117,6 @@ static int dsi_peek(DSI *dsi)
 
             dsi->eof += len;
         }
-
-        if (FD_ISSET(dsi->socket, &writefds)) {
-            /* we can write again */
-            LOG(log_debug, logtype_dsi, "dsi_peek: can write again");
-            break;
-        }
     }
 
     return 0;
@@ -227,24 +234,26 @@ static size_t from_buf(DSI *dsi, u_int8_t *buf, size_t count)
 {
     size_t nbe = 0;
 
+    if (dsi->buffer == NULL)
+        /* afpd master has no DSI buffering */
+        return 0;
+
     LOG(log_maxdebug, logtype_dsi, "from_buf: %u bytes", count);
     
-    if (dsi->start) {        
-        nbe = dsi->eof - dsi->start;
+    nbe = dsi->eof - dsi->start;
 
-        if (nbe > 0) {
-           nbe = min((size_t)nbe, count);
-           memcpy(buf, dsi->start, nbe);
-           dsi->start += nbe;
+    if (nbe > 0) {
+        nbe = min((size_t)nbe, count);
+        memcpy(buf, dsi->start, nbe);
+        dsi->start += nbe;
 
-           if (dsi->eof == dsi->start) 
-               dsi->start = dsi->eof = dsi->buffer;
-
-        }
+        if (dsi->eof == dsi->start)
+            dsi->start = dsi->eof = dsi->buffer;
     }
 
-    LOG(log_maxdebug, logtype_dsi, "from_buf(dead: %u, unread:%u , space left: %u): returning %u",
+    LOG(log_debug, logtype_dsi, "from_buf(read: %u, unread:%u , space left: %u): returning %u",
         dsi->start - dsi->buffer, dsi->eof - dsi->start, dsi->end - dsi->eof, nbe);
+
     return nbe;
 }
 
@@ -316,7 +325,7 @@ size_t dsi_stream_read(DSI *dsi, void *data, const size_t length)
 
 /*
  * Get "length" bytes from buffer and/or socket. In order to avoid frequent small reads
- * this tries to read larger chunks (65536 bytes) into a buffer.
+ * this tries to read larger chunks (8192 bytes) into a buffer.
  */
 static size_t dsi_buffered_stream_read(DSI *dsi, u_int8_t *data, const size_t length)
 {
@@ -331,8 +340,8 @@ static size_t dsi_buffered_stream_read(DSI *dsi, u_int8_t *data, const size_t le
       return len;               /* yes */
   }
 
-  /* fill the buffer with 65536 bytes or until buffer is full */
-  buflen = min(65536, dsi->end - dsi->eof);
+  /* fill the buffer with 8192 bytes or until buffer is full */
+  buflen = min(8192, dsi->end - dsi->eof);
   if (buflen > 0) {
       ssize_t ret;
       ret = read(dsi->socket, dsi->eof, buflen);