]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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) 2004-2006 Sage Weil <sage@newdream.net> | |
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 version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | #include <ctype.h> | |
15 | #include <sstream> | |
7c673cae FG |
16 | #include "ObjectStore.h" |
17 | #include "common/Formatter.h" | |
18 | #include "common/safe_io.h" | |
19 | ||
20effc67 | 20 | #include "memstore/MemStore.h" |
11fdf7f2 | 21 | #if defined(WITH_BLUESTORE) |
7c673cae FG |
22 | #include "bluestore/BlueStore.h" |
23 | #endif | |
9f95a23c | 24 | #ifndef WITH_SEASTAR |
7c673cae | 25 | #include "kstore/KStore.h" |
9f95a23c | 26 | #endif |
7c673cae | 27 | |
f67539c2 TL |
28 | using std::string; |
29 | ||
20effc67 TL |
30 | std::unique_ptr<ObjectStore> ObjectStore::create( |
31 | CephContext *cct, | |
32 | const string& type, | |
33 | const string& data) | |
7c673cae | 34 | { |
7c673cae | 35 | if (type == "memstore") { |
20effc67 | 36 | return std::make_unique<MemStore>(cct, data); |
7c673cae | 37 | } |
11fdf7f2 | 38 | #if defined(WITH_BLUESTORE) |
20effc67 TL |
39 | if (type == "bluestore" || type == "random") { |
40 | return std::make_unique<BlueStore>(cct, data); | |
7c673cae | 41 | } |
9f95a23c | 42 | #endif |
20effc67 TL |
43 | return nullptr; |
44 | } | |
45 | ||
9f95a23c | 46 | #ifndef WITH_SEASTAR |
20effc67 TL |
47 | std::unique_ptr<ObjectStore> ObjectStore::create( |
48 | CephContext *cct, | |
49 | const string& type, | |
50 | const string& data, | |
51 | const string& journal, | |
52 | osflagbits_t flags) | |
53 | { | |
1e59de90 TL |
54 | if (type == "filestore") { |
55 | lgeneric_derr(cct) << __func__ << ": FileStore has been deprecated and is no longer supported" << dendl; | |
56 | return nullptr; | |
7c673cae | 57 | } |
7c673cae FG |
58 | if (type == "kstore" && |
59 | cct->check_experimental_feature_enabled("kstore")) { | |
20effc67 | 60 | return std::make_unique<KStore>(cct, data); |
7c673cae | 61 | } |
20effc67 | 62 | return create(cct, type, data); |
7c673cae | 63 | } |
20effc67 | 64 | #endif |
7c673cae FG |
65 | |
66 | int ObjectStore::probe_block_device_fsid( | |
67 | CephContext *cct, | |
68 | const string& path, | |
69 | uuid_d *fsid) | |
70 | { | |
71 | int r; | |
72 | ||
11fdf7f2 | 73 | #if defined(WITH_BLUESTORE) |
7c673cae FG |
74 | // first try bluestore -- it has a crc on its header and will fail |
75 | // reliably. | |
76 | r = BlueStore::get_block_device_fsid(cct, path, fsid); | |
77 | if (r == 0) { | |
78 | lgeneric_dout(cct, 0) << __func__ << " " << path << " is bluestore, " | |
79 | << *fsid << dendl; | |
80 | return r; | |
81 | } | |
82 | #endif | |
83 | ||
7c673cae FG |
84 | return -EINVAL; |
85 | } | |
86 | ||
87 | int ObjectStore::write_meta(const std::string& key, | |
88 | const std::string& value) | |
89 | { | |
90 | string v = value; | |
91 | v += "\n"; | |
92 | int r = safe_write_file(path.c_str(), key.c_str(), | |
eafe8130 | 93 | v.c_str(), v.length(), 0600); |
7c673cae FG |
94 | if (r < 0) |
95 | return r; | |
96 | return 0; | |
97 | } | |
98 | ||
99 | int ObjectStore::read_meta(const std::string& key, | |
100 | std::string *value) | |
101 | { | |
102 | char buf[4096]; | |
103 | int r = safe_read_file(path.c_str(), key.c_str(), | |
104 | buf, sizeof(buf)); | |
105 | if (r <= 0) | |
106 | return r; | |
107 | // drop trailing newlines | |
108 | while (r && isspace(buf[r-1])) { | |
109 | --r; | |
110 | } | |
111 | *value = string(buf, r); | |
112 | return 0; | |
113 | } |