Revision 96610da2

b/.gitignore
70 70
*.tp
71 71
*.vr
72 72
*.d
73
!scripts/qemu-guest-agent/fsfreeze-hook.d
73 74
*.o
74 75
*.lo
75 76
*.la
b/Makefile
232 232
# avoid old build problems by removing potentially incorrect old files
233 233
	rm -f config.mak op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h
234 234
	rm -f qemu-options.def
235
	find . -name '*.[od]' -exec rm -f {} +
235
	find . -name '*.[od]' -type f -exec rm -f {} +
236 236
	rm -f *.a *.lo $(TOOLS) $(HELPERS-y) qemu-ga TAGS cscope.* *.pod *~ */*~
237 237
	rm -Rf .libs
238 238
	rm -f qemu-img-cmds.h
b/scripts/qemu-guest-agent/fsfreeze-hook
1
#!/bin/sh
2

  
3
# This script is executed when a guest agent receives fsfreeze-freeze and
4
# fsfreeze-thaw command, if it is specified in --fsfreeze-hook (-F)
5
# option of qemu-ga or placed in default path (/etc/qemu/fsfreeze-hook).
6
# When the agent receives fsfreeze-freeze request, this script is issued with
7
# "freeze" argument before the filesystem is frozen. And for fsfreeze-thaw
8
# request, it is issued with "thaw" argument after filesystem is thawed.
9

  
10
LOGFILE=/var/log/qga-fsfreeze-hook.log
11
FSFREEZE_D=$(dirname -- "$0")/fsfreeze-hook.d
12

  
13
# Check whether file $1 is a backup or rpm-generated file and should be ignored
14
is_ignored_file() {
15
    case "$1" in
16
        *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave | *.sample)
17
            return 0 ;;
18
    esac
19
    return 1
20
}
21

  
22
# Iterate executables in directory "fsfreeze-hook.d" with the specified args
23
[ ! -d "$FSFREEZE_D" ] && exit 0
24
for file in "$FSFREEZE_D"/* ; do
25
    is_ignored_file "$file" && continue
26
    [ -x "$file" ] || continue
27
    printf "$(date): execute $file $@\n" >>$LOGFILE
28
    "$file" "$@" >>$LOGFILE 2>&1
29
    STATUS=$?
30
    printf "$(date): $file finished with status=$STATUS\n" >>$LOGFILE
31
done
32

  
33
exit 0
b/scripts/qemu-guest-agent/fsfreeze-hook.d/mysql-flush.sh.sample
1
#!/bin/sh
2

  
3
# Flush MySQL tables to the disk before the filesystem is frozen.
4
# At the same time, this keeps a read lock in order to avoid write accesses
5
# from the other clients until the filesystem is thawed.
6

  
7
MYSQL="/usr/bin/mysql"
8
MYSQL_OPTS="-uroot" #"-prootpassword"
9
FIFO=/var/run/mysql-flush.fifo
10

  
11
# Check mysql is installed and the server running
12
[ -x "$MYSQL" ] && "$MYSQL" $MYSQL_OPTS < /dev/null || exit 0
13

  
14
flush_and_wait() {
15
    printf "FLUSH TABLES WITH READ LOCK \\G\n"
16
    trap 'printf "$(date): $0 is killed\n">&2' HUP INT QUIT ALRM TERM
17
    read < $FIFO
18
    printf "UNLOCK TABLES \\G\n"
19
    rm -f $FIFO
20
}
21

  
22
case "$1" in
23
    freeze)
24
        mkfifo $FIFO || exit 1
25
        flush_and_wait | "$MYSQL" $MYSQL_OPTS &
26
        # wait until every block is flushed
27
        while [ "$(echo 'SHOW STATUS LIKE "Key_blocks_not_flushed"' |\
28
                 "$MYSQL" $MYSQL_OPTS | tail -1 | cut -f 2)" -gt 0 ]; do
29
            sleep 1
30
        done
31
        # for InnoDB, wait until every log is flushed
32
        INNODB_STATUS=$(mktemp /tmp/mysql-flush.XXXXXX)
33
        [ $? -ne 0 ] && exit 2
34
        trap "rm -f $INNODB_STATUS; exit 1" HUP INT QUIT ALRM TERM
35
        while :; do
36
            printf "SHOW ENGINE INNODB STATUS \\G" |\
37
                "$MYSQL" $MYSQL_OPTS > $INNODB_STATUS
38
            LOG_CURRENT=$(grep 'Log sequence number' $INNODB_STATUS |\
39
                          tr -s ' ' | cut -d' ' -f4)
40
            LOG_FLUSHED=$(grep 'Log flushed up to' $INNODB_STATUS |\
41
                          tr -s ' ' | cut -d' ' -f5)
42
            [ "$LOG_CURRENT" = "$LOG_FLUSHED" ] && break
43
            sleep 1
44
        done
45
        rm -f $INNODB_STATUS
46
        ;;
47

  
48
    thaw)
49
        [ ! -p $FIFO ] && exit 1
50
        echo > $FIFO
51
        ;;
52

  
53
    *)
54
        exit 1
55
        ;;
56
esac

Also available in: Unified diff