summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/virtual-media/virtual-media/0015-virtual-media.1-Fix-Use-usb-ctrl-cdrom-is-pre-config.patch
blob: ae2bc7d5ddcaebfd97fae7ae833d80329919f654 (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
From c7755195ee7107a72bf40ad3101079f94cf015ae Mon Sep 17 00:00:00 2001
From: Alexandr Ilenko <AIlenko@IBS.RU>
Date: Fri, 24 Jun 2022 17:15:54 +0300
Subject: [PATCH 15/20] virtual-media.1: Fix: Use "usb-ctrl" ("cdrom" is
 pre-configured).

---
 src/configuration.hpp       | 18 ++++++++++++++++++
 src/state/initial_state.hpp | 31 ++++++++++++++++++++++++++++++-
 src/system.hpp              |  3 ---
 virtual-media.json          | 12 ++++++++----
 4 files changed, 56 insertions(+), 8 deletions(-)

diff --git a/src/configuration.hpp b/src/configuration.hpp
index efdddf2..0a713a5 100644
--- a/src/configuration.hpp
+++ b/src/configuration.hpp
@@ -36,6 +36,7 @@ class Configuration
         static constexpr int defaultTimeout = 30;
 
         NBDDevice nbdDevice;
+        std::string interfaceType;
         std::string unixSocket;
         std::string endPointId;
         std::optional<int> timeout;
@@ -142,6 +143,23 @@ class Configuration
                             continue;
                         }
                     };
+                    const auto interfaceTypeIter =
+                        mountpoint.value().find("InterfaceType");
+                    if (interfaceTypeIter != mountpoint.value().cend())
+                    {
+                        const std::string* value =
+                            interfaceTypeIter->get_ptr<const std::string*>();
+                        if (value)
+                        {
+                            mp.interfaceType = *value;
+                        }
+                        else
+                        {
+                            LogMsg(Logger::Error,
+                                   "InterfaceType required, not set");
+                            continue;
+                        }
+                    }
                     const auto unixSocketIter =
                         mountpoint.value().find("UnixSocket");
                     if (unixSocketIter != mountpoint.value().cend())
diff --git a/src/state/initial_state.hpp b/src/state/initial_state.hpp
index e0d8a5d..7f25fc7 100644
--- a/src/state/initial_state.hpp
+++ b/src/state/initial_state.hpp
@@ -249,11 +249,40 @@ struct InitialState : public BasicStateT<InitialState>
             iface->register_method(
                 "Mount", [&machine = machine](boost::asio::yield_context yield,
                                               std::string imgUrl, bool rw,
-                                              uint8_t type,
+                                              // This new argument requires 3-repos to be updated:
+                                              //   uint8_t type,
+                                              // Let`s use original way:
+                                              //   cdrom-type is pre-configured hardly
                                               optional_fd fd) {
                     LogMsg(Logger::Info, "[App]: Mount called on ",
                            getObjectPath(machine), machine.getName());
 
+                    uint8_t type = UsbGadget::interfaceTypeUSB;
+                    // TODO: extract id<=>string mapping to proper place
+                    static const std::map<std::string, uint8_t> vmInterfaces {
+                        {"usb"  , UsbGadget::interfaceTypeUSB,   },
+                        {"hdd"  , UsbGadget::interfaceTypeHDD,   },
+                        {"cdrom", UsbGadget::interfaceTypeCDROM, },
+                    };
+                    const auto& interfaceTypeStr = machine.getConfig().interfaceType;
+                    auto interfaceIt = vmInterfaces.find(interfaceTypeStr);
+                    if (interfaceIt == vmInterfaces.end())
+                    {
+                        LogMsg(Logger::Error,
+                               "[App]: Spiecifed unknown interface type: ", interfaceTypeStr);
+                        interfaceIt = vmInterfaces.begin();
+                        LogMsg(Logger::Warning,
+                               "[App]: Forcly apply interface type: ", interfaceIt->first);
+                    }
+                    type = interfaceIt->second;
+
+                    if (type == UsbGadget::interfaceTypeCDROM && rw)
+                    {
+                        LogMsg(Logger::Warning,
+                               "[App]: Forcly apply read-only for cdrom: ");
+                        rw = false;
+                    }
+
                     interfaces::MountPointStateMachine::Target target = {
                         imgUrl, rw,
                         static_cast<UsbGadget::InterfaceType>(type),
diff --git a/src/system.hpp b/src/system.hpp
index 5dfb4df..33e3363 100644
--- a/src/system.hpp
+++ b/src/system.hpp
@@ -549,9 +549,6 @@ struct UsbGadget : private FsHelper
 
         if (change == StateChange::inserted)
         {
-            const std::string roConfPath = "/sys/kernel/config/usb_gadget/" +
-                                           name + "/functions/mass_storage." +
-                                           name + "/lun.0/ro";
             // /usr/bin/usb-ctrl insert <name> <file> [<type=usb|usb-ro|hdd|cdrom>]
             try
             {
diff --git a/virtual-media.json b/virtual-media.json
index 79615c9..6d035f1 100644
--- a/virtual-media.json
+++ b/virtual-media.json
@@ -1,34 +1,38 @@
 {
     "InactivityTimeout": 1800,
     "MountPoints": {
-        "USB0": {
+        "ISO0": {
             "EndpointId": "/nbd/0",
             "Mode": 0,
             "NBDDevice": "nbd0",
+            "InterfaceType": "cdrom",
             "UnixSocket": "/run/virtual-media/nbd0.sock",
             "Timeout": 30,
             "BlockSize": 512
         },
-        "USB1": {
+        "USB0": {
             "EndpointId": "/nbd/1",
             "Mode": 0,
             "NBDDevice": "nbd1",
+            "InterfaceType": "usb",
             "UnixSocket": "/run/virtual-media/nbd1.sock",
             "Timeout": 30,
             "BlockSize": 512
         },
-        "USB2": {
+        "ISO1": {
             "EndpointId": "",
             "Mode": 1,
             "NBDDevice": "nbd2",
+            "InterfaceType": "cdrom",
             "UnixSocket": "/run/virtual-media/nbd2.sock",
             "Timeout": 90,
             "BlockSize": 512
         },
-        "USB3": {
+        "USB1": {
             "EndpointId": "",
             "Mode": 1,
             "NBDDevice": "nbd3",
+            "InterfaceType": "usb",
             "UnixSocket": "/run/virtual-media/nbd3.sock",
             "Timeout": 90,
             "BlockSize": 512
-- 
2.35.1