3
# Copyright (C) 2007 Oracle. All rights reserved.
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public
7
# License, version 2, as published by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# General Public License for more details.
14
# You should have received a copy of the GNU General Public
15
# License along with this program; if not, write to the
16
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
# Boston, MA 021110-1307, USA.
19
# Author: Sunil Mushran 03/01/2007
21
################################################################
25
# This script lists all the objects using the clusters that are
26
# reserved for OCFS2's backup superblocks. This script is
27
# useful for users unable to retroactively enable backup super
28
# block using tunefs.ocfs2 --backup-super.
30
################################################################
33
echo "usage ${APP} /dev/sdX"
38
bsbits=`${DEBUGFS} -R "stats" ${device} 2>/dev/null | ${AWK} '/Block Size Bits/ {print $4;}'`
39
csbits=`${DEBUGFS} -R "stats" ${device} 2>/dev/null | ${AWK} '/Cluster Size Bits/ {print $8;}'`
40
numcls=`${DEBUGFS} -R "stats" ${device} 2>/dev/null | ${AWK} '/Clusters:/ {print $4;}'`
42
if [ -z "$bsbits" ] || [ -a "$csbits" ] || [ -a "$numcls" ]; then
43
echo "error: not an OCFS2 device"
48
blocksize=$[$[2 ** $[$bsbits - 9]] * 512]
49
clustsize=$[$[2 ** $[$csbits - 9]] * 512]
52
numblocks=$[$numcls * $clustsize / $blocksize]
55
# Ensure version is >= 1.2.3
57
ret=`${DEBUGFS} --version 2>&1 |
58
${AWK} '/debugfs.ocfs2/ {
59
flds=split($2, ver, ".");
60
if (flds >= 3) { if (ver[1] > 1) {print 1;}
61
else if (ver[2] < 2) {print 0;}
62
else if (ver[2] > 2) {print 1;}
63
else if (ver[3] > 2) {print 1;}
66
if [ "${ret}" = "0" ]; then
67
echo "Upgrade to ocfs2-tools 1.2.3 or later"
72
# Feature Compat: 1 BackupSuper
74
feat=`${DEBUGFS} -R "stats" ${device} 2>/dev/null |
75
${AWK} 'BEGIN {fnd=0;} /Feature Compat/ {if (match($0, "BackupSuper")) fnd=1;} END {print fnd;}'`
76
if [ "${feat}" = "1" ]; then
77
echo "Backup super block already enabled on device ${device}"
83
if [ $numblocks -le ${backup[0]} ]; then
84
echo "Device $device too small to hold backup superblocks"
90
block=$[${backup[$i]} / $[2 ** $[$bsbits - 9]]]
91
if [ $block -lt $numblocks ]; then
92
icheckargs="$icheckargs $block"
99
DEBUGFS=`which debugfs.ocfs2`
106
if [ -z "${DEBUGFS}" ]; then echo "error: \"debugfs.ocfs2\" not found in path"; exit 1; fi
107
if [ -z "${AWK}" ]; then echo "error: \"awk\" not found in path"; exit 1; fi
108
if [ -z "${SEQ}" ]; then echo "error: \"seq\" not found in path"; exit 1; fi
109
if [ -z "${TEE}" ]; then echo "error: \"tee\" not found in path"; exit 1; fi
110
if [ -z "${DATE}" ]; then echo "error: \"date\" not found in path"; exit 1; fi
119
YMD=`${DATE} +%Y%m%d_%H%M%S`
120
TEMPFILE=/tmp/__${YMD}__
122
# Backup super offsets in 512 byte blocks
132
if [ -z "${device}" ]; then
144
echo "Locating inodes using blocks${icheckargs} on device ${device}"
145
#echo "${DEBUGFS} -R \"icheck${icheckargs}\" ${device}"
146
${DEBUGFS} -R "icheck${icheckargs}" ${device} | ${TEE} ${TEMPFILE}
148
inodes=`${AWK} 'BEGIN {out = "";} // {if (strtonum($2) != 0) out = out " " "<"$2">";} END {print out};' ${TEMPFILE}`
152
if [ -z "${inodes}" ]; then
153
echo "All Backup superblock clusters are unused"
157
echo "Matching inodes to object names"
158
#echo "${DEBUGFS} -R \"findpath ${inodes}\" ${device}"
159
${DEBUGFS} -R "findpath ${inodes}" ${device}