Skip to content

Commit 2b1d997

Browse files
committed
CLOUDSTACK-5248: Fixed creation of mount point when running as non root (cloud) user.
The systemvm iso file is copied only when a systemvm or router vm is to be started on a host. The file gets copied to the secondary storage. The mount point used is the one that has permissions for regular user to mount a share. CLOUDSTACK-5275: The failure was because a secondary storage wasn't available when the host was added. When a setup is done through wizard the hosts get added before the secondary storage. CS was tying to copy yhe systemvm iso to secondary and it used to fail if it wasn't available. Made a change to copy the iso only when a systemvm is being started on a host. CLOUDSTACK-5202: Made changes to clean up mount points on stop and start. All the three are related fixes; so putting a fix in one commit.
1 parent ab025f0 commit 2b1d997

9 files changed

Lines changed: 520 additions & 251 deletions

File tree

‎core/src/com/cloud/agent/api/SetupCommand.java‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ public class SetupCommand extends Command {
2323
HostEnvironment env;
2424
boolean multipath;
2525
boolean needSetup;
26-
String secondaryStorage;
27-
String systemVmIso;
2826

2927
public boolean needSetup() {
3028
return needSetup;
@@ -38,8 +36,6 @@ public SetupCommand(HostEnvironment env) {
3836
this.env = env;
3937
this.multipath = false;
4038
this.needSetup = false;
41-
secondaryStorage = null;
42-
systemVmIso = null;
4339
}
4440

4541
public HostEnvironment getEnvironment() {
@@ -57,22 +53,6 @@ public boolean useMultipath() {
5753
return multipath;
5854
}
5955

60-
public void setSecondaryStorage(String secondaryStorage) {
61-
this.secondaryStorage = secondaryStorage;
62-
}
63-
64-
public String getSecondaryStorage() {
65-
return this.secondaryStorage;
66-
}
67-
68-
public void setSystemVmIso(String systemVmIso) {
69-
this.systemVmIso = systemVmIso;
70-
}
71-
72-
public String getSystemVmIso() {
73-
return this.systemVmIso;
74-
}
75-
7656
@Override
7757
public boolean executeInSequence() {
7858
return true;

‎core/src/com/cloud/agent/api/StartCommand.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class StartCommand extends Command {
2525
VirtualMachineTO vm;
2626
String hostIp;
2727
boolean executeInSequence = false;
28+
String secondaryStorage;
2829

2930
public VirtualMachineTO getVirtualMachine() {
3031
return vm;
@@ -42,9 +43,18 @@ public StartCommand(VirtualMachineTO vm, Host host, boolean executeInSequence) {
4243
this.vm = vm;
4344
this.hostIp = host.getPrivateIpAddress();
4445
this.executeInSequence = executeInSequence;
46+
this.secondaryStorage = null;
4547
}
4648

4749
public String getHostIp() {
4850
return this.hostIp;
4951
}
52+
53+
public String getSecondaryStorage() {
54+
return this.secondaryStorage;
55+
}
56+
57+
public void setSecondaryStorage(String secondary) {
58+
this.secondaryStorage = secondary;
59+
}
5060
}

‎plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/HypervResourceController.cs‎

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public static void Configure(HypervResourceControllerConfig config)
141141
public static HypervResourceControllerConfig config = new HypervResourceControllerConfig();
142142

143143
private static ILog logger = LogManager.GetLogger(typeof(HypervResourceController));
144-
private static string systemVmIso;
144+
private string systemVmIso = "";
145145
Dictionary<String, String> contextMap = new Dictionary<String, String>();
146146

147147
public static void Initialize()
@@ -179,19 +179,6 @@ public JContainer SetupCommand([FromBody]dynamic cmd)
179179

180180
try
181181
{
182-
NFSTO share = new NFSTO();
183-
String uriStr = (String)cmd.secondaryStorage;
184-
share.uri = new Uri(uriStr);
185-
186-
string systemVmIso = (string)cmd.systemVmIso;
187-
string defaultDataPath = wmiCallsV2.GetDefaultDataRoot();
188-
string isoPath = Path.Combine(defaultDataPath, Path.GetFileName(systemVmIso));
189-
if (!File.Exists(isoPath))
190-
{
191-
logger.Info("File " + isoPath + " not found. Copying it from the secondary share.");
192-
Utils.DownloadCifsFileToLocalFile(systemVmIso, share, isoPath);
193-
}
194-
HypervResourceController.systemVmIso = isoPath;
195182
result = true;
196183
}
197184
catch (Exception sysEx)
@@ -957,7 +944,40 @@ public JContainer StartCommand([FromBody]dynamic cmd)
957944

958945
try
959946
{
960-
wmiCallsV2.DeployVirtualMachine(cmd, systemVmIso);
947+
string systemVmIsoPath = systemVmIso;
948+
lock (systemVmIso)
949+
{
950+
systemVmIsoPath = systemVmIso;
951+
String uriStr = (String)cmd.secondaryStorage;
952+
if (!String.IsNullOrEmpty(uriStr))
953+
{
954+
if (String.IsNullOrEmpty(systemVmIsoPath) || !File.Exists(systemVmIsoPath))
955+
{
956+
NFSTO share = new NFSTO();
957+
share.uri = new Uri(uriStr);
958+
string defaultDataPath = wmiCallsV2.GetDefaultDataRoot();
959+
960+
string secondaryPath = Path.Combine(share.UncPath, "systemvm").Replace(@"/", @"\");
961+
string[] choices = choices = Directory.GetFiles(secondaryPath, "systemvm*.iso");
962+
if (choices.Length != 1)
963+
{
964+
String errMsg = "Couldn't locate the systemvm iso on " + secondaryPath;
965+
logger.Debug(errMsg);
966+
}
967+
else
968+
{
969+
systemVmIsoPath = Path.Combine(defaultDataPath, Path.GetFileName(choices[0]));
970+
if (!File.Exists(systemVmIsoPath))
971+
{
972+
Utils.DownloadCifsFileToLocalFile(choices[0], share, systemVmIsoPath);
973+
}
974+
systemVmIso = systemVmIsoPath;
975+
}
976+
}
977+
}
978+
}
979+
980+
wmiCallsV2.DeployVirtualMachine(cmd, systemVmIsoPath);
961981
result = true;
962982
}
963983
catch (Exception wmiEx)

‎plugins/hypervisors/hyperv/DotNet/ServerResource/HypervResource/WmiCallsV2.cs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ public ComputerSystem DeployVirtualMachine(dynamic jsonObj, string systemVmIso)
453453
// call patch systemvm iso only for systemvms
454454
if (vmName.StartsWith("r-") || vmName.StartsWith("s-") || vmName.StartsWith("v-"))
455455
{
456-
patchSystemVmIso(vmName, systemVmIso);
456+
if (systemVmIso != null && systemVmIso.Length != 0)
457+
{
458+
patchSystemVmIso(vmName, systemVmIso);
459+
}
457460
}
458461

459462
logger.DebugFormat("Starting VM {0}", vmName);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
<beans xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xmlns:context="http://www.springframework.org/schema/context"
22+
xmlns:aop="http://www.springframework.org/schema/aop"
23+
xsi:schemaLocation="http://www.springframework.org/schema/beans
24+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
25+
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
26+
http://www.springframework.org/schema/context
27+
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
28+
>
29+
30+
<bean id="HypervManager" class="com.cloud.hypervisor.hyperv.manager.HypervManagerImpl" />
31+
<bean id="HypervDirectConnectResource" class="com.cloud.hypervisor.hyperv.resource.HypervDirectConnectResource" />
32+
</beans>

0 commit comments

Comments
 (0)