summaryrefslogtreecommitdiff
path: root/virtual-media/src/smb.hpp
diff options
context:
space:
mode:
authorAgata Olender <agata.olender@intel.com>2020-01-13 17:57:37 +0300
committerOlender, Agata <agata.olender@intel.com>2020-02-06 12:07:57 +0300
commit50a08676fe320defa961610c29ace5fc71b0c0f1 (patch)
tree68d3371656840924860f07aaa1ff86f9a9265524 /virtual-media/src/smb.hpp
parent8f3c2240f6dd48888e8552e905945ffcd62900a6 (diff)
downloadprovingground-50a08676fe320defa961610c29ace5fc71b0c0f1.tar.xz
Integration with NBDKit for Legacy mode
This change introduces integration of virtual-media application with NBDKit. NBDKit is used here to connect to externally provided image on web and expose NBD device internally in BMC for NBD subsystem (already implemented in Proxy mode) to use. 'Mount' D-Bus call accepts 's imgUrl' and 'b rw'. Based on 's imgUrl' prefix (https:// or smb://) proper mount type is attempted. 'b rw' determines Read-Only mode for both USB Gadget and NBD stack. When 'Mount' is called, virtual-media parses arguments, determines mounting options and attempts to mount external share. For SMB protocol native CIFS Linux module is used: 1) mount(8) call is used to mound provided CIFS share 2) NBDKit loads file on mounted filesystem and exposes NBD Server on internal unix socket 3) Pre-existing code takes care of mouting gadget automatically (connecting socket to /dev/nbdX and then /dev/nbdX to USB Gadget) For HTTPS protocol provisioning is performed by NBDKit: 1) NBDKit connects to provided resource and exposes NBD Server on internal unix socket 2) Pre-existing code takes care of mouting gadget automatically (connecting socket to /dev/nbdX and then /dev/nbdX to USB Gadget) Tested: Manual and automated tests on WilsonCity platform: - mounting and unmounting images over CIFS and HTTPS (single, multiple at the same time etc) - positive and negative tests for D-Bus calls - ensuring proper information is exposed on D-Bus Change-Id: Ia2b6e8c13603521063f5c94cdfdb06f2e872e9e7 Signed-off-by: Adrian Ambrożewicz <adrian.ambrozewicz@linux.intel.com> Signed-off-by: Agata Olender <agata.olender@intel.com>
Diffstat (limited to 'virtual-media/src/smb.hpp')
-rw-r--r--virtual-media/src/smb.hpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/virtual-media/src/smb.hpp b/virtual-media/src/smb.hpp
new file mode 100644
index 0000000..3189770
--- /dev/null
+++ b/virtual-media/src/smb.hpp
@@ -0,0 +1,76 @@
+#pragma once
+
+#include "logger.hpp"
+
+#include <sys/mount.h>
+
+#include <filesystem>
+#include <optional>
+
+namespace fs = std::filesystem;
+
+class SmbShare
+{
+ public:
+ SmbShare(const fs::path& mountDir) : mountDir(mountDir)
+ {
+ }
+
+ bool mount(const fs::path& remote, bool rw)
+ {
+ LogMsg(Logger::Debug, "Trying to mount remote : ", remote);
+
+ const std::string params = "nolock,sec=ntlmsspi,seal,vers=3.0";
+ const std::string perm = rw ? "rw" : "ro";
+ auto options = params + "," + perm;
+ LogMsg(Logger::Debug, "Mounting with options: ", options);
+
+ auto ec = ::mount(remote.c_str(), mountDir.c_str(), "cifs", 0,
+ options.c_str());
+ if (ec)
+ {
+ LogMsg(Logger::Error, "Mount failed with ec = ", ec,
+ " errno = ", errno);
+ return false;
+ }
+
+ return true;
+ }
+
+ static std::optional<fs::path> createMountDir(const fs::path& name)
+ {
+ auto destPath = fs::temp_directory_path() / name;
+ std::error_code ec;
+
+ if (fs::create_directory(destPath, ec))
+ {
+ return destPath;
+ }
+
+ LogMsg(Logger::Error, ec,
+ " : Unable to create mount directory: ", destPath);
+ return {};
+ }
+
+ static void unmount(const fs::path& mountDir)
+ {
+ int result;
+ std::error_code ec;
+
+ result = ::umount(mountDir.string().c_str());
+ if (result)
+ {
+ LogMsg(Logger::Error, result, " : Unable to unmout directory ",
+ mountDir);
+ }
+
+ if (!fs::remove_all(mountDir, ec))
+ {
+ LogMsg(Logger::Error, ec, " : Unable to remove mount directory ",
+ mountDir);
+ }
+ }
+
+ private:
+ std::string mountDir;
+}; \ No newline at end of file