From: Alex Rousskov Date: Sat, 9 Feb 2013 06:44:36 +0000 (-0700) Subject: Make squid -z for cache_dir rock work like UFS instead of like COSS. X-Git-Tag: SQUID_3_2_8~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=642634727b2fc497a223d6b16663393c87a271e6;p=thirdparty%2Fsquid.git Make squid -z for cache_dir rock work like UFS instead of like COSS. Also, Polish -z documentation and cache.log reporting. When a startup script runs squid -z by mistake against a cache_dir that is already initialized and full of cached entries, some admins prefer that nothing happens. Rock store now skips reinitialization if both the cache_dir directory and the db file in that directory exist. If one or both are missing, the missing pieces are created. UFS does something similar because it creates missing L1 and L2 directories but does not erase any entries already present in the cache_dir path. COSS, OTOH, re-initializes the existing db. Rock behavior will now be closer to UFS. To clean a corrupted cache_dir, the admin must remove its top-level directory before running squid -z. Squid now logs "Creating missing swap directories" instead of "Creating Swap Directories", and our documentation now reflects the "if missing" part of the -z algorithm. Also documented that recent Squid versions run -z in daemon mode (so that SMP configuration macros continue to work). --- diff --git a/src/fs/rock/RockSwapDir.cc b/src/fs/rock/RockSwapDir.cc index 78417bfcb9..682ee37039 100644 --- a/src/fs/rock/RockSwapDir.cc +++ b/src/fs/rock/RockSwapDir.cc @@ -152,8 +152,19 @@ Rock::SwapDir::create() debugs (47,3, HERE << "creating in " << path); - struct stat swap_sb; - if (::stat(path, &swap_sb) < 0) { + struct stat dir_sb; + if (::stat(path, &dir_sb) == 0) { + struct stat file_sb; + if (::stat(filePath, &file_sb) == 0) { + debugs (47, DBG_IMPORTANT, "Skipping existing Rock db: " << filePath); + return; + } + // else the db file is not there or is not accessible, and we will try + // to create it later below, generating a detailed error on failures. + } else { // path does not exist or is inaccessible + // If path exists but is not accessible, mkdir() below will fail, and + // the admin should see the error and act accordingly, so there is + // no need to distinguish ENOENT from other possible stat() errors. debugs (47, DBG_IMPORTANT, "Creating Rock db directory: " << path); const int res = mkdir(path, 0700); if (res != 0) { @@ -163,6 +174,7 @@ Rock::SwapDir::create() } } + debugs (47, DBG_IMPORTANT, "Creating Rock db: " << filePath); #if SLOWLY_FILL_WITH_ZEROS char block[1024]; Must(maxSize() % sizeof(block) == 0); diff --git a/src/main.cc b/src/main.cc index 38af4d4382..cf4d71dff3 100644 --- a/src/main.cc +++ b/src/main.cc @@ -283,7 +283,7 @@ usage(void) " Enable logging to syslog.\n" " -u port Specify ICP port number (default: %d), disable with 0.\n" " -v Print version.\n" - " -z Create swap directories\n" + " -z Create missing swap directories and then exit.\n" " -C Do not catch fatal signals.\n" " -D OBSOLETE. Scheduled for removal.\n" " -F Don't serve any requests until store is rebuilt.\n" @@ -1429,7 +1429,7 @@ SquidMain(int argc, char **argv) } setEffectiveUser(); - debugs(0, 0, "Creating Swap Directories"); + debugs(0, DBG_CRITICAL, "Creating missing swap directories"); Store::Root().create(); return 0; diff --git a/src/squid.8.in b/src/squid.8.in index 4ed2d91972..0d48d788ac 100644 --- a/src/squid.8.in +++ b/src/squid.8.in @@ -166,7 +166,21 @@ during fast reload. . .if !'po4a'hide' .TP .if !'po4a'hide' .B \-z -Create swap directories +Create missing swap directories and other missing cache_dir structures, +then exit. All cache_dir types create the configured top-level directory if +it is missing. Other actions are type-specific. For example, ufs-based +storage systems create missing L1 and L2 directories while Rock creates +the missing database file. +.IP +This option does not enable validation of any present swap structures. Its +focus is on creation of missing pieces. If nothing is missing, squid -z +just exits. If you suspect cache_dir corruption, you must delete the top-level +cache_dir directory before running squid -z. +.IP +By default, squid -z runs in daemon mode (so that configuration macros and +other SMP features work as expected). Use +.B \-N +option to overwrite this. . .SH FILES Squid configuration files located in @SYSCONFDIR@/: