swap: renewed swap image creation process
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Thu, 11 Jun 2015 05:28:33 +0000 (14:28 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 12 Jun 2015 05:12:10 +0000 (14:12 +0900)
Now we create swap image per vm by copying from base image.

Change-Id: Iae9fb8fa5234c918cdd520707e50e2116fb429a3
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
src/org/tizen/emulator/manager/EmulatorManager.java
src/org/tizen/emulator/manager/resources/FilePathResources.java
src/org/tizen/emulator/manager/tool/CheckEmulatorDir.java
src/org/tizen/emulator/manager/vms/Creator.java

index 2410ab5..b50e4d7 100755 (executable)
@@ -311,7 +311,6 @@ public class EmulatorManager {
 
                // check SD Card folder
                CheckEmulatorDir.CheckSDCardDir();
-               CheckEmulatorDir.CheckSwapDir();
 
                if (isConsoleMode) {
                        EmulatorManager.startConsoleProcessor();
index 9336197..85c71b0 100644 (file)
@@ -204,7 +204,8 @@ public class FilePathResources {
 
                tizensdkdataEmulatorPath = tizensdkdataPath + sdkdata_new_emulator_suffix;
                sdcardPath = tizensdkdataEmulatorPath + sdcard_suffix;
-               swapPath = tizensdkdataEmulatorPath + swap_suffix;
+//             swapPath = tizensdkdataEmulatorPath + swap_suffix;
+               swapPath = sdkDataSwapPath;
                sdkDataVmsPath = tizensdkdataEmulatorPath + vms_suffix;
 
                tizensdkdataOldEmulatorPath = tizensdkdataPath + sdkdata_old_emulator_suffix;
index 09fcd95..c29dcb4 100644 (file)
@@ -99,81 +99,6 @@ public class CheckEmulatorDir {
                return true;
        }
 
-       public static void CheckSwapDir() {
-               File dir = new File(FilePathResources.getSwapPath());
-
-               if (!dir.exists()) {
-                       dir.mkdir();
-               }
-
-               File dest = null;
-               File src = null;
-               dest = new File(FilePathResources.getSwapPath()
-                                       + File.separator + StringResources.SWAP_IMAGE);
-               if (!dest.exists()) {
-                       src = new File(FilePathResources.getbaseSwapPath()
-                                       + File.separator + StringResources.SWAP_IMAGE);
-                       if (!src.exists()) {
-                               EMLogger.getLogger().log(Level.WARNING,
-                               "Failed to create swap image.!" + StringResources.NEW_LINE
-                               + "File does not exist :" + src.getPath());
-                               return;
-                       }
-
-                       try {
-                               dest.createNewFile();
-                       } catch (IOException e1) {
-                               EMLogger.getLogger().log(Level.WARNING,
-                               "Failed to create swap image!" + StringResources.NEW_LINE
-                               + e1.getMessage());
-                               return;
-                       }
-
-                       FileInputStream inputStream = null;
-                       FileOutputStream outputStream = null;
-                       FileChannel fcin = null;
-                       FileChannel fcout = null;
-                       try {
-                               inputStream = new FileInputStream(src);
-                               outputStream = new FileOutputStream(dest);
-                               fcin =  inputStream.getChannel();
-                               fcout = outputStream.getChannel();
-                               long size = fcin.size();
-                               long transferredSize = fcin.transferTo(0, size, fcout);
-                               if(size != transferredSize) {
-                                       EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
-                                                                                                               + StringResources.NEW_LINE + "Copy failed.");
-                                       dest.delete();
-                               }
-                       } catch (FileNotFoundException e) {
-                               EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
-                                                       + StringResources.NEW_LINE + e.getMessage());
-                               dest.delete();
-                       } catch (IOException e) {
-                               EMLogger.getLogger().log(Level.WARNING, "Failed to create swap image!"
-                                                       + StringResources.NEW_LINE + e.getMessage());
-                               dest.delete();
-                       }finally {
-                               try {
-                                       if (fcout != null) {
-                                               fcout.close();
-                                       }
-                                       if (fcin != null) {
-                                               fcin.close();
-                                       }
-                                       if (outputStream != null) {
-                                               outputStream.close();
-                                       }
-                                       if (inputStream != null) {
-                                               inputStream.close();
-                                       }
-                               } catch (IOException e) {
-                                       EMLogger.getLogger().log(Level.WARNING, e.getMessage());
-                               }
-                       }
-               }
-       }
-
        public static void CheckSDCardDir() {
                File dir = new File(FilePathResources.getSDCardPath());
                
index db41635..316110f 100644 (file)
@@ -32,6 +32,9 @@ package org.tizen.emulator.manager.vms;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -184,20 +187,12 @@ public class Creator {
        }
 
        private void createSwapImageInternal(String basePath, String targetPath) throws VMCreatorException {
-               String exe_path         = getQemuImgPath();
-
-               List<String> cmd = new ArrayList<String>();
-               cmd.add(exe_path);
-               cmd.add("create");
-               cmd.add("-b");
-               cmd.add(basePath);
-               cmd.add("-f");
-               cmd.add("qcow2");
-               cmd.add(targetPath);
-
-               if (!new QemuImgProc(cmd).Running()) {
-                       throw new VMCreatorException("Failed to create the VM because of failed qemu-img processing."
-                                       + StringResources.NEW_LINE
+               // Swap images created by clone base image.
+               try {
+                       Files.copy(Paths.get(basePath), Paths.get(targetPath), StandardCopyOption.COPY_ATTRIBUTES);
+               } catch (IOException e) {
+                       e.printStackTrace();
+                       throw new VMCreatorException("Failed to copy swap image." + StringResources.NEW_LINE
                                        + "You can get more information in log file ("
                                        + FilePathResources.getTizenVmsPath() +  File.separator + "emulator-manager)");
                }