Skip to content

Commit 39471c8

Browse files
configdrive: make fewer mountpoints on hosts (apache#2716)
This ensure that fewer mount points are made on hosts for either primary storagepools or secondary storagepools. Signed-off-by: Rohit Yadav <[email protected]>
1 parent 08a59e8 commit 39471c8

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
lines changed

engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDrive.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,27 @@
1919

2020
public class ConfigDrive {
2121

22-
public final static String CONFIGDRIVEFILENAME = "configdrive.iso";
2322
public final static String CONFIGDRIVEDIR = "configdrive";
2423

2524
public static final String cloudStackConfigDriveName = "/cloudstack/";
2625
public static final String openStackConfigDriveName = "/openstack/latest/";
2726

2827
/**
2928
* Creates the path to ISO file relative to mount point.
30-
* The config driver path will have the following formated: {@link #CONFIGDRIVEDIR} + / + instanceName + / + {@link #CONFIGDRIVEFILENAME}
29+
* The config driver path will have the following format: {@link #CONFIGDRIVEDIR} + / + instanceName + ".iso"
3130
*
3231
* @return config drive ISO file path
3332
*/
3433
public static String createConfigDrivePath(String instanceName) {
35-
return ConfigDrive.CONFIGDRIVEDIR + "/" + instanceName + "/" + ConfigDrive.CONFIGDRIVEFILENAME;
34+
return ConfigDrive.CONFIGDRIVEDIR + "/" + configIsoFileName(instanceName);
35+
}
36+
37+
/**
38+
* Config Drive iso file name for an instance name
39+
* @param instanceName
40+
* @return
41+
*/
42+
public static String configIsoFileName(String instanceName) {
43+
return instanceName + ".iso";
3644
}
3745
}

engine/storage/configdrive/src/org/apache/cloudstack/storage/configdrive/ConfigDriveBuilder.java

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public static String fileToBase64String(File isoFile) throws IOException {
7979
public static File base64StringToFile(String encodedIsoData, String folder, String fileName) throws IOException {
8080
byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII));
8181
Path destPath = Paths.get(folder, fileName);
82+
try {
83+
Files.createDirectories(destPath.getParent());
84+
} catch (final IOException e) {
85+
LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString());
86+
}
8287
return Files.write(destPath, decoded).toFile();
8388
}
8489

engine/storage/configdrive/test/org/apache/cloudstack/storage/configdrive/ConfigDriveTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ConfigDriveTest {
2626

2727
@Test
2828
public void testConfigDriveIsoPath() throws IOException {
29-
Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), "configdrive/i-x-y/configdrive.iso");
29+
Assert.assertEquals(ConfigDrive.createConfigDrivePath("i-x-y"), "configdrive/i-x-y.iso");
3030
}
3131

3232
}

plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtHandleConfigDriveCommandWrapper.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.nio.file.Paths;
2525

2626
import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
27-
import org.apache.commons.io.FileUtils;
2827
import org.apache.log4j.Logger;
2928

3029
import com.cloud.agent.api.Answer;
@@ -67,7 +66,7 @@ public Answer execute(final HandleConfigDriveIsoCommand command, final LibvirtCo
6766
}
6867
} else {
6968
try {
70-
FileUtils.deleteDirectory(isoPath.getParent().toFile());
69+
Files.deleteIfExists(isoPath);
7170
} catch (IOException e) {
7271
LOG.warn("Failed to delete config drive: " + isoPath.toAbsolutePath().toString());
7372
return new Answer(command, false, "Failed due to exception: " + e.getMessage());

server/src/com/cloud/network/element/ConfigDriveNetworkElement.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,9 @@ private boolean createConfigDriveIso(VirtualMachineProfile profile, DeployDestin
375375

376376
LOG.debug("Creating config drive ISO for vm: " + profile.getInstanceName());
377377

378+
final String isoFileName = ConfigDrive.configIsoFileName(profile.getInstanceName());
378379
final String isoPath = ConfigDrive.createConfigDrivePath(profile.getInstanceName());
379-
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), ConfigDrive.CONFIGDRIVEFILENAME, profile.getConfigDriveLabel());
380+
final String isoData = ConfigDriveBuilder.buildConfigDrive(profile.getVmData(), isoFileName, profile.getConfigDriveLabel());
380381
final HandleConfigDriveIsoCommand configDriveIsoCommand = new HandleConfigDriveIsoCommand(isoPath, isoData, dataStore.getTO(), true);
381382

382383
final Answer answer = agentManager.easySend(agentId, configDriveIsoCommand);

services/secondary-storage/server/src/org/apache/cloudstack/storage/resource/NfsSecondaryStorageResource.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.net.InetAddress;
4343
import java.net.URI;
4444
import java.net.UnknownHostException;
45+
import java.nio.file.Files;
4546
import java.nio.file.Path;
4647
import java.security.NoSuchAlgorithmException;
4748
import java.util.ArrayList;
@@ -337,7 +338,7 @@ private Answer execute(HandleConfigDriveIsoCommand cmd) {
337338
Path tempDir = null;
338339
try {
339340
tempDir = java.nio.file.Files.createTempDirectory(ConfigDrive.CONFIGDRIVEDIR);
340-
File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), ConfigDrive.CONFIGDRIVEFILENAME);
341+
File tmpIsoFile = ConfigDriveBuilder.base64StringToFile(cmd.getIsoData(), tempDir.toAbsolutePath().toString(), cmd.getIsoFile());
341342
copyLocalToNfs(tmpIsoFile, new File(cmd.getIsoFile()), cmd.getDestStore());
342343
} catch (IOException | ConfigurationException e) {
343344
return new Answer(cmd, false, "Failed due to exception: " + e.getMessage());
@@ -355,11 +356,11 @@ private Answer execute(HandleConfigDriveIsoCommand cmd) {
355356
DataStoreTO dstore = cmd.getDestStore();
356357
if (dstore instanceof NfsTO) {
357358
NfsTO nfs = (NfsTO) dstore;
358-
String relativeTemplatePath = new File(cmd.getIsoFile()).getParent();
359+
String relativeTemplatePath = new File(cmd.getIsoFile()).getPath();
359360
String nfsMountPoint = getRootDir(nfs.getUrl(), _nfsVersion);
360361
File tmpltPath = new File(nfsMountPoint, relativeTemplatePath);
361362
try {
362-
FileUtils.deleteDirectory(tmpltPath);
363+
Files.deleteIfExists(tmpltPath.toPath());
363364
} catch (IOException e) {
364365
return new Answer(cmd, e);
365366
}

0 commit comments

Comments
 (0)