--------------------- PatchSet 391 Date: 2002/12/15 06:06:54 Author: rbcollins Branch: unify-io Tag: (none) Log: move fields to CossSwapDir Members: src/fs/coss/store_coss.h:1.3.10.28->1.3.10.29 src/fs/coss/store_dir_coss.cc:1.4.10.35->1.4.10.36 src/fs/coss/store_io_coss.cc:1.3.10.15->1.3.10.16 Index: squid3/src/fs/coss/store_coss.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_coss.h,v retrieving revision 1.3.10.28 retrieving revision 1.3.10.29 diff -u -r1.3.10.28 -r1.3.10.29 --- squid3/src/fs/coss/store_coss.h 15 Dec 2002 02:34:36 -0000 1.3.10.28 +++ squid3/src/fs/coss/store_coss.h 15 Dec 2002 06:06:54 -0000 1.3.10.29 @@ -41,8 +41,7 @@ dlink_list membufs; struct _cossmembuf *current_membuf; size_t current_offset; /* in Blocks */ - int fd; - int swaplog_fd; + //int swaplog_fd; int numcollisions; dlink_list index; int count; @@ -99,6 +98,7 @@ class CossSwapDir : public SwapDir { public: + CossSwapDir(); virtual void init(); virtual void newFileSystem(); virtual void dump(StoreEntry &)const; @@ -116,6 +116,9 @@ virtual void writeCleanDone(); virtual void logEntry(const StoreEntry & e, int op) const; virtual void parse (int index, char *path); +//private: + int fd; + int swaplog_fd; }; extern off_t storeCossAllocate(SwapDir * SD, const StoreEntry * e, int which); Index: squid3/src/fs/coss/store_dir_coss.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_dir_coss.cc,v retrieving revision 1.4.10.35 retrieving revision 1.4.10.36 diff -u -r1.4.10.35 -r1.4.10.36 --- squid3/src/fs/coss/store_dir_coss.cc 15 Dec 2002 02:34:36 -0000 1.4.10.35 +++ squid3/src/fs/coss/store_dir_coss.cc 15 Dec 2002 06:06:54 -0000 1.4.10.36 @@ -1,6 +1,6 @@ /* - * $Id: store_dir_coss.cc,v 1.4.10.35 2002/12/15 02:34:36 rbcollins Exp $ + * $Id: store_dir_coss.cc,v 1.4.10.36 2002/12/15 06:06:54 rbcollins Exp $ * * DEBUG: section 47 Store COSS Directory Routines * AUTHOR: Eric Stern @@ -50,7 +50,7 @@ typedef struct _RebuildState RebuildState; struct _RebuildState { - SwapDir *sd; + CossSwapDir *sd; int n_read; FILE *log; int speed; @@ -72,9 +72,9 @@ u_int32_t refcount, u_int16_t flags, int clean); -static void storeCossDirRebuild(SwapDir * sd); -static void storeCossDirCloseTmpSwapLog(SwapDir * sd); -static FILE *storeCossDirOpenTmpSwapLog(SwapDir *, int *, int *); +static void storeCossDirRebuild(CossSwapDir * sd); +static void storeCossDirCloseTmpSwapLog(CossSwapDir * sd); +static FILE *storeCossDirOpenTmpSwapLog(CossSwapDir *, int *, int *); static STFSRECONFIGURE storeCossDirReconfigure; /* The "only" externally visible function */ @@ -113,29 +113,25 @@ void CossSwapDir::openLog() { - CossInfo *cs = (CossInfo *) fsdata; char *logPath; - int fd; logPath = storeCossDirSwapLogFile(this, NULL); - fd = file_open(logPath, O_WRONLY | O_CREAT | O_BINARY); - if (fd < 0) { + swaplog_fd = file_open(logPath, O_WRONLY | O_CREAT | O_BINARY); + if (swaplog_fd < 0) { debug(47, 1) ("%s: %s\n", logPath, xstrerror()); fatal("storeCossDirOpenSwapLog: Failed to open swap log."); } - debug(47, 3) ("Cache COSS Dir #%d log opened on FD %d\n", index, fd); - cs->swaplog_fd = fd; + debug(47, 3) ("Cache COSS Dir #%d log opened on FD %d\n", index, swaplog_fd); } void CossSwapDir::closeLog() { - CossInfo *cs = (CossInfo *) fsdata; - if (cs->swaplog_fd < 0) /* not open */ + if (swaplog_fd < 0) /* not open */ return; - file_close(cs->swaplog_fd); + file_close(swaplog_fd); debug(47, 3) ("Cache COSS Dir #%d log closed on FD %d\n", - index, cs->swaplog_fd); - cs->swaplog_fd = -1; + index, swaplog_fd); + swaplog_fd = -1; } void @@ -145,8 +141,8 @@ a_file_setupqueue(&cs->aq); openLog(); storeCossDirRebuild(this); - cs->fd = file_open(path, O_RDWR | O_CREAT); - if (cs->fd < 0) { + fd = file_open(path, O_RDWR | O_CREAT); + if (fd < 0) { debug(47, 1) ("%s: %s\n", path, xstrerror()); fatal("storeCossDirInit: Failed to open a COSS directory."); } @@ -327,7 +323,7 @@ CBDATA_TYPE(RebuildState); static void -storeCossDirRebuild(SwapDir * sd) +storeCossDirRebuild(CossSwapDir * sd) { RebuildState *rb; int clean = 0; @@ -370,13 +366,12 @@ } static void -storeCossDirCloseTmpSwapLog(SwapDir * sd) +storeCossDirCloseTmpSwapLog(CossSwapDir * sd) { - CossInfo *cs = (CossInfo *) sd->fsdata; char *swaplog_path = xstrdup(storeCossDirSwapLogFile(sd, NULL)); char *new_path = xstrdup(storeCossDirSwapLogFile(sd, ".new")); - int fd; - file_close(cs->swaplog_fd); + int anfd; + file_close(sd->swaplog_fd); #if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_) if (unlink(swaplog_path) < 0) { debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); @@ -386,28 +381,27 @@ if (xrename(new_path, swaplog_path) < 0) { fatal("storeCossDirCloseTmpSwapLog: rename failed"); } - fd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY); - if (fd < 0) { + anfd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY); + if (anfd < 0) { debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror()); fatal("storeCossDirCloseTmpSwapLog: Failed to open swap log."); } safe_free(swaplog_path); safe_free(new_path); - cs->swaplog_fd = fd; - debug(47, 3) ("Cache COSS Dir #%d log opened on FD %d\n", sd->index, fd); + sd->swaplog_fd = anfd; + debug(47, 3) ("Cache COSS Dir #%d log opened on FD %d\n", sd->index, anfd); } static FILE * -storeCossDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag) +storeCossDirOpenTmpSwapLog(CossSwapDir * sd, int *clean_flag, int *zero_flag) { - CossInfo *cs = (CossInfo *) sd->fsdata; char *swaplog_path = xstrdup(storeCossDirSwapLogFile(sd, NULL)); char *clean_path = xstrdup(storeCossDirSwapLogFile(sd, ".last-clean")); char *new_path = xstrdup(storeCossDirSwapLogFile(sd, ".new")); struct stat log_sb; struct stat clean_sb; FILE *fp; - int fd; + int anfd; if (stat(swaplog_path, &log_sb) < 0) { debug(50, 1) ("Cache COSS Dir #%d: No log file\n", sd->index); safe_free(swaplog_path); @@ -417,15 +411,15 @@ } *zero_flag = log_sb.st_size == 0 ? 1 : 0; /* close the existing write-only FD */ - if (cs->swaplog_fd >= 0) - file_close(cs->swaplog_fd); + if (sd->swaplog_fd >= 0) + file_close(sd->swaplog_fd); /* open a write-only FD for the new log */ - fd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); - if (fd < 0) { + anfd = file_open(new_path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY); + if (anfd < 0) { debug(50, 1) ("%s: %s\n", new_path, xstrerror()); fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); } - cs->swaplog_fd = fd; + sd->swaplog_fd = anfd; /* open a read-only stream of the old log */ fp = fopen(swaplog_path, "rb"); if (fp == NULL) { @@ -559,7 +553,6 @@ void CossSwapDir::writeCleanDone() { - int fd; CossCleanLog *state = (CossCleanLog *)cleanLog; if (NULL == state) return; @@ -581,7 +574,7 @@ */ closeLog(); /* save the fd value for a later test */ - fd = state->fd; + int anfd = state->fd; /* rename */ if (state->fd >= 0) { #if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_) @@ -596,7 +589,7 @@ /* touch a timestamp file if we're not still validating */ if (store_dirs_rebuilding) (void) 0; - else if (fd < 0) + else if (anfd < 0) (void) 0; else file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY)); @@ -620,7 +613,6 @@ void CossSwapDir::logEntry(const StoreEntry & e, int op) const { - CossInfo *cs = (CossInfo *) fsdata; storeSwapLogData *s = (storeSwapLogData *)memAllocate(MEM_SWAP_LOG_DATA); s->op = (char) op; s->swap_filen = e.swap_filen; @@ -632,7 +624,7 @@ s->refcount = e.refcount; s->flags = e.flags; xmemcpy(s->key, e.key, MD5_DIGEST_CHARS); - file_write(cs->swaplog_fd, + file_write(swaplog_fd, -1, s, sizeof(storeSwapLogData), @@ -655,8 +647,8 @@ sync(); /* This'll call a_file_syncqueue() */ a_file_closequeue(&cs->aq); - file_close(cs->fd); - cs->fd = -1; + file_close(fd); + fd = -1; closeLog(); n_coss_dirs--; @@ -746,12 +738,7 @@ max_size = size; fsdata = cs; - cs->fd = -1; - cs->swaplog_fd = -1; - cs->current_offset = 0; - cs->fd = -1; - cs->swaplog_fd = -1; cs->numcollisions = 0; cs->membufs.head = cs->membufs.tail = NULL; /* set when the rebuild completes */ cs->current_membuf = NULL; @@ -854,6 +841,10 @@ return result; } +CossSwapDir::CossSwapDir() : fd (-1), swaplog_fd(-1) +{ +} + void storeFsSetup_coss(storefs_entry_t * storefs) { Index: squid3/src/fs/coss/store_io_coss.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/fs/coss/store_io_coss.cc,v retrieving revision 1.3.10.15 retrieving revision 1.3.10.16 diff -u -r1.3.10.15 -r1.3.10.16 --- squid3/src/fs/coss/store_io_coss.cc 14 Dec 2002 00:54:29 -0000 1.3.10.15 +++ squid3/src/fs/coss/store_io_coss.cc 15 Dec 2002 06:06:55 -0000 1.3.10.16 @@ -1,6 +1,6 @@ /* - * $Id: store_io_coss.cc,v 1.3.10.15 2002/12/14 00:54:29 rbcollins Exp $ + * $Id: store_io_coss.cc,v 1.3.10.16 2002/12/15 06:06:55 rbcollins Exp $ * * DEBUG: section 79 Storage Manager COSS Interface * AUTHOR: Eric Stern @@ -47,7 +47,7 @@ static void storeCossMemBufLock(SwapDir * SD, storeIOState * e); static void storeCossMemBufUnlock(SwapDir * SD, storeIOState * e); static void storeCossWriteMemBuf(SwapDir * SD, CossMemBuf * t); -static void storeCossWriteMemBufDone(int fd, int errflag, size_t len, void *my_data); +static void storeCossWriteMemBufDone(int, int errflag, size_t len, void *my_data); static CossMemBuf *storeCossCreateMemBuf(SwapDir * SD, size_t start, sfileno curfn, int *collision); @@ -285,7 +285,7 @@ CossState::read_(char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data) { char *p; - SwapDir *SD = INDEXSD(swap_dirn); + CossSwapDir *SD = (CossSwapDir *)INDEXSD(swap_dirn); CossInfo *cs = (CossInfo *) SD->fsdata; assert(read.callback == NULL); @@ -303,7 +303,7 @@ if (readbuffer == NULL) { p = storeCossMemPointerFromDiskOffset(SD, swap_filen, NULL); /* Remember we need to translate the block offset to a disk offset! */ - a_file_read(&cs->aq, cs->fd, + a_file_read(&cs->aq, SD->fd, p, st_size, reqdiskoffset, @@ -311,7 +311,7 @@ this); reqdiskoffset = 0; /* XXX */ } else { - storeCossReadDone(cs->fd, + storeCossReadDone(SD->fd, readbuffer, st_size, 0, @@ -347,7 +347,7 @@ /* === STATIC =========================================================== */ static void -storeCossReadDone(int fd, const char *buf, int len, int errflag, void *my_data) +storeCossReadDone(int rvfd, const char *buf, int len, int errflag, void *my_data) { storeIOState *sio = (storeIOState *)my_data; char *p; @@ -358,7 +358,7 @@ ssize_t rlen; debug(79, 3) ("storeCossReadDone: fileno %d, FD %d, len %d\n", - sio->swap_filen, fd, len); + sio->swap_filen, rvfd, len); cstate->flags.reading = 0; if (errflag) { debug(79, 3) ("storeCossReadDone: got failure (%d)\n", errflag); @@ -476,27 +476,28 @@ t = (CossMemBuf *)m->data; if (t->flags.writing) sleep(5); /* XXX EEEWWW! */ - lseek(cs->fd, t->diskstart, SEEK_SET); + lseek(fd, t->diskstart, SEEK_SET); end = (t == cs->current_membuf) ? cs->current_offset : t->diskend; - FD_WRITE_METHOD(cs->fd, t->buffer, end - t->diskstart); + FD_WRITE_METHOD(fd, t->buffer, end - t->diskstart); } } static void storeCossWriteMemBuf(SwapDir * SD, CossMemBuf * t) { + CossSwapDir * sd = (CossSwapDir *)SD; CossInfo *cs = (CossInfo *) SD->fsdata; debug(79, 3) ("storeCossWriteMemBuf: offset %ld, len %ld\n", (long int) t->diskstart, (long int) (t->diskend - t->diskstart)); t->flags.writing = 1; /* Remember that diskstart/diskend are block offsets! */ - a_file_write(&cs->aq, cs->fd, t->diskstart, &t->buffer, + a_file_write(&cs->aq, sd->fd, t->diskstart, &t->buffer, t->diskend - t->diskstart, storeCossWriteMemBufDone, t, NULL); } static void -storeCossWriteMemBufDone(int fd, int errflag, size_t len, void *my_data) +storeCossWriteMemBufDone(int rvfd, int errflag, size_t len, void *my_data) { CossMemBuf *t = (CossMemBuf *)my_data; CossInfo *cs = (CossInfo *) t->SD->fsdata;