tests: Added util functions

Added functions to extract gfid, gfid-str
function to check if a file is open
deleting gfid-link of a file

Change-Id: If2f39f43a6631cddb68b4ba7febcd3cf66f399ee
BUG: 821056
Signed-off-by: Pranith Kumar K <pkarampu@redhat.com>
Reviewed-on: http://review.gluster.org/4386
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Anand Avati <avati@redhat.com>
This commit is contained in:
Pranith Kumar K 2013-01-11 17:37:10 +05:30 committed by Anand Avati
parent 04e673f14e
commit 5c01280de7

View File

@ -90,13 +90,19 @@ function glustershd_up_status {
gluster volume status | grep "Self-heal Daemon" | awk '{print $6}' gluster volume status | grep "Self-heal Daemon" | awk '{print $6}'
} }
function kill_brick() function get_brick_pid {
{ vol=$1
local vol=$1 host=$2
local host=$2 brick=$3
local brick=$3
brick_hiphenated=$(echo $brick | tr '/' '-') brick_hiphenated=$(echo $brick | tr '/' '-')
kill -9 `cat /var/lib/glusterd/vols/$vol/run/${host}${brick_hiphenated}.pid` echo `cat /var/lib/glusterd/vols/$vol/run/${host}${brick_hiphenated}.pid`
}
function kill_brick {
vol=$1
host=$2
brick=$3
kill -9 $(get_brick_pid $vol $host $brick)
} }
function check_option_help_presence { function check_option_help_presence {
@ -124,3 +130,41 @@ function afr_get_num_indices_in_brick {
local brick_path=$1 local brick_path=$1
echo $(ls $(afr_get_index_path $brick_path) | grep -v xattrop | wc -l) echo $(ls $(afr_get_index_path $brick_path) | grep -v xattrop | wc -l)
} }
function gf_get_gfid_xattr {
file=$1
getfattr -n trusted.gfid -e hex $file 2>/dev/null | grep "trusted.gfid" | cut -f2 -d'='
}
function gf_gfid_xattr_to_str {
xval=$1
echo "${xval:2:8}-${xval:10:4}-${xval:14:4}-${xval:18:4}-${xval:22:12}"
}
function gf_check_file_opened_in_brick {
vol=$1
host=$2
brick=$3
realpath=$4
ls -l /proc/$(get_brick_pid $vol $host $brick)/fd | grep "${realpath}$" 2>&1 > /dev/null
if [ $? -eq 0 ]; then
echo "Y"
else
echo "N"
fi
}
function gf_get_gfid_backend_file_path {
brickpath=$1
filepath_in_brick=$2
gfid=$(gf_get_gfid_xattr "$brickpath/$filepath_in_brick")
gfidstr=$(gf_gfid_xattr_to_str $gfid)
echo "$brickpath/.glusterfs/${gfidstr:0:2}/${gfidstr:2:2}/$gfidstr"
}
function gf_rm_file_and_gfid_link {
brickpath=$1
filepath_in_brick=$2
rm -f $(gf_get_gfid_backend_file_path $brickpath $filepath_in_brick)
rm -f "$brickpath/$filepath_in_brick"
}