httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Reid" <ab...@dial.pipex.com>
Subject Re: {PATCH} ap_put_statinfo
Date Wed, 03 Nov 1999 12:19:47 GMT
What I'm trying to avoid is having the ap_mmap function re-stat the file.
As Bill pointed out this would be a big loss...

The file in the default_handler has already been statted so when the
ap_file_t is created I propose using the ap_put_statinfo to simply add the
stat information into the ap_file_t, then when I create the ap_mmap_t via
the ap_file_t no further stat will be required.  This seemed to be cleaner
than trying to create a new ap_mmap_t creation function that only took a
size, or to get involved in to stat or not to stat flags in the function
calls.

To show what I have in mind here is a diff of the files in src/main that are
affected.  I've tested this on FreeBSD 3.3 and BeOS and it works OK.  I'm
sure it can be improved on though :-)

This needs some functions that are in mmap and I'll commit them later today.

david


diff -u /boot/home/cvs/apache-2.0/src/main/http_core.c ./http_core.c
--- /boot/home/cvs/apache-2.0/src/main/http_core.c Thu Oct 21 19:57:41 1999
+++ ./http_core.c Wed Nov  3 10:41:45 1999
@@ -71,7 +71,7 @@
 #include "http_connection.h"

 #ifdef USE_MMAP_FILES
-#include <sys/mman.h>
+#include "apr_mmap.h"

 /* mmap support for static files based on ideas from John Heidemann's
  * patch against 1.0.5.  See
@@ -2442,25 +2442,6 @@

 static int do_nothing(request_rec *r) { return OK; }

-#ifdef USE_MMAP_FILES
-struct mmap_rec {
-    void *mm;
-    size_t length;
-};
-
-static ap_status_t mmap_cleanup(void *mmv)
-{
-    struct mmap_rec *mmd = mmv;
-
-    if (munmap(mmd->mm, mmd->length) == -1) {
-        ap_log_error(APLOG_MARK, APLOG_ERR, errno, NULL,
-                     "Failed to munmap memory of length %ld at 0x%lx",
-                     (long) mmd->length, (long) mmd->mm);
-    }
-    return APR_SUCCESS;
-}
-#endif
-
 /*
  * Default handler for MIME types without other handlers.  Only GET
  * and OPTIONS at this point... anyone who wants to write a generic
@@ -2478,7 +2459,7 @@
     int fd_os;
     ap_status_t status;
 #ifdef USE_MMAP_FILES
-    caddr_t mm;
+    ap_mmap_t *mm = NULL;
 #endif
 #ifdef CHARSET_EBCDIC
     /* To make serving of "raw ASCII text" files easy (they serve faster
@@ -2528,8 +2509,10 @@
        "file permissions deny server access: %s", r->filename);
         return FORBIDDEN;
     }
-    else
-       ap_get_os_file(&fd_os, fd);
+    else {
+        ap_put_statinfo(fd, &r->finfo);
+        ap_get_os_file(&fd_os, fd);
+ }

     ap_update_mtime(r, r->finfo.st_mtime);
     ap_set_last_modified(r);
@@ -2543,22 +2526,20 @@

 #ifdef USE_MMAP_FILES
     if ((r->finfo.st_size >= MMAP_THRESHOLD)
- && (r->finfo.st_size < MMAP_LIMIT)
- && (!r->header_only || (d->content_md5 & 1))) {
- /* we need to protect ourselves in case we die while we've got the
-   * file mmapped */
- mm = mmap(NULL, r->finfo.st_size, PROT_READ, MAP_PRIVATE,
-    fd_os, 0);
- if (mm == (caddr_t)-1) {
-     ap_log_rerror(APLOG_MARK, APLOG_CRIT, errno, r,
+     && (r->finfo.st_size < MMAP_LIMIT)
+   && (!r->header_only || (d->content_md5 & 1))) {
+   /* we need to protect ourselves in case we die while we've got the
+     * file mmapped */
+        if ((ap_mmap_open_create(&mm, fd, r->pool)) != APR_SUCCESS)

+         ap_log_rerror(APLOG_MARK, APLOG_CRIT, errno, r,
     "default_handler: mmap failed: %s", r->filename);
- }
+     }
     }
     else {
- mm = (caddr_t)-1;
+     mm = NULL;
     }

-    if (mm == (caddr_t)-1) {
+    if (mm == NULL) {
 #endif

 #ifdef CHARSET_EBCDIC
@@ -2600,18 +2581,13 @@
 #ifdef USE_MMAP_FILES
     }
     else {
- struct mmap_rec *mmd;
-
- mmd = ap_palloc(r->pool, sizeof(*mmd));
- mmd->mm = mm;
- mmd->length = r->finfo.st_size;
- ap_register_cleanup(r->pool, (void *)mmd, mmap_cleanup, mmap_cleanup);
-
+    char *addr;
+    ap_mmap_offset((void**)&addr, mm, 0);
  if (d->content_md5 & 1) {
      AP_MD5_CTX context;

      ap_MD5Init(&context);
-     ap_MD5Update(&context, (void *)mm, (unsigned int)r->finfo.st_size);
+     ap_MD5Update(&context, addr, (unsigned int)r->finfo.st_size);
      ap_table_setn(r->headers_out, "Content-MD5",
      ap_md5contextTo64(r->pool, &context));
  }
diff -u /boot/home/cvs/apache-2.0/src/main/http_protocol.c ./http_protocol.c
--- /boot/home/cvs/apache-2.0/src/main/http_protocol.c Tue Nov  2 11:22:47
1999
+++ ./http_protocol.c Wed Nov  3 10:27:31 1999
@@ -2156,15 +2156,17 @@
 #define MMAP_SEGMENT_SIZE       32768
 #endif

+#ifdef USE_MMAP_FILES
 /* send data from an in-memory buffer */
-API_EXPORT(size_t) ap_send_mmap(void *mm, request_rec *r, size_t offset,
+API_EXPORT(size_t) ap_send_mmap(ap_mmap_t *mm, request_rec *r, size_t
offset,
                              size_t length)
 {
     size_t total_bytes_sent = 0;
     int n;
     ap_ssize_t w;
     ap_status_t rv;
-
+    char *base;
+
     if (length == 0)
         return 0;

@@ -2179,7 +2181,8 @@
         }

         while (n && !r->connection->aborted) {
-            rv = ap_bwrite(r->connection->client, (char *) mm + offset, n,
&w);
+            ap_mmap_offset((void*)&base, mm, offset);
+            rv = ap_bwrite(r->connection->client, base, n, &w);
             if (w > 0) {
                 total_bytes_sent += w;
                 n -= w;
@@ -2204,6 +2207,7 @@
     SET_BYTES_SENT(r);
     return total_bytes_sent;
 }
+#endif /* USE_MMAP_FILES */

 API_EXPORT(int) ap_rputc(int c, request_rec *r)
 {


----- Original Message -----
From: Manoj Kasichainula <manojk@io.com>
To: <new-httpd@apache.org>
Sent: 03 November 1999 08:14
Subject: Re: {PATCH} ap_put_statinfo


> On Tue, Nov 02, 1999 at 10:23:21PM -0000, David Reid wrote:
> > Whilst looking into the ap_mmap stuff it seemed like a good idea to add
the
> > following function.  Rather than just committing I'm flagging it here as
it
> > might not be portable etc etc
>
> If an ap_put_statinfo function is useful, I think that suggests that
> stat information should be kept in a new and different APR object from
> ap_file_t.
>
> > For an idea of where this might be useful can I point you at
default_handler
> > in http_core.c for the mmap sections.
>
> I don't see it. Maybe I will after some sleep, but in the mean time,
> can you point it out? :)
>
> --
> Manoj Kasichainula - manojk at io dot com - http://www.io.com/~manojk/


Mime
View raw message