From: Eric Blake <eblake@redhat.com>
To: Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>
Cc: lcapitulino@redhat.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com
Subject: Re: [Qemu-devel] [PATCH v7 2/2] qemu-ga: sample fsfreeze hooks
Date: Fri, 07 Dec 2012 11:34:50 -0700 [thread overview]
Message-ID: <50C236CA.5050801@redhat.com> (raw)
In-Reply-To: <20121207083932.10624.8173.stgit@melchior2.sdl.hitachi.co.jp>
[-- Attachment #1: Type: text/plain, Size: 2930 bytes --]
On 12/07/2012 01:39 AM, Tomoki Sekiyama wrote:
> Adds sample hook scripts for --fsfreeze-hook option of qemu-ga.
> - fsfreeze-hook : execute scripts in fsfreeze-hook.d/
> - fsfreeze-hook.d/mysql-flush.sh.sample : quiesce MySQL before snapshot
>
> Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>
> ---
> @@ -0,0 +1,33 @@
> +#!/bin/sh
> +
> +# This script is executed when a guest agent receives fsfreeze-freeze and
> +# fsfreeze-thaw command, if it is specified in --fsfreeze-hook (-F)
> +# option of qemu-ga or placed in default path (/etc/qemu/fsfreeze-hook).
> +# When the agent receives fsfreeze-freeze request, this script is issued with
> +# "freeze" argument before the filesystem is freezed. And for fsfreeze-thaw
s/freezed/frozen/
> +
> +# Iterate executables in directory "fsfreeze-hook.d" with the specified args
> +[ ! -d "$FSFREEZE_D" ] && exit 1
Do you really want to fail the entire operation if the directory doesn't
exist? Shouldn't you instead exit 0 because there is nothing to do?
> +for file in "$FSFREEZE_D"/* ; do
> + is_ignored_file "$file" && continue
> + [ -x "$file" ] || continue
> + echo "$(date): execute $file $@" >>$LOGFILE
This is unsafe (although the worst that will happen is a poor message to
the log file). $file might contain backslash, and echo cannot portably
be mixed with backslash. Use printf(1) instead.
> + "$file" "$@" >>$LOGFILE 2>&1
> + STATUS=$?
> + echo "$(date): $file finished with status=$STATUS" >>$LOGFILE
Again.
> @@ -0,0 +1,55 @@
> +#!/bin/sh
> +
> +# Flush MySQL tables to the disk before the filesystem is freezed.
s/freezed/frozen/
> +# At the same time, this keeps a read lock in order to avoid write accesses
> +# from the other clients until the filesystem is thawed.
> +
> +MYSQL="/usr/bin/mysql"
> +MYSQL_OPTS="-uroot" #"-prootpassword"
> +FIFO=/tmp/mysql-flush.fifo
> +MYSQL_CMD="$MYSQL $MYSQL_OPTS"
> +
> +# Check mysql is installed and the server running
> +[ -x $MYSQL ] && $MYSQL_CMD < /dev/null || exit 0
Safe as written, since you just initialized $MYSQL above; but risky,
since the mere use of MYSQL in the initialization might encourage
someone to point to an alternate path that includes spaces. Then again,
if they do that, then MYSQL_CMD is broken. It might be better to be
explicit and write
[ -x "$MYSQL" ] && "$MYSQL" $MYSQL_OPTS < /dev/null
but I won't insist.
> + # for InnoDB, wait until every log is flushed
> + INNODB_STATUS=$(mktemp /tmp/mysql-flush.XXXXXX)
> + [ $? -ne 0 ] && exit 2
> + trap "rm -f $INNODB_STATUS" SIGINT
POSIX says that 'trap foo INT' is required to work, but 'trap foo
SIGINT' is optional. Also, shouldn't you also worry about HUP, ALRM,
and TERM?
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]
next prev parent reply other threads:[~2012-12-07 18:35 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-07 8:39 [Qemu-devel] [PATCH v7 0/2] qemu-ga: add hook to quiesce the guest on fsfreeze-freeze/thaw Tomoki Sekiyama
2012-12-07 8:39 ` [Qemu-devel] [PATCH v7 1/2] qemu-ga: execute " Tomoki Sekiyama
2012-12-07 13:52 ` Luiz Capitulino
2012-12-07 8:39 ` [Qemu-devel] [PATCH v7 2/2] qemu-ga: sample fsfreeze hooks Tomoki Sekiyama
2012-12-07 13:55 ` Luiz Capitulino
2012-12-07 17:47 ` mdroth
2012-12-07 18:29 ` Luiz Capitulino
2012-12-07 18:22 ` Eric Blake
2012-12-07 18:31 ` Luiz Capitulino
2012-12-07 18:37 ` Eric Blake
2012-12-07 18:57 ` Luiz Capitulino
2012-12-10 6:23 ` Tomoki Sekiyama
2012-12-07 18:34 ` Eric Blake [this message]
2012-12-10 6:23 ` Tomoki Sekiyama
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50C236CA.5050801@redhat.com \
--to=eblake@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=tomoki.sekiyama.qu@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).