Exemple #1
0
        /// <summary>
        /// Mounts the persistent disk.
        /// </summary>
        /// <param name="diskId">Id of the disk.</param>
        public static void MountPersistentDisk(int diskId)
        {
            string storeMountPoint = Path.Combine(BaseMessage.BaseDir, "store");
            string mountpoint;

            if (DiskUtil.IsMountPoint(storeMountPoint))
            {
                Logger.Info("Mounting persistent disk store migration target");
                mountpoint = Path.Combine(BaseMessage.BaseDir, "store_migraton_target");
            }
            else
            {
                Logger.Info("Mounting persistent disk store");
                mountpoint = storeMountPoint;
            }

            if (!Directory.Exists(mountpoint))
            {
                Directory.CreateDirectory(mountpoint);
            }

            Logger.Info(String.Format(CultureInfo.InvariantCulture, "Mount Partition {0} {1}", diskId, mountpoint));

            int returnCode = DiskUtil.MountPartition(diskId, mountpoint);

            if (returnCode != 0)
            {
                throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Failed mount disk {0} on {1}. Exit code: {2}", diskId, mountpoint, returnCode));
            }
        }
Exemple #2
0
        /// <summary>
        /// Processes the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        public object Process(dynamic args)
        {
            List <string> diskInfo = new List <string>();

            Logger.Info("Processing list disk");
            dynamic settings = Config.Settings;
            dynamic cids;

            cids = settings["disks"]["persistent"] ?? new string[] {};

            foreach (var cid in cids)
            {
                int diskId = int.Parse(Config.Platform.LookupDiskByCid(cid.Name));
                Logger.Info("Found disk with Id :" + diskId);

                if (!(DiskUtil.MountEntry(diskId) == null))
                {
                    diskInfo.Add(cid.Name);
                }
            }

            JArray obj = JArray.FromObject(diskInfo);

            return(obj);
        }
 public static bool CheckMountPoints()
 {
     if (DiskUtil.IsMountPoint(BaseMessage.StorePath) && DiskUtil.IsMountPoint(BaseMessage.StoreMigrationTarget))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
        /// <summary>
        /// Mounts the store.
        /// </summary>
        /// <param name="cid">The cid.</param>
        public static void MountStore(string cid)
        {
            int diskId = int.Parse(Config.Platform.LookupDiskByCid(cid), CultureInfo.InvariantCulture);

            Logger.Info(String.Format(CultureInfo.InvariantCulture, "Mount Partition {0} {1}", diskId, BaseMessage.StorePath));

            int returnCode = DiskUtil.MountPartition(diskId, BaseMessage.StorePath);

            if (returnCode != 0)
            {
                throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Failed mount disk {0} on {1}. Exit code: {2}", diskId, BaseMessage.StorePath, returnCode));
            }
        }
        public void Migrate(dynamic args)
        {
            Logger.Info(String.Format("MigrateDisk:{0}", args));
            oldCid = args[0].ToString();
            newCid = args[1].ToString();
            DiskUtil.UnmountGuard(BaseMessage.StorePath);
            MountStoreReadOnly(oldCid);

            if (CheckMountPoints())
            {
                Logger.Info("Copy data from old to new store disk");

                ProcessStartInfo info = new ProcessStartInfo();
                info.FileName = "robocopy";
                string systemVolumeInfo = "\"" + Path.Combine(BaseMessage.StorePath, "System Volume Information") + "\"";
                string recicleBinPath   = "\"" + Path.Combine(BaseMessage.StorePath, "$Recycle.Bin") + "\"";
                info.Arguments = String.Format(CultureInfo.InvariantCulture, "{0} {1} /MIR /R:1 /W:1 /COPYALL /XD {2} {3}", BaseMessage.StorePath, BaseMessage.StoreMigrationTarget, systemVolumeInfo, recicleBinPath);
                info.RedirectStandardOutput = true;
                info.UseShellExecute        = false;

                Process p = new Process();
                try
                {
                    p.StartInfo = info;
                    p.Start();
                    p.WaitForExit();
                    Logger.Debug(p.StandardOutput.ReadToEnd());
                    if (p.ExitCode > 2)
                    {
                        throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Failed to copy data from old to new store disk with exit code {0}", p.ExitCode.ToString()));
                    }
                }
                finally
                {
                    p.Dispose();
                }
            }

            DiskUtil.UnmountGuard(BaseMessage.StorePath);
            DiskUtil.UnmountGuard(BaseMessage.StoreMigrationTarget);

            MountStore(newCid);
        }
Exemple #6
0
        /// <summary>
        /// Processes the specified args.
        /// </summary>
        /// <param name="args">The args.</param>
        /// <returns></returns>
        public object Process(dynamic args)
        {
            Logger.Info("Processing unmount disk :" + args.ToString());
            string cid = args[0].Value.ToString();

            int    diskId     = int.Parse(Config.Platform.LookupDiskByCid(cid), CultureInfo.InvariantCulture);
            string mountEntry = DiskUtil.MountEntry(diskId);

            if (mountEntry != null)
            {
                DiskUtil.UnmountGuard(mountEntry);
                UnmountMessage unmountMessage = new UnmountMessage();
                unmountMessage.Message = string.Format(CultureInfo.InvariantCulture, "done unmount {0} on {1}", mountEntry, diskId);
                return(unmountMessage);
            }
            else
            {
                UnmountMessage unmountMessage = new UnmountMessage();
                unmountMessage.Message = string.Format(CultureInfo.InvariantCulture, "Unknown mount for partition {0}", diskId.ToString(CultureInfo.InvariantCulture));
                return(unmountMessage);
            }
        }
Exemple #7
0
        /// <summary>
        /// Setups the disk.
        /// </summary>
        public object SetupDisk()
        {
            int diskId = int.Parse(Config.Platform.LookupDiskByCid(cid), CultureInfo.InvariantCulture);

            Logger.Info("Setup disk settings: " + BaseMessage.Settings.ToString());

            if (!DiskUtil.DiskHasPartition(diskId))
            {
                Logger.Info("Found blank disk " + diskId.ToString(CultureInfo.InvariantCulture));
                int returnCode = DiskUtil.CreatePrimaryPartition(diskId, "store");
                if (returnCode != 0)
                {
                    throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Unable to create partition. Exit code: {0}", returnCode));
                }
            }
            else
            {
                Logger.Info(String.Format(CultureInfo.InvariantCulture, "Disk has partition"));
            }

            MountPersistentDisk(diskId);

            return(new object());
        }
        private static void MountStoreReadOnly(string cid)
        {
            int diskId    = int.Parse(Config.Platform.LookupDiskByCid(cid), CultureInfo.InvariantCulture);
            int diskIndex = DiskUtil.GetDiskIndexForDiskId(diskId);

            Logger.Info("Mounting {0} {1}", cid, BaseMessage.StorePath);

            int returnCode = -2;

            string script = String.Format(CultureInfo.InvariantCulture, @"SELECT Disk {0}
ATTRIBUTE DISK SET READONLY
SELECT Disk {0}
ONLINE DISK NOERR
SELECT Disk {0}
SELECT PARTITION 1
REMOVE ALL NOERR
ASSIGN MOUNT={1}
EXIT", diskIndex, BaseMessage.StorePath);

            string fileName = Path.GetTempFileName();

            File.WriteAllText(fileName, script);

            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName  = "diskpart.exe";
            info.Arguments = String.Format(CultureInfo.InvariantCulture, "/s {0}", fileName);
            info.RedirectStandardOutput = true;
            info.UseShellExecute        = false;

            int retryCount = 10;

            while (retryCount > 0)
            {
                Process p = new Process();
                try
                {
                    p.StartInfo = info;
                    p.Start();
                    p.WaitForExit(60000);
                    if (!p.HasExited)
                    {
                        p.Kill();
                        returnCode = -1;
                    }
                    else
                    {
                        if (p.ExitCode != 0)
                        {
                            retryCount--;
                            Thread.Sleep(1000);
                            continue;
                        }
                        else
                        {
                            Logger.Warning(p.StandardOutput.ReadToEnd());
                            returnCode = p.ExitCode;
                            break;
                        }
                    }
                }
                finally
                {
                    p.Dispose();
                }
            }

            if (returnCode != 0)
            {
                throw new MessageHandlerException(String.Format(CultureInfo.InvariantCulture, "Failed mount disk {0} on {1}. Exit code: {2}", diskIndex, BaseMessage.StorePath, returnCode));
            }
        }