Beispiel #1
0
        private void UpdateUI()
        {
            if (this.InvokeRequired)
            {
                this.Invoke((MethodInvoker)UpdateUI);
            }
            else
            {
                if (m_started)
                {
                    lblStatus.Text = String.Format("{0} Active Sessions", m_usageCounter.SessionCount);
                }

                if (listTargets.SelectedIndices.Count > 0)
                {
                    int         targetIndex = listTargets.SelectedIndices[0];
                    ISCSITarget target      = m_targets[targetIndex];
                    bool        isInUse     = m_usageCounter.IsTargetInUse(target.TargetName);
                    btnRemoveTarget.Enabled = !isInUse;
                }
                else
                {
                    btnRemoveTarget.Enabled = false;
                }
            }
        }
Beispiel #2
0
        public static ISCSITarget AddTarget(string targetName)
        {
            List <Disk> disks  = new List <Disk>();
            ISCSITarget target = new ISCSITarget(targetName, disks);

            m_targets.Add(target);
            return(target);
        }
Beispiel #3
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (!ISCSINameHelper.IsValidIQN(txtTargetIQN.Text))
     {
         MessageBox.Show("Target IQN is invalid", "Error");
         return;
     }
     m_target = new ISCSITarget(txtTargetIQN.Text, m_disks);
     m_targetNumber++;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Beispiel #4
0
        public static void AttachISCSIDisk(Disk disk, string defaultTargetName, KeyValuePairList <string, string> parameters)
        {
            if (VerifyParameters(parameters, "readonly", "target"))
            {
                bool isReadOnly = parameters.ContainsKey("readonly");
                disk.IsReadOnly |= isReadOnly;
                if (disk is DiskImage)
                {
                    bool isLocked = ((DiskImage)disk).ExclusiveLock();
                    if (!isLocked)
                    {
                        Console.WriteLine("Error: Cannot lock the disk image for exclusive access");
                        return;
                    }
                }

                ISCSITarget target     = null;
                string      targetName = defaultTargetName;
                if (parameters.ContainsKey("target"))
                {
                    string name = parameters.ValueOf("target");
                    if (IsValidISCSIName(name))
                    {
                        targetName = name;
                    }
                    else if (IsValidStorageTargetName(name))
                    {
                        targetName = DefaultTargetIQN + ":" + name;
                    }
                    else
                    {
                        Console.WriteLine("Invalid parameter.");
                        HelpAttach();
                    }
                }

                target = FindTarget(targetName);

                if (target == null)
                {
                    target = AddTarget(targetName);
                }

                target.Disks.Add(disk);
                Console.WriteLine("Disk added to target: {0}", target.TargetName);
            }
            else
            {
                HelpAttach();
            }
        }
 private void btnOK_Click(object sender, EventArgs e)
 {
     if (!ISCSINameHelper.IsValidIQN(txtTargetIQN.Text))
     {
         DialogResult dialogResult = MessageBox.Show("Target IQN is invalid, Continue?", "Warning", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.No)
         {
             return;
         }
     }
     m_target = new ISCSITarget(txtTargetIQN.Text, m_disks);
     m_targetNumber++;
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
Beispiel #6
0
 private void btnRemoveTarget_Click(object sender, EventArgs e)
 {
     if (listTargets.SelectedIndices.Count > 0)
     {
         int         targetIndex     = listTargets.SelectedIndices[0];
         ISCSITarget target          = m_targets[targetIndex];
         bool        isTargetRemoved = m_server.RemoveTarget(target.TargetName);
         if (!isTargetRemoved)
         {
             MessageBox.Show("Could not remove iSCSI target", "Error");
             return;
         }
         List <Disk> disks = ((SCSI.VirtualSCSITarget)target.SCSITarget).Disks;
         LockUtils.ReleaseDisks(disks);
         m_targets.RemoveAt(targetIndex);
         listTargets.Items.RemoveAt(targetIndex);
     }
 }
Beispiel #7
0
        private void btnAddTarget_Click(object sender, EventArgs e)
        {
            AddTargetForm addTarget       = new AddTargetForm();
            DialogResult  addTargetResult = addTarget.ShowDialog();

            if (addTargetResult == DialogResult.OK)
            {
                ISCSITarget target = addTarget.Target;
                ((SCSI.VirtualSCSITarget)target.SCSITarget).OnLogEntry += Program.OnLogEntry;
                target.OnAuthorizationRequest += new EventHandler <AuthorizationRequestArgs>(ISCSITarget_OnAuthorizationRequest);
                target.OnSessionTermination   += new EventHandler <SessionTerminationArgs>(ISCSITarget_OnSessionTermination);
                m_targets.Add(target);
                try
                {
                    m_server.AddTarget(target);
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message, "Error");
                    return;
                }
                listTargets.Items.Add(target.TargetName);
            }
        }
Beispiel #8
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

            this.Text           += " v" + version.ToString(3);
            m_server.OnLogEntry += Program.OnLogEntry;

            List <IPAddress> localIPs = GetHostIPAddresses();
            KeyValuePairList <string, IPAddress> list = new KeyValuePairList <string, IPAddress>();

            list.Add("Any", IPAddress.Any);
            foreach (IPAddress address in localIPs)
            {
                list.Add(address.ToString(), address);
            }
            comboIPAddress.DataSource    = list;
            comboIPAddress.DisplayMember = "Key";
            comboIPAddress.ValueMember   = "Value";
            lblStatus.Text = "Author: Tal Aloni ([email protected])";
#if Win32
            if (!SecurityHelper.IsAdministrator())
            {
                lblStatus.Text = "Some features require administrator privileges and have been disabled";
            }
#endif
            //test
            string[] args = Environment.GetCommandLineArgs();
            if (args.Length > 1)
            {
                //to do

                /*
                 * if (args[0].Equals("DiskImage", StringComparison.OrdinalIgnoreCase)) { m_disks.Add(DiskImage.GetDiskImage(args[2], false)); }
                 */
            }
            if (System.IO.File.Exists("config.xml") && args.Length <= 1)
            {
                XmlDocument XmlDocObj = new XmlDocument();
                XmlDocObj.Load("config.xml");
                XmlNode node            = XmlDocObj.SelectSingleNode("//target");
                string  targetname      = "";
                string  targetpath      = "";
                string  targettype      = "";
                string  targetsize      = "";
                string  targetdiskindex = "";
                if (node.Attributes["name"] != null)
                {
                    targetname = node.Attributes["name"].Value;
                }
                if (node.Attributes["path"] != null)
                {
                    targetpath = node.Attributes["path"].Value;
                }
                if (node.Attributes["class"] != null)
                {
                    targettype = node.Attributes["class"].Value;
                }
                if (node.Attributes["size"] != null)
                {
                    targetsize = node.Attributes["size"].Value;
                }
                if (node.Attributes["index"] != null)
                {
                    targetdiskindex = node.Attributes["index"].Value;
                }
                if (targetname != "")
                {
                    //
                    List <Disk> m_disks = new List <Disk>();
                    if (targettype.Equals("RAMDisk", StringComparison.OrdinalIgnoreCase))
                    {
                        m_disks.Add(new RAMDisk(int.Parse(targetsize) * 1024 * 1024));
                    }
                    if (targettype.Equals("DiskImage", StringComparison.OrdinalIgnoreCase))
                    {
                        m_disks.Add(DiskImage.GetDiskImage(targetpath, false));
                    }
                    if (targettype.Equals("createDiskImage", StringComparison.OrdinalIgnoreCase))
                    {
                        m_disks.Add(VirtualHardDisk.CreateFixedDisk(targetpath, long.Parse(targetsize) * 1024 * 1024));
                    }
                    if (targettype.Equals("createRawDiskImage", StringComparison.OrdinalIgnoreCase))
                    {
                        m_disks.Add(RawDiskImage.Create(targetpath, long.Parse(targetsize) * 1024 * 1024));
                    }
                    if (targettype.Equals("PhysicalDisk", StringComparison.OrdinalIgnoreCase))
                    {
                        m_disks.Add(new PhysicalDisk(int.Parse(targetdiskindex)));
                    }
                    ISCSITarget target = new ISCSITarget(targetname, m_disks);
                    ((SCSI.VirtualSCSITarget)target.SCSITarget).OnLogEntry += Program.OnLogEntry;
                    target.OnAuthorizationRequest += new EventHandler <AuthorizationRequestArgs>(ISCSITarget_OnAuthorizationRequest);
                    target.OnSessionTermination   += new EventHandler <SessionTerminationArgs>(ISCSITarget_OnSessionTermination);
                    m_targets.Add(target);
                    //
                    try
                    {
                        m_server.AddTarget(target);
                    }
                    catch (ArgumentException ex)
                    {
                        MessageBox.Show(ex.Message, "Error");
                        return;
                    }
                    listTargets.Items.Add(target.TargetName);
                }
            }
        }