From ae02970ecf43af2fe52e775588bc31c7a316d9a3 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Mon, 11 May 2009 16:22:08 -0700 Subject: [PATCH] librados: build the .so --- src/Makefile.am | 53 +++-- src/common/dyn_snprintf.c | 2 +- src/librados/librados.cc | 417 +++++++++++++++++++++++++++++++++++++ src/librados/librados.h | 17 +- src/librados/testrados.cc | 425 +------------------------------------- 5 files changed, 471 insertions(+), 443 deletions(-) create mode 100644 src/librados/librados.cc diff --git a/src/Makefile.am b/src/Makefile.am index 5733a18827f69..91f298a7e9fd1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,8 +21,6 @@ osdmaptool_SOURCES = osdmaptool.cc osdmaptool_LDADD = libcrush.a libcommon.a cconf_SOURCES = cconf.cc cconf_LDADD = libcommon.a -testrados_SOURCES = librados/testrados.cc msg/SimpleMessenger.cc -testrados_LDADD = libmds.a libosdc.a libcrush.a libcommon.a mount_ceph_SOURCES = mount.ceph.c @@ -89,25 +87,48 @@ bin_PROGRAMS += psim fakesyn endif -## libcrush.so +########## +BUILT_SOURCES = + +# libcrush.so libcrush_so_a_SOURCES = \ crush/builder.c \ crush/mapper.c \ crush/crush.c -libcrush_so_a_CFLAGS = ${AM_CFLAGS} -fPIC -#libcrush.so: libcrush_so.a -# ${CC} -I. -fPIC -shared -Wl,-soname,$@.1 ${CFLAGS} ${LIBS} ${libcrush_so_a_SOURCES} -o $@ -#BUILT_SOURCES = libcrush.so +libcrush.so: ${libcrush_so_a_SOURCES} + ${CC} -I. -fPIC -shared -Wl,-soname,$@.1 ${AM_CFLAGS} ${LIBS} $^ -o $@ +BUILT_SOURCES += libcrush.so + +# librados +librados_so_a_SOURCES = \ + librados/librados.cc \ + msg/SimpleMessenger.cc \ + osdc/Objecter.cc \ + mon/MonClient.cc \ + msg/Message.cc \ + common/Clock.cc \ + common/Timer.cc \ + common/Finisher.cc \ + common/sctp_crc32.c\ + common/assert.cc \ + common/ConfUtils.cc \ + mon/MonMap.cc \ + mon/MonClient.cc \ + osd/OSDMap.cc \ + common/tls.cc \ + common/common_init.cc \ + common/buffer.cc \ + common/debug.cc \ + config.cc \ + common/lockdep.cc +librados.so: ${librados_so_a_SOURCES} + ${CXX} -fPIC -shared -Wl,-soname,$@.1 -I. ${AM_CXXFLAGS} ${LIBS} $^ -o $@ +BUILT_SOURCES += librados.so + +testrados_SOURCES = librados/testrados.cc + -# crushwrapper -#SWIG_FILES = crush/CrushWrapper.i crush/CrushWrapper.h -#crush/CrushWrapper_wrap.cxx: ${SWIG_FILES} -# ${SWIG} -perl5 -c++ -shadow -outdir . $< -# -#libCrushWrapper.so: crush/CrushWrapper_wrap.cxx libcrush_so.a -# ${CXX} ${CXXFLAGS} ${SWIG_PL_INCLUDES} -I. -shared -fPIC $^ config.cc -o $@ -#BUILT_SOURCES = libCrushWrapper.so ## libcephclient.so @@ -160,7 +181,7 @@ noinst_LIBRARIES = \ libmon.a libmds.a libosdc.a libosd.a libclient.a \ libos.a -noinst_LIBRARIES += libcrush_so.a #libcephclient_so.a +noinst_LIBRARIES += libcrush_so.a librados_so.a #libcephclient_so.a # extra bits EXTRA_DIST = verify-mds-journal.sh vstart.sh \ diff --git a/src/common/dyn_snprintf.c b/src/common/dyn_snprintf.c index e274b7972fbc6..be03ae562b95c 100644 --- a/src/common/dyn_snprintf.c +++ b/src/common/dyn_snprintf.c @@ -43,7 +43,7 @@ int dyn_snprintf(char **pbuf, size_t *pmax_size, int nargs, const char *format, va_end(vl); ret = CALL_SNPRINTF(*pbuf, *pmax_size, format, args); - if (ret >= *pmax_size) { + if (ret >= (int)*pmax_size) { *pmax_size = ret * 2; *pbuf = (char *)realloc(*pbuf, *pmax_size); ret = CALL_SNPRINTF(*pbuf, *pmax_size, format, args); diff --git a/src/librados/librados.cc b/src/librados/librados.cc new file mode 100644 index 0000000000000..42078ee61c72a --- /dev/null +++ b/src/librados/librados.cc @@ -0,0 +1,417 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2004-2006 Sage Weil + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include +#include +#include + +#include +#include +#include +using namespace std; + +#include "config.h" + +#include "mon/MonMap.h" +#include "mds/MDS.h" +#include "osd/OSDMap.h" + +#include "msg/SimpleMessenger.h" + +#include "common/Timer.h" +#include "common/common_init.h" + +#include "mon/MonClient.h" + +#include "osdc/Objecter.h" + +#include "messages/MOSDGetMap.h" +#include "messages/MClientMount.h" +#include "messages/MClientMountAck.h" + + +class RadosClient : public Dispatcher +{ + MonMap monmap; + OSDMap osdmap; + Messenger *messenger; + MonClient *mc; + SimpleMessenger rank; + + bool _dispatch(Message *m); + bool dispatch_impl(Message *m); + + Objecter *objecter; + + Mutex lock; + + class C_WriteAck : public Context { + object_t oid; + loff_t start; + size_t *length; + Cond *pcond; + public: + tid_t tid; + C_WriteAck(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} + void finish(int r) { + if (pcond) { + *length = r; + pcond->Signal(); + } + } + }; + class C_WriteCommit : public Context { + object_t oid; + loff_t start; + size_t *length; + Cond *pcond; + public: + tid_t tid; + C_WriteCommit(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} + void finish(int r) { + if (pcond) { + *length = r; + pcond->Signal(); + } + } + }; + class C_ExecCommit : public Context { + object_t oid; + loff_t start; + size_t *length; + Cond *pcond; + public: + tid_t tid; + C_ExecCommit(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} + void finish(int r) { + if (pcond) { + *length = r; + pcond->Signal(); + } + } + }; + class C_ReadCommit : public Context { + object_t oid; + loff_t start; + size_t *length; + bufferlist *bl; + Cond *pcond; + public: + tid_t tid; + C_ReadCommit(object_t o, loff_t s, size_t *l, bufferlist *b, Cond *cond) : oid(o), start(s), length(l), bl(b), + pcond(cond) {} + void finish(int r) { + *length = r; + if (pcond) + pcond->Signal(); + } + }; + +public: + RadosClient() : messenger(NULL), mc(NULL), lock("c3") {} + ~RadosClient(); + bool init(); + + int write(object_t& oid, const char *buf, off_t off, size_t len); + int exec(object_t& oid, const char *code, off_t data_off, size_t data_len, char *buf, size_t out_len); + int read(object_t& oid, char *buf, off_t off, size_t len); +}; + +bool RadosClient::init() +{ + mc = new MonClient(&monmap, NULL); + + // get monmap + if (!mc->get_monmap()) + return false; + + rank.bind(); + cout << "starting c3." << g_conf.id + << " at " << rank.get_rank_addr() + << " fsid " << monmap.get_fsid() + << std::endl; + + messenger = rank.register_entity(entity_name_t::CLIENT(-1)); + assert_warn(messenger); + if (!messenger) + return false; + + mc->set_messenger(messenger); + + rank.set_policy(entity_name_t::TYPE_MON, SimpleMessenger::Policy::lossy_fail_after(1.0)); + rank.set_policy(entity_name_t::TYPE_MDS, SimpleMessenger::Policy::lossless()); + rank.set_policy(entity_name_t::TYPE_OSD, SimpleMessenger::Policy::lossless()); + rank.set_policy(entity_name_t::TYPE_CLIENT, SimpleMessenger::Policy::lossless()); // mds does its own timeout/markdown + + rank.start(1); + + mc->mount(g_conf.client_mount_timeout); + + objecter = new Objecter(messenger, &monmap, &osdmap, lock); + if (!objecter) + return false; + + lock.Lock(); + mc->link_dispatcher(this); + + objecter->set_client_incarnation(0); + objecter->init(); + + objecter->set_client_incarnation(0); + + lock.Unlock(); + + return true; +} + +RadosClient::~RadosClient() +{ + if (mc) + delete mc; + if (messenger) + messenger->shutdown(); +} + + +bool RadosClient::dispatch_impl(Message *m) +{ + bool ret; + + // verify protocol version + if (m->get_orig_source().is_mds() && + m->get_header().mds_protocol != CEPH_MDS_PROTOCOL) { + dout(0) << "mds protocol v " << (int)m->get_header().mds_protocol << " != my " << CEPH_MDS_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + + if (m->get_header().mdsc_protocol != CEPH_MDSC_PROTOCOL) { + dout(0) << "mdsc protocol v " << (int)m->get_header().mdsc_protocol << " != my " << CEPH_MDSC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_orig_source().is_mon() && + m->get_header().monc_protocol != CEPH_MONC_PROTOCOL) { + dout(0) << "monc protocol v " << (int)m->get_header().monc_protocol << " != my " << CEPH_MONC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + if (m->get_orig_source().is_osd() && + m->get_header().osdc_protocol != CEPH_OSDC_PROTOCOL) { + dout(0) << "osdc protocol v " << (int)m->get_header().osdc_protocol << " != my " << CEPH_OSDC_PROTOCOL + << " from " << m->get_orig_source_inst() << " " << *m << dendl; + delete m; + return true; + } + + lock.Lock(); + ret = _dispatch(m); + lock.Unlock(); + + return ret; +} + + +bool RadosClient::_dispatch(Message *m) +{ + switch (m->get_type()) { + // OSD + case CEPH_MSG_OSD_OPREPLY: + objecter->handle_osd_op_reply((class MOSDOpReply*)m); + break; + case CEPH_MSG_OSD_MAP: + objecter->handle_osd_map((MOSDMap*)m); + break; + case CEPH_MSG_MDS_MAP: + break; + + default: + return false; + } + + return true; +} + +int RadosClient::write(object_t& oid, const char *buf, off_t off, size_t len) +{ + SnapContext snapc; + bufferlist bl; + utime_t ut = g_clock.now(); + + Mutex lock("RadosClient::write"); + Cond write_wait; + bl.append(&buf[off], len); + + C_WriteAck *onack = new C_WriteAck(oid, off, &len, &write_wait); + C_WriteCommit *oncommit = new C_WriteCommit(oid, off, &len, NULL); + + ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); + + dout(0) << "going to write" << dendl; + + lock.Lock(); + + objecter->write(oid, layout, + off, len, snapc, bl, ut, 0, + onack, oncommit); + + dout(0) << "after write call" << dendl; + + write_wait.Wait(lock); + + lock.Unlock(); + + return len; +} + +int RadosClient::exec(object_t& oid, const char *code, off_t data_off, size_t data_len, char *buf, size_t out_len) +{ + SnapContext snapc; + bufferlist bl, obl; + utime_t ut = g_clock.now(); + + Mutex lock("RadosClient::exec"); + Cond exec_wait; + bl.append(code, strlen(code) + 1); + + C_ExecCommit *oncommit = new C_ExecCommit(oid, data_off, &out_len, &exec_wait); + + ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); + + dout(0) << "going to exec" << dendl; + + lock.Lock(); + + objecter->exec(oid, layout, + data_off, data_len, CEPH_NOSNAP, bl, 0, + &obl, out_len, + oncommit); + + dout(0) << "after write call" << dendl; + + exec_wait.Wait(lock); + + lock.Unlock(); + + if (out_len) + memcpy(buf, obl.c_str(), out_len); + + return out_len; +} + +int RadosClient::read(object_t& oid, char *buf, off_t off, size_t len) +{ + SnapContext snapc; + bufferlist *bl = new bufferlist; + Mutex lock("RadosClient::read"); + Cond read_wait; + + C_ReadCommit *oncommit = new C_ReadCommit(oid, off, &len, bl, &read_wait); + + ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); + + dout(0) << "going to read" << dendl; + + lock.Lock(); + + objecter->read(oid, layout, + off, len, CEPH_NOSNAP, bl, 0, + oncommit); + + dout(0) << "after read call" << dendl; + read_wait.Wait(lock); + + lock.Unlock(); + + if (len) + memcpy(buf, bl->c_str(), len); + + delete bl; + + return len; +} + + +// --------------------------------------------- + +static void __rados_init(int argc, const char *argv[]) +{ + vector args; + + if (argc && argv) { + argv_to_vec(argc, argv, args); + env_to_vec(args); + } + common_init(args, "librados", false); + + if (g_conf.clock_tare) g_clock.tare(); +} + +static Mutex rados_init_mutex("rados_init"); +static int rados_initialized = 0; + +static RadosClient *radosp; + +#include "librados.h" + +extern "C" int rados_initialize(int argc, const char **argv) +{ + int ret = 0; + rados_init_mutex.Lock(); + + if (!rados_initialized) { + __rados_init(argc, argv); + radosp = new RadosClient; + + if (!radosp) { + ret = ENOMEM; + goto out; + } + radosp->init(); + } + ++rados_initialized; + +out: + rados_init_mutex.Unlock(); + return ret; +} + +extern "C" void rados_deinitialize() +{ + rados_init_mutex.Lock(); + --rados_initialized; + + if (!rados_initialized) + delete radosp; + + radosp = NULL; + + rados_init_mutex.Unlock(); +} + +extern "C" int rados_write(ceph_object *o, const char *buf, off_t off, size_t len) +{ + object_t oid(*o); + return radosp->write(oid, buf, off, len); +} + +extern "C" int rados_read(ceph_object *o, char *buf, off_t off, size_t len) +{ + object_t oid(*o); + return radosp->read(oid, buf, off, len); +} + diff --git a/src/librados/librados.h b/src/librados/librados.h index c2cec4d5ea02a..5b41f0a4baf6b 100644 --- a/src/librados/librados.h +++ b/src/librados/librados.h @@ -1,20 +1,19 @@ -#ifndef __C3_H -#define __C3_H +#ifndef __LIBRADOS_H +#define __LIBRADOS_H + +#include "include/types.h" #ifdef __cplusplus extern "C" { #endif - - /* initialization */ -int c3_initialize(int argc, const char **argv); /* arguments are optional */ -void c3_deinitialize(); - +int rados_initialize(int argc, const char **argv); /* arguments are optional */ +void rados_deinitialize(); /* read/write objects */ -int c3_write(object_t *oid, const char *buf, off_t off, size_t len); -int c3_read(object_t *oid, char *buf, off_t off, size_t len); +int rados_write(ceph_object *oid, const char *buf, off_t off, size_t len); +int rados_read(ceph_object *oid, char *buf, off_t off, size_t len); #ifdef __cplusplus } diff --git a/src/librados/testrados.cc b/src/librados/testrados.cc index fd93a82eb8e33..4d904a599a44c 100644 --- a/src/librados/testrados.cc +++ b/src/librados/testrados.cc @@ -12,422 +12,11 @@ * */ -#include -#include -#include - -#include -#include -#include -using namespace std; - -#include "config.h" - -#include "mon/MonMap.h" -#include "mds/MDS.h" -#include "osd/OSDMap.h" - -#include "msg/SimpleMessenger.h" - -#include "common/Timer.h" -#include "common/common_init.h" - -#include "mon/MonClient.h" - -#include "osdc/Objecter.h" - -#include "messages/MOSDGetMap.h" -#include "messages/MClientMount.h" -#include "messages/MClientMountAck.h" - -void usage() -{ - cerr << "usage: c3 -i name [flags] [--mds rank] [--shadow rank]\n"; - cerr << " -m monitorip:port\n"; - cerr << " connect to monitor at given address\n"; - cerr << " --debug_mds n\n"; - cerr << " debug MDS level (e.g. 10)\n"; - generic_server_usage(); -} - -class C3 : public Dispatcher -{ - MonMap monmap; - OSDMap osdmap; - Messenger *messenger; - MonClient *mc; - SimpleMessenger rank; - - bool _dispatch(Message *m); - bool dispatch_impl(Message *m); - - Objecter *objecter; - - Mutex lock; - - class C_WriteAck : public Context { - object_t oid; - loff_t start; - size_t *length; - Cond *pcond; - public: - tid_t tid; - C_WriteAck(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} - void finish(int r) { - if (pcond) { - *length = r; - pcond->Signal(); - } - } - }; - class C_WriteCommit : public Context { - object_t oid; - loff_t start; - size_t *length; - Cond *pcond; - public: - tid_t tid; - C_WriteCommit(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} - void finish(int r) { - if (pcond) { - *length = r; - pcond->Signal(); - } - } - }; - class C_ExecCommit : public Context { - object_t oid; - loff_t start; - size_t *length; - Cond *pcond; - public: - tid_t tid; - C_ExecCommit(object_t o, loff_t s, size_t *l, Cond *cond) : oid(o), start(s), length(l), pcond(cond) {} - void finish(int r) { - if (pcond) { - *length = r; - pcond->Signal(); - } - } - }; - class C_ReadCommit : public Context { - object_t oid; - loff_t start; - size_t *length; - bufferlist *bl; - Cond *pcond; - public: - tid_t tid; - C_ReadCommit(object_t o, loff_t s, size_t *l, bufferlist *b, Cond *cond) : oid(o), start(s), length(l), bl(b), - pcond(cond) {} - void finish(int r) { - *length = r; - if (pcond) - pcond->Signal(); - } - }; - -public: - C3() : messenger(NULL), mc(NULL), lock("c3") {} - ~C3(); - bool init(); - - int write(object_t& oid, const char *buf, off_t off, size_t len); - int exec(object_t& oid, const char *code, off_t data_off, size_t data_len, char *buf, size_t out_len); - int read(object_t& oid, char *buf, off_t off, size_t len); -}; - -bool C3::init() -{ - mc = new MonClient(&monmap, NULL); - - // get monmap - if (!mc->get_monmap()) - return false; - - rank.bind(); - cout << "starting c3." << g_conf.id - << " at " << rank.get_rank_addr() - << " fsid " << monmap.get_fsid() - << std::endl; - - messenger = rank.register_entity(entity_name_t::CLIENT(-1)); - assert_warn(messenger); - if (!messenger) - return false; - - mc->set_messenger(messenger); - - rank.set_policy(entity_name_t::TYPE_MON, SimpleMessenger::Policy::lossy_fail_after(1.0)); - rank.set_policy(entity_name_t::TYPE_MDS, SimpleMessenger::Policy::lossless()); - rank.set_policy(entity_name_t::TYPE_OSD, SimpleMessenger::Policy::lossless()); - rank.set_policy(entity_name_t::TYPE_CLIENT, SimpleMessenger::Policy::lossless()); // mds does its own timeout/markdown - - rank.start(1); - - mc->mount(g_conf.client_mount_timeout); - - objecter = new Objecter(messenger, &monmap, &osdmap, lock); - if (!objecter) - return false; - - lock.Lock(); - mc->link_dispatcher(this); - - objecter->set_client_incarnation(0); - objecter->init(); - - objecter->set_client_incarnation(0); - - lock.Unlock(); - - return true; -} - -C3::~C3() -{ - if (mc) - delete mc; - if (messenger) - messenger->shutdown(); -} - - -bool C3::dispatch_impl(Message *m) -{ - bool ret; - - // verify protocol version - if (m->get_orig_source().is_mds() && - m->get_header().mds_protocol != CEPH_MDS_PROTOCOL) { - dout(0) << "mds protocol v " << (int)m->get_header().mds_protocol << " != my " << CEPH_MDS_PROTOCOL - << " from " << m->get_orig_source_inst() << " " << *m << dendl; - delete m; - return true; - } - - if (m->get_header().mdsc_protocol != CEPH_MDSC_PROTOCOL) { - dout(0) << "mdsc protocol v " << (int)m->get_header().mdsc_protocol << " != my " << CEPH_MDSC_PROTOCOL - << " from " << m->get_orig_source_inst() << " " << *m << dendl; - delete m; - return true; - } - if (m->get_orig_source().is_mon() && - m->get_header().monc_protocol != CEPH_MONC_PROTOCOL) { - dout(0) << "monc protocol v " << (int)m->get_header().monc_protocol << " != my " << CEPH_MONC_PROTOCOL - << " from " << m->get_orig_source_inst() << " " << *m << dendl; - delete m; - return true; - } - if (m->get_orig_source().is_osd() && - m->get_header().osdc_protocol != CEPH_OSDC_PROTOCOL) { - dout(0) << "osdc protocol v " << (int)m->get_header().osdc_protocol << " != my " << CEPH_OSDC_PROTOCOL - << " from " << m->get_orig_source_inst() << " " << *m << dendl; - delete m; - return true; - } - - lock.Lock(); - ret = _dispatch(m); - lock.Unlock(); - - return ret; -} - - -bool C3::_dispatch(Message *m) -{ - switch (m->get_type()) { - // OSD - case CEPH_MSG_OSD_OPREPLY: - objecter->handle_osd_op_reply((class MOSDOpReply*)m); - break; - case CEPH_MSG_OSD_MAP: - objecter->handle_osd_map((MOSDMap*)m); - break; - case CEPH_MSG_MDS_MAP: - break; - - default: - return false; - } - - return true; -} - -int C3::write(object_t& oid, const char *buf, off_t off, size_t len) -{ - SnapContext snapc; - bufferlist bl; - utime_t ut = g_clock.now(); - - Mutex lock("C3::write"); - Cond write_wait; - bl.append(&buf[off], len); - - C_WriteAck *onack = new C_WriteAck(oid, off, &len, &write_wait); - C_WriteCommit *oncommit = new C_WriteCommit(oid, off, &len, NULL); - - ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); - - dout(0) << "going to write" << dendl; - - lock.Lock(); - - objecter->write(oid, layout, - off, len, snapc, bl, ut, 0, - onack, oncommit); - - dout(0) << "after write call" << dendl; - - write_wait.Wait(lock); - - lock.Unlock(); - - return len; -} - -int C3::exec(object_t& oid, const char *code, off_t data_off, size_t data_len, char *buf, size_t out_len) -{ - SnapContext snapc; - bufferlist bl, obl; - utime_t ut = g_clock.now(); - - Mutex lock("C3::exec"); - Cond exec_wait; - bl.append(code, strlen(code) + 1); - - C_ExecCommit *oncommit = new C_ExecCommit(oid, data_off, &out_len, &exec_wait); - - ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); - - dout(0) << "going to exec" << dendl; - - lock.Lock(); - - objecter->exec(oid, layout, - data_off, data_len, CEPH_NOSNAP, bl, 0, - &obl, out_len, - oncommit); - - dout(0) << "after write call" << dendl; - - exec_wait.Wait(lock); - - lock.Unlock(); - - if (out_len) - memcpy(buf, obl.c_str(), out_len); - - return out_len; -} - -int C3::read(object_t& oid, char *buf, off_t off, size_t len) -{ - SnapContext snapc; - bufferlist *bl = new bufferlist; - Mutex lock("C3::read"); - Cond read_wait; - - C_ReadCommit *oncommit = new C_ReadCommit(oid, off, &len, bl, &read_wait); - - ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, 0); - - dout(0) << "going to read" << dendl; - - lock.Lock(); - - objecter->read(oid, layout, - off, len, CEPH_NOSNAP, bl, 0, - oncommit); - - dout(0) << "after read call" << dendl; - read_wait.Wait(lock); - - lock.Unlock(); - - if (len) - memcpy(buf, bl->c_str(), len); - - delete bl; - - return len; -} - -static void __c3_init(int argc, const char *argv[]) -{ - vector args; - - if (argc && argv) { - argv_to_vec(argc, argv, args); - env_to_vec(args); - } - common_init(args, "ccc", true); - - if (g_conf.clock_tare) g_clock.tare(); -} - -static Mutex c3_init_mutex("c3_init"); -static int c3_initialized = 0; - -static C3 *c3p; - #include "librados.h" -extern "C" int c3_initialize(int argc, const char **argv) -{ - int ret = 0; - c3_init_mutex.Lock(); - - if (!c3_initialized) { - __c3_init(argc, argv); - c3p = new C3(); - - if (!c3p) { - ret = ENOMEM; - goto out; - } - c3p->init(); - } - ++c3_initialized; - -out: - c3_init_mutex.Unlock(); - return ret; -} - -extern "C" void c3_deinitialize() -{ - c3_init_mutex.Lock(); - --c3_initialized; - - if (!c3_initialized) - delete c3p; - - c3p = NULL; - - c3_init_mutex.Unlock(); -} - -extern "C" int c3_write(object_t *oid, const char *buf, off_t off, size_t len) -{ - return c3p->write(*oid, buf, off, len); -} - -extern "C" int c3_read(object_t *oid, char *buf, off_t off, size_t len) -{ - return c3p->read(*oid, buf, off, len); -} - -extern "C" int c3_exec(object_t *oid, const char *code, off_t off, size_t len, char *buf, size_t out_len) -{ - return c3p->exec(*oid, code, off, len, buf, out_len); -} - - int main(int argc, const char **argv) { - if (c3_initialize(argc, argv)) { + if (rados_initialize(argc, argv)) { cerr << "error initializing" << std::endl; exit(1); } @@ -438,18 +27,20 @@ int main(int argc, const char **argv) time(&tm); snprintf(buf, 128, "%s", ctime(&tm)); - object_t oid(0x2010, 0); + ceph_object oid; + memset(&oid, 0, sizeof(oid)); + oid.ino = 0x2010; - c3_write(&oid, buf, 0, strlen(buf) + 1); - c3_exec(&oid, "code", 0, 128, buf, 128); + rados_write(&oid, buf, 0, strlen(buf) + 1); + //rados_exec(&oid, "code", 0, 128, buf, 128); cerr << "exec result=" << buf << std::endl; - size_t size = c3_read(&oid, buf2, 0, 128); + size_t size = rados_read(&oid, buf2, 0, 128); cerr << "read result=" << buf2 << "" << std::endl; cerr << "size=" << size << std::endl; - c3_deinitialize(); + rados_deinitialize(); return 0; } -- 2.39.5