Hi, Here is the first stab. The whole thing is entirely based on Adrian Chadd's IFS patch for diskd, this one uses the ufs store class. Relevant parts of squid configuration. # directory should be a ifs mount point cache_dir ufs /mnt 32 4 64 # store swap log must be outside the ifs mount point cache_swap_log /opt/squid/var/logs/swap.state # must run as root since ifs mount point can't be chown()'d cache_effective_user root TODO: * Runtime configuration if we should do ifs on the ufs cache_dir. * Store rebuilding not implemented, not sure how to go about this. * Not sure how unlinking should be done. What's broken: * Some cache hits fail, need to check with squid folks why this happens. 2005/08/26 03:10:50| storeClientCopy3: Need to open swap in file 2005/08/26 03:10:50| storeSwapInStart: called for 0 00000066 5B51A9E775AD73CC90EFFEE2BEB6F277 2005/08/26 03:10:50| storeSwapInStart: Opening fileno 00000066 2005/08/26 03:10:50| storeUfsOpen: fileno 00000066 2005/08/26 03:10:50| storeUfsOpen: path /mnt/102, fileno 102 2005/08/26 03:10:50| storeUfsOpen: opened FD 12 2005/08/26 03:10:50| storeClientCopy3: reading from STORE 2005/08/26 03:10:50| storeUfsRead: dirno 0, fileno 00000066, FD 12 2005/08/26 03:10:50| storeUfsReadDone: dirno 0, fileno 00000066, FD 12, len 1746 2005/08/26 03:10:50| storeClientReadHeader: len 1746 2005/08/26 03:10:50| storeClientReadHeader: swapin MD5 mismatch 2005/08/26 03:10:50| 416B3F2C156B459C94A41E092D6BD823 2005/08/26 03:10:50| 5B51A9E775AD73CC90EFFEE2BEB6F277 2005/08/26 03:10:50| WARNING: 1 swapin MD5 mismatches 416B3F2C156B459C94A41E092D6BD823 is the md5 sum of the url in the store file itself but squid claims that the requested url now has a different md5 sum. I have not managed to nail down if the request and store md5 sum is correct then the store entry is written to disk. * Most likely plenty of other things as well. Regards -- Pawel Worach ? src/fs/ufs/.dirstamp ? src/fs/ufs/Makefile Index: src/main.c =================================================================== RCS file: /squid/squid/src/main.c,v retrieving revision 1.345.2.27 diff -u -u -p -r1.345.2.27 main.c --- src/main.c 27 Jun 2005 21:24:28 -0000 1.345.2.27 +++ src/main.c 26 Aug 2005 02:12:21 -0000 @@ -438,7 +438,9 @@ setEffectiveUser(void) debug(0, 0) ("start Squid as root, then you must configure\n"); debug(0, 0) ("it to run as a non-priveledged user with the\n"); debug(0, 0) ("'cache_effective_user' option in the config file.\n"); +#if 0 fatal("Don't run Squid as root, set 'cache_effective_user'!"); +#endif } } Index: src/fs/ufs/store_dir_ufs.c =================================================================== RCS file: /squid/squid/src/fs/ufs/store_dir_ufs.c,v retrieving revision 1.39.2.13 diff -u -u -p -r1.39.2.13 store_dir_ufs.c --- src/fs/ufs/store_dir_ufs.c 26 Mar 2005 23:27:11 -0000 1.39.2.13 +++ src/fs/ufs/store_dir_ufs.c 26 Aug 2005 02:12:21 -0000 @@ -76,6 +76,7 @@ static int storeUfsDirVerifyDirectory(co static void storeUfsDirCreateSwapSubDirs(SwapDir *); static char *storeUfsDirSwapLogFile(SwapDir *, const char *); static EVH storeUfsDirRebuildFromDirectory; +static EVH storeUfsDirRebuildFromIfsDirectory; static EVH storeUfsDirRebuildFromSwapLog; static int storeUfsDirGetNextFile(RebuildState *, sfileno *, int *size); static StoreEntry *storeUfsDirAddDiskRestore(SwapDir * SD, const cache_key * key, @@ -356,12 +357,13 @@ static void storeUfsDirInit(SwapDir * sd) { static int started_clean_event = 0; + ufsinfo_t *ufsinfo = sd->fsdata; static const char *errmsg = "\tFailed to verify one of the swap directories, Check cache.log\n" "\tfor details. Run 'squid -z' to create swap directories\n" "\tif needed, or if running Squid for the first time."; storeUfsDirInitBitmap(sd); - if (storeUfsDirVerifyCacheDirs(sd) < 0) + if (!ufsinfo->doifs && storeUfsDirVerifyCacheDirs(sd) < 0) fatal(errmsg); storeUfsDirOpenSwapLog(sd); storeUfsDirRebuild(sd); @@ -556,6 +558,15 @@ storeUfsDirRebuildFromDirectory(void *da } static void +storeUfsDirRebuildFromIfsDirectory(void *data) +{ + RebuildState *rb = data; + + /* For now, fake it */ + storeUfsDirRebuildComplete(rb); +} + +static void storeUfsDirRebuildFromSwapLog(void *data) { RebuildState *rb = data; @@ -1068,6 +1079,7 @@ storeUfsDirRebuild(SwapDir * sd) RebuildState *rb; int clean = 0; int zero = 0; + ufsinfo_t *ufsinfo = sd->fsdata; FILE *fp; EVH *func = NULL; CBDATA_INIT_TYPE(RebuildState); @@ -1084,7 +1096,11 @@ storeUfsDirRebuild(SwapDir * sd) if (fp == NULL || zero) { if (fp != NULL) fclose(fp); - func = storeUfsDirRebuildFromDirectory; + /* If we're doing IFS, do a different rebuild */ + if (ufsinfo->doifs) + func = storeUfsDirRebuildFromIfsDirectory; + else + func = storeUfsDirRebuildFromDirectory; } else { func = storeUfsDirRebuildFromSwapLogCheckVersion; rb->log = fp; @@ -1387,8 +1403,14 @@ static void storeUfsDirNewfs(SwapDir * sd) { debug(47, 3) ("Creating swap space in %s\n", sd->path); - storeUfsDirCreateDirectory(sd->path, 0); - storeUfsDirCreateSwapSubDirs(sd); + ufsinfo_t *ufsinfo = sd->fsdata; + + if(ufsinfo->doifs) + debug(47, 3) ("No need to newfs for ifs in %s\n", sd->path); + else { + storeUfsDirCreateDirectory(sd->path, 0); + storeUfsDirCreateSwapSubDirs(sd); + } } static int @@ -1426,6 +1448,11 @@ storeUfsDirClean(int swap_index) D1 = (swap_index / N0) % N1; N2 = ufsinfo->l2; D2 = ((swap_index / N0) / N1) % N2; + + /* If we're doing ifs on this partition, ignore it */ + if(ufsinfo->doifs) + return 0; + snprintf(p1, SQUID_MAXPATHLEN, "%s/%02X/%02X", Config.cacheSwap.swapDirs[D0].path, D1, D2); debug(36, 3) ("storeDirClean: Cleaning directory %s\n", p1); @@ -1557,6 +1584,11 @@ storeUfsDirValidFileno(SwapDir * SD, sfi ufsinfo_t *ufsinfo = (ufsinfo_t *) SD->fsdata; if (filn < 0) return 0; + + /* If we are doing IFS, we don't know whether its valid .. */ + if (ufsinfo->doifs) + return 1; + /* * If flag is set it means out-of-range file number should * be considered invalid. @@ -1712,9 +1744,10 @@ storeUfsDirStats(SwapDir * SD, StoreEntr 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", - ufsinfo->map->n_files_in_map, ufsinfo->map->max_n_files, - percent(ufsinfo->map->n_files_in_map, ufsinfo->map->max_n_files)); + if(!ufsinfo->doifs) + storeAppendPrintf(sentry, "Filemap bits in use: %d of %d (%d%%)\n", + ufsinfo->map->n_files_in_map, ufsinfo->map->max_n_files, + percent(ufsinfo->map->n_files_in_map, ufsinfo->map->max_n_files)); x = storeDirGetUFSStats(SD->path, &totl_kb, &free_kb, &totl_in, &free_in); if (0 == x) { storeAppendPrintf(sentry, "Filesystem Space in use: %d/%d KB (%d%%)\n", @@ -1785,6 +1818,7 @@ void storeUfsDirDump(StoreEntry * entry, SwapDir * s) { ufsinfo_t *ufsinfo = (ufsinfo_t *) s->fsdata; + /* XXX need to put whether we're doing IFS or not here! */ storeAppendPrintf(entry, " %d %d %d", s->max_size >> 10, ufsinfo->l1, @@ -1819,11 +1853,15 @@ storeUfsDirFullPath(SwapDir * SD, sfilen if (!fullpath) fullpath = fullfilename; fullpath[0] = '\0'; - snprintf(fullpath, SQUID_MAXPATHLEN, "%s/%02X/%02X/%08X", - SD->path, - ((filn / L2) / L2) % L1, - (filn / L2) % L2, - filn); + if(ufsinfo->doifs) + snprintf(fullpath, SQUID_MAXPATHLEN, "%s/%d", SD->path, filn); + else { + snprintf(fullpath, SQUID_MAXPATHLEN, "%s/%02X/%02X/%08X", + SD->path, + ((filn / L2) / L2) % L1, + (filn / L2) % L2, + filn); + } return fullpath; } @@ -1898,6 +1936,8 @@ storeUfsDirParse(SwapDir * sd, int index ufsinfo->map = NULL; /* Debugging purposes */ ufsinfo->suggest = 0; ufsinfo->open_files = 0; + /* XXX this should be picked up from configuration */ + ufsinfo->doifs = 1; sd->init = storeUfsDirInit; sd->newfs = storeUfsDirNewfs; sd->dump = storeUfsDirDump; Index: src/fs/ufs/store_io_ufs.c =================================================================== RCS file: /squid/squid/src/fs/ufs/store_io_ufs.c,v retrieving revision 1.9.2.6 diff -u -u -p -r1.9.2.6 store_io_ufs.c --- src/fs/ufs/store_io_ufs.c 26 Mar 2005 22:44:10 -0000 1.9.2.6 +++ src/fs/ufs/store_io_ufs.c 26 Aug 2005 02:12:21 -0000 @@ -97,20 +97,39 @@ storeUfsCreate(SwapDir * SD, StoreEntry ufsinfo_t *ufsinfo = (ufsinfo_t *) SD->fsdata; sfileno filn; sdirno dirn; + struct stat sb; /* Allocate a number */ dirn = SD->index; - filn = storeUfsDirMapBitAllocate(SD); - ufsinfo->suggest = filn + 1; - /* Shouldn't we handle a 'bitmap full' error here? */ - path = storeUfsDirFullPath(SD, filn, NULL); + /* If we are in ifs mode, the FS gives us the file number */ + if (!ufsinfo->doifs) { + filn = storeUfsDirMapBitAllocate(SD); + /* Shouldn't we handle a 'bitmap full' error here? */ + path = storeUfsDirFullPath(SD, filn, NULL); + } else { + asprintf(&path, "%s/newfile", SD->path); + } - debug(79, 3) ("storeUfsCreate: fileno %08X\n", filn); fd = file_open(path, mode); if (fd < 0) { debug(79, 1) ("storeUfsCreate: Failed to create %s (%s)\n", path, xstrerror()); + if(ufsinfo->doifs) + xfree(path); + return NULL; + } + + /* Get the IFS file number from the inode number */ + if(ufsinfo->doifs) { + if(fstat(fd, &sb) != 0) { + debug(79, 1) ("storeUfsCreate: Failed to stat %s (%s)\n", path, xstrerror()); + xfree(path); return NULL; + } + filn = sb.st_ino; + ufsinfo->suggest = filn + 1; } + + debug(79, 3) ("storeUfsCreate: fileno %08X\n", filn); debug(79, 3) ("storeUfsCreate: opened FD %d\n", fd); CBDATA_INIT_TYPE_FREECB(storeIOState, storeUfsIOFreeEntry); sio = cbdataAlloc(storeIOState); @@ -132,6 +151,7 @@ storeUfsCreate(SwapDir * SD, StoreEntry /* now insert into the replacement policy */ storeUfsDirReplAdd(SD, e); + xfree(path); return sio; } @@ -189,9 +209,14 @@ storeUfsWrite(SwapDir * SD, storeIOState void storeUfsUnlink(SwapDir * SD, StoreEntry * e) { + ufsinfo_t *ufsinfo = SD->fsdata; + debug(79, 3) ("storeUfsUnlink: fileno %08X\n", e->swap_filen); storeUfsDirReplRemove(e); - storeUfsDirMapBitReset(SD, e->swap_filen); + if(!ufsinfo->doifs) { + /* If we are in ifs mode, we don't need to do this! */ + storeUfsDirMapBitReset(SD, e->swap_filen); + } storeUfsDirUnlinkFile(SD, e->swap_filen); } Index: src/fs/ufs/store_ufs.h =================================================================== RCS file: /squid/squid/src/fs/ufs/store_ufs.h,v retrieving revision 1.2.4.1 diff -u -u -p -r1.2.4.1 store_ufs.h --- src/fs/ufs/store_ufs.h 31 May 2004 22:03:31 -0000 1.2.4.1 +++ src/fs/ufs/store_ufs.h 26 Aug 2005 02:12:22 -0000 @@ -14,6 +14,7 @@ struct _ufsinfo_t { fileMap *map; int suggest; int open_files; + int doifs; }; struct _ufsstate_t {