~ubuntu-branches/ubuntu/utopic/ceph/utopic

« back to all changes in this revision

Viewing changes to src/tools/ceph_osdomap_tool.cc

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-04-09 11:14:03 UTC
  • mfrom: (1.1.33)
  • Revision ID: package-import@ubuntu.com-20140409111403-jlql95pa8kg1nk9a
Tags: 0.79-0ubuntu1
* New upstream release (LP: #1278466):
  - d/p/modules.patch: Refreshed.
  - d/ceph.install: Install all jerasure modules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 
2
// vim: ts=8 sw=2 smarttab
 
3
/*
 
4
* Ceph - scalable distributed file system
 
5
*
 
6
* Copyright (C) 2012 Inktank, Inc.
 
7
*
 
8
* This is free software; you can redistribute it and/or
 
9
* modify it under the terms of the GNU Lesser General Public
 
10
* License kkjversion 2.1, as published by the Free Software
 
11
* Foundation. See file COPYING.
 
12
*/
 
13
#include <boost/scoped_ptr.hpp>
 
14
#include <boost/lexical_cast.hpp>
 
15
#include <boost/program_options/option.hpp>
 
16
#include <boost/program_options/options_description.hpp>
 
17
#include <boost/program_options/variables_map.hpp>
 
18
#include <boost/program_options/cmdline.hpp>
 
19
#include <boost/program_options/parsers.hpp>
 
20
#include <iostream>
 
21
#include <set>
 
22
#include <sstream>
 
23
#include <stdlib.h>
 
24
#include <fstream>
 
25
#include <string>
 
26
#include <sstream>
 
27
#include <map>
 
28
#include <set>
 
29
#include <boost/scoped_ptr.hpp>
 
30
 
 
31
#include "global/global_init.h"
 
32
#include "os/LevelDBStore.h"
 
33
#include "mon/MonitorDBStore.h"
 
34
#include "os/DBObjectMap.h"
 
35
 
 
36
namespace po = boost::program_options;
 
37
using namespace std;
 
38
 
 
39
int main(int argc, char **argv) {
 
40
  po::options_description desc("Allowed options");
 
41
  string store_path, cmd, out_path;
 
42
  bool paranoid = false;
 
43
  desc.add_options()
 
44
    ("help", "produce help message")
 
45
    ("omap-path", po::value<string>(&store_path),
 
46
     "path to mon directory, mandatory (current/omap usually)")
 
47
    ("paranoid", po::value<bool>(&paranoid),
 
48
     "use paranoid checking")
 
49
    ("command", po::value<string>(&cmd),
 
50
     "command")
 
51
    ;
 
52
  po::positional_options_description p;
 
53
  p.add("command", 1);
 
54
 
 
55
  po::variables_map vm;
 
56
  po::parsed_options parsed =
 
57
    po::command_line_parser(argc, argv).options(desc).positional(p).run();
 
58
  po::store(
 
59
    parsed,
 
60
    vm);
 
61
  try {
 
62
    po::notify(vm);
 
63
  } catch (...) {
 
64
    cout << desc << std::endl;
 
65
    return 1;
 
66
  }
 
67
 
 
68
  vector<const char *> ceph_options, def_args;
 
69
  vector<string> ceph_option_strings = po::collect_unrecognized(
 
70
    parsed.options, po::include_positional);
 
71
  ceph_options.reserve(ceph_option_strings.size());
 
72
  for (vector<string>::iterator i = ceph_option_strings.begin();
 
73
       i != ceph_option_strings.end();
 
74
       ++i) {
 
75
    ceph_options.push_back(i->c_str());
 
76
  }
 
77
 
 
78
  global_init(
 
79
    &def_args, ceph_options, CEPH_ENTITY_TYPE_OSD,
 
80
    CODE_ENVIRONMENT_UTILITY, 0);
 
81
  common_init_finish(g_ceph_context);
 
82
  g_ceph_context->_conf->apply_changes(NULL);
 
83
  g_conf = g_ceph_context->_conf;
 
84
 
 
85
  if (vm.count("help")) {
 
86
    std::cerr << desc << std::endl;
 
87
    return 1;
 
88
  }
 
89
 
 
90
  LevelDBStore* store(new LevelDBStore(g_ceph_context, store_path));
 
91
  if (paranoid) {
 
92
    std::cerr << "Enabling paranoid checks" << std::endl;
 
93
    store->options.paranoid_checks = paranoid;
 
94
  }
 
95
  DBObjectMap omap(store);
 
96
  stringstream out;
 
97
  int r = store->open(out);
 
98
  if (r < 0) {
 
99
    std::cerr << "Store open got: " << cpp_strerror(r) << std::endl;
 
100
    std::cerr << "Output: " << out.str() << std::endl;
 
101
    goto done;
 
102
  }
 
103
  r = 0;
 
104
 
 
105
 
 
106
  if (cmd == "dump-raw-keys") {
 
107
    KeyValueDB::WholeSpaceIterator i = store->get_iterator();
 
108
    for (i->seek_to_first(); i->valid(); i->next()) {
 
109
      std::cout << i->raw_key() << std::endl;
 
110
    }
 
111
  } else if (cmd == "dump-raw-key-vals") {
 
112
    KeyValueDB::WholeSpaceIterator i = store->get_iterator();
 
113
    for (i->seek_to_first(); i->valid(); i->next()) {
 
114
      std::cout << i->raw_key() << std::endl;
 
115
      i->value().hexdump(std::cout);
 
116
    }
 
117
  } else if (cmd == "dump-objects") {
 
118
    vector<ghobject_t> objects;
 
119
    r = omap.list_objects(&objects);
 
120
    if (r < 0) {
 
121
      std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
 
122
      goto done;
 
123
    }
 
124
    for (vector<ghobject_t>::iterator i = objects.begin();
 
125
         i != objects.end();
 
126
         ++i) {
 
127
      std::cout << *i << std::endl;
 
128
    }
 
129
    r = 0;
 
130
  } else if (cmd == "dump-objects-with-keys") {
 
131
    vector<ghobject_t> objects;
 
132
    r = omap.list_objects(&objects);
 
133
    if (r < 0) {
 
134
      std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
 
135
      goto done;
 
136
    }
 
137
    for (vector<ghobject_t>::iterator i = objects.begin();
 
138
         i != objects.end();
 
139
         ++i) {
 
140
      std::cout << "Object: " << *i << std::endl;
 
141
      ObjectMap::ObjectMapIterator j = omap.get_iterator(i->hobj);
 
142
      for (j->seek_to_first(); j->valid(); j->next()) {
 
143
        std::cout << j->key() << std::endl;
 
144
        j->value().hexdump(std::cout);
 
145
      }
 
146
    }
 
147
  } else if (cmd == "check") {
 
148
    r = omap.check(std::cout);
 
149
    if (!r) {
 
150
      std::cerr << "check got: " << cpp_strerror(r) << std::endl;
 
151
      goto done;
 
152
    }
 
153
    std::cout << "check succeeded" << std::endl;
 
154
  } else {
 
155
    std::cerr << "Did not recognize command " << cmd << std::endl;
 
156
    goto done;
 
157
  }
 
158
 
 
159
  done:
 
160
  return r;
 
161
}