Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified string collection of file exclusions.</summary>
        /// <param name="writeToDb">If true, the object will be written to the Database.</param>
        public async Task <LogicalVolume> AddLogicalVolume(LogicalVolume volume, bool writeToDb)
        {
            if (LogicalVolumes.Contains(volume))
            {
                return(LogicalVolumes.First(x => x.Equals(volume)));
            }

            LogicalVolumes.Add(volume);
            if (writeToDb)
            {
                await Database.InsertLogicalVolumeAsync(volume);
            }

            return(volume);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the specified archive and all children from the index.</summary>
        /// <param name="writeToDb">If true, the object will be removed from the Database.</param>
        public async Task RemoveArchiveAsync(Archive archive, bool writeToDb)
        {
            if (archive is null)
            {
                return;
            }

            if (Archives.Where(x => x.Volume.Equals(archive.Volume)).Count() < 2)
            {
                // No other archive shares the logical volume of the
                // set that's about to be deleted, it can therefore be removed
                LogicalVolumes.Remove(archive.Volume);
                if (writeToDb)
                {
                    await Database.DeleteLogicalVolumeAsync(archive.Volume);
                }
            }

            // Get a list of all hashes related to the current archive,
            // remove all nodes from these hashes.
            var archiveHashes = archive.GetFileHashes();
            await archive.ClearAsync();

            archive.Dispose();

            // Get hashes in the collection with node count 0
            // these can be removed from the index
            var emptyHashes = archiveHashes.Where(x => x.NodeCount.Equals(0)).ToList();

            emptyHashes.ForEach(x => Hashes.Remove(x));

            if (writeToDb)
            {
                await Database.BatchDeleteFileHashAsync(emptyHashes);
            }

            Archives.Remove(archive);
            //NotifyPropertyChanged("Archive");
            if (writeToDb)
            {
                await Database.DeleteArchiveAsync(archive);
            }
        }
        private bool LogicalVolumeLayout()
        {
            var upSizeLock = new Dictionary <string, long>();

            //Try to resize lv to fit inside newly created lvm
            foreach (var volumeGroup in VolumeGroupHelpers)
            {
                //Tell the volume group it has a size of the physical volume to work with * 99% to account for errors to allow alittle over
                //volumeGroup.AgreedPvSizeBlk = Convert.ToInt64(volumeGroup.AgreedPvSizeBlk * .99);
                foreach (var partition in _imageSchema.HardDrives[HdNumberToGet].Partitions)
                {
                    //Find the partition this volume group belongs to
                    if (_imageSchema.HardDrives[HdNumberToGet].Name + partition.Prefix + partition.Number !=
                        volumeGroup.Pv)
                    {
                        continue;
                    }
                    var singleLvVerified = false;

                    var percentCounter = -.1;

                    while (!singleLvVerified)
                    {
                        percentCounter += .1;
                        double totalPvPercentage = 0;
                        LogicalVolumes.Clear();
                        if (!partition.Active)
                        {
                            continue;
                        }

                        var isError = false;
                        foreach (var lv in partition.VolumeGroup.LogicalVolumes)
                        {
                            if (!lv.Active)
                            {
                                continue;
                            }

                            var clientPartitionLv = new ClientLogicalVolume
                            {
                                Name   = lv.Name,
                                Vg     = lv.VolumeGroup,
                                Uuid   = lv.Uuid,
                                VgUuid = volumeGroup.Uuid,
                                FsType = lv.FsType
                            };

                            var logicalVolumeHelper = new ServiceClientPartition(_imageProfile).LogicalVolume(lv, LbsByte,
                                                                                                              _newHdSize, HdNumberToGet);
                            var percentOfPvForThisLv = (double)logicalVolumeHelper.MinSizeBlk /
                                                       volumeGroup.AgreedPvSizeBlk;
                            var tmpClientPartitionSizeLvBlk = logicalVolumeHelper.MinSizeBlk;

                            if (volumeGroup.IsFusion)
                            {
                                clientPartitionLv.Size = 0;
                                LogicalVolumes.Add(clientPartitionLv);
                                singleLvVerified = true;
                                continue;
                            }

                            if (upSizeLock.ContainsKey(lv.Name))
                            {
                                tmpClientPartitionSizeLvBlk = upSizeLock[lv.Name];
                            }
                            else
                            {
                                if (logicalVolumeHelper.IsDynamicSize)
                                {
                                    clientPartitionLv.SizeIsDynamic = true;
                                    var percentOfOrigDrive = Convert.ToInt64(lv.Size) /
                                                             (double)
                                                             Convert.ToInt64(
                                        _imageSchema.HardDrives[HdNumberToGet].Size);

                                    if (Convert.ToInt64(NewHdBlk * percentOfOrigDrive) < logicalVolumeHelper.MinSizeBlk)
                                    {
                                        //This will never work because each loop only gets smaller
                                        tmpClientPartitionSizeLvBlk =
                                            Convert.ToInt64(NewHdBlk * (percentOfOrigDrive + percentCounter / 100));

                                        if (logicalVolumeHelper.MinSizeBlk < tmpClientPartitionSizeLvBlk)
                                        {
                                            upSizeLock.Add(lv.Name, tmpClientPartitionSizeLvBlk);
                                        }
                                    }
                                    else
                                    {
                                        if (percentOfOrigDrive - percentCounter / 100 <= 0)
                                        {
                                            tmpClientPartitionSizeLvBlk =
                                                Convert.ToInt64(NewHdBlk * percentOfOrigDrive);
                                        }
                                        else
                                        {
                                            tmpClientPartitionSizeLvBlk =
                                                Convert.ToInt64(NewHdBlk *
                                                                (percentOfOrigDrive - percentCounter / 100));
                                        }
                                    }
                                    percentOfPvForThisLv = (double)tmpClientPartitionSizeLvBlk /
                                                           volumeGroup.AgreedPvSizeBlk;
                                }
                            }

                            if (logicalVolumeHelper.MinSizeBlk > tmpClientPartitionSizeLvBlk)
                            {
                                isError = true;
                                break;
                            }

                            clientPartitionLv.Size = tmpClientPartitionSizeLvBlk;
                            totalPvPercentage     += percentOfPvForThisLv;
                            LogicalVolumes.Add(clientPartitionLv);
                        }

                        //Could not determine a partition layout that works with this hard drive
                        if (isError && percentCounter > 99)
                        {
                            return(false);
                        }

                        //This partition size doesn't work, continuation of break from earlier
                        if (isError)
                        {
                            continue;
                        }

                        if (totalPvPercentage <= 1)
                        {
                            long totalAllocatedBlk     = 0;
                            var  dynamicPartitionCount = 0;
                            //If totalPercentage is too far below 1 try to increase size of available resizable partitions
                            if (totalPvPercentage < .95)
                            {
                                foreach (var lv in LogicalVolumes)
                                {
                                    totalAllocatedBlk += Convert.ToInt64(lv.Size);
                                    if (lv.SizeIsDynamic)
                                    {
                                        dynamicPartitionCount++;
                                    }
                                }
                                var totalUnallocated = volumeGroup.AgreedPvSizeBlk - totalAllocatedBlk;
                                if (dynamicPartitionCount > 0)
                                {
                                    foreach (var lv in LogicalVolumes.Where(lv => lv.SizeIsDynamic))
                                    {
                                        lv.Size = lv.Size + totalUnallocated / dynamicPartitionCount;
                                    }
                                }
                            }
                            singleLvVerified = true;
                        }

                        //Theoretically should never hit this, but added to prevent infinite loop
                        if (percentCounter > 100)
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Refreshes the connected status for all logical volumes in the file index.</summary>
 public void RefreshVolumeStatus()
 {
     LogicalVolumes.ForEach(x => x.RefreshStatus());
 }