summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/virtual-media/virtual-media/0002-Add-http-ftp-nfs-protocols-nbdkit-curl-plugin-suppor.patch
blob: c41a5e37a93f36f3d8fb070ee1be271c7fee8622 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
From a907de416f0fa41a27af562a9b31fa5224da3899 Mon Sep 17 00:00:00 2001
From: Alexandr Ilenko <AIlenko@IBS.RU>
Date: Mon, 6 Jun 2022 15:36:08 +0300
Subject: [PATCH 2/8] Add: http, ftp, nfs protocols (nbdkit-curl-plugin
 supports) (FT-58, TZ-5.1.2.3)

---
 src/state/activating_state.cpp | 80 +++++++++++++++++++++++++++++++++-
 src/state/activating_state.hpp | 13 ++++++
 2 files changed, 92 insertions(+), 1 deletion(-)

diff --git a/src/state/activating_state.cpp b/src/state/activating_state.cpp
index 1098192..c28310e 100644
--- a/src/state/activating_state.cpp
+++ b/src/state/activating_state.cpp
@@ -125,6 +125,18 @@ std::unique_ptr<BasicState> ActivatingState::activateLegacyMode()
     {
         return mountHttpsShare();
     }
+    if (isHttpUrl(machine.getTarget()->imgUrl))
+    {
+        return mountHttpShare();
+    }
+    if (isFtpUrl(machine.getTarget()->imgUrl))
+    {
+        return mountFtpShare();
+    }
+    if (isNfsUrl(machine.getTarget()->imgUrl))
+    {
+        return mountNfsShare();
+    }
 
     return std::make_unique<ReadyState>(machine, std::errc::invalid_argument,
                                         "URL not recognized");
@@ -167,13 +179,34 @@ std::unique_ptr<BasicState> ActivatingState::mountSmbShare()
 }
 
 std::unique_ptr<BasicState> ActivatingState::mountHttpsShare()
+{
+	return mountXxxShare("HTTPS");
+}
+
+std::unique_ptr<BasicState> ActivatingState::mountHttpShare()
+{
+	return mountXxxShare("HTTP");
+}
+
+std::unique_ptr<BasicState> ActivatingState::mountFtpShare()
+{
+	return mountXxxShare("FTP");
+}
+
+std::unique_ptr<BasicState> ActivatingState::mountNfsShare()
+{
+	return mountXxxShare("NFS");
+}
+
+std::unique_ptr<BasicState> ActivatingState::mountXxxShare(const char* pMountType)
 {
     process = spawnNbdKit(machine, machine.getTarget()->imgUrl);
     if (!process)
     {
         return std::make_unique<ReadyState>(machine,
                                             std::errc::invalid_argument,
-                                            "Failed to mount HTTPS share");
+                                            (std::stringstream("Failed to mount ")
+                                            << pMountType << " share").str());
     }
 
     return nullptr;
@@ -330,12 +363,45 @@ bool ActivatingState::isHttpsUrl(const std::string& imageUrl)
     return checkUrl("https://", imageUrl);
 }
 
+bool ActivatingState::isHttpUrl(const std::string& imageUrl)
+{
+    return checkUrl("http://", imageUrl);
+}
+
+bool ActivatingState::isFtpUrl(const std::string& imageUrl)
+{
+    return checkUrl("ftp://", imageUrl);
+}
+
+bool ActivatingState::isNfsUrl(const std::string& imageUrl)
+{
+    return checkUrl("nfs://", imageUrl);
+}
+
 bool ActivatingState::getImagePathFromHttpsUrl(const std::string& imageUrl,
                                                std::string* imagePath)
 {
     return getImagePathFromUrl("https://", imageUrl, imagePath);
 }
 
+bool ActivatingState::getImagePathFromHttpUrl(const std::string& imageUrl,
+                                               std::string* imagePath)
+{
+    return getImagePathFromUrl("http://", imageUrl, imagePath);
+}
+
+bool ActivatingState::getImagePathFromFtpUrl(const std::string& imageUrl,
+                                               std::string* imagePath)
+{
+    return getImagePathFromUrl("ftp://", imageUrl, imagePath);
+}
+
+bool ActivatingState::getImagePathFromNfsUrl(const std::string& imageUrl,
+                                               std::string* imagePath)
+{
+    return getImagePathFromUrl("nfs://", imageUrl, imagePath);
+}
+
 bool ActivatingState::isCifsUrl(const std::string& imageUrl)
 {
     return checkUrl("smb://", imageUrl);
@@ -355,6 +421,18 @@ fs::path ActivatingState::getImagePath(const std::string& imageUrl)
     {
         return {imagePath};
     }
+    if (isHttpUrl(imageUrl) && getImagePathFromHttpUrl(imageUrl, &imagePath))
+    {
+        return {imagePath};
+    }
+    if (isFtpUrl(imageUrl) && getImagePathFromFtpUrl(imageUrl, &imagePath))
+    {
+        return {imagePath};
+    }
+    if (isNfsUrl(imageUrl) && getImagePathFromNfsUrl(imageUrl, &imagePath))
+    {
+        return {imagePath};
+    }
     if (isCifsUrl(imageUrl) && getImagePathFromCifsUrl(imageUrl, &imagePath))
     {
         return {imagePath};
diff --git a/src/state/activating_state.hpp b/src/state/activating_state.hpp
index 295d185..affca24 100644
--- a/src/state/activating_state.hpp
+++ b/src/state/activating_state.hpp
@@ -26,6 +26,10 @@ struct ActivatingState : public BasicStateT<ActivatingState>
     std::unique_ptr<BasicState> activateLegacyMode();
     std::unique_ptr<BasicState> mountSmbShare();
     std::unique_ptr<BasicState> mountHttpsShare();
+    std::unique_ptr<BasicState> mountHttpShare();
+    std::unique_ptr<BasicState> mountFtpShare();
+    std::unique_ptr<BasicState> mountNfsShare();
+    std::unique_ptr<BasicState> mountXxxShare(const char* pMountType);
 
     static std::unique_ptr<resource::Process>
         spawnNbdKit(interfaces::MountPointStateMachine& machine,
@@ -44,8 +48,17 @@ struct ActivatingState : public BasicStateT<ActivatingState>
                                     const std::string& imageUrl,
                                     std::string* imagePath);
     static bool isHttpsUrl(const std::string& imageUrl);
+    static bool isHttpUrl(const std::string& imageUrl);
+    static bool isFtpUrl(const std::string& imageUrl);
+    static bool isNfsUrl(const std::string& imageUrl);
     static bool getImagePathFromHttpsUrl(const std::string& imageUrl,
                                          std::string* imagePath);
+    static bool getImagePathFromHttpUrl(const std::string& imageUrl,
+                                         std::string* imagePath);
+    static bool getImagePathFromFtpUrl(const std::string& imageUrl,
+                                         std::string* imagePath);
+    static bool getImagePathFromNfsUrl(const std::string& imageUrl,
+                                         std::string* imagePath);
 
     static bool isCifsUrl(const std::string& imageUrl);
     static bool getImagePathFromCifsUrl(const std::string& imageUrl,
-- 
2.35.1