apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnicho...@apache.org
Subject cvs commit: apr/include/arch/netware fileio.h
Date Wed, 23 Oct 2002 22:21:20 GMT
bnicholes    2002/10/23 15:21:19

  Modified:    file_io/unix open.c
               file_io/netware filestat.c
               file_io/win32 filepath.c
               include/arch/netware fileio.h
  Log:
  Getting ready for an API change in the NetWare LIBC library that will speed up
  the file IO.  Use a path context rather than the file path to get direct
  access to the file in the file system rather than having to make the file system
  traverse the directory tree.
  
  Revision  Changes    Path
  1.99      +30 -1     apr/file_io/unix/open.c
  
  Index: open.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/open.c,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- open.c	16 Jul 2002 17:55:01 -0000	1.98
  +++ open.c	23 Oct 2002 22:21:18 -0000	1.99
  @@ -58,6 +58,14 @@
   #include "apr_thread_mutex.h"
   #include "inherit.h"
   
  +#ifdef FAST_STAT
  +#ifdef NETWARE
  +#include "nks/dirio.h"
  +#include "apr_hash.h"
  +#include "fsio.h"
  +#endif
  +#endif
  +
   apr_status_t apr_unix_file_cleanup(void *thefile)
   {
       apr_file_t *file = thefile;
  @@ -97,6 +105,13 @@
       apr_status_t rv;
   #endif
   
  +#ifdef FAST_STAT
  +#ifdef NETWARE
  +    apr_hash_t *statCache = (apr_hash_t *)getStatCache(CpuCurrentProcessor);
  +    apr_stat_entry_t *stat_entry;
  +#endif
  +#endif
  +
       (*new) = (apr_file_t *)apr_pcalloc(pool, sizeof(apr_file_t));
       (*new)->pool = pool;
       (*new)->flags = flag;
  @@ -158,12 +173,26 @@
       }
   #endif
       
  +#ifdef FAST_STAT
  +#ifdef NETWARE
  +    stat_entry = (apr_stat_entry_t*) apr_hash_get(statCache, fname, APR_HASH_KEY_STRING);
  +    if (stat_entry) {
  +        errno = NXFileOpen (stat_entry->pathCtx, stat_entry->casedName, oflags, &(*new)->filedes);
  +    }
  +    else {
  +#endif
  +#endif
       if (perm == APR_OS_DEFAULT) {
           (*new)->filedes = open(fname, oflags, 0666);
       }
       else {
           (*new)->filedes = open(fname, oflags, apr_unix_perms2mode(perm));
  -    }    
  +    } 
  +#ifdef FAST_STAT
  +#ifdef NETWARE
  +    }
  +#endif
  +#endif
   
       if ((*new)->filedes < 0) {
          (*new)->filedes = -1;
  
  
  
  1.18      +173 -7    apr/file_io/netware/filestat.c
  
  Index: filestat.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/netware/filestat.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- filestat.c	3 Oct 2002 00:32:20 -0000	1.17
  +++ filestat.c	23 Oct 2002 22:21:19 -0000	1.18
  @@ -53,6 +53,9 @@
    */
   
   #include "fileio.h"
  +#ifdef FAST_STAT
  +#include "fsio.h"
  +#endif
   #include "nks/dirio.h"
   #include "apr_file_io.h"
   #include "apr_general.h"
  @@ -104,6 +107,7 @@
        */
   }
   
  +#ifndef FAST_STAT
   char *case_filename(apr_pool_t *pPool, const char *szFile)
   {
       char *casedFileName = NULL;
  @@ -126,6 +130,7 @@
       }
       return casedFileName;
   }
  +#endif
   
   
   APR_DECLARE(apr_status_t) apr_file_info_get(apr_finfo_t *finfo, 
  @@ -205,16 +210,176 @@
       return apr_file_perms_set(fname, finfo.protection);
   }
   
  -typedef struct apr_stat_entry_t apr_stat_entry_t;
  +#ifdef FAST_STAT
  +int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *pool)
  +{
  +    apr_hash_t *statCache = (apr_hash_t *)getStatCache(CpuCurrentProcessor);
  +    apr_pool_t *gPool = (apr_pool_t *)getGlobalPool(CpuCurrentProcessor);
  +    apr_stat_entry_t *stat_entry;
  +    struct stat *info;
  +    apr_time_t now = apr_time_now();
  +    NXPathCtx_t pathCtx = 0;
  +    char *key;
  +    int ret;
  +    int found = 0;
   
  -struct apr_stat_entry_t {
  -    struct stat info;
  -    char *casedName;
  -    apr_time_t expire;
  -};
  +    *casedName = NULL;
  +    errno = 0;
  +
  +    /* If there isn't a global pool then just stat the file
  +       and return */
  +    if (!gPool) {
  +        char poolname[50];
  +
  +        if (apr_pool_create(&gPool, NULL) != APR_SUCCESS) {
  +            getcwdpath(NULL, &pathCtx, CTX_ACTUAL_CWD);
  +            ret = getstat(pathCtx, path, buf, ST_STAT_BITS|ST_NAME_BIT);
  +            if (ret == 0) {
  +                *casedName = apr_pstrdup (pool, buf->st_name);
  +                return 0;
  +            }
  +            else {
  +                errno = ret;
  +                return -1;
  +            }
  +        }
  +
  +        sprintf (poolname, "cstat_mem_pool_%d", CpuCurrentProcessor);
  +        apr_pool_tag(gPool, apr_pstrdup(gPool, poolname));
  +
  +        setGlobalPool(gPool, CpuCurrentProcessor);
  +    }
  +
  +    /* If we have a statCache hash table then use it.
  +       Otherwise we need to create it and initialized it
  +       with a new mutex lock. */
  +    if (!statCache) {
  +        statCache = apr_hash_make(gPool);
  +        setStatCache((void*)statCache, CpuCurrentProcessor);
  +    }
  +
  +    /* If we have a statCache then try to pull the information
  +       from the cache.  Otherwise just stat the file and return.*/
  +    if (statCache) {
  +        stat_entry = (apr_stat_entry_t*) apr_hash_get(statCache, path, APR_HASH_KEY_STRING);
  +        /* If we got an entry then check the expiration time.  If the entry
  +           hasn't expired yet then copy the information and return. */
  +        if (stat_entry) {
  +            if ((now - stat_entry->expire) <= APR_USEC_PER_SEC) {
  +                memcpy (buf, &(stat_entry->info), sizeof(struct stat));
  +                *casedName = apr_pstrdup (pool, stat_entry->casedName);
  +                found = 1;
  +            }
  +        }
   
  -extern apr_int32_t CpuCurrentProcessor; /* system variable */
  +        /* Since we are creating a separate stat cache for each processor, we
  +           don't need to worry about locking the hash table before manipulating
  +           it. */
  +        if (!found) {
  +            /* Bind the thread to the current cpu so that we don't wake
  +               up on some other cpu and try to manipulate the wrong cache. */
  +            NXThreadBind (CpuCurrentProcessor);
  +
  +            /* If we don't have a stat_entry then create one, copy
  +               the data and add it to the hash table. */
  +            if (!stat_entry) {
  +                char *dirPath = NULL, *fname = NULL;
  +                char *ptr;
  +                int err, len;
  +                char pathbuf[256];
  +
  +                getcwdpath(pathbuf, &pathCtx, CTX_ACTUAL_CWD);
  +                ret = getstat(pathCtx, path, buf, ST_STAT_BITS|ST_NAME_BIT);
  +
  +                if (ret) {
  +                    NXThreadBind (NX_THR_UNBOUND);
  +                    errno = ret;
  +                    return -1;
  +    			}
  +
  +                if (filetype_from_mode(buf->st_mode) == APR_DIR) {
  +                    dirPath = apr_pstrdup (pool, path);
  +                    len = strlen (dirPath) - strlen(buf->st_name);
  +                    dirPath[len-1] = '\0';
  +                }
  +                else if (filetype_from_mode(buf->st_mode) == APR_REG) {
  +                    dirPath = apr_pstrdup (pool, path);
  +                    ptr = strrchr (dirPath, '/');
  +                    if (ptr) {
  +                        *ptr = '\0';
  +                    }
  +                }
   
  +/* xxx Need to handle error codes here */
  +                err = NXCreatePathContext(pathCtx, dirPath, 0, NULL, &pathCtx);
  +
  +                key = apr_pstrdup (gPool, path);
  +                stat_entry = apr_palloc (gPool, sizeof(apr_stat_entry_t));
  +                memcpy (&(stat_entry->info), buf, sizeof(struct stat));
  +                stat_entry->casedName = (stat_entry->info).st_name;
  +                *casedName = apr_pstrdup(pool, stat_entry->casedName);
  +                stat_entry->expire = now;
  +                if (err == 0) {
  +                    stat_entry->pathCtx = pathCtx;
  +                }
  +                else {
  +                    stat_entry->pathCtx = 0;
  +                }
  +                apr_hash_set(statCache, key, APR_HASH_KEY_STRING, stat_entry);
  +            }
  +            else {
  +                NXDirAttrNks_t dirInfo;
  +
  +                /* If we have a path context then get the info the fast way.  Otherwise

  +                   just default to getting the stat info from stat() */
  +                if (stat_entry->pathCtx) {
  +                    ret = getstat(stat_entry->pathCtx, stat_entry->casedName, buf,

  +                                  ST_MODE_BIT|ST_ATIME_BIT|ST_MTIME_BIT|ST_CTIME_BIT|ST_SIZE_BIT|ST_NAME_BIT);
  +                }
  +                else {
  +                    char pathbuf[256];
  +                    getcwdpath(pathbuf, &pathCtx, CTX_ACTUAL_CWD);
  +                    ret = getstat(pathCtx, path, buf, 
  +                                  ST_MODE_BIT|ST_ATIME_BIT|ST_MTIME_BIT|ST_CTIME_BIT|ST_SIZE_BIT|ST_NAME_BIT);
  +                }
  +    
  +                if (ret) {
  +                    NXThreadBind (NX_THR_UNBOUND);
  +                    errno = ret;
  +                    return -1;
  +                }
  +                else {
  +                    (stat_entry->info).st_atime.tv_sec = (buf->st_atime).tv_sec;
  +                    (stat_entry->info).st_mtime.tv_sec = (buf->st_mtime).tv_sec;
  +                    (stat_entry->info).st_ctime.tv_sec = (buf->st_ctime).tv_sec;
  +                    (stat_entry->info).st_size = buf->st_size;
  +                    (stat_entry->info).st_mode = buf->st_mode;
  +                    memcpy ((stat_entry->info).st_name, buf->st_name, sizeof(buf->st_name));
  +                    memcpy (buf, &(stat_entry->info), sizeof(struct stat));
  +                }
  +
  +                /* If we do have a stat_entry then it must have expired.  Just
  +                   copy the data and reset the expiration. */
  +                *casedName = apr_pstrdup(pool, stat_entry->casedName);
  +                stat_entry->expire = now;
  +            }
  +            NXThreadBind (NX_THR_UNBOUND);
  +        }
  +    }
  +    else {
  +        getcwdpath(NULL, &pathCtx, CTX_ACTUAL_CWD);
  +        ret = getstat(pathCtx, path, buf, ST_STAT_BITS|ST_NAME_BIT);
  +        if (ret == 0) {
  +            *casedName = apr_pstrdup(pool, buf->st_name);
  +        }
  +        else {
  +            errno = ret;
  +            return -1;
  +        }
  +    }
  +    return 0;
  +}
  +#else
   int cstat (const char *path, struct stat *buf, char **casedName, apr_pool_t *pool)
   {
       apr_hash_t *statCache = (apr_hash_t *)getStatCache(CpuCurrentProcessor);
  @@ -320,6 +485,7 @@
       }
       return 0;
   }
  +#endif
   
   APR_DECLARE(apr_status_t) apr_stat(apr_finfo_t *finfo, 
                                      const char *fname, 
  
  
  
  1.26      +3 -0      apr/file_io/win32/filepath.c
  
  Index: filepath.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/filepath.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- filepath.c	10 Jul 2002 06:01:12 -0000	1.25
  +++ filepath.c	23 Oct 2002 22:21:19 -0000	1.26
  @@ -61,6 +61,9 @@
   
   #ifdef NETWARE
   #include <unistd.h>
  +#ifdef FAST_STAT
  +#include <fsio.h>
  +#endif
   #endif
   
    /* WinNT accepts several odd forms of a 'root' path.  Under Unicode
  
  
  
  1.9       +19 -0     apr/include/arch/netware/fileio.h
  
  Index: fileio.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/netware/fileio.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- fileio.h	3 Jun 2002 18:52:46 -0000	1.8
  +++ fileio.h	23 Oct 2002 22:21:19 -0000	1.9
  @@ -55,6 +55,8 @@
   #ifndef FILE_IO_H
   #define FILE_IO_H
   
  +//#define FAST_STAT
  +
   #include "apr.h"
   #include "apr_private.h"
   #include "apr_general.h"
  @@ -102,6 +104,12 @@
   #include <sys/time.h>
   #endif
   
  +#ifdef FAST_STAT
  +#include <fsio.h>
  +#else
  +#include <nks\fsio.h>
  +#endif
  +
   /* End System headers */
   
   #define APR_FILE_BUFSIZE 4096
  @@ -135,6 +143,17 @@
       DIR *dirstruct;
       struct dirent *entry;
   };
  +
  +typedef struct apr_stat_entry_t apr_stat_entry_t;
  +
  +struct apr_stat_entry_t {
  +    struct stat info;
  +    char *casedName;
  +    apr_time_t expire;
  +    NXPathCtx_t pathCtx;
  +};
  +
  +extern apr_int32_t CpuCurrentProcessor; /* system variable */
   
   #define MAX_SERVER_NAME     64
   #define MAX_VOLUME_NAME     64
  
  
  

Mime
View raw message