public const int BackupBufferSizeLBA = 128; // there are about 180 contiguous free sectors in a private region

        /// <summary>
        /// Move extent to another disk
        /// </summary>
        public static void MoveExtentToAnotherDisk(List<DynamicDisk> disks, DynamicVolume volume, DynamicDiskExtent sourceExtent, DiskExtent relocatedExtent, ref long bytesCopied)
        {
            DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(disks, volume.DiskGroupGuid);
            if (database == null)
            {
                throw new DatabaseNotFoundException();
            }

            // copy the data
            long transferSizeLBA = Settings.MaximumTransferSizeLBA;
            for (long sectorIndex = 0; sectorIndex < relocatedExtent.TotalSectors; sectorIndex += transferSizeLBA)
            {
                long sectorsLeft = relocatedExtent.TotalSectors - sectorIndex;
                int sectorsToRead = (int)Math.Min(transferSizeLBA, sectorsLeft);

                byte[] data = sourceExtent.ReadSectors(sectorIndex, sectorsToRead);
                
                relocatedExtent.WriteSectors(sectorIndex, data);

                bytesCopied += sectorsToRead * sourceExtent.BytesPerSector;
            }

            // Update the database to point to the relocated extent
            DynamicDisk targetDisk = DynamicDisk.ReadFromDisk(relocatedExtent.Disk);
            DynamicDiskExtent dynamicRelocatedExtent = new DynamicDiskExtent(relocatedExtent, sourceExtent.ExtentID);
            dynamicRelocatedExtent.Name = sourceExtent.Name;
            dynamicRelocatedExtent.DiskGuid = targetDisk.DiskGuid;
            VolumeManagerDatabaseHelper.UpdateExtentLocation(database, volume, dynamicRelocatedExtent);
        }
示例#2
0
        public byte[] ReadSectors(long sectorIndex, int sectorCount)
        {
            List <ArrayPosition> readPositions = TranslateSectors(sectorIndex, sectorCount);

            byte[] result    = new byte[sectorCount * BytesPerSector];
            int    bytesRead = 0;

            foreach (ArrayPosition readPosition in readPositions)
            {
                DynamicDiskExtent extent      = m_extents[readPosition.DiskIndex];
                byte[]            extentBytes = extent.ReadSectors(readPosition.SectorIndex, readPosition.SectorCount);

                Array.Copy(extentBytes, 0, result, bytesRead, extentBytes.Length);
                bytesRead += extentBytes.Length;
            }

            return(result);
        }
示例#3
0
 public override byte[] ReadSectors(long sectorIndex, int sectorCount)
 {
     return(m_extent.ReadSectors(sectorIndex, sectorCount));
 }