JPP <jpp1@frws.com>
Juan <jdsq12@yahoo.es>
Juerg Michel
+ Juju4 <juju4@users.noreply.github.com>
Julien Pinon <jpinon@olfeo.com>
Karl Benoit <karl.isatwork@gmail.com>
Khalid Abdullah <khalidcomilla58@gmail.com>
void aioStat(char *, struct stat *, AIOCB *, void *);
void aioUnlink(const char *, AIOCB *, void *);
-int aioQueueSize(void);
+size_t aioQueueSize(void);
#include "DiskIO/DiskFile.h"
static Mem::Allocator *squidaio_tiny_bufs = nullptr; /* 2K */
static Mem::Allocator *squidaio_micro_bufs = nullptr; /* 128K */
-static int request_queue_len = 0;
+static size_t request_queue_len = 0;
static Mem::Allocator *squidaio_request_pool = nullptr;
static Mem::Allocator *squidaio_thread_pool = nullptr;
static squidaio_request_queue_t request_queue;
void
squidaio_init(void)
{
- int i;
squidaio_thread_t *threadp;
if (squidaio_initialised)
assert(NUMTHREADS != 0);
- for (i = 0; i < NUMTHREADS; ++i) {
+ for (size_t i = 0; i < NUMTHREADS; ++i) {
threadp = (squidaio_thread_t *)squidaio_thread_pool->alloc();
threadp->status = _THREAD_STARTING;
threadp->current_req = nullptr;
/* Warn if out of threads */
if (request_queue_len > MAGIC1) {
static int last_warn = 0;
- static int queue_high, queue_low;
+ static size_t queue_high, queue_low;
if (high_start == 0) {
high_start = squid_curtime;
squidaio_stats(StoreEntry * sentry)
{
squidaio_thread_t *threadp;
- int i;
if (!squidaio_initialised)
return;
threadp = threads;
- for (i = 0; i < NUMTHREADS; ++i) {
- storeAppendPrintf(sentry, "%i\t0x%lx\t%ld\n", i + 1, (unsigned long)threadp->thread, threadp->requests);
+ for (size_t i = 0; i < NUMTHREADS; ++i) {
+ storeAppendPrintf(sentry, "%zu\t0x%lx\t%ld\n", i + 1, (unsigned long)threadp->thread, threadp->requests);
threadp = threadp->next;
}
}
dlinkAdd(ctrlp, &ctrlp->node, &used_list);
} /* aioUnlink */
-int
+size_t
aioQueueSize(void)
{
return squidaio_ctrl_t::UseCount();
~DiskConfig() { delete[] swapDirs; }
RefCount<SwapDir> *swapDirs = nullptr;
- int n_allocated = 0;
- int n_configured = 0;
+ size_t n_allocated = 0;
+ size_t n_configured = 0;
/// number of disk processes required to support all cache_dirs
int n_strands = 0;
};
{}
void
-Auth::SchemeConfig::parse(Auth::SchemeConfig * scheme, int, char *param_str)
+Auth::SchemeConfig::parse(Auth::SchemeConfig * scheme, size_t, char *param_str)
{
if (strcmp(param_str, "program") == 0) {
if (authenticateProgram)
virtual void registerWithCacheManager(void);
/** parse config options */
- virtual void parse(SchemeConfig *, int, char *);
+ virtual void parse(SchemeConfig *, size_t, char *);
/** the http string id */
virtual const char * type() const = 0;
}
void
-Auth::Basic::Config::parse(Auth::SchemeConfig * scheme, int n_configured, char *param_str)
+Auth::Basic::Config::parse(Auth::SchemeConfig * scheme, size_t n_configured, char *param_str)
{
if (strcmp(param_str, "credentialsttl") == 0) {
parse_time_t(&credentialsTTL);
bool dump(StoreEntry *, const char *, Auth::SchemeConfig *) const override;
void fixHeader(Auth::UserRequest::Pointer, HttpReply *, Http::HdrType, HttpRequest *) override;
void init(Auth::SchemeConfig *) override;
- void parse(Auth::SchemeConfig *, int, char *) override;
+ void parse(Auth::SchemeConfig *, size_t, char *) override;
void decode(char const *httpAuthHeader, Auth::UserRequest::Pointer);
void registerWithCacheManager(void) override;
const char * type() const override;
{}
void
-Auth::Digest::Config::parse(Auth::SchemeConfig * scheme, int n_configured, char *param_str)
+Auth::Digest::Config::parse(Auth::SchemeConfig * scheme, size_t n_configured, char *param_str)
{
if (strcmp(param_str, "nonce_garbage_interval") == 0) {
parse_time_t(&nonceGCInterval);
bool dump(StoreEntry *, const char *, Auth::SchemeConfig *) const override;
void fixHeader(Auth::UserRequest::Pointer, HttpReply *, Http::HdrType, HttpRequest *) override;
void init(Auth::SchemeConfig *) override;
- void parse(Auth::SchemeConfig *, int, char *) override;
+ void parse(Auth::SchemeConfig *, size_t, char *) override;
void registerWithCacheManager(void) override;
const char * type() const override;
void Rock::SwapDirRr::create()
{
Must(mapOwners.empty() && freeSlotsOwners.empty());
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (const Rock::SwapDir *const sd = dynamic_cast<Rock::SwapDir *>(INDEXSD(i))) {
rebuildStatsOwners.push_back(Rebuild::Stats::Init(*sd));
#include <sys/stat.h>
#endif
-int Fs::Ufs::UFSSwapDir::NumberOfUFSDirs = 0;
+size_t Fs::Ufs::UFSSwapDir::NumberOfUFSDirs = 0;
int *Fs::Ufs::UFSSwapDir::UFSDirToGlobalDirMapping = nullptr;
class UFSCleanLog : public SwapDir::CleanLog
if (swaplog_fd < 0) /* not open */
return;
+ assert(NumberOfUFSDirs > 0);
--NumberOfUFSDirs;
- assert(NumberOfUFSDirs >= 0);
if (!NumberOfUFSDirs)
safe_free(UFSDirToGlobalDirMapping);
Fs::Ufs::UFSSwapDir::HandleCleanEvent()
{
static int swap_index = 0;
- int i;
int j = 0;
- int n = 0;
+ size_t n = 0;
if (!NumberOfUFSDirs)
return 0; // probably in the middle of reconfiguration
*/
UFSDirToGlobalDirMapping = (int *)xcalloc(NumberOfUFSDirs, sizeof(*UFSDirToGlobalDirMapping));
- for (i = 0, n = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
/* This is bogus, the controller should just clean each instance once */
sd = dynamic_cast <SwapDir *>(INDEXSD(i));
int D1, D2;
int L1, L2;
int filn = fn;
- assert(F0 < Config.cacheSwap.n_configured);
+ assert(F0 >= 0);
+ assert(static_cast<size_t>(F0) < Config.cacheSwap.n_configured);
assert (UFSSwapDir::IsUFSDir (dynamic_cast<SwapDir *>(INDEXSD(F0))));
UFSSwapDir *sd = dynamic_cast<UFSSwapDir *>(INDEXSD(F0));
private:
void parseSizeL1L2();
- static int NumberOfUFSDirs;
+ static size_t NumberOfUFSDirs;
static int * UFSDirToGlobalDirMapping;
bool pathIsDirectory(const char *path)const;
int swaplog_fd;
int
IdleConnList::findIndexOf(const Comm::ConnectionPointer &conn) const
{
- for (int index = size_ - 1; index >= 0; --index) {
+ for (auto right = size_; right > 0; --right) {
+ const auto index = right - 1;
if (conn->fd == theList_[index]->fd) {
debugs(48, 3, "found " << conn << " at index " << index);
return index;
* \retval false The index is not an in-use entry.
*/
bool
-IdleConnList::removeAt(int index)
+IdleConnList::removeAt(size_t index)
{
- if (index < 0 || index >= size_)
+ if (index >= size_)
return false;
+ assert(size_ > 0);
// shuffle the remaining entries to fill the new gap.
for (; index < size_ - 1; ++index)
// almost a duplicate of removeFD. But drops multiple entries.
void
-IdleConnList::closeN(size_t n)
+IdleConnList::closeN(const size_t n)
{
if (n < 1) {
debugs(48, 2, "Nothing to do.");
return;
- } else if (n >= (size_t)size_) {
+ } else if (n >= size_) {
debugs(48, 2, "Closing all entries.");
while (size_ > 0) {
const Comm::ConnectionPointer conn = theList_[--size_];
parent_->noteConnectionRemoved();
}
// shuffle the list N down.
- for (index = 0; index < (size_t)size_ - n; ++index) {
+ for (index = 0; index < size_ - n; ++index) {
theList_[index] = theList_[index + n];
}
// ensure the last N entries are unset
- while (index < ((size_t)size_)) {
+ while (index < size_) {
theList_[index] = nullptr;
++index;
}
capacity_ <<= 1;
const Comm::ConnectionPointer *oldList = theList_;
theList_ = new Comm::ConnectionPointer[capacity_];
- for (int index = 0; index < size_; ++index)
+ for (size_t index = 0; index < size_; ++index)
theList_[index] = oldList[index];
delete[] oldList;
Comm::ConnectionPointer
IdleConnList::pop()
{
- for (int i=size_-1; i>=0; --i) {
+ for (auto right = size_; right > 0; --right) {
+ const auto i = right - 1;
if (!isAvailable(i))
continue;
const bool keyCheckAddr = !aKey->local.isAnyAddr();
const bool keyCheckPort = aKey->local.port() > 0;
- for (int i=size_-1; i>=0; --i) {
+ for (auto right = size_; right > 0; --right) {
+ const auto i = right - 1;
if (!isAvailable(i))
continue;
void clearHandlers(const Comm::ConnectionPointer &conn);
+ // TODO: Upgrade to return size_t
int count() const { return size_; }
+
void closeN(size_t count);
// IndependentRunner API
void endingShutdown() override;
private:
bool isAvailable(int i) const;
- bool removeAt(int index);
+ bool removeAt(size_t index);
int findIndexOf(const Comm::ConnectionPointer &conn) const;
void findAndClose(const Comm::ConnectionPointer &conn);
static IOCB Read;
Comm::ConnectionPointer *theList_;
/// Number of entries theList can currently hold without re-allocating (capacity).
- int capacity_;
+ size_t capacity_;
///< Number of in-use entries in theList
- int size_;
+ size_t size_;
/** The pool containing this sub-list.
* The parent performs all stats accounting, and
Must(swap_status == SWAPOUT_NONE);
} else {
Must(swap_filen >= 0);
- Must(swap_dirn < Config.cacheSwap.n_configured);
+ Must(static_cast<size_t>(swap_dirn) < Config.cacheSwap.n_configured);
if (swapoutFailed()) {
Must(EBIT_TEST(flags, RELEASE_REQUEST));
} else {
/// TODO: Remove when cache_dir-iterating functions are converted to Disks methods
static SwapDir &
-SwapDirByIndex(const int i)
+SwapDirByIndex(const size_t i)
{
- assert(i >= 0);
assert(i < Config.cacheSwap.n_allocated);
const auto sd = INDEXSD(i);
assert(sd);
// Increment the first candidate once per selection (not once per
// iteration) to reduce bias when some disk(s) attract more entries.
- static int firstCandidate = 0;
+ static size_t firstCandidate = 0;
if (++firstCandidate >= Config.cacheSwap.n_configured)
firstCandidate = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
- const int dirn = (firstCandidate + i) % Config.cacheSwap.n_configured;
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ const auto dirn = (firstCandidate + i) % Config.cacheSwap.n_configured;
auto &dir = SwapDirByIndex(dirn);
int load = 0;
int least_load = INT_MAX;
int load;
SwapDir *selectedDir = nullptr;
- int i;
const int64_t objsize = objectSizeForDirSelection(*e);
- for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
auto &sd = SwapDirByIndex(i);
sd.flags.selected = false;
}
SwapDir *
-Store::Disks::store(int const x) const
+Store::Disks::store(const size_t x) const
{
return &SwapDirByIndex(x);
}
SwapDir &
-Store::Disks::Dir(const int i)
+Store::Disks::Dir(const size_t i)
{
return SwapDirByIndex(i);
}
{
int result = 0;
int j;
- static int ndir = 0;
+ static size_t ndir = 0;
do {
j = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (ndir >= Config.cacheSwap.n_configured)
ndir = ndir % Config.cacheSwap.n_configured;
debugs(0, DBG_PARSE_NOTE(DBG_CRITICAL), "No cache_dir stores are configured.");
}
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).active())
store(i)->create();
}
StoreEntry *
Store::Disks::get(const cache_key *key)
{
- if (const int cacheDirs = Config.cacheSwap.n_configured) {
+ if (const auto cacheDirs = Config.cacheSwap.n_configured) {
// ask each cache_dir until the entry is found; use static starting
// point to avoid asking the same subset of disks more often
// TODO: coordinate with put() to be able to guess the right disk often
- static int idx = 0;
- for (int n = 0; n < cacheDirs; ++n) {
+ static size_t idx = 0;
+ for (size_t n = 0; n < cacheDirs; ++n) {
idx = (idx + 1) % cacheDirs;
auto &sd = Dir(idx);
if (!sd.active())
// level is decremented in each corresponding storeRebuildComplete() call.
StoreController::store_dirs_rebuilding += Config.cacheSwap.n_configured;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
/* this starts a search of the store dirs, loading their
* index. under the new Store api this should be
* driven by the StoreHashIndex, not by each store.
{
uint64_t result = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).doReportStat())
result += store(i)->maxSize();
}
{
uint64_t result = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).doReportStat())
result += store(i)->minSize();
}
{
uint64_t result = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).doReportStat())
result += store(i)->currentSize();
}
{
uint64_t result = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).doReportStat())
result += store(i)->currentCount();
}
Config.cacheSwap.n_strands = 0;
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
auto &disk = Dir(i);
if (disk.needsDiskStrand()) {
assert(InDaemonMode());
// check for the existing cache_dir
// XXX: This code mistreats duplicated cache_dir entries (that should be fatal).
- for (int i = 0; i < swap.n_configured; ++i) {
+ for (size_t i = 0; i < swap.n_configured; ++i) {
auto &disk = Dir(i);
if ((strcasecmp(pathStr, disk.path)) == 0) {
/* this is specific to on-fs Stores. The right
}
}
- const int cacheDirCountLimit = 64; // StoreEntry::swap_dirn is a signed 7-bit integer
+ const size_t cacheDirCountLimit = 64; // StoreEntry::swap_dirn is a signed 7-bit integer
if (swap.n_configured >= cacheDirCountLimit)
throw TextException(ToSBuf("Squid cannot handle more than ", cacheDirCountLimit, " cache_dir directives"), Here());
void
Store::Disks::Dump(const DiskConfig &swap, StoreEntry &entry, const char *name)
{
- for (int i = 0; i < swap.n_configured; ++i) {
+ for (size_t i = 0; i < swap.n_configured; ++i) {
const auto &disk = Dir(i);
storeAppendPrintf(&entry, "%s %s %s", name, disk.type(), disk.path);
disk.dump(entry);
Store::Disks::getStats(StoreInfoStats &stats) const
{
// accumulate per-disk cache stats
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
StoreInfoStats dirStats;
store(i)->getStats(dirStats);
stats += dirStats;
void
Store::Disks::stat(StoreEntry & output) const
{
- int i;
-
/* Now go through each store, calling its stat routine */
- for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
storeAppendPrintf(&output, "\n");
store(i)->stat(output);
}
void
Store::Disks::maintain()
{
- int i;
/* walk each fs */
- for (i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
/* XXX FixMe: This should be done "in parallel" on the different
* cache_dirs, not one at a time.
*/
void
Store::Disks::sync()
{
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i)
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i)
store(i)->sync();
}
void
Store::Disks::evictIfFound(const cache_key *key)
{
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (Dir(i).active())
Dir(i).evictIfFound(key);
}
if (entry.hasDisk())
return true; // already anchored
- if (const int cacheDirs = Config.cacheSwap.n_configured) {
+ if (const size_t cacheDirs = Config.cacheSwap.n_configured) {
// ask each cache_dir until the entry is found; use static starting
// point to avoid asking the same subset of disks more often
// TODO: coordinate with put() to be able to guess the right disk often
- static int idx = 0;
- for (int n = 0; n < cacheDirs; ++n) {
+ static size_t idx = 0;
+ for (size_t n = 0; n < cacheDirs; ++n) {
idx = (idx + 1) % cacheDirs;
SwapDir &sd = Dir(idx);
if (!sd.active())
bool
Store::Disks::SmpAware()
{
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
// A mix is not supported, but we conservatively check every
// dir because features like collapsed revalidation should
// currently be disabled if any dir is SMP-aware
bool
Store::Disks::hasReadableEntry(const StoreEntry &e) const
{
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i)
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i)
if (Dir(i).active() && Dir(i).hasReadableEntry(e))
return true;
return false;
void
storeDirOpenSwapLogs()
{
- for (int dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+ for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
SwapDirByIndex(dirn).openLog();
}
void
storeDirCloseSwapLogs()
{
- for (int dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+ for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
SwapDirByIndex(dirn).closeLog();
}
struct timeval start;
double dt;
- int dirn;
int notdone = 1;
// Check for store_dirs_rebuilding because fatal() often calls us in early
getCurrentTime();
start = current_time;
- for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
+ for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
auto &sd = SwapDirByIndex(dirn);
if (sd.writeCleanStart() < 0) {
while (notdone) {
notdone = 0;
- for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
+ for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn) {
auto &sd = SwapDirByIndex(dirn);
if (!sd.cleanLog)
}
/* Flush */
- for (dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
+ for (size_t dirn = 0; dirn < Config.cacheSwap.n_configured; ++dirn)
SwapDirByIndex(dirn).writeCleanDone();
if (reopen)
if (swap.n_allocated == swap.n_configured) {
swap.n_allocated <<= 1;
const auto tmp = new SwapDir::Pointer[swap.n_allocated];
- for (int i = 0; i < swap.n_configured; ++i) {
+ for (size_t i = 0; i < swap.n_configured; ++i) {
tmp[i] = swap.swapDirs[i];
}
delete[] swap.swapDirs;
private:
/* migration logic */
- SwapDir *store(int const x) const;
- static SwapDir &Dir(int const idx);
+ SwapDir *store(size_t index) const;
+ static SwapDir &Dir(size_t index);
int64_t largestMinimumObjectSize; ///< maximum of all Disk::minObjectSize()s
int64_t largestMaximumObjectSize; ///< maximum of all Disk::maxObjectSize()s
* progress.
*/
void
-storeRebuildProgress(int sd_index, int total, int sofar)
+storeRebuildProgress(const int sd_index_raw, const int total, const int sofar)
{
static time_t last_report = 0;
// TODO: Switch to int64_t and fix handling of unknown totals.
double n = 0.0;
double d = 0.0;
- if (sd_index < 0)
+ if (sd_index_raw < 0)
return;
+ // TODO: Upgrade Disk::index and sd_index_raw to size_t, removing this cast.
+ const auto sd_index = static_cast<size_t>(sd_index_raw);
if (sd_index >= Config.cacheSwap.n_configured)
return;
if (squid_curtime - last_report < 15)
return;
- for (sd_index = 0; sd_index < Config.cacheSwap.n_configured; ++sd_index) {
- n += (double) RebuildProgress[sd_index].scanned;
- d += (double) RebuildProgress[sd_index].total;
+ for (size_t diskIndex = 0; diskIndex < Config.cacheSwap.n_configured; ++diskIndex) {
+ n += (double) RebuildProgress[diskIndex].scanned;
+ d += (double) RebuildProgress[diskIndex].total;
}
debugs(20, Important(57), "Indexing cache entries: " << Progress(n, d));
e->swap_filen = 0; /* garh - lower level*/
e->swap_dirn = -1;
- for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (INDEXSD(i) == aStore)
e->swap_dirn = i;
}
e->swap_filen = 0; /* garh - lower level*/
e->swap_dirn = -1;
- for (int i=0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
if (INDEXSD(i) == aStore)
e->swap_dirn = i;
}
unlinkdNeeded(void)
{
// we should start unlinkd if there are any cache_dirs using it
- for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
+ for (size_t i = 0; i < Config.cacheSwap.n_configured; ++i) {
const RefCount<SwapDir> sd = Config.cacheSwap.swapDirs[i];
if (sd->unlinkdUseful())
return true;