Skip to content

Commit

Permalink
Merge branch 'bridge_list'
Browse files Browse the repository at this point in the history
  • Loading branch information
kvaps committed Jul 3, 2019
2 parents d98f77d + 35f5a03 commit 46232e3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 37 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ TM_MAD_CONF = [
Add new **DS_MAD_CONF** section:
```
DS_MAD_CONF = [
NAME = "linstor_un", REQUIRED_ATTRS = "BRIDGE_LIST", PERSISTENT_ONLY = "NO",
NAME = "linstor_un", PERSISTENT_ONLY = "NO",
MARKETPLACE_ACTIONS = "export"
]
```
Expand All @@ -105,7 +105,7 @@ To use your Linstor cluster with the OpenNebula, you need to define a System and
|---------------------------|------------------------------------------------------------------------------------------------------------------|-----------|
| `NAME` | The name of the datastore | **YES** |
| `CLONE_MODE` | `snapshot` - will create snapshot for instantiate VMs. `copy` - create full copy of image, this is default mode. | NO |
| `BRIDGE_LIST` | Space separated hosts list used for transfer operations. Copy data between images and etc. | **YES** |
| `BRIDGE_LIST` | Space separated hosts list used for transfer operations. Copy data between images and etc. Default: all hosts. | NO |
| `LS_CONTROLLERS` | Comma separated linstor controllers list for establish connection. | NO |
| `NODE_LIST` | Space separated hosts list to place replicas. Replicas will always be created on all these hosts. | **YES** * |
| `LAYER_LIST` | Comma separated layer list to place replicas. | NO |
Expand All @@ -118,7 +118,7 @@ To use your Linstor cluster with the OpenNebula, you need to define a System and
| `DO_NOT_PLACE_WITH_REGEX` | Regular expression to avoid placing replicas on same place with targeted resources. | NO |
| `STORAGE_POOL` | Storage pool name to place replicas. | **YES** |
| `DISKLESS_POOL` | Diskless pool to place diskless replicas. Default: `DfltDisklessStorPool`. | NO |
| `ENCRYPTION` | `yes` - will enable encryption during volume creation. | NO | |
| `ENCRYPTION` | `yes` - will enable encryption during volume creation. | NO |

*\* - only one attribute required*

Expand All @@ -143,7 +143,6 @@ TYPE="SYSTEM_DS"
STORAGE_POOL="data"
AUTO_PLACE="2"
CHECKPOINT_AUTO_PLACE="1"
BRIDGE_LIST="node1 node2 node3"
TM_MAD="linstor_un"
EOT

Expand Down Expand Up @@ -171,7 +170,6 @@ NAME="linstor-images"
TYPE="IMAGE_DS"
STORAGE_POOL="data"
AUTO_PLACE="2"
BRIDGE_LIST="node1 node2 node3"
DISK_TYPE="BLOCK"
DS_MAD="linstor_un"
TM_MAD="linstor_un"
Expand Down
3 changes: 1 addition & 2 deletions datastore/linstor_un/clone
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ DST_RES="one-image-${ID}"
DST_DEV="/dev/drbd/by-res/${DST_RES}/0"
DST="$DST_DEV"

SRC_HOST=`linstor_get_bridge_host_for_res $SRC_RES 0 $ID`
SRC_HOST=`linstor_get_bridge_host $SRC_RES 0 $ID`

if [ -z "$SRC_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi
if [ -z "$NODE_LIST" ] && [ -z "$AUTO_PLACE" ]; then
Expand Down
3 changes: 1 addition & 2 deletions datastore/linstor_un/cp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ SHA1="${XPATH_ELEMENTS[j++]}"
NO_DECOMPRESS="${XPATH_ELEMENTS[j++]}"
LIMIT_TRANSFER_BW="${XPATH_ELEMENTS[j++]}"

DST_HOST=`get_destination_host $ID`
DST_HOST=`linstor_get_bridge_host "" "" $ID`

if [ -z "$DST_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi
if [ -z "$NODE_LIST" ] && [ -z "$AUTO_PLACE" ]; then
Expand Down
3 changes: 1 addition & 2 deletions datastore/linstor_un/export
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ echo "<FORMAT><![CDATA[raw]]></FORMAT>"
EOF
)

SRC_HOST=`linstor_get_bridge_host_for_res "$SRC_RES" 0`
SRC_HOST=`linstor_get_bridge_host "$SRC_RES" 1`
if [ -z "$SRC_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi

Expand Down
62 changes: 42 additions & 20 deletions datastore/linstor_un/linstor_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,39 +196,60 @@ function linstor_get_snaps_for_res {
# not defined
# @return host to be used as bridge
#-------------------------------------------------------------------------------
function linstor_get_bridge_host_for_res {
function linstor_get_bridge_host {
local RES="$1"
local MUST_CONTAIN="${2:-0}"
local RR_ID="$3"
local HOSTS_ARRAY=()

local IMAGE_NODES="$(linstor_get_hosts_for_res $RES)"
unset REDUCED_LIST
for NODE in $BRIDGE_LIST; do
if [[ " $IMAGE_NODES " =~ " $NODE " ]] ; then
local REDUCED_LIST="$REDUCED_LIST $NODE"
fi
done
if [ -z "$BRIDGE_LIST" ]; then
# Get online hosts
local REDUCED_LIST="$(onehost list --no-pager --csv \
--filter="STAT!=off,STAT!=err,STAT!=dsbl" --list=NAME,STAT | awk -F, 'NR>1{print $1}')"

local REDUCED_LIST=$(remove_off_hosts "$REDUCED_LIST")
if [ -n "$REDUCED_LIST" ]; then
local HOSTS_ARRAY=($REDUCED_LIST)
local N_HOSTS=${#HOSTS_ARRAY[@]}

if [ -n "$RR_ID" ]; then
local ARRAY_INDEX=$(($RR_ID % ${N_HOSTS}))
else
local ARRAY_INDEX=$((RANDOM % ${N_HOSTS}))
if [ -z "$REDUCED_LIST" ]; then
error_message "'BRIDGE_LIST' is not specified, all other nodes are offline, error or disabled"
exit -1
fi

echo ${HOSTS_ARRAY[$ARRAY_INDEX]}
else
# Remove offline hosts
local REDUCED_LIST=$(remove_off_hosts "$BRIDGE_LIST")
if [ -z "$REDUCED_LIST" ]; then
error_message "All hosts from 'BRIDGE_LIST' are offline, error or disabled"
exit -1
fi
fi

# Remove hosts not containing resource
if [ -n "$RES" ]; then
local RES_HOSTS="$(linstor_get_hosts_for_res $RES)"
for HOST in $REDUCED_LIST; do
if [[ " $RES_HOSTS " =~ " $HOST " ]] ; then
local HOSTS_ARRAY+=($HOST)
fi
done
fi

# Fallback to hosts from BRIDGE_LIST
local N_HOSTS=${#HOSTS_ARRAY[@]}
if [ "$N_HOSTS" = 0 ]; then
if [ "$MUST_CONTAIN" = "1" ]; then
error_message "All hosts from 'BRIDGE_LIST' that contains $RES are offline, error or disabled"
exit -1
else
get_destination_host $RR_ID
local HOSTS_ARRAY=($REDUCED_LIST)
local N_HOSTS=${#HOSTS_ARRAY[@]}
fi
fi

# Select random host
if [ -n "$RR_ID" ]; then
local ARRAY_INDEX=$(($RR_ID % ${N_HOSTS}))
else
local ARRAY_INDEX=$((RANDOM % ${N_HOSTS}))
fi

echo ${HOSTS_ARRAY[$ARRAY_INDEX]}
}


Expand Down Expand Up @@ -303,6 +324,7 @@ function linstor_exec_and_log {
# Gets environment variables:
# - LINSTOR_CLEANUP_RD
# - LINSTOR_CLEANUP_R
# - LINSTOR_CLEANUP_SNAPSHOT
#-------------------------------------------------------------------------------
function linstor_cleanup_trap {
for RES in $LINSTOR_CLEANUP_RD; do
Expand Down
3 changes: 1 addition & 2 deletions datastore/linstor_un/mkfs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ ENCRYPTION="${XPATH_ELEMENTS[j++]}"
FSTYPE="${XPATH_ELEMENTS[j++]}"
SIZE="${XPATH_ELEMENTS[j++]}"

DST_HOST=`get_destination_host $ID`
DST_HOST=`linstor_get_bridge_host "" "" $ID`

if [ -z "$DST_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi
if [ -z "$NODE_LIST" ] && [ -z "$AUTO_PLACE" ]; then
Expand Down
3 changes: 1 addition & 2 deletions datastore/linstor_un/snap_revert
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ LAST_SNAP_ID="${XPATH_ELEMENTS[j++]}"

SRC_DEV="$SRC"
SRC_RES="$(echo "$SRC_DEV" | $AWK -F/ '{print $(NF-1)}')"
SRC_HOST=`linstor_get_bridge_host_for_res $SRC_RES 0 $ID`
SRC_HOST=`linstor_get_bridge_host $SRC_RES 0 $ID`

if [ -z "$SRC_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi

Expand Down
3 changes: 1 addition & 2 deletions tm/linstor_un/clone
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,8 @@ ENCRYPTION="${XPATH_ELEMENTS[j++]}"
# Clone the image
#-------------------------------------------------------------------------------

SRC_HOST=`linstor_get_bridge_host_for_res "$SRC_RES" 0`
SRC_HOST=`linstor_get_bridge_host "$SRC_RES" 0`
if [ -z "$SRC_HOST" ]; then
error_message "Datastore template missing 'BRIDGE_LIST' attribute."
exit -1
fi
if [ -z "$NODE_LIST" ] && [ -z "$AUTO_PLACE" ]; then
Expand Down

0 comments on commit 46232e3

Please sign in to comment.