apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr-util/dbm/sdbm sdbm.c
Date Mon, 30 Apr 2001 19:03:50 GMT
wrowe       01/04/30 12:03:49

  Modified:    include  apr_file_io.h
               .        CHANGES
               dbm/sdbm sdbm.c
  Log:
    shared sdbm file locking patch, writes/deletes require an excl lock,
    read/getkeys require a shared lock
  
  Revision  Changes    Path
  1.99      +4 -1      apr/include/apr_file_io.h
  
  Index: apr_file_io.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_file_io.h,v
  retrieving revision 1.98
  retrieving revision 1.99
  diff -u -r1.98 -r1.99
  --- apr_file_io.h	2001/03/29 09:45:39	1.98
  +++ apr_file_io.h	2001/04/30 19:03:38	1.99
  @@ -81,11 +81,14 @@
   #define APR_TRUNCATE   16          /* Open the file and truncate to 0 length */
   #define APR_BINARY     32          /* Open the file in binary mode */
   #define APR_EXCL       64          /* Open should fail if APR_CREATE and file
  -				    exists. */
  +				      exists. */
   #define APR_BUFFERED   128         /* Open the file for buffered I/O */
   #define APR_DELONCLOSE 256         /* Delete the file after close */
   #define APR_XTHREAD    512         /* Platform dependent tag to open the file 
                                         for use across multiple threads */
  +#define APR_SHARELOCK  1024        /* Platform dependent support for higher
  +                                      level locked read/write access to support
  +                                      writes across process/machines */
   
   /* flags for apr_file_seek */
   #define APR_SET SEEK_SET
  
  
  
  1.14      +3 -0      apr-util/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr-util/CHANGES,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- CHANGES	2001/04/30 17:16:07	1.13
  +++ CHANGES	2001/04/30 19:03:43	1.14
  @@ -1,5 +1,8 @@
   Changes with APR-util b1  
   
  +  *) Add APR_SHARELOCK support to apr_sdbm_open(), locking read operations
  +     with a shared lock and all write ops with an excl lock.  [Will Rowe]
  +
     *) Namespace protect apr_sdbm, and normalize the return values (including
        the apr_sdbm_fetch, apr_sdbm_firstkey and apr_sdbm_nextkey functions).
        Normalized the get/clear error function names, and stores the actual 
  
  
  
  1.14      +96 -35    apr-util/dbm/sdbm/sdbm.c
  
  Index: sdbm.c
  ===================================================================
  RCS file: /home/cvs/apr-util/dbm/sdbm/sdbm.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- sdbm.c	2001/04/30 17:16:17	1.13
  +++ sdbm.c	2001/04/30 19:03:47	1.14
  @@ -116,7 +116,8 @@
       apr_sdbm_t *db = data;
   
       (void) apr_file_close(db->dirf);
  -    (void) sdbm_unlock(db);
  +    if (!(db->flags & SDBM_SHARED))
  +        (void) sdbm_unlock(db);
       (void) apr_file_close(db->pagf);
       free(db);
   
  @@ -146,8 +147,17 @@
           db->flags = SDBM_RDONLY;
       }
   
  -    flags |= APR_BINARY | APR_READ;
  +    /*
  +     * adjust user flags so that SHARELOCK isn't used within
  +     * APR (if it's ever implemented) since we will perform
  +     * that locking here.
  +     */
  +    if (flags & APR_SHARELOCK) {
  +        flags &= ~APR_SHARELOCK;
  +        db->flags |= SDBM_SHARED;
  +    }
   
  +    flags |= APR_BINARY | APR_READ;
       /*
        * open the files in sequence, and stat the dirfile.
        * If we fail anywhere, undo everything, return NULL.
  @@ -166,6 +176,13 @@
           goto error;
   
       /*
  +     * if we are opened in SHARED mode, unlock ourself 
  +     */
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            goto error;
  +
  +    /*
        * need the dirfile size to establish max bit number.
        */
       if ((status = apr_file_info_get(&finfo, APR_FINFO_SIZE, db->dirf)) 
  @@ -222,13 +239,21 @@
       if (db == NULL || bad(key))
           return APR_EINVAL;
   
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_lock(db, 0)) != APR_SUCCESS)
  +            return ioerr(db, status);
  +
       if ((status = getpage(db, exhash(key))) == APR_SUCCESS) {
           *val = getpair(db->pagbuf, key);
  -        /* ### do we want a not-found result? */
  -        return APR_SUCCESS;
  +        /* ### do we want a not-found status result? */
       }
  +    else
  +        ioerr(db, status);
  +
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            ioerr(db, status);
   
  -    ioerr(db, status);
       return status;
   }
   
  @@ -240,8 +265,7 @@
       if ((status = apr_file_seek(db->pagf, APR_SET, &off)) != APR_SUCCESS ||
           (status = apr_file_write_full(db->pagf, buf, PBLKSIZ, NULL)) 
                   != APR_SUCCESS) {
  -        ioerr(db, status);
  -        return status;
  +        return ioerr(db, status);
       }
       
       return APR_SUCCESS;
  @@ -256,22 +280,28 @@
       if (apr_sdbm_rdonly(db))
           return APR_EINVAL;
   
  -    if ((status = getpage(db, exhash(key))) == APR_SUCCESS) {
  -        if (!delpair(db->pagbuf, key))
  -            /* ### should we define some APRUTIL codes? */
  -            return APR_EGENERAL;
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_lock(db, 1)) != APR_SUCCESS)
  +            return ioerr(db, status);
   
  +    if ((status = getpage(db, exhash(key))) == APR_SUCCESS) {
           /*
  -         * update the page file
  +         * remove the key and update the page file
            */
  -        if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  -            return status;
  -
  -        return APR_SUCCESS;
  +        if (!delpair(db->pagbuf, key))
  +            /* ### should we define some APRUTIL codes? */
  +            status = APR_EGENERAL;
  +        else
  +            status = write_page(db, db->pagbuf, db->pagbno);
       }
  +    else
  +        ioerr(db, status);
   
  -    ioerr(db, status);
  -    return APR_EACCES;
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            return ioerr(db, status);
  +
  +    return status;
   }
   
   apr_status_t apr_sdbm_store(apr_sdbm_t *db, apr_sdbm_datum_t key, 
  @@ -293,6 +323,10 @@
       if (need < 0 || need > PAIRMAX)
           return APR_EINVAL;
   
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_lock(db, 1)) != APR_SUCCESS)
  +            return ioerr(db, status);
  +
       if ((status = getpage(db, (hash = exhash(key)))) == APR_SUCCESS) {
   
           /*
  @@ -301,27 +335,32 @@
            */
           if (flags == APR_SDBM_REPLACE)
               (void) delpair(db->pagbuf, key);
  -        else if (!(flags & APR_SDBM_INSERTDUP) && duppair(db->pagbuf, key))
  -            return APR_EEXIST;
  +        else if (!(flags & APR_SDBM_INSERTDUP) && duppair(db->pagbuf, key))
{
  +            status = ioerr(db, APR_EEXIST);
  +            goto error;
  +        }
           /*
            * if we do not have enough room, we have to split.
            */
           if (!fitpair(db->pagbuf, need))
  -            if ((status = makroom(db, hash, need)) != APR_SUCCESS)
  -                return status;
  +            if ((status = makroom(db, hash, need)) != APR_SUCCESS) {
  +                ioerr(db, status);
  +                goto error;
  +            }
           /*
            * we have enough room or split is successful. insert the key,
            * and update the page file.
            */
           (void) putpair(db->pagbuf, key, val);
   
  -        if ((status = write_page(db, db->pagbuf, db->pagbno)) != APR_SUCCESS)
  -            return status;
  -
  -        return APR_SUCCESS;
  +        status = write_page(db, db->pagbuf, db->pagbno);
       }
  -    
  -    ioerr(db, status);
  +
  +error:
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            ioerr(db, status);
  +
       return status;
   }
   
  @@ -433,26 +472,48 @@
    */
   apr_status_t apr_sdbm_firstkey(apr_sdbm_t *db, apr_sdbm_datum_t *key)
   {
  +    apr_status_t status;
  +
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_lock(db, 0)) != APR_SUCCESS)
  +            return ioerr(db, status);
  +
       /*
        * start at page 0
        */
  -    apr_status_t status;
       if ((status = read_from(db->pagf, db->pagbuf, OFF_PAG(0), PBLKSIZ))
                   != APR_SUCCESS) {
           ioerr(db, status);
  -        return status;
  +    }
  +    else {
  +        db->pagbno = 0;
  +        db->blkptr = 0;
  +        db->keyptr = 0;
  +        status = getnext(key, db);
       }
   
  -    db->pagbno = 0;
  -    db->blkptr = 0;
  -    db->keyptr = 0;
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            ioerr(db, status);
   
  -    return getnext(key, db);
  +    return status;
   }
   
   apr_status_t apr_sdbm_nextkey(apr_sdbm_t *db, apr_sdbm_datum_t *key)
   {
  -    return getnext(key, db);
  +    apr_status_t status;
  +
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_lock(db, 0)) != APR_SUCCESS)
  +            return ioerr(db, status);
  +
  +    status = getnext(key, db);
  +
  +    if (db->flags & SDBM_SHARED)
  +        if ((status = sdbm_unlock(db)) != APR_SUCCESS)
  +            ioerr(db, status);
  +
  +    return status;
   }
   
   /*
  
  
  

Mime
View raw message