private LogicalVolumeStatus GetVolumeStatus(VolumeRecord volume)
        {
            int   numFailed           = 0;
            ulong numOK               = 0;
            LogicalVolumeStatus worst = LogicalVolumeStatus.Healthy;

            foreach (var cmpnt in _database.GetVolumeComponents(volume.Id))
            {
                LogicalVolumeStatus cmpntStatus = GetComponentStatus(cmpnt);
                worst = WorstOf(worst, cmpntStatus);
                if (cmpntStatus == LogicalVolumeStatus.Failed)
                {
                    numFailed++;
                }
                else
                {
                    numOK++;
                }
            }

            if (numOK < 1)
            {
                return(LogicalVolumeStatus.Failed);
            }
            else if (numOK == volume.ComponentCount)
            {
                return(worst);
            }
            else
            {
                return(LogicalVolumeStatus.FailedRedundancy);
            }
        }
 internal LogicalVolumeInfo(Guid guid, PhysicalVolumeInfo physicalVolume, SparseStreamOpenDelegate opener, long length, byte biosType, LogicalVolumeStatus status)
 {
     _guid = guid;
     _physicalVol = physicalVolume;
     _opener = opener;
     _length = length;
     _biosType = biosType;
     _status = status;
 }
示例#3
0
 internal LogicalVolumeInfo(Guid guid, PhysicalVolumeInfo physicalVolume, SparseStreamOpenDelegate opener, long length, byte biosType, LogicalVolumeStatus status)
 {
     _guid        = guid;
     _physicalVol = physicalVolume;
     _opener      = opener;
     _length      = length;
     _biosType    = biosType;
     _status      = status;
 }
        private LogicalVolumeStatus GetComponentStatus(ComponentRecord cmpnt)
        {
            // NOTE: no support for RAID, so either valid or failed...
            LogicalVolumeStatus status = LogicalVolumeStatus.Healthy;

            foreach (ExtentRecord extent in _database.GetComponentExtents(cmpnt.Id))
            {
                DiskRecord disk = _database.GetDisk(extent.DiskId);
                if (!_disks.ContainsKey(new Guid(disk.DiskGuidString)))
                {
                    status = LogicalVolumeStatus.Failed;
                    break;
                }
            }

            return(status);
        }
        internal void Parse(string head, TextReader data)
        {
            var segments = new List <MetadataSegmentSection>();

            Name = head.Trim().TrimEnd('{').TrimEnd();
            string line;

            while ((line = Metadata.ReadLine(data)) != null)
            {
                if (line == String.Empty)
                {
                    continue;
                }
                if (line.Contains("="))
                {
                    var parameter = Metadata.ParseParameter(line);
                    switch (parameter.Key.Trim().ToLowerInvariant())
                    {
                    case "id":
                        Id = Metadata.ParseStringValue(parameter.Value);
                        byte[] guid = new byte[16];
                        EndianUtilities.StringToBytes(Id.Replace("-", String.Empty), guid, 0, 16);
                        // Mark it as a version 4 GUID
                        guid[7]  = (byte)((guid[7] | (byte)0x40) & (byte)0x4f);
                        guid[8]  = (byte)((guid[8] | (byte)0x80) & (byte)0xbf);
                        Identity = new Guid(guid);
                        break;

                    case "status":
                        var values = Metadata.ParseArrayValue(parameter.Value);
                        foreach (var value in values)
                        {
                            switch (value.ToLowerInvariant().Trim())
                            {
                            case "read":
                                Status |= LogicalVolumeStatus.Read;
                                break;

                            case "write":
                                Status |= LogicalVolumeStatus.Write;
                                break;

                            case "visible":
                                Status |= LogicalVolumeStatus.Visible;
                                break;

                            default:
                                throw new ArgumentOutOfRangeException("status", "Unexpected status in physical volume metadata");
                            }
                        }
                        break;

                    case "flags":
                        Flags = Metadata.ParseArrayValue(parameter.Value);
                        break;

                    case "creation_host":
                        CreationHost = Metadata.ParseStringValue(parameter.Value);
                        break;

                    case "creation_time":
                        CreationTime = Metadata.ParseDateTimeValue(parameter.Value);
                        break;

                    case "segment_count":
                        SegmentCount = Metadata.ParseNumericValue(parameter.Value);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(parameter.Key, "Unexpected parameter in global metadata");
                    }
                }
                else if (line.EndsWith("{"))
                {
                    var segment = new MetadataSegmentSection();
                    segment.Parse(line, data);
                    segments.Add(segment);
                }
                else if (line.EndsWith("}"))
                {
                    break;
                }
                else
                {
                    throw new ArgumentOutOfRangeException(line, "unexpected input");
                }
            }
            Segments = segments.ToArray();
        }
 private static LogicalVolumeStatus WorstOf(LogicalVolumeStatus x, LogicalVolumeStatus y)
 {
     return((LogicalVolumeStatus)Math.Max((int)x, (int)y));
 }
 private static LogicalVolumeStatus WorstOf(LogicalVolumeStatus x, LogicalVolumeStatus y)
 {
     return (LogicalVolumeStatus)Math.Max((int)x, (int)y);
 }