dlm: master - man: fix dlm.conf man page
by David Teigland
Gitweb: http://git.fedorahosted.org/git/?p=dlm.git;a=commitdiff;h=41f4121768ab494...
Commit: 41f4121768ab4948898945007f49168acfac6c9f
Parent: 2b697668c41a12e816a153dde96dea43bb0094d9
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri May 17 11:06:12 2013 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri May 17 11:06:12 2013 -0500
man: fix dlm.conf man page
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
dlm_controld/dlm.conf.5 | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlm_controld/dlm.conf.5 b/dlm_controld/dlm.conf.5
index 95f74b9..793435a 100644
--- a/dlm_controld/dlm.conf.5
+++ b/dlm_controld/dlm.conf.5
@@ -349,15 +349,15 @@ Example of nodeid 1 as master of all resources:
lockspace foo nodir=1
.br
-master node=1
+master foo node=1
Example of nodeid's 1 and 2 as masters of all resources:
lockspace foo nodir=1
.br
-master node=1
+master foo node=1
.br
-master node=2
+master foo node=2
Lock management will be partitioned among the available masters. There
can be any number of masters defined. The designated master nodes will
@@ -376,9 +376,9 @@ can also be assigned to master nodes, e.g.
lockspace foo nodir=1
.br
-master node=1 weight=2
+master foo node=1 weight=2
.br
-master node=2 weight=1
+master foo node=2 weight=1
In which case node 1 will master 2/3 of the total resources and node 2
will master the other 1/3.
11 years
cluster: RHEL510 - fence_ipmilan: Fix return code when 'cycle' method is used.
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=f6df91f927b...
Commit: f6df91f927b79c1c8e3078d1bcaf7ff0eb9383f6
Parent: 0c2a7efa4eb476e776ce333c1e6a8245be2ba719
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Fri May 17 12:54:33 2013 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Fri May 17 12:54:33 2013 +0200
fence_ipmilan: Fix return code when 'cycle' method is used.
Resolves: rhbz#961119
---
fence/agents/ipmilan/ipmilan.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/fence/agents/ipmilan/ipmilan.c b/fence/agents/ipmilan/ipmilan.c
index 7134916..fd4afaf 100644
--- a/fence/agents/ipmilan/ipmilan.c
+++ b/fence/agents/ipmilan/ipmilan.c
@@ -1421,6 +1421,7 @@ main(int argc, char **argv)
if (!strcasecmp(method, "cycle")) {
ret = ipmi_cycle(i);
+ translated_ret = (ret==0?ERR_OFF_SUCCESSFUL:ERR_OFF_FAIL);
} else {
/* Original onoff method */
ret = ipmi_off(i);
11 years
cluster: RHEL510 - rgmanager: Update the Oracle resource agents to support Oracle 11g
by Ryan McCabe
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=0c2a7efa4eb...
Commit: 0c2a7efa4eb476e776ce333c1e6a8245be2ba719
Parent: 43c60106f4078699502771ff1be25c4bd6369f41
Author: Ryan McCabe <rmccabe(a)redhat.com>
AuthorDate: Thu May 16 16:51:55 2013 -0400
Committer: Ryan McCabe <rmccabe(a)redhat.com>
CommitterDate: Thu May 16 16:53:26 2013 -0400
rgmanager: Update the Oracle resource agents to support Oracle 11g
Add Oracle 11g support to the orainstance, oralistener, and oracledb
resource agents.
Resolves: rhbz#670024
Signed-off-by: Ryan McCabe <rmccabe(a)redhat.com>
---
rgmanager/src/resources/oracledb.sh | 428 ++++++++++++++++++++------------
rgmanager/src/resources/orainstance.sh | 298 +++++++++++++---------
rgmanager/src/resources/oralistener.sh | 224 ++++++++++-------
3 files changed, 578 insertions(+), 372 deletions(-)
diff --git a/rgmanager/src/resources/oracledb.sh b/rgmanager/src/resources/oracledb.sh
index bcb367f..2bbb807 100755
--- a/rgmanager/src/resources/oracledb.sh
+++ b/rgmanager/src/resources/oracledb.sh
@@ -1,22 +1,27 @@
#!/bin/bash
#
-# Copyright 2003-2004, 2006-2008 Red Hat, Inc.
+# Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved.
+# Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Author(s):
# Hardy Merrill <hmerrill at redhat.com>
# Lon Hohberger <lhh at redhat.com>
# Michael Moon <Michael dot Moon at oracle.com>
-#
-# This program is Open Source software. You may modify and/or redistribute
-# it persuant to the terms of the Open Software License version 2.1, which
-# is available from the following URL and is included herein by reference:
-#
-# http://opensource.org/licenses/osl-2.1.php
-#
-# chkconfig: 345 99 01
-# description: Service script for starting/stopping \
-# Oracle(R) Database 10g on \
-# Red Hat Enterprise Linux 5
+# Ryan McCabe <rmccabe at redhat.com>
#
# NOTES:
#
@@ -35,15 +40,16 @@
# Oracle is a registered trademark of Oracle Corporation.
# Oracle9i is a trademark of Oracle Corporation.
# Oracle10g is a trademark of Oracle Corporation.
+# Oracle11g is a trademark of Oracle Corporation.
# All other trademarks are property of their respective owners.
#
-. /etc/init.d/functions
+. $(dirname $0)/ocf-shellfuncs
+. $(dirname $0)/utils/config-utils.sh
+. $(dirname $0)/utils/messages.sh
+. $(dirname $0)/utils/ra-skelet.sh
-#
-# Source stuff from /etc/sysconfig, but this may be overridden if
-# this is being called as a cluster resource agent instead.
-#. /etc/sysconfig/oracledb
+. /etc/init.d/functions
declare SCRIPT="`basename $0`"
declare SCRIPTDIR="`dirname $0`"
@@ -122,6 +128,15 @@ declare -r DB_PROCNAMES="pmon"
declare -r LSNR_PROCNAME="tnslsnr"
#declare -r LSNR_PROCNAME="tnslsnrXX" # testing
+# clulog will not log messages when run by the oracle user.
+# This is a hack to work around that.
+if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then
+ ocf_log() {
+ prio=$1
+ shift
+ logger -i -p daemon."$prio" -- "$*"
+ }
+fi
##########################################################
# (Hopefully) No user-serviceable parts below this line. #
@@ -134,10 +149,10 @@ meta_data()
<version>1.0</version>
<longdesc lang="en">
- Oracle 10g Failover Instance
+ Oracle 10g/11g Failover Instance
</longdesc>
<shortdesc lang="en">
- Oracle 10g Failover Instance
+ Oracle 10g/11g Failover Instance
</shortdesc>
<parameters>
@@ -164,7 +179,6 @@ meta_data()
<content type="string"/>
</parameter>
-
<parameter name="user" required="1">
<longdesc lang="en">
Oracle user name. This is the user name of the Oracle
@@ -191,8 +205,10 @@ meta_data()
<longdesc lang="en">
This is the Oracle installation type:
base - Database Instance and Listener only
+ base-11g - Oracle11g Database Instance and Listener Only
base-em (or 10g) - Database, Listener, Enterprise Manager,
and iSQL*Plus
+ base-em-11g - Database, Listener, Enterprise Manager dbconsole
ias (or 10g-ias) - Internet Application Server (Infrastructure)
</longdesc>
<shortdesc lang="en">
@@ -230,7 +246,7 @@ meta_data()
<action name="monitor" depth="10" timeout="30" interval="30"/>
<action name="meta-data" timeout="5"/>
- <action name="verify-all" timeout="5"/>
+ <action name="validate-all" timeout="5"/>
</actions>
<special tag="rgmanager">
@@ -240,84 +256,55 @@ meta_data()
EOT
}
-
-#
-# "action"-like macro supporting functions
-#
-faction()
-{
- echo -n "$1"
- shift
- $*
- if [ $? -eq 0 ]; then
- echo_success
- echo
- return 0
- fi
-
- echo_failure
- echo
- return 1
-}
-
-
#
-# Start Oracle9i (database portion)
+# Start Oracle9i/10g/11g (database portion)
#
start_db()
{
- declare tmpfile
- declare logfile
declare -i rv
+ declare startup_cmd
+ declare startup_stdout
- tmpfile=$(mktemp /tmp/$SCRIPT-start.tmp.XXXXXX)
- logfile=$(mktemp /tmp/$SCRIPT-start.log.XXXXXX)
+ ocf_log info "Starting Oracle DB $ORACLE_SID"
- #
# Set up our sqlplus script. Basically, we're trying to
# capture output in the hopes that it's useful in the case
# that something doesn't work properly.
- #
- echo "startup" > $tmpfile
- echo "quit" >> $tmpfile
-
- sqlplus "/ as sysdba" < $tmpfile &> $logfile
+ startup_cmd="set heading off;\nstartup;\nquit;\n"
+ startup_stdout=$(echo -e "$startup_cmd" | sqlplus -S "/ as sysdba")
rv=$?
- # Dump logfile to /var/log/messages
- initlog -q -c "cat $logfile"
-
+ # Dump output to syslog for debugging
+ ocf_log debug "[$ORACLE_SID] [$rv] sent $startup_cmd"
+ ocf_log debug "[$ORACLE_SID] [$rv] got $startup_stdout"
+
if [ $rv -ne 0 ]; then
- echo "ORACLE_HOME Incorrectly set?"
- echo "See $logfile for more information."
- return 1
+ ocf_log error "Starting Oracle DB $ORACLE_SID failed, sqlplus returned $rv"
+ return 1
fi
- #
# If we see:
# ORA-.....: failure, we failed
- #
-
- rm -f $tmpfile
- grep -q "^ORA-" $logfile
- if [ $? -eq 0 ]; then
- rm -f $tmpfile
- echo "ORACLE_SID Incorrectly set?"
- echo "See $logfile for more information."
- return 1
+ # Troubleshooting:
+ # ORA-00845 - Try rm -f /dev/shm/ora_*
+ # ORA-01081 - Try echo -e 'shutdown abort;\nquit;'|sqlplus "/ as sysdba"
+ if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then
+ ocf_log error "Starting Oracle DB $ORACLE_SID failed, found errors in stdout"
+ return 1
fi
+ ocf_log info "Started Oracle DB $ORACLE_SID successfully"
return 0
}
#
-# Stop Oracle9i (database portion)
+# Stop Oracle (database portion)
#
stop_db()
{
- declare tmpfile
- declare logfile
+ declare stop_cmd
+ declare stop_stdout
declare -i rv
declare how_shutdown="$1"
@@ -325,38 +312,30 @@ stop_db()
how_shutdown="immediate"
fi
- tmpfile=$(mktemp /tmp/$SCRIPT-stop.tmp.XXXXXX)
- logfile=$(mktemp /tmp/$SCRIPT-stop.log.XXXXXX)
+ ocf_log info "Stopping Oracle DB $ORACLE_SID $how_shutdown"
# Setup for Stop ...
- echo "shutdown $how_shutdown" > $tmpfile
- echo "quit" >> $tmpfile
-
- sqlplus "/ as sysdba" < $tmpfile &> $logfile
+ stop_cmd="set heading off;\nshutdown $how_shutdown;\nquit;\n"
+ stop_stdout=$(echo -e "$stop_cmd" | sqlplus -S "/ as sysdba")
rv=$?
- # Dump logfile to /var/log/messages
- initlog -q -c "cat $logfile"
-
+ # Log stdout of the stop command
+ ocf_log debug "[$ORACLE_SID] sent stop command $stop_cmd"
+ ocf_log debug "[$ORACLE_SID] got $stop_stdout"
+
+ # sqlplus returned failure. We'll return failed to rhcs
if [ $rv -ne 0 ]; then
- echo "ORACLE_HOME Incorrectly set?"
- echo "See $logfile for more information."
- return 1
+ ocf_log error "Stopping Oracle DB $ORACLE_SID failed, sqlplus returned $rv"
+ return 1
fi
- #
- # If we see 'failure' in the log, we're done.
- #
- rm -f $tmpfile
- grep -q "^ORA-" $logfile
- if [ $? -eq 0 ]; then
- echo_failure
- echo
- echo "Possible reason: ORACLE_SID Incorrectly set."
- echo "See $logfile for more information."
- return 1
+ # If we see 'ORA-' or 'failure' in stdout, we're done.
+ if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then
+ ocf_log error "Stopping Oracle DB $ORACLE_SID failed, errors in stdout"
+ return 1
fi
+ ocf_log info "Stopped Oracle DB $ORACLE_SID successfully"
return 0
}
@@ -372,12 +351,15 @@ force_cleanup()
# Patch from Shane Bradley to fix 471266
pids=`ps ax | grep $ORACLE_HOME | grep "ora_.*_${ORACLE_SID}" | grep -v grep | awk '{print $1}'`
- initlog -n $SCRIPT -s "<err> Not all Oracle processes exited cleanly, killing"
-
+ ocf_log error "Not all Oracle processes for $ORACLE_SID exited cleanly, killing"
+
for pid in $pids; do
kill -9 $pid
- if [ $? -eq 0 ]; then
- initlog -n $SCRIPT -s "Killed $pid"
+ rv=$?
+ if [ $rv -eq 0 ]; then
+ ocf_log info "Cleanup $ORACLE_SID Killed PID $pid"
+ else
+ ocf_log error "Cleanup $ORACLE_SID Kill PID $pid failed: $rv"
fi
done
@@ -392,14 +374,19 @@ force_cleanup()
exit_idle()
{
declare -i n=0
+
+ ocf_log debug "Waiting for Oracle processes for $ORACLE_SID to terminate..."
while ps ax | grep $ORACLE_HOME | grep -q -v grep; do
if [ $n -ge 90 ]; then
+ ocf_log debug "Timed out while waiting for Oracle processes for $ORACLE_SID to terminate"
force_cleanup
return 0
fi
sleep 1
((n++))
done
+
+ ocf_log debug "All Oracle processes for $ORACLE_SID have terminated"
return 0
}
@@ -438,24 +425,27 @@ get_db_status()
for (( i=$RESTART_RETRIES ; i; i-- )) ; do
# this db process is down - stop and
# (re)start all ora_XXXX_$ORACLE_SID processes
- initlog -q -n $SCRIPT -s "Restarting Oracle Database..."
+ ocf_log info "Restarting Oracle Database $ORACLE_SID"
stop_db immediate
- if [ $? != 0 ] ; then
+ if [ $? -ne 0 ] ; then
# stop failed - return 1
+ ocf_log error "Error stopping Oracle Database $ORACLE_SID"
return 1
fi
start_db
- if [ $? == 0 ] ; then
+ if [ $? -eq 0 ] ; then
# ora_XXXX_$ORACLE_SID processes started
# successfully, so break out of the
# stop/start # 'for' loop
+ ocf_log info "Restarted Oracle Database $ORACLE_SID successfully"
break
fi
done
if [ $i -eq 0 ]; then
# stop/start's failed - return 1 (failure)
+ ocf_log error "Failed to restart Oracle Database $ORACLE_SID after $RESTART_RETRIES tries"
return 1
fi
done
@@ -471,42 +461,46 @@ get_lsnr_status()
declare -i subsys_lock=$1
declare -i rv
- status $LSNR_PROCNAME
+ ocf_log debug "Checking status for listener $ORACLE_LISTENER"
+ lsnrctl status "$ORACLE_LISTENER" >& /dev/null
rv=$?
- if [ $rv == 0 ] ; then
+ if [ $rv -eq 0 ] ; then
+ ocf_log debug "Listener $ORACLE_LISTENER is up"
return 0 # Listener is running fine
fi
- #
# We're not supposed to be running, and we are,
# in fact, not running. Return 3
- #
if [ $subsys_lock -ne 0 ]; then
+ ocf_log debug "Listener $ORACLE_LISTENER is stopped as expected"
return 3
fi
- #
# Listener is NOT running (but should be) - try to restart
- #
for (( i=$RESTART_RETRIES ; i; i-- )) ; do
-
- action "Restarting Oracle listener:" lsnrctl start \
- $ORACLE_LISTENER
- lsnrctl status $ORACLE_LISTENER >& /dev/null
- if [ $? == 0 ] ; then
+ ocf_log info "Listener $ORACLE_LISTENER is down, attempting to restart"
+ lsnrctl start "$ORACLE_LISTENER" >& /dev/null
+ lsnrctl status "$ORACLE_LISTENER" >& /dev/null
+ if [ $? -eq 0 ] ; then
+ ocf_log info "Listener $ORACLE_LISTENER was restarted successfully"
break # Listener was (re)started and is running fine
fi
done
if [ $i -eq 0 ]; then
# stop/start's failed - return 1 (failure)
+ ocf_log error "Failed to restart listener $ORACLE_LISTENER after $RESTART_RETRIES tries"
return 1
fi
- status $LSNR_PROCNAME
- if [ $? != 0 ] ; then
+ lsnrctl_stdout=$(lsnrctl status "$ORACLE_LISTENER")
+ rv=$?
+ if [ $rv -ne 0 ] ; then
+ ocf_log error "Starting listener $ORACLE_LISTENER failed: $rv output $lsnrctl_stdout"
return 1 # Problem restarting the Listener
fi
+
+ ocf_log info "Listener $ORACLE_LISTENER started successfully"
return 0 # Success restarting the Listener
}
@@ -541,12 +535,12 @@ get_opmn_proc_status()
_status=`echo $_status | cut -f2 -d' '`
if [ "${_status}" == "Alive" ] || [ "${_status}" == "Init" ]; then
if [ $i -lt $RESTART_RETRIES ] ; then
- echo " $comp$type_pretty restarted"
+ ocf_log info "$comp$type_pretty restarted"
fi
- echo " $comp$type_pretty (pid $_pid) is running..."
+ ocf_log info "$comp$type_pretty (pid $_pid) is running..."
break
else
- echo " $comp$type_pretty is stopped"
+ ocf_log info "$comp$type_pretty is stopped"
#
# Try to restart it, but don't worry if we fail. OPMN
@@ -564,6 +558,7 @@ get_opmn_proc_status()
if [ $i -eq 0 ]; then
# restarts failed - return 1 (failure)
+ ocf_log error "Failed to restart OPMN process $comp"
return 1
fi
@@ -584,7 +579,7 @@ get_opmn_status()
#
# OPMN not running??
#
- echo "opmn is stopped"
+ ocf_log info "OPMN is stopped"
if [ $subsys_lock -eq 0 ]; then
#
@@ -600,8 +595,8 @@ get_opmn_status()
#
# Print out the PIDs for everyone.
#
- echo "opmn is running..."
- echo "opmn components:"
+ ocf_log info "OPMN is running..."
+ ocf_log info "opmn components:"
#
# Check the OPMN-managed processes
@@ -615,6 +610,7 @@ get_opmn_status()
# restarted.
#
if [ $ct_errors -ne 0 ]; then
+ ocf_log error "$ct_errors errors occurred while restarting OPMN-managed processes"
return 1
fi
return 0
@@ -659,10 +655,7 @@ update_status()
#
oops()
{
- echo "Please configure this script ($0) to"
- echo "match your installation."
- echo
- echo " $1 failed validation checks."
+ ocf_log error "$ORACLE_SID: Fatal: $1 failed validation checks"
exit 1
}
@@ -673,6 +666,8 @@ oops()
#
validation_checks()
{
+ ocf_log debug "Validating configuration for $ORACLE_SID"
+
#
# If the oracle user doesn't exist, we're done.
#
@@ -701,8 +696,12 @@ validation_checks()
ORACLE_TYPE="base-em"
elif [ "$ORACLE_TYPE" = "10g-ias" ] || [ "$ORACLE_TYPE" = "ias" ]; then
ORACLE_TYPE="ias"
+ elif [ "$ORACLE_TYPE" = "11g" ] || [ "$ORACLE_TYPE" = "base-em-11g" ]; then
+ ORACLE_TYPE="base-em-11g"
+ elif [ "$ORACLE_TYPE" = "base-11g" ]; then
+ ORACLE_TYPE="base-11g"
else
- oops ORACLE_TYPE
+ oops "ORACLE_TYPE $ORACLE_TYPE"
fi
#
@@ -715,7 +714,7 @@ validation_checks()
# Oracle needs to be run as the Oracle user, not root!
#
if [ "`id -u`" = "0" ]; then
- echo "Restarting $0 as $ORACLE_USER."
+ #echo "Restarting $0 as $ORACLE_USER."
#
# Breaks on RHEL5
# exec sudo -u $ORACLE_USER $0 $*
@@ -727,75 +726,191 @@ validation_checks()
#
# If we're not root and not the Oracle user, we're done.
#
- [ "`id -u`" = "`id -u $ORACLE_USER`" ] || exit 1
- [ "`id -g`" = "`id -g $ORACLE_USER`" ] || exit 1
+ [ "`id -u`" = "`id -u $ORACLE_USER`" ] || oops "not ORACLE_USER after su"
+ [ "`id -g`" = "`id -g $ORACLE_USER`" ] || oops "not ORACLE_GROUP after su"
#
# Go home.
#
- cd $ORACLE_HOME
+ cd "$ORACLE_HOME"
+ ocf_log debug "Validation checks for $ORACLE_SID succeeded"
return 0
}
#
-# Start Oracle9i Application Server Infrastructure
+# Start Oracle 9i/10g/11g Application Server Infrastructure
#
start_oracle()
{
- faction "Starting Oracle Database:" start_db || return 1
- action "Starting Oracle Listener:" lsnrctl start $ORACLE_LISTENER || return 1
+ ocf_log info "Starting service $ORACLE_SID"
+
+ start_db
+ rv=$?
+ if [ $rv -ne 0 ]; then
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ fi
+
+ ocf_log info "Starting listener $ORACLE_LISTENER"
+ lsnrctl_stdout=$(lsnrctl start "$ORACLE_LISTENER")
+ rv=$?
+ if [ $rv -ne 0 ]; then
+ ocf_log debug "[$ORACLE_SID] Listener $ORACLE_LISTENER start returned $rv output $lsnrctl_stdout"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ fi
if [ "$ORACLE_TYPE" = "base-em" ]; then
- action "Starting iSQL*Plus:" isqlplusctl start || return 1
- action "Starting Oracle EM DB Console:" emctl start dbconsole || return 1
+ ocf_log info "Starting iSQL*Plus for $ORACLE_SID"
+ isqlplusctl start
+ if [ $? -ne 0 ]; then
+ ocf_log error "iSQL*Plus startup for $ORACLE_SID failed"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "iSQL*Plus startup for $ORACLE_SID succeeded"
+ fi
+
+ ocf_log info "Starting Oracle EM DB Console for $ORACLE_SID"
+ emctl start dbconsole
+ if [ $? -ne 0 ]; then
+ ocf_log error "Oracle EM DB Console startup for $ORACLE_SID failed"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Oracle EM DB Console startup for $ORACLE_SID succeeded"
+ fi
elif [ "$ORACLE_TYPE" = "ias" ]; then
- action "Starting Oracle EM:" emctl start em || return 1
- action "Starting iAS Infrastructure:" opmnctl startall || return 1
+ ocf_log info "Starting Oracle EM for $ORACLE_SID"
+ emctl start em
+ if [ $? -ne 0 ]; then
+ ocf_log error "Oracle EM startup for $ORACLE_SID failed"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Oracle EM startup for $ORACLE_SID succeeded"
+ fi
+
+ ocf_log info "Starting iAS Infrastructure for $ORACLE_SID"
+ opmnctl startall
+ if [ $? -ne 0 ]; then
+ ocf_log error "iAS Infrastructure startup for $ORACLE_SID failed"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "iAS Infrastructure startup for $ORACLE_SID succeeded"
+ fi
+ elif [ "$ORACLE_TYPE" = "base-em-11g" ]; then
+ ocf_log info "Starting Oracle EM DB Console for $ORACLE_SID"
+ emctl start dbconsole
+ if [ $? -ne 0 ]; then
+ ocf_log error "Oracle EM DB Console startup for $ORACLE_SID failed"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Oracle EM DB Console startup for $ORACLE_SID succeeded"
+ fi
fi
if [ -n "$LOCKFILE" ]; then
- touch $LOCKFILE
+ touch "$LOCKFILE"
fi
+
+ ocf_log info "Starting service $ORACLE_SID completed successfully"
return 0
}
#
-# Stop Oracle9i Application Server Infrastructure
+# Stop Oracle 9i/10g/11g Application Server Infrastructure
#
stop_oracle()
{
+ ocf_log info "Stopping service $ORACLE_SID"
+
if ! [ -e "$ORACLE_HOME/bin/lsnrctl" ]; then
- echo "Oracle Listener Control is not available"
- echo " ($ORACLE_HOME not mounted?)"
+ ocf_log error "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)"
return 0
fi
if [ "$ORACLE_TYPE" = "base-em" ]; then
- action "Stopping Oracle EM DB Console:" emctl stop dbconsole || return 1
- action "Stopping iSQL*Plus:" isqlplusctl stop || return 1
+ ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID"
+ emctl stop dbconsole
+ if [ $? -ne 0 ]; then
+ ocf_log error "Stopping Oracle EM DB Console for $ORACLE_SID failed"
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID succeeded"
+ fi
+
+ ocf_log info "Stopping iSQL*Plus for $ORACLE_SID"
+ isqlplusctl stop
+ if [ $? -ne 0 ]; then
+ ocf_log error "Stopping iSQL*Plus for $ORACLE_SID failed"
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Stopping iSQL*Plus for $ORACLE_SID succeeded"
+ fi
elif [ "$ORACLE_TYPE" = "ias" ]; then
- action "Stopping iAS Infrastructure:" opmnctl stopall || return 1
- action "Stopping Oracle EM:" emctl stop em || return 1
+ ocf_log info "Stopping iAS Infrastructure for $ORACLE_SID"
+ opmnctl stopall
+ if [ $? -ne 0 ]; then
+ ocf_log error "Stopping iAS Infrastructure for $ORACLE_SID failed"
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Stopping iAS Infrastructure for $ORACLE_SID succeeded"
+ fi
+
+ ocf_log info "Stopping Oracle EM for $ORACLE_SID"
+ emctl stop em
+ if [ $? -ne 0 ]; then
+ ocf_log error "Stopping Oracle EM for $ORACLE_SID failed"
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Stopping Oracle EM for $ORACLE_SID succeeded"
+ fi
+ elif [ "$ORACLE_TYPE" = "base-em-11g" ]; then
+ ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID"
+ emctl stop dbconsole
+ if [ $? -ne 0 ]; then
+ ocf_log error "Stopping Oracle EM DB Console for $ORACLE_SID failed"
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
+ else
+ ocf_log info "Stopping Oracle EM DB Console for $ORACLE_SID succeeded"
+ fi
fi
- faction "Stopping Oracle Database:" stop_db immediate
+ stop_db immediate || stop_db abort
if [ $? -ne 0 ]; then
- faction "Stopping Oracle Database (hard):" stop_db abort || return 1
+ ocf_log error "Stopping service $ORACLE_SID failed"
+ return 1
fi
- action "Stopping Oracle Listener:" lsnrctl stop $ORACLE_LISTENER
- faction "Waiting for all Oracle processes to exit:" exit_idle
+ ocf_log info "Stopping listener $ORACLE_LISTENER for $ORACLE_SID"
+ lsnrctl_stdout=$(lsnrctl stop "$ORACLE_LISTENER")
+ rv=$?
+ if [ $? -ne 0 ]; then
+ ocf_log error "Listener $ORACLE_LISTENER stop failed for $ORACLE_SID: $rv output $lsnrctl_stdout"
+ # XXX - failure?
+ fi
+ exit_idle
if [ $? -ne 0 ]; then
- echo "WARNING: Not all Oracle processes exited cleanly"
+ ocf_log warning "WARNING: Not all Oracle processes exited cleanly for $ORACLE_SID"
fi
if [ -n "$LOCKFILE" ]; then
- rm -f $LOCKFILE
+ rm -f "$LOCKFILE"
fi
+
+ ocf_log info "Stopping service $ORACLE_SID succeeded"
return 0
}
@@ -823,10 +938,12 @@ status_oracle()
declare -i subsys_lock=1
declare -i last
+ ocf_log debug "Checking status for $ORACLE_SID depth $depth"
+
#
# Check for lock file. Crude and rudimentary, but it works
#
- if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
+ if [ -z "$LOCKFILE" ] || [ -f "$LOCKFILE" ]; then
subsys_lock=0
fi
@@ -840,9 +957,9 @@ status_oracle()
update_status $? $last
last=$?
- if [ "$ORACLE_TYPE" = "base-em" ]; then
+ if [ "$ORACLE_TYPE" = "base-em" ] || [ "$ORACLE_TYPE" = "base-em-11g" ]; then
# XXX Add isqlplus status check?!
- emctl status dbconsole 2>&1 | grep "is running"
+ emctl status dbconsole >&/dev/null
update_status $? $last
last=$?
elif [ "$ORACLE_TYPE" = "ias" ]; then
@@ -857,9 +974,10 @@ status_oracle()
# file back. XXX - this kosher?
#
if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then
- touch $LOCKFILE
+ touch "$LOCKFILE"
fi
+ ocf_log debug "Status returning $last for $ORACLE_SID"
return $last
}
diff --git a/rgmanager/src/resources/orainstance.sh b/rgmanager/src/resources/orainstance.sh
index a9f690d..ac71a92 100755
--- a/rgmanager/src/resources/orainstance.sh
+++ b/rgmanager/src/resources/orainstance.sh
@@ -1,11 +1,12 @@
#!/bin/bash
#
-# Copyright 2003-2004, 2006-2007 Red Hat, Inc.
+# Copyright 2003-2004, 2006-2013 Red Hat, Inc.
#
# Author(s):
# Hardy Merrill <hmerrill at redhat.com>
# Lon Hohberger <lhh at redhat.com>
# Michael Moon <Michael dot Moon at oracle.com>
+# Ryan McCabe <rmccabe at redhat.com>
#
# This program is Open Source software. You may modify and/or redistribute
# it persuant to the terms of the Open Software License version 2.1, which
@@ -13,11 +14,6 @@
#
# http://opensource.org/licenses/osl-2.1.php
#
-# chkconfig: 345 99 01
-# description: Service script for starting/stopping \
-# Oracle(R) Database 10g on \
-# Red Hat Enterprise Linux 5
-#
# NOTES:
#
# (1) You can comment out the LOCKFILE declaration below. This will prevent
@@ -35,6 +31,7 @@
# Oracle is a registered trademark of Oracle Corporation.
# Oracle9i is a trademark of Oracle Corporation.
# Oracle10g is a trademark of Oracle Corporation.
+# Oracle11g is a trademark of Oracle Corporation.
# All other trademarks are property of their respective owners.
#
#
@@ -48,6 +45,12 @@
# - SysV init support removed. Only usable with rgmanager
#
+# Grab the global RHCS helper functions
+. $(dirname $0)/ocf-shellfuncs
+. $(dirname $0)/utils/config-utils.sh
+. $(dirname $0)/utils/messages.sh
+. $(dirname $0)/utils/ra-skelet.sh
+
. /etc/init.d/functions
declare SCRIPT="`basename $0`"
@@ -60,60 +63,64 @@ ORACLE_SID=$OCF_RESKEY_name
# Optional parameters with default values
LISTENERS=$OCF_RESKEY_listeners
-LOCKFILE="/tmp/.oracle10g-${ORACLE_SID}.lock"
+LOCKFILE="$ORACLE_HOME/.orainstance-${ORACLE_SID}.lock"
[ -n "$OCF_RESKEY_lockfile" ] && LOCKFILE=$OCF_RESKEY_lockfile
export LISTENERS ORACLE_USER ORACLE_HOME ORACLE_SID LOCKFILE
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
-export PATH=$ORACLE_HOME/bin:$PATH
+export PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin
declare -i RESTART_RETRIES=3
declare -r DB_PROCNAMES="pmon"
declare -r LSNR_PROCNAME="tnslsnr"
+# clulog will not log messages when run by the oracle user.
+# This is a hack to work around that.
+if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then
+ ocf_log() {
+ prio=$1
+ shift
+ logger -i -p daemon."$prio" -- "$*"
+ }
+fi
#
# Start Oracle (database portion)
#
start_db() {
- declare tmpfile
- declare logfile
declare -i rv
+ declare startup_cmd
+ declare startup_stdout
- tmpfile=/tmp/$SCRIPT-start.$$
- logfile=/tmp/$SCRIPT-start.log.$$
+ ocf_log info "Starting Oracle DB $ORACLE_SID"
# Set up our sqlplus script. Basically, we're trying to
# capture output in the hopes that it's useful in the case
# that something doesn't work properly.
- echo "startup" > $tmpfile
- echo "quit" >> $tmpfile
-
- sqlplus "/ as sysdba" < $tmpfile > $logfile
+ startup_cmd="set heading off;\nstartup;\nquit;\n"
+ startup_stdout=$(echo -e "$startup_cmd" | sqlplus -S "/ as sysdba")
rv=$?
- rm -f $tmpfile
-
- # Dump logfile to /var/log/messages
- initlog -q -c "cat $logfile"
+ # Dump output to syslog for debugging
+ ocf_log debug "[$ORACLE_SID] [$rv] sent $startup_cmd"
+ ocf_log debug "[$ORACLE_SID] [$rv] got $startup_stdout"
if [ $rv -ne 0 ]; then
- rm -f $logfile
- initlog -n $SCRIPT -q -s "sqlplus returned 1, failed"
+ ocf_log error "Starting Oracle DB $ORACLE_SID failed, sqlplus returned $rv"
return 1
fi
# If we see:
# ORA-.....: failure, we failed
- grep -q "^ORA-" $logfile
- rv=$?
-
- rm -f $logfile
- if [ $rv -eq 0 ]; then
- initlog -n $SCRIPT -q -s "found failure in stdout, returning 1"
+ # Troubleshooting:
+ # ORA-00845 - Try rm -f /dev/shm/ora_*
+ # ORA-01081 - Try echo -e 'shutdown abort;\nquit;'|sqlplus "/ as sysdba"
+ if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then
+ ocf_log error "Starting Oracle DB $ORACLE_SID failed, found errors in stdout"
return 1
fi
+ ocf_log info "Started Oracle DB $ORACLE_SID successfully"
return 0
}
@@ -122,49 +129,47 @@ start_db() {
# Stop Oracle (database portion)
#
stop_db() {
- declare tmpfile
- declare logfile
+ declare stop_cmd
+ declare stop_stdout
declare -i rv
+ declare how_shutdown="$1"
- tmpfile=/tmp/$SCRIPT-stop.$$
- logfile=/tmp/$SCRIPT-stop.log.$$
+ if [ -z "$1" ]; then
+ how_shutdown="immediate"
+ fi
- ora_procname="ora_${DB_PROCNAMES}_${ORACLE_SID}"
- status $ora_procname
- if [ $? -ne 0 ]; then
- # No pmon process found, db already down
- return 0
- fi
+ ocf_log info "Stopping Oracle DB $ORACLE_SID $how_shutdown"
- # Setup for Stop ...
- echo "shutdown immediate" > $tmpfile
- echo "quit" >> $tmpfile
+ ora_procname="ora_${DB_PROCNAMES}_${ORACLE_SID}"
+ status $ora_procname
+ if [ $? -ne 0 ]; then
+ ocf_log debug "no pmon process -- DB $ORACLE_SID already stopped"
+ # No pmon process found, db already down
+ return 0
+ fi
- sqlplus "/ as sysdba" < $tmpfile > $logfile
+ # Setup for Stop ...
+ stop_cmd="set heading off;\nshutdown $how_shutdown;\nquit;\n"
+ stop_stdout=$(echo -e "$stop_cmd" | sqlplus -S "/ as sysdba")
rv=$?
- rm -f $tmpfile
-
- # Dump logfile to /var/log/messages
- initlog -q -c "cat $logfile"
+ # Log stdout of the stop command
+ ocf_log debug "[$ORACLE_SID] sent stop command $stop_cmd"
+ ocf_log debug "[$ORACLE_SID] got $stop_stdout"
- # sqlplus returned failure. We'll return failed to rhcs
+ # sqlplus returned failure. We'll return failed to rhcs
if [ $rv -ne 0 ]; then
- rm -f $logfile
- initlog -n $SCRIPT -q -s "sqlplus returned 1, failed"
+ ocf_log error "Stopping Oracle DB $ORACLE_SID failed, sqlplus returned $rv"
return 1
fi
- grep -q "^ORA-" $logfile
- rv=$?
- rm -f $logfile
-
- # If we see 'failure' in the log, we're done.
- if [ $rv -eq 0 ]; then
- initlog -n $SCRIPT -q -s "found failure in stdout, returning 1"
+ # If we see 'ORA-' or 'failure' in stdout, we're done.
+ if [[ "$startup_stdout" =~ "ORA-" ]] || [[ "$startup_stdout" =~ "failure" ]]; then
+ ocf_log error "Stopping Oracle DB $ORACLE_SID failed, errors in stdout"
return 1
fi
+ ocf_log info "Stopped Oracle DB $ORACLE_SID successfully"
return 0
}
@@ -176,14 +181,17 @@ force_cleanup() {
declare pids
declare pid
- pids=`ps ax | grep $ORACLE_SID | grep -v grep | awk '{print $1}'`
-
- initlog -n $SCRIPT -s "<err> Not all Oracle processes exited cleanly, killing"
+ ocf_log error "Not all Oracle processes for $ORACLE_SID exited cleanly, killing"
+ pids=`ps ax | grep "ora_.*_${ORACLE_SID}" | grep -v grep | awk '{print $1}'`
+
for pid in $pids; do
kill -9 $pid
- if [ $? -eq 0 ]; then
- initlog -n $SCRIPT -s "Killed $pid"
+ rv=$?
+ if [ $rv -eq 0 ]; then
+ ocf_log info "Cleanup $ORACLE_SID Killed PID $pid"
+ else
+ ocf_log error "Cleanup $ORACLE_SID Kill PID $pid failed: $rv"
fi
done
@@ -197,14 +205,18 @@ force_cleanup() {
exit_idle() {
declare -i n=0
+ ocf_log debug "Waiting for Oracle processes for $ORACLE_SID to terminate..."
while ps ax | grep $ORACLE_SID | grep -q -v $LSNR_PROCNAME | grep -q -v grep; do
if [ $n -ge 90 ]; then
+ ocf_log debug "Timed out while waiting for Oracle processes for $ORACLE_SID to terminate"
force_cleanup
return 0
fi
sleep 1
((n++))
done
+
+ ocf_log debug "All Oracle processes for $ORACLE_SID have terminated"
return 0
}
@@ -219,6 +231,8 @@ get_db_status() {
declare -i rv=0
declare ora_procname
+ ocf_log debug "Checking status of DB $ORACLE_SID"
+
for procname in $DB_PROCNAMES ; do
ora_procname="ora_${procname}_${ORACLE_SID}"
@@ -231,30 +245,34 @@ get_db_status() {
# We're not supposed to be running, and we are,
# in fact, not running...
if [ $subsys_lock -ne 0 ]; then
+ ocf_log debug "DB $ORACLE_SID is already stopped"
return 3
fi
for (( i=$RESTART_RETRIES ; i; i-- )) ; do
# this db process is down - stop and
# (re)start all ora_XXXX_$ORACLE_SID processes
- initlog -q -n $SCRIPT -s "Restarting Oracle Database..."
+ ocf_log info "Restarting Oracle Database $ORACLE_SID"
stop_db
start_db
- if [ $? == 0 ] ; then
+ if [ $? -eq 0 ] ; then
# ora_XXXX_$ORACLE_SID processes started
# successfully, so break out of the
# stop/start # 'for' loop
+ ocf_log info "Restarted Oracle DB $ORACLE_SID successfully"
break
fi
done
if [ $i -eq 0 ]; then
# stop/start's failed - return 1 (failure)
- initlog -q -n $SCRIPT -s "Restart failed, retuning 1"
+ ocf_log error "Failed to restart Oracle DB $ORACLE_SID after $RESTART_RETRIES tries"
return 1
fi
done
+
+ ocf_log debug "Checking status of DB $ORACLE_SID success"
return 0
}
@@ -265,41 +283,48 @@ get_db_status() {
get_lsnr_status() {
declare -i subsys_lock=$1
declare -i rv
- declare -r LISTENER=$3
+ declare -r LISTENER=$3
- lsnrctl status $LISTENER >& /dev/null
+ ocf_log debug "Checking status for listener $LISTENER"
+ lsnrctl status "$LISTENER" >& /dev/null
rv=$?
- if [ $rv == 0 ] ; then
+ if [ $rv -eq 0 ] ; then
+ ocf_log debug "Listener $LISTENER is up"
return 0 # Listener is running fine
fi
# We're not supposed to be running, and we are,
# in fact, not running. Return 3
if [ $subsys_lock -ne 0 ]; then
+ ocf_log debug "Listener $LISTENER is stopped as expected"
return 3
fi
# Listener is NOT running (but should be) - try to restart
for (( i=$RESTART_RETRIES ; i; i-- )) ; do
- initlog -n $SCRIPT -q -s "Restarting Oracle listener ($LISTENER)"
- lsnrctl start $LISTENER
- lsnrctl status $LISTENER >& /dev/null
- if [ $? == 0 ] ; then
+ ocf_log info "Listener $LISTENER is down, attempting to restart"
+ lsnrctl start "$LISTENER" >& /dev/null
+ lsnrctl status "$LISTENER" >& /dev/null
+ if [ $? -eq 0 ]; then
+ ocf_log info "Listener $LISTENER was restarted successfully"
break # Listener was (re)started and is running fine
fi
done
if [ $i -eq 0 ]; then
# stop/start's failed - return 1 (failure)
- initlog -n $SCRIPT -q -s "Listener restart failed, retuning 1"
+ ocf_log error "Failed to restart listener $LISTENER after $RESTART_RETRIES tries"
return 1
fi
- lsnrctl status $LISTENER >& /dev/null
- if [ $? != 0 ] ; then
- initlog -n $SCRIPT -q -s "Listener status failed, retuning 1"
+ lsnrctl_stdout=$(lsnrctl status "$LISTENER")
+ rv=$?
+ if [ $rv -ne 0 ] ; then
+ ocf_log error "Starting listener $LISTENER failed: $rv output $lsnrctl_stdout"
return 1 # Problem restarting the Listener
fi
+
+ ocf_log info "Listener $LISTENER started successfully"
return 0 # Success restarting the Listener
}
@@ -329,7 +354,7 @@ update_status() {
fi
if [ $old_status -ne $new_status ]; then
- initlog -n $SCRIPT -q -s "$old_status vs $new_status - returning 1"
+ ocf_log error "Error: $old_status vs $new_status for $ORACLE_SID - returning 1"
return 1
fi
@@ -341,11 +366,7 @@ update_status() {
# Print an error message to the user and exit.
#
oops() {
- #echo "Please configure this script ($0) to"
- #echo "match your installation."
- #echo
- #echo " $1 failed validation checks."
- initlog -n $SCRIPT -q -s "$1 failed validation checks"
+ ocf_log error "$ORACLE_SID: Fatal: $1 failed validation checks"
exit 1
}
@@ -355,16 +376,18 @@ oops() {
# script.
#
validation_checks() {
+ ocf_log debug "Validating configuration for $ORACLE_SID"
+
# If the oracle user doesn't exist, we're done.
[ -n "$ORACLE_USER" ] || oops "ORACLE_USER"
id -u $ORACLE_USER > /dev/null || oops "ORACLE_USER"
- id -g $ORACLE_USER > /dev/null || oops "ORACLE_USER"
+ id -g $ORACLE_USER > /dev/null || oops "ORACLE_GROUP"
# If the oracle home isn't a directory, we're done
- [ -n "$ORACLE_HOME" ] || oops ORACLE_HOME
+ [ -n "$ORACLE_HOME" ] || oops "ORACLE_HOME"
# If the oracle SID is NULL, we're done
- [ -n "$ORACLE_SID" ] || oops ORACLE_SID
+ [ -n "$ORACLE_SID" ] || oops "ORACLE_SID"
# Super user? Automatically change UID and exec as oracle user.
# Oracle needs to be run as the Oracle user, not root!
@@ -374,12 +397,13 @@ validation_checks() {
fi
# If we're not root and not the Oracle user, we're done.
- [ "`id -u`" = "`id -u $ORACLE_USER`" ] || exit 1
- [ "`id -g`" = "`id -g $ORACLE_USER`" ] || exit 1
+ [ "`id -u`" = "`id -u $ORACLE_USER`" ] || oops "not ORACLE_USER after su"
+ [ "`id -g`" = "`id -g $ORACLE_USER`" ] || oops "not ORACLE_GROUP after su"
# Go home.
- cd $ORACLE_HOME
+ cd "$ORACLE_HOME"
+ ocf_log debug "Validation checks for $ORACLE_SID succeeded"
return 0
}
@@ -388,20 +412,31 @@ validation_checks() {
# Start Oracle
#
start_oracle() {
- initlog -n $SCRIPT -q -s "Starting Oracle Database"
- start_db || return 1
-
- for LISTENER in ${LISTENERS}; do
- logfile=/tmp/$SCRIPT-lsn-$$.log
- initlog -n $SCRIPT -q -s "Starting Oracle Listener $LISTENER"
- lsnrctl start $LISTENER > $logfile
- initlog -q -c "cat $logfile"
- rm -f $logfile
- done
+ ocf_log info "Starting service $ORACLE_SID"
+
+ start_db
+ rv=$?
+ if [ $rv -ne 0 ]; then
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ fi
+
+ for LISTENER in ${LISTENERS}; do
+ ocf_log info "Starting listener $LISTENER"
+ lsnrctl_stdout=$(lsnrctl start "$LISTENER")
+ rv=$?
+ if [ $rv -ne 0 ]; then
+ ocf_log debug "[$ORACLE_SID] Listener $LISTENER start returned $rv output $lsnrctl_stdout"
+ ocf_log error "Starting service $ORACLE_SID failed"
+ return 1
+ fi
+ done
if [ -n "$LOCKFILE" ]; then
- touch $LOCKFILE
+ touch "$LOCKFILE"
fi
+
+ ocf_log info "Starting service $ORACLE_SID completed successfully"
return 0
}
@@ -410,30 +445,42 @@ start_oracle() {
# Stop Oracle
#
stop_oracle() {
+ ocf_log info "Stopping service $ORACLE_SID"
+
if ! [ -e "$ORACLE_HOME/bin/lsnrctl" ]; then
- initlog -n $SCRIPT -q -s "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)"
+ ocf_log error "Oracle Listener Control is not available ($ORACLE_HOME not mounted?)"
+ # XXX should this return 1?
return 0
fi
- initlog -n $SCRIPT -q -s "Stopping Oracle Database"
- stop_db || return 1
+ stop_db || stop_db abort
+ if [ $? -ne 0 ]; then
+ ocf_log error "Unable to stop DB for $ORACLE_SID"
+ return 1
+ fi
-
- for LISTENER in ${LISTENERS}; do
- initlog -n $SCRIPT -q -s "Stopping Oracle Listener $LISTENER"
- lsnrctl stop $LISTENER
- done
+ for LISTENER in ${LISTENERS}; do
+ ocf_log info "Stopping listener $LISTENER for $ORACLE_SID"
+ lsnrctl_stdout=$(lsnrctl stop "$LISTENER")
+ rv=$?
+ if [ $? -ne 0 ]; then
+ ocf_log error "Listener $LISTENER stop failed for $ORACLE_SID: $rv output $lsnrctl_stdout"
+ # XXX - failure?
+ fi
+ done
- initlog -n $SCRIPT -q -s "Waiting for all Oracle processes to exit"
- exit_idle
+ exit_idle
if [ $? -ne 0 ]; then
- initlog -n $SCRIPT -q -s "WARNING: Not all Oracle processes exited cleanly"
+ ocf_log error "WARNING: Not all Oracle processes exited cleanly for $ORACLE_SID"
+ # XXX - failure?
fi
if [ -n "$LOCKFILE" ]; then
- rm -f $LOCKFILE
+ rm -f "$LOCKFILE"
fi
+
+ ocf_log info "Stopping service $ORACLE_SID succeeded"
return 0
}
@@ -461,8 +508,10 @@ status_oracle() {
declare -i last
declare -i depth=$1
+ ocf_log debug "Checking status for $ORACLE_SID depth $depth"
+
# Check for lock file. Crude and rudimentary, but it works
- if [ -z "$LOCKFILE" ] || [ -f $LOCKFILE ]; then
+ if [ -z "$LOCKFILE" ] || [ -f "$LOCKFILE" ]; then
subsys_lock=0
fi
@@ -472,18 +521,19 @@ status_oracle() {
last=$?
# Check & report listener status
- for LISTENER in ${LISTENERS}; do
- get_lsnr_status $subsys_lock $depth $LISTENER
- update_status $? $last
- last=$?
- done
+ for LISTENER in ${LISTENERS}; do
+ get_lsnr_status $subsys_lock $depth "$LISTENER"
+ update_status $? $last
+ last=$?
+ done
# No lock file, but everything's running. Put the lock
# file back. XXX - this kosher?
if [ $last -eq 0 ] && [ $subsys_lock -ne 0 ]; then
- touch $LOCKFILE
+ touch "$LOCKFILE"
fi
+ ocf_log debug "Status returning $last for $ORACLE_SID"
return $last
}
@@ -493,22 +543,22 @@ status_oracle() {
########################
case $1 in
- meta-data)
- cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
- exit 0
- ;;
+ meta-data)
+ cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
+ exit 0
+ ;;
start)
- validation_checks $*
+ validation_checks $*
start_oracle
exit $?
;;
stop)
- validation_checks $*
+ validation_checks $*
stop_oracle
exit $?
;;
status|monitor)
- validation_checks $*
+ validation_checks $*
status_oracle $OCF_CHECK_LEVEL
exit $?
;;
diff --git a/rgmanager/src/resources/oralistener.sh b/rgmanager/src/resources/oralistener.sh
index 3d6b839..30b8e06 100755
--- a/rgmanager/src/resources/oralistener.sh
+++ b/rgmanager/src/resources/oralistener.sh
@@ -1,7 +1,5 @@
#!/bin/bash
#
-# $Id: oralistener.sh 127 2009-08-21 09:17:52Z hevirtan $
-#
# Red Hat Cluster Suite resource agent for controlling Oracle 10g
# listener instances. This script will start, stop and monitor running
# listeners.
@@ -12,6 +10,24 @@
#
# monitor: Will check that the listener is OK by calling lsnrctl status
#
+#
+# Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved.
+# Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
# Grab the global RHCS helper functions
. $(dirname $0)/ocf-shellfuncs
@@ -27,126 +43,148 @@ LISTENER=$OCF_RESKEY_name
LC_ALL=C
LANG=C
-PATH=/bin:/sbin:/usr/bin:/usr/sbin:$ORACLE_HOME/bin
-export LC_ALL LANG PATH ORACLE_HOME
+PATH=$ORACLE_HOME/bin:/bin:/sbin:/usr/bin:/usr/sbin
+export LC_ALL LANG PATH ORACLE_USER ORACLE_HOME
+
+# clulog will not log messages when run by the oracle user.
+# This is a hack to work around that.
+if [ "`id -u`" = "`id -u $ORACLE_USER`" ]; then
+ ocf_log() {
+ prio=$1
+ shift
+ logger -i -p daemon."$prio" -- "$*"
+ }
+fi
verify_all() {
- clog_service_verify $CLOG_INIT
-
- if [ -z "$OCF_RESKEY_name" ]; then
- clog_service_verify $CLOG_FAILED "Invalid name of service (listener name)"
- return $OCF_ERR_ARGS
- fi
-
- if [ -z "$OCF_RESKEY_home" ]; then
- clog_service_verify $CLOG_FAILED "No Oracle home specified."
- return $OCF_ERR_ARGS
- fi
-
- if [ -z "$OCF_RESKEY_user" ]; then
- clog_service_verify $CLOG_FAILED "No Oracle username specified."
- return $OCF_ERR_ARGS
- fi
-
- # Make sure the lsnrctl binary is in our $PATH
- if [ ! -x $(which lsnrctl) ]; then
- clog_service_verify $CLOG_FAILED "oralistener:${OCF_RESKEY_home}: Unable to locate lsnrctl command from path! ($PATH)"
- return $OCF_ERR_GENERIC
- fi
-
- clog_service_verify $CLOG_SUCCEED
- return 0
-}
+ ocf_log debug "Validating configuration for $LISTENER"
-start () {
- clog_service_start $CLOG_INIT
-
- logfile="/tmp/oracle_lsn.$$"
- su -p - $ORACLE_USER -c "lsnrctl start $LISTENER > $logfile"
+ if [ -z "$OCF_RESKEY_name" ]; then
+ ocf_log error "Validation for $LISTENER failed: Invalid name of service (listener name)"
+ return $OCF_ERR_ARGS
+ fi
- initlog -q -c "cat $logfile"
- rm -f $logfile
+ if [ -z "$OCF_RESKEY_home" ]; then
+ ocf_log error "Validation for $LISTENER failed: No Oracle home specified."
+ return $OCF_ERR_ARGS
+ fi
- clog_service_start $CLOG_SUCCEED
- return 0
+ if [ -z "$OCF_RESKEY_user" ]; then
+ ocf_log error "Validation for $LISTENER failed: No Oracle username specified."
+ return $OCF_ERR_ARGS
+ fi
+
+ # Super user? Automatically change UID and exec as oracle user.
+ # Oracle needs to be run as the Oracle user, not root!
+ if [ "`id -u`" = "0" ]; then
+ su $OCF_RESKEY_user -c "$0 $*"
+ exit $?
+ fi
+
+ # Make sure the lsnrctl binary is in our $PATH
+ if [ ! -x $(which lsnrctl) ]; then
+ ocf_log error "Validation for $LISTENER failed: Unable to locate lsnrctl command from path! ($PATH)"
+ return $OCF_ERR_GENERIC
+ fi
+
+ ocf_log debug "Validation checks for $LISTENER succeeded"
+ return 0
+}
+
+start() {
+ ocf_log info "Starting listener $LISTENER"
+ lsnrctl_stdout=$(lsnrctl start "$LISTENER")
+ if [ $? -ne 0 ]; then
+ ocf_log error "start listener $LISTENER failed $lsnrctl_stdout"
+ return $OCF_ERR_GENERIC
+ fi
+
+ ocf_log info "Listener $LISTENER started successfully"
+ return 0
}
-stop () {
- clog_service_stop $CLOG_INIT
-
- logfile="/tmp/oracle_lsn.$$"
- su -p - $ORACLE_USER -c "lsnrctl stop $LISTENER > $logfile"
+stop() {
+ ocf_log info "Stopping listener $LISTENER"
- initlog -q -c "cat $logfile"
- rm -f $logfile
+ lsnrctl_stdout=$(lsnrctl stop "$LISTENER")
+ if [ $? -ne 0 ]; then
+ ocf_log debug "stop listener $LISTENER failed $lsnrctl_stdout"
+ return $OCF_ERR_GENERIC
+ fi
- clog_service_stop $CLOG_SUCCEED
- return 0
+ ocf_log info "Listener $LISTENER stopped successfully"
+ return 0
}
-monitor () {
- clog_service_status $CLOG_INIT
-
- su -p - $ORACLE_USER -c "lsnrctl status $LISTENER"
- rv=$?
- if [ $rv == 0 ]; then
- clog_service_status $CLOG_SUCCEED
- return 0 # Listener is running fine
- else
- clog_service_status $CLOG_FAILED
- return $OCF_ERR_GENERIC
- fi
+monitor() {
+ declare -i depth=$1
+
+ ocf_log debug "Checking status for listener $LISTENER depth $depth"
+ lsnrctl status "$LISTENER" >& /dev/null
+ if [ $? -ne 0 ]; then
+ ocf_log error "Listener $LISTENER not running"
+ return $OCF_ERR_GENERIC
+ fi
+
+ ocf_log debug "Listener $LISTENER is up"
+ return 0 # Listener is running fine
}
recover() {
+ ocf_log debug "Recovering listener $LISTENER"
+
for (( i=$RESTART_RETRIES ; i; i-- )); do
start
- if [ $? == 0 ] ; then
- break
+ if [ $? -eq 0 ] ; then
+ ocf_log debug "Restarted listener $LISTENER successfully"
+ break
fi
done
if [ $i -eq 0 ]; then
# stop/start's failed - return 1 (failure)
+ ocf_log debug "Failed to restart listener $LISTENER after $RESTART_RETRIES tries"
return 1
fi
- status
- if [ $? != 0 ] ; then
+ status
+ if [ $? -ne 0 ] ; then
+ ocf_log debug "Failed to restart listener $LISTENER"
return 1 # Problem restarting the Listener
fi
+ ocf_log debug "Restarted listener $LISTENER successfully"
return 0 # Success restarting the Listener
}
case $1 in
- meta-data)
- cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
- exit 0
- ;;
- verify-all)
- verify_all
- exit $?
- ;;
- start)
- verify_all && start
- exit $?
- ;;
- stop)
- verify_all && stop
- exit $?
- ;;
- recover)
- verify_all && recover
- exit $?
- ;;
- status|monitor)
- verify_all
- monitor
- exit $?
- ;;
- *)
- echo "Usage: $0 {start|stop|recover|monitor|status|meta-data|verify-all}"
- exit $OCF_ERR_GENERIC
- ;;
+ meta-data)
+ cat `echo $0 | sed 's/^\(.*\)\.sh$/\1.metadata/'`
+ exit 0
+ ;;
+ verify-all)
+ verify_all $*
+ exit $?
+ ;;
+ start)
+ verify_all $* && start
+ exit $?
+ ;;
+ stop)
+ verify_all $* && stop
+ exit $?
+ ;;
+ recover)
+ verify_all $* && recover
+ exit $?
+ ;;
+ status|monitor)
+ verify_all $*
+ monitor $OCF_CHECK_LEVEL
+ exit $?
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|recover|monitor|status|meta-data|verify-all}"
+ exit $OCF_ERR_GENERIC
+ ;;
esac
11 years
cluster: RHEL510 - cman: enable and document logging of CMAN subsystem
by Jan Pokorný
Gitweb: http://git.fedorahosted.org/git/?p=cluster.git;a=commitdiff;h=43c60106f40...
Commit: 43c60106f4078699502771ff1be25c4bd6369f41
Parent: eaf31c53c822f73d31c4b4f2f586b27277ba9b10
Author: Jan Pokorný <jpokorny(a)redhat.com>
AuthorDate: Thu May 16 16:32:34 2013 +0200
Committer: Jan Pokorný <jpokorny(a)redhat.com>
CommitterDate: Thu May 16 16:32:34 2013 +0200
cman: enable and document logging of CMAN subsystem
Resolves: rhbz#963251
Signed-off-by: Jan Pokorný <jpokorny(a)redhat.com>
---
cman/daemon/logging.c | 2 --
cman/daemon/logging.h | 11 -----------
cman/man/cman.5 | 17 +++++++++++------
3 files changed, 11 insertions(+), 19 deletions(-)
diff --git a/cman/daemon/logging.c b/cman/daemon/logging.c
index 461890b..4f6e731 100644
--- a/cman/daemon/logging.c
+++ b/cman/daemon/logging.c
@@ -55,7 +55,6 @@ void set_debuglog(int subsystems)
subsys_mask = subsystems;
}
-#ifdef DEBUG
void log_debug(int subsys, int stamp, const char *fmt, ...)
{
va_list va;
@@ -96,4 +95,3 @@ void log_debug(int subsys, int stamp, const char *fmt, ...)
log_printf(LOG_LEVEL_DEBUG, log_buf);
va_end(va);
}
-#endif
diff --git a/cman/daemon/logging.h b/cman/daemon/logging.h
index 839e62f..05a4685 100644
--- a/cman/daemon/logging.h
+++ b/cman/daemon/logging.h
@@ -15,8 +15,6 @@ extern void init_debug(int subsystems);
void set_debuglog(int subsystems);
/* Debug macros */
-#ifdef DEBUG
-
#define CMAN_DEBUG_NONE 1
#define CMAN_DEBUG_BARRIER 2
#define CMAN_DEBUG_MEMB 4
@@ -29,12 +27,3 @@ extern void log_debug(int subsys, int stamp, const char *fmt, ...);
#define P_MEMB(fmt, args...) log_debug(CMAN_DEBUG_MEMB, 1, fmt, ## args)
#define P_DAEMON(fmt, args...) log_debug(CMAN_DEBUG_DAEMON, 1, fmt, ## args)
#define P_AIS(fmt, args...) log_debug(CMAN_DEBUG_AIS, 1, fmt, ## args)
-
-#else
-
-#define P_BARRIER(fmt, args...)
-#define P_MEMB(fmt, args...)
-#define P_DAEMON(fmt, args...)
-#define P_AIS(fmt, args...)
-
-#endif
diff --git a/cman/man/cman.5 b/cman/man/cman.5
index 0644295..a1d359f 100644
--- a/cman/man/cman.5
+++ b/cman/man/cman.5
@@ -1,5 +1,5 @@
.\"
-.\" Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+.\" Copyright (C) 2004-2013 Red Hat, Inc. All rights reserved.
.\" groff -t -e -mandoc -Tlatin1 cman.5 | less
@@ -189,13 +189,18 @@ Here's how to set the token timeout to five seconds:
And this is how to add extra openais logging options to CMAN and CPG:
- <logging to_stderr="yes">
- <logger ident="CPG" debug="on" to_stderr="yes">
- </logger>
- <logger ident="CMAN" debug="on" to_stderr="yes">
- </logger>
+ <logging>
+ <logger ident="CPG" debug="on"/>
+ <logger ident="CMAN" debug="on"/>
</logging>
+For logging of CMAN subsystem specifically, one can add
+\fIdebug_mask\fR attribute to \fIcman\fR element in cluster.conf
+(or, alternatively, export CMAN_DEBUGLOG environment variable
+prior to execution) with a value as described in cman_tool(8),
+section \fBDEBUG OPTIONS\fR. That man page also explains how
+to adjust the debug level at runtime.
+
.in -7
11 years
gfs2-utils: master - gfs2: add native setup to man page
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=0492586f...
Commit: 0492586f1f6e0198e9cc99eb846cc14d48e4c197
Parent: dfa6d76b29dcc48c20ebada3ad9f57598b72f490
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Tue May 14 13:50:38 2013 -0400
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Wed May 15 10:45:24 2013 +0100
gfs2: add native setup to man page
List the simplest sequence of steps to manually
set up and run gfs2/dlm.
Signed-off-by: David Teigland <teigland(a)redhat.com>
---
gfs2/man/gfs2.5 | 187 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 187 insertions(+), 0 deletions(-)
diff --git a/gfs2/man/gfs2.5 b/gfs2/man/gfs2.5
index 25effdd..0517944 100644
--- a/gfs2/man/gfs2.5
+++ b/gfs2/man/gfs2.5
@@ -196,3 +196,190 @@ The GFS2 documentation has been split into a number of sections:
\fBgfs2_tool\fP(8) Tool to manipulate a GFS2 file system (obsolete)
\fBtunegfs2\fP(8) Tool to manipulate GFS2 superblocks
+.SH SETUP
+
+GFS2 clustering is driven by the dlm, which depends on dlm_controld to
+provide clustering from userspace. dlm_controld clustering is built on
+corosync cluster/group membership and messaging.
+
+Follow these steps to manually configure and run gfs2/dlm/corosync.
+
+.B 1. create /etc/corosync/corosync.conf and copy to all nodes
+
+In this sample, replace cluster_name and IP addresses, and add nodes as
+needed. If using only two nodes, uncomment the two_node line.
+See corosync.conf(5) for more information.
+
+.nf
+totem {
+ version: 2
+ secauth: off
+ cluster_name: abc
+}
+
+nodelist {
+ node {
+ ring0_addr: 10.10.10.1
+ nodeid: 1
+ }
+ node {
+ ring0_addr: 10.10.10.2
+ nodeid: 2
+ }
+ node {
+ ring0_addr: 10.10.10.3
+ nodeid: 3
+ }
+}
+
+quorum {
+ provider: corosync_votequorum
+# two_node: 1
+}
+
+logging {
+ to_syslog: yes
+}
+.fi
+
+.PP
+
+.B 2. start corosync on all nodes
+
+.nf
+systemctl start corosync
+.fi
+
+Run corosync-quorumtool to verify that all nodes are listed.
+
+.PP
+
+.B 3. create /etc/dlm/dlm.conf and copy to all nodes
+
+.B *
+To use no fencing, use this line:
+
+.nf
+enable_fencing=0
+.fi
+
+.B *
+To use no fencing, but exercise fencing functions, use this line:
+
+.nf
+fence_all /bin/true
+.fi
+
+The "true" binary will be executed for all nodes and will succeed (exit 0)
+immediately.
+
+.B *
+To use manual fencing, use this line:
+
+.nf
+fence_all /bin/false
+.fi
+
+The "false" binary will be executed for all nodes and will fail (exit 1)
+immediately.
+
+When a node fails, manually run: dlm_tool fence_ack <nodeid>
+
+.B *
+To use stonith/pacemaker for fencing, use this line:
+
+.nf
+fence_all /usr/sbin/dlm_stonith
+.fi
+
+The "dlm_stonith" binary will be executed for all nodes. If
+stonith/pacemaker systems are not available, dlm_stonith will fail and
+this config becomes the equivalent of the previous /bin/false config.
+
+.B *
+To use an APC power switch, use these lines:
+
+.nf
+device apc /usr/sbin/fence_apc ipaddr=1.1.1.1 login=admin password=pw
+connect apc node=1 port=1
+connect apc node=2 port=2
+connect apc node=3 port=3
+.fi
+
+Other network switch based agents are configured similarly.
+
+.B *
+To use sanlock/watchdog fencing, use these lines:
+
+.nf
+device wd /usr/sbin/fence_sanlock path=/dev/fence/leases
+connect wd node=1 host_id=1
+connect wd node=2 host_id=2
+unfence wd
+.fi
+
+See fence_sanlock(8) for more information.
+
+.B *
+For other fencing configurations see dlm.conf(5) man page.
+
+.PP
+
+.B 4. start dlm_controld on all nodes
+
+.nf
+systemctl start dlm
+.fi
+
+Run "dlm_tool status" to verify that all nodes are listed.
+
+.PP
+
+.B 5. if using clvm, start clvmd on all nodes
+
+systemctl clvmd start
+
+.PP
+
+.B 6. make new gfs2 file systems
+
+mkfs.gfs2 -p lock_dlm -t cluster_name:fs_name -j num /path/to/storage
+
+The cluster_name must match the name used in step 1 above.
+The fs_name must be a unique name in the cluster.
+The -j option is the number of journals to create, there must
+be one for each node that will mount the fs.
+
+.PP
+
+.B 7. mount gfs2 file systems
+
+mount /path/to/storage /mountpoint
+
+Run "dlm_tool ls" to verify the nodes that have each fs mounted.
+
+.PP
+
+.B 8. shut down
+
+.nf
+umount -a -t gfs2
+systemctl clvmd stop
+systemctl dlm stop
+systemctl corosync stop
+.fi
+
+.PP
+
+.B More setup information:
+.br
+.BR dlm_controld (8),
+.br
+.BR dlm_tool (8),
+.br
+.BR dlm.conf (5),
+.br
+.BR corosync (8),
+.br
+.BR corosync.conf (5)
+.br
11 years
gfs2-utils: master - libgfs2: Clarify gfs2_compute_bitstructs's parameters
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=dfa6d76b...
Commit: dfa6d76b29dcc48c20ebada3ad9f57598b72f490
Parent: f384741c961d1781a39e61e58d2de2d09b50551f
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon May 13 12:28:53 2013 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue May 14 14:05:12 2013 +0100
libgfs2: Clarify gfs2_compute_bitstructs's parameters
gfs2_compute_bitstructs accepted an sdp and only used it to look up the
block size. Replace the sdp parameter with a bsize parameter to make it
easier to reason through code which uses this function.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/convert/gfs2_convert.c | 2 +-
gfs2/fsck/rgrepair.c | 6 +++---
gfs2/libgfs2/fs_geometry.c | 2 +-
gfs2/libgfs2/libgfs2.h | 2 +-
gfs2/libgfs2/rgrp.c | 10 +++++-----
gfs2/libgfs2/super.c | 2 +-
gfs2/mkfs/main_mkfs.c | 2 +-
7 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/gfs2/convert/gfs2_convert.c b/gfs2/convert/gfs2_convert.c
index d286512..d4bad1d 100644
--- a/gfs2/convert/gfs2_convert.c
+++ b/gfs2/convert/gfs2_convert.c
@@ -1898,7 +1898,7 @@ static int journ_space_to_rg(struct gfs2_sbd *sdp)
rgd->bh[x] = bget(sdp, rgd->ri.ri_addr + x);
memset(rgd->bh[x]->b_data, 0, sdp->bsize);
}
- if (gfs2_compute_bitstructs(sdp, rgd)) {
+ if (gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, rgd)) {
log_crit(_("gfs2_convert: Error converting bitmaps.\n"));
exit(-1);
}
diff --git a/gfs2/fsck/rgrepair.c b/gfs2/fsck/rgrepair.c
index 27368a2..1ebdc70 100644
--- a/gfs2/fsck/rgrepair.c
+++ b/gfs2/fsck/rgrepair.c
@@ -503,7 +503,7 @@ static int gfs2_rindex_rebuild(struct gfs2_sbd *sdp, int *num_rgs,
break; /* end of bitmap, so call it quits. */
} /* for subsequent bitmaps */
- gfs2_compute_bitstructs(sdp, calc_rgd);
+ gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, calc_rgd);
calc_rgd->ri.ri_data0 = calc_rgd->ri.ri_addr +
calc_rgd->ri.ri_length;
if (prev_rgd) {
@@ -732,7 +732,7 @@ static int expect_rindex_sanity(struct gfs2_sbd *sdp, int *num_rgs)
memcpy(&exp->rg, &rgd->rg, sizeof(exp->rg));
exp->bits = NULL;
exp->bh = NULL;
- gfs2_compute_bitstructs(sdp, exp);
+ gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, exp);
}
sdp->rgrps = *num_rgs;
return 0;
@@ -948,7 +948,7 @@ int rg_repair(struct gfs2_sbd *sdp, int trust_lvl, int *rg_count, int *sane)
}
else
log_err( _("rindex not fixed.\n"));
- gfs2_compute_bitstructs(sdp, actual);
+ gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, actual);
rindex_modified = FALSE;
}
e = enext;
diff --git a/gfs2/libgfs2/fs_geometry.c b/gfs2/libgfs2/fs_geometry.c
index e716127..932a2e6 100644
--- a/gfs2/libgfs2/fs_geometry.c
+++ b/gfs2/libgfs2/fs_geometry.c
@@ -207,7 +207,7 @@ void build_rgrps(struct gfs2_sbd *sdp, int do_write)
rl->rg.rg_header.mh_format = GFS2_FORMAT_RG;
rl->rg.rg_free = rgblocks;
- if (gfs2_compute_bitstructs(sdp, rl)) {
+ if (gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, rl)) {
fprintf(stderr, "%s: Unable to build resource groups "
"with these characteristics.\n", __FUNCTION__);
exit(-1);
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index e069e9d..997e23f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -725,7 +725,7 @@ extern int gfs2_find_jhead(struct gfs2_inode *ip, struct gfs2_log_header *head);
extern int clean_journal(struct gfs2_inode *ip, struct gfs2_log_header *head);
/* rgrp.c */
-extern int gfs2_compute_bitstructs(struct gfs2_sbd *sdp, struct rgrp_tree *rgd);
+extern int gfs2_compute_bitstructs(const uint32_t bsize, struct rgrp_tree *rgd);
extern struct rgrp_tree *gfs2_blk2rgrpd(struct gfs2_sbd *sdp, uint64_t blk);
extern uint64_t gfs2_rgrp_read(struct gfs2_sbd *sdp, struct rgrp_tree *rgd);
extern void gfs2_rgrp_relse(struct rgrp_tree *rgd);
diff --git a/gfs2/libgfs2/rgrp.c b/gfs2/libgfs2/rgrp.c
index f7dc01e..f2b8304 100644
--- a/gfs2/libgfs2/rgrp.c
+++ b/gfs2/libgfs2/rgrp.c
@@ -12,11 +12,11 @@
/**
* gfs2_compute_bitstructs - Compute the bitmap sizes
- * @rgd: The resource group descriptor
- *
+ * bsize: Block size
+ * rgd: The resource group descriptor
* Returns: 0 on success, -1 on error
*/
-int gfs2_compute_bitstructs(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
+int gfs2_compute_bitstructs(const uint32_t bsize, struct rgrp_tree *rgd)
{
struct gfs2_bitmap *bits;
uint32_t length = rgd->ri.ri_length;
@@ -49,7 +49,7 @@ int gfs2_compute_bitstructs(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
bits->bi_len = bytes;
}
else if (x == 0){
- bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_rgrp);
+ bytes = bsize - sizeof(struct gfs2_rgrp);
bits->bi_offset = sizeof(struct gfs2_rgrp);
bits->bi_start = 0;
bits->bi_len = bytes;
@@ -61,7 +61,7 @@ int gfs2_compute_bitstructs(struct gfs2_sbd *sdp, struct rgrp_tree *rgd)
bits->bi_len = bytes;
}
else{
- bytes = sdp->sd_sb.sb_bsize - sizeof(struct gfs2_meta_header);
+ bytes = bsize - sizeof(struct gfs2_meta_header);
bits->bi_offset = sizeof(struct gfs2_meta_header);
bits->bi_start = rgd->ri.ri_bitbytes - bytes_left;
bits->bi_len = bytes;
diff --git a/gfs2/libgfs2/super.c b/gfs2/libgfs2/super.c
index 21c9f7b..eb97c40 100644
--- a/gfs2/libgfs2/super.c
+++ b/gfs2/libgfs2/super.c
@@ -188,7 +188,7 @@ int rindex_read(struct gfs2_sbd *sdp, int fd, int *count1, int *sane)
prev_rgd->length = rgrp_size(prev_rgd);
}
- if(gfs2_compute_bitstructs(sdp, rgd))
+ if(gfs2_compute_bitstructs(sdp->sd_sb.sb_bsize, rgd))
*sane = 0;
(*count1)++;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 6265c58..80b2782 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -606,7 +606,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, const struct mkfs_opts *opts)
/* TODO: This call allocates buffer heads and bitmap pointers
* in rgt. We really shouldn't need to do that. */
- err = gfs2_compute_bitstructs(sdp, rgt);
+ err = gfs2_compute_bitstructs(sdp->bsize, rgt);
if (err != 0) {
fprintf(stderr, _("Could not compute bitmaps. "
"Check resource group and block size options.\n"));
11 years
gfs2-utils: master - mkfs.gfs2: Add a struct to store device info
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f384741c...
Commit: f384741c961d1781a39e61e58d2de2d09b50551f
Parent: 531eead1d0ab1bff33e8edbffa2f36ee2e0eadd0
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Mar 21 19:19:47 2013 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue May 14 14:05:12 2013 +0100
mkfs.gfs2: Add a struct to store device info
Adds a struct mkfs_dev to store the fd, topology and stat info for the
target. Not using lgfs2_device_info as we now probe the topology with
libblkid so that functionality should eventually disappear from libgfs2.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_mkfs.c | 173 +++++++++++++++++++++++++++++++++----------------
1 files changed, 118 insertions(+), 55 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 3d6f724..6265c58 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -113,6 +113,27 @@ struct mkfs_opts {
unsigned confirm:1;
};
+/**
+ * Values probed by libblkid:
+ * alignment_offset: offset, in bytes, of the start of the dev from its natural alignment
+ * logical_sector_size: smallest addressable unit
+ * minimum_io_size: device's preferred unit of I/O. RAID stripe unit.
+ * optimal_io_size: biggest I/O we can submit without incurring a penalty. RAID stripe width.
+ * physical_sector_size: the smallest unit we can write atomically
+ */
+struct mkfs_dev {
+ int fd;
+ struct stat stat;
+ uint64_t size;
+ unsigned long alignment_offset;
+ unsigned long logical_sector_size;
+ unsigned long minimum_io_size;
+ unsigned long optimal_io_size;
+ unsigned long physical_sector_size;
+
+ unsigned int got_topol:1;
+};
+
static void opts_init(struct mkfs_opts *opts)
{
memset(opts, 0, sizeof(*opts));
@@ -401,25 +422,26 @@ static void are_you_sure(void)
free(line);
}
-static unsigned choose_blocksize(struct mkfs_opts *opts, struct lgfs2_dev_info *dinfo)
+static unsigned choose_blocksize(struct mkfs_opts *opts, const struct mkfs_dev *dev)
{
unsigned int x;
unsigned int bsize = opts->bsize;
- if (!opts->got_bsize) {
- if (S_ISREG(dinfo->stat.st_mode))
- bsize = GFS2_DEFAULT_BSIZE;
- /* See if optimal_io_size (the biggest I/O we can submit
- without incurring a penalty) is a suitable block size. */
- else if (dinfo->io_optimal_size <= getpagesize() && dinfo->io_optimal_size >= dinfo->io_min_size)
- bsize = dinfo->io_optimal_size;
- /* See if physical_block_size (the smallest unit we can write
- without incurring read-modify-write penalty) is suitable. */
- else if (dinfo->physical_block_size <= getpagesize() && dinfo->physical_block_size >= GFS2_DEFAULT_BSIZE)
- bsize = dinfo->physical_block_size;
- else
- bsize = GFS2_DEFAULT_BSIZE;
+ if (dev->got_topol && opts->debug) {
+ printf("alignment_offset: %lu\n", dev->alignment_offset);
+ printf("logical_sector_size: %lu\n", dev->logical_sector_size);
+ printf("minimum_io_size: %lu\n", dev->minimum_io_size);
+ printf("optimal_io_size: %lu\n", dev->optimal_io_size);
+ printf("physical_sector_size: %lu\n", dev->physical_sector_size);
+ }
+ if (!opts->got_bsize && dev->got_topol) {
+ if (dev->optimal_io_size <= getpagesize() &&
+ dev->optimal_io_size >= dev->minimum_io_size)
+ bsize = dev->optimal_io_size;
+ else if (dev->physical_sector_size <= getpagesize() &&
+ dev->physical_sector_size >= GFS2_DEFAULT_BSIZE)
+ bsize = dev->physical_sector_size;
}
/* Block sizes must be a power of two from 512 to 65536 */
@@ -431,15 +453,15 @@ static unsigned choose_blocksize(struct mkfs_opts *opts, struct lgfs2_dev_info *
die( _("Block size must be a power of two between 512 and %d\n"),
getpagesize());
- if (bsize < dinfo->logical_block_size) {
+ if (bsize < dev->logical_sector_size) {
die( _("Error: Block size %d is less than minimum logical "
- "block size (%d).\n"), bsize, dinfo->logical_block_size);
+ "block size (%lu).\n"), bsize, dev->logical_sector_size);
}
- if (bsize < dinfo->physical_block_size) {
+ if (bsize < dev->physical_sector_size) {
printf( _("Warning: Block size %d is inefficient because it "
- "is less than the physical block size (%d).\n"),
- bsize, dinfo->physical_block_size);
+ "is less than the physical block size (%lu).\n"),
+ bsize, dev->physical_sector_size);
opts->confirm = 1;
}
return bsize;
@@ -447,6 +469,11 @@ static unsigned choose_blocksize(struct mkfs_opts *opts, struct lgfs2_dev_info *
static void opts_check(struct mkfs_opts *opts)
{
+ if (!opts->got_device) {
+ fprintf(stderr, _("No device specified. Use -h for help\n"));
+ exit(1);
+ }
+
if (!opts->expert)
test_locking(opts->lockproto, opts->locktable);
if (opts->expert) {
@@ -600,7 +627,7 @@ static int place_rgrps(struct gfs2_sbd *sdp, const struct mkfs_opts *opts)
return 0;
}
-static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_dev_info *dinfo, int fd)
+static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct mkfs_dev *dev)
{
memset(sdp, 0, sizeof(struct gfs2_sbd));
sdp->time = time(NULL);
@@ -609,20 +636,20 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_
sdp->qcsize = opts->qcsize;
sdp->jsize = opts->jsize;
sdp->md.journals = opts->journals;
- sdp->device_fd = fd;
- sdp->bsize = choose_blocksize(opts, dinfo);
+ sdp->device_fd = dev->fd;
+ sdp->bsize = choose_blocksize(opts, dev);
if (compute_constants(sdp)) {
perror(_("Failed to compute file system constants"));
exit(1);
}
- sdp->device.length = dinfo->size / sdp->bsize;
+ sdp->device.length = dev->size / sdp->bsize;
if (opts->got_fssize) {
if (opts->fssize > sdp->device.length) {
fprintf(stderr, _("Specified size is bigger than the device."));
- die("%s %.2f %s (%llu %s)\n", _("Device size:"),
- dinfo->size / ((float)(1 << 30)), _("GB"),
- (unsigned long long)dinfo->size / sdp->bsize, _("blocks"));
+ die("%s %.2f %s (%"PRIu64" %s)\n", _("Device size:"),
+ dev->size / ((float)(1 << 30)), _("GB"),
+ dev->size / sdp->bsize, _("blocks"));
}
/* TODO: Check if the fssize is too small, somehow */
sdp->device.length = opts->fssize;
@@ -644,18 +671,23 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_
}
}
-static int probe_contents(int fd)
+static int probe_contents(struct mkfs_dev *dev)
{
int ret;
const char *contents;
blkid_probe pr = blkid_new_probe();
- if (pr == NULL || blkid_probe_set_device(pr, fd, 0, 0) != 0
+ if (pr == NULL || blkid_probe_set_device(pr, dev->fd, 0, 0) != 0
|| blkid_probe_enable_superblocks(pr, TRUE) != 0
|| blkid_probe_enable_partitions(pr, TRUE) != 0) {
fprintf(stderr, _("Failed to create probe\n"));
return -1;
}
+ if (!S_ISREG(dev->stat.st_mode) && blkid_probe_enable_topology(pr, TRUE) != 0) {
+ fprintf(stderr, _("Failed to create probe\n"));
+ return -1;
+ }
+
ret = blkid_do_fullprobe(pr);
if (ret == -1) {
fprintf(stderr, _("Failed to probe device\n"));
@@ -671,53 +703,84 @@ static int probe_contents(int fd)
printf(_("It appears to contain a partition table (%s).\n"), contents);
}
- blkid_free_probe(pr);
+ if (!S_ISREG(dev->stat.st_mode)) {
+ blkid_topology tp = blkid_probe_get_topology(pr);
+ if (tp != NULL) {
+ dev->alignment_offset = blkid_topology_get_alignment_offset(tp);
+ dev->logical_sector_size = blkid_topology_get_logical_sector_size(tp);
+ dev->minimum_io_size = blkid_topology_get_minimum_io_size(tp);
+ dev->optimal_io_size = blkid_topology_get_optimal_io_size(tp);
+ dev->physical_sector_size = blkid_topology_get_physical_sector_size(tp);
+ dev->got_topol = 1;
+ }
+ }
+ blkid_free_probe(pr);
return 0;
}
+static void open_dev(const char *path, struct mkfs_dev *dev)
+{
+ int error;
+
+ memset(dev, 0, sizeof(*dev));
+ dev->fd = open(path, O_RDWR | O_CLOEXEC);
+ if (dev->fd < 0) {
+ perror(path);
+ exit(1);
+ }
+
+ error = fstat(dev->fd, &dev->stat);
+ if (error < 0) {
+ perror(path);
+ exit(1);
+ }
+
+ if (S_ISREG(dev->stat.st_mode)) {
+ dev->size = dev->stat.st_size;
+ } else if (S_ISBLK(dev->stat.st_mode)) {
+ dev->size = lseek(dev->fd, 0, SEEK_END);
+ if (dev->size < 1) {
+ fprintf(stderr, _("Device '%s' is too small\n"), path);
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, _("'%s' is not a block device or regular file\n"), path);
+ exit(1);
+ }
+
+ error = probe_contents(dev);
+ if (error)
+ exit(1);
+}
+
void main_mkfs(int argc, char *argv[])
{
struct gfs2_sbd sbd;
struct mkfs_opts opts;
- struct lgfs2_dev_info dinfo;
+ struct mkfs_dev dev;
int error;
unsigned char uuid[16];
- int fd;
opts_init(&opts);
opts_get(argc, argv, &opts);
+ opts_check(&opts);
- if (!opts.got_device) {
- fprintf(stderr, _("No device specified. Use -h for help\n"));
- exit(1);
- }
-
- fd = open(opts.device, O_RDWR | O_CLOEXEC);
- if (fd < 0){
- perror(opts.device);
- exit(EXIT_FAILURE);
- }
+ open_dev(opts.device, &dev);
- if (lgfs2_get_dev_info(fd, &dinfo) < 0) {
- perror(opts.device);
- exit(EXIT_FAILURE);
+ if (S_ISREG(dev.stat.st_mode)) {
+ opts.got_bsize = 1; /* Use default block size for regular files */
}
- opts_check(&opts);
warn_of_destruction(opts.device);
- error = probe_contents(fd);
- if (error)
- exit(EXIT_FAILURE);
-
- sbd_init(&sbd, &opts, &dinfo, fd);
+ sbd_init(&sbd, &opts, &dev);
if (opts.confirm && !opts.override)
are_you_sure();
- if (!S_ISREG(dinfo.stat.st_mode) && opts.discard)
- discard_blocks(fd, sbd.bsize * sbd.device.length, opts.debug);
+ if (!S_ISREG(dev.stat.st_mode) && opts.discard)
+ discard_blocks(dev.fd, sbd.bsize * sbd.device.length, opts.debug);
error = place_rgrps(&sbd, &opts);
if (error) {
@@ -770,18 +833,18 @@ void main_mkfs(int argc, char *argv[])
inode_put(&sbd.md.statfs);
gfs2_rgrp_free(&sbd.rgtree);
- error = fsync(fd);
+ error = fsync(dev.fd);
if (error){
perror(opts.device);
exit(EXIT_FAILURE);
}
- error = close(fd);
+ error = close(dev.fd);
if (error){
perror(opts.device);
exit(EXIT_FAILURE);
}
if (!opts.quiet)
- print_results(&sbd, dinfo.size, &opts, uuid);
+ print_results(&sbd, dev.size, &opts, uuid);
}
11 years
gfs2-utils: master - mkfs.gfs2: Use libblkid for checking contents
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=531eead1...
Commit: 531eead1d0ab1bff33e8edbffa2f36ee2e0eadd0
Parent: 227a11136a36ec3c758275a247e9cc1fb401ce44
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Thu Mar 7 12:09:45 2013 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue May 14 14:05:12 2013 +0100
mkfs.gfs2: Use libblkid for checking contents
Use libblkid to probe the contents of the target device instead of
execing 'file'.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_mkfs.c | 181 ++++++++++++++-----------------------------------
1 files changed, 51 insertions(+), 130 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 864ff98..3d6f724 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -20,6 +20,7 @@
#include <libintl.h>
#include <sys/ioctl.h>
#include <limits.h>
+#include <blkid.h>
#define _(String) gettext(String)
@@ -123,6 +124,7 @@ static void opts_init(struct mkfs_opts *opts)
opts->rgsize = GFS2_DEFAULT_RGSIZE;
opts->lockproto = "lock_dlm";
opts->locktable = "";
+ opts->confirm = 1;
}
#ifndef BLKDISCARD
@@ -468,105 +470,6 @@ static void opts_check(struct mkfs_opts *opts)
}
-static int get_file_output(int fd, char *buffer, size_t buflen)
-{
- struct pollfd pf = { .fd = fd, .events = POLLIN|POLLRDHUP };
- int flags;
- int pos = 0;
- int rv;
-
- flags = fcntl(fd, F_GETFL, 0);
- if (flags < 0)
- return flags;
-
- flags |= O_NONBLOCK;
- rv = fcntl(fd, F_SETFL, flags);
- if (rv < 0)
- return rv;
-
- while (1) {
- rv = poll(&pf, 1, 10 * 1000);
- if (rv == 0)
- break;
- if (rv < 0)
- return rv;
- if (pf.revents & POLLIN) {
- rv = read(fd, buffer + pos,
- buflen - pos);
- if (rv < 0) {
- if (errno == EAGAIN)
- continue;
- return rv;
- }
- if (rv == 0)
- break;
- pos += rv;
- if (pos >= buflen)
- return -1;
- buffer[pos] = 0;
- continue;
- }
- if (pf.revents & (POLLRDHUP | POLLHUP | POLLERR))
- break;
- }
- return 0;
-}
-
-static void check_dev_content(const char *devname)
-{
- struct sigaction sa;
- char content[1024] = { 0, };
- char * args[] = {
- (char *)"/usr/bin/file",
- (char *)"-bsL",
- (char *)devname,
- NULL };
- int p[2] = {-1, -1};
- int ret;
- int pid;
-
- ret = sigaction(SIGCHLD, NULL, &sa);
- if (ret)
- return;
- sa.sa_handler = SIG_IGN;
- sa.sa_flags |= (SA_NOCLDSTOP | SA_NOCLDWAIT);
- ret = sigaction(SIGCHLD, &sa, NULL);
- if (ret)
- goto fail;
-
- ret = pipe(p);
- if (ret)
- goto fail;
-
- pid = fork();
-
- if (pid < 0) {
- close(p[1]);
- goto fail;
- }
-
- if (pid) {
- close(p[1]);
- ret = get_file_output(p[0], content, sizeof(content));
- if (ret) {
-fail:
- printf( _("Content of file or device unknown (do you have GNU fileutils installed?)\n"));
- } else {
- if (*content == 0)
- goto fail;
- printf( _("It appears to contain: %s"), content);
- }
- if (p[0] >= 0)
- close(p[0]);
- return;
- }
-
- close(p[0]);
- dup2(p[1], STDOUT_FILENO);
- close(STDIN_FILENO);
- exit(execv(args[0], args));
-}
-
static void print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
struct mkfs_opts *opts, unsigned char uuid[16])
{
@@ -587,30 +490,27 @@ static void print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
printf("%-27s%s\n", _("UUID:"), str_uuid(uuid));
}
-/**
- * If path is a symlink, return 1 with *abspath pointing to the absolute path,
- * otherwise return 0. Exit on errors. The caller must free the memory pointed
- * to by *abspath.
- */
-static int is_symlink(const char *path, char **abspath)
+static void warn_of_destruction(const char *path)
{
struct stat lnkstat;
+ char *abspath = NULL;
if (lstat(path, &lnkstat) == -1) {
perror(_("Failed to lstat the device"));
exit(EXIT_FAILURE);
}
- if (!S_ISLNK(lnkstat.st_mode)) {
- return 0;
- }
- *abspath = canonicalize_file_name(path);
- if (*abspath == NULL) {
- perror(_("Could not find the absolute path of the device"));
- exit(EXIT_FAILURE);
+ if (S_ISLNK(lnkstat.st_mode)) {
+ abspath = canonicalize_file_name(path);
+ if (abspath == NULL) {
+ perror(_("Could not find the absolute path of the device"));
+ exit(EXIT_FAILURE);
+ }
+ /* Translators: Example: "/dev/vg/lv is a symbolic link to /dev/dm-2" */
+ printf( _("%s is a symbolic link to %s\n"), path, abspath);
+ path = abspath;
}
- /* Translators: Example: "/dev/vg/lv is a symbolic link to /dev/dm-2" */
- printf( _("%s is a symbolic link to %s\n"), path, *abspath);
- return 1;
+ printf(_("This will destroy any data on %s\n"), path);
+ free(abspath);
}
static int writerg(int fd, const struct rgrp_tree *rgt, const unsigned bsize)
@@ -744,6 +644,38 @@ static void sbd_init(struct gfs2_sbd *sdp, struct mkfs_opts *opts, struct lgfs2_
}
}
+static int probe_contents(int fd)
+{
+ int ret;
+ const char *contents;
+ blkid_probe pr = blkid_new_probe();
+ if (pr == NULL || blkid_probe_set_device(pr, fd, 0, 0) != 0
+ || blkid_probe_enable_superblocks(pr, TRUE) != 0
+ || blkid_probe_enable_partitions(pr, TRUE) != 0) {
+ fprintf(stderr, _("Failed to create probe\n"));
+ return -1;
+ }
+
+ ret = blkid_do_fullprobe(pr);
+ if (ret == -1) {
+ fprintf(stderr, _("Failed to probe device\n"));
+ return -1;
+ }
+
+ if (ret == 1)
+ return 0;
+
+ if (!blkid_probe_lookup_value(pr, "TYPE", &contents, NULL)) {
+ printf(_("It appears to contain an existing filesystem (%s)\n"), contents);
+ } else if (!blkid_probe_lookup_value(pr, "PTTYPE", &contents, NULL)) {
+ printf(_("It appears to contain a partition table (%s).\n"), contents);
+ }
+
+ blkid_free_probe(pr);
+
+ return 0;
+}
+
void main_mkfs(int argc, char *argv[])
{
struct gfs2_sbd sbd;
@@ -751,9 +683,6 @@ void main_mkfs(int argc, char *argv[])
struct lgfs2_dev_info dinfo;
int error;
unsigned char uuid[16];
- char *absname = NULL;
- char *fdpath = NULL;
- int islnk = 0;
int fd;
opts_init(&opts);
@@ -776,21 +705,13 @@ void main_mkfs(int argc, char *argv[])
}
opts_check(&opts);
- sbd_init(&sbd, &opts, &dinfo, fd);
+ warn_of_destruction(opts.device);
- if (asprintf(&fdpath, "/proc/%d/fd/%d", getpid(), fd) < 0) {
- perror(_("Failed to build string"));
+ error = probe_contents(fd);
+ if (error)
exit(EXIT_FAILURE);
- }
- if (!opts.override) {
- islnk = is_symlink(opts.device, &absname);
- printf(_("This will destroy any data on %s.\n"), islnk ? absname : opts.device);
- free(absname);
- check_dev_content(fdpath);
- opts.confirm = 1;
- }
- free(fdpath);
+ sbd_init(&sbd, &opts, &dinfo, fd);
if (opts.confirm && !opts.override)
are_you_sure();
11 years
gfs2-utils: master - mkfs.gfs2: Link to libblkid
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=227a1113...
Commit: 227a11136a36ec3c758275a247e9cc1fb401ce44
Parent: 1cebece3e922bfffa52f58ac6594700764868771
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Wed Mar 6 16:38:18 2013 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue May 14 14:05:12 2013 +0100
mkfs.gfs2: Link to libblkid
Add the build system bits to check for, and link mkfs.gfs2 to libblkid.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
configure.ac | 1 +
gfs2/mkfs/Makefile.am | 3 +++
2 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 45b38eb..6940d79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -126,6 +126,7 @@ PKG_CHECK_MODULES([check], [check >= 0.9.8],
AM_CONDITIONAL([BUILD_TESTS], [test "x$have_check" = "xyes"])
PKG_CHECK_MODULES([zlib],[zlib])
+PKG_CHECK_MODULES([blkid],[blkid])
# old versions of ncurses don't ship pkg-config files
PKG_CHECK_MODULES([ncurses],[ncurses],,
diff --git a/gfs2/mkfs/Makefile.am b/gfs2/mkfs/Makefile.am
index 3e72026..6ed89fa 100644
--- a/gfs2/mkfs/Makefile.am
+++ b/gfs2/mkfs/Makefile.am
@@ -20,6 +20,9 @@ mkfs_gfs2_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE \
-I$(top_srcdir)/gfs2/include \
-I$(top_srcdir)/gfs2/libgfs2
+mkfs_gfs2_CFLAGS = $(blkid_CFLAGS)
+mkfs_gfs2_LDFLAGS = $(blkid_LIBS)
+
mkfs_gfs2_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la
relative_sbin = $(shell perl -MFile::Spec -le 'print File::Spec->abs2rel("/sbin", "$(sbindir)")')
11 years
gfs2-utils: master - libgfs2: Remove 'writes' field from gfs2_sbd
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1cebece3...
Commit: 1cebece3e922bfffa52f58ac6594700764868771
Parent: a3ab08213c87313ec899c114c23650d05268eef5
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Mar 1 16:03:52 2013 +0000
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue May 14 14:05:11 2013 +0100
libgfs2: Remove 'writes' field from gfs2_sbd
This was only used to print out how many writes mkfs.gfs2 had made
during its run in debug mode, which doesn't really make sense any more
as we don't use bwrite for much of the mkfs process now.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/buf.c | 1 -
gfs2/libgfs2/libgfs2.h | 1 -
gfs2/mkfs/main_mkfs.c | 5 -----
3 files changed, 0 insertions(+), 7 deletions(-)
diff --git a/gfs2/libgfs2/buf.c b/gfs2/libgfs2/buf.c
index 68f0731..6fcdd17 100644
--- a/gfs2/libgfs2/buf.c
+++ b/gfs2/libgfs2/buf.c
@@ -80,7 +80,6 @@ int bwrite(struct gfs2_buffer_head *bh)
if (pwritev(sdp->device_fd, &bh->iov, 1, bh->b_blocknr * sdp->bsize) != bh->iov.iov_len)
return -1;
- sdp->writes++;
bh->b_modified = 0;
return 0;
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 7d2d9ff..e069e9d 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -311,7 +311,6 @@ struct gfs2_sbd {
struct gfs2_inode *master_dir;
struct master_dir md;
- unsigned int writes;
int metafs_fd;
char metafs_path[PATH_MAX]; /* where metafs is mounted */
struct special_blocks eattr_blocks;
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index 6471600..864ff98 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -583,15 +583,10 @@ static void print_results(struct gfs2_sbd *sdp, uint64_t real_device_size,
printf("%-27s%llu\n", _("Resource groups:"), (unsigned long long)sdp->rgrps);
printf("%-27s\"%s\"\n", _("Locking protocol:"), sdp->lockproto);
printf("%-27s\"%s\"\n", _("Lock table:"), sdp->locktable);
-
- if (opts->debug) {
- printf("%-27s%u\n", _("Writes:"), sdp->writes);
- }
/* Translators: "UUID" = universally unique identifier. */
printf("%-27s%s\n", _("UUID:"), str_uuid(uuid));
}
-
/**
* If path is a symlink, return 1 with *abspath pointing to the absolute path,
* otherwise return 0. Exit on errors. The caller must free the memory pointed
11 years