~wb-munzinger/+junk/ocfs2-tools

« back to all changes in this revision

Viewing changes to extras/verify_backup_super

  • Committer: David Weber
  • Date: 2012-01-30 08:42:00 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: wb@munzinger.de-20120130084200-c8cy478mu9fk7tkf
Import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
3
# Copyright (C) 2007 Oracle.  All rights reserved.
 
4
#
 
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.
 
8
 
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.
 
13
 
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.
 
18
#
 
19
# Author: Sunil Mushran 03/01/2007
 
20
#
 
21
################################################################
 
22
#
 
23
# verify_backup_super
 
24
#
 
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.
 
29
#
 
30
################################################################
 
31
 
 
32
usage() {
 
33
    echo "usage ${APP} /dev/sdX"
 
34
    exit 1
 
35
}
 
36
 
 
37
get_sizes() {
 
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;}'`
 
41
 
 
42
    if [ -z "$bsbits" ] || [ -a "$csbits" ] || [ -a "$numcls" ]; then
 
43
        echo "error: not an OCFS2 device"
 
44
        exit 1
 
45
    fi
 
46
 
 
47
    #in bytes
 
48
    blocksize=$[$[2 ** $[$bsbits - 9]] * 512]
 
49
    clustsize=$[$[2 ** $[$csbits - 9]] * 512]
 
50
 
 
51
    #in blocks
 
52
    numblocks=$[$numcls * $clustsize / $blocksize]
 
53
}
 
54
 
 
55
# Ensure version is >= 1.2.3
 
56
verify_version() {
 
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;}
 
64
                               else {print 0}; }
 
65
              else {print 0;} }'`
 
66
    if [ "${ret}" = "0" ]; then
 
67
        echo "Upgrade to ocfs2-tools 1.2.3 or later"
 
68
        exit 1
 
69
    fi
 
70
}
 
71
 
 
72
# Feature Compat: 1 BackupSuper
 
73
has_backup_super() {
 
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}"
 
78
        exit 0
 
79
    fi
 
80
}
 
81
 
 
82
get_icheck_args() {
 
83
    if [ $numblocks -le ${backup[0]} ]; then
 
84
        echo "Device $device too small to hold backup superblocks"
 
85
        exit 0
 
86
    fi
 
87
 
 
88
    for i in `${SEQ} 0 5`
 
89
    do
 
90
       block=$[${backup[$i]} / $[2 ** $[$bsbits - 9]]]
 
91
       if [ $block -lt $numblocks ]; then
 
92
           icheckargs="$icheckargs $block"
 
93
       else
 
94
           break
 
95
       fi
 
96
    done
 
97
}
 
98
 
 
99
DEBUGFS=`which debugfs.ocfs2`
 
100
AWK=`which awk`
 
101
SEQ=`which seq`
 
102
TEE=`which tee`
 
103
DATE=`which date`
 
104
APP=`basename $0`
 
105
 
 
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
 
111
 
 
112
blocksize=0
 
113
bsbits=0
 
114
csbits=0
 
115
clustersize=0
 
116
numblocks=0
 
117
icheckargs=""
 
118
 
 
119
YMD=`${DATE} +%Y%m%d_%H%M%S`
 
120
TEMPFILE=/tmp/__${YMD}__
 
121
 
 
122
# Backup super offsets in 512 byte blocks
 
123
backup[0]=2097152
 
124
backup[1]=8388608
 
125
backup[2]=33554432
 
126
backup[3]=134217728
 
127
backup[4]=536870912
 
128
backup[5]=2147483648
 
129
 
 
130
device=$1
 
131
 
 
132
if [ -z "${device}" ]; then
 
133
    usage ;
 
134
fi
 
135
 
 
136
get_sizes
 
137
 
 
138
verify_version
 
139
 
 
140
has_backup_super
 
141
 
 
142
get_icheck_args
 
143
 
 
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}
 
147
 
 
148
inodes=`${AWK} 'BEGIN {out = "";} // {if (strtonum($2) != 0) out = out " " "<"$2">";} END {print out};'  ${TEMPFILE}`
 
149
 
 
150
#echo $inodes
 
151
 
 
152
if [ -z "${inodes}" ]; then
 
153
    echo "All Backup superblock clusters are unused"
 
154
    exit 0
 
155
fi
 
156
 
 
157
echo "Matching inodes to object names"
 
158
#echo "${DEBUGFS} -R \"findpath ${inodes}\" ${device}"
 
159
${DEBUGFS} -R "findpath ${inodes}" ${device}