]>
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 return new BlueStore(cct
, data
);
79 if (type
== "random") {
81 return new FileStore(cct
, data
, journal
, flags
);
83 return new BlueStore(cct
, data
);
87 if (type
== "random") {
88 return new FileStore(cct
, data
, journal
, flags
);
91 if (type
== "kstore" &&
92 cct
->check_experimental_feature_enabled("kstore")) {
93 return new KStore(cct
, data
);
98 int ObjectStore::probe_block_device_fsid(
105 #if defined(HAVE_LIBAIO)
106 // first try bluestore -- it has a crc on its header and will fail
108 r
= BlueStore::get_block_device_fsid(cct
, path
, fsid
);
110 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is bluestore, "
116 // okay, try FileStore (journal).
117 r
= FileStore::get_block_device_fsid(cct
, path
, fsid
);
119 lgeneric_dout(cct
, 0) << __func__
<< " " << path
<< " is filestore, "
127 int ObjectStore::write_meta(const std::string
& key
,
128 const std::string
& value
)
132 int r
= safe_write_file(path
.c_str(), key
.c_str(),
133 v
.c_str(), v
.length());
139 int ObjectStore::read_meta(const std::string
& key
,
143 int r
= safe_read_file(path
.c_str(), key
.c_str(),
147 // drop trailing newlines
148 while (r
&& isspace(buf
[r
-1])) {
151 *value
= string(buf
, r
);
158 ostream
& operator<<(ostream
& out
, const ObjectStore::Sequencer
& s
)
160 return out
<< "osr(" << s
.get_name() << " " << &s
<< ")";
163 ostream
& operator<<(ostream
& out
, const ObjectStore::Transaction
& tx
) {
165 return out
<< "Transaction(" << &tx
<< ")";
168 unsigned ObjectStore::apply_transactions(Sequencer
*osr
,
169 vector
<Transaction
>& tls
,
174 Mutex
my_lock("ObjectStore::apply_transaction::my_lock");
177 C_SafeCond
*onreadable
= new C_SafeCond(&my_lock
, &my_cond
, &done
, &r
);
179 queue_transactions(osr
, tls
, onreadable
, ondisk
);
183 my_cond
.Wait(my_lock
);
188 int ObjectStore::queue_transactions(
190 vector
<Transaction
>& tls
,
193 Context
*onreadable_sync
,
195 TrackedOpRef op
= TrackedOpRef())
197 RunOnDeleteRef
_complete (std::make_shared
<RunOnDelete
>(oncomplete
));
198 Context
*_onreadable
= new Wrapper
<RunOnDeleteRef
>(
199 onreadable
, _complete
);
200 Context
*_oncommit
= new Wrapper
<RunOnDeleteRef
>(
201 oncommit
, _complete
);
202 return queue_transactions(osr
, tls
, _onreadable
, _oncommit
,
203 onreadable_sync
, op
);