]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3608: part 1 - per-service name for workers UDS sockets
authorAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Jan 2014 05:27:41 +0000 (22:27 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Mon, 27 Jan 2014 05:27:41 +0000 (22:27 -0700)
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.

12 files changed:
src/CollapsedForwarding.cc
src/DiskIO/IpcIo/IpcIoFile.cc
src/ipc/Coordinator.cc
src/ipc/Forwarder.cc
src/ipc/Inquirer.cc
src/ipc/Port.cc
src/ipc/Port.h
src/ipc/SharedListen.cc
src/ipc/Strand.cc
src/mgr/Action.cc
src/snmp/Forwarder.cc
src/tests/stub_Port.cc

index a3aa4a1e800ece698d703465d32a23eb429ace9d..862a0111c9ca126d013ae862a4a5dfa1b3e5857d 100644 (file)
@@ -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);
 }
 
index 85972209eb97545ccf2b9a8bf2a30c641a10d077..7307727d8509bd82b67f8f7039869002e49daab8 100644 (file)
@@ -114,7 +114,7 @@ IpcIoFile::open(int flags, mode_t mode, RefCount<IORequestor> 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<IORequestor> 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);
 }
 
index 7cf2619723fb0cb0023e0e8b5b962ac1c846ecb9..bb7318fcba712ab81be14d124d5acca51f6c6dfe 100644 (file)
@@ -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_));
 }
index 2446bcfa750d668b5e5e2bc43a3079f27de5e9d5..4d05e3f70c11e5ab4e714191a6e0cff51053fb3d 100644 (file)
@@ -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);
 }
index 6ffc51344d60c9bec6fdb58c37d76b171318f167..9b0d93a3514b3df9ff48dcc4748b4f93adbb8409 100644 (file)
@@ -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);
 }
index 927252ce26308c163fcd8354a3efca751494047f..2535d05b25c4c1b8aa26ab5fadc32be0c713cacd 100644 (file)
@@ -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 <<
index 299a6c7ade7d438f7bfe2bea1e32bf4344c48418..01949b844b0ee52a24c51c348d34c6761613cab9 100644 (file)
@@ -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
 
index 430617891ec0cd8eca9d01fc3917f5803274a26a..52bfd2d5a83c7899d3a81732dde77676858fa79b 100644 (file)
@@ -117,7 +117,7 @@ void Ipc::JoinSharedListen(const OpenListenerParams &params,
 
     TypedMsgHdr message;
     request.pack(message);
-    SendMessage(coordinatorAddr, message);
+    SendMessage(Ipc::Port::CoordinatorAddr(), message);
 }
 
 void Ipc::SharedListenJoined(const SharedListenResponse &response)
index 20c57236f3dd421f434d052293679bde605cc14a..60c4e5badb9e0be5e1d99c8aa2bd902acad981f1 100644 (file)
@@ -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?
 }
 
index f350e5ef764d45b00d6654ab561e1e0b9f1d6c78..46985cbe3996620f5a509ee69f73748ee0d18017 100644 (file)
@@ -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
index 3ec663fcf2ad7286476f7f4af00c2b117c7fe5db..252a50b0997c67bb298396498af6d8c5f721b06d 100644 (file)
@@ -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);
 }
index 5c12a54ead8d1b408955c835cb8ee4e5e4171773..d39f6e2f9bb5a6b8c5f86079cc09073babb364b4 100644 (file)
@@ -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("")