Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created April 20, 2011 06:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tagomoris/930505 to your computer and use it in GitHub Desktop.
Save tagomoris/930505 to your computer and use it in GitHub Desktop.
Run "check" about specified md device if it's status is "idle"
#!/bin/sh
TARGET_MD=$1
### call md verifying when idle.
######
# HOW TO USE
### md_sync_call.sh md0
error_exit() {
echo $*
exit 1
}
is_root_user() {
UNAME=`whoami`
if [ $UNAME != "root" ]; then
error_exit "md_sync_call.sh: requested operation requires superuser privilege"
fi
return 0
}
md_exists() {
if [ -d /sys/block/$TARGET_MD ]; then
return 0
fi
error_exit "md_sync_call.sh: no such md:" $TARGET_MD
}
in_idle() {
MD_STATE=`cat /sys/block/$TARGET_MD/md/sync_action`
if [ $MD_STATE != "idle" ]; then
error_exit "md_sync_call.sh: target md" $TARGET_MD "is not in idle:" $MD_STATE
fi
return 0
}
call_check() {
echo "check" > /sys/block/$TARGET_MD/md/sync_action
return 0
}
is_root_user
md_exists
in_idle
call_check
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment