~tritone-team/tritone/eucalyptus

« back to all changes in this revision

Viewing changes to clc/modules/storage-controller/src/main/java/edu/ucsb/eucalyptus/storage/LVM2Manager.java

  • Committer: Bazaar Package Importer
  • Author(s): Dustin Kirkland
  • Date: 2009-12-01 21:09:28 UTC
  • mto: This revision was merged to the branch mainline in revision 75.
  • Revision ID: james.westby@ubuntu.com-20091201210928-o2dvg0ubljhb0ft6
Tags: upstream-1.6.1~bzr1083
ImportĀ upstreamĀ versionĀ 1.6.1~bzr1083

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
import java.io.File;
69
69
import java.io.FileInputStream;
70
70
import java.io.FileOutputStream;
 
71
import java.io.IOException;
71
72
import java.net.InetAddress;
72
73
import java.nio.channels.FileChannel;
73
74
import java.util.ArrayList;
94
95
        public static final String lvmRootDirectory = "/dev";
95
96
        public static final String PATH_SEPARATOR = "/";
96
97
        public static boolean initialized = false;
97
 
        public static String hostName = "localhost";
98
98
        public static final int MAX_LOOP_DEVICES = 256;
99
99
        public static final int MAX_MINOR_NUMBER = 16;
100
100
        private  static final String blockSize = "1M";
270
270
 
271
271
        public void configure() {
272
272
                try {
273
 
                        hostName = InetAddress.getLocalHost().getHostName();
274
273
                        EntityWrapper<LVMMetaInfo> db = StorageController.getEntityWrapper();
275
 
                        LVMMetaInfo metaInfo = new LVMMetaInfo(hostName);
 
274
                        LVMMetaInfo metaInfo = new LVMMetaInfo();
276
275
                        List<LVMMetaInfo> metaInfoList = db.query(metaInfo);
277
276
                        if(metaInfoList.size() <= 0) {
 
277
                                metaInfo.setHostName(StorageProperties.NAME);
278
278
                                metaInfo.setMajorNumber(0);
279
279
                                metaInfo.setMinorNumber(0);
280
280
                                db.add(metaInfo);
350
350
                int majorNumber = -1;
351
351
                int minorNumber = -1;
352
352
                List<Integer> deviceNumbers = new ArrayList<Integer>();
353
 
                LVMMetaInfo metaInfo = new LVMMetaInfo(hostName);
 
353
                LVMMetaInfo metaInfo = new LVMMetaInfo();
354
354
                EntityWrapper<LVMMetaInfo> db = StorageController.getEntityWrapper();
355
355
                List<LVMMetaInfo> metaInfoList = db.query(metaInfo);
356
356
                if(metaInfoList.size() > 0) {
404
404
                }
405
405
 
406
406
                File vbladePidFile = new File(eucaHome + EUCA_VAR_RUN_PATH + "/vblade-" + majorNumber + minorNumber + ".pid");
 
407
                FileOutputStream fileOutStream = null;
407
408
                try {
408
 
                        FileOutputStream fileOutStream = new FileOutputStream(vbladePidFile);
 
409
                        fileOutStream = new FileOutputStream(vbladePidFile);
409
410
                        String pidString = String.valueOf(pid);
410
411
                        fileOutStream.write(pidString.getBytes());
411
 
                        fileOutStream.close();
412
412
                } catch (Exception ex) {
413
413
                        LOG.error("Could not write pid file vblade-" + majorNumber + minorNumber + ".pid");
 
414
                } finally {
 
415
                        if(fileOutStream != null)
 
416
                                try {
 
417
                                        fileOutStream.close();
 
418
                                } catch (IOException e) {
 
419
                                        LOG.error(e);
 
420
                                }
414
421
                }
415
422
                lvmVolumeInfo.setVbladePid(pid);
416
423
                lvmVolumeInfo.setMajorNumber(majorNumber);
419
426
        }
420
427
 
421
428
        public void dupFile(String oldFileName, String newFileName) {
 
429
                FileOutputStream fileOutputStream = null;
 
430
                FileChannel out = null;
 
431
                FileInputStream fileInputStream = null;
 
432
                FileChannel in = null;
422
433
                try {
423
 
                        FileChannel out = new FileOutputStream(new File(newFileName)).getChannel();
424
 
                        FileChannel in = new FileInputStream(new File(oldFileName)).getChannel();
 
434
                        fileOutputStream = new FileOutputStream(new File(newFileName));
 
435
                        out = fileOutputStream.getChannel();
 
436
                        fileInputStream = new FileInputStream(new File(oldFileName));
 
437
                        in = fileInputStream.getChannel();
425
438
                        in.transferTo(0, in.size(), out);
426
 
                        in.close();
427
 
                        out.close();
428
439
                } catch (Exception ex) {
429
440
                        ex.printStackTrace();
 
441
                } finally {
 
442
                        if(fileOutputStream != null) {
 
443
                                try {
 
444
                                        out.close();
 
445
                                        fileOutputStream.close();
 
446
                                } catch (IOException e) {
 
447
                                        LOG.error(e);
 
448
                                }
 
449
                        }
 
450
                        if(fileInputStream != null) {
 
451
                                try {
 
452
                                        in.close();
 
453
                                        fileInputStream.close();
 
454
                                } catch(IOException e) {
 
455
                                        LOG.error(e);
 
456
                                }
 
457
                        }
430
458
                }
431
459
        }
432
460
 
928
956
                                        pid = exportManager.exportVolume(StorageProperties.iface, absoluteLVName, majorNumber, minorNumber);
929
957
                                        foundVolumeInfo.setVbladePid(pid);
930
958
                                        File vbladePidFile = new File(eucaHome + EUCA_VAR_RUN_PATH + "/vblade-" + majorNumber + minorNumber + ".pid");
 
959
                                        FileOutputStream fileOutStream = null;
931
960
                                        try {
932
 
                                                FileOutputStream fileOutStream = new FileOutputStream(vbladePidFile);
 
961
                                                fileOutStream = new FileOutputStream(vbladePidFile);
933
962
                                                String pidString = String.valueOf(pid);
934
963
                                                fileOutStream.write(pidString.getBytes());
935
964
                                                fileOutStream.close();
936
965
                                        } catch (Exception ex) {
937
 
                                                LOG.error("Could not write pid file vblade-" + majorNumber + minorNumber + ".pid");
 
966
                                                if(fileOutStream != null)
 
967
                                                        try {
 
968
                                                                fileOutStream.close();
 
969
                                                        } catch (IOException e) {
 
970
                                                                LOG.error(e);
 
971
                                                        }
 
972
                                                        LOG.error("Could not write pid file vblade-" + majorNumber + minorNumber + ".pid");
938
973
                                        }
939
974
                                }
940
975
                        }
976
1011
                File file = new File("/proc/" + pid + "/cmdline");
977
1012
                String returnString = "";
978
1013
                if(file.exists()) {
 
1014
                        FileInputStream fileIn = null;
979
1015
                        try {
980
 
                                FileInputStream fileIn = new FileInputStream(file);
 
1016
                                fileIn = new FileInputStream(file);
981
1017
                                byte[] bytes = new byte[512];
982
1018
                                int bytesRead;
983
1019
                                while((bytesRead = fileIn.read(bytes)) > 0) {
985
1021
                                }
986
1022
                        } catch (Exception ex) {
987
1023
                                LOG.warn("could not find " + file.getAbsolutePath());
 
1024
                        } finally {
 
1025
                                if(fileIn != null)
 
1026
                                        try {
 
1027
                                                fileIn.close();
 
1028
                                        } catch (IOException e) {
 
1029
                                                LOG.error(e);
 
1030
                                        }
988
1031
                        }
989
1032
                }
990
1033
                return returnString;