Commit 8109ceb1 authored by Kirk Webb's avatar Kirk Webb

Checkpoint - new blockstore objects / API in parser.

parent d2088a58
# -*- tcl -*-
#
# Copyright (c) 2000-2012 University of Utah and the Flux Group.
#
# {{{EMULAB-LICENSE
#
# This file is part of the Emulab network testbed software.
#
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
#
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
# License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
#
# }}}
#
######################################################################
# blockstore.tcl
#
# This class defines the blockstore storage object.
#
######################################################################
Class Blockstore -superclass NSObject
Blockstore instproc init {s} {
global ::GLOBALS::last_class
$self set sim $s
$self set node {}
$self set type {}
$self set size 0
$self set sclass {}
$self set proto {}
$self set type {}
$self set role "unknown"
#$self set parameters {}
set ::GLOBALS::last_class $self
}
Blockstore instproc rename {old new} {
$self instvar sim
$sim rename_blockstore $old $new
}
Blockstore instproc set-class {newclass} {
set bsclasses [list "SAN" "local"]
if {[lsearch -exact $bsclasses $newclass] == -1} {
perror "\[set-class] Class must be one of: [join $bsclasses {, }]"
return
}
$self set sclass $newclass
return
}
Blockstore instproc set-protocol {newproto} {
set protocols [list "iSCSI" "FCoE" "SCSI" "SATA"]
if {[lsearch -exact $protocols $newproto] == -1} {
perror "\[set-protocol] Protocol must be one of: [join $protocols {, }]"
return
}
$self set proto $newproto
return
}
Blockstore instproc set-type {newtype} {
var_import ::TBCOMPAT::sotypes
if {[lsearch $sotypes $newtype] == -1} {
perror "\[set-type] Invalid Storage Object type: $newtype"
return
}
$self set type $newtype
return
}
Blockstore instproc set-size {newsize} {
set mindisksize [expr 2 ** 20]; # 1 MiB
# Convert various input size strings to bytes.
set convsize [convert_to_bytes $newsize]
# Do some boundary checks.
if { $convsize < $mindisksize } {
perror "\[set-size] $convsize is smaller than allowed minimum (1 MiB)"
return
}
if { $convsize % $mindisksize } {
puts stderr "*** WARNING: \[set-size] blockstore size will be rounded down to the nearest MiB"
}
# Convert to MiB
set convsize [expr $convsize >> 20]
$self set size $convsize
return
}
# updatedb DB
# This adds rows to the virt_blockstores and virt_blockstore_attributes
# tables, corresponding to this storage object.
Blockstore instproc updatedb {DB} {
var_import ::GLOBALS::pid
var_import ::GLOBALS::eid
var_import ::TBCOMPAT::sotypes
$self instvar sim
$self instvar node
$self instvar type
$self instvar size
$self instvar role
#$self instvar parameters
if { $role == "unknown" } {
puts stderr "*** WARNING: Disk role not set and unable to infer it."
}
set vb_fields [list "vname" "type" "role" "size"]
set vb_values [list $self $type $role $size]
#if { $parameters != "" } {
#lappend fields "parameters"
#lappend values $parameters
#}
#if { $command != "" } {
#lappend fields "command"
#lappend values $command
#}
# Update the DB
spitxml_data "virt_blockstores" $vb_fields $vb_values
#$sim spitxml_data "virt_agents" [list "vnode" "vname" "objecttype" ] [list $node $self $objtypes(DISK) ]
}
......@@ -627,6 +627,37 @@ proc parse_delay {dspec} {
return [expr int($val)]
}
# convert_to_bytes
# This takes a data size specifier in the form of <amt><unit> where
# <unit> is any of [B, KB, KiB, MB, MiB, GB, GiB, TB, TiB]. If no
# unit is given then bytes (B) is assumed. It returns the size
# in bytes. Data sizes in bits (lowercase b) are not handled (yet).
proc convert_to_bytes {size} {
# Default to bytes
if {[scan $size "%f%s" sz unit] == 1} {
set unit B
}
# We could do better below with a regexp match. But it is better to keep it simple.
switch -- $unit {
B {set val $sz}
KB {set val [expr int($sz * 10**3)]}
KiB {set val [expr int($sz * 2**10)]}
MB {set val [expr int($sz * 10**6)]}
MiB {set val [expr int($sz * 2**20)]}
GB {set val [expr int($sz * 10**9)]}
GiB {set val [expr int($sz * 2**30)]}
TB {set val [expr int($sz * 10**12)]}
TiB {set val [expr int($sz * 2**40)]}
default {
perror "Unknown size unit $unit."
set val 0
}
}
return $val
}
# We now have all our infrastructure in place. We are ready to load
# the NS file.
......
......@@ -87,10 +87,14 @@ Simulator instproc init {args} {
$self instvar prog_list;
array set prog_list {}
# Disk list.
# Disk list (shaped/emulated disk).
$self instvar disk_list;
array set disk_list {}
# Blockstore list - blockstore storage object.
$self instvar blockstore_list;
array set blockstore_list {}
# Custom list.
$self instvar custom_list;
array set custom_list {}
......@@ -428,6 +432,29 @@ Simulator instproc event-group {{list {}}} {
return $curgrp
}
# blockstore
# This method adds a new block storage object to the topology and returns
# its id.
Simulator instproc blockstore {args} {
var_import ::GLOBALS::last_class
$self instvar id_counter
$self instvar blockstore_list
if {($args != {})} {
punsup "Arguments for node: $args"
}
set curblock tbblk-n[incr id_counter]
Blockstore $curblock $self
set blockstore_list($curblock) {}
set last_class $curblock
$self instvar new_blockstore_config;
return $curblock
}
# run
# This method causes the fill_ips method to be invoked on all
# lanlinks and then, if not running in impotent mode, calls the
......@@ -440,6 +467,7 @@ Simulator instproc run {} {
$self instvar event_list
$self instvar prog_list
$self instvar disk_list
$self instvar block_list
$self instvar custom_list
$self instvar eventgroup_list
$self instvar firewall_list
......@@ -658,6 +686,9 @@ Simulator instproc run {} {
foreach disk [array names disk_list] {
$disk updatedb "sql"
}
foreach blockstore [array names blockstore_list] {
$blockstore updatedb "sql"
}
foreach custom [array names custom_list] {
$custom updatedb "sql"
}
......@@ -1064,6 +1095,12 @@ Simulator instproc rename_disk {old new} {
set disk_list($new) {}
}
Simulator instproc rename_blockstore {old new} {
$self instvar blockstore_list
unset blockstore_list($old)
set blockstore_list($new) {}
}
Simulator instproc rename_custom {old new} {
$self instvar custom_list
unset custom_list($old)
......
......@@ -94,6 +94,9 @@ namespace eval TBCOMPAT {
variable isvirt
variable issubnode
# Storage object tracking (types, resources, etc.)
variable sotypes
# NSE hack: sim type is not in DB. Just adding it now
set hwtypes(sim) 1
set isremote(sim) 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment