/*
- * $Id$
+ * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
*
- * DEBUG: section 79 Squid-side DISKD I/O functions.
- * AUTHOR: Duane Wessels
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * 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.
*/
+/* DEBUG: section 79 Squid-side DISKD I/O functions. */
+
#include "squid.h"
+#include "comm/Loops.h"
+#include "ConfigOption.h"
+#include "diomsg.h"
+#include "DiskdFile.h"
+#include "DiskdIOStrategy.h"
+#include "DiskIO/DiskFile.h"
+#include "fd.h"
+#include "SquidConfig.h"
+#include "SquidIpc.h"
+#include "SquidTime.h"
+#include "StatCounters.h"
+#include "Store.h"
+#include "unlinkd.h"
+#include <cerrno>
+#if HAVE_SYS_IPC_H
#include <sys/ipc.h>
+#endif
+#if HAVE_SYS_MSG_H
#include <sys/msg.h>
+#endif
+#if HAVE_SYS_SHM_H
#include <sys/shm.h>
-#include "DiskdIOStrategy.h"
-#include "ConfigOption.h"
-#include "DiskIO/DiskFile.h"
-#include "DiskdFile.h"
-#include "diomsg.h"
-/* for statfs */
-#include "Store.h"
-#include "SquidTime.h"
+#endif
diskd_stats_t diskd_stats;
void
DiskdIOStrategy::openFailed()
{
- diskd_stats.open_fail_queue_len++;
+ ++diskd_stats.open_fail_queue_len;
}
DiskFile::Pointer
return new DiskdFile (path, this);
}
-DiskdIOStrategy::DiskdIOStrategy() : magic1(64), magic2(72), away(0) , smsgid(-1), rmsgid(-1), wfd(-1) , instanceID(newInstance())
+DiskdIOStrategy::DiskdIOStrategy() : magic1(64), magic2(72), away(0), smsgid(-1), rmsgid(-1), wfd(-1), instanceID(newInstance())
{}
+bool
+DiskdIOStrategy::unlinkdUseful() const
+{
+ return true;
+}
+
void
DiskdIOStrategy::unlinkFile(char const *path)
{
if (shedLoad()) {
/* Damn, we need to issue a sync unlink here :( */
debugs(79, 2, "storeDiskUnlink: Out of queue space, sync unlink");
-#if USE_UNLINKD
-
unlinkdUnlink(path);
-#else
-
- unlink(path);
-#endif
-
return;
}
shm_offset);
if (x < 0) {
- debugs(79, 1, "storeDiskdSend UNLINK: " << xstrerror());
- ::unlink(buf); /* XXX EWW! */
+ int xerrno = errno;
+ debugs(79, DBG_IMPORTANT, "storeDiskdSend UNLINK: " << xstrerr(xerrno));
+ ::unlink(buf); /* XXX EWW! */
// shm.put (shm_offset);
}
- diskd_stats.unlink.ops++;
+ ++diskd_stats.unlink.ops;
}
void
char skey1[32];
char skey2[32];
char skey3[32];
- IpAddress localhost;
+ Ip::Address localhost;
ikey = (getpid() << 10) + (instanceID << 2);
ikey &= 0x7fffffff;
smsgid = msgget((key_t) ikey, 0700 | IPC_CREAT);
if (smsgid < 0) {
- debugs(50, 0, "storeDiskdInit: msgget: " << xstrerror());
+ int xerrno = errno;
+ debugs(50, DBG_CRITICAL, MYNAME << "msgget: " << xstrerr(xerrno));
fatal("msgget failed");
}
rmsgid = msgget((key_t) (ikey + 1), 0700 | IPC_CREAT);
if (rmsgid < 0) {
- debugs(50, 0, "storeDiskdInit: msgget: " << xstrerror());
+ int xerrno = errno;
+ debugs(50, DBG_CRITICAL, MYNAME << "msgget: " << xstrerr(xerrno));
fatal("msgget failed");
}
args[2] = skey2;
args[3] = skey3;
args[4] = NULL;
- localhost.SetLocalhost();
+ localhost.setLocalhost();
pid = ipcCreate(IPC_STREAM,
Config.Program.diskd,
args,
fd_note(wfd, "squid -> diskd");
- commSetTimeout(wfd, -1, NULL, NULL);
-
+ commUnsetFdTimeout(wfd);
commSetNonBlocking(wfd);
-
- comm_quick_poll_required();
+ Comm::QuickPollRequired();
}
/*
char *aBuf = NULL;
int i;
- for (i = 0; i < nbufs; i++) {
+ for (i = 0; i < nbufs; ++i) {
if (CBIT_TEST(inuse_map, i))
continue;
assert(aBuf);
assert(aBuf >= buf);
assert(aBuf < buf + (nbufs * SHMBUF_BLKSZ));
- diskd_stats.shmbuf_count++;
+ ++diskd_stats.shmbuf_count;
if (diskd_stats.max_shmuse < diskd_stats.shmbuf_count)
diskd_stats.max_shmuse = diskd_stats.shmbuf_count;
nbufs * SHMBUF_BLKSZ, 0600 | IPC_CREAT);
if (id < 0) {
- debugs(50, 0, "storeDiskdInit: shmget: " << xstrerror());
+ int xerrno = errno;
+ debugs(50, DBG_CRITICAL, MYNAME << "shmget: " << xstrerr(xerrno));
fatal("shmget failed");
}
buf = (char *)shmat(id, NULL, 0);
if (buf == (void *) -1) {
- debugs(50, 0, "storeDiskdInit: shmat: " << xstrerror());
+ int xerrno = errno;
+ debugs(50, DBG_CRITICAL, MYNAME << "shmat: " << xstrerr(xerrno));
fatal("shmat failed");
}
inuse_map = (char *)xcalloc((nbufs + 7) / 8, 1);
diskd_stats.shmbuf_count += nbufs;
- for (int i = 0; i < nbufs; i++) {
+ for (int i = 0; i < nbufs; ++i) {
CBIT_SET(inuse_map, i);
put (i * SHMBUF_BLKSZ);
}
DiskdIOStrategy::unlinkDone(diomsg * M)
{
debugs(79, 3, "storeDiskdUnlinkDone: file " << shm.buf + M->shm_offset << " status " << M->status);
- statCounter.syscalls.disk.unlinks++;
+ ++statCounter.syscalls.disk.unlinks;
if (M->status < 0)
- diskd_stats.unlink.fail++;
+ ++diskd_stats.unlink.fail;
else
- diskd_stats.unlink.success++;
+ ++diskd_stats.unlink.success;
}
void
return;
}
-
/* set errno passed from diskd. makes debugging more meaningful */
if (M->status < 0)
errno = -M->status;
if (M->newstyle) {
DiskdFile *theFile = (DiskdFile *)M->callback_data;
- theFile->RefCountDereference();
+ theFile->unlock();
theFile->completed (M);
} else
switch (M->mtype) {
}
int
-DiskdIOStrategy::send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, RefCountable_ *requestor)
+DiskdIOStrategy::send(int mtype, int id, DiskdFile *theFile, size_t size, off_t offset, ssize_t shm_offset, Lock *requestor)
{
diomsg M;
M.callback_data = cbdataReference(theFile);
- theFile->RefCountReference();
+ theFile->lock();
M.requestor = requestor;
M.newstyle = true;
if (requestor)
- requestor->RefCountReference();
+ requestor->lock();
return SEND(&M, mtype, id, size, offset, shm_offset);
}
M->seq_no = ++seq_no;
if (M->seq_no < last_seq_no)
- debugs(79, 1, "WARNING: sequencing out of order");
+ debugs(79, DBG_IMPORTANT, "WARNING: sequencing out of order");
x = msgsnd(smsgid, M, diomsg::msg_snd_rcv_sz, IPC_NOWAIT);
last_seq_no = M->seq_no;
if (0 == x) {
- diskd_stats.sent_count++;
- away++;
+ ++diskd_stats.sent_count;
+ ++away;
} else {
- debugs(79, 1, "storeDiskdSend: msgsnd: " << xstrerror());
+ int xerrno = errno;
+ debugs(79, DBG_IMPORTANT, MYNAME << "msgsnd: " << xstrerr(xerrno));
cbdataReferenceDone(M->callback_data);
- assert(++send_errors < 100);
+ ++send_errors;
+ assert(send_errors < 100);
if (shm_offset > -1)
shm.put(shm_offset);
}
* will cause an assertion in storeDiskdShmGet().
*/
/* TODO: have DiskdIO hold a link to the swapdir, to allow detailed reporting again */
- debugs(3, 1, "WARNING: cannot increase cache_dir Q1 value while Squid is running.");
+ debugs(3, DBG_IMPORTANT, "WARNING: cannot increase cache_dir Q1 value while Squid is running.");
magic1 = old_magic1;
return true;
}
if (old_magic1 != magic1)
- debugs(3, 1, "cache_dir new Q1 value '" << magic1 << "'");
+ debugs(3, DBG_IMPORTANT, "cache_dir new Q1 value '" << magic1 << "'");
return true;
}
if (old_magic2 < magic2) {
/* See comments in Q1 function above */
- debugs(3, 1, "WARNING: cannot increase cache_dir Q2 value while Squid is running.");
+ debugs(3, DBG_IMPORTANT, "WARNING: cannot increase cache_dir Q2 value while Squid is running.");
magic2 = old_magic2;
return true;
}
if (old_magic2 != magic2)
- debugs(3, 1, "cache_dir new Q2 value '" << magic2 << "'");
+ debugs(3, DBG_IMPORTANT, "cache_dir new Q2 value '" << magic2 << "'");
return true;
}
while (away > 0) {
if (squid_curtime > lastmsg) {
- debugs(47, 1, "storeDiskdDirSync: " << away << " messages away");
+ debugs(47, DBG_IMPORTANT, "storeDiskdDirSync: " << away << " messages away");
lastmsg = squid_curtime;
}
}
}
-
/*
* Handle callbacks. If we have more than magic2 requests away, we block
* until the queue is below magic2. Otherwise, we simply return when we
int retval = 0;
if (away >= magic2) {
- diskd_stats.block_queue_len++;
+ ++diskd_stats.block_queue_len;
retval = 1;
/* We might not have anything to do, but our queue
* is full.. */
}
while (1) {
-#ifdef ALWAYS_ZERO_BUFFERS
+#ifdef ALWAYS_ZERO_BUFFERS
memset(&M, '\0', sizeof(M));
#endif
if (x < 0)
break;
else if (x != diomsg::msg_snd_rcv_sz) {
- debugs(47, 1, "storeDiskdDirCallback: msgget returns " << x);
+ debugs(47, DBG_IMPORTANT, "storeDiskdDirCallback: msgget returns " << x);
break;
}
- diskd_stats.recv_count++;
+ ++diskd_stats.recv_count;
--away;
handle(&M);
- retval = 1; /* Return that we've actually done some work */
+ retval = 1; /* Return that we've actually done some work */
if (M.shm_offset > -1)
shm.put ((off_t) M.shm_offset);
{
storeAppendPrintf(&sentry, "Pending operations: %d\n", away);
}
+