From: wessels <> Date: Tue, 4 May 1999 04:41:09 +0000 (+0000) Subject: split a bunch of FS-dependent stuff from store_dir.c into store_dir_ufs.c, X-Git-Tag: SQUID_3_0_PRE1~2231 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=95dcd2b8dd0efdc96589997f76b967c5ffb95a4a;p=thirdparty%2Fsquid.git split a bunch of FS-dependent stuff from store_dir.c into store_dir_ufs.c, but its probably not really enough. --- diff --git a/src/Makefile.in b/src/Makefile.in index f6726e2825..3fe6b42175 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.171 1999/05/03 21:54:55 wessels Exp $ +# $Id: Makefile.in,v 1.172 1999/05/03 22:41:09 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -158,6 +158,7 @@ OBJS = \ store_client.o \ store_digest.o \ store_dir.o \ + store_dir_ufs.o \ store_key_md5.o \ store_log.o \ store_rebuild.o \ diff --git a/src/protos.h b/src/protos.h index fcf588b83b..dd5f92aa16 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,7 +1,7 @@ /* - * $Id: protos.h,v 1.325 1999/05/03 21:55:03 wessels Exp $ - * $Id: protos.h,v 1.325 1999/05/03 21:55:03 wessels Exp $ + * $Id: protos.h,v 1.326 1999/05/03 22:41:10 wessels Exp $ + * $Id: protos.h,v 1.326 1999/05/03 22:41:10 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -850,20 +850,20 @@ extern int storeTooManyDiskFilesOpen(void); extern void storeEntryReset(StoreEntry *); /* store_io.c */ -extern storeIOState *storeOpen(sfileno f, mode_t mode, STIOCB *callback, void *callback_data); -extern void storeClose(storeIOState *sio); -extern void storeRead(storeIOState *sio, char *buf, size_t size, off_t offset, STRCB *callback, void *callback_data); -extern void storeWrite(storeIOState *sio, char *buf, size_t size, off_t offset); +extern storeIOState *storeOpen(sfileno f, mode_t mode, STIOCB * callback, void *callback_data); +extern void storeClose(storeIOState * sio); +extern void storeRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data); +extern void storeWrite(storeIOState * sio, char *buf, size_t size, off_t offset); extern void storeUnlink(int fileno); extern off_t storeOffset(storeIOState *); /* store_io_ufs.c */ -extern storeIOState *storeUfsOpen(sfileno f, mode_t mode, STIOCB *callback, void *callback_data); -extern void storeUfsClose(storeIOState *sio); -extern void storeUfsRead(storeIOState *sio, char *buf, size_t size, off_t offset, STRCB *callback, void *callback_data); -extern void storeUfsWrite(storeIOState *sio, char *buf, size_t size, off_t offset); +extern storeIOState *storeUfsOpen(sfileno f, mode_t mode, STIOCB * callback, void *callback_data); +extern void storeUfsClose(storeIOState * sio); +extern void storeUfsRead(storeIOState * sio, char *buf, size_t size, off_t offset, STRCB * callback, void *callback_data); +extern void storeUfsWrite(storeIOState * sio, char *buf, size_t size, off_t offset); extern void storeUfsUnlink(int fileno); -extern char *storeUfsFullPath(sfileno fn, char *fullpath); /* XXX want this to be static */ +extern char *storeUfsFullPath(sfileno fn, char *fullpath); /* XXX want this to be static */ /* * store_log.c @@ -905,33 +905,46 @@ extern void storeDigestReport(StoreEntry *); /* * store_dir.c */ +extern OBJH storeDirStats; +extern char *storeDirSwapLogFile(int, const char *); +extern char *storeSwapDir(int); extern char *storeSwapFullPath(int, char *); extern char *storeSwapSubSubDir(int, char *); -extern int storeVerifySwapDirs(void); extern const char *storeSwapPath(int); -extern int storeDirMapBitTest(int fn); -extern void storeDirMapBitSet(int fn); -extern void storeDirMapBitReset(int fn); extern int storeDirMapAllocate(void); -extern char *storeSwapDir(int); -extern FILE *storeDirOpenTmpSwapLog(int dirn, int *clean, int *zero); -extern void storeDirCloseTmpSwapLog(int dirn); -extern void storeDirOpenSwapLogs(void); -extern void storeDirCloseSwapLogs(void); -extern char *storeDirSwapLogFile(int, const char *); -extern void storeDirSwapLog(const StoreEntry *, int op); +extern int storeDirMapBitTest(int fn); +extern int storeDirMapBitsInUse(void); extern int storeDirNumber(int fileno); -extern void storeDirUpdateSwapSize(int fn, size_t size, int sign); extern int storeDirProperFileno(int dirn, int fn); -extern void storeCreateSwapDirectories(void); -extern int storeVerifyCacheDirs(void); -extern int storeDirWriteCleanLogs(int reopen); extern int storeDirValidFileno(int fn); -extern int storeFilenoBelongsHere(int, int, int, int); -extern OBJH storeDirStats; -extern int storeDirMapBitsInUse(void); +extern int storeDirWriteCleanLogs(int reopen); +extern int storeVerifyCacheDirs(void); +extern int storeVerifySwapDirs(void); +extern void storeCreateSwapDirectories(void); +extern void storeDirCloseSwapLogs(void); +extern void storeDirCloseTmpSwapLog(int dirn); extern void storeDirConfigure(void); extern void storeDirDiskFull(int fn); +extern void storeDirMapBitReset(int fn); +extern void storeDirMapBitSet(int fn); +extern void storeDirOpenSwapLogs(void); +extern void storeDirSwapLog(const StoreEntry *, int op); +extern void storeDirUpdateSwapSize(int fn, size_t size, int sign); + +/* + * store_dir_ufs.c + */ +extern FILE *storeUfsDirOpenTmpSwapLog(int dirn, int *clean, int *zero); +extern OBJH storeUfsDirStats; +extern char *storeUfsDirSwapLogFile(int, const char *); +extern int storeUfsDirWriteCleanLogs(int reopen); +extern int storeUfsFilenoBelongsHere(int, int, int, int); +extern int storeUfsVerifyCacheDirs(void); +extern void storeUfsCreateSwapDirectories(void); +extern void storeUfsDirCloseSwapLogs(void); +extern void storeUfsDirCloseTmpSwapLog(int dirn); +extern void storeUfsDirOpenSwapLogs(void); +extern void storeUfsDirSwapLog(const StoreEntry *, int op); /* diff --git a/src/squid.h b/src/squid.h index 1dfbd3b902..c176731602 100644 --- a/src/squid.h +++ b/src/squid.h @@ -1,7 +1,7 @@ /* - * $Id: squid.h,v 1.190 1999/04/26 21:52:39 glenn Exp $ - * $Id: squid.h,v 1.190 1999/04/26 21:52:39 glenn Exp $ + * $Id: squid.h,v 1.191 1999/05/03 22:41:11 wessels Exp $ + * $Id: squid.h,v 1.191 1999/05/03 22:41:11 wessels Exp $ * * AUTHOR: Duane Wessels * @@ -397,4 +397,7 @@ struct rusage { #define SQUID_NONBLOCK O_NDELAY #endif +#define SWAP_DIR_SHIFT 24 +#define SWAP_FILE_MASK 0x00FFFFFF + #endif /* SQUID_H */ diff --git a/src/store_dir.cc b/src/store_dir.cc index 15778e1ed0..dea107c8d8 100644 --- a/src/store_dir.cc +++ b/src/store_dir.cc @@ -1,7 +1,7 @@ /* - * $Id: store_dir.cc,v 1.87 1999/05/03 21:55:09 wessels Exp $ - * $Id: store_dir.cc,v 1.87 1999/05/03 21:55:09 wessels Exp $ + * $Id: store_dir.cc,v 1.88 1999/05/03 22:41:13 wessels Exp $ + * $Id: store_dir.cc,v 1.88 1999/05/03 22:41:13 wessels Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -35,124 +35,11 @@ */ #include "squid.h" -#if HAVE_STATVFS -#if HAVE_SYS_STATVFS_H -#include -#endif -#endif - -#define SWAP_DIR_SHIFT 24 -#define SWAP_FILE_MASK 0x00FFFFFF -#define DefaultLevelOneDirs 16 -#define DefaultLevelTwoDirs 256 - -static char *storeSwapSubDir(int dirn, int subdirn); -static int storeDirSelectSwapDir(void); -static int storeVerifyDirectory(const char *path); -static int storeCreateDirectory(const char *path, int); -static void storeCreateSwapSubDirs(int j); char * storeSwapFullPath(sfileno f, char *buf) { - return storeUfsFullPath(f, buf); -} - -static char * -storeSwapSubDir(int dirn, int subdirn) -{ - LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); - SwapDir *SD; - assert(0 <= dirn && dirn < Config.cacheSwap.n_configured); - SD = &Config.cacheSwap.swapDirs[dirn]; - assert(0 <= subdirn && subdirn < SD->l1); - snprintf(fullfilename, SQUID_MAXPATHLEN, "%s/%02X", - Config.cacheSwap.swapDirs[dirn].path, - subdirn); - return fullfilename; -} - -char * -storeSwapSubSubDir(int fn, char *fullpath) -{ - LOCAL_ARRAY(char, fullfilename, SQUID_MAXPATHLEN); - int dirn = (fn >> SWAP_DIR_SHIFT) % Config.cacheSwap.n_configured; - int filn = fn & SWAP_FILE_MASK; - int L1 = Config.cacheSwap.swapDirs[dirn].l1; - int L2 = Config.cacheSwap.swapDirs[dirn].l2; - if (!fullpath) - fullpath = fullfilename; - fullpath[0] = '\0'; - snprintf(fullpath, SQUID_MAXPATHLEN, "%s/%02X/%02X", - Config.cacheSwap.swapDirs[dirn].path, - ((filn / L2) / L2) % L1, - (filn / L2) % L2); - return fullpath; -} - -/* - * Does swapfile number 'fn' belong in cachedir #F0, - * level1 dir #F1, level2 dir #F2? - * - * This is called by storeDirClean(), but placed here because - * the algorithm needs to match storeSwapSubSubDir(). - * - * Don't check that (fn >> SWAP_DIR_SHIFT) == F0 because - * 'fn' may not have the directory bits set. - */ -int -storeFilenoBelongsHere(int fn, int F0, int F1, int F2) -{ - int D1, D2; - int L1, L2; - int filn = fn & SWAP_FILE_MASK; - assert(F0 < Config.cacheSwap.n_configured); - L1 = Config.cacheSwap.swapDirs[F0].l1; - L2 = Config.cacheSwap.swapDirs[F0].l2; - D1 = ((filn / L2) / L2) % L1; - if (F1 != D1) - return 0; - D2 = (filn / L2) % L2; - if (F2 != D2) - return 0; - return 1; -} - -static int -storeCreateDirectory(const char *path, int should_exist) -{ - int created = 0; - struct stat st; - getCurrentTime(); - if (0 == stat(path, &st)) { - if (S_ISDIR(st.st_mode)) { - debug(20, should_exist ? 3 : 1) ("%s exists\n", path); - } else { - fatalf("Swap directory %s is not a directory.", path); - } - } else if (0 == mkdir(path, 0755)) { - debug(20, should_exist ? 1 : 3) ("%s created\n", path); - created = 1; - } else { - fatalf("Failed to make swap directory %s: %s", - path, xstrerror()); - } - return created; -} - -static int -storeVerifyDirectory(const char *path) -{ - struct stat sb; - if (stat(path, &sb) < 0) { - debug(20, 0) ("%s: %s\n", path, xstrerror()); - return -1; - } - if (S_ISDIR(sb.st_mode) == 0) { - debug(20, 0) ("%s is not a directory\n", path); - return -1; - } - return 0; + return storeUfsFullPath(f, buf); } /* @@ -163,54 +50,13 @@ storeVerifyDirectory(const char *path) int storeVerifyCacheDirs(void) { - int i; - int j; - const char *path; - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - path = Config.cacheSwap.swapDirs[i].path; - if (storeVerifyDirectory(path) < 0) - return -1; - for (j = 0; j < Config.cacheSwap.swapDirs[i].l1; j++) { - path = storeSwapSubDir(i, j); - if (storeVerifyDirectory(path) < 0) - return -1; - } - } - return 0; + return storeUfsVerifyCacheDirs(); } void storeCreateSwapDirectories(void) { - int i; - const char *path = NULL; - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - path = Config.cacheSwap.swapDirs[i].path; - debug(47, 3) ("Creating swap space in %s\n", path); - storeCreateDirectory(path, 0); - storeCreateSwapSubDirs(i); - } -} - -static void -storeCreateSwapSubDirs(int j) -{ - int i, k; - int should_exist; - SwapDir *SD = &Config.cacheSwap.swapDirs[j]; - LOCAL_ARRAY(char, name, MAXPATHLEN); - for (i = 0; i < SD->l1; i++) { - snprintf(name, MAXPATHLEN, "%s/%02X", SD->path, i); - if (storeCreateDirectory(name, 0)) - should_exist = 0; - else - should_exist = 1; - debug(47, 1) ("Making directories in %s\n", name); - for (k = 0; k < SD->l2; k++) { - snprintf(name, MAXPATHLEN, "%s/%02X/%02X", SD->path, i, k); - storeCreateDirectory(name, should_exist); - } - } + storeUfsCreateSwapDirectories(); } /* @@ -385,9 +231,7 @@ storeDirProperFileno(int dirn, int fn) void storeDirSwapLog(const StoreEntry * e, int op) { - storeSwapLogData *s; - int dirn; - dirn = e->swap_file_number >> SWAP_DIR_SHIFT; + int dirn = e->swap_file_number >> SWAP_DIR_SHIFT; assert(dirn < Config.cacheSwap.n_configured); assert(!EBIT_TEST(e->flags, KEY_PRIVATE)); assert(e->swap_file_number >= 0); @@ -401,156 +245,13 @@ storeDirSwapLog(const StoreEntry * e, int op) swap_log_op_str[op], storeKeyText(e->key), e->swap_file_number); - s = xcalloc(1, sizeof(storeSwapLogData)); - s->op = (char) op; - s->swap_file_number = e->swap_file_number; - s->timestamp = e->timestamp; - s->lastref = e->lastref; - s->expires = e->expires; - s->lastmod = e->lastmod; - s->swap_file_sz = e->swap_file_sz; - s->refcount = e->refcount; - s->flags = e->flags; - xmemcpy(s->key, e->key, MD5_DIGEST_CHARS); - file_write(Config.cacheSwap.swapDirs[dirn].swaplog_fd, - -1, - s, - sizeof(storeSwapLogData), - NULL, - NULL, - xfree); + storeUfsDirSwapLog(e, op); } char * storeDirSwapLogFile(int dirn, const char *ext) { - LOCAL_ARRAY(char, path, SQUID_MAXPATHLEN); - LOCAL_ARRAY(char, digit, 32); - if (Config.Log.swap) { - xstrncpy(path, Config.Log.swap, SQUID_MAXPATHLEN - 64); - strcat(path, "."); - snprintf(digit, 32, "%02d", dirn); - strncat(path, digit, 3); - } else { - xstrncpy(path, storeSwapDir(dirn), SQUID_MAXPATHLEN - 64); - strcat(path, "/swap.state"); - } - if (ext) - strncat(path, ext, 16); - return path; -} - -void -storeDirOpenSwapLogs(void) -{ - int i; - char *path; - int fd; - SwapDir *SD; - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - SD = &Config.cacheSwap.swapDirs[i]; - path = storeDirSwapLogFile(i, NULL); - fd = file_open(path, O_WRONLY | O_CREAT, NULL, NULL, NULL); - if (fd < 0) { - debug(50, 1) ("%s: %s\n", path, xstrerror()); - fatal("storeDirOpenSwapLogs: Failed to open swap log."); - } - debug(47, 3) ("Cache Dir #%d log opened on FD %d\n", i, fd); - SD->swaplog_fd = fd; - } -} - -void -storeDirCloseSwapLogs(void) -{ - int i; - SwapDir *SD; - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - SD = &Config.cacheSwap.swapDirs[i]; - if (SD->swaplog_fd < 0) /* not open */ - continue; - file_close(SD->swaplog_fd); - debug(47, 3) ("Cache Dir #%d log closed on FD %d\n", i, SD->swaplog_fd); - SD->swaplog_fd = -1; - } -} - -FILE * -storeDirOpenTmpSwapLog(int dirn, int *clean_flag, int *zero_flag) -{ - char *swaplog_path = xstrdup(storeDirSwapLogFile(dirn, NULL)); - char *clean_path = xstrdup(storeDirSwapLogFile(dirn, ".last-clean")); - char *new_path = xstrdup(storeDirSwapLogFile(dirn, ".new")); - struct stat log_sb; - struct stat clean_sb; - SwapDir *SD = &Config.cacheSwap.swapDirs[dirn]; - FILE *fp; - int fd; - if (stat(swaplog_path, &log_sb) < 0) { - debug(47, 1) ("Cache Dir #%d: No log file\n", dirn); - safe_free(swaplog_path); - safe_free(clean_path); - safe_free(new_path); - return NULL; - } - *zero_flag = log_sb.st_size == 0 ? 1 : 0; - /* close the existing write-only 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, NULL, NULL, NULL); - if (fd < 0) { - debug(50, 1) ("%s: %s\n", new_path, xstrerror()); - fatal("storeDirOpenTmpSwapLog: Failed to open swap log."); - } - SD->swaplog_fd = fd; - /* open a read-only stream of the old log */ - fp = fopen(swaplog_path, "r"); - if (fp == NULL) { - debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); - fatal("Failed to open swap log for reading"); - } - memset(&clean_sb, '\0', sizeof(struct stat)); - if (stat(clean_path, &clean_sb) < 0) - *clean_flag = 0; - else if (clean_sb.st_mtime < log_sb.st_mtime) - *clean_flag = 0; - else - *clean_flag = 1; - safeunlink(clean_path, 1); - safe_free(swaplog_path); - safe_free(clean_path); - safe_free(new_path); - return fp; -} - -void -storeDirCloseTmpSwapLog(int dirn) -{ - char *swaplog_path = xstrdup(storeDirSwapLogFile(dirn, NULL)); - char *new_path = xstrdup(storeDirSwapLogFile(dirn, ".new")); - SwapDir *SD = &Config.cacheSwap.swapDirs[dirn]; - int fd; - file_close(SD->swaplog_fd); -#ifdef _SQUID_OS2_ - if (unlink(swaplog_path) < 0) { - debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror()); - fatal("storeDirCloseTmpSwapLog: unlink failed"); - } -#endif - if (rename(new_path, swaplog_path) < 0) { - debug(50, 0) ("%s,%s: %s\n", new_path, swaplog_path, xstrerror()); - fatal("storeDirCloseTmpSwapLog: rename failed"); - } - fd = file_open(swaplog_path, O_WRONLY | O_CREAT, NULL, NULL, NULL); - if (fd < 0) { - debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror()); - fatal("storeDirCloseTmpSwapLog: Failed to open swap log."); - } - safe_free(swaplog_path); - safe_free(new_path); - SD->swaplog_fd = fd; - debug(47, 3) ("Cache Dir #%d log opened on FD %d\n", dirn, fd); + return storeUfsDirSwapLogFile(dirn, ext); } void @@ -569,8 +270,6 @@ storeDirUpdateSwapSize(int fn, size_t size, int sign) void storeDirStats(StoreEntry * sentry) { - int i; - SwapDir *SD; #if HAVE_STATVFS struct statvfs sfs; #endif @@ -584,40 +283,7 @@ storeDirStats(StoreEntry * sentry) storeAppendPrintf(sentry, "Current Capacity : %d%% used, %d%% free\n", percent((int) store_swap_size, (int) Config.Swap.maxSize), percent((int) (Config.Swap.maxSize - store_swap_size), (int) Config.Swap.maxSize)); - for (i = 0; i < Config.cacheSwap.n_configured; i++) { - SD = &Config.cacheSwap.swapDirs[i]; - storeAppendPrintf(sentry, "\n"); - storeAppendPrintf(sentry, "Store Directory #%d: %s\n", i, SD->path); - storeAppendPrintf(sentry, "First level subdirectories: %d\n", SD->l1); - storeAppendPrintf(sentry, "Second level subdirectories: %d\n", SD->l2); - storeAppendPrintf(sentry, "Maximum Size: %d KB\n", SD->max_size); - storeAppendPrintf(sentry, "Current Size: %d KB\n", SD->cur_size); - storeAppendPrintf(sentry, "Percent Used: %0.2f%%\n", - 100.0 * SD->cur_size / SD->max_size); - storeAppendPrintf(sentry, "Filemap bits in use: %d of %d (%d%%)\n", - SD->map->n_files_in_map, SD->map->max_n_files, - percent(SD->map->n_files_in_map, SD->map->max_n_files)); -#if HAVE_STATVFS -#define fsbtoblk(num, fsbs, bs) \ - (((fsbs) != 0 && (fsbs) < (bs)) ? \ - (num) / ((bs) / (fsbs)) : (num) * ((fsbs) / (bs))) - if (!statvfs(SD->path, &sfs)) { - storeAppendPrintf(sentry, "Filesystem Space in use: %d/%d KB (%d%%)\n", - fsbtoblk((sfs.f_blocks - sfs.f_bfree), sfs.f_frsize, 1024), - fsbtoblk(sfs.f_blocks, sfs.f_frsize, 1024), - percent(sfs.f_blocks - sfs.f_bfree, sfs.f_blocks)); - storeAppendPrintf(sentry, "Filesystem Inodes in use: %d/%d (%d%%)\n", - sfs.f_files - sfs.f_ffree, sfs.f_files, - percent(sfs.f_files - sfs.f_ffree, sfs.f_files)); - } -#endif - storeAppendPrintf(sentry, "Flags:"); - if (SD->flags.selected) - storeAppendPrintf(sentry, " SELECTED"); - if (SD->flags.read_only) - storeAppendPrintf(sentry, " READ-ONLY"); - storeAppendPrintf(sentry, "\n"); - } + storeUfsDirStats(sentry); } int @@ -635,188 +301,11 @@ storeDirMapBitsInUse(void) * * Writes a "clean" swap log file from in-memory metadata. */ -#define CLEAN_BUF_SZ 16384 int storeDirWriteCleanLogs(int reopen) { - StoreEntry *e = NULL; - int *fd; - int n = 0; - time_t start, stop, r; - struct stat sb; - char **cur; - char **new; - char **cln; - int dirn; - int N = Config.cacheSwap.n_configured; - dlink_node *m; - char **outbuf; - off_t *outbufoffset; - storeSwapLogData s; - size_t ss = sizeof(storeSwapLogData); - if (store_rebuilding) { - debug(20, 1) ("Not currently OK to rewrite swap log.\n"); - debug(20, 1) ("storeDirWriteCleanLogs: Operation aborted.\n"); - return 0; - } - debug(20, 1) ("storeDirWriteCleanLogs: Starting...\n"); - start = squid_curtime; - fd = xcalloc(N, sizeof(int)); - cur = xcalloc(N, sizeof(char *)); - new = xcalloc(N, sizeof(char *)); - cln = xcalloc(N, sizeof(char *)); - for (dirn = 0; dirn < N; dirn++) { - fd[dirn] = -1; - cur[dirn] = xstrdup(storeDirSwapLogFile(dirn, NULL)); - new[dirn] = xstrdup(storeDirSwapLogFile(dirn, ".clean")); - cln[dirn] = xstrdup(storeDirSwapLogFile(dirn, ".last-clean")); - unlink(new[dirn]); - unlink(cln[dirn]); - fd[dirn] = file_open(new[dirn], - O_WRONLY | O_CREAT | O_TRUNC, - NULL, - NULL, - NULL); - if (fd[dirn] < 0) { - debug(50, 0) ("storeDirWriteCleanLogs: %s: %s\n", new[dirn], xstrerror()); - continue; - } - debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n", - new[dirn], fd[dirn]); -#if HAVE_FCHMOD - if (stat(cur[dirn], &sb) == 0) - fchmod(fd[dirn], sb.st_mode); -#endif - } - outbuf = xcalloc(N, sizeof(char *)); - outbufoffset = xcalloc(N, sizeof(*outbufoffset)); - for (dirn = 0; dirn < N; dirn++) { - outbuf[dirn] = xcalloc(CLEAN_BUF_SZ, 1); - outbufoffset[dirn] = 0; - } - for (m = store_list.tail; m; m = m->prev) { - e = m->data; - if (e->swap_file_number < 0) - continue; - if (e->swap_status != SWAPOUT_DONE) - continue; - if (e->swap_file_sz <= 0) - continue; - if (EBIT_TEST(e->flags, RELEASE_REQUEST)) - continue; - if (EBIT_TEST(e->flags, KEY_PRIVATE)) - continue; - if (EBIT_TEST(e->flags, ENTRY_SPECIAL)) - continue; - dirn = storeDirNumber(e->swap_file_number); - assert(dirn < N); - if (fd[dirn] < 0) - continue; - memset(&s, '\0', ss); - s.op = (char) SWAP_LOG_ADD; - s.swap_file_number = e->swap_file_number; - s.timestamp = e->timestamp; - s.lastref = e->lastref; - s.expires = e->expires; - s.lastmod = e->lastmod; - s.swap_file_sz = e->swap_file_sz; - s.refcount = e->refcount; - s.flags = e->flags; - xmemcpy(&s.key, e->key, MD5_DIGEST_CHARS); - xmemcpy(outbuf[dirn] + outbufoffset[dirn], &s, ss); - outbufoffset[dirn] += ss; - /* buffered write */ - if (outbufoffset[dirn] + ss > CLEAN_BUF_SZ) { - if (write(fd[dirn], outbuf[dirn], outbufoffset[dirn]) < 0) { - debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", - new[dirn], xstrerror()); - debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); - file_close(fd[dirn]); - fd[dirn] = -1; - unlink(new[dirn]); - continue; - } - outbufoffset[dirn] = 0; - } - if ((++n & 0xFFFF) == 0) { - getCurrentTime(); - debug(20, 1) (" %7d entries written so far.\n", n); - } - } - /* flush */ - for (dirn = 0; dirn < N; dirn++) { - if (outbufoffset[dirn] == 0) - continue; - if (fd[dirn] < 0) - continue; - if (write(fd[dirn], outbuf[dirn], outbufoffset[dirn]) < 0) { - debug(50, 0) ("storeDirWriteCleanLogs: %s: write: %s\n", - new[dirn], xstrerror()); - debug(20, 0) ("storeDirWriteCleanLogs: Current swap logfile not replaced.\n"); - file_close(fd[dirn]); - fd[dirn] = -1; - unlink(new[dirn]); - continue; - } - safe_free(outbuf[dirn]); - } - safe_free(outbuf); - safe_free(outbufoffset); - /* - * You can't rename open files on Microsoft "operating systems" - * so we have to close before renaming. - */ - storeDirCloseSwapLogs(); - /* rename */ - for (dirn = 0; dirn < N; dirn++) { - if (fd[dirn] < 0) - continue; -#ifdef _SQUID_OS2_ - file_close(fd[dirn]); - fd[dirn] = -1; - if (unlink(cur[dirn]) < 0) - debug(50, 0) ("storeDirWriteCleanLogs: unlinkd failed: %s, %s\n", - xstrerror(), cur[dirn]); -#endif - if (rename(new[dirn], cur[dirn]) < 0) { - debug(50, 0) ("storeDirWriteCleanLogs: rename failed: %s, %s -> %s\n", - xstrerror(), new[dirn], cur[dirn]); - } - } - if (reopen) - storeDirOpenSwapLogs(); - stop = squid_curtime; - r = stop - start; - debug(20, 1) (" Finished. Wrote %d entries.\n", n); - debug(20, 1) (" Took %d seconds (%6.1f entries/sec).\n", - r > 0 ? (int) r : 0, - (double) n / (r > 0 ? r : 1)); - /* touch a timestamp file if we're not still validating */ - if (!store_rebuilding) { - for (dirn = 0; dirn < N; dirn++) { - if (fd[dirn] < 0) - continue; - file_close(file_open(cln[dirn], - O_WRONLY | O_CREAT | O_TRUNC, NULL, NULL, NULL)); - } - } - /* close */ - for (dirn = 0; dirn < N; dirn++) { - safe_free(cur[dirn]); - safe_free(new[dirn]); - safe_free(cln[dirn]); - if (fd[dirn] < 0) - continue; - file_close(fd[dirn]); - fd[dirn] = -1; - } - safe_free(cur); - safe_free(new); - safe_free(cln); - safe_free(fd); - return n; + return storeUfsDirWriteCleanLogs(reopen); } -#undef CLEAN_BUF_SZ void storeDirConfigure(void) @@ -854,3 +343,21 @@ storeDirDiskFull(int fn) debug(20, 1) ("WARNING: Shrinking cache_dir #%d to %d KB\n", dirn, SD->cur_size); } + +void +storeDirOpenSwapLogs(void) +{ + return storeUfsDirCloseSwapLogs(); +} + +void +storeDirCloseSwapLogs(void) +{ + return storeUfsDirCloseSwapLogs(); +} + +void +storeDirCloseTmpSwapLog(int dirn) +{ + return storeUfsDirCloseTmpSwapLog(dirn); +} diff --git a/src/store_rebuild.cc b/src/store_rebuild.cc index f10bb9b03f..f838b338fc 100644 --- a/src/store_rebuild.cc +++ b/src/store_rebuild.cc @@ -1,6 +1,6 @@ /* - * $Id: store_rebuild.cc,v 1.57 1999/05/03 21:55:11 wessels Exp $ + * $Id: store_rebuild.cc,v 1.58 1999/05/03 22:41:14 wessels Exp $ * * DEBUG: section 20 Store Rebuild Routines * AUTHOR: Duane Wessels @@ -506,7 +506,7 @@ storeGetNextFile(rebuild_dir * d, int *sfileno, int *size) d->entry->d_name); continue; } - if (!storeFilenoBelongsHere(d->fn, d->dirn, d->curlvl1, d->curlvl2)) { + if (!storeUfsFilenoBelongsHere(d->fn, d->dirn, d->curlvl1, d->curlvl2)) { debug(20, 3) ("storeGetNextFile: %08X does not belong in %d/%d/%d\n", d->fn, d->dirn, d->curlvl1, d->curlvl2); continue; @@ -693,7 +693,7 @@ storeRebuildStart(void) * use storeRebuildFromDirectory() to open up each file * and suck in the meta data. */ - fp = storeDirOpenTmpSwapLog(i, &clean, &zero); + fp = storeUfsDirOpenTmpSwapLog(i, &clean, &zero); if (fp == NULL || zero) { if (fp != NULL) fclose(fp);