]>
git.proxmox.com Git - ceph.git/blob - ceph/src/os/ObjectStore.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
16 #include "ObjectStore.h"
17 #include "common/Formatter.h"
18 #include "common/safe_io.h"
21 #include "filestore/FileStore.h"
23 #include "memstore/MemStore.h"
24 #if defined(WITH_BLUESTORE)
25 #include "bluestore/BlueStore.h"
28 #include "kstore/KStore.h"
33 std::unique_ptr
<ObjectStore
> ObjectStore::create(
38 if (type
== "memstore") {
39 return std::make_unique
<MemStore
>(cct
, data
);
41 #if defined(WITH_BLUESTORE)
42 if (type
== "bluestore" || type
== "random") {
43 return std::make_unique
<BlueStore
>(cct
, data
);
50 std::unique_ptr
<ObjectStore
> ObjectStore::create(
54 const string
& journal
,
57 if (type
== "filestore" || (type
== "random" && rand() % 2)) {
58 return std::make_unique
<FileStore
>(cct
, data
, journal
, flags
);
60 if (type
== "kstore" &&
61 cct
->check_experimental_feature_enabled("kstore")) {
62 return std::make_unique
<KStore
>(cct
, data
);
64 return create(cct
, type
, data
);
68 int ObjectStore::probe_block_device_fsid(
75 #if defined(WITH_BLUESTORE)
76 // first try bluestore -- it has a crc on its header and will fail
78 r
= BlueStore::get_block_device_fsid(cct
, path
, fsid
);
80 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is bluestore, "
87 // okay, try FileStore (journal).
88 r
= FileStore::get_block_device_fsid(cct
, path
, fsid
);
90 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is filestore, "
99 int ObjectStore::write_meta(const std::string
& key
,
100 const std::string
& value
)
104 int r
= safe_write_file(path
.c_str(), key
.c_str(),
105 v
.c_str(), v
.length(), 0600);
111 int ObjectStore::read_meta(const std::string
& key
,
115 int r
= safe_read_file(path
.c_str(), key
.c_str(),
119 // drop trailing newlines
120 while (r
&& isspace(buf
[r
-1])) {
123 *value
= string(buf
, r
);