Example #1
0
        protected Vdev(NvList config)
        {
            this.Guid = config.Get<ulong>("guid");
            this.ID = config.Get<ulong>("id");

            MetaSlabArray = config.GetOptional<ulong>("metaslab_array");
            MetaSlabShift = config.GetOptional<ulong>("metaslab_shift");
            AShift = config.GetOptional<ulong>("ashift");
            ASize = config.GetOptional<ulong>("asize");
        }
Example #2
0
        protected Vdev(NvList config)
        {
            this.Guid = config.Get <ulong>("guid");
            this.ID   = config.Get <ulong>("id");

            MetaSlabArray = config.GetOptional <ulong>("metaslab_array");
            MetaSlabShift = config.GetOptional <ulong>("metaslab_shift");
            AShift        = config.GetOptional <ulong>("ashift");
            ASize         = config.GetOptional <ulong>("asize");
        }
Example #3
0
        public RaidzVdev(NvList config, Dictionary<ulong, LeafVdevInfo> leafs)
            : base(config)
        {
            this.mVdevs = config.Get<NvList[]>("children")
                .Select(child => Vdev.Create(child, leafs))
                .OrderBy(child => child.ID)
                .ToArray();

            mNparity = config.Get<UInt64>("nparity");
            mUnitShift = (int)config.Get<UInt64>("ashift");
        }
Example #4
0
        readonly int mUnitShift; //ashift
        public RaidzVdev(NvList config, Dictionary<ulong, LeafVdevInfo> leafs)
            : base(config)
        {
            this.mVdevs = config.Get<NvList[]>("children")
                .Select(child => Vdev.Create(child, leafs))
                .OrderBy(child => child.ID)
                .ToArray();

            mNparity = config.Get<UInt64>("nparity");
            mUnitShift = (int)config.Get<UInt64>("ashift");
        }
Example #5
0
 public MirrorVdev(NvList config, Dictionary <ulong, LeafVdevInfo> leafs)
     : base(config)
 {
     this.mVdevs = config.Get <NvList[]>("children")
                   .Select(child => Vdev.Create(child, leafs))
                   .ToArray();
 }
Example #6
0
 public MirrorVdev(NvList config, Dictionary<ulong, LeafVdevInfo> leafs)
     : base(config)
 {
     this.mVdevs = config.Get<NvList[]>("children")
         .Select(child => Vdev.Create(child, leafs))
         .ToArray();
 }
Example #7
0
 public static Vdev Create(NvList config, Dictionary<ulong, LeafVdevInfo> leafs)
 {
     var type = config.Get<string>("type");
     switch (type)
     {
         case "mirror":
             return new MirrorVdev(config, leafs);
         case "disk":
         case "file":
             return new HddVdev(config, leafs[config.Get<ulong>("guid")]);
         case "raidz":
             return new RaidzVdev(config, leafs);
         default:
             throw new NotSupportedException("Unknown type: " + type);
     }
     throw new NotImplementedException();
 }
Example #8
0
        public LeafVdevInfo(HardDisk hdd)
        {
            this.HDD = hdd;

            var rentedBytes = Program.RentBytes(VDEV_PHYS_SIZE);

            try
            {
                if (!hdd.ReadLabelBytes(rentedBytes, VDEV_SKIP_SIZE))
                    throw new Exception("Invalid checksum on lable config data!");
                Config = new NvList(rentedBytes);
            }
            finally
            {
                Program.ReturnBytes(rentedBytes);
                rentedBytes = default(ArraySegment<byte>);
            }

            //figure out how big the uber blocks are
            var vdevTree = Config.Get<NvList>("vdev_tree");
            var ubShift = (int)vdevTree.Get<ulong>("ashift");
            ubShift = Math.Max(ubShift, UBERBLOCK_SHIFT);
            ubShift = Math.Min(ubShift, MAX_UBERBLOCK_SHIFT);
            var ubSize = 1 << ubShift;
            var ubCount = VDEV_UBERBLOCK_RING >> ubShift;

            List<uberblock_t> blocks = new List<uberblock_t>();
            var ubBytes = Program.RentBytes(ubSize);
            try
            {
                for (long i = 0; i < ubCount; i++)
                {
                    var offset = VDEV_SKIP_SIZE + VDEV_PHYS_SIZE + ubSize * i;
                    if (!hdd.ReadLabelBytes(ubBytes, offset))
                        continue;
                    uberblock_t b = Program.ToStruct<uberblock_t>(ubBytes.Array, ubBytes.Offset);
                    if (b.Magic == uberblock_t.UbMagic)
                    {
                        blocks.Add(b);
                    }
                }
            }
            finally
            {
                Program.ReturnBytes(ubBytes);
                ubBytes = default(ArraySegment<byte>);
            }
            this.Uberblock = blocks.OrderByDescending(u => u.Txg).ThenByDescending(u => u.TimeStamp).First();

            const int VDevLableSizeStart = 4 << 20;
            const int VDevLableSizeEnd = 512 << 10;
            hdd = OffsetHardDisk.Create(hdd, VDevLableSizeStart, hdd.Length - VDevLableSizeStart - VDevLableSizeEnd);
            this.HDD = hdd;
        }
Example #9
0
        public static Vdev Create(NvList config, Dictionary <ulong, LeafVdevInfo> leafs)
        {
            var type = config.Get <string>("type");

            switch (type)
            {
            case "mirror":
                return(new MirrorVdev(config, leafs));

            case "disk":
            case "file":
                return(new HddVdev(config, leafs[config.Get <ulong>("guid")]));

            case "raidz":
                return(new RaidzVdev(config, leafs));

            default:
                throw new NotSupportedException("Unknown type: " + type);
            }
            throw new NotImplementedException();
        }