1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2013 Inktank
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#include <boost/scoped_ptr.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/program_options/option.hpp>
#include <boost/program_options/options_description.hpp>
#include <boost/program_options/variables_map.hpp>
#include <boost/program_options/cmdline.hpp>
#include <boost/program_options/parsers.hpp>
#include <iostream>
#include <set>
#include <sstream>
#include <stdlib.h>
#include <fstream>
#include "common/Formatter.h"
#include "global/global_init.h"
#include "os/ObjectStore.h"
#include "os/FileStore.h"
#include "common/perf_counters.h"
#include "common/errno.h"
#include "osd/PG.h"
#include "osd/OSD.h"
namespace po = boost::program_options;
using namespace std;
static void invalid_path(string &path)
{
cout << "Invalid path to osd store specified: " << path << "\n";
exit(1);
}
int main(int argc, char **argv)
{
string fspath, jpath, pgid, type;
Formatter *formatter = new JSONFormatter(true);
po::options_description desc("Allowed options");
desc.add_options()
("help", "produce help message")
("filestore-path", po::value<string>(&fspath),
"path to filestore directory, mandatory")
("journal-path", po::value<string>(&jpath),
"path to journal, mandatory")
("pgid", po::value<string>(&pgid),
"PG id, mandatory")
("type", po::value<string>(&type),
"Type which is 'info' or 'log', mandatory")
("debug", "Enable diagnostic output to stderr")
;
po::variables_map vm;
po::parsed_options parsed =
po::command_line_parser(argc, argv).options(desc).allow_unregistered().run();
po::store( parsed, vm);
try {
po::notify(vm);
}
catch(...) {
cout << desc << std::endl;
exit(1);
}
if (vm.count("help")) {
cout << desc << std::endl;
return 1;
}
if (!vm.count("filestore-path")) {
cout << "Must provide filestore-path" << std::endl
<< desc << std::endl;
return 1;
}
if (!vm.count("journal-path")) {
cout << "Must provide journal-path" << std::endl
<< desc << std::endl;
return 1;
}
if (!vm.count("pgid")) {
cout << "Must provide pgid" << std::endl
<< desc << std::endl;
return 1;
}
if (!vm.count("type")) {
cout << "Must provide type ('info' or 'log')" << std::endl
<< desc << std::endl;
return 1;
}
if (fspath.length() == 0 || jpath.length() == 0 || pgid.length() == 0 ||
(type != "info" && type != "log")) {
cerr << "Invalid params" << std::endl;
exit(1);
}
vector<const char *> ceph_options, def_args;
vector<string> ceph_option_strings = po::collect_unrecognized(
parsed.options, po::include_positional);
ceph_options.reserve(ceph_option_strings.size());
for (vector<string>::iterator i = ceph_option_strings.begin();
i != ceph_option_strings.end();
++i) {
ceph_options.push_back(i->c_str());
}
//Suppress derr() output to stderr by default
if (!vm.count("debug")) {
close(2);
(void)open("/dev/null", O_WRONLY);
}
global_init(
&def_args, ceph_options, CEPH_ENTITY_TYPE_OSD,
CODE_ENVIRONMENT_UTILITY, 0);
//CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
common_init_finish(g_ceph_context);
g_ceph_context->_conf->apply_changes(NULL);
g_conf = g_ceph_context->_conf;
//Verify that fspath really is an osd store
struct stat st;
if (::stat(fspath.c_str(), &st) == -1) {
perror("fspath");
invalid_path(fspath);
}
if (!S_ISDIR(st.st_mode)) {
invalid_path(fspath);
}
string check = fspath + "/whoami";
if (::stat(check.c_str(), &st) == -1) {
perror("whoami");
invalid_path(fspath);
}
if (!S_ISREG(st.st_mode)) {
invalid_path(fspath);
}
check = fspath + "/current";
if (::stat(check.c_str(), &st) == -1) {
perror("current");
invalid_path(fspath);
}
if (!S_ISDIR(st.st_mode)) {
invalid_path(fspath);
}
pg_t arg_pgid;
if (!arg_pgid.parse(pgid.c_str())) {
cerr << "Invalid pgid '" << pgid << "' specified" << std::endl;
exit(1);
}
int ret = 0;
ObjectStore *fs = new FileStore(fspath, jpath);
if (fs->mount() < 0) {
cout << "mount failed" << std::endl;
return 1;
}
bool found = false;
vector<coll_t> ls;
int r = fs->list_collections(ls);
if (r < 0) {
cerr << "failed to list pgs: " << cpp_strerror(-r) << std::endl;
exit(1);
}
for (vector<coll_t>::iterator it = ls.begin();
it != ls.end();
it++) {
coll_t coll = *it;
pg_t pgid;
snapid_t snap;
if (!it->is_pg(pgid, snap)) {
continue;
}
if (pgid != arg_pgid) {
continue;
}
if (snap != CEPH_NOSNAP) {
cout << "load_pgs skipping snapped dir " << coll
<< " (pg " << pgid << " snap " << snap << ")" << std::endl;
continue;
}
bufferlist bl;
epoch_t map_epoch = PG::peek_map_epoch(fs, coll, &bl);
(void)map_epoch;
found = true;
pg_info_t info;
map<epoch_t,pg_interval_t> past_intervals;
hobject_t biginfo_oid = OSD::make_pg_biginfo_oid(pgid);
interval_set<snapid_t> snap_collections;
int r = PG::read_info(fs, coll, bl, info, past_intervals, biginfo_oid,
snap_collections);
if (r < 0) {
cerr << "read_info error " << cpp_strerror(-r) << std::endl;
ret = 1;
continue;
}
if (type == "info") {
formatter->open_object_section("info");
info.dump(formatter);
formatter->close_section();
formatter->flush(cout);
cout << std::endl;
break;
} else if (type == "log") {
PG::OndiskLog ondisklog;
PG::IndexedLog log;
pg_missing_t missing;
hobject_t logoid = OSD::make_pg_log_oid(pgid);
try {
ostringstream oss;
PG::read_log(fs, coll, logoid, info, ondisklog, log, missing, oss);
if (vm.count("debug"))
cerr << oss;
}
catch (const buffer::error &e) {
cerr << "read_log threw exception error", e.what();
ret = 1;
break;
}
formatter->open_object_section("log");
log.dump(formatter);
formatter->close_section();
formatter->flush(cout);
cout << std::endl;
formatter->open_object_section("missing");
missing.dump(formatter);
formatter->close_section();
formatter->flush(cout);
cout << std::endl;
}
}
if (!found) {
cerr << "PG '" << arg_pgid << "' not found" << std::endl;
ret = 1;
}
if (fs->umount() < 0) {
cerr << "umount failed" << std::endl;
return 1;
}
return ret;
}
|