summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Platash <anna.platash@intel.com>2021-04-15 11:22:15 +0300
committerCzarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>2021-04-27 00:27:12 +0300
commit7cc83164ffd69b4da0143f7e531f919b9006f944 (patch)
tree84f656aa359d698fae9acd370b2a97dc221a3a11
parent4c9eb513d67d0b6261da7579d21a00079a3deaea (diff)
downloadvirtual-media-7cc83164ffd69b4da0143f7e531f919b9006f944.tar.xz
Image mount fails if socket directory not present
When trying to mount virtual media image in Legacy mode nbd tries to create unix socket and if the parent directory does not exist mount fails. Also used noexcept versions of filesystem operations. Tested: Locally, by manually removing the socket's parent folder and mounting an image in Legacy mode (Samba). Change-Id: If5beb7add655e09a60511b30e4edbd34c8c15ec5 Signed-off-by: Anna Platash <anna.platash@intel.com> Signed-off-by: Czarnowski, Przemyslaw <przemyslaw.hawrylewicz.czarnowski@intel.com>
-rw-r--r--src/state/activating_state.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp
index 9cbd324..15d7214 100644
--- a/src/state/activating_state.cpp
+++ b/src/state/activating_state.cpp
@@ -11,6 +11,7 @@
#include <boost/container/flat_map.hpp>
#include <boost/container/flat_set.hpp>
#include <boost/process.hpp>
+#include <boost/system/detail/error_code.hpp>
#include <filesystem>
#include <iostream>
#include <memory>
@@ -82,6 +83,36 @@ std::unique_ptr<BasicState> ActivatingState::activateLegacyMode()
" Mount requested on address: ", machine.getTarget()->imgUrl,
" ; RW: ", machine.getTarget()->rw);
+ std::filesystem::path socketPath(machine.getConfig().unixSocket);
+ if (!std::filesystem::exists(socketPath.parent_path()))
+ {
+ LogMsg(Logger::Debug, machine.getName(),
+ " Parent path for the socket does not exist, ",
+ socketPath.parent_path());
+
+ std::error_code errc;
+ std::filesystem::create_directories(socketPath.parent_path(), errc);
+ if (errc)
+ {
+ LogMsg(Logger::Debug, machine.getName(),
+ " Failed to create parent directory for socket", errc);
+ return std::make_unique<ReadyState>(
+ machine, static_cast<std::errc>(errc.value()),
+ "Failed to create parent directory for socket");
+ }
+ std::filesystem::permissions(socketPath.parent_path(),
+ std::filesystem::perms::owner_all, errc);
+ if (errc)
+ {
+ LogMsg(Logger::Debug, machine.getName(),
+ " Failed to set parent directory permissions for socket",
+ errc);
+ return std::make_unique<ReadyState>(
+ machine, static_cast<std::errc>(errc.value()),
+ "Failed to set parent permissions directory for socket");
+ }
+ }
+
if (isCifsUrl(machine.getTarget()->imgUrl))
{
return mountSmbShare();