4545
4646import org .apache .commons .collections .MapUtils ;
4747import org .apache .commons .io .IOUtils ;
48+ import org .apache .commons .lang .StringUtils ;
4849import org .apache .log4j .Logger ;
4950import org .libvirt .Connect ;
5051import org .libvirt .Domain ;
@@ -332,9 +333,9 @@ private String replaceStorage(String xmlDesc, Map<String, MigrateCommand.Migrate
332333 if ("disk" .equals (deviceChildNode .getNodeName ())) {
333334 Node diskNode = deviceChildNode ;
334335
335- String sourceFileDevText = getSourceFileDevText (diskNode );
336+ String sourceText = getSourceText (diskNode );
336337
337- String path = getPathFromSourceFileDevText (migrateStorage .keySet (), sourceFileDevText );
338+ String path = getPathFromSourceText (migrateStorage .keySet (), sourceText );
338339
339340 if (path != null ) {
340341 MigrateCommand .MigrateDiskInfo migrateDiskInfo = migrateStorage .remove (path );
@@ -383,10 +384,10 @@ private String replaceStorage(String xmlDesc, Map<String, MigrateCommand.Migrate
383384 return getXml (doc );
384385 }
385386
386- private String getPathFromSourceFileDevText (Set <String > paths , String sourceFileDevText ) {
387- if (paths != null && sourceFileDevText != null ) {
387+ private String getPathFromSourceText (Set <String > paths , String sourceText ) {
388+ if (paths != null && ! StringUtils . isBlank ( sourceText ) ) {
388389 for (String path : paths ) {
389- if (sourceFileDevText .contains (path )) {
390+ if (sourceText .contains (path )) {
390391 return path ;
391392 }
392393 }
@@ -395,7 +396,7 @@ private String getPathFromSourceFileDevText(Set<String> paths, String sourceFile
395396 return null ;
396397 }
397398
398- private String getSourceFileDevText (Node diskNode ) {
399+ private String getSourceText (Node diskNode ) {
399400 NodeList diskChildNodes = diskNode .getChildNodes ();
400401
401402 for (int i = 0 ; i < diskChildNodes .getLength (); i ++) {
@@ -415,6 +416,20 @@ private String getSourceFileDevText(Node diskNode) {
415416 if (diskNodeAttribute != null ) {
416417 return diskNodeAttribute .getTextContent ();
417418 }
419+
420+ diskNodeAttribute = diskNodeAttributes .getNamedItem ("protocol" );
421+
422+ if (diskNodeAttribute != null ) {
423+ String textContent = diskNodeAttribute .getTextContent ();
424+
425+ if ("rbd" .equalsIgnoreCase (textContent )) {
426+ diskNodeAttribute = diskNodeAttributes .getNamedItem ("name" );
427+
428+ if (diskNodeAttribute != null ) {
429+ return diskNodeAttribute .getTextContent ();
430+ }
431+ }
432+ }
418433 }
419434 }
420435
0 commit comments