Program: 105503
Project: 105503
Buggy source:
/** 
 * This copies a volume from Primary Storage to Secondary Storage In theory it could also do it the other way around, but the current implementation in ManagementServerImpl shows that the destPool is always a Secondary Storage Pool
 */
@Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPool,int timeout){
  KVMStoragePool srcPool=disk.getPool();
  PhysicalDiskFormat sourceFormat=disk.getFormat();
  String sourcePath=disk.getPath();
  KVMPhysicalDisk newDisk;
  s_logger.debug("String_Node_Str" + disk.getSize() + "String_Node_Str"+ disk.getVirtualSize()+ "String_Node_Str"+ disk.getFormat());
  if (destPool.getType() != StoragePoolType.RBD) {
    if (disk.getFormat() == PhysicalDiskFormat.TAR) {
      newDisk=destPool.createPhysicalDisk(name,PhysicalDiskFormat.DIR,Storage.ProvisioningType.THIN,disk.getVirtualSize());
    }
 else {
      if (srcPool.getType() != StoragePoolType.RBD) {
        newDisk=destPool.createPhysicalDisk(name,Storage.ProvisioningType.THIN,disk.getVirtualSize());
      }
 else {
        newDisk=destPool.createPhysicalDisk(name,Storage.ProvisioningType.THIN,disk.getVirtualSize());
      }
    }
  }
 else {
    newDisk=new KVMPhysicalDisk(destPool.getSourceDir() + "String_Node_Str" + name,name,destPool);
    newDisk.setFormat(PhysicalDiskFormat.RAW);
    newDisk.setSize(disk.getVirtualSize());
    newDisk.setVirtualSize(disk.getSize());
  }
  String destPath=newDisk.getPath();
  PhysicalDiskFormat destFormat=newDisk.getFormat();
  QemuImg qemu=new QemuImg(timeout);
  QemuImgFile srcFile=null;
  QemuImgFile destFile=null;
  if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() != StoragePoolType.RBD)) {
    if (sourceFormat == PhysicalDiskFormat.TAR && destFormat == PhysicalDiskFormat.DIR) {
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath);
    }
 else     if (sourceFormat == PhysicalDiskFormat.TAR) {
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
    }
 else     if (sourceFormat == PhysicalDiskFormat.DIR) {
      Script.runSimpleBashScript("String_Node_Str" + destPath);
      Script.runSimpleBashScript("String_Node_Str" + destPath);
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
    }
 else {
      srcFile=new QemuImgFile(sourcePath,sourceFormat);
      try {
        Map<String,String> info=qemu.info(srcFile);
        String backingFile=info.get(new String("String_Node_Str"));
        if (sourceFormat.equals(destFormat) && backingFile == null && sourcePath.endsWith("String_Node_Str")) {
          String result=Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
          if (result != null) {
            throw new CloudRuntimeException("String_Node_Str" + result);
          }
        }
 else {
          destFile=new QemuImgFile(destPath,destFormat);
          try {
            qemu.convert(srcFile,destFile);
          }
 catch (          QemuImgException e) {
            s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
            newDisk=null;
          }
        }
      }
 catch (      QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ e.getMessage());
        newDisk=null;
      }
    }
  }
 else   if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() == StoragePoolType.RBD)) {
    s_logger.debug("String_Node_Str");
    String sourceFile;
    boolean useTmpFile=false;
    try {
      srcFile=new QemuImgFile(sourcePath,sourceFormat);
      String rbdDestFile=KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),destPool.getSourcePort(),destPool.getAuthUserName(),destPool.getAuthSecret(),destPool.getSourceDir() + "String_Node_Str" + name);
      destFile=new QemuImgFile(rbdDestFile,destFormat);
      s_logger.debug("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destPool.getSourceDir()+ "String_Node_Str"+ name);
      qemu.convert(srcFile,destFile);
      s_logger.debug("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destPool.getSourceDir()+ "String_Node_Str"+ name);
      Rados r=new Rados(destPool.getAuthUserName());
      r.confSet("String_Node_Str",destPool.getSourceHost() + "String_Node_Str" + destPool.getSourcePort());
      r.confSet("String_Node_Str",destPool.getAuthSecret());
      r.confSet("String_Node_Str","String_Node_Str");
      r.connect();
      s_logger.debug("String_Node_Str" + r.confGet("String_Node_Str"));
      IoCTX io=r.ioCtxCreate(destPool.getSourceDir());
      Rbd rbd=new Rbd(io);
      RbdImage image=rbd.open(name);
      rbd.close(image);
      r.ioCtxDestroy(io);
    }
 catch (    QemuImgException e) {
      s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
catch (    RadosException e) {
      s_logger.error("String_Node_Str" + e.getReturnValue() + "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
catch (    RbdException e) {
      s_logger.error("String_Node_Str" + e.getReturnValue() + "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
  }
 else {
    srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(),srcPool.getSourcePort(),srcPool.getAuthUserName(),srcPool.getAuthSecret(),sourcePath));
    srcFile.setFormat(sourceFormat);
    destFile=new QemuImgFile(destPath);
    destFile.setFormat(destFormat);
    try {
      qemu.convert(srcFile,destFile);
    }
 catch (    QemuImgException e) {
      s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
  }
  if (newDisk == null) {
    throw new CloudRuntimeException("String_Node_Str" + disk.getPath() + "String_Node_Str"+ name);
  }
  return newDisk;
}

Fixed version (ground truth):
/** 
 * This copies a volume from Primary Storage to Secondary Storage In theory it could also do it the other way around, but the current implementation in ManagementServerImpl shows that the destPool is always a Secondary Storage Pool
 */
@Override public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk,String name,KVMStoragePool destPool,int timeout){
  KVMStoragePool srcPool=disk.getPool();
  PhysicalDiskFormat sourceFormat=disk.getFormat();
  String sourcePath=disk.getPath();
  KVMPhysicalDisk newDisk;
  s_logger.debug("String_Node_Str" + disk.getSize() + "String_Node_Str"+ disk.getVirtualSize()+ "String_Node_Str"+ disk.getFormat());
  if (destPool.getType() != StoragePoolType.RBD) {
    if (disk.getFormat() == PhysicalDiskFormat.TAR) {
      newDisk=destPool.createPhysicalDisk(name,PhysicalDiskFormat.DIR,Storage.ProvisioningType.THIN,disk.getVirtualSize());
    }
 else {
      if (srcPool.getType() != StoragePoolType.RBD) {
        newDisk=destPool.createPhysicalDisk(name,Storage.ProvisioningType.THIN,disk.getVirtualSize());
      }
 else {
        newDisk=destPool.createPhysicalDisk(name,Storage.ProvisioningType.THIN,disk.getVirtualSize());
      }
    }
  }
 else {
    newDisk=new KVMPhysicalDisk(destPool.getSourceDir() + "String_Node_Str" + name,name,destPool);
    newDisk.setFormat(PhysicalDiskFormat.RAW);
    newDisk.setSize(disk.getVirtualSize());
    newDisk.setVirtualSize(disk.getSize());
  }
  String destPath=newDisk.getPath();
  PhysicalDiskFormat destFormat=newDisk.getFormat();
  QemuImg qemu=new QemuImg(timeout);
  QemuImgFile srcFile=null;
  QemuImgFile destFile=null;
  if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() != StoragePoolType.RBD)) {
    if (sourceFormat == PhysicalDiskFormat.TAR && destFormat == PhysicalDiskFormat.DIR) {
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath);
    }
 else     if (sourceFormat == PhysicalDiskFormat.TAR) {
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
    }
 else     if (sourceFormat == PhysicalDiskFormat.DIR) {
      Script.runSimpleBashScript("String_Node_Str" + destPath);
      Script.runSimpleBashScript("String_Node_Str" + destPath);
      Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
    }
 else {
      srcFile=new QemuImgFile(sourcePath,sourceFormat);
      try {
        Map<String,String> info=qemu.info(srcFile);
        String backingFile=info.get(new String("String_Node_Str"));
        if (sourceFormat.equals(destFormat) && backingFile == null && sourcePath.endsWith("String_Node_Str")) {
          String result=Script.runSimpleBashScript("String_Node_Str" + sourcePath + "String_Node_Str"+ destPath,timeout);
          if (result != null) {
            throw new CloudRuntimeException("String_Node_Str" + result);
          }
        }
 else {
          destFile=new QemuImgFile(destPath,destFormat);
          try {
            qemu.convert(srcFile,destFile);
          }
 catch (          QemuImgException e) {
            s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
            newDisk=null;
          }
        }
      }
 catch (      QemuImgException e) {
        s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ e.getMessage());
        newDisk=null;
      }
    }
  }
 else   if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() == StoragePoolType.RBD)) {
    s_logger.debug("String_Node_Str");
    try {
      srcFile=new QemuImgFile(sourcePath,sourceFormat);
      String rbdDestFile=KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),destPool.getSourcePort(),destPool.getAuthUserName(),destPool.getAuthSecret(),destPool.getSourceDir() + "String_Node_Str" + name);
      destFile=new QemuImgFile(rbdDestFile,destFormat);
      s_logger.debug("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destPool.getSourceDir()+ "String_Node_Str"+ name);
      qemu.convert(srcFile,destFile);
      s_logger.debug("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destPool.getSourceDir()+ "String_Node_Str"+ name);
      Rados r=new Rados(destPool.getAuthUserName());
      r.confSet("String_Node_Str",destPool.getSourceHost() + "String_Node_Str" + destPool.getSourcePort());
      r.confSet("String_Node_Str",destPool.getAuthSecret());
      r.confSet("String_Node_Str","String_Node_Str");
      r.connect();
      s_logger.debug("String_Node_Str" + r.confGet("String_Node_Str"));
      IoCTX io=r.ioCtxCreate(destPool.getSourceDir());
      Rbd rbd=new Rbd(io);
      RbdImage image=rbd.open(name);
      rbd.close(image);
      r.ioCtxDestroy(io);
    }
 catch (    QemuImgException e) {
      s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
catch (    RadosException e) {
      s_logger.error("String_Node_Str" + e.getReturnValue() + "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
catch (    RbdException e) {
      s_logger.error("String_Node_Str" + e.getReturnValue() + "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
  }
 else {
    srcFile=new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(srcPool.getSourceHost(),srcPool.getSourcePort(),srcPool.getAuthUserName(),srcPool.getAuthSecret(),sourcePath));
    srcFile.setFormat(sourceFormat);
    destFile=new QemuImgFile(destPath);
    destFile.setFormat(destFormat);
    try {
      qemu.convert(srcFile,destFile);
    }
 catch (    QemuImgException e) {
      s_logger.error("String_Node_Str" + srcFile.getFileName() + "String_Node_Str"+ destFile.getFileName()+ "String_Node_Str"+ e.getMessage());
      newDisk=null;
    }
  }
  if (newDisk == null) {
    throw new CloudRuntimeException("String_Node_Str" + disk.getPath() + "String_Node_Str"+ name);
  }
  return newDisk;
}