Skip to content

Commit f78cbf4

Browse files
authored
ssvm: wrong SSVM behavior causes redownloading for all the templates (#3844)
As per discussion at #3838 and proposal by @weizhouapache this PR implements the fix. Fixes #3838
1 parent a746b29 commit f78cbf4

3 files changed

Lines changed: 16 additions & 36 deletions

File tree

server/src/main/java/org/apache/cloudstack/storage/NfsMountManagerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,16 +163,16 @@ private void deleteMountPath(String localRootPath) {
163163

164164
private boolean mountExists(String localRootPath) {
165165
Script script = new Script(true, "mount", timeout, s_logger);
166-
ZfsPathParser parser = new ZfsPathParser(localRootPath);
166+
PathParser parser = new PathParser(localRootPath);
167167
script.execute(parser);
168168
return parser.getPaths().stream().filter(s -> s.contains(localRootPath)).findAny().map(s -> true).orElse(false);
169169
}
170170

171-
public static class ZfsPathParser extends OutputInterpreter {
171+
public static class PathParser extends OutputInterpreter {
172172
String _parent;
173173
List<String> paths = new ArrayList<>();
174174

175-
public ZfsPathParser(String parent) {
175+
public PathParser(String parent) {
176176
_parent = parent;
177177
}
178178

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder;
6868
import org.apache.cloudstack.storage.template.DownloadManager;
6969
import org.apache.cloudstack.storage.template.DownloadManagerImpl;
70-
import org.apache.cloudstack.storage.template.DownloadManagerImpl.ZfsPathParser;
70+
import org.apache.cloudstack.storage.NfsMountManagerImpl.PathParser;
7171
import org.apache.cloudstack.storage.template.UploadEntity;
7272
import org.apache.cloudstack.storage.template.UploadManager;
7373
import org.apache.cloudstack.storage.template.UploadManagerImpl;
@@ -2905,7 +2905,7 @@ protected boolean mountExists(String localRootPath, URI uri) {
29052905
script = new Script(!_inSystemVM, "mount", _timeout, s_logger);
29062906

29072907
List<String> res = new ArrayList<String>();
2908-
ZfsPathParser parser = new ZfsPathParser(localRootPath);
2908+
PathParser parser = new PathParser(localRootPath);
29092909
script.execute(parser);
29102910
res.addAll(parser.getPaths());
29112911
for (String s : res) {

services/secondary-storage/server/src/main/java/org/apache/cloudstack/storage/template/DownloadManagerImpl.java

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.storage.template;
1818

19-
import java.io.BufferedReader;
2019
import java.io.File;
2120
import java.io.FileInputStream;
2221
import java.io.IOException;
@@ -60,6 +59,7 @@
6059
import org.apache.cloudstack.storage.command.DownloadCommand.ResourceType;
6160
import org.apache.cloudstack.storage.command.DownloadProgressCommand;
6261
import org.apache.cloudstack.storage.command.DownloadProgressCommand.RequestType;
62+
import org.apache.cloudstack.storage.NfsMountManagerImpl.PathParser;
6363
import org.apache.cloudstack.storage.resource.NfsSecondaryStorageResource;
6464
import org.apache.cloudstack.storage.resource.SecondaryStorageResource;
6565
import org.apache.commons.collections.CollectionUtils;
@@ -82,7 +82,6 @@
8282
import com.cloud.utils.StringUtils;
8383
import com.cloud.utils.component.ManagerBase;
8484
import com.cloud.utils.exception.CloudRuntimeException;
85-
import com.cloud.utils.script.OutputInterpreter;
8685
import com.cloud.utils.script.Script;
8786
import com.cloud.utils.storage.QCOW2Utils;
8887
import org.apache.cloudstack.utils.security.ChecksumValue;
@@ -850,8 +849,12 @@ private List<String> listVolumes(String rootdir) {
850849

851850
Script script = new Script(listVolScr, LOGGER);
852851
script.add("-r", rootdir);
853-
ZfsPathParser zpp = new ZfsPathParser(rootdir);
852+
PathParser zpp = new PathParser(rootdir);
854853
script.execute(zpp);
854+
if (script.getExitValue() != 0) {
855+
LOGGER.error("Error while executing script " + script.toString());
856+
throw new CloudRuntimeException("Error while executing script " + script.toString());
857+
}
855858
result.addAll(zpp.getPaths());
856859
LOGGER.info("found " + zpp.getPaths().size() + " volumes" + zpp.getPaths());
857860
return result;
@@ -862,8 +865,12 @@ private List<String> listTemplates(String rootdir) {
862865

863866
Script script = new Script(listTmpltScr, LOGGER);
864867
script.add("-r", rootdir);
865-
ZfsPathParser zpp = new ZfsPathParser(rootdir);
868+
PathParser zpp = new PathParser(rootdir);
866869
script.execute(zpp);
870+
if (script.getExitValue() != 0) {
871+
LOGGER.error("Error while executing script " + script.toString());
872+
throw new CloudRuntimeException("Error while executing script " + script.toString());
873+
}
867874
result.addAll(zpp.getPaths());
868875
LOGGER.info("found " + zpp.getPaths().size() + " templates" + zpp.getPaths());
869876
return result;
@@ -961,33 +968,6 @@ public Map<Long, TemplateProp> gatherVolumeInfo(String rootDir) {
961968
return result;
962969
}
963970

964-
public static class ZfsPathParser extends OutputInterpreter {
965-
String _parent;
966-
List<String> paths = new ArrayList<String>();
967-
968-
public ZfsPathParser(String parent) {
969-
_parent = parent;
970-
}
971-
972-
@Override
973-
public String interpret(BufferedReader reader) throws IOException {
974-
String line = null;
975-
while ((line = reader.readLine()) != null) {
976-
paths.add(line);
977-
}
978-
return null;
979-
}
980-
981-
public List<String> getPaths() {
982-
return paths;
983-
}
984-
985-
@Override
986-
public boolean drain() {
987-
return true;
988-
}
989-
}
990-
991971
public DownloadManagerImpl() {
992972
}
993973

0 commit comments

Comments
 (0)