This are tests and should be in the src/test subdir.
Signed-off-by: Roald J. van Loon <roaldvanloon@gmail.com>
ceph_test_rewrite_latency_LDADD = libcommon.la $(PTHREAD_LIBS) -lm $(CRYPTO_LIBS) $(EXTRALIBS)
bin_DEBUGPROGRAMS += ceph_test_rewrite_latency
-ceph_test_msgr_SOURCES = testmsgr.cc
+ceph_test_msgr_SOURCES = test/testmsgr.cc
ceph_test_msgr_LDADD = $(LIBGLOBAL_LDA)
bin_DEBUGPROGRAMS += ceph_test_msgr
ceph_dupstore_SOURCES = dupstore.cc
ceph_dupstore_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS}
ceph_dupstore_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA)
-ceph_streamtest_SOURCES = streamtest.cc
+ceph_streamtest_SOURCES = test/streamtest.cc
ceph_streamtest_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS}
ceph_streamtest_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA)
bin_DEBUGPROGRAMS += ceph_dupstore ceph_streamtest
-ceph_test_trans_SOURCES = test_trans.cc
+ceph_test_trans_SOURCES = test/test_trans.cc
ceph_test_trans_CXXFLAGS= ${CRYPTO_CXXFLAGS} ${AM_CXXFLAGS}
ceph_test_trans_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA)
bin_DEBUGPROGRAMS += ceph_test_trans
endif
-ceph_test_crypto_SOURCES = testcrypto.cc
+ceph_test_crypto_SOURCES = test/testcrypto.cc
ceph_test_crypto_LDADD = $(LIBGLOBAL_LDA)
ceph_test_crypto_CXXFLAGS = ${AM_CXXFLAGS}
bin_DEBUGPROGRAMS += ceph_test_crypto
-ceph_test_keys_SOURCES = testkeys.cc
+ceph_test_keys_SOURCES = test/testkeys.cc
ceph_test_keys_LDADD = libmon.a $(LIBGLOBAL_LDA)
ceph_test_keys_CXXFLAGS = ${AM_CXXFLAGS}
bin_DEBUGPROGRAMS += ceph_test_keys
+++ /dev/null
-
-
-
-#include <iostream>
-#include <string.h>
-#include <stdlib.h>
-
-#include "objclass/objclass.h"
-
-CLS_VER(1,0)
-CLS_NAME(bar)
-
-cls_handle_t h_class;
-
-cls_method_handle_t h_foo;
-
-int foo_method(cls_method_context_t ctx, char *indata, int datalen,
- char **outdata, int *outdatalen)
-{
- int i;
-
- cls_log("hello world, this is bar");
- cls_log("indata=%s", indata);
-
- *outdata = (char *)malloc(128);
- for (i=0; i<strlen(indata) + 1; i++) {
- if (indata[i] == '0') {
- (*outdata)[i] = '*';
- } else {
- (*outdata)[i] = indata[i];
- }
- }
- *outdatalen = strlen(*outdata) + 1;
- cls_log("outdata=%s", *outdata);
-
- return 0;
-}
-
-void class_init()
-{
- cls_log("Loaded bar class!");
-
- cls_register("bar", &h_class);
- cls_register_method(h_class, "bar", foo_method, &h_foo);
-
- return;
-}
-
+++ /dev/null
-
-
-
-#include <iostream>
-#include <string.h>
-#include <stdlib.h>
-
-#include "objclass/objclass.h"
-
-CLS_VER(1,0)
-CLS_NAME(foo)
-
-cls_handle_t h_class;
-
-cls_method_handle_t h_foo;
-
-int foo_method(cls_method_context_t ctx, char *indata, int datalen,
- char **outdata, int *outdatalen)
-{
- int i;
-
- cls_log("hello world, this is foo");
- cls_log("indata=%s", indata);
-
- *outdata = (char *)malloc(128);
- for (i=0; i<strlen(indata) + 1; i++) {
- if (indata[i] == '1') {
- (*outdata)[i] = 'I';
- } else {
- (*outdata)[i] = indata[i];
- }
- }
- *outdatalen = strlen(*outdata) + 1;
- cls_log("outdata=%s", *outdata);
-
- return 0;
-}
-
-void class_init()
-{
- cls_log("Loaded foo class!");
-
- cls_register("foo", &h_class);
- cls_register_method(h_class, "foo", foo_method, &h_foo);
-
- return;
-}
-
+++ /dev/null
-// -*- 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 <sage@newdream.net>
- *
- * 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 <iostream>
-#include "os/FileStore.h"
-#include "global/global_init.h"
-#include "common/ceph_argparse.h"
-#include "common/debug.h"
-
-#undef dout_prefix
-#define dout_prefix *_dout
-
-struct io {
- utime_t start, ack, commit;
- bool done() {
- return ack.sec() && commit.sec();
- }
-};
-map<off_t,io> writes;
-Cond cond;
-Mutex lock("streamtest.cc lock");
-
-unsigned concurrent = 1;
-void throttle()
-{
- Mutex::Locker l(lock);
- while (writes.size() >= concurrent) {
- //generic_dout(0) << "waiting" << dendl;
- cond.Wait(lock);
- }
-}
-
-double total_ack = 0;
-double total_commit = 0;
-int total_num = 0;
-
-void pr(off_t off)
-{
- io &i = writes[off];
- if (false) cout << off << "\t"
- << (i.ack - i.start) << "\t"
- << (i.commit - i.start) << std::endl;
- total_num++;
- total_ack += (i.ack - i.start);
- total_commit += (i.commit - i.start);
- writes.erase(off);
- cond.Signal();
-}
-
-void set_start(off_t off, utime_t t)
-{
- Mutex::Locker l(lock);
- writes[off].start = t;
-}
-
-void set_ack(off_t off, utime_t t)
-{
- Mutex::Locker l(lock);
- //generic_dout(0) << "ack " << off << dendl;
- writes[off].ack = t;
- if (writes[off].done())
- pr(off);
-}
-
-void set_commit(off_t off, utime_t t)
-{
- Mutex::Locker l(lock);
- //generic_dout(0) << "commit " << off << dendl;
- writes[off].commit = t;
- if (writes[off].done())
- pr(off);
-}
-
-
-struct C_Ack : public Context {
- off_t off;
- C_Ack(off_t o) : off(o) {}
- void finish(int r) {
- set_ack(off, ceph_clock_now(g_ceph_context));
- }
-};
-struct C_Commit : public Context {
- off_t off;
- C_Commit(off_t o) : off(o) {}
- void finish(int r) {
- set_commit(off, ceph_clock_now(g_ceph_context));
- }
-};
-
-
-int main(int argc, const char **argv)
-{
- vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
- common_init_finish(g_ceph_context);
-
- // args
- if (args.size() < 3) return -1;
- const char *filename = args[0];
- int seconds = atoi(args[1]);
- int bytes = atoi(args[2]);
- const char *journal = 0;
- if (args.size() >= 4)
- journal = args[3];
- if (args.size() >= 5)
- concurrent = atoi(args[4]);
-
- cout << "concurrent = " << concurrent << std::endl;
-
- buffer::ptr bp(bytes);
- bp.zero();
- bufferlist bl;
- bl.push_back(bp);
-
- //float interval = 1.0 / 1000;
-
- cout << "#dev " << filename
- << ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl;
-
- ObjectStore *fs = new FileStore(filename, journal);
-
- if (fs->mkfs() < 0) {
- cout << "mkfs failed" << std::endl;
- return -1;
- }
-
- if (fs->mount() < 0) {
- cout << "mount failed" << std::endl;
- return -1;
- }
-
- ObjectStore::Transaction ft;
- ft.create_collection(coll_t());
- fs->apply_transaction(ft);
-
- utime_t now = ceph_clock_now(g_ceph_context);
- utime_t start = now;
- utime_t end = now;
- end += seconds;
- off_t pos = 0;
- //cout << "stop at " << end << std::endl;
- cout << "# offset\tack\tcommit" << std::endl;
- while (now < end) {
- sobject_t poid(object_t("streamtest"), 0);
-
- set_start(pos, ceph_clock_now(g_ceph_context));
- ObjectStore::Transaction *t = new ObjectStore::Transaction;
- t->write(coll_t(), hobject_t(poid), pos, bytes, bl);
- fs->queue_transaction(NULL, t, new C_Ack(pos), new C_Commit(pos));
- pos += bytes;
-
- throttle();
-
- now = ceph_clock_now(g_ceph_context);
-
- // wait?
- /*
- utime_t next = start;
- next += interval;
- if (now < next) {
- float s = next - now;
- s *= 1000 * 1000; // s -> us
- //cout << "sleeping for " << s << " us" << std::endl;
- usleep((int)s);
- }
- */
- }
-
- cout << "total num " << total_num << std::endl;
- cout << "avg ack\t" << (total_ack / (double)total_num) << std::endl;
- cout << "avg commit\t" << (total_commit / (double)total_num) << std::endl;
- cout << "tput\t" << prettybyte_t((double)(total_num * bytes) / (double)(end-start)) << "/sec" << std::endl;
-
- fs->umount();
-
-}
-
--- /dev/null
+
+
+
+#include <iostream>
+#include <string.h>
+#include <stdlib.h>
+
+#include "objclass/objclass.h"
+
+CLS_VER(1,0)
+CLS_NAME(bar)
+
+cls_handle_t h_class;
+
+cls_method_handle_t h_foo;
+
+int foo_method(cls_method_context_t ctx, char *indata, int datalen,
+ char **outdata, int *outdatalen)
+{
+ int i;
+
+ cls_log("hello world, this is bar");
+ cls_log("indata=%s", indata);
+
+ *outdata = (char *)malloc(128);
+ for (i=0; i<strlen(indata) + 1; i++) {
+ if (indata[i] == '0') {
+ (*outdata)[i] = '*';
+ } else {
+ (*outdata)[i] = indata[i];
+ }
+ }
+ *outdatalen = strlen(*outdata) + 1;
+ cls_log("outdata=%s", *outdata);
+
+ return 0;
+}
+
+void class_init()
+{
+ cls_log("Loaded bar class!");
+
+ cls_register("bar", &h_class);
+ cls_register_method(h_class, "bar", foo_method, &h_foo);
+
+ return;
+}
+
--- /dev/null
+
+
+
+#include <iostream>
+#include <string.h>
+#include <stdlib.h>
+
+#include "objclass/objclass.h"
+
+CLS_VER(1,0)
+CLS_NAME(foo)
+
+cls_handle_t h_class;
+
+cls_method_handle_t h_foo;
+
+int foo_method(cls_method_context_t ctx, char *indata, int datalen,
+ char **outdata, int *outdatalen)
+{
+ int i;
+
+ cls_log("hello world, this is foo");
+ cls_log("indata=%s", indata);
+
+ *outdata = (char *)malloc(128);
+ for (i=0; i<strlen(indata) + 1; i++) {
+ if (indata[i] == '1') {
+ (*outdata)[i] = 'I';
+ } else {
+ (*outdata)[i] = indata[i];
+ }
+ }
+ *outdatalen = strlen(*outdata) + 1;
+ cls_log("outdata=%s", *outdata);
+
+ return 0;
+}
+
+void class_init()
+{
+ cls_log("Loaded foo class!");
+
+ cls_register("foo", &h_class);
+ cls_register_method(h_class, "foo", foo_method, &h_foo);
+
+ return;
+}
+
--- /dev/null
+// -*- 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 <sage@newdream.net>
+ *
+ * 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 <iostream>
+#include "os/FileStore.h"
+#include "global/global_init.h"
+#include "common/ceph_argparse.h"
+#include "common/debug.h"
+
+#undef dout_prefix
+#define dout_prefix *_dout
+
+struct io {
+ utime_t start, ack, commit;
+ bool done() {
+ return ack.sec() && commit.sec();
+ }
+};
+map<off_t,io> writes;
+Cond cond;
+Mutex lock("streamtest.cc lock");
+
+unsigned concurrent = 1;
+void throttle()
+{
+ Mutex::Locker l(lock);
+ while (writes.size() >= concurrent) {
+ //generic_dout(0) << "waiting" << dendl;
+ cond.Wait(lock);
+ }
+}
+
+double total_ack = 0;
+double total_commit = 0;
+int total_num = 0;
+
+void pr(off_t off)
+{
+ io &i = writes[off];
+ if (false) cout << off << "\t"
+ << (i.ack - i.start) << "\t"
+ << (i.commit - i.start) << std::endl;
+ total_num++;
+ total_ack += (i.ack - i.start);
+ total_commit += (i.commit - i.start);
+ writes.erase(off);
+ cond.Signal();
+}
+
+void set_start(off_t off, utime_t t)
+{
+ Mutex::Locker l(lock);
+ writes[off].start = t;
+}
+
+void set_ack(off_t off, utime_t t)
+{
+ Mutex::Locker l(lock);
+ //generic_dout(0) << "ack " << off << dendl;
+ writes[off].ack = t;
+ if (writes[off].done())
+ pr(off);
+}
+
+void set_commit(off_t off, utime_t t)
+{
+ Mutex::Locker l(lock);
+ //generic_dout(0) << "commit " << off << dendl;
+ writes[off].commit = t;
+ if (writes[off].done())
+ pr(off);
+}
+
+
+struct C_Ack : public Context {
+ off_t off;
+ C_Ack(off_t o) : off(o) {}
+ void finish(int r) {
+ set_ack(off, ceph_clock_now(g_ceph_context));
+ }
+};
+struct C_Commit : public Context {
+ off_t off;
+ C_Commit(off_t o) : off(o) {}
+ void finish(int r) {
+ set_commit(off, ceph_clock_now(g_ceph_context));
+ }
+};
+
+
+int main(int argc, const char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ env_to_vec(args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ // args
+ if (args.size() < 3) return -1;
+ const char *filename = args[0];
+ int seconds = atoi(args[1]);
+ int bytes = atoi(args[2]);
+ const char *journal = 0;
+ if (args.size() >= 4)
+ journal = args[3];
+ if (args.size() >= 5)
+ concurrent = atoi(args[4]);
+
+ cout << "concurrent = " << concurrent << std::endl;
+
+ buffer::ptr bp(bytes);
+ bp.zero();
+ bufferlist bl;
+ bl.push_back(bp);
+
+ //float interval = 1.0 / 1000;
+
+ cout << "#dev " << filename
+ << ", " << seconds << " seconds, " << bytes << " bytes per write" << std::endl;
+
+ ObjectStore *fs = new FileStore(filename, journal);
+
+ if (fs->mkfs() < 0) {
+ cout << "mkfs failed" << std::endl;
+ return -1;
+ }
+
+ if (fs->mount() < 0) {
+ cout << "mount failed" << std::endl;
+ return -1;
+ }
+
+ ObjectStore::Transaction ft;
+ ft.create_collection(coll_t());
+ fs->apply_transaction(ft);
+
+ utime_t now = ceph_clock_now(g_ceph_context);
+ utime_t start = now;
+ utime_t end = now;
+ end += seconds;
+ off_t pos = 0;
+ //cout << "stop at " << end << std::endl;
+ cout << "# offset\tack\tcommit" << std::endl;
+ while (now < end) {
+ sobject_t poid(object_t("streamtest"), 0);
+
+ set_start(pos, ceph_clock_now(g_ceph_context));
+ ObjectStore::Transaction *t = new ObjectStore::Transaction;
+ t->write(coll_t(), hobject_t(poid), pos, bytes, bl);
+ fs->queue_transaction(NULL, t, new C_Ack(pos), new C_Commit(pos));
+ pos += bytes;
+
+ throttle();
+
+ now = ceph_clock_now(g_ceph_context);
+
+ // wait?
+ /*
+ utime_t next = start;
+ next += interval;
+ if (now < next) {
+ float s = next - now;
+ s *= 1000 * 1000; // s -> us
+ //cout << "sleeping for " << s << " us" << std::endl;
+ usleep((int)s);
+ }
+ */
+ }
+
+ cout << "total num " << total_num << std::endl;
+ cout << "avg ack\t" << (total_ack / (double)total_num) << std::endl;
+ cout << "avg commit\t" << (total_commit / (double)total_num) << std::endl;
+ cout << "tput\t" << prettybyte_t((double)(total_num * bytes) / (double)(end-start)) << "/sec" << std::endl;
+
+ fs->umount();
+
+}
+
--- /dev/null
+// -*- 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 <sage@newdream.net>
+ *
+ * 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 <iostream>
+#include "common/ceph_argparse.h"
+#include "common/debug.h"
+#include "os/FileStore.h"
+#include "global/global_init.h"
+#include "include/assert.h"
+
+#define dout_subsys ceph_subsys_filestore
+#undef dout_prefix
+#define dout_prefix *_dout
+
+struct Foo : public Thread {
+ void *entry() {
+ dout(0) << "foo started" << dendl;
+ sleep(1);
+ dout(0) << "foo asserting 0" << dendl;
+ assert(0);
+ }
+} foo;
+
+int main(int argc, const char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ env_to_vec(args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ // args
+ if (args.size() < 2) return -1;
+ const char *filename = args[0];
+ int mb = atoi(args[1]);
+
+ cout << "#dev " << filename << std::endl;
+ cout << "#mb " << mb << std::endl;
+
+ ObjectStore *fs = new FileStore(filename, NULL);
+ if (fs->mount() < 0) {
+ cout << "mount failed" << std::endl;
+ return -1;
+ }
+
+ ObjectStore::Transaction t;
+ char buf[1 << 20];
+ bufferlist bl;
+ bl.append(buf, sizeof(buf));
+ t.create_collection(coll_t());
+
+ for (int i=0; i<mb; i++) {
+ char f[30];
+ snprintf(f, sizeof(f), "foo%d\n", i);
+ sobject_t soid(f, CEPH_NOSNAP);
+ t.write(coll_t(), hobject_t(soid), 0, bl.length(), bl);
+ }
+
+ dout(0) << "starting thread" << dendl;
+ foo.create();
+ dout(0) << "starting op" << dendl;
+ fs->apply_transaction(t);
+
+}
+
--- /dev/null
+
+
+
+#include <iostream>
+#include <string.h>
+#include <stdlib.h>
+
+#include "objclass/objclass.h"
+
+CLS_VER(1,0)
+CLS_NAME(test)
+
+cls_handle_t h_class;
+
+cls_method_handle_t h_foo;
+
+int foo_method(cls_method_context_t ctx, char *indata, int datalen,
+ char **outdata, int *outdatalen)
+{
+ int i, r;
+
+ cls_log("hello world");
+ cls_log("indata=%s", indata);
+
+ *outdata = (char *)cls_alloc(128);
+ for (i=0; i<strlen(indata) + 1; i++) {
+ if (indata[i] == '0') {
+ (*outdata)[i] = '*';
+ } else {
+ (*outdata)[i] = indata[i];
+ }
+ }
+ *outdatalen = strlen(*outdata) + 1;
+ cls_log("outdata=%s", *outdata);
+
+ r = cls_call(ctx, "foo", "foo", *outdata, *outdatalen, outdata, outdatalen);
+
+ return r;
+}
+
+static cls_deps_t depend[] = {{"foo", "1.0"}, {"bar", "1.0"}, {NULL, NULL}};
+
+extern "C" cls_deps_t *class_deps()
+{
+ return depend;
+};
+
+void class_init()
+{
+ cls_log("Loaded class test!");
+
+ cls_register("test", &h_class);
+ cls_register_method(h_class, "foo", foo_method, &h_foo);
+
+ return;
+}
+
--- /dev/null
+#include "auth/Crypto.h"
+#include "common/Clock.h"
+
+#include "common/config.h"
+#include "common/debug.h"
+
+#define dout_subsys ceph_subsys_auth
+
+#define AES_KEY_LEN 16
+
+int main(int argc, char *argv[])
+{
+ char aes_key[AES_KEY_LEN];
+ memset(aes_key, 0x77, sizeof(aes_key));
+ bufferptr keybuf(aes_key, sizeof(aes_key));
+ CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf);
+
+ const char *msg="hello! this is a message\n";
+ char pad[16];
+ memset(pad, 0, 16);
+ bufferptr ptr(msg, strlen(msg));
+ bufferlist enc_in;
+ enc_in.append(ptr);
+ enc_in.append(msg, strlen(msg));
+
+ bufferlist enc_out;
+ std::string error;
+ key.encrypt(g_ceph_context, enc_in, enc_out, error);
+ if (!error.empty()) {
+ dout(0) << "couldn't encode! error " << error << dendl;
+ exit(1);
+ }
+
+ const char *enc_buf = enc_out.c_str();
+ for (unsigned i=0; i<enc_out.length(); i++) {
+ std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " ";
+ if (i && !(i%16))
+ std::cout << std::endl;
+ }
+
+ bufferlist dec_in, dec_out;
+
+ dec_in = enc_out;
+
+ key.decrypt(g_ceph_context, dec_in, dec_out, error);
+ if (!error.empty()) {
+ dout(0) << "couldn't decode! error " << error << dendl;
+ exit(1);
+ }
+
+ dout(0) << "decoded len: " << dec_out.length() << dendl;
+ dout(0) << "decoded msg: " << dec_out.c_str() << dendl;
+
+ return 0;
+}
+
--- /dev/null
+#include "auth/cephx/CephxKeyServer.h"
+#include "common/ceph_argparse.h"
+#include "global/global_init.h"
+#include "common/config.h"
+
+#define AES_KEY_LEN 16
+
+int main(int argc, const char **argv)
+{
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ env_to_vec(args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+ KeyRing extra;
+ KeyServer server(g_ceph_context, &extra);
+
+ generic_dout(0) << "server created" << dendl;
+
+ getchar();
+
+#if 0
+ char aes_key[AES_KEY_LEN];
+ memset(aes_key, 0x77, sizeof(aes_key));
+ bufferptr keybuf(aes_key, sizeof(aes_key));
+ CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf);
+
+ const char *msg="hello! this is a message\n";
+ char pad[16];
+ memset(pad, 0, 16);
+ bufferptr ptr(msg, strlen(msg));
+ bufferlist enc_in;
+ enc_in.append(ptr);
+ enc_in.append(msg, strlen(msg));
+
+ bufferlist enc_out;
+ if (key.encrypt(enc_in, enc_out) < 0) {
+ derr(0) << "couldn't encode!" << dendl;
+ exit(1);
+ }
+
+ const char *enc_buf = enc_out.c_str();
+ for (unsigned i=0; i<enc_out.length(); i++) {
+ std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " ";
+ if (i && !(i%16))
+ std::cout << std::endl;
+ }
+
+ bufferlist dec_in, dec_out;
+
+ dec_in = enc_out;
+
+ if (key.decrypt(dec_in, dec_out) < 0) {
+ derr(0) << "couldn't decode!" << dendl;
+ }
+
+ dout(0) << "decoded len: " << dec_out.length() << dendl;
+ dout(0) << "decoded msg: " << dec_out.c_str() << dendl;
+
+ return 0;
+#endif
+}
+
--- /dev/null
+// -*- 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 <sage@newdream.net>
+ *
+ * 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 <sys/stat.h>
+#include <iostream>
+#include <string>
+using namespace std;
+
+#include "common/config.h"
+
+#include "mon/MonMap.h"
+#include "mon/MonClient.h"
+#include "msg/Messenger.h"
+#include "messages/MPing.h"
+
+#include "common/Timer.h"
+#include "global/global_init.h"
+#include "common/ceph_argparse.h"
+
+#ifndef DARWIN
+#include <envz.h>
+#endif // DARWIN
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#define dout_subsys ceph_subsys_ms
+
+Messenger *messenger = 0;
+
+Mutex lock("mylock");
+Cond cond;
+
+uint64_t received = 0;
+
+class Admin : public Dispatcher {
+public:
+ Admin()
+ : Dispatcher(g_ceph_context)
+ {
+ }
+private:
+ bool ms_dispatch(Message *m) {
+
+ //cerr << "got ping from " << m->get_source() << std::endl;
+ dout(0) << "got ping from " << m->get_source() << dendl;
+ lock.Lock();
+ ++received;
+ cond.Signal();
+ lock.Unlock();
+
+ m->put();
+ return true;
+ }
+
+ bool ms_handle_reset(Connection *con) { return false; }
+ void ms_handle_remote_reset(Connection *con) {}
+
+} dispatcher;
+
+
+int main(int argc, const char **argv, const char *envp[]) {
+
+ vector<const char*> args;
+ argv_to_vec(argc, argv, args);
+ env_to_vec(args);
+
+ global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+
+ dout(0) << "i am mon " << args[0] << dendl;
+
+ // get monmap
+ MonClient mc(g_ceph_context);
+ if (mc.build_initial_monmap() < 0)
+ return -1;
+
+ // start up network
+ int whoami = mc.monmap.get_rank(args[0]);
+ assert(whoami >= 0);
+ ostringstream ss;
+ ss << mc.monmap.get_addr(whoami);
+ std::string sss(ss.str());
+ g_ceph_context->_conf->set_val("public_addr", sss.c_str());
+ g_ceph_context->_conf->apply_changes(NULL);
+ Messenger *rank = Messenger::create(g_ceph_context,
+ entity_name_t::MON(whoami), "tester",
+ getpid());
+ int err = rank->bind(g_ceph_context->_conf->public_addr);
+ if (err < 0)
+ return 1;
+
+ // start monitor
+ messenger = rank;
+ messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
+ messenger->add_dispatcher_head(&dispatcher);
+
+ rank->start();
+
+ int isend = 0;
+ if (whoami == 0)
+ isend = 100;
+
+ lock.Lock();
+ uint64_t sent = 0;
+ while (1) {
+ while (received + isend <= sent) {
+ //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl;
+ dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl;
+ cond.Wait(lock);
+ }
+
+ int t = rand() % mc.get_num_mon();
+ if (t == whoami)
+ continue;
+
+ if (rand() % 10 == 0) {
+ //cerr << "mark_down " << t << std::endl;
+ dout(0) << "mark_down " << t << dendl;
+ messenger->mark_down(mc.get_mon_addr(t));
+ }
+ //cerr << "pinging " << t << std::endl;
+ dout(0) << "pinging " << t << dendl;
+ messenger->send_message(new MPing, mc.get_mon_inst(t));
+ cerr << isend << "\t" << ++sent << "\t" << received << "\r";
+ }
+ lock.Unlock();
+
+ // wait for messenger to finish
+ rank->wait();
+
+ return 0;
+}
+
+++ /dev/null
-// -*- 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 <sage@newdream.net>
- *
- * 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 <iostream>
-#include "common/ceph_argparse.h"
-#include "common/debug.h"
-#include "os/FileStore.h"
-#include "global/global_init.h"
-#include "include/assert.h"
-
-#define dout_subsys ceph_subsys_filestore
-#undef dout_prefix
-#define dout_prefix *_dout
-
-struct Foo : public Thread {
- void *entry() {
- dout(0) << "foo started" << dendl;
- sleep(1);
- dout(0) << "foo asserting 0" << dendl;
- assert(0);
- }
-} foo;
-
-int main(int argc, const char **argv)
-{
- vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
- common_init_finish(g_ceph_context);
-
- // args
- if (args.size() < 2) return -1;
- const char *filename = args[0];
- int mb = atoi(args[1]);
-
- cout << "#dev " << filename << std::endl;
- cout << "#mb " << mb << std::endl;
-
- ObjectStore *fs = new FileStore(filename, NULL);
- if (fs->mount() < 0) {
- cout << "mount failed" << std::endl;
- return -1;
- }
-
- ObjectStore::Transaction t;
- char buf[1 << 20];
- bufferlist bl;
- bl.append(buf, sizeof(buf));
- t.create_collection(coll_t());
-
- for (int i=0; i<mb; i++) {
- char f[30];
- snprintf(f, sizeof(f), "foo%d\n", i);
- sobject_t soid(f, CEPH_NOSNAP);
- t.write(coll_t(), hobject_t(soid), 0, bl.length(), bl);
- }
-
- dout(0) << "starting thread" << dendl;
- foo.create();
- dout(0) << "starting op" << dendl;
- fs->apply_transaction(t);
-
-}
-
+++ /dev/null
-
-
-
-#include <iostream>
-#include <string.h>
-#include <stdlib.h>
-
-#include "objclass/objclass.h"
-
-CLS_VER(1,0)
-CLS_NAME(test)
-
-cls_handle_t h_class;
-
-cls_method_handle_t h_foo;
-
-int foo_method(cls_method_context_t ctx, char *indata, int datalen,
- char **outdata, int *outdatalen)
-{
- int i, r;
-
- cls_log("hello world");
- cls_log("indata=%s", indata);
-
- *outdata = (char *)cls_alloc(128);
- for (i=0; i<strlen(indata) + 1; i++) {
- if (indata[i] == '0') {
- (*outdata)[i] = '*';
- } else {
- (*outdata)[i] = indata[i];
- }
- }
- *outdatalen = strlen(*outdata) + 1;
- cls_log("outdata=%s", *outdata);
-
- r = cls_call(ctx, "foo", "foo", *outdata, *outdatalen, outdata, outdatalen);
-
- return r;
-}
-
-static cls_deps_t depend[] = {{"foo", "1.0"}, {"bar", "1.0"}, {NULL, NULL}};
-
-extern "C" cls_deps_t *class_deps()
-{
- return depend;
-};
-
-void class_init()
-{
- cls_log("Loaded class test!");
-
- cls_register("test", &h_class);
- cls_register_method(h_class, "foo", foo_method, &h_foo);
-
- return;
-}
-
+++ /dev/null
-#include "auth/Crypto.h"
-#include "common/Clock.h"
-
-#include "common/config.h"
-#include "common/debug.h"
-
-#define dout_subsys ceph_subsys_auth
-
-#define AES_KEY_LEN 16
-
-int main(int argc, char *argv[])
-{
- char aes_key[AES_KEY_LEN];
- memset(aes_key, 0x77, sizeof(aes_key));
- bufferptr keybuf(aes_key, sizeof(aes_key));
- CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf);
-
- const char *msg="hello! this is a message\n";
- char pad[16];
- memset(pad, 0, 16);
- bufferptr ptr(msg, strlen(msg));
- bufferlist enc_in;
- enc_in.append(ptr);
- enc_in.append(msg, strlen(msg));
-
- bufferlist enc_out;
- std::string error;
- key.encrypt(g_ceph_context, enc_in, enc_out, error);
- if (!error.empty()) {
- dout(0) << "couldn't encode! error " << error << dendl;
- exit(1);
- }
-
- const char *enc_buf = enc_out.c_str();
- for (unsigned i=0; i<enc_out.length(); i++) {
- std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " ";
- if (i && !(i%16))
- std::cout << std::endl;
- }
-
- bufferlist dec_in, dec_out;
-
- dec_in = enc_out;
-
- key.decrypt(g_ceph_context, dec_in, dec_out, error);
- if (!error.empty()) {
- dout(0) << "couldn't decode! error " << error << dendl;
- exit(1);
- }
-
- dout(0) << "decoded len: " << dec_out.length() << dendl;
- dout(0) << "decoded msg: " << dec_out.c_str() << dendl;
-
- return 0;
-}
-
+++ /dev/null
-#include "auth/cephx/CephxKeyServer.h"
-#include "common/ceph_argparse.h"
-#include "global/global_init.h"
-#include "common/config.h"
-
-#define AES_KEY_LEN 16
-
-int main(int argc, const char **argv)
-{
- vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
- common_init_finish(g_ceph_context);
- KeyRing extra;
- KeyServer server(g_ceph_context, &extra);
-
- generic_dout(0) << "server created" << dendl;
-
- getchar();
-
-#if 0
- char aes_key[AES_KEY_LEN];
- memset(aes_key, 0x77, sizeof(aes_key));
- bufferptr keybuf(aes_key, sizeof(aes_key));
- CryptoKey key(CEPH_CRYPTO_AES, ceph_clock_now(g_ceph_context), keybuf);
-
- const char *msg="hello! this is a message\n";
- char pad[16];
- memset(pad, 0, 16);
- bufferptr ptr(msg, strlen(msg));
- bufferlist enc_in;
- enc_in.append(ptr);
- enc_in.append(msg, strlen(msg));
-
- bufferlist enc_out;
- if (key.encrypt(enc_in, enc_out) < 0) {
- derr(0) << "couldn't encode!" << dendl;
- exit(1);
- }
-
- const char *enc_buf = enc_out.c_str();
- for (unsigned i=0; i<enc_out.length(); i++) {
- std::cout << hex << (int)(unsigned char)enc_buf[i] << dec << " ";
- if (i && !(i%16))
- std::cout << std::endl;
- }
-
- bufferlist dec_in, dec_out;
-
- dec_in = enc_out;
-
- if (key.decrypt(dec_in, dec_out) < 0) {
- derr(0) << "couldn't decode!" << dendl;
- }
-
- dout(0) << "decoded len: " << dec_out.length() << dendl;
- dout(0) << "decoded msg: " << dec_out.c_str() << dendl;
-
- return 0;
-#endif
-}
-
+++ /dev/null
-// -*- 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 <sage@newdream.net>
- *
- * 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 <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "common/config.h"
-
-#include "mon/MonMap.h"
-#include "mon/MonClient.h"
-#include "msg/Messenger.h"
-#include "messages/MPing.h"
-
-#include "common/Timer.h"
-#include "global/global_init.h"
-#include "common/ceph_argparse.h"
-
-#ifndef DARWIN
-#include <envz.h>
-#endif // DARWIN
-
-#include <sys/types.h>
-#include <fcntl.h>
-
-#define dout_subsys ceph_subsys_ms
-
-Messenger *messenger = 0;
-
-Mutex lock("mylock");
-Cond cond;
-
-uint64_t received = 0;
-
-class Admin : public Dispatcher {
-public:
- Admin()
- : Dispatcher(g_ceph_context)
- {
- }
-private:
- bool ms_dispatch(Message *m) {
-
- //cerr << "got ping from " << m->get_source() << std::endl;
- dout(0) << "got ping from " << m->get_source() << dendl;
- lock.Lock();
- ++received;
- cond.Signal();
- lock.Unlock();
-
- m->put();
- return true;
- }
-
- bool ms_handle_reset(Connection *con) { return false; }
- void ms_handle_remote_reset(Connection *con) {}
-
-} dispatcher;
-
-
-int main(int argc, const char **argv, const char *envp[]) {
-
- vector<const char*> args;
- argv_to_vec(argc, argv, args);
- env_to_vec(args);
-
- global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT, CODE_ENVIRONMENT_UTILITY, 0);
- common_init_finish(g_ceph_context);
-
- dout(0) << "i am mon " << args[0] << dendl;
-
- // get monmap
- MonClient mc(g_ceph_context);
- if (mc.build_initial_monmap() < 0)
- return -1;
-
- // start up network
- int whoami = mc.monmap.get_rank(args[0]);
- assert(whoami >= 0);
- ostringstream ss;
- ss << mc.monmap.get_addr(whoami);
- std::string sss(ss.str());
- g_ceph_context->_conf->set_val("public_addr", sss.c_str());
- g_ceph_context->_conf->apply_changes(NULL);
- Messenger *rank = Messenger::create(g_ceph_context,
- entity_name_t::MON(whoami), "tester",
- getpid());
- int err = rank->bind(g_ceph_context->_conf->public_addr);
- if (err < 0)
- return 1;
-
- // start monitor
- messenger = rank;
- messenger->set_default_send_priority(CEPH_MSG_PRIO_HIGH);
- messenger->add_dispatcher_head(&dispatcher);
-
- rank->start();
-
- int isend = 0;
- if (whoami == 0)
- isend = 100;
-
- lock.Lock();
- uint64_t sent = 0;
- while (1) {
- while (received + isend <= sent) {
- //cerr << "wait r " << received << " s " << sent << " is " << isend << std::endl;
- dout(0) << "wait r " << received << " s " << sent << " is " << isend << dendl;
- cond.Wait(lock);
- }
-
- int t = rand() % mc.get_num_mon();
- if (t == whoami)
- continue;
-
- if (rand() % 10 == 0) {
- //cerr << "mark_down " << t << std::endl;
- dout(0) << "mark_down " << t << dendl;
- messenger->mark_down(mc.get_mon_addr(t));
- }
- //cerr << "pinging " << t << std::endl;
- dout(0) << "pinging " << t << dendl;
- messenger->send_message(new MPing, mc.get_mon_inst(t));
- cerr << isend << "\t" << ++sent << "\t" << received << "\r";
- }
- lock.Unlock();
-
- // wait for messenger to finish
- rank->wait();
-
- return 0;
-}
-