/*
- * $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.
*/
-#include "squid-old.h"
+/* 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 "StatCounters.h"
-#include "SquidTime.h"
+#endif
diskd_stats_t diskd_stats;
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
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);
}
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,
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");
}
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);
++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
}
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;
--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);
}
+