]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/DiskIO/DiskThreads/DiskThreadsIOStrategy.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / src / DiskIO / DiskThreads / DiskThreadsIOStrategy.cc
index bbc5580cd396c1a9477af8596dfcc3499649b00a..3d9bf8b64657aa8a430cc629226eb608d30c0ef6 100644 (file)
@@ -1,47 +1,26 @@
-
 /*
- * $Id: DiskThreadsIOStrategy.cc,v 1.12 2007/04/28 22:26:47 hno Exp $
- *
- * DEBUG: section 79    Squid-side Disk I/O functions.
- * AUTHOR: Robert Collins
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
  *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *  
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *  
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
-#include "squid.h"
+/* DEBUG: section 79    Squid-side Disk I/O functions. */
 
-#include "CacheManager.h"
-#include "DiskThreadsIOStrategy.h"
+#include "squid.h"
 #include "DiskThreadsDiskFile.h"
-/* for statfs */
-#include "Store.h"
+#include "DiskThreadsIOStrategy.h"
 #include "fde.h"
+#include "mgr/Registration.h"
+#include "SquidConfig.h"
+#include "StatCounters.h"
+#include "Store.h"
+
+/* squidaio_ctrl_t uses explicit alloc()/freeOne().
+ * XXX: convert to MEMPROXY_CLASS() API
+ */
+#include "mem/Pool.h"
 
 void
 DiskThreadsIOStrategy::init(void)
@@ -49,8 +28,6 @@ DiskThreadsIOStrategy::init(void)
     if (initialised)
         return;
 
-    squidaio_ctrl_pool = memPoolCreate("aio_ctrl", sizeof(squidaio_ctrl_t));
-
     initialised = true;
 
     /*
@@ -59,15 +36,14 @@ DiskThreadsIOStrategy::init(void)
      * there are, which means we don't know how many threads to start.
      */
 
-     registerWithCacheManager();
+    registerWithCacheManager();
 }
 
 void
 DiskThreadsIOStrategy::registerWithCacheManager(void)
 {
-    CacheManager::GetInstance()->
-        registerAction("squidaio_counts", "Async IO Function Counters",
-                       aioStats, 0, 1);
+    Mgr::RegisterAction("squidaio_counts", "Async IO Function Counters",
+                        aioStats, 0, 1);
 }
 
 void
@@ -78,10 +54,6 @@ DiskThreadsIOStrategy::done(void)
 
     squidaio_shutdown();
 
-    delete squidaio_ctrl_pool;
-
-    squidaio_ctrl_pool = NULL;
-
     initialised = false;
 }
 
@@ -93,7 +65,7 @@ DiskThreadsIOStrategy::callback()
     int retval = 0;
 
     assert(initialised);
-    squidaio_counts.check_callback++;
+    ++squidaio_counts.check_callback;
 
     for (;;) {
         if ((resultp = squidaio_poll_done()) == NULL)
@@ -134,19 +106,19 @@ DiskThreadsIOStrategy::callback()
         }
 
         if (ctrlp == NULL)
-            continue;          /* XXX Should not happen */
+            continue;       /* XXX Should not happen */
 
         dlinkDelete(&ctrlp->node, &used_list);
 
         if (ctrlp->done_handler) {
-            AIOCB *callback = ctrlp->done_handler;
+            AIOCB *done_callback = ctrlp->done_handler;
             void *cbdata;
             ctrlp->done_handler = NULL;
 
             if (cbdataReferenceValidDone(ctrlp->done_handler_data, &cbdata)) {
-                retval = 1;    /* Return that we've actually done some work */
-                callback(ctrlp->fd, cbdata, ctrlp->bufp,
-                         ctrlp->result.aio_return, ctrlp->result.aio_errno);
+                retval = 1; /* Return that we've actually done some work */
+                done_callback(ctrlp->fd, cbdata, ctrlp->bufp,
+                              ctrlp->result.aio_return, ctrlp->result.aio_errno);
             } else {
                 if (ctrlp->operation == _AIO_OPEN) {
                     /* The open operation was aborted.. */
@@ -166,7 +138,7 @@ DiskThreadsIOStrategy::callback()
         if (ctrlp->operation == _AIO_READ)
             squidaio_xfree(ctrlp->bufp, ctrlp->len);
 
-        squidaio_ctrl_pool->free(ctrlp);
+        delete ctrlp;
     }
 
     return retval;
@@ -177,34 +149,36 @@ void
 DiskThreadsIOStrategy::sync()
 {
     if (!initialised)
-        return;                        /* nothing to do then */
+        return;         /* nothing to do then */
 
     /* Flush all pending operations */
-    debugs(32, 1, "aioSync: flushing pending I/O operations");
+    debugs(32, 2, "aioSync: flushing pending I/O operations");
 
     do {
         callback();
     } while (squidaio_sync());
 
-    debugs(32, 1, "aioSync: done");
+    debugs(32, 2, "aioSync: done");
 }
 
-DiskThreadsIOStrategy::DiskThreadsIOStrategy() :  initialised (false) {}
+DiskThreadsIOStrategy::DiskThreadsIOStrategy() :
+    initialised(false)
+{}
 
 void
 DiskThreadsIOStrategy::aioStats(StoreEntry * sentry)
 {
     storeAppendPrintf(sentry, "ASYNC IO Counters:\n");
-    storeAppendPrintf(sentry, "Operation\t# Requests\tNumber serviced\n");
-    storeAppendPrintf(sentry, "open\t%d\t%d\n", squidaio_counts.open_start, squidaio_counts.open_finish);
-    storeAppendPrintf(sentry, "close\t%d\t%d\n", squidaio_counts.close_start, squidaio_counts.close_finish);
-    storeAppendPrintf(sentry, "cancel\t%d\t-\n", squidaio_counts.cancel);
-    storeAppendPrintf(sentry, "write\t%d\t%d\n", squidaio_counts.write_start, squidaio_counts.write_finish);
-    storeAppendPrintf(sentry, "read\t%d\t%d\n", squidaio_counts.read_start, squidaio_counts.read_finish);
-    storeAppendPrintf(sentry, "stat\t%d\t%d\n", squidaio_counts.stat_start, squidaio_counts.stat_finish);
-    storeAppendPrintf(sentry, "unlink\t%d\t%d\n", squidaio_counts.unlink_start, squidaio_counts.unlink_finish);
-    storeAppendPrintf(sentry, "check_callback\t%d\t-\n", squidaio_counts.check_callback);
-    storeAppendPrintf(sentry, "queue\t%d\t-\n", squidaio_get_queue_len());
+    storeAppendPrintf(sentry, "  Operation\t# Requests\tNumber serviced\n");
+    storeAppendPrintf(sentry, "  open\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.open_start, squidaio_counts.open_finish);
+    storeAppendPrintf(sentry, "  close\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.close_start, squidaio_counts.close_finish);
+    storeAppendPrintf(sentry, "  cancel\t%" PRIu64 "\t-\n", squidaio_counts.cancel);
+    storeAppendPrintf(sentry, "  write\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.write_start, squidaio_counts.write_finish);
+    storeAppendPrintf(sentry, "  read\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.read_start, squidaio_counts.read_finish);
+    storeAppendPrintf(sentry, "  stat\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.stat_start, squidaio_counts.stat_finish);
+    storeAppendPrintf(sentry, "  unlink\t%" PRIu64 "\t%" PRIu64 "\n", squidaio_counts.unlink_start, squidaio_counts.unlink_finish);
+    storeAppendPrintf(sentry, "  check_callback\t%" PRIu64 "\t-\n", squidaio_counts.check_callback);
+    storeAppendPrintf(sentry, "  queue\t%d\t-\n", squidaio_get_queue_len());
     squidaio_stats(sentry);
 }
 
@@ -251,12 +225,19 @@ DiskThreadsIOStrategy::newFile (char const *path)
         return NULL;
     }
 
-    return new DiskThreadsDiskFile (path, this);
+    return new DiskThreadsDiskFile(path);
+}
+
+bool
+DiskThreadsIOStrategy::unlinkdUseful() const
+{
+    return false;
 }
 
 void
 DiskThreadsIOStrategy::unlinkFile(char const *path)
 {
-    statCounter.syscalls.disk.unlinks++;
+    ++statCounter.syscalls.disk.unlinks;
     aioUnlink(path, NULL, NULL);
 }
+