From: Dmitry Kurochkin Date: Tue, 19 Apr 2011 03:56:16 +0000 (+0400) Subject: Unlink shared segments used by memory cache, using RunnersRegistry API. X-Git-Tag: take06~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c011f9bc30434b5376ebe9bbd338bdd46fc49e5d;p=thirdparty%2Fsquid.git Unlink shared segments used by memory cache, using RunnersRegistry API. Implement static Unlink() method for Ipc::Mem::Segment and other shared classes. --- diff --git a/src/MemStore.cc b/src/MemStore.cc index e1491d68a1..cd12ec04c2 100644 --- a/src/MemStore.cc +++ b/src/MemStore.cc @@ -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); +} diff --git a/src/ipc/StoreMap.cc b/src/ipc/StoreMap.cc index 705f171855..36763d215a 100644 --- a/src/ipc/StoreMap.cc +++ b/src/ipc/StoreMap.cc @@ -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) { diff --git a/src/ipc/StoreMap.h b/src/ipc/StoreMap.h index 9ca540f625..7356471954 100644 --- a/src/ipc/StoreMap.h +++ b/src/ipc/StoreMap.h @@ -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); diff --git a/src/ipc/mem/PagePool.cc b/src/ipc/mem/PagePool.cc index b698017302..4a9ce46ff5 100644 --- a/src/ipc/mem/PagePool.cc +++ b/src/ipc/mem/PagePool.cc @@ -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) { diff --git a/src/ipc/mem/PagePool.h b/src/ipc/mem/PagePool.h index d151263f19..4c4b96b6c8 100644 --- a/src/ipc/mem/PagePool.h +++ b/src/ipc/mem/PagePool.h @@ -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 diff --git a/src/ipc/mem/PageStack.cc b/src/ipc/mem/PageStack.cc index 41b09967c1..30891d0981 100644 --- a/src/ipc/mem/PageStack.cc +++ b/src/ipc/mem/PageStack.cc @@ -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: diff --git a/src/ipc/mem/PageStack.h b/src/ipc/mem/PageStack.h index 936a207cb4..20d6a1a3d9 100644 --- a/src/ipc/mem/PageStack.h +++ b/src/ipc/mem/PageStack.h @@ -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()); } diff --git a/src/ipc/mem/Pages.cc b/src/ipc/mem/Pages.cc index 61684b6e77..dccb7b0e7d 100644 --- a/src/ipc/mem/Pages.cc +++ b/src/ipc/mem/Pages.cc @@ -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); +} diff --git a/src/ipc/mem/Pages.h b/src/ipc/mem/Pages.h index bbd2023e4b..9c97155503 100644 --- a/src/ipc/mem/Pages.h +++ b/src/ipc/mem/Pages.h @@ -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 diff --git a/src/ipc/mem/Segment.cc b/src/ipc/mem/Segment.cc index 1b059fba77..fac4b61acd 100644 --- a/src/ipc/mem/Segment.cc +++ b/src/ipc/mem/Segment.cc @@ -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 diff --git a/src/ipc/mem/Segment.h b/src/ipc/mem/Segment.h index f05481729f..415cee1cac 100644 --- a/src/ipc/mem/Segment.h +++ b/src/ipc/mem/Segment.h @@ -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(); diff --git a/src/main.cc b/src/main.cc index 2a5bac5c49..a526290b7b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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();