On Thu, 23 May 2003, Robert Collins wrote:

> I've no objection - but would like to see the patch :}.

Here is the patch with fixed (512 byte) blocksize.  I can make it
configurable.


Index: src/fs/coss/async_io.c
===================================================================
RCS file: /squid/squid/src/fs/coss/async_io.c,v
retrieving revision 1.7.2.1
diff -u -w -u -r1.7.2.1 async_io.c
--- src/fs/coss/async_io.c      21 Jul 2002 00:30:03 -0000      1.7.2.1
+++ src/fs/coss/async_io.c      29 May 2003 17:31:35 -0000
@@ -94,7 +94,7 @@

     /* Initiate aio */
     if (aio_read(&qe->aq_e_aiocb) < 0) {
-       fatalf("Aiee! aio_read() returned error (%d)!\n", errno);
+       fatalf("Aiee! aio_read() returned error: %s\n", xstrerror());
     }
 }

@@ -140,7 +140,7 @@

     /* Initiate aio */
     if (aio_write(&qe->aq_e_aiocb) < 0) {
-       fatalf("Aiee! aio_read() returned error (%d)!\n", errno);
+       fatalf("Aiee! aio_read() returned error: %s\n", xstrerror());
     }
 }

Index: src/fs/coss/store_coss.h
===================================================================
RCS file: /squid/squid/src/fs/coss/store_coss.h,v
retrieving revision 1.6
diff -u -w -u -r1.6 store_coss.h
--- src/fs/coss/store_coss.h    12 Aug 2001 10:20:41 -0000      1.6
+++ src/fs/coss/store_coss.h    29 May 2003 17:31:35 -0000
@@ -91,7 +91,7 @@
 extern STOBJUNLINK storeCossUnlink;
 extern STSYNC storeCossSync;

-extern off_t storeCossAllocate(SwapDir * SD, const StoreEntry * e, int which);
+extern sfileno storeCossAllocate(SwapDir * SD, const StoreEntry * e, int which);
 extern void storeCossAdd(SwapDir *, StoreEntry *);
 extern void storeCossRemove(SwapDir *, StoreEntry *);
 extern void storeCossStartMembuf(SwapDir * SD);
Index: src/fs/coss/store_dir_coss.c
===================================================================
RCS file: /squid/squid/src/fs/coss/store_dir_coss.c,v
retrieving revision 1.30.2.5
diff -u -w -u -r1.30.2.5 store_dir_coss.c
--- src/fs/coss/store_dir_coss.c        9 Jan 2003 03:38:41 -0000       1.30.2.5
+++ src/fs/coss/store_dir_coss.c        29 May 2003 17:31:35 -0000
@@ -336,6 +336,7 @@
     storeHashInsert(e, key);   /* do it after we clear KEY_PRIVATE */
     storeCossAdd(SD, e);
     e->swap_filen = storeCossAllocate(SD, e, COSS_ALLOC_NOTIFY);
+    assert(e->swap_filen >= 0);
     return e;
 }

Index: src/fs/coss/store_io_coss.c
===================================================================
RCS file: /squid/squid/src/fs/coss/store_io_coss.c,v
retrieving revision 1.13.2.4
diff -u -w -u -r1.13.2.4 store_io_coss.c
--- src/fs/coss/store_io_coss.c 8 Aug 2002 20:17:41 -0000       1.13.2.4
+++ src/fs/coss/store_io_coss.c 29 May 2003 17:31:35 -0000
@@ -49,6 +49,8 @@
 static CossMemBuf *storeCossCreateMemBuf(SwapDir * SD, size_t start,
     sfileno curfn, int *collision);
 static CBDUNL storeCossIOFreeEntry;
+static off_t storeCossFilenoToOffset(sfileno f);
+static sfileno storeCossOffsetToFileno(off_t o);

 CBDATA_TYPE(storeIOState);
 CBDATA_TYPE(CossMemBuf);
@@ -62,7 +64,7 @@
  * to work..
  * -- Adrian
  */
-off_t
+sfileno
 storeCossAllocate(SwapDir * SD, const StoreEntry * e, int which)
 {
     CossInfo *cs = (CossInfo *) SD->fsdata;
@@ -78,8 +80,6 @@
     else
        checkf = -1;

-    retofs = e->swap_filen;    /* Just for defaults, or while rebuilding */
-
     if (e->swap_file_sz > 0)
        allocsize = e->swap_file_sz;
     else
@@ -118,7 +118,9 @@
     if (coll == 0) {
        retofs = cs->current_offset;
        cs->current_offset = retofs + allocsize;
-       return retofs;
+       /* round up to 512 multiple */
+       cs->current_offset = ((cs->current_offset + 511) >> 9 ) << 9;
+       return storeCossOffsetToFileno(retofs);
     } else {
        debug(79, 3) ("storeCossAllocate: Collision\n");
        return -1;
@@ -159,7 +161,7 @@
     sio->st_size = objectLen(e) + e->mem_obj->swap_hdr_sz;
     sio->swap_dirn = SD->index;
     sio->swap_filen = storeCossAllocate(SD, e, COSS_ALLOC_ALLOCATE);
-    debug(79, 3) ("storeCossCreate: offset %d, size %ld, end %ld\n", sio->swap_filen, 
(long int) sio->st_size, (long int) (sio->swap_filen + sio->st_size));
+    debug(79, 3) ("storeCossCreate: offset %ld, size %ld, end %ld\n", (long int) 
storeCossFilenoToOffset(sio->swap_filen), (long int) sio->st_size, (long int) 
(sio->swap_filen + sio->st_size));

     sio->callback = callback;
     sio->file_callback = file_callback;
@@ -211,7 +213,7 @@
     cstate->flags.reading = 0;
     cstate->readbuffer = NULL;
     cstate->reqdiskoffset = -1;
-    p = storeCossMemPointerFromDiskOffset(SD, f, NULL);
+    p = storeCossMemPointerFromDiskOffset(SD, storeCossFilenoToOffset(f), NULL);
     /* make local copy so we don't have to lock membuf */
     if (p) {
        cstate->readbuffer = xmalloc(sio->st_size);
@@ -227,7 +229,7 @@
         * a place for the object here, and the file_read() reads the object
         * into the cossmembuf for later writing ..
         */
-       cstate->reqdiskoffset = sio->swap_filen;
+       cstate->reqdiskoffset = storeCossFilenoToOffset(sio->swap_filen);
        sio->swap_filen = -1;
        sio->swap_filen = storeCossAllocate(SD, e, COSS_ALLOC_REALLOC);
        if (sio->swap_filen == -1) {
@@ -291,7 +293,7 @@
     cstate->requestbuf = buf;
     cstate->requestoffset = offset;
     if (cstate->readbuffer == NULL) {
-       p = storeCossMemPointerFromDiskOffset(SD, sio->swap_filen, NULL);
+       p = storeCossMemPointerFromDiskOffset(SD, 
storeCossFilenoToOffset(sio->swap_filen), NULL);
        /* Remember we need to translate the block offset to a disk offset! */
        a_file_read(&cs->aq, cs->fd,
            p,
@@ -323,7 +325,7 @@
     assert(sio->e->mem_obj->object_sz != -1);

     debug(79, 3) ("storeCossWrite: offset %ld, len %lu\n", (long int) sio->offset, 
(unsigned long int) size);
-    diskoffset = sio->swap_filen + sio->offset;
+    diskoffset = storeCossFilenoToOffset(sio->swap_filen) + sio->offset;
     dest = storeCossMemPointerFromDiskOffset(SD, diskoffset, &membuf);
     assert(dest != NULL);
     xmemcpy(dest, buf, size);
@@ -355,7 +357,7 @@
     } else {
        if (cstate->readbuffer == NULL) {
            cstate->readbuffer = xmalloc(sio->st_size);
-           p = storeCossMemPointerFromDiskOffset(SD, sio->swap_filen, NULL);
+           p = storeCossMemPointerFromDiskOffset(SD, 
storeCossFilenoToOffset(sio->swap_filen), NULL);
            xmemcpy(cstate->readbuffer, p, sio->st_size);
            storeCossMemBufUnlock(SD, sio);
        }
@@ -412,10 +414,11 @@
     CossMemBuf *t;
     dlink_node *m;
     CossInfo *cs = (CossInfo *) SD->fsdata;
+    off_t o = storeCossFilenoToOffset(e->swap_filen);

     for (m = cs->membufs.head; m; m = m->next) {
        t = m->data;
-       if ((e->swap_filen >= t->diskstart) && (e->swap_filen <= t->diskend)) {
+       if ((o >= t->diskstart) && (o <= t->diskend)) {
            debug(79, 3) ("storeCossMemBufLock: locking %p, lockcount %d\n", t, 
t->lockcount);
            t->lockcount++;
            return;
@@ -430,6 +433,7 @@
     CossMemBuf *t;
     dlink_node *m, *n;
     CossInfo *cs = (CossInfo *) SD->fsdata;
+    off_t o = storeCossFilenoToOffset(e->swap_filen);

     for (m = cs->membufs.head; m; m = n) {
        /*
@@ -439,7 +443,7 @@
         */
        n = m->next;
        t = m->data;
-       if ((e->swap_filen >= t->diskstart) && (e->swap_filen <= t->diskend)) {
+       if ((o >= t->diskstart) && (o <= t->diskend)) {
            t->lockcount--;
            debug(79, 3) ("storeCossMemBufUnlock: unlocking %p, lockcount %d\n", t, 
t->lockcount);
        }
@@ -532,12 +536,14 @@
      * Kill objects from the tail to make space for a new chunk
      */
     for (m = cs->index.tail; m; m = prev) {
+       off_t o;
        prev = m->prev;
        e = m->data;
+       o = storeCossFilenoToOffset(e->swap_filen);
        if (curfn == e->swap_filen)
            *collision = 1;     /* Mark an object alloc collision */
-       if ((e->swap_filen >= newmb->diskstart) &&
-           (e->swap_filen <= newmb->diskend)) {
+       if ((o >= newmb->diskstart) &&
+           (o <= newmb->diskend)) {
            storeRelease(e);
            numreleased++;
        } else
@@ -567,4 +573,17 @@
 storeCossIOFreeEntry(void *sio)
 {
     memPoolFree(coss_state_pool, ((storeIOState *) sio)->fsstate);
+}
+
+static off_t
+storeCossFilenoToOffset(sfileno f)
+{
+       return f << 9;
+}
+
+static sfileno
+storeCossOffsetToFileno(off_t o)
+{
+       assert(0 == (o & 511));
+       return o >> 9;
 }

Reply via email to