<commit_before># Copyright (c) 2010-2011 <NAME>
#
# Permission to use, copy, modify, and/or distribute this software for 
# any purpose with or without fee is hereby granted, provided that the 
# above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# @author <NAME>

# Defines a class capable of creating iSCSI shares using the new
# COMStar framework. This classes uses the various command line tools, 
# not the C API.
class COMStar
  
  # Create a new, ready to use, iSCSI target. Functionally this is command
  # is equivalent to the old "shareiscsi=on" ZFS volume property.
  def self.new_target(volume_path, volume_guid)
    
    # Create a new disk target for the ZFS volume
    SANStore::CLI::Logger.instance.log_level(:low, :create, "New SCSI block device at /dev/zvol/rdsk/#{volume_path}")
    disk_target = %x[sbdadm create-lu /dev/zvol/rdsk/#{volume_path}]

    # Get the ID of the new disk target from the output of the
    # target creation command
    id = disk_target.split(/$/)[4].split[0]
    SANStore::CLI::Logger.instance.log_level(:low, :info, "Using #{id} as the logical unit identifier")
   
    # Modify the just created logical unit to include the path of the
    # volume backing it. This makes it much easier to get rid of the
    # relevant volume later
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Storing the volume GUID as the logical unit alias")
    modify_lu = %x[stmfadm modify-lu --lu-prop alias=#{volume_guid} #{id}]

    # Link the new disk target to the iSCSI framework
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Attaching logical unit #{id} into the iSCSI framework")
    vol_frame = %x[stmfadm add-view #{id}]

    # Create the target...
    SANStore::CLI::Logger.instance.log_level(:low, :create, "iSCSI block target")
    target = %x[itadm create-target]
    target_name = target.split[1]
    
    # Store the volume GUID as the alias so we can find it later
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Storing the volume GUID as the iSCSI target alias")
    %x[itadm modify-target --alias #{volume_guid} #{target_name}]
    
    # Return the target name to the caller
    return target_name
  end
  
  # Delete an iSCSI target. This returns the name of the underlying ZFS store in case the
  # caller wants to delete that as well<commit_msg>Limit new targets to a dedicated target group. Fixes the long list of devices seen by hosts, and means each target now acts as an independent device<commit_after># Copyright (c) 2010-2011 <NAME>
#
# Permission to use, copy, modify, and/or distribute this software for 
# any purpose with or without fee is hereby granted, provided that the 
# above copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

# @author <NAME>

# Defines a class capable of creating iSCSI shares using the new
# COMStar framework. This classes uses the various command line tools, 
# not the C API.
class COMStar
  
  # Create a new, ready to use, iSCSI target. Functionally this is command
  # is equivalent to the old "shareiscsi=on" ZFS volume property.
  def self.new_target(volume_path, volume_guid)
    
    # Create a new disk target for the ZFS volume
    SANStore::CLI::Logger.instance.log_level(:low, :create, "New SCSI block device at /dev/zvol/rdsk/#{volume_path}")
    disk_target = %x[sbdadm create-lu /dev/zvol/rdsk/#{volume_path}]

    # Get the ID of the new disk target from the output of the
    # target creation command
    id = disk_target.split(/$/)[4].split[0]
    SANStore::CLI::Logger.instance.log_level(:low, :info, "Using #{id} as the logical unit identifier")
   
    # Modify the just created logical unit to include the path of the
    # volume backing it. This makes it much easier to get rid of the
    # relevant volume later
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Storing the volume GUID as the logical unit alias")
    modify_lu = %x[stmfadm modify-lu --lu-prop alias=#{volume_guid} #{id}]
    
    # Create a new target group
    SANStore::CLI::Logger.instance.log_level(:low, :create, "Creating target group #{id}")
    %x[stmfadm create-tg #{id}]

    # Link the new disk target to the iSCSI framework
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Attaching logical unit #{id} into the iSCSI framework")
    vol_frame = %x[stmfadm add-view --target-group #{id} #{id}]

    # Create the target...
    SANStore::CLI::Logger.instance.log_level(:low, :create, "iSCSI block target")
    target = %x[itadm create-target]
    target_name = target.split[1]
    
    # Store the volume GUID as the alias so we can find it later
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Storing the volume GUID as the iSCSI target alias")
    %x[itadm modify-target --alias #{volume_guid} #{target_name}]

    # Add the new target to the correct target group
    SANStore::CLI::Logger.instance.log_level(:low, :update, "Adding the target #{target_name} to its target group")
    %x[svcadm disable stmf; sleep 2; stmfadm add-tg-member -g #{id} #{target_name}; svcadm enable stmf]
    
    # Return the target name to the caller
    return target_name
  end
  
  # Delete an iSCSI target. This returns the name of the underlying ZFS store in case the
  # caller wants to delete that as well
{'fraction_non_alphanumeric': 0.08763049667826638, 'fraction_numerical': 0.0036380892122745965, 'mean_word_length': 3.8452107279693486, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '97533', 'n_tokens_mistral': 1932, 'n_tokens_neox': 1858, 'n_words': 793}