Package com.cybozu.vmbkp.util

Examples of com.cybozu.vmbkp.util.VmdkBitmap


    public static void main(String[] args)
    {
        /* basic test */
        if (true) {
            VmdkBitmap bmp = new VmdkBitmap(32, 1);

            try {
                bmp.setRangeInBytes(0, 4);
                bmp.setRangeInBytes(16, 8);
            } catch (Exception e) {
                e.printStackTrace();
            }
       
            System.out.println(bmp.toString());

            System.out.println("bytestring begin.");
            byte[] a = bmp.getAsByteString();
            for (int i = 0; i < a.length; i ++) {
                System.out.printf("%02x ", a[i]);
            }
            System.out.println("bytestring end.");
        }

        /* alignment test */
        if (true) {
            VmdkBitmap bmp = new VmdkBitmap(8 * 1024, 1024);

            try {
                bmp.setRangeInBytes(0, 1);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("10000000");
                bmp.clear();

                bmp.setRangeInBytes(2047, 1);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("01000000");
                bmp.clear();

                bmp.setRangeInBytes(4096, 0);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("00000000");
                bmp.clear();

                bmp.setRangeInBytes(4096, 1);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("00001000");
                bmp.clear();
               
                bmp.setRangeInBytes(1024, 1024);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("01000000");
                bmp.clear();

                bmp.setRangeInBytes(1024, 1025);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("01100000");
                bmp.clear();

                bmp.setRangeInBytes(1023, 1025);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("11000000");
                bmp.clear();

                bmp.setRangeInBytes(1023, 1026);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("11100000");
                bmp.clear();

                bmp.setRangeInBytes(1023, 1);
                System.out.println(bmp.toString());
                assert bmp.toString().equals("10000000");
                bmp.clear();

            } catch (Exception e) {
                e.printStackTrace();
            }


        }
       
        /* large bitmap test. */
        if (true) {
            /* 1TB */
            System.out.printf("1TB: %d\n", TERA);
            VmdkBitmap bmp = new VmdkBitmap(TERA);
           
            try {
                bmp.setRangeInBytes(0, MEGA);
                System.out.println(bmp.get(0));
                assert bmp.get(0) == true;
                bmp.clear();

                bmp.setRangeInBytes(GIGA + 1, 2 * MEGA);
                //bmp.setRangeInBytes(GIGA + , 1 * MEGA + 2 * KILO);

                System.out.println(bmp.get(1022)); assert bmp.get(1022) == false;
                System.out.println(bmp.get(1023)); assert bmp.get(1023) == false;
                System.out.println(bmp.get(1024)); assert bmp.get(1024) == true;
                System.out.println(bmp.get(1025)); assert bmp.get(1025) == true;
                System.out.println(bmp.get(1026)); assert bmp.get(1026) == true;
                System.out.println(bmp.get(1027)); assert bmp.get(1027) == false;
                bmp.clear();
               
            } catch (Exception e) {
                e.printStackTrace();
            }

View Full Code Here


        logger_.info(baseChangeId); /* debug */

        final long capacityInBytes = vmdkInfo.capacityInKB_ * 1024L;
       
        /* block size is fixed to 1MB currently */
        VmdkBitmap bmp = new VmdkBitmap(capacityInBytes, 1024 * 1024);
       
        boolean isNotChangedAtAll = false;
        try {
            long offset = 0;
            DiskChangeInfo dci = null;
            do {
                dci = vm.queryChangedDiskAreas
                    (vmSnap, vmdkInfo.key_, offset, baseChangeId);

                if (offset == 0 && (dci.changedArea == null)) {
                    /*
                      ChangeId is not null and DiskChangeInfo.changedArea is null,
                       then the disk is not changed at all.
                     */
                    isNotChangedAtAll = true;
                    logger_.info("This vmdk is not changed at all " +
                                 "from previous backup.");
                    break;
                }
               
                for (int j = 0; j < dci.changedArea.length; j ++) {
                    long start = dci.getChangedArea()[j].getStart();
                    long len = dci.getChangedArea()[j].getLength();
                    logger_.info
                        (String.format
                         ("(%d,%d) %s \n", start, len,
                          (len % 1048576 == 0 ? "" : "not x MB")));

                    bmp.setRangeInBytes(start, len);
                }
                logger_.info
                    (String.format
                     ("offset %d, length %d\n",
                      dci.getStartOffset(), dci.getLength()));
View Full Code Here

         int diskId)
    {
        String prevChangeId = vmArcMgr.getPrevChangeId(diskId);
        assert prevChangeId != null && (prevChangeId.equals("*") == false);
       
        VmdkBitmap bmp = snap.getChangedBlocksOfDisk(vmdkInfo, prevChangeId);
        if (bmp == null) { return false; }

        ProfileGeneration profGen = vmArcMgr.getTargetGeneration();

        try {
            /* Save the changed bitmap file */
            FilterOutputStream fos =
                new FilterOutputStream
                (new FileOutputStream
                 (profGen.getBmpInPath(diskId)));
            bmp.writeTo(fos);
            fos.close();

            /* Check whether the bitmap is all zero or not.
               (All zero means the vmdk does not change at all.) */
            profGen.setIsChanged(diskId, bmp.isAllZero() == false);
           
        } catch (Exception e) {
            logger_.warning(Utility.toString(e));
            return false;
        }
View Full Code Here

    final static long MEGA = 1024L * 1024L;

    public static void main(String[] args)
    {
        try {
            VmdkBitmap bmp = new VmdkBitmap(1025 * MEGA, (int)MEGA);
            bmp.set(5);
            bmp.set(20);
            bmp.writeTo(new FilterOutputStream(System.out));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

{
    static final long MEGA = 1024L * 1024L;
    public static void main(String[] args)
    {
        try {
            VmdkBitmap bmp = new VmdkBitmap
                ((int) MEGA,
                 new BufferedInputStream(System.in));
            System.out.printf("%s\n", bmp.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

TOP

Related Classes of com.cybozu.vmbkp.util.VmdkBitmap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.