1
0
mirror of https://git.yoctoproject.org/meta-arm synced 2026-05-31 00:39:57 +00:00

arm-autonomy/xenguest-manager: Allow guests with substring names

Created new function for determining guest running state such that
two guests with names such as "myguest" and "myguest2" report
correctly, by searching for exact guestname instead of contains.

Also modified the status command to use the same function to avoid
duplication, and added a new nested function for testing status for
a particular guest, instead of recursively calling the whole bash
script.

Using the nested function speeds up "xenguest-manager status" from
~7.5s to ~1.5s my machine.

Change-Id: Ie6fc08cacc55f623c44b08478f76031510a59126
Issue-Id: SCM-1517
Signed-off-by: Nathan Dunne <Nathan.Dunne@arm.com>
Signed-off-by: Jon Mason <jon.mason@arm.com>
This commit is contained in:
Nathan Dunne
2020-10-30 10:03:38 +00:00
committed by Jon Mason
parent 5f8eabe68f
commit acac8ed6ce
@@ -597,11 +597,22 @@ function check_guest_exist()
fi fi
} }
function xl_list_contains()
{
guestname="${1}"
# Select first column of xl list, and find guestname exactly using regex
running=$(xl list | awk 'NR > 1 {print $1}' | grep "^${guestname}$" || echo)
if [ "${running}" = "${guestname}" ]; then
return 0
fi
return 1
}
function check_guest_running() function check_guest_running()
{ {
guestname="${1}" guestname="${1}"
running=$(xl list | awk 'NR > 1 {print $1}' | grep "${guestname}" || echo) if ! xl_list_contains $guestname; then
if [ ! "${running}" = "${guestname}" ]; then
echo "${PREF} Guest ${guestname} is not running" echo "${PREF} Guest ${guestname} is not running"
exit 1 exit 1
fi fi
@@ -610,8 +621,7 @@ function check_guest_running()
function check_guest_not_running() function check_guest_not_running()
{ {
guestname="${1}" guestname="${1}"
running=$(xl list | awk 'NR > 1 {print $1}' | grep "${guestname}" || echo) if xl_list_contains $guestname; then
if [ "${running}" = "${guestname}" ]; then
echo "${PREF} Guest ${guestname} is running" echo "${PREF} Guest ${guestname} is running"
exit 1 exit 1
fi fi
@@ -668,10 +678,8 @@ case ${cmd} in
guestname="${arg1:-}" guestname="${arg1:-}"
check_guest_arg ${cmd} ${guestname} check_guest_arg ${cmd} ${guestname}
check_guest_exist ${guestname} check_guest_exist ${guestname}
# We need to stop the guest first # We need to stop the guest first if it is running
running=$(xl list | awk 'NR > 1 {print $1}' | grep "${guestname}" \ if xl_list_contains $guestname; then
|| echo)
if [ "${running}" = "${guestname}" ]; then
echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1 echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1
xl destroy ${guestname} >> ${LOGFILE} 2>&1 xl destroy ${guestname} >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@@ -719,20 +727,25 @@ case ${cmd} in
fi fi
;; ;;
status) status)
guestname="${arg1}"
if [ -n "${guestname}" ]; then single_status() (
guestname="${1}"
check_guest_exist ${guestname} check_guest_exist ${guestname}
if xl list | awk 'NR > 1 {print $1}' | grep "${guestname}" > \ if xl_list_contains $guestname; then
/dev/null 2>&1; then
echo "${guestname}: Running" echo "${guestname}: Running"
else else
echo "${guestname}: Stopped" echo "${guestname}: Stopped"
fi fi
)
guestname="${arg1}"
if [ -n "${guestname}" ]; then
single_status ${guestname}
else else
guestlist=$($this list) guestlist=$($this list)
if [ -n "${guestlist}" ]; then if [ -n "${guestlist}" ]; then
for f in ${guestlist}; do for f in ${guestlist}; do
$this status $f single_status $f
done done
fi fi
fi fi