コード例 #1
0
        public void Disconnect(XenAPI.Session xenSession)
        {
            try
            {
                if (iDisk != null)
                {
                    iDisk.Dispose();
                }
                iDisk = null;
            }
            catch (Exception exn)
            {
                log.Debug("Failed to dispose iDisk. Continuing.", exn);
            }

            try
            {
                if (_iscsisession != null)
                {
                    _iscsisession.Dispose();
                }
                _iscsisession = null;
            }
            catch (Exception exn)
            {
                log.Debug("Failed to dispose iScsiSession. Continuing.", exn);
            }

            StopiScsiTarget(xenSession);
        }
コード例 #2
0
 public void Disconnect(XenAPI.Session xenSession)
 {
     try
     {
         if (iDisk != null)
         {
             iDisk.Dispose();
         }
         iDisk = null;
     }
     catch (Exception exn)
     {
         Log.Warning("Exception when disposing iDisk", exn);
     }
     try
     {
         if (_iscsisession != null)
         {
             _iscsisession.Dispose();
         }
         _iscsisession = null;
     }
     catch (Exception exn)
     {
         Log.Warning("Exception when disposing iscsisession", exn);
     }
     StopiScsiTarget(xenSession);
 }
コード例 #3
0
 private void InitializeiSCSI()
 {
     _iscsisession = null;
     _newscsi      = false;
     _pluginrecord = "";
     _bytescopied  = 0;
     _bytestotal   = 0;
     _buffer       = new byte[2 * MB];
 }
コード例 #4
0
        public DiskStream Connect(XenAPI.Session xenSession, string vdiuuid, bool read_only)
        {
            StartiScsiTarget(xenSession, vdiuuid, read_only);

            string ipaddress, port, targetGroupTag, username, password;

            if (!TryParsePluginRecordFor(_pluginrecord, "ip", out ipaddress))
            {
                throw new Exception(Messages.ISCSI_ERROR_NO_IPADDRESS);
            }

            TryParsePluginRecordFor(_pluginrecord, "port", out port);
            int ipport = Convert.ToInt32(port);

            TryParsePluginRecordFor(_pluginrecord, "isci_lun", out targetGroupTag);
            TryParsePluginRecordFor(_pluginrecord, "username", out username);
            TryParsePluginRecordFor(_pluginrecord, "password", out password);

            Initiator initiator = new Initiator();

            if (username != null && password != null)
            {
                initiator.SetCredentials(username, password);
            }

            int  iSCSIConnectRetry = Properties.Settings.Default.iSCSIConnectRetry;
            bool iSCSIConnected    = false;

            while (!iSCSIConnected && iSCSIConnectRetry > 0)
            {
                if (Cancel)
                {
                    throw new OperationCanceledException();
                }

                try
                {
                    log.DebugFormat("Connecting virtual disk {0}... ", vdiuuid);
                    TargetAddress ta      = new TargetAddress(ipaddress, ipport, targetGroupTag);
                    TargetInfo[]  targets = initiator.GetTargets(ta);
                    log.InfoFormat("iSCSI.Connect found {0} targets, connecting to: {1}", targets.Length, targets[0].Name);
                    _iscsisession  = initiator.ConnectTo(targets[0]);
                    iSCSIConnected = true;
                }
                catch (Exception ex)
                {
                    log.Error($"Failed to connect to VDI {vdiuuid} over iSCSI.", ex);
                    Thread.Sleep(new TimeSpan(0, 0, 5));
                    iSCSIConnectRetry--;
                }
            }

            if (!iSCSIConnected)
            {
                throw new Exception(Messages.ISCSI_ERROR);
            }

            long lun = 0;

            try
            {
                LunInfo[] luns = _iscsisession.GetLuns();
                if (_newscsi)
                {
                    string idx;
                    TryParsePluginRecordFor(_pluginrecord, "iscsi_lun", out idx);
                    long lunIdx = Convert.ToInt32(idx);
                    lun = luns[lunIdx].Lun;
                }

                log.InfoFormat("iSCSI.Connect found {0} luns, looking for block storage.", luns.Length);

                foreach (LunInfo iLun in luns)
                {
                    if (iLun.DeviceType == LunClass.BlockStorage)
                    {
                        if (_newscsi && iLun.Lun == lun)
                        {
                            break;
                        }

                        lun = iLun.Lun;
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("Could not determine LUN", e);
                throw;
            }

            log.InfoFormat("iSCSI.Connect, found on lun: {0}", lun);

            try
            {
                iDisk = _iscsisession.OpenDisk(lun);
                // Use our own DiskStream class to workaround a bug in DiscUtils.DiskStream.
                return(new DiskStream(_iscsisession, lun, (read_only ? FileAccess.Read : FileAccess.ReadWrite)));
            }
            catch (Exception ex)
            {
                log.Error("Failed to open virtual disk.", ex);
                throw new Exception(Messages.ISCSI_ERROR_CANNOT_OPEN_DISK, ex);
            }
        }
コード例 #5
0
        public XenOvfTransport.DiskStream Connect(XenAPI.Session xenSession, string vdiuuid, bool read_only)
        {
            int  iSCSIConnectRetry = Properties.Settings.Default.iSCSIConnectRetry;
            bool iSCSIConnected    = false;

            StartiScsiTarget(xenSession, vdiuuid, read_only);
            string ipaddress      = ParsePluginRecordFor("ip");
            int    ipport         = Convert.ToInt32(ParsePluginRecordFor("port"));
            string targetGroupTag = ParsePluginRecordFor("isci_lun");

            if (ipaddress == null)
            {
                throw new NullReferenceException(Messages.ISCSI_ERROR_NO_IPADDRESS);
            }
            string username = ParsePluginRecordFor("username");
            string password = ParsePluginRecordFor("password");

            Initiator initiator = new Initiator();

            if (username != null && password != null)
            {
                initiator.SetCredentials(username, password);
            }
            while (!iSCSIConnected && iSCSIConnectRetry > 0)
            {
                if (Cancel)
                {
                    throw new OperationCanceledException();
                }

                try
                {
                    Log.Debug(Messages.FILES_TRANSPORT_SETUP, vdiuuid);
                    TargetAddress ta      = new TargetAddress(ipaddress, ipport, targetGroupTag);
                    TargetInfo[]  targets = initiator.GetTargets(ta);
                    Log.Info("iSCSI.Connect found {0} targets, connecting to: {1}", targets.Length, targets[0].Name);
                    _iscsisession  = initiator.ConnectTo(targets[0]);
                    iSCSIConnected = true;
                }
                catch (Exception ex)
                {
                    Log.Error("{0} {1}", Messages.ISCSI_ERROR, ex.Message);
                    Thread.Sleep(new TimeSpan(0, 0, 5));
                    iSCSIConnectRetry--;
                }
            }

            if (!iSCSIConnected)
            {
                throw new Exception(Messages.ISCSI_ERROR);
            }

            long lun = 0;

            try
            {
                LunInfo[] luns = _iscsisession.GetLuns();
                if (_newscsi)
                {
                    long lunIdx = Convert.ToInt32(ParsePluginRecordFor("iscsi_lun"));
                    lun = luns[lunIdx].Lun;
                }
                Log.Info("iSCSI.Connect found {0} luns, looking for block storage.", luns.Length);
                foreach (LunInfo iLun in luns)
                {
                    if (iLun.DeviceType == LunClass.BlockStorage)
                    {
                        if (_newscsi && iLun.Lun == lun)
                        {
                            break;
                        }
                        lun = iLun.Lun;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("Could not determin LUN");
                throw;
            }
            Log.Info("iSCSI.Connect, found on lun: {0}", lun);
            try
            {
                iDisk = _iscsisession.OpenDisk(lun);
                // Use our own DiskStream class to workaround a bug in DiscUtils.DiskStream.
                return(new XenOvfTransport.DiskStream(_iscsisession, lun, (read_only ? FileAccess.Read : FileAccess.ReadWrite)));
            }
            catch (Exception ex)
            {
                Log.Error("{0} {1}", Messages.ISCSI_ERROR_CANNOT_OPEN_DISK, ex.Message);
                throw new Exception(Messages.ISCSI_ERROR_CANNOT_OPEN_DISK, ex);
            }
        }
コード例 #6
0
ファイル: iSCSI.cs プロジェクト: ChrisH4rding/xenadmin
 private void InitializeiSCSI()
 {
     _iscsisession = null;
     _newscsi = false;
     _pluginrecord = "";
     _bytescopied = 0;
     _bytestotal = 0;
     _buffer = new byte[2 * MB];
 }
コード例 #7
0
ファイル: iSCSI.cs プロジェクト: ChrisH4rding/xenadmin
 public void Disconnect(XenAPI.Session xenSession)
 {
     try
     {
         if (iDisk != null)
             iDisk.Dispose();
         iDisk = null;
     }
     catch (Exception exn)
     {
         Log.Warning("Exception when disposing iDisk", exn);
     }
     try
     {
         if (_iscsisession != null)
             _iscsisession.Dispose();
         _iscsisession = null;
     }
     catch (Exception exn)
     {
         Log.Warning("Exception when disposing iscsisession", exn);
     }
     StopiScsiTarget(xenSession);
 }
コード例 #8
0
ファイル: iSCSI.cs プロジェクト: ChrisH4rding/xenadmin
        public XenOvfTransport.DiskStream Connect(XenAPI.Session xenSession, string vdiuuid, bool read_only)
        {
            int iSCSIConnectRetry = Properties.Settings.Default.iSCSIConnectRetry;
            bool iSCSIConnected = false;
            StartiScsiTarget(xenSession, vdiuuid, read_only);
            string ipaddress = ParsePluginRecordFor("ip");
            int ipport = Convert.ToInt32(ParsePluginRecordFor("port"));
            string targetGroupTag = ParsePluginRecordFor("isci_lun");
            if (ipaddress == null)
            {
                throw new NullReferenceException(Messages.ISCSI_ERROR_NO_IPADDRESS);
            }
            string username = ParsePluginRecordFor("username");
            string password = ParsePluginRecordFor("password");

            Initiator initiator = new Initiator();
            if (username != null && password != null)
                initiator.SetCredentials(username, password);
            while (!iSCSIConnected && iSCSIConnectRetry > 0)
            {
                if (Cancel)
                    throw new OperationCanceledException();

                try
                {
                    Log.Debug(Messages.FILES_TRANSPORT_SETUP, vdiuuid);
                    TargetAddress ta = new TargetAddress(ipaddress, ipport, targetGroupTag);
                    TargetInfo[] targets = initiator.GetTargets(ta);
                    Log.Info("iSCSI.Connect found {0} targets, connecting to: {1}", targets.Length, targets[0].Name);
                    _iscsisession = initiator.ConnectTo(targets[0]);
                    iSCSIConnected = true;
                }
                catch (Exception ex)
                {
                    Log.Error("{0} {1}", Messages.ISCSI_ERROR, ex.Message);
                    Thread.Sleep(new TimeSpan(0, 0, 5));
                    iSCSIConnectRetry--;
                }
            }

            if (!iSCSIConnected)
            {
                throw new Exception(Messages.ISCSI_ERROR);
            }

            long lun = 0;
            try
            {
                LunInfo[] luns = _iscsisession.GetLuns();
                if (_newscsi)
                {
                    long lunIdx = Convert.ToInt32(ParsePluginRecordFor("iscsi_lun"));
                    lun = luns[lunIdx].Lun;
                }
                Log.Info("iSCSI.Connect found {0} luns, looking for block storage.", luns.Length);
                foreach (LunInfo iLun in luns)
                {
                    if (iLun.DeviceType == LunClass.BlockStorage)
                    {
                        if (_newscsi && iLun.Lun == lun) { break; }
                        lun = iLun.Lun;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                Log.Error("Could not determin LUN");
                throw;
            }
            Log.Info("iSCSI.Connect, found on lun: {0}", lun);
            try
            {
                iDisk = _iscsisession.OpenDisk(lun);
                // Use our own DiskStream class to workaround a bug in DiscUtils.DiskStream.
                return new XenOvfTransport.DiskStream(_iscsisession, lun, (read_only ? FileAccess.Read : FileAccess.ReadWrite));
            }
            catch (Exception ex)
            {
                Log.Error("{0} {1}", Messages.ISCSI_ERROR_CANNOT_OPEN_DISK, ex.Message);
                throw new Exception(Messages.ISCSI_ERROR_CANNOT_OPEN_DISK, ex);
            }
        }
コード例 #9
0
ファイル: iSCSI.cs プロジェクト: BATYD-Turksat/xenadmin
        public void Disconnect(XenAPI.Session xenSession)
        {
            try
            {
                if (iDisk != null)
                    iDisk.Dispose();
                iDisk = null;
            }
            catch (Exception exn)
            {
                log.DebugFormat("Failed to dispose iDisk: {0}. Continuing.", exn);
            }

            try
            {
                if (_iscsisession != null)
                    _iscsisession.Dispose();
                _iscsisession = null;
            }
            catch (Exception exn)
            {
                log.DebugFormat("Failed to dispose iScsiSession: {0}. Continuing.", exn);
            }

            StopiScsiTarget(xenSession);
        }