예제 #1
0
        public void Dispose()
        {
            if (LogEvent != null)
            {
                LogEvent(this, new LogEventArgs(0, Severity.TRIVIA, "Disposing LinuxStorageDiscoverer ressources..."));
            }
            if (loopDevices != null && loopDevices.Count > 0)
            {
                LinuxLoopDeviceHelper lldh = new LinuxLoopDeviceHelper();
                foreach (FileSystem fs in this.layout.GetAllFileSystems(null))
                {
                    if (!lldh.Umount(fs.MountPoint))
                    {
                        if (LogEvent != null)
                        {
                            LogEvent(this, new LogEventArgs(0, Severity.NOTICE, "Couldn't umount FS '" + fs.MountPoint + "'"));
                        }
                    }
                    else
                    if (LogEvent != null)
                    {
                        LogEvent(this, new LogEventArgs(0, Severity.TRIVIA, "Unmounted '" + fs.MountPoint + "'"));
                    }
                }

                /*foreach(IDiskElement ide in this.layout.Entries)
                 *      try{
                 *              lldh.RemoveLoop(ide.Path);
                 *      }
                 *      catch(Exception e){
                 *              LogEvent(this, new LogEventArgs(0, Severity.INFO, "Couldn't remore loop device '"+ide.Path+"' : "+e.Message));
                 *
                 *      }*/
            }
        }
예제 #2
0
        private void FinishBuildDisksLinux()
        {
            // Maybe the returned layout is partial because disks are loops (proxied Linux VM backup...)
            List <string> loopNames = new List <string>();

            foreach (IDiskElement elt in layout.Entries)
            {
                if (elt is Disk && ((Disk)elt).Type == DiskType.Loop /*&& ((Disk)elt).Enabled*/)
                {
                    Disk disk = (Disk)elt;
                    loopH = new LinuxLoopDeviceHelper();
                    try{
                        string loopPath = loopH.GetLoop(disk.ProxiedPath, "");
                        Logger.Append(Severity.DEBUG, "Obtained loop device " + loopPath + " for fuse device " + disk.ProxiedPath);
                        disk.ProxiedPath = loopPath;
                        if (loopPath != null)
                        {
                            loopNames.Add(loopPath.Substring(loopPath.LastIndexOf("/") + 1));
                            Console.WriteLine(" #### Added loopPath  " + loopPath.Substring(loopPath.LastIndexOf("/")));
                        }
                    }
                    catch (Exception e) {
                        Logger.Append(Severity.ERROR, "Couldn't create loop device for disk '" + disk.ProxiedPath + "' : " + e.Message);
                    }

                    /*
                     * Logger.Append(Severity.DEBUG, "Disk '"+disk.ProxiedPath+"' got loop entry "+loopPath);
                     * // update disk proxied path, since we'll have to use instead of the original proxied path
                     * // wich is now useless for the rest of operations
                     * disk.ProxiedPath = loopPath;
                     *
                     *
                     * }
                     * else{
                     * Logger.Append(Severity.WARNING, "Disk '"+disk.ProxiedPath+"' could'nt got a loop device entry.");
                     * disk.Enabled = false;
                     * }*/
                }
            }

            //If we are asked to manage loop devices, call Linux discoverer  to the rescue
            // and replace actual layout by the one we got from it
            if (loopNames.Count > 0)
            {
                lsd           = new LinuxStorageDiscoverer();
                lsd.LogEvent += LogReceivedEvent;
                lsd.Initialize(loopNames, Path.Combine(Utilities.ConfigManager.GetValue("Storage.IndexPath"), "tmp"));
                StorageLayout fromLinuxDiscovererLayout = lsd.BuildStorageLayout();

                foreach (IDiskElement ldlEntry in fromLinuxDiscovererLayout.Entries)
                {
                    foreach (IDiskElement elt in layout.Entries)
                    {
                        if (!(elt is Disk) || !(ldlEntry is Disk))
                        {
                            continue;
                        }
                        Console.WriteLine("vmware disk path=" + elt.Path + ", proxiedpath=" + ((Disk)elt).ProxiedPath + ", linuxdisco path=" + ldlEntry.Path + ", linuxdisco proxiedpath=" + ((Disk)ldlEntry).ProxiedPath);
                        if (((Disk)elt).ProxiedPath == ((Disk)ldlEntry).Path)
                        {
                            foreach (IDiskElement newE in ldlEntry.Children)
                            {
                                elt.AddChild(newE);
                            }
                        }
                    }
                }
            }
            //disk.Children.AddRange(lsd.GetSysfsPartitions(disk.ProxiedPath, ""));


            // Now, we should have everything that is was possible to gather about disk layout.
            // Finish it by parsing MBR/bootmanager and compare partitions layouts
            foreach (IDiskElement elt in layout.Entries)
            {
                if (!(elt is Disk))
                {
                    continue;
                }
                Disk d = (Disk)elt;
                if (d.BlockStream == null)
                {
                    Logger.Append(Severity.ERROR, "No access to block device '" + d.Path + "' stream, cannot finish building disk layout");
                    continue;
                }
                d.MbrBytes = new byte[512];
                d.BlockStream.Read(d.MbrBytes, 0, 512);
                MBR mbr = new MBR(d.MbrBytes);
                d.Signature = mbr.DiskSignature;

                /*if(d.TreatAsLoop)
                 *      disk.Children.AddRange(lsd.GetSysfsPartitions(disk.ProxiedPath, ""));
                 * else
                 *      disk.Children.AddRange(lsd.GetSysfsPartitions(disk.Path, ""));*/
                foreach (Partition p in GetPartitionsFromMBR(d))
                {
                    bool ofound = false;
                    foreach (IDiskElement dskE in d.Children)
                    {
                        //Console.WriteLine ("     EEEEEEEEEEEE  current elt is "+dskE.ToString());
                        if (!(dskE is Partition))
                        {
                            continue;
                        }

                        Partition tempP = (Partition)dskE;
                        //Console.WriteLine ("     EEEEEEEEEEEE MBR says : "+p.ToString());
                        //Console.WriteLine ("     EEEEEEEEEEEEinside layout.children.Children : "+tempP.ToString());
                        if (tempP.Offset != p.Offset)
                        {
                            continue;
                        }
                        ofound = true;
                        if (dskE.Size == 0)
                        {
                            Logger.Append(Severity.TRIVIA, "added 'size' information to partition with offset " + dskE.Offset);
                            dskE.Size = p.Size;
                        }
                        if (dskE.Size != p.Size)
                        {
                            Logger.Append(Severity.WARNING, "Mismatch in 'size' information between discoverer and MBR for partition with offset " + dskE.Offset
                                          + ", trusting MBR");
                            dskE.Size = p.Size;
                        }
                        tempP.Type = p.Type;
                        break;
                    }
                    if (!ofound)                     // MBR partition undected by storage discoverer
                    {
                        Logger.Append(Severity.TRIVIA, "Adding new partition from MBR, previously undiscovered. Partition is " + p.ToString());
                        elt.AddChild(p);
                    }
                }
            }
        }