4 # Copyright (C) 2015 Ubuntu Kylin
6 # Author: Min Chen <minchen@ubuntukylin.com>
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU Library Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Library Public License for more details.
19 my_dir=$(dirname "$0")
25 function check_ceph_osd()
27 local func="check_ceph_osd"
29 # if ceph-osd service is still running, except flush-journal
30 if [ "`ps aux|grep ceph-osd|grep -v flush-journal|grep -v grep`"x != ""x ];then
31 echo "[$host]: $func: ceph-osd is running..., stop it"
36 function cat_pg_epoch()
38 local func="cat_pg_epoch"
40 if [ -e $node_pg_epoch ];then
45 function cat_image_v1()
47 local func="cat_image_v1"
49 if [ -e $image_v1 ];then
54 function cat_image_v2()
56 local func="cat_image_v2"
58 if [ -e $image_v2 ];then
63 function flush_osd_journal()
65 local func="flush_osd_journal"
67 local osd_data_path=$osd_data
68 local osd_journal_path=$osd_data/journal
69 local whoami_path=$osd_data/whoami
71 if [ ! -e $whoami_path ];then
72 echo "[$host]: $func: $whoami_path not exists"
75 local whoami=`cat $whoami_path`
76 echo "[$host]: $func ..."
77 ceph-osd -i $whoami --osd-data $osd_data_path --osd-journal $osd_journal_path --flush-journal >/dev/null
79 echo "[$host]: $func: flush osd journal failed"
84 function do_omap_list()
86 local func="do_omap_list"
89 echo "[$host]: $func ..."
94 function do_pg_epoch()
96 local func="do_pg_epoch"
103 local host=`hostname`
104 echo "[$host]: $func ..."
108 pgid=`echo $line|awk '{print $1}'`
109 data_path=`echo $line|awk '{print $2}'`
111 echo -e "$node $pgid $pg_epoch $data_path" >>$node_pg_epoch
116 # get an list of image in this osd node, pg epoch maybe not the latest, the admin node will do distinguish
117 function do_image_list()
119 local func="do_image_list"
122 local node=`hostname`
125 local host=`hostname`
126 echo "[$host]: $func ..."
127 for line in `cat $image_list_v1`
129 pgid=`get_pgid $line`
131 echo "$node $line $pg_epoch" >> $image_v1
133 for line in `cat $image_list_v2`
135 pgid=`get_pgid $line`
137 echo "$node $line $pg_epoch" >> $image_v2
141 function do_image_id()
143 local func="do_image_id"
148 function do_image_metadata_v1()
150 local func="do_image_metadata_v1"
152 local image_header_hobject=$2
154 get_image_metadata_v1 $image_header_hobject $snap_name
157 function do_image_metadata_v2()
159 local func="do_image_metadata_v2"
162 local image_header_hobject=$3
164 get_map_header $image_id
165 get_meta_header_seq $map_header_prefix $map_header_key
166 get_image_metadata_v2 $meta_header_seq $snap_name