]>
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 "include/memory.h"
17 #include "ObjectStore.h"
18 #include "common/Formatter.h"
19 #include "common/safe_io.h"
21 #include "filestore/FileStore.h"
22 #include "memstore/MemStore.h"
23 #if defined(HAVE_LIBAIO)
24 #include "bluestore/BlueStore.h"
26 #include "kstore/KStore.h"
28 void decode_str_str_map_to_bl(bufferlist::iterator
& p
,
31 bufferlist::iterator start
= p
;
44 start
.copy(len
, *out
);
47 void decode_str_set_to_bl(bufferlist::iterator
& p
,
50 bufferlist::iterator start
= p
;
60 start
.copy(len
, *out
);
63 ObjectStore
*ObjectStore::create(CephContext
*cct
,
66 const string
& journal
,
69 if (type
== "filestore") {
70 return new FileStore(cct
, data
, journal
, flags
);
72 if (type
== "memstore") {
73 return new MemStore(cct
, data
);
75 #if defined(HAVE_LIBAIO)
76 if (type
== "bluestore" &&
77 cct
->check_experimental_feature_enabled("bluestore")) {
78 return new BlueStore(cct
, data
);
80 if (type
== "random" &&
81 cct
->check_experimental_feature_enabled("bluestore")) {
83 return new FileStore(cct
, data
, journal
, flags
);
85 return new BlueStore(cct
, data
);
89 if (type
== "random") {
90 return new FileStore(cct
, data
, journal
, flags
);
93 if (type
== "kstore" &&
94 cct
->check_experimental_feature_enabled("kstore")) {
95 return new KStore(cct
, data
);
100 int ObjectStore::probe_block_device_fsid(
107 #if defined(HAVE_LIBAIO)
108 // first try bluestore -- it has a crc on its header and will fail
110 r
= BlueStore::get_block_device_fsid(cct
, path
, fsid
);
112 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is bluestore, "
118 // okay, try FileStore (journal).
119 r
= FileStore::get_block_device_fsid(cct
, path
, fsid
);
121 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is filestore, "
129 int ObjectStore::write_meta(const std::string
& key
,
130 const std::string
& value
)
134 int r
= safe_write_file(path
.c_str(), key
.c_str(),
135 v
.c_str(), v
.length());
141 int ObjectStore::read_meta(const std::string
& key
,
145 int r
= safe_read_file(path
.c_str(), key
.c_str(),
149 // drop trailing newlines
150 while (r
&& isspace(buf
[r
-1])) {
153 *value
= string(buf
, r
);
160 ostream
& operator<<(ostream
& out
, const ObjectStore::Sequencer
& s
)
162 return out
<< "osr(" << s
.get_name() << " " << &s
<< ")";
165 ostream
& operator<<(ostream
& out
, const ObjectStore::Transaction
& tx
) {
167 return out
<< "Transaction(" << &tx
<< ")";
170 unsigned ObjectStore::apply_transactions(Sequencer
*osr
,
171 vector
<Transaction
>& tls
,
176 Mutex
my_lock("ObjectStore::apply_transaction::my_lock");
179 C_SafeCond
*onreadable
= new C_SafeCond(&my_lock
, &my_cond
, &done
, &r
);
181 queue_transactions(osr
, tls
, onreadable
, ondisk
);
185 my_cond
.Wait(my_lock
);
190 int ObjectStore::queue_transactions(
192 vector
<Transaction
>& tls
,
195 Context
*onreadable_sync
,
197 TrackedOpRef op
= TrackedOpRef())
199 RunOnDeleteRef
_complete (std::make_shared
<RunOnDelete
>(oncomplete
));
200 Context
*_onreadable
= new Wrapper
<RunOnDeleteRef
>(
201 onreadable
, _complete
);
202 Context
*_oncommit
= new Wrapper
<RunOnDeleteRef
>(
203 oncommit
, _complete
);
204 return queue_transactions(osr
, tls
, _onreadable
, _oncommit
,
205 onreadable_sync
, op
);