Пример #1
0
        static void Main(string[] args)
        {
            //args = new string[] { @"C:\VPC\SmartOs\" };
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ZfsSharp.exe <a directory containing VHD, VDI, or ZFS files>");
                return;
            }

            using (var zfs = new Zfs(args[0]))
            {
                foreach (var ds in zfs.GetDataSets())
                {
                    Console.WriteLine("{0}: {1}", ds.Type, ds.Name);

                    if (ds.Type != DataSetType.ZFS)
                        continue;

                    var zpl = ds.GetHeadZfs();
                    printContent(ds.Name, zpl.Root);

                    if (ds.Name == "zones/var")
                        Console.WriteLine(Encoding.ASCII.GetString(zpl.GetFileContents(@"/svc/log/svc.startd.log")));

                    foreach (var snap in ds.GetZfsSnapShots())
                    {
                        var snapName = ds.Name + "@" + snap.Key;
                        Console.WriteLine(snapName);
                        printContent(snapName, snap.Value.Root);
                    }
                }
            }

            Console.WriteLine();
        }
Пример #2
0
        public ZfsDokan(Zfs zfs)
        {
            foreach (var ds in zfs.GetAllDataSets().Where(ds => ds.Type == DataSetType.ZFS && ds.Name.Contains("var")))
            {
                loadItems(ds.GetHeadZfs().Root);

                break;
            }
        }
Пример #3
0
        public ZfsDokan(Zfs zfs)
        {
            foreach (var ds in zfs.GetDataSets().Where(ds => ds.Type == DataSetType.ZFS && ds.Name.Contains("var")))
            {

                loadItems(ds.GetHeadZfs().Root);

                break;
            }
        }
Пример #4
0
        private static void BenchmarkFileReading(Zfs zfs)
        {
            var varzpl = zfs.GetDataSets().Where(k => k.Name == "zones/var").Select(ds => ds.GetHeadZfs()).Single();
            Stopwatch st = Stopwatch.StartNew();
            for (int i = 0; i < 1000; i++)
            {
                varzpl.GetFileContents(@"/svc/log/svc.startd.log");
            }
            st.Stop();

            Console.WriteLine(st.Elapsed.TotalSeconds);
        }
Пример #5
0
        private static void BenchmarkFileReading(Zfs zfs)
        {
            var       varzpl = zfs.GetAllDataSets().Where(k => k.Name == "zones/var").Select(ds => ds.GetHeadZfs()).Single();
            Stopwatch st     = Stopwatch.StartNew();

            for (int i = 0; i < 1000; i++)
            {
                varzpl.GetFileContents(@"/svc/log/svc.startd.log");
            }
            st.Stop();

            Console.WriteLine(st.Elapsed.TotalSeconds);
        }
Пример #6
0
        static void Main(string[] args)
        {
            //args = new string[] { @"C:\VPC\SmartOs\" };
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ZfsSharp.exe <a directory containing VHD, VDI, or ZFS files>");
                return;
            }

            using (var zfs = new Zfs(args[0]))
            {
                DokanOptions opt = new DokanOptions();
                opt.MountPoint  = "z:\\";
                opt.DebugMode   = true;
                opt.UseStdErr   = true;
                opt.VolumeLabel = "ZFS";
                int status = DokanNet.DokanMain(opt, new ZfsDokan(zfs));
                switch (status)
                {
                case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                    Console.WriteLine("Drvie letter error");
                    break;

                case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                    Console.WriteLine("Driver install error");
                    break;

                case DokanNet.DOKAN_MOUNT_ERROR:
                    Console.WriteLine("Mount error");
                    break;

                case DokanNet.DOKAN_START_ERROR:
                    Console.WriteLine("Start error");
                    break;

                case DokanNet.DOKAN_ERROR:
                    Console.WriteLine("Unknown error");
                    break;

                case DokanNet.DOKAN_SUCCESS:
                    Console.WriteLine("Success");
                    break;

                default:
                    Console.WriteLine("Unknown status: {0}", status);
                    break;
                }
            }
        }
Пример #7
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ZfsSharp.exe <a directory containing VHD, VHDX, VDI, or ZFS files>");
                return;
            }

            var sw = Stopwatch.StartNew();

            sw.Stop();

            using (var zfs = new Zfs(args[0]))
            {
                sw = Stopwatch.StartNew();
                foreach (var ds in zfs.GetAllDataSets())
                {
                    Console.WriteLine("{0}: {1}", ds.Type, ds.Name);

                    if (ds.Type != DataSetType.ZFS)
                    {
                        continue;
                    }

                    var zpl = ds.GetHeadZfs();
                    printContent(ds.Name, zpl.Root);

                    if (ds.Name == "zones/var")
                    {
                        Console.WriteLine(Encoding.ASCII.GetString(zpl.GetFileContents(@"/svc/log/svc.startd.log")));
                    }

                    foreach (var snap in ds.GetZfsSnapShots())
                    {
                        var snapName = ds.Name + "@" + snap.Key;
                        Console.WriteLine(snapName);
                        printContent(snapName, snap.Value.Root);
                    }
                }
                sw.Stop();
                Console.WriteLine("time: " + sw.ElapsedMilliseconds);
            }

            Console.WriteLine();
        }
Пример #8
0
        static void Main(string[] args)
        {
            //args = new string[] { @"C:\VPC\SmartOs\" };
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ZfsSharp.exe <a directory containing VHD, VDI, or ZFS files>");
                return;
            }

            using (var zfs = new Zfs(args[0]))
            {
                DokanOptions opt = new DokanOptions();
                opt.MountPoint = "z:\\";
                opt.DebugMode = true;
                opt.UseStdErr = true;
                opt.VolumeLabel = "ZFS";
                int status = DokanNet.DokanMain(opt, new ZfsDokan(zfs));
                switch (status)
                {
                    case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                        Console.WriteLine("Drvie letter error");
                        break;
                    case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                        Console.WriteLine("Driver install error");
                        break;
                    case DokanNet.DOKAN_MOUNT_ERROR:
                        Console.WriteLine("Mount error");
                        break;
                    case DokanNet.DOKAN_START_ERROR:
                        Console.WriteLine("Start error");
                        break;
                    case DokanNet.DOKAN_ERROR:
                        Console.WriteLine("Unknown error");
                        break;
                    case DokanNet.DOKAN_SUCCESS:
                        Console.WriteLine("Success");
                        break;
                    default:
                        Console.WriteLine("Unknown status: {0}", status);
                        break;

                }
            }
        }
Пример #9
0
        int Run(string[] args)
        {
            if (args.Length < 2)
            {
                Usage();
                return(1);
            }

            string zfsDiskDir = args[0];
            string targetDir  = args[1];

            if (!(Directory.Exists(zfsDiskDir) || File.Exists(zfsDiskDir)) || !Directory.Exists(targetDir))
            {
                Console.WriteLine("Both directories must already exist.");
                Console.WriteLine();
                Usage();
                return(1);
            }

            if (Compatibility.Status != CompatibilityStatus.Supported)
            {
                Console.WriteLine("ProjectedFS is not supported: " + Compatibility.Status);
                return(1);
            }

            using (mZfs = new Zfs(zfsDiskDir))
            {
                populateDatasets("", mZfs.GetRootDataset());
                using (mProjFs = new ProjectedFileSystem(targetDir, this))
                {
                    Console.WriteLine("Start virtualizing in " + targetDir);
                    Console.WriteLine("Press enter to exit.");
                    Console.ReadLine();
                }
            }

            return(0);
        }
Пример #10
0
        public AntdZfsModule()
        {
            Get["/zfs"] = x => {
                var zpool   = new Zpool();
                var zfsSnap = new ZfsSnap();
                var zfs     = new Zfs();
                var disks   = new Disks();

                var model = new PageZfsModel {
                    ZpoolList    = zpool.List(),
                    ZfsList      = zfs.List(),
                    ZfsSnap      = zfsSnap.List(),
                    ZpoolHistory = zpool.History(),
                    DisksList    = disks.GetList().Where(_ => _.Type == "disk" && string.IsNullOrEmpty(_.Mountpoint))
                };
                return(JsonConvert.SerializeObject(model));
            };

            //todo
            //Get["/zfs/cron"] = x => {
            //    var list = _timerRepository.GetAll();
            //    return Response.AsJson(list);
            //};

            Post["/zfs/snap"] = x => {
                string pool     = Request.Form.Pool;
                string interval = Request.Form.Interval;
                if (string.IsNullOrEmpty(pool) || string.IsNullOrEmpty(interval))
                {
                    return(HttpStatusCode.InternalServerError);
                }
                _timers.Create(pool + "snap", interval, $"/sbin/zfs snap -r {pool}@${{TTDATE}}");
                return(HttpStatusCode.OK);
            };

            //Post["/zfs/snap/disable"] = x => {
            //    string guid = Request.Form.Guid;
            //    var tt = _timerRepository.GetByGuid(guid);
            //    if(tt == null)
            //        return HttpStatusCode.InternalServerError;
            //    _timers.Disable(tt.Alias);
            //    return HttpStatusCode.OK;
            //};

            Post["/zpool/create"] = x => {
                string altroot  = Request.Form.Altroot;
                string poolname = Request.Form.Name;
                string pooltype = Request.Form.Type;
                string disk     = Request.Form.Disk;
                if (string.IsNullOrEmpty(altroot) || string.IsNullOrEmpty(poolname) || string.IsNullOrEmpty(pooltype) || string.IsNullOrEmpty(disk))
                {
                    return(HttpStatusCode.BadRequest);
                }
                ConsoleLogger.Log($"[zpool] create => altroot:{altroot} poolname:{poolname} pooltype:{pooltype} disk:{disk} ");
                _launcher.Launch("zpool-create", new Dictionary <string, string> {
                    { "$pool_altroot", altroot },
                    { "$pool_name", poolname },
                    { "$pool_type", poolname },
                    { "$disk", disk }
                });
                return(HttpStatusCode.OK);
            };

            Post["/zfs/create"] = x => {
                string altroot     = Request.Form.Altroot;
                string poolname    = Request.Form.Name;
                string datasetname = Request.Form.Dataset;
                if (string.IsNullOrEmpty(altroot) || string.IsNullOrEmpty(poolname) || string.IsNullOrEmpty(datasetname))
                {
                    return(HttpStatusCode.BadRequest);
                }
                _launcher.Launch("zfs-create", new Dictionary <string, string> {
                    { "$pool_altroot", altroot },
                    { "$pool_name", poolname },
                    { "$dataset_name", datasetname }
                });
                return(HttpStatusCode.OK);
            };
        }
Пример #11
0
        /// <summary>
        /// Ottiene un Master valorizzato coi valori ottenuti direttamente dal sistema operativo
        /// Potrebbe non corrispondere al Master salvato
        /// Viene utilizzato per ottenere le differenze tra i parametri salvati e quelli effettivamente applicati
        /// </summary>
        /// <returns></returns>
        public static MachineStatus GetRunning()
        {
            //var STOPWATCH = new System.Diagnostics.Stopwatch();
            //STOPWATCH.Start();
            var master = new MachineStatus();

            master.Info.Uptime    = Uptime.Get();
            master.Info.CpuInfo   = CpuInfo.Get();
            master.Info.MemInfo   = MemInfo.Get();
            master.Info.Free      = Free.Get();
            master.Info.Losetup   = Losetup.Get();
            master.Info.DiskUsage = DiskUsage.Get();
            master.Info.Versions  = Versioning.Get();

            master.Host     = Hostnamectl.Get();
            master.TimeDate = new TimeDate()
            {
                Timezone = Timedatectl.Get().Timezone
            };
            master.Boot = new Boot();
            var modules     = Mod.Get();
            var bootModules = new SystemModule[modules.Length];

            for (var i = 0; i < modules.Length; i++)
            {
                bootModules[i] = new SystemModule()
                {
                    Module = modules[i].Module, Active = true
                };
            }
            master.Boot.Modules           = bootModules;
            master.Boot.Services          = cmds.Systemctl.GetAll();
            master.Boot.Parameters        = Sysctl.Get();
            master.Users.SystemUsers      = Passwd.Get();
            master.Users.ApplicativeUsers = new ApplicativeUser[] { new ApplicativeUser()
                                                                    {
                                                                        Active = true, Type = AuthenticationType.simple, Id = "master", Claims = new[] { SHA.Generate("master") }
                                                                    } };

            master.Network.KnownDns          = Dns.GetResolv();
            master.Network.KnownHosts        = Dns.GetHosts();
            master.Network.KnownNetworks     = Dns.GetNetworks();
            master.Network.Bridges           = Brctl.Get();
            master.Network.Bonds             = Bond.Get();
            master.Network.NetworkInterfaces = cmds.Network.Get();
            master.Network.RoutingTables     = Route.GetRoutingTable();
            master.Network.Routing           = Route.Get();

            master.NsSwitch = NS.Switch.Get();

            master.Storage.Mounts       = Mount.Get();
            master.Storage.Zpools       = Zpool.GetPools();
            master.Storage.ZfsDatasets  = Zfs.GetDatasets();
            master.Storage.ZfsSnapshots = Zfs.GetSnapshots();

            master.Services.Ssh.PublicKey     = Ssh.GetRootPublicKey();
            master.Services.Ssh.PrivateKey    = Ssh.GetRootPrivateKey();
            master.Services.Ssh.AuthorizedKey = Ssh.GetAuthorizedKey();

            master.Services.Virsh.Domains = Virsh.GetDomains();

            //ConsoleLogger.Log($"[conf] loaded running conf ({STOPWATCH.ElapsedMilliseconds})");
            return(master);
        }