Exemple #1
0
        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();
                }
            }
        }
Exemple #2
0
        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 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();
            }
        }