4
# Replace any '-' by '_' to avoid that device manager modifies the name of
5
# the device (it replaces '-' by '--' in /dev/mapper)
6
LVM_PREFIX="patchy_snap_${GFREG_ID//-/_}"
10
#This function will init B# bricks
11
#This is used when launch_cluster is
12
#not called to init B#. Call it before
14
function init_n_bricks() {
16
for i in `seq 1 $count`; do
17
eval "B$i=/d/backends/$i"
26
if [ "$1" == "" ]; then
27
echo "Error: Invalid argument supplied"
32
if [ "$2" != "" ]; then
39
if [ "$B1" = "" ]; then
43
for i in `seq 1 $LVM_COUNT`; do
45
if [ "${!b}" = "" ]; then
46
echo "Error: $b not defined."
47
echo "Please run launch_cluster with atleast $LVM_COUNT nodes"
51
eval "L$i=${!b}/${LVM_PREFIX}_mnt"
55
echo "Error: failed to create dir ${!l}"
59
eval "VG$i=${LVM_PREFIX}_vg_${i}"
66
function verify_lvm_version() {
67
if `/sbin/lvcreate --help | grep -q thin`; then
74
init_lvm $@ || return 1
79
function cleanup_lvm() {
87
# Find out how this file was sourced, source traps.rc the same way, and use
88
# push_trapfunc to make sure cleanup_lvm gets called before we exit.
89
. $(dirname ${BASH_SOURCE[0]})/traps.rc
90
push_trapfunc cleanup_lvm
92
########################################################
94
########################################################
95
function _setup_lvm() {
96
local count=$LVM_COUNT
100
for i in `seq 1 $count`; do
109
function _cleanup_lvm_again() {
112
findmnt -nRlT "${B0}" -o TARGET,SOURCE | grep "${LVM_PREFIX}" | awk '{print $2}' | xargs -r ${UMOUNT_F}
113
findmnt -nRlo TARGET,SOURCE | grep "run/gluster/snaps" | awk '{print $2}' | xargs -r ${UMOUNT_F}
114
\rm -rf /var/run/gluster/snaps/*
116
vgremove -fyS "vg_name=~^${LVM_PREFIX}_vg"
118
for dev in $(ls ${DEVDIR}/loop* 2>/dev/null); do
123
find $B0 -name "${LVM_PREFIX}*" | xargs -r rm -rf
126
########################################################
127
########################################################
128
function _create_vhd() {
131
fallocate -l${VHD_SIZE} $dir/${LVM_PREFIX}_vhd
132
dev="$(losetup -f --show "${dir}/${LVM_PREFIX}_vhd")"
133
ln -sf "${dev}" "${DEVDIR}/$(basename "${dev}")"
134
ln -sf "${DEVDIR}/$(basename "${dev}")" "${dir}/${LVM_PREFIX}_loop"
137
function _create_lv() {
141
local thinpoolsize="200M"
142
local virtualsize="150M"
143
local path="$(realpath "${dir}/${LVM_PREFIX}_loop")"
146
/sbin/pvcreate --zero n "${path}"
147
/sbin/vgcreate --zero n ${!vg} "${path}"
149
/sbin/lvcreate --zero n -L ${thinpoolsize} -T ${!vg}/thinpool
150
/sbin/lvcreate -V ${virtualsize} -T ${!vg}/thinpool -n brick_lvm
152
mkfs.xfs -K -f /dev/${!vg}/brick_lvm
155
function _mount_lv() {
160
mount -t xfs -o nouuid /dev/${!vg}/brick_lvm ${!l}
163
function _umount_lv() {
167
${UMOUNT_F} ${!l} 2>/dev/null || true
168
rmdir ${!l} 2>/dev/null || true
171
function _remove_lv() {
178
function _remove_vhd() {
181
losetup -d $dir/${LVM_PREFIX}_loop
182
rm -f "$(readlink "${dir}/${LVM_PREFIX}_loop")"
183
rm -f $dir/${LVM_PREFIX}_loop
184
rm -f $dir/${LVM_PREFIX}_vhd
187
########################################################
189
########################################################
190
function snapshot_exists() {
194
if [ "$clitype" == "1" ]; then
197
if [ "$clitype" == "2" ]; then
200
$cli snapshot list | egrep -q "^$snapname\$"
204
#Create N number of snaps in a given volume
206
#Arg2 : <Count of snaps to be created>
207
#Arg3 : <Snap Name Pattern>
208
#Return: Returns 0 if all snaps are created ,
209
# if not will return exit code of last failed
210
# snap create command.
211
function create_n_snapshots() {
217
for i in `seq 1 $snap_count`; do
218
$CLI_1 snapshot create $snap_name$i ${vol} no-timestamp &
222
if [ "$ret" != "0" ]; then
230
#Delete N number of snaps in a given volume
232
#Arg2 : <Count of snaps to be deleted>
233
#Arg3 : <Snap Name Pattern>
234
#Return: Returns 0 if all snaps are Delete,
235
# if not will return exit code of last failed
236
# snap delete command.
237
function delete_n_snapshots() {
242
for i in `seq 1 $snap_count`; do
243
$CLI_1 snapshot delete $snap_name$i &
247
if [ "$temp" != "0" ]; then
254
#Check for the existance of N number of snaps in a given volume
256
#Arg2 : <Count of snaps to be checked>
257
#Arg3 : <Snap Name Pattern>
258
#Return: Returns 0 if all snaps exists,
259
# if not will return exit code of last failed
261
function snapshot_n_exists() {
266
for i in `seq 1 $snap_count`; do
267
snapshot_exists 1 $snap_name$i
269
if [ "$ret" != "0" ]; then
276
#Check for the status of snapshot for a volume
278
function snapshot_status()
282
if [ "$cli" = "" ]; then
286
#TODO: Right now just fetches the status of the single snap volume.
287
#When snapshot will have multiple snap volumes, should have a
288
#cummulative logic for status
289
$cli snapshot info $snap | grep "Status" | sed 's/.*: //';
293
#Check the different status of a particular snapshot
295
#Arg2 : <Filed in status>
296
#Arg3 : <Expected value>
297
function snapshot_snap_status()
304
if [ "$cli" = "" ]; then
307
for i in $($cli snapshot status $snap | grep "$field" | \
308
cut -d ':' -f2 | awk '{print $1}') ;
310
if [ "$i" != "$expected" ]; then
319
# arg-1 : From which node the command should be trigerred
320
# Ex : $CLI_1, $CLI_2, etc.
322
# arg-3 : Starting index for the snapname "snap$i"
323
# arg-4 : Number of snapshots to be taken
324
function snap_create()
326
eval local cli_index=\$$1
329
local limit=$[$i + $4]
331
while [ $i -lt $limit ]
333
$cli_index snapshot create snap$i $volname no-timestamp
338
# arg-1 : From which node the command should be trigerred
339
# Ex : $CLI_1. $CLI_2, etc.
340
# arg-2 : Volume name.
341
function get_snap_count()
343
eval local cli_index=\$$1
349
$cli_index snapshot list | grep -v "No snapshots present"\
352
$cli_index snapshot list $volname\
353
| grep -v "No snapshots present"\
358
# arg-1 : From which node the command should be trigerred
359
# Ex : $CLI_1, $CLI_2, etc.
360
# arg-2 : Starting index for the snapname "snap$i"
361
# arg-3 : Number of snapshots to be deleted.
362
function snap_delete()
364
eval local cli_index=\$$1
366
local limit=$[$i + $3]
368
while [ $i -lt $limit ]
370
$cli_index snapshot delete snap$i
375
# arg-1 : From which node the command should be triggered
376
# Ex : $CLI_1, $CLI_2, etc.
378
function snap_config()
380
eval local cli_index=\$$1
382
$cli_index snapshot config | grep "^$var" | sed 's/.*: //'
385
function check_if_snapd_exist() {
387
pid=$(ps aux | grep "snapd" | grep -v grep | awk '{print $2}')
388
if [ -n "$pid" ]; then echo "Y"; else echo "N"; fi
391
# returns number of snapshot being displayed in ".snaps" directory
392
function uss_count_snap_displayed() {
394
ls $path/.snaps | wc -l
397
function snap_info_volume()
399
eval local cli_index=\$$1
402
$cli_index snapshot info volume $vol | grep "^$var" | sed 's/.*: //'
405
function snap_config_volume()
407
eval local cli_index=\$$1
410
$cli_index snapshot config $vol| grep "^$var" | sed 's/.*: //'
413
#return specific fields of xml output
414
function get-cmd-field-xml()
417
if [ "$cli" = "" ]; then
424
$cli $COMMAND --xml | xmllint --format - | grep $PATTERN
427
function get_snap_brick_status()
431
$CLI snapshot status $snap | grep "Brick Running" | sed 's/.*: //';
436
echo "Skip test on LVM which is not available on NetBSD" >&2