1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
From 740679a451f361b83f9604d238f02ef95aefd01e Mon Sep 17 00:00:00 2001
From: Alexandr Ilenko <AIlenko@IBS.RU>
Date: Mon, 20 Jun 2022 10:02:29 +0300
Subject: [PATCH 13/20] virtual-media.3: Upd: Apply "NetDevShare" devices
("CifsShare" and "NfsShare")
---
src/resources.hpp | 9 +++++----
src/state/activating_state.cpp | 11 ++++++++---
src/state/activating_state.hpp | 1 +
3 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/resources.hpp b/src/resources.hpp
index e307955..f300308 100644
--- a/src/resources.hpp
+++ b/src/resources.hpp
@@ -1,6 +1,6 @@
#pragma once
-#include "smb.hpp"
+#include "netdev.hpp"
#include "system.hpp"
namespace interfaces
@@ -74,15 +74,16 @@ class Mount
Mount& operator=(Mount&& other) = delete;
explicit Mount(
- std::unique_ptr<Directory> directory, SmbShare& smb,
+ std::unique_ptr<Directory> directory, NetDevShare& netDevShare,
const std::filesystem::path& remote, bool rw,
const std::unique_ptr<utils::CredentialsProvider>& credentials) :
directory(std::move(directory))
{
- if (!smb.mount(remote, rw, credentials))
+ if (!netDevShare.mount(remote, rw, credentials))
{
throw Error(std::errc::invalid_argument,
- "Failed to mount CIFS share");
+ (std::stringstream("Failed to mount ")
+ << netDevShare.getMountType() << " share").str());
}
}
diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp
index f926547..e50d284 100644
--- a/src/state/activating_state.cpp
+++ b/src/state/activating_state.cpp
@@ -143,13 +143,18 @@ std::unique_ptr<BasicState> ActivatingState::activateLegacyMode()
}
std::unique_ptr<BasicState> ActivatingState::mountSmbShare()
+{
+ return mountNetDevShare([](const fs::path& mountDir){ return std::make_unique<SmbShare>(mountDir); });
+}
+
+std::unique_ptr<BasicState> ActivatingState::mountNetDevShare(const std::function<std::unique_ptr<NetDevShare>(const fs::path&)>& netDevShareCreator)
{
try
{
auto mountDir =
std::make_unique<resource::Directory>(machine.getName());
- SmbShare smb(mountDir->getPath());
+ std::unique_ptr<NetDevShare> netDevShare = netDevShareCreator(mountDir->getPath());
fs::path remote = getImagePath(machine.getTarget()->imgUrl);
auto remoteParent = "/" + remote.parent_path().string();
auto localFile = mountDir->getPath() / remote.filename();
@@ -159,7 +164,7 @@ std::unique_ptr<BasicState> ActivatingState::mountSmbShare()
"\n Local file: ", localFile);
machine.getTarget()->mountPoint = std::make_unique<resource::Mount>(
- std::move(mountDir), smb, remoteParent, machine.getTarget()->rw,
+ std::move(mountDir), *netDevShare, remoteParent, machine.getTarget()->rw,
machine.getTarget()->credentials);
process = spawnNbdKit(machine, localFile);
@@ -195,7 +200,7 @@ std::unique_ptr<BasicState> ActivatingState::mountFtpShare()
std::unique_ptr<BasicState> ActivatingState::mountNfsShare()
{
- return mountXxxShare("NFS");
+ return mountNetDevShare([](const fs::path& mountDir){ return std::make_unique<NfsShare>(mountDir); });
}
std::unique_ptr<BasicState> ActivatingState::mountXxxShare(const char* pMountType)
diff --git a/src/state/activating_state.hpp b/src/state/activating_state.hpp
index affca24..1dca7aa 100644
--- a/src/state/activating_state.hpp
+++ b/src/state/activating_state.hpp
@@ -30,6 +30,7 @@ struct ActivatingState : public BasicStateT<ActivatingState>
std::unique_ptr<BasicState> mountFtpShare();
std::unique_ptr<BasicState> mountNfsShare();
std::unique_ptr<BasicState> mountXxxShare(const char* pMountType);
+ std::unique_ptr<BasicState> mountNetDevShare(const std::function<std::unique_ptr<NetDevShare>(const fs::path&)>& netDevShareCreator);
static std::unique_ptr<resource::Process>
spawnNbdKit(interfaces::MountPointStateMachine& machine,
--
2.35.1
|