prod_iscsi.patch

SZTAKI LPDS, 10/25/2012 03:23 PM

Download (7.55 KB)

View differences:

src/datastore_mad/remotes/iscsi/clone
76 76
CLONE_CMD=$(cat <<EOF
77 77
    set -e
78 78
    $SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
79
    $SUDO $DD if=$DEV_SRC of=$DEV bs=64k
79
    $SUDO $DD if=$DEV_SRC of=$DEV bs=2M
80 80

  
81
    TID=\$($SUDO $(tgtadm_next_tid))
82

  
83
    $SUDO $(tgtadm_target_new "\$TID" "$IQN")
84
    $SUDO $(tgtadm_target_bind_all "\$TID")
85
    $SUDO $(tgtadm_logicalunit_new "\$TID" "$DEV")
81
    $SUDO $(tgt_setup_lun "$IQN" "$DEV")
86 82
    $SUDO $(tgt_admin_dump_config "$TARGET_CONF")
87 83
EOF
88 84
)
src/datastore_mad/remotes/iscsi/cp
84 84
    set -e
85 85
    $SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
86 86

  
87
    TID=\$($SUDO $(tgtadm_next_tid))
88

  
89
    [ -z "\$TID" ] && TID=1
90

  
91
    $SUDO $(tgtadm_target_new "\$TID" "$IQN")
92
    $SUDO $(tgtadm_target_bind_all "\$TID")
93
    $SUDO $(tgtadm_logicalunit_new "\$TID" "$DEV")
87
    $SUDO $(tgt_setup_lun "$IQN" "$DEV")
94 88
    $SUDO $(tgt_admin_dump_config "$TARGET_CONF")
95 89
EOF
96 90
)
......
121 115

  
122 116
ssh_exec_and_log "$DST_HOST" "$REGISTER_CMD" "Error registering $DST_HOST:$DEV"
123 117

  
124
exec_and_log "eval $DUMP | $SSH $DST_HOST $SUDO $DD of=$DEV bs=64k" \
118
exec_and_log "eval $DUMP | $SSH $DST_HOST $SUDO $DD of=$DEV bs=2M" \
125 119
    "Error dumping $SRC to $DST_HOST:$DEV"
126 120

  
127 121
echo "$IQN"
src/datastore_mad/remotes/iscsi/mkfs
76 76
    set -e
77 77
    $SUDO $LVCREATE -L${SIZE}M ${VG_NAME} -n ${LV_NAME}
78 78

  
79
    TID=\$($SUDO $(tgtadm_next_tid))
80
    [ -z "\$TID" ] && TID=1
81

  
82
    $SUDO $(tgtadm_target_new "\$TID" "$IQN")
83
    $SUDO $(tgtadm_target_bind_all "\$TID")
84
    $SUDO $(tgtadm_logicalunit_new "\$TID" "$DEV")
79
    $SUDO $(tgt_setup_lun "$IQN" "$DEV") 
85 80
    $SUDO $(tgt_admin_dump_config "$TARGET_CONF")
86 81

  
87 82
    if [ "$FSTYPE" != "save_as" ]; then
src/mad/sh/scripts_common.sh
44 44
TAR=tar
45 45
TGTADM=tgtadm
46 46
TGTADMIN=tgt-admin
47
TGTSETUPLUN=tgt-setup-lun
47 48
VMKFSTOOLS=vmkfstools
48 49
WGET=wget
49 50

  
......
349 350

  
350 351
function tgtadm_get_tid_for_iqn {
351 352
    IQN="$1"
352
    echo "$TGTADM --lld iscsi --op show --mode target | \
353
    echo "$TGTADM --lld iscsi --op show --mode target | strings | \
353 354
        grep \"$IQN\" | awk '{split(\$2,tmp,\":\"); print(tmp[1]);}'"
354 355
}
355 356

  
356 357
function tgtadm_next_tid {
357
    echo "$TGTADM --lld iscsi --op show --mode target | \
358
    echo "$TGTADM --lld iscsi --op show --mode target | strings | \
358 359
            $GREP \"Target\" | tail -n 1 | \
359 360
            $AWK '{split(\$2,tmp,\":\"); print tmp[1]+1;}'"
360 361
}
......
402 403
    echo $TARGET|$AWK -F. '{print $(NF-1)}'
403 404
}
404 405

  
406
function tgt_setup_lun {
407
    IQN="$1"
408
    DEV="$2"
409
    echo "$TGTSETUPLUN -d $DEV -n $IQN 1>&2"
410
}
411

  
405 412
function iqn_get_host {
406 413
    IQN="$1"
407 414
    TARGET=`echo "$IQN"|$CUT -d: -f2`
src/tm_mad/iscsi/clone
81 81
    $SUDO $LVCREATE -L\${SIZE} ${VG_NAME} -n ${TARGET_LV_NAME}
82 82

  
83 83
    # clone lv with dd
84
    $SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=64k
84
    $SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M
85 85

  
86 86
    # new iscsi target
87
    TID=\$($SUDO $(tgtadm_next_tid))
88

  
89
    $SUDO $(tgtadm_target_new "\$TID" "$NEW_IQN")
90
    $SUDO $(tgtadm_target_bind_all "\$TID")
91
    $SUDO $(tgtadm_logicalunit_new "\$TID" "$TARGET_DEV")
87
    $SUDO $(tgt_setup_lun "$NEW_IQN" "$TARGET_DEV")
92 88
    $SUDO $(tgt_admin_dump_config "$TARGET_CONF")
93 89
EOF
94 90
)
......
101 97
    mkdir -p $DST_DIR
102 98
    $SUDO $(iscsiadm_discovery "$TARGET_HOST")
103 99
    $SUDO $(iscsiadm_login "$NEW_IQN" "$TARGET_HOST")
104
    sleep 2
105
    DISK_BY_PATH=\$(ls /dev/disk/by-path/*$NEW_IQN-lun-1)
106
    ln -s "\$DISK_BY_PATH" "$DST_PATH"
107 100
EOF
108 101
)
109 102

  
110 103
ssh_exec_and_log "$DST_HOST" "$DISCOVERY_CMD" \
111 104
        "Error discovering $NEW_IQN in $DST_HOST"
112 105

  
106
TEST_CMD=$(cat <<EOF
107
    set -e
108
    while [ ! -L /dev/disk/by-path/*$NEW_IQN-lun-1 ]; do
109
	sleep 1
110
    done
111
EOF
112
)
113

  
114
ssh_exec_and_log "$DST_HOST" "$TEST_CMD" \
115
        "Error waiting for $NEW_IQN iSCSI LUN to appear in $DST_HOST"
116

  
117

  
118
LINK_CMD=$(cat <<EOF
119
    set -e
120
    DISK_BY_PATH=\$(ls /dev/disk/by-path/*$NEW_IQN-lun-1)
121
    ln -s "\$DISK_BY_PATH" "$DST_PATH"
122
    DISK_DEVNAME=\$(readlink -f \$DISK_BY_PATH  | awk -F'/' '{ print \$NF }')
123
EOF
124
)
125

  
126
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
127
        "Error linking $NEW_IQN in $DST_HOST"
128

  
113 129
exit 0
src/tm_mad/iscsi/ln
63 63
    mkdir -p $DST_DIR
64 64
    $SUDO $(iscsiadm_discovery "$TARGET_HOST")
65 65
    $SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
66
    sleep 2
66
EOF
67
)
68

  
69
ssh_exec_and_log "$DST_HOST" "$DISCOVER_CMD" \
70
        "Error discovering $DST_HOST:$DEV"
71

  
72
TEST_CMD=$(cat <<EOF
73
    set -e
74
    while [ ! -L /dev/disk/by-path/*$IQN-lun-1 ]; do
75
	sleep 1
76
    done
77
EOF
78
)
79

  
80
ssh_exec_and_log "$DST_HOST" "$TEST_CMD" \
81
        "Error waiting for $IQN iSCSI LUN to appear in $DST_HOST"
82

  
83
LINK_CMD=$(cat <<EOF
84
    set -e
67 85
    DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
68 86
    ln -s "\$DISK_BY_PATH" "$DST_PATH"
87
    DISK_DEVNAME=\$(readlink -f \$DISK_BY_PATH  | awk -F'/' '{ print \$NF }')
69 88
EOF
70 89
)
71 90

  
72
ssh_exec_and_log "$DST_HOST" "$DISCOVER_CMD" \
73
        "Error registering $DST_HOST:$DEV"
91
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
92
        "Error linking $DST_HOST:$DEV"
93

  
74 94

  
75 95
exit 0
src/tm_mad/iscsi/mv
114 114

  
115 115
    TARGET_HOST=$(iqn_get_host "$IQN")
116 116

  
117
    LOGIN_CMD=$(cat <<EOF
117
LOGIN_CMD=$(cat <<EOF
118 118
        set -e
119 119
        mkdir -p $DST_DIR
120 120
        $SUDO $(iscsiadm_discovery "$TARGET_HOST")
121 121
        $SUDO $(iscsiadm_login "$IQN" "$TARGET_HOST")
122
EOF
123
)
124

  
125
ssh_exec_and_log "$DST_HOST" "$LOGIN_CMD" \
126
    "Error logging in $IQN"
127

  
128
TEST_CMD=$(cat <<EOF
129
    set -e
130
    while [ ! -L /dev/disk/by-path/*$IQN-lun-1 ]; do
122 131
        sleep 1
132
    done
133
EOF
134
)
135

  
136
ssh_exec_and_log "$DST_HOST" "$TEST_CMD" \
137
        "Error waiting for $IQN iSCSI LUN to appear in $DST_HOST"
138

  
139
LINK_CMD=$(cat <<EOF
140
        set -e
123 141
        DISK_BY_PATH=\$(ls /dev/disk/by-path/*$IQN-lun-1)
124 142
        ln -sf "\$DISK_BY_PATH" "$DST_PATH"
125 143
EOF
126 144
)
127 145

  
128
ssh_exec_and_log "$DST_HOST" "$LOGIN_CMD" \
129
    "Error logging in $IQN"
146
ssh_exec_and_log "$DST_HOST" "$LINK_CMD" \
147
    "Error linking to $DISK_BY_PATH $DST_PATH"
148

  
149

  
130 150
fi
131 151

  
132 152
exit 0
src/tm_mad/iscsi/mvds
101 101
    set -e
102 102

  
103 103
    # clone lv with dd
104
    $SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=64k
104
    $SUDO $DD if=$SOURCE_DEV of=$TARGET_DEV bs=2M
105 105

  
106 106
    # remove if source_dev is not persistent
107 107
    if [ -z "$PERSISTENT" ]; then