From 05eb73ebe684b8d2879c3802029fd783bdf6686c Mon Sep 17 00:00:00 2001 From: Karol Wachowski Date: Thu, 23 Jul 2020 08:25:04 +0000 Subject: VirtualMedia throw EBUSY exception when receive invalid event in actiavting/deactivating states Previously mount/unmount waited until timeout occurs, when operation was already process it could finish before the timeout causing mount/unmount to get false positive/negative results. Tested: - Mount/Unmount dbus calls cause EBUSY exception in actiavting/deactivating states Change-Id: Idaacde212531c963aec304ac87e536d014d9d8d2 Signed-off-by: Karol Wachowski --- src/state/activating_state.hpp | 8 +++----- src/state/deactivating_state.hpp | 8 +++----- src/state/initial_state.hpp | 23 ++--------------------- 3 files changed, 8 insertions(+), 31 deletions(-) diff --git a/src/state/activating_state.hpp b/src/state/activating_state.hpp index bd1688f..295d185 100644 --- a/src/state/activating_state.hpp +++ b/src/state/activating_state.hpp @@ -17,14 +17,12 @@ struct ActivatingState : public BasicStateT std::unique_ptr handleEvent(SubprocessStoppedEvent event); template - std::unique_ptr handleEvent(AnyEvent event) - { + [[noreturn]] std::unique_ptr handleEvent(AnyEvent event) { LogMsg(Logger::Error, "Invalid event: ", event.eventName); - return nullptr; + throw sdbusplus::exception::SdBusError(EBUSY, "Resource is busy"); } - private: - std::unique_ptr activateProxyMode(); + private : std::unique_ptr activateProxyMode(); std::unique_ptr activateLegacyMode(); std::unique_ptr mountSmbShare(); std::unique_ptr mountHttpsShare(); diff --git a/src/state/deactivating_state.hpp b/src/state/deactivating_state.hpp index 7f3010a..0ad6f5b 100644 --- a/src/state/deactivating_state.hpp +++ b/src/state/deactivating_state.hpp @@ -49,14 +49,12 @@ struct DeactivatingState : public BasicStateT } template - std::unique_ptr handleEvent(AnyEvent event) - { + [[noreturn]] std::unique_ptr handleEvent(AnyEvent event) { LogMsg(Logger::Error, "Invalid event: ", event.eventName); - return nullptr; + throw sdbusplus::exception::SdBusError(EBUSY, "Resource is busy"); } - private: - std::unique_ptr evaluate() + private : std::unique_ptr evaluate() { if (udevStateChangeEvent && subprocessStoppedEvent) { diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp index fecf2b6..f64ff25 100644 --- a/src/state/initial_state.hpp +++ b/src/state/initial_state.hpp @@ -134,17 +134,7 @@ struct InitialState : public BasicStateT timerPeriod](boost::asio::yield_context yield) { LogMsg(Logger::Info, "[App]: Unmount called on ", machine.getName()); - - try - { - machine.emitUnmountEvent(); - } - catch (const std::exception& e) - { - LogMsg(Logger::Error, e.what()); - throw sdbusplus::exception::SdBusError(EPERM, e.what()); - return false; - } + machine.emitUnmountEvent(); auto repeats = waitCnt; boost::asio::steady_timer timer(machine.getIoc()); @@ -174,16 +164,7 @@ struct InitialState : public BasicStateT interfaces::MountPointStateMachine& machine, std::optional target) { - try - { - machine.emitMountEvent(std::move(target)); - } - catch (const std::exception& e) - { - LogMsg(Logger::Error, e.what()); - throw sdbusplus::exception::SdBusError(EPERM, e.what()); - return false; - } + machine.emitMountEvent(std::move(target)); auto repeats = waitCnt; boost::asio::steady_timer timer(machine.getIoc()); -- cgit v1.2.3