+function check_who_locked(){
+ local sliver=$1
+ local sliver_nid=`get_nid $sliver`
+ local ret=0
+
+ if [ -e $LOCK_DIR ]; then
+ if [[ `cat $FILE_LOCK_SLIVER` != $sliver_nid ]]; then
+ echo "Interface in use by another slice.";
+ ret=1
+ fi
+ else
+ ret=1
+ fi
+
+ return $ret
+
+}
+
+function lock(){
+ local sliver=$1
+ local sliver_nid=`get_nid $sliver`
+ local ret=0
+
+ if [ -e $LOCK_DIR ]; then
+ if ! check_who_locked $sliver; then
+ ret=1
+ fi
+ else
+ if mkdir $LOCK_DIR >/dev/null 2>&1; then
+ echo "$sliver_nid" > $FILE_LOCK_SLIVER
+ else
+ ret=1
+ fi
+ fi
+
+ return $ret
+}
+
+function unlock(){
+ local sliver=$1
+ local sliver_nid=`get_nid $sliver`
+ local ret=0
+
+ if ! [ -e $LOCK_DIR ]; then
+ ret=1
+ else
+ if ! check_who_locked $sliver; then
+ ret=1
+ else
+ if ! rmdir $LOCK_DIR; then
+ ret=1
+ fi
+ fi
+ fi
+
+ return $ret
+}
+
+
+
+