From: Amos Jeffries Date: Mon, 27 Jan 2014 05:27:41 +0000 (-0700) Subject: Bug 3608: part 1 - per-service name for workers UDS sockets X-Git-Tag: SQUID_3_5_0_1~397 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ee292b7b9744bc535e69fc5a00118763a9fd339;p=thirdparty%2Fsquid.git Bug 3608: part 1 - per-service name for workers UDS sockets Separate the UDS socket names used by SMP workers by the -n service_name label assigned to the Squid instance being run. TODO: separate shared memory blocks per-service. --- diff --git a/src/CollapsedForwarding.cc b/src/CollapsedForwarding.cc index a3aa4a1e80..862a0111c9 100644 --- a/src/CollapsedForwarding.cc +++ b/src/CollapsedForwarding.cc @@ -87,7 +87,7 @@ CollapsedForwarding::Notify(const int workerId) Ipc::TypedMsgHdr msg; msg.setType(Ipc::mtCollapsedForwardingNotification); msg.putInt(KidIdentifier); - const String addr = Ipc::Port::MakeAddr(Ipc::strandAddrPfx, workerId); + const String addr = Ipc::Port::MakeAddr(Ipc::strandAddrLabel, workerId); Ipc::SendMessage(addr, msg); } diff --git a/src/DiskIO/IpcIo/IpcIoFile.cc b/src/DiskIO/IpcIo/IpcIoFile.cc index 85972209eb..7307727d85 100644 --- a/src/DiskIO/IpcIo/IpcIoFile.cc +++ b/src/DiskIO/IpcIo/IpcIoFile.cc @@ -114,7 +114,7 @@ IpcIoFile::open(int flags, mode_t mode, RefCount callback) ann.strand.tag = dbName; Ipc::TypedMsgHdr message; ann.pack(message); - SendMessage(Ipc::coordinatorAddr, message); + SendMessage(Ipc::Port::CoordinatorAddr(), message); ioRequestor->ioCompletedNotification(); return; @@ -126,7 +126,7 @@ IpcIoFile::open(int flags, mode_t mode, RefCount callback) Ipc::TypedMsgHdr msg; request.pack(msg); - Ipc::SendMessage(Ipc::coordinatorAddr, msg); + Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), msg); WaitingForOpen.push_back(this); @@ -460,7 +460,7 @@ IpcIoFile::Notify(const int peerId) Ipc::TypedMsgHdr msg; msg.setType(Ipc::mtIpcIoNotification); // TODO: add proper message type? msg.putInt(KidIdentifier); - const String addr = Ipc::Port::MakeAddr(Ipc::strandAddrPfx, peerId); + const String addr = Ipc::Port::MakeAddr(Ipc::strandAddrLabel, peerId); Ipc::SendMessage(addr, msg); } diff --git a/src/ipc/Coordinator.cc b/src/ipc/Coordinator.cc index 7cf2619723..bb7318fcba 100644 --- a/src/ipc/Coordinator.cc +++ b/src/ipc/Coordinator.cc @@ -28,7 +28,7 @@ CBDATA_NAMESPACED_CLASS_INIT(Ipc, Coordinator); Ipc::Coordinator* Ipc::Coordinator::TheInstance = NULL; Ipc::Coordinator::Coordinator(): - Port(coordinatorAddr) + Port(Ipc::Port::CoordinatorAddr()) { } @@ -136,7 +136,7 @@ void Ipc::Coordinator::handleRegistrationRequest(const HereIamMessage& msg) // send back an acknowledgement; TODO: remove as not needed? TypedMsgHdr message; msg.pack(message); - SendMessage(MakeAddr(strandAddrPfx, msg.strand.kidId), message); + SendMessage(MakeAddr(strandAddrLabel, msg.strand.kidId), message); } void @@ -156,7 +156,7 @@ Ipc::Coordinator::handleSharedListenRequest(const SharedListenRequest& request) SharedListenResponse response(c->fd, errNo, request.mapId); TypedMsgHdr message; response.pack(message); - SendMessage(MakeAddr(strandAddrPfx, request.requestorId), message); + SendMessage(MakeAddr(strandAddrLabel, request.requestorId), message); } void @@ -181,7 +181,7 @@ Ipc::Coordinator::handleCacheMgrRequest(const Mgr::Request& request) Mgr::Response response(request.requestId); TypedMsgHdr message; response.pack(message); - SendMessage(MakeAddr(strandAddrPfx, request.requestorId), message); + SendMessage(MakeAddr(strandAddrLabel, request.requestorId), message); } @@ -221,7 +221,7 @@ Ipc::Coordinator::notifySearcher(const Ipc::StrandSearchRequest &request, const StrandSearchResponse response(strand); TypedMsgHdr message; response.pack(message); - SendMessage(MakeAddr(strandAddrPfx, request.requestorId), message); + SendMessage(MakeAddr(strandAddrLabel, request.requestorId), message); } #if SQUID_SNMP @@ -233,7 +233,7 @@ Ipc::Coordinator::handleSnmpRequest(const Snmp::Request& request) Snmp::Response response(request.requestId); TypedMsgHdr message; response.pack(message); - SendMessage(MakeAddr(strandAddrPfx, request.requestorId), message); + SendMessage(MakeAddr(strandAddrLabel, request.requestorId), message); AsyncJob::Start(new Snmp::Inquirer(request, strands_)); } diff --git a/src/ipc/Forwarder.cc b/src/ipc/Forwarder.cc index 2446bcfa75..4d05e3f70c 100644 --- a/src/ipc/Forwarder.cc +++ b/src/ipc/Forwarder.cc @@ -59,7 +59,7 @@ Ipc::Forwarder::start() handleError(); } - SendMessage(coordinatorAddr, message); + SendMessage(Ipc::Port::CoordinatorAddr(), message); eventAdd("Ipc::Forwarder::requestTimedOut", &Forwarder::RequestTimedOut, this, timeout, 0, false); } diff --git a/src/ipc/Inquirer.cc b/src/ipc/Inquirer.cc index 6ffc51344d..9b0d93a351 100644 --- a/src/ipc/Inquirer.cc +++ b/src/ipc/Inquirer.cc @@ -72,7 +72,7 @@ Ipc::Inquirer::inquire() TheRequestsMap[request->requestId] = callback; TypedMsgHdr message; request->pack(message); - SendMessage(Port::MakeAddr(strandAddrPfx, kidId), message); + SendMessage(Port::MakeAddr(strandAddrLabel, kidId), message); eventAdd("Ipc::Inquirer::requestTimedOut", &Inquirer::RequestTimedOut, this, timeout, 0, false); } diff --git a/src/ipc/Port.cc b/src/ipc/Port.cc index 927252ce26..2535d05b25 100644 --- a/src/ipc/Port.cc +++ b/src/ipc/Port.cc @@ -7,10 +7,12 @@ #include "comm.h" #include "comm/Connection.h" #include "CommCalls.h" +#include "globals.h" #include "ipc/Port.h" -const char Ipc::coordinatorAddr[] = DEFAULT_STATEDIR "/coordinator.ipc"; -const char Ipc::strandAddrPfx[] = DEFAULT_STATEDIR "/kid"; +static const char channelPathPfx[] = DEFAULT_STATEDIR "/"; +static const char coordinatorAddrLabel[] = "-coordinator"; +const char Ipc::strandAddrLabel[] = "-kid"; Ipc::Port::Port(const String& aListenAddr): UdsOp(aListenAddr) @@ -39,16 +41,31 @@ bool Ipc::Port::doneAll() const return false; // listen forever } -String Ipc::Port::MakeAddr(const char* pathAddr, int id) +String Ipc::Port::MakeAddr(const char* processLabel, int id) { assert(id >= 0); - String addr = pathAddr; + String addr = channelPathPfx; + addr.append(service_name); + addr.append(processLabel); addr.append('-'); addr.append(xitoa(id)); addr.append(".ipc"); return addr; } +String +Ipc::Port::CoordinatorAddr() +{ + static String coordinatorAddr; + if (!coordinatorAddr.size()) { + coordinatorAddr= channelPathPfx; + coordinatorAddr.append(service_name); + coordinatorAddr.append(coordinatorAddrLabel); + coordinatorAddr.append(".ipc"); + } + return coordinatorAddr; +} + void Ipc::Port::noteRead(const CommIoCbParams& params) { debugs(54, 6, HERE << params.conn << " flag " << params.flag << diff --git a/src/ipc/Port.h b/src/ipc/Port.h index 299a6c7ade..01949b844b 100644 --- a/src/ipc/Port.h +++ b/src/ipc/Port.h @@ -17,8 +17,11 @@ class Port: public UdsOp { public: Port(const String &aListenAddr); - /// calculates IPC message address for strand #id at path - static String MakeAddr(const char *path, int id); + /// calculates IPC message address for strand #id of processLabel type + static String MakeAddr(const char *proccessLabel, int id); + + /// get the IPC message address for coordinator process + static String CoordinatorAddr(); protected: virtual void start() = 0; // UdsOp (AsyncJob) API; has body @@ -37,8 +40,7 @@ private: TypedMsgHdr buf; ///< msghdr struct filled by Comm }; -extern const char coordinatorAddr[]; ///< where coordinator listens -extern const char strandAddrPfx[]; ///< strand's listening address prefix +extern const char strandAddrLabel[]; ///< strand's listening address unique label } // namespace Ipc diff --git a/src/ipc/SharedListen.cc b/src/ipc/SharedListen.cc index 430617891e..52bfd2d5a8 100644 --- a/src/ipc/SharedListen.cc +++ b/src/ipc/SharedListen.cc @@ -117,7 +117,7 @@ void Ipc::JoinSharedListen(const OpenListenerParams ¶ms, TypedMsgHdr message; request.pack(message); - SendMessage(coordinatorAddr, message); + SendMessage(Ipc::Port::CoordinatorAddr(), message); } void Ipc::SharedListenJoined(const SharedListenResponse &response) diff --git a/src/ipc/Strand.cc b/src/ipc/Strand.cc index 20c57236f3..60c4e5badb 100644 --- a/src/ipc/Strand.cc +++ b/src/ipc/Strand.cc @@ -32,7 +32,7 @@ CBDATA_NAMESPACED_CLASS_INIT(Ipc, Strand); Ipc::Strand::Strand(): - Port(MakeAddr(strandAddrPfx, KidIdentifier)), + Port(MakeAddr(strandAddrLabel, KidIdentifier)), isRegistered(false) { } @@ -51,7 +51,7 @@ void Ipc::Strand::registerSelf() HereIamMessage ann(StrandCoord(KidIdentifier, getpid())); TypedMsgHdr message; ann.pack(message); - SendMessage(coordinatorAddr, message); + SendMessage(Port::CoordinatorAddr(), message); setTimeout(6, "Ipc::Strand::timeoutHandler"); // TODO: make 6 configurable? } diff --git a/src/mgr/Action.cc b/src/mgr/Action.cc index f350e5ef76..46985cbe39 100644 --- a/src/mgr/Action.cc +++ b/src/mgr/Action.cc @@ -79,7 +79,7 @@ Mgr::Action::sendResponse(unsigned int requestId) Response response(requestId, this); Ipc::TypedMsgHdr message; response.pack(message); - Ipc::SendMessage(Ipc::coordinatorAddr, message); + Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), message); } void diff --git a/src/snmp/Forwarder.cc b/src/snmp/Forwarder.cc index 3ec663fcf2..252a50b099 100644 --- a/src/snmp/Forwarder.cc +++ b/src/snmp/Forwarder.cc @@ -101,5 +101,5 @@ Snmp::SendResponse(unsigned int requestId, const Pdu& pdu) } Ipc::TypedMsgHdr message; response.pack(message); - Ipc::SendMessage(Ipc::coordinatorAddr, message); + Ipc::SendMessage(Ipc::Port::CoordinatorAddr(), message); } diff --git a/src/tests/stub_Port.cc b/src/tests/stub_Port.cc index 5c12a54ead..d39f6e2f9b 100644 --- a/src/tests/stub_Port.cc +++ b/src/tests/stub_Port.cc @@ -4,7 +4,7 @@ #define STUB_API "ipc/Port.cc" #include "tests/STUB.h" -const char Ipc::coordinatorAddr[] = ""; -const char Ipc::strandAddrPfx[] = ""; +const char Ipc::strandAddrLabel[] = "-kid"; String Ipc::Port::MakeAddr(char const*, int) STUB_RETVAL("") +String Ipc::Port::CoordinatorAddr() STUB_RETVAL("")