]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Make squid -z for cache_dir rock work like UFS instead of like COSS.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sat, 9 Feb 2013 06:44:36 +0000 (23:44 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 9 Feb 2013 06:44:36 +0000 (23:44 -0700)
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).

src/fs/rock/RockSwapDir.cc
src/main.cc
src/squid.8.in

index 78417bfcb9046d1185aa3a3dc98cb0b5e9f9ff61..682ee3703975ee1e87c9895d4c2a88bc4bbb26ff 100644 (file)
@@ -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);
index 38af4d43824fe7f7140eba4dbdd2a95290462ae6..cf4d71dff3b7dfb6885a4b5494c66a4513c67b87 100644 (file)
@@ -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;
index 4ed2d919727d748ec18b70dccd0ccb73ff5144ab..0d48d788ac258daba731d82341b6e3239672ad60 100644 (file)
@@ -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@/: