Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/data_watcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ int DataWatcher::inotifyInit() const
return fd;
}

void DataWatcher::stop()
Comment thread
manishtwari marked this conversation as resolved.
{
lg2::debug("Stopping DataWatcher for [{PATH}], removing [{COUNT}] watches",
"PATH", _dataPathToWatch, "COUNT", _watchDescriptors.size());

auto wds = _watchDescriptors | std::views::keys |
std::ranges::to<std::vector>();

std::ranges::for_each(wds, [this](int wd) { removeWatch(wd); });
}

std::string DataWatcher::eventName(uint32_t eventMask)
{
std::vector<std::string> events{};
Expand Down
10 changes: 10 additions & 0 deletions src/data_watcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <filesystem>
#include <map>
#include <unordered_set>
#include <vector>

namespace data_sync::watch::inotify
{
Expand Down Expand Up @@ -105,6 +106,15 @@ class DataWatcher
*/
sdbusplus::async::task<DataOperations> onDataChange();

/**
* @brief Stop all active inotify watches.
*
* Removes all watch descriptors, causing the kernel to emit
* IN_IGNORED which unblocks any pending co_await on onDataChange().
* The inotify fd is closed by the destructor after the coroutine exits.
*/
void stop();

/**
* @brief Get the current watch descriptors map
*
Expand Down
30 changes: 9 additions & 21 deletions src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,21 +264,9 @@ sdbusplus::async::task<> Manager::startSyncEvents()
return this->isSyncEligible(dataSyncCfg);
}),
[this](const auto& dataSyncCfg) {
using enum config::SyncDirection;
using enum config::SyncType;
if (dataSyncCfg._syncType == Immediate)
{
// Bidirectional watchers can already be running when sync is
// enabled again during failover. Skip creating the same watcher
// again.
if ((dataSyncCfg._syncDirection == Bidirectional) &&
_activeWatchers.contains(dataSyncCfg._path))
{
lg2::debug(
"Bidirectional watcher already exists for {PATH}, skipping duplicate watcher",
"PATH", dataSyncCfg._path);
return;
}
try
{
this->_ctx.spawn(this->monitorDataToSync(dataSyncCfg));
Expand All @@ -293,14 +281,6 @@ sdbusplus::async::task<> Manager::startSyncEvents()
}
else if (dataSyncCfg._syncType == Deferred)
{
if ((dataSyncCfg._syncDirection == Bidirectional) &&
_activeWatchers.contains(dataSyncCfg._path))
{
lg2::debug(
"Bidirectional watcher already exists for {PATH}, skipping duplicate watcher",
"PATH", dataSyncCfg._path);
return;
}
try
{
this->_ctx.spawn(this->monitorDeferredDataToSync(dataSyncCfg));
Expand Down Expand Up @@ -331,6 +311,14 @@ sdbusplus::async::task<> Manager::startSyncEvents()
co_return;
}

void Manager::stopSyncEvents()
{
for (auto& [path, watcher] : _activeWatchers)
{
watcher->stop();
}
}

bool Manager::isRetryEligible(uint8_t errCode) noexcept
{
switch (errCode)
Expand Down Expand Up @@ -966,8 +954,8 @@ void Manager::disableSyncPropChanged(bool disableSync)
{
if (disableSync)
{
// TODO: Disable all sync events using Sender Receiver.
lg2::info("Sync is Disabled, Stopping events");
stopSyncEvents();
}
else
{
Expand Down
8 changes: 8 additions & 0 deletions src/manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,14 @@ class Manager
*/
sdbusplus::async::task<> startSyncEvents();

/**
* @brief Stop all active data change watchers.
*
* Stops each watcher in _activeWatchers, allowing their monitor
* coroutines to exit cleanly.
*/
void stopSyncEvents();

/**
* @brief API responsible to trigger sibling notification if required.
*
Expand Down