/*
- * $Id: DiskIOModule.cc,v 1.2 2006/05/29 00:15:03 robertc Exp $
+ * $Id: DiskIOModule.cc,v 1.3 2006/09/14 00:51:10 robertc Exp $
*
* DEBUG: section 92 Storage File System
* AUTHOR: Robert Collins
return NULL;
}
+DiskIOModule *
+DiskIOModule::FindDefault()
+{
+ /* Best IO options are in order: */
+ DiskIOModule * result;
+ result = Find("DiskThreads");
+ if (NULL == result)
+ result = Find("DiskDaemon");
+ if (NULL == result)
+ result = Find("AIO");
+ if (NULL == result)
+ result = Find("Blocking");
+ return result;
+}
+
/* disk modules dont export anything by default */
void
DiskIOModule::registerWithCacheManager(CacheManager & manager)
/*
- * $Id: DiskIOModule.h,v 1.2 2006/05/29 00:15:03 robertc Exp $
+ * $Id: DiskIOModule.h,v 1.3 2006/09/14 00:51:10 robertc Exp $
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
* ----------------------------------------------------------
static void ModuleAdd(DiskIOModule &);
static void FreeAllModules();
static DiskIOModule *Find(char const *type);
+ /* find *any* usable disk module. This will look for the 'best'
+ * available module for this system.
+ */
+ static DiskIOModule *FindDefault();
static Vector<DiskIOModule*> const &Modules();
typedef Vector<DiskIOModule*>::iterator iterator;
typedef Vector<DiskIOModule*>::const_iterator const_iterator;
#
# Makefile for the Squid Object Cache server
#
-# $Id: Makefile.am,v 1.168 2006/09/13 20:09:50 serassio Exp $
+# $Id: Makefile.am,v 1.169 2006/09/14 00:51:09 robertc Exp $
#
# Uncomment and customize the following to suit your needs:
#
tests/testACLMaxUserIP \
tests/testBoilerplate \
tests/testCacheManager \
+ tests/testDiskIO \
tests/testEvent \
tests/testEventLoop \
tests/testHeaders \
@SQUID_CPPUNIT_LA@ \
@ICAP_LIBS@
+tests_testDiskIO_SOURCES= \
+ $(SWAP_TEST_SOURCES) \
+ tests/testDiskIO.cc \
+ tests/testDiskIO.h \
+ tests/testMain.cc
+tests_testDiskIO_LDADD= \
+ $(SWAP_TEST_LDADD) \
+ @SSLLIB@
+tests_testDiskIO_LDFLAGS = $(LIBADD_DL)
+tests_testDiskIO_DEPENDENCIES = $(top_builddir)/lib/libmiscutil.a \
+ @SQUID_CPPUNIT_LA@
+
## Tests of the Even module.
tests_testEvent_SOURCES = \
debug.cc \
/*
- * $Id: store_dir_coss.cc,v 1.67 2006/09/03 04:12:03 hno Exp $
+ * $Id: store_dir_coss.cc,v 1.68 2006/09/14 00:51:10 robertc Exp $
* vim: set et :
*
* DEBUG: section 47 Store COSS Directory Routines
parseOptions(0);
+ if (NULL == io)
+ changeIO(DiskIOModule::FindDefault());
+
/* Enforce maxobjsize being set to something */
if (max_objsize == -1)
fatal("COSS requires max-size to be set to something other than -1!\n");
/*
- * $Id: StoreFSufs.h,v 1.4 2004/12/21 17:28:29 robertc Exp $
+ * $Id: StoreFSufs.h,v 1.5 2006/09/14 00:51:12 robertc Exp $
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
* ----------------------------------------------------------
#include "DiskIO/DiskIOModule.h"
+/* core UFS class. This template provides compile time aliases for
+ * ufs/aufs/diskd to ease configuration conversion - each becomes a
+ * StoreFS module whose createSwapDir method parameterises the common
+ * UFSSwapDir with an IO module instance.
+ */
template <class TheSwapDir>
-
class StoreFSufs : public StoreFileSystem
{
DiskIOModule *IO;
char const *moduleName;
char const *label;
-
-private:
- void checkIO();
};
template <class C>
StoreFSufs<C>::createSwapDir()
{
C *result = new C(type(), moduleName);
- checkIO();
- result->IO = new UFSStrategy(IO->createStrategy());
return result;
}
initialised = true;
}
-template <class C>
-void
-StoreFSufs<C>::checkIO()
-{
- if (IO)
- return;
-
- IO = DiskIOModule::Find(moduleName);
-}
-
#endif /* SQUID_STOREFSUFS_H */
/*
- * $Id: store_dir_ufs.cc,v 1.75 2006/08/19 12:31:24 robertc Exp $
+ * $Id: store_dir_ufs.cc,v 1.76 2006/09/14 00:51:12 robertc Exp $
*
* DEBUG: section 47 Store Directory Routines
* AUTHOR: Duane Wessels
currentIOOptions->options.push_back(new ConfigOptionAdapter<UFSSwapDir>(*const_cast<UFSSwapDir *>(this), &UFSSwapDir::optionIOParse, &UFSSwapDir::optionIODump));
- ConfigOption *ioOptions = IO->io->getOptionTree();
+ ConfigOption *ioOptions = NULL;
+
+ IO->io->getOptionTree();
if (ioOptions)
currentIOOptions->options.push_back(ioOptions);
"\tfor details. Run 'squid -z' to create swap directories\n"
"\tif needed, or if running Squid for the first time.";
IO->init();
- initBitmap();
if (verifyCacheDirs())
fatal(errmsg);
createSwapSubDirs();
}
-UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(NULL), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType)) {}
+UFSSwapDir::UFSSwapDir(char const *aType, const char *anIOType) : SwapDir(aType), IO(NULL), map(file_map_create()), suggest(0), swaplog_fd (-1), currentIOOptions(new ConfigOptionVector()), ioType(xstrdup(anIOType))
+{
+ /* modulename is only set to disk modules that are built, by configure,
+ * so the Find call should never return NULL here.
+ */
+ IO = new UFSStrategy(DiskIOModule::Find(anIOType)->createStrategy());
+}
UFSSwapDir::~UFSSwapDir()
{
return fn;
}
-/*
- * Initialise the ufs bitmap
- *
- * If there already is a bitmap, and the numobjects is larger than currently
- * configured, we allocate a new bitmap and 'grow' the old one into it.
- */
-void
-UFSSwapDir::initBitmap()
-{
- if (map == NULL) {
- /* First time */
- map = file_map_create();
- } else if (map->max_n_files) {
- /* it grew, need to expand */
- /* XXX We don't need it anymore .. */
- }
-
- /* else it shrunk, and we leave the old one in place */
-}
-
char *
UFSSwapDir::swapSubDir(int subdirn)const
{
/*
- * $Id: ufscommon.h,v 1.8 2006/08/07 02:28:26 robertc Exp $
+ * $Id: ufscommon.h,v 1.9 2006/09/14 00:51:12 robertc Exp $
*
* SQUID Web Proxy Cache http://www.squid-cache.org/
* ----------------------------------------------------------
bool pathIsDirectory(const char *path)const;
int swaplog_fd;
static EVH CleanEvent;
- void initBitmap();
bool verifyCacheDirs();
void rebuild();
int createDirectory(const char *path, int);
#include "RefCount.h"
#include "DiskIO/IORequestor.h"
-/* UFS dir specific IO calls */
+/* UFS dir specific IO calls
+ *
+ * This should be whittled away - DiskIOModule should be providing the
+ * entire needed api.
+ */
class DiskIOStrategy;
/* cachemgr output on the IO instance stats */
virtual void statfs(StoreEntry & sentry)const;
+ /* The io strategy in use */
+ DiskIOStrategy *io;
protected:
friend class UFSSwapDir;
- DiskIOStrategy *io;
};
/* Common ufs-store-dir logic */
if (0 > system ("rm -rf " TESTDIR))
throw std::runtime_error("Failed to clean test work directory");
}
+
+/* The COSS store should always configure an IO engine even if none is
+ * supplied on the configuration line.
+ */
+void
+testCoss::testDefaultEngine()
+{
+ /* boring common test boilerplate */
+ if (0 > system ("rm -rf " TESTDIR))
+ throw std::runtime_error("Failed to clean test work directory");
+
+ StorePointer aRoot (new StoreController);
+ Store::Root(aRoot);
+ SwapDirPointer aStore (new CossSwapDir());
+ addSwapDir(aStore);
+ commonInit();
+
+ char *path=xstrdup(TESTDIR);
+ char *config_line=xstrdup("foo 100 max-size=102400 block-size=512");
+ strtok(config_line, w_space);
+ aStore->parse(0, path);
+ safe_free(path);
+ safe_free(config_line);
+ CPPUNIT_ASSERT(aStore->io != NULL);
+
+ free_cachedir(&Config.cacheSwap);
+ Store::Root(NULL);
+ if (0 > system ("rm -rf " TESTDIR))
+ throw std::runtime_error("Failed to clean test work directory");
+}
CPPUNIT_TEST_SUITE( testCoss );
CPPUNIT_TEST( testCossCreate );
CPPUNIT_TEST( testCossSearch );
+ CPPUNIT_TEST( testDefaultEngine );
CPPUNIT_TEST_SUITE_END();
public:
void commonInit();
void testCossCreate();
void testCossSearch();
+ void testDefaultEngine();
};
#endif
}
void
-testUfs::testUfsSearch()
+testUfs::commonInit()
{
- /* test sequence
- * make a valid working ufs swapdir
- * put two entries in it and sync logs
- * search the ufs dir
- * check the entries we find are what we want
- */
-
- if (0 > system ("rm -rf " TESTDIR))
- throw std::runtime_error("Failed to clean test work directory");
+ static bool inited = false;
- StorePointer aRoot (new StoreController);
-
- Store::Root(aRoot);
-
- SwapDirPointer aStore (new UFSSwapDir("ufs", "Blocking"));
-
- aStore->IO = new UFSStrategy(DiskIOModule::Find("Blocking")->createStrategy());
-
- addSwapDir(aStore);
+ if (inited)
+ return;
Config.Store.avgObjectSize = 1024;
httpReplyInitModule(); /* must go before accepting replies */
+ inited = true;
+}
+
+void
+testUfs::testUfsSearch()
+{
+ /* test sequence
+ * make a valid working ufs swapdir
+ * put two entries in it and sync logs
+ * search the ufs dir
+ * check the entries we find are what we want
+ */
+
+ if (0 > system ("rm -rf " TESTDIR))
+ throw std::runtime_error("Failed to clean test work directory");
+
+ StorePointer aRoot (new StoreController);
+
+ Store::Root(aRoot);
+
+ SwapDirPointer aStore (new UFSSwapDir("ufs", "Blocking"));
+
+ aStore->IO = new UFSStrategy(DiskIOModule::Find("Blocking")->createStrategy());
+
+ addSwapDir(aStore);
+
+ commonInit();
mem_policy = createRemovalPolicy(Config.replPolicy);
+
char *path=xstrdup(TESTDIR);
char *config_line=xstrdup("foo 100 1 1");
/* todo: here we should test a dirty rebuild */
+ Store::Root(NULL);
+ safe_free(Config.replPolicy->type);
+ delete Config.replPolicy;
+
+ if (0 > system ("rm -rf " TESTDIR))
+ throw std::runtime_error("Failed to clean test work directory");
+}
+
+/* The UFS store should always configure an IO engine even if none is
+ * supplied on the configuration line.
+ */
+void
+testUfs::testUfsDefaultEngine()
+{
+ /* boring common test boilerplate */
+ if (0 > system ("rm -rf " TESTDIR))
+ throw std::runtime_error("Failed to clean test work directory");
+
+ StorePointer aRoot (new StoreController);
+ Store::Root(aRoot);
+ SwapDirPointer aStore (new UFSSwapDir("ufs", "Blocking"));
+ addSwapDir(aStore);
+ commonInit();
+ Config.replPolicy = new RemovalPolicySettings;
+ Config.replPolicy->type = xstrdup ("lru");
+ mem_policy = createRemovalPolicy(Config.replPolicy);
+
+ char *path=xstrdup(TESTDIR);
+ char *config_line=xstrdup("foo 100 1 1");
+ strtok(config_line, w_space);
+ aStore->parse(0, path);
+ safe_free(path);
+ safe_free(config_line);
+ CPPUNIT_ASSERT(aStore->IO->io != NULL);
+
+ free_cachedir(&Config.cacheSwap);
+ Store::Root(NULL);
safe_free(Config.replPolicy->type);
delete Config.replPolicy;
{
CPPUNIT_TEST_SUITE( testUfs );
CPPUNIT_TEST( testUfsSearch );
+ CPPUNIT_TEST( testUfsDefaultEngine );
CPPUNIT_TEST_SUITE_END();
public:
protected:
+ void commonInit();
void testUfsSearch();
+ void testUfsDefaultEngine();
};
#endif