private void ResumeAdd(AddDiskOperationResumeRecord resumeRecord) { // the RAID-5 volume was temporarily converted to striped volume if (m_volume is StripedVolume) { StripedVolume stripedVolume = (StripedVolume)m_volume; DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { long bytesTotal = stripedVolume.Size / stripedVolume.NumberOfColumns * (stripedVolume.NumberOfColumns - 2); long bytesCopied = 0; Thread workerThread = new Thread(delegate() { m_isWorking = true; List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(stripedVolume.DiskGroupGuid); DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(diskGroup, stripedVolume.DiskGroupGuid); AddDiskToArrayHelper.ResumeAddDiskToRaid5Volume(database, stripedVolume, resumeRecord, ref bytesCopied); m_isWorking = false; }); workerThread.Start(); new Thread(delegate() { while (workerThread.IsAlive) { Thread.Sleep(250); int progress = (int)(100 * (double)bytesCopied / bytesTotal); this.Invoke((MethodInvoker) delegate() { progressBar.Value = progress; }); } this.Invoke((MethodInvoker) delegate() { DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); }); }).Start(); } } }
public static DiskGroupLockResult ExtendDynamicVolume(List <DynamicDisk> diskGroup, DynamicVolume volume, long numberOfAdditionalExtentSectors) { if (volume is StripedVolume) { numberOfAdditionalExtentSectors -= numberOfAdditionalExtentSectors % ((StripedVolume)volume).SectorsPerStripe; } if (volume is Raid5Volume) { numberOfAdditionalExtentSectors -= numberOfAdditionalExtentSectors % ((Raid5Volume)volume).SectorsPerStripe; } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(diskGroup); if (result != DiskGroupLockResult.Success) { return(result); } DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(diskGroup, volume.DiskGroupGuid); ExtendHelper.ExtendDynamicVolume((DynamicVolume)volume, numberOfAdditionalExtentSectors, database); DiskGroupHelper.UnlockDiskGroup(diskGroup); return(DiskGroupLockResult.Success); }
private void ResumeMove(MoveExtentOperationResumeRecord resumeRecord) { DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { int extentIndex = DynamicDiskExtentHelper.GetIndexOfExtentID(m_volume.DynamicExtents, (resumeRecord).ExtentID); DynamicDiskExtent sourceExtent = m_volume.DynamicExtents[extentIndex]; long bytesTotal = sourceExtent.Size; long bytesCopied = 0; Thread workerThread = new Thread(delegate() { m_isWorking = true; List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(m_volume.DiskGroupGuid); DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(diskGroup, m_volume.DiskGroupGuid); MoveExtentHelper.ResumeMoveExtent(database, m_volume, resumeRecord, ref bytesCopied); m_isWorking = false; }); workerThread.Start(); new Thread(delegate() { while (workerThread.IsAlive) { Thread.Sleep(250); int progress = (int)(100 * (double)bytesCopied / bytesTotal); this.Invoke((MethodInvoker) delegate() { progressBar.Value = progress; }); } this.Invoke((MethodInvoker) delegate() { DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); }); }).Start(); } }
private static ExtendFileSystemResult ExtendUnmountedFileSystem(List <DynamicDisk> diskGroup, DynamicVolume volume, long numberOfAdditionalSectors) { if (!volume.IsOperational) { return(ExtendFileSystemResult.NonOperationalVolume); } IExtendableFileSystem fileSystem = FileSystemHelper.ReadFileSystem(volume) as IExtendableFileSystem; // Windows Vista / 7 enforce various limitations on direct write operations to volumes and disks. // Basic disks are not needed to be taken offline for direct write operations within volume region. Only dynamic disks have to. if (Environment.OSVersion.Version.Major >= 6) { // Lock disks and volumes DiskGroupLockResult lockResult = DiskGroupHelper.LockDiskGroup(diskGroup); if (lockResult == DiskGroupLockResult.CannotLockDisk) { return(ExtendFileSystemResult.CannotLockDisk); } else if (lockResult == DiskGroupLockResult.CannotLockVolume) { return(ExtendFileSystemResult.CannotLockVolume); } else if (lockResult == DiskGroupLockResult.CannotTakeDiskOffline) { return(ExtendFileSystemResult.CannotTakeDiskOffline); } else if (lockResult == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { return(ExtendFileSystemResult.OneOrMoreDisksAreOfflineOrReadonly); } } fileSystem.Extend(numberOfAdditionalSectors); if (Environment.OSVersion.Version.Major >= 6) { DiskGroupHelper.UnlockDiskGroup(diskGroup); } return(ExtendFileSystemResult.Success); }
private void btnOK_Click(object sender, EventArgs e) { DynamicDisk targetDynamicDisk = (DynamicDisk)listDisks.SelectedValue; Raid5Volume raid5Volume = (Raid5Volume)m_volume; DiskExtent newExtent = DynamicDiskHelper.FindExtentAllocation(targetDynamicDisk, raid5Volume.ColumnSize); if (newExtent == null) { MessageBox.Show("The disk specified does not contain enough free space.", "Error"); return; } List <DynamicDisk> diskGroup = WindowsDynamicDiskHelper.GetPhysicalDynamicDisks(raid5Volume.DiskGroupGuid); DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(diskGroup, raid5Volume.DiskGroupGuid); if (database.AreDisksMissing) { DialogResult disksMissingResult = MessageBox.Show("Some of the disks in this disk group are missing, Continue anyway?", "Warning", MessageBoxButtons.YesNo); if (disksMissingResult != DialogResult.Yes) { return; } } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { listDisks.Enabled = false; btnCancel.Enabled = false; btnOK.Enabled = false; progressBar.Visible = true; long bytesTotal = raid5Volume.Size; long bytesCopied = 0; Thread workerThread = new Thread(delegate() { m_isWorking = true; AddDiskToArrayHelper.AddDiskToRaid5Volume(database, raid5Volume, newExtent, ref bytesCopied); m_isWorking = false; }); workerThread.Start(); new Thread(delegate() { while (workerThread.IsAlive) { Thread.Sleep(250); int progress = (int)(100 * (double)bytesCopied / bytesTotal); this.Invoke((MethodInvoker) delegate() { progressBar.Value = progress; }); } this.Invoke((MethodInvoker) delegate() { DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); }); }).Start(); } }
private void btnOK_Click(object sender, EventArgs e) { DynamicDisk targetDisk = (DynamicDisk)listDisks.SelectedValue; long offset = GetDiskOffset(); bool isSameDisk = (targetDisk.Disk == m_extent.Disk); if (!DynamicDiskHelper.IsMoveLocationValid(m_extent, targetDisk, offset)) { StringBuilder builder = new StringBuilder(); builder.AppendLine("Invalid offset specified."); builder.AppendLine(); builder.AppendLine("The following conditions must be met:"); builder.AppendLine("1. The destination must reside inside the data portion of the disk."); builder.AppendLine("2. The destination must not be used by any other extents."); builder.AppendLine("3. The offset must be aligned to sector size."); builder.AppendLine("4. Source and destination disk must have the same sector size."); MessageBox.Show(builder.ToString(), "Error"); return; } if (isSameDisk && offset == m_extent.FirstSector * m_extent.BytesPerSector) { MessageBox.Show("Source and destination are the same.", "Error"); return; } DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup, targetDisk.DiskGroupGuid); if (database.AreDisksMissing) { DialogResult disksMissingResult = MessageBox.Show("Some of the disks in this disk group are missing, Continue anyway?", "Warning", MessageBoxButtons.YesNo); if (disksMissingResult != DialogResult.Yes) { return; } } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { listDisks.Enabled = false; numericDiskOffset.Enabled = false; listSuffixes.Enabled = false; btnCancel.Enabled = false; btnOK.Enabled = false; progressBar.Visible = true; long firstSector = offset / targetDisk.BytesPerSector; DiskExtent targetExtent = new DiskExtent(targetDisk.Disk, firstSector, m_extent.Size); long bytesTotal = m_extent.Size; long bytesCopied = 0; Thread workerThread = new Thread(delegate() { m_isWorking = true; if (isSameDisk) { MoveExtentHelper.MoveExtentWithinSameDisk(database, m_volume, m_extent, targetExtent, ref bytesCopied); } else { MoveExtentHelper.MoveExtentToAnotherDisk(database, m_volume, m_extent, targetExtent, ref bytesCopied); } m_isWorking = false; }); workerThread.Start(); new Thread(delegate() { while (workerThread.IsAlive) { Thread.Sleep(250); int progress = (int)(100 * (double)bytesCopied / bytesTotal); this.Invoke((MethodInvoker) delegate() { progressBar.Value = progress; }); } this.Invoke((MethodInvoker) delegate() { DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); }); }).Start(); } }
private void btnOK_Click(object sender, EventArgs e) { int diskCount = listDisks.CheckedIndices.Count; if (rbSimple.Checked && diskCount != 1) { MessageBox.Show("You must select a single disk in order to create a simple volume.", "Error"); return; } if (rbRaid5.Checked) { if (chkDegraded.Checked && diskCount < 2) { MessageBox.Show("You must select at least 2 disks in order to create a degraded RAID-5 volume.", "Error"); return; } if (!chkDegraded.Checked && diskCount < 3) { MessageBox.Show("You must select at least 3 disks in order to create a RAID-5 volume.", "Error"); return; } } long extentSizeInBytes = (long)numericExtentSize.Value * 1024 * 1024; List <DiskExtent> extents = new List <DiskExtent>(); foreach (int checkedIndex in listDisks.CheckedIndices) { DynamicDisk dynamicDisk = m_diskGroup[checkedIndex]; DiskExtent extent = DynamicDiskHelper.FindExtentAllocation(dynamicDisk, extentSizeInBytes); if (extent == null) { MessageBox.Show("One of the disks does not contain enough free space", "Error"); return; } extents.Add(extent); } DiskGroupLockResult result = DiskGroupHelper.LockDiskGroup(m_diskGroup); if (result == DiskGroupLockResult.CannotLockDisk) { MessageBox.Show("Unable to lock all disks!", "Error"); } else if (result == DiskGroupLockResult.CannotLockVolume) { MessageBox.Show("Unable to lock all volumes!", "Error"); } else if (result == DiskGroupLockResult.OneOrMoreDisksAreOfflineOrReadonly) { MessageBox.Show("One or more disks are offline or set to readonly.", "Error"); } else if (result == DiskGroupLockResult.CannotTakeDiskOffline) { MessageBox.Show("Failed to take all dynamic disks offline!", "Error"); } else if (result == DiskGroupLockResult.Success) { DiskGroupDatabase database = DiskGroupDatabase.ReadFromDisks(m_diskGroup)[0]; if (rbSimple.Checked) { VolumeManagerDatabaseHelper.CreateSimpleVolume(database, extents[0]); } else { VolumeManagerDatabaseHelper.CreateRAID5Volume(database, extents, chkDegraded.Checked); } DiskGroupHelper.UnlockDiskGroup(m_diskGroup); this.DialogResult = DialogResult.OK; this.Close(); } }