]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Unlink shared segments used by memory cache, using RunnersRegistry API.
authorDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 19 Apr 2011 03:56:16 +0000 (07:56 +0400)
committerDmitry Kurochkin <dmitry.kurochkin@measurement-factory.com>
Tue, 19 Apr 2011 03:56:16 +0000 (07:56 +0400)
Implement static Unlink() method for Ipc::Mem::Segment and other shared
classes.

12 files changed:
src/MemStore.cc
src/ipc/StoreMap.cc
src/ipc/StoreMap.h
src/ipc/mem/PagePool.cc
src/ipc/mem/PagePool.h
src/ipc/mem/PageStack.cc
src/ipc/mem/PageStack.h
src/ipc/mem/Pages.cc
src/ipc/mem/Pages.h
src/ipc/mem/Segment.cc
src/ipc/mem/Segment.h
src/main.cc

index e1491d68a1eed0338caf39d5650a75bee0efd23c..cd12ec04c2d61e86ddf98d109df5ad052f14cdb0 100644 (file)
@@ -364,7 +364,7 @@ class MemStoreRr: public RegisteredRunner
 public:
     /* RegisteredRunner API */
     virtual void run(const RunnerRegistry &);
-    // TODO: cleanup in destructor
+    virtual ~MemStoreRr();
 };
 
 RunnerRegistrationEntry(rrAfterConfig, MemStoreRr);
@@ -377,3 +377,11 @@ void MemStoreRr::run(const RunnerRegistry &)
     if (IamMasterProcess())
         MemStore::Init();
 }
+
+MemStoreRr::~MemStoreRr()
+{
+    // XXX: restore if (!UsingSmp()) return;
+
+    if (IamMasterProcess())
+        MemStoreMap::Unlink(ShmLabel);
+}
index 705f17185553eee1d9a13c9a2bee0e34a0b59329..36763d215a1a7a4308f4cd10f8ac062b43ca8c00 100644 (file)
@@ -32,6 +32,12 @@ Ipc::StoreMap::StoreMap(const char *const aPath):
     debugs(54, 5, HERE << "attached map [" << path << "] created: " << shared->limit);
 }
 
+void
+Ipc::StoreMap::Unlink(const char *const path)
+{
+    Mem::Segment::Unlink(path);
+}
+
 Ipc::StoreMap::Slot *
 Ipc::StoreMap::openForWriting(const cache_key *const key, sfileno &fileno)
 {
index 9ca540f625796f93490b096e00d96e443e3c6480..735647195476ffb53e8b7264a7719ab0965464f4 100644 (file)
@@ -55,6 +55,7 @@ public:
 
     StoreMap(const char *const aPath, const int limit, size_t sharedSizeExtra); ///< create a new shared StoreMap
     explicit StoreMap(const char *const aPath); ///< open an existing shared StoreMap
+    static void Unlink(const char *const path); ///< unlink shared memory segment
 
     /// finds, reservers space for writing a new entry or returns nil
     Slot *openForWriting(const cache_key *const key, sfileno &fileno);
index b698017302332ebf1f1336c0114f5526f2e09195..4a9ce46ff5694bd57de051ad5426da4972014412 100644 (file)
@@ -38,6 +38,13 @@ Ipc::Mem::PagePool::PagePool(const String &id):
     assert(shared);
 }
 
+void
+Ipc::Mem::PagePool::Unlink(const String &id)
+{
+    PageStack::Unlink(PageIndexId(id));
+    Segment::Unlink(id.termedBuf());
+}
+
 bool
 Ipc::Mem::PagePool::get(PageId &page)
 {
index d151263f199a48c1e57a3a0e00292220a143fd88..4c4b96b6c857cea732a1cc77f7d3cec9ff6039ef 100644 (file)
@@ -24,6 +24,8 @@ public:
     PagePool(const String &id, const unsigned int capacity, const size_t pageSize);
     /// attaches to the identified shared page pool
     PagePool(const String &id);
+    /// unlinks shared memory segments
+    static void Unlink(const String &id);
 
     unsigned int capacity() const { return shared->theCapacity; }
     /// lower bound for the number of free pages
index 41b09967c1ae9b6a12c13bf1bdf9ae7cd1050310..30891d0981bdd037b9eaf01dbcd31e2553736be2 100644 (file)
@@ -29,6 +29,12 @@ Ipc::Mem::PageStack::PageStack(const String &id): shm(id.termedBuf())
     assert(shared);
 }
 
+void
+Ipc::Mem::PageStack::Unlink(const String &id)
+{
+    Segment::Unlink(id.termedBuf());
+}
+
 /*
  * TODO: We currently rely on the theLastReadable hint during each
  * loop iteration. We could also use hint just for the start position:
index 936a207cb4a52b2d497b71b019a5d6c4e89345a5..20d6a1a3d98160cd149f4df3730037f2407a4ac4 100644 (file)
@@ -24,6 +24,8 @@ public:
     PageStack(const String &id, const unsigned int capacity);
     /// attaches to the identified shared stack
     PageStack(const String &id);
+    /// unlinks shared memory segment
+    static void Unlink(const String &id);
 
     /// lower bound for the number of free pages
     unsigned int size() const { return max(0, shared->theSize.get()); }
index 61684b6e77bab691cb831e12b70baefd027e63a0..dccb7b0e7d4f6e560f9d28d8988548cfb29d836b 100644 (file)
@@ -85,7 +85,7 @@ class SharedMemPagesRr: public RegisteredRunner
 public:
     /* RegisteredRunner API */
     virtual void run(const RunnerRegistry &);
-    // TODO: cleanup in destructor
+    virtual ~SharedMemPagesRr();
 };
 
 RunnerRegistrationEntry(rrAfterConfig, SharedMemPagesRr);
@@ -114,3 +114,10 @@ void SharedMemPagesRr::run(const RunnerRegistry &)
     else
         Ipc::Mem::Attach();
 }
+
+SharedMemPagesRr::~SharedMemPagesRr()
+{
+    delete ThePagePool;
+    if (IamMasterProcess())
+        Ipc::Mem::PagePool::Unlink(PagePoolId);
+}
index bbd2023e4b9b5900590fe4106dce2bed35069efa..9c97155503ede5c539923b93e0fe12c2916ad9c7 100644 (file)
@@ -18,7 +18,6 @@ void Init();
 /// attaches this kid to the already configured shared memory [pools]
 void Attach();
 
-
 /* Single page manipulation */
 
 /// sets page ID and returns true unless no free pages are found
index 1b059fba77c33356cc75303fff45a8d1a2cabdf8..fac4b61acddebf3361fba33e2519d15bbd8e8df3 100644 (file)
@@ -124,6 +124,14 @@ Ipc::Mem::Segment::reserve(size_t chunkSize)
     return result;
 }
 
+void
+Ipc::Mem::Segment::Unlink(const char *const id)
+{
+    const String path = GenerateName(id);
+    if (shm_unlink(path.termedBuf()) != 0)
+        debugs(54, 5, HERE << "shm_unlink(" << path << "): " << xstrerror());
+}
+
 /// determines the size of the underlying "file"
 off_t
 Ipc::Mem::Segment::statSize(const char *context) const
index f05481729f6dcf95bf1e94914e39880a999a1619..415cee1cacb59bf0db1197a21373966290c27653 100644 (file)
@@ -30,6 +30,8 @@ public:
     void *reserve(size_t chunkSize); ///< reserve and return the next chunk
     // TODO: convert most mem() calls to reserve()
 
+    static void Unlink(const char *const id); ///< unlink the segment
+
 private:
     void attach();
     void detach();
index 2a5bac5c4977f5ebeca1a39a8f22e2a61c21b360..a526290b7b4afebb8b3a83fefee5db3a626b4813 100644 (file)
@@ -1431,7 +1431,6 @@ SquidMain(int argc, char **argv)
 
     debugs(1,2, HERE << "Doing post-config initialization\n");
     ActivateRegistered(rrAfterConfig);
-    // TODO: find a place to call DeactivateRegistered(rrAfterConfig);
 
     if (!opt_no_daemon && Config.workers > 0)
         watch_child(argv);
@@ -1797,6 +1796,8 @@ syslog(LOG_NOTICE, "XXX: will start %d kids", (int)TheKids.count());
 #endif
 
         if (!TheKids.someRunning() && !TheKids.shouldRestartSome()) {
+            DeactivateRegistered(rrAfterConfig);
+
             if (TheKids.someSignaled(SIGINT) || TheKids.someSignaled(SIGTERM)) {
                 syslog(LOG_ALERT, "Exiting due to unexpected forced shutdown");
                 exit(1);
@@ -1896,6 +1897,7 @@ SquidShutdown()
     Store::Root().sync();              /* Flush log close */
     StoreFileSystem::FreeAllFs();
     DiskIOModule::FreeAllModules();
+    DeactivateRegistered(rrAfterConfig);
 #if LEAK_CHECK_MODE && 0 /* doesn't work at the moment */
 
     configFreeMemory();