]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/fs/rock/RockIoState.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / fs / rock / RockIoState.cc
index 4ee24ac55c31e3b5749eb377d1f8a4a9d7bb4780..94c627a11dd191f7043925f6c970b6fc9246b2eb 100644 (file)
@@ -1,19 +1,24 @@
 /*
- * DEBUG: section 79    Disk IO Routines
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 79    Disk IO Routines */
+
 #include "squid.h"
-#include "CollapsedForwarding.h"
 #include "base/TextException.h"
+#include "CollapsedForwarding.h"
 #include "DiskIO/DiskIOModule.h"
 #include "DiskIO/DiskIOStrategy.h"
 #include "DiskIO/WriteRequest.h"
-#include "fs/rock/RockIoState.h"
 #include "fs/rock/RockIoRequests.h"
+#include "fs/rock/RockIoState.h"
 #include "fs/rock/RockSwapDir.h"
 #include "globals.h"
 #include "MemObject.h"
-#include "Mem.h"
 #include "Parsing.h"
 #include "Transients.h"
 
@@ -22,13 +27,13 @@ Rock::IoState::IoState(Rock::SwapDir::Pointer &aDir,
                        StoreIOState::STFNCB *cbFile,
                        StoreIOState::STIOCB *cbIo,
                        void *data):
-        readableAnchor_(NULL),
-        writeableAnchor_(NULL),
-        sidCurrent(-1),
-        dir(aDir),
-        slotSize(dir->slotSize),
-        objOffset(0),
-        theBuf(dir->slotSize)
+    readableAnchor_(NULL),
+    writeableAnchor_(NULL),
+    sidCurrent(-1),
+    dir(aDir),
+    slotSize(dir->slotSize),
+    objOffset(0),
+    theBuf(dir->slotSize)
 {
     e = anEntry;
     e->lock("rock I/O");
@@ -119,10 +124,10 @@ Rock::IoState::read_(char *buf, size_t len, off_t coreOff, STRCB *cb, void *data
 
     offset_ = coreOff;
     len = min(len,
-        static_cast<size_t>(objOffset + currentReadableSlice().size - coreOff));
+              static_cast<size_t>(objOffset + currentReadableSlice().size - coreOff));
     const uint64_t diskOffset = dir->diskOffset(sidCurrent);
     theFile->read(new ReadRequest(::ReadRequest(buf,
-        diskOffset + sizeof(DbCellHeader) + coreOff - objOffset, len), this));
+                                  diskOffset + sizeof(DbCellHeader) + coreOff - objOffset, len), this));
 }
 
 void
@@ -137,7 +142,6 @@ Rock::IoState::callReaderBack(const char *buf, int rlen)
         callb(cbdata, buf, rlen, this);
 }
 
-
 /// wraps tryWrite() to handle deep write failures centrally and safely
 bool
 Rock::IoState::write(char const *buf, size_t size, off_t coreOff, FREE *dtor)
@@ -154,16 +158,19 @@ Rock::IoState::write(char const *buf, size_t size, off_t coreOff, FREE *dtor)
     }
 
     // careful: 'this' might be gone here
+
     if (dtor)
         (dtor)(const_cast<char*>(buf)); // cast due to a broken API?
 
     return success;
 }
 
-/** We only write data when full slot is accumulated or when close() is called.
- We buffer, in part, to avoid forcing OS to _read_ old unwritten portions of
- the slot when the write does not end at the page or sector boundary. */
+/**
+ * Possibly send data to be written to disk:
+ * We only write data when full slot is accumulated or when close() is called.
+ * We buffer, in part, to avoid forcing OS to _read_ old unwritten portions of
+ * the slot when the write does not end at the page or sector boundary.
+ */
 void
 Rock::IoState::tryWrite(char const *buf, size_t size, off_t coreOff)
 {
@@ -172,7 +179,7 @@ Rock::IoState::tryWrite(char const *buf, size_t size, off_t coreOff)
     // either this is the first write or append; we do not support write gaps
     assert(!coreOff || coreOff == -1);
 
-    // allocate the first slice diring the first write
+    // allocate the first slice during the first write
     if (!coreOff) {
         assert(sidCurrent < 0);
         sidCurrent = reserveSlotForWriting(); // throws on failures
@@ -204,7 +211,7 @@ Rock::IoState::tryWrite(char const *buf, size_t size, off_t coreOff)
 }
 
 /// Buffers incoming data for the current slot.
-/// Returns the number of bytes buffered.
+/// \return the number of bytes buffered
 size_t
 Rock::IoState::writeToBuffer(char const *buf, size_t size)
 {
@@ -273,7 +280,7 @@ Rock::IoState::writeBufToDisk(const SlotId sidNext, bool eof)
 
     WriteRequest *const r = new WriteRequest(
         ::WriteRequest(static_cast<char*>(wBuf), diskOffset, theBuf.size,
-            memFreeBufFunc(wBufCap)), this);
+                       memFreeBufFunc(wBufCap)), this);
     r->sidCurrent = sidCurrent;
     r->sidNext = sidNext;
     r->eof = eof;
@@ -344,20 +351,20 @@ class StoreIOStateCb: public CallDialer
 {
 public:
     StoreIOStateCb(StoreIOState::STIOCB *cb, void *data, int err, const Rock::IoState::Pointer &anSio):
-            callback(NULL),
-            callback_data(NULL),
-            errflag(err),
-            sio(anSio) {
+        callback(NULL),
+        callback_data(NULL),
+        errflag(err),
+        sio(anSio) {
 
         callback = cb;
         callback_data = cbdataReference(data);
     }
 
     StoreIOStateCb(const StoreIOStateCb &cb):
-            callback(NULL),
-            callback_data(NULL),
-            errflag(cb.errflag),
-            sio(cb.sio) {
+        callback(NULL),
+        callback_data(NULL),
+        errflag(cb.errflag),
+        sio(cb.sio) {
 
         callback = cb.callback;
         callback_data = cbdataReference(cb.callback_data);
@@ -367,13 +374,13 @@ public:
         cbdataReferenceDone(callback_data); // may be nil already
     }
 
-    void dial(AsyncCall &call) {
+    void dial(AsyncCall &) {
         void *cbd;
         if (cbdataReferenceValidDone(callback_data, &cbd) && callback)
             callback(cbd, errflag, sio.getRaw());
     }
 
-    bool canDial(AsyncCall &call) const {
+    bool canDial(AsyncCall &) const {
         return cbdataReferenceValid(callback_data) && callback;
     }
 
@@ -382,7 +389,7 @@ public:
     }
 
 private:
-    StoreIOStateCb &operator =(const StoreIOStateCb &cb); // not defined
+    StoreIOStateCb &operator =(const StoreIOStateCb &); // not defined
 
     StoreIOState::STIOCB *callback;
     void *callback_data;