+++ /dev/null
-#!/bin/bash
-
-set -e
-name=`echo $0 | sed 's/\//_/g'`
-mkdir $name
-cd $name
-
-iozone -c -e -s 1024M -r 16K -t 1 -F f1 -i 0 -i 1
-iozone -c -e -s 1024M -r 1M -t 1 -F f2 -i 0 -i 1
-iozone -c -e -s 10240M -r 1M -t 1 -F f3 -i 0 -i 1
-
-cd ..
\ No newline at end of file
+++ /dev/null
-#!/bin/bash
-
-set -e
-name=`echo $0 | sed 's/\//_/g'`
-mkdir $name
-cd $name
-
-tar jxvf /root/linux*
-cd linux*
-make defconfig
-make
-cd ..
-rm -r linux*
--- /dev/null
+#!/bin/bash
+
+set -e
+name=`echo $0 | sed 's/\//_/g'`
+mkdir $name
+cd $name
+
+iozone -c -e -s 1024M -r 16K -t 1 -F f1 -i 0 -i 1
+iozone -c -e -s 1024M -r 1M -t 1 -F f2 -i 0 -i 1
+iozone -c -e -s 10240M -r 1M -t 1 -F f3 -i 0 -i 1
+
+cd ..
\ No newline at end of file
--- /dev/null
+#!/bin/bash
+
+set -e
+name=`echo $0 | sed 's/\//_/g'`
+mkdir $name
+cd $name
+
+tar jxvf /root/linux*
+cd linux*
+make defconfig
+make
+cd ..
+rm -r linux*
+++ /dev/null
-
-
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-
-#include "mds/MDS.h"
-#include "osd/OSD.h"
-#include "fakeclient/FakeClient.h"
-
-#include "mds/MDCluster.h"
-#include "mds/MDCache.h"
-#include "mds/MDStore.h"
-
-#include "msg/FakeMessenger.h"
-
-#include "messages/MPing.h"
-
-using namespace std;
-
-__uint64_t ino = 1;
-
-
-
-#include "config.h"
-#define NUMMDS g_conf.num_mds
-#define NUMOSD g_conf.num_osd
-#define NUMCLIENT g_conf.num_fakeclient
-
-// this parses find output
-int play();
-
-int main(int oargc, char **oargv) {
- cerr << "hi there" << endl;
-
- int argc;
- char **argv;
- parse_config_options(oargc, oargv,
- argc, argv);
-
- MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD);
-
- // local config settings
- g_conf.num_client = g_conf.num_fakeclient; // to fool mds, hack gross
-
- // create osds
- OSD *osd[NUMOSD];
- for (int i=0; i<NUMOSD; i++) {
- osd[i] = new OSD(i, new FakeMessenger(MSG_ADDR_OSD(i)));
- osd[i]->init();
- }
-
- // create mds
- MDS *mds[NUMMDS];
- for (int i=0; i<NUMMDS; i++) {
- mds[i] = new MDS(mdc, i, new FakeMessenger(MSG_ADDR_MDS(i)));
- mds[i]->init();
- }
-
-
- // create clients
- FakeClient *client[NUMCLIENT];
- for (int i=0; i<NUMCLIENT; i++) {
- client[i] = new FakeClient(mdc, i, new FakeMessenger(MSG_ADDR_CLIENT(i)), g_conf.fakeclient_requests);
- client[i]->init();
- }
-
- // mount clients
- for (int i=0; i<NUMCLIENT; i++)
- //for (int i=0; i<1; i++)
- client[i]->mount();
-
- // loop
- fakemessenger_do_loop();
-
- //mds[0]->shutdown_start();
- //fakemessenger_do_loop();
-
- //
- if (argc > 1 &&
- strcmp(argv[1], "nocheck") == 0) {
- cerr << "---- nocheck" << endl;
- } else {
- cout << "---- check ----" << endl;
- for (int i=0; i<NUMMDS; i++)
- mds[i]->mdcache->shutdown_pass();
- }
-
- // cleanup
- cout << "cleanup" << endl;
- for (int i=0; i<NUMMDS; i++) {
- delete mds[i];
- }
- for (int i=0; i<NUMOSD; i++) {
- delete osd[i];
- }
- for (int i=0; i<NUMCLIENT; i++) {
- delete client[i];
- }
- delete mdc;
- cout << "done." << endl;
- return 0;
-}
-
+++ /dev/null
-
-#include "include/types.h"
-#include "include/frag.h"
-
-int main(int argc, char **argv)
-{
- fragtree_t tree;
- tree.split(frag_t(),2);
- tree.split(frag_t(0,2),1);
- tree.split(frag_t(1,2),1);
- tree.split(frag_t(2,2),1);
- tree.split(frag_t(1,3),1);
-
- cout << "tree is " << tree << endl;
- frag_t fg(2,4);
- cout << "fg is " << fg << endl;
- tree.force_to_leaf(fg);
-
-}
+++ /dev/null
-#include <iostream>
-#include <string>
-using namespace std;
-
-int make_dirs(const char *basedir, int dirs, int files, int depth)
-{
- //if (time_to_stop()) return 0;
-
- // make sure base dir exists
- int r = mkdir(basedir, 0755);
- if (r != 0) {
- cout << "can't make base dir? " << basedir << endl;
- return -1;
- }
-
- // children
- char d[500];
- cout << "make_dirs " << basedir << " dirs " << dirs << " files " << files << " depth " << depth << endl;
- for (int i=0; i<files; i++) {
- sprintf(d,"%s/file.%d", basedir, i);
- mknod(d, 0644);
- }
-
- if (depth == 0) return 0;
-
- for (int i=0; i<dirs; i++) {
- sprintf(d, "%s/dir.%d", basedir, i);
- make_dirs(d, dirs, files, depth-1);
- }
-
- return 0;
-}
-
-int main()
-{
- make_dirs("blah", 10, 10, 4);
-
-}
+++ /dev/null
-
-
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "mds/MDCluster.h"
-#include "mds/MDS.h"
-#include "osd/OSD.h"
-#include "fakeclient/FakeClient.h"
-
-#include "mds/MDCache.h"
-#include "mds/MDStore.h"
-
-#include "msg/MPIMessenger.h"
-//#include "msg/CheesySerializer.h"
-
-#include "messages/MPing.h"
-
-
-__uint64_t ino = 1;
-
-
-
-#include "config.h"
-#define NUMMDS g_conf.num_mds
-#define NUMOSD g_conf.num_osd
-#define NUMCLIENT g_conf.num_client
-
-// this parses find output
-int play();
-
-int main(int argc, char **argv) {
- cout << "mpitest starting" << endl;
-
- int myrank = mpimessenger_init(argc, argv);
- int world = mpimessenger_world();
-
-
-
- MDCluster *mdc = new MDCluster(NUMMDS, NUMOSD);
-
- // create osds
- OSD *osd[NUMOSD];
- for (int i=0; i<NUMOSD; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_OSD(i),world)) continue;
- osd[i] = new OSD(i, new MPIMessenger(MSG_ADDR_OSD(i)));
- osd[i]->init();
- }
-
- // create mds
- MDS *mds[NUMMDS];
- for (int i=0; i<NUMMDS; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_MDS(i),world)) continue;
- mds[i] = new MDS(mdc, i, new MPIMessenger(MSG_ADDR_MDS(i)));
- mds[i]->init();
- }
-
- // create clients
- FakeClient *client[NUMCLIENT];
- for (int i=0; i<NUMCLIENT; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_CLIENT(i),world)) continue;
-
- MPIMessenger *real = new MPIMessenger(MSG_ADDR_CLIENT(i));
- CheesySerializer *serializer = new CheesySerializer(real);
- real->set_dispatcher(serializer);
-
- client[i] = new FakeClient(mdc, i, real, g_conf.fakeclient_requests);
- client[i]->init();
- }
-
- // seed initial requests
- for (int i=0; i<NUMCLIENT; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_CLIENT(i),world)) continue;
- client[i]->issue_request();
- }
-
- mpimessenger_start(); // start message loop
- mpimessenger_wait(); // wait for thread to finish
- mpimessenger_shutdown(); // shutdown MPI
-
- //
- /*
- cout << "---- check ----" << endl;
- for (int i=0; i<NUMMDS; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_MDS(i),world)) continue;
- mds[i]->mdcache->shutdown_pass();
- }
- */
-
- // cleanup
- //cout << "cleanup" << endl;
- for (int i=0; i<NUMMDS; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_MDS(i),world)) continue;
- delete mds[i];
- }
- for (int i=0; i<NUMOSD; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_OSD(i),world)) continue;
- delete osd[i];
- }
- for (int i=0; i<NUMCLIENT; i++) {
- if (myrank != MPI_DEST_TO_RANK(MSG_ADDR_CLIENT(i),world)) continue;
- delete client[i];
- }
- delete mdc;
-
- //cout << "done." << endl;
- return 0;
-}
-
+++ /dev/null
-// Check that MTMessenger properly dispatches replies to the correct
-// thread. Processes with mutliple threads of clients send a
-// "request" to a server, which then sends back a "reply". The client
-// checks that it received the correct reply for its request. The
-// request and reply are both an MClientRequest, which we used because
-// it allows us to pass an arbitrary string in the sarg field. In the
-// request, the sarg field contains a string "rN:tN:mN" which uniquely
-// identifies a request by rank (process), thread and message. The
-// server sends the reply with the sarg field set to "rN:tN:mN reply",
-// and the client can the verify it receive the correct reply for its
-// request.
-
-#include <pthread.h>
-#include "mpi.h"
-
-#include "messages/MClientRequest.h"
-#include "msg/MTMessenger.h"
-#include "include/error.h"
-
-#define SARG_SIZE 64
-#define SERVER_RANK 0
-#define NTHREADS 11 // number of threads per rank
-#define NMESSAGES 31 // number of messages per thread
-
-static void server_loop(MTMessenger &msgr, int world_size)
-{
- // we expect this many messages from clients, then we quit
- // (world_size-1 since server is one of the processes).
- int totmsg = NTHREADS * NMESSAGES * (world_size - 1);
- int nmsg = 0;
-
- char buf[SARG_SIZE];
-
- while(nmsg < totmsg) {
- MClientRequest *req = (MClientRequest*)msgr.recvreq();
- ASSERT(req->get_type() == MSG_CLIENT_REQUEST);
-
- //cout << "Server acknowledging " << req->get_sarg() << endl;
-
- sprintf(buf, "%s reply", req->get_sarg().c_str());
- MClientRequest resp(0, 0);
- resp.set_sarg(buf);
- msgr.sendresp(req, &resp);
-
- delete req;
- nmsg++;
- }
-
- cout << "Server successful" << endl;
-}
-
-// arguments for client thread start function (see pthread_create)
-struct client_arg
-{
- MTMessenger *msgr;
- int rank;
- int thread;
-};
-
-static void *client_session(void *_carg)
-{
- client_arg *carg = (client_arg *)_carg;
-
- char buf[SARG_SIZE];
-
- // repeat some number (arbitrary really) of rounds
- for (int i = 0; i < NMESSAGES; i++) {
-
- // send the message, receive the reply and check reply is as
- // expected
-
- MClientRequest request(0, 0);
- sprintf(buf, "r%d:t%d:m%d", carg->rank, carg->thread, i);
- request.set_sarg(buf);
-
- //cout << "Client sending " << request.get_sarg() << endl;
-
- MClientRequest *resp =
- (MClientRequest*)carg->msgr->sendrecv(&request, SERVER_RANK);
-
- ASSERT(resp->get_type() == MSG_CLIENT_REQUEST);
- sprintf(buf, "r%d:t%d:m%d reply", carg->rank, carg->thread, i);
- ASSERT(strcmp(buf, resp->get_sarg().c_str()) == 0);
-
- //cout << "Client verified " << resp->get_sarg() << endl;
-
- delete resp;
- }
-
- cout << "Client (" << carg->rank << "," << carg->thread
- << ") successful" << endl;
-
- delete carg;
- return NULL;
-}
-
-static void launch_clients(MTMessenger &msgr, int rank)
-{
- pthread_t tid[NTHREADS];
-
- // launch some number (arbitrary really) of threads
- for (int i = 0; i < NTHREADS; i++) {
-
- client_arg *carg = (client_arg*)malloc(sizeof(client_arg));
- ASSERT(carg);
- carg->msgr = &msgr;
- carg->rank = rank;
- carg->thread = i;
-
- if (pthread_create(&tid[i], NULL, client_session, carg) < 0)
- SYSERROR();
- }
-
- // we must wait for all the threads to exit before returning,
- // otherwise we shutdown MPI before while the threads are
- // chatting.
- for (int i = 0; i < NTHREADS; i++) {
- void *retval;
-
- if (pthread_join(tid[i], &retval) < 0)
- SYSERROR();
- }
-}
-
-int main(int argc, char **argv)
-{
- MTMessenger msgr(argc, argv);
-
- int rank;
- ASSERT(MPI_Comm_rank(MPI_COMM_WORLD, &rank) == MPI_SUCCESS);
- int world_size;
- ASSERT(MPI_Comm_size(MPI_COMM_WORLD, &world_size) == MPI_SUCCESS);
-
- if (rank == SERVER_RANK)
- server_loop(msgr, world_size);
- else
- launch_clients(msgr, rank);
-
- return 0;
-}
--- /dev/null
+
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/uio.h>
+
+#include "common/Clock.h"
+
+#include <iostream>
+using namespace std;
+
+int main(int argc, char **argv)
+{
+ void *buf;
+ int fd, count, loop = 0, ret;
+
+ if (argc != 4) {
+ fprintf(stderr, "Usage: %s device bsize count\n", argv[0]);
+ exit (0);
+ }
+
+ int bsize = atoi(argv[2]);
+ count = atoi(argv[3]);
+
+ posix_memalign(&buf, sysconf(_SC_PAGESIZE), bsize);
+
+ //if ((fd = open(argv[1], O_SYNC|O_RDWR)) < 0) {
+ if ((fd = open(argv[1], O_DIRECT|O_RDWR)) < 0) {
+
+ fprintf(stderr, "Can't open device %s\n", argv[1]);
+ exit (4);
+ }
+
+
+ utime_t start = g_clock.now();
+ while (loop++ < count) {
+ ret = ::write(fd, buf, bsize);
+ //if ((loop % 100) == 0)
+ //fprintf(stderr, ".");
+ }
+ ::fsync(fd);
+ ::close(fd);
+ utime_t end = g_clock.now();
+ end -= start;
+
+
+ char hostname[80];
+ gethostname(hostname, 80);
+
+ double mb = bsize*count/1024/1024;
+
+ cout << hostname << "\t" << mb << " MB\t" << end << " seconds\t" << (mb / (double)end) << " MB/sec" << std::endl;
+}
--- /dev/null
+#include "include/types.h"
+#include "common/Clock.h"
+
+#include <linux/fs.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, char **argv)
+{
+ char *fn = argv[1];
+
+ int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
+ if (fd < 0) return 1;
+
+ uint64_t bytes = 0;
+ int r = ioctl(fd, BLKGETSIZE64, &bytes);
+ uint64_t numblocks = bytes / 4096;
+
+ //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
+ int count = 1000;
+
+ cout << "fn " << fn << endl;
+ cout << "numblocks " << numblocks << endl;
+
+ int blocks = 1;
+ while (blocks <= 1024) {
+ //cout << "fd is " << fd << endl;
+
+ void *buf;
+ ::posix_memalign(&buf, 4096, 4096*blocks);
+
+ int s = blocks*4096;
+
+ utime_t start = g_clock.now();
+ for (int i=0; i<count; i++) {
+ off64_t so, o = (lrand48() % numblocks) * 4096;
+ //cout << "s = " << s << " o = " << o << endl;
+ //::lseek(fd, o, SEEK_SET);
+ lseek64(fd, o, SEEK_SET);
+
+ int r = ::read(fd, buf, blocks*4096);
+ //int r = ::read(fd, buf, s);
+ if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
+ }
+ utime_t end = g_clock.now();
+
+ double timeper = end - start;
+ timeper /= count;
+ cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
+
+ blocks *= 2;
+ free(buf);
+ }
+
+ close(fd);
+
+}
+
--- /dev/null
+#define __USE_GNU 1
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <linux/types.h>
+#include "include/ceph_fs.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "kernel/ioctl.h"
+
+
+main() {
+ struct ceph_file_layout l;
+ int fd = open("foo.txt", O_RDONLY);
+ int r = ioctl(fd, CEPH_IOC_GET_LAYOUT, &l, sizeof(l));
+ printf("get = %d\n", r);
+
+ l.fl_stripe_unit = 65536;
+ l.fl_object_size = 65536;
+
+ r = ioctl(fd, CEPH_IOC_SET_LAYOUT, &l, sizeof(l));
+ printf("set = %d\n", r);
+}
--- /dev/null
+#include "include/types.h"
+#include "common/Clock.h"
+
+#include <linux/fs.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+
+int main(int argc, char **argv)
+{
+ char *fn = argv[1];
+
+ int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
+ if (fd < 0) return 1;
+
+ uint64_t bytes = 0;
+ int r = ioctl(fd, BLKGETSIZE64, &bytes);
+ uint64_t numblocks = bytes / 4096;
+
+ //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
+ int count = 1000;
+
+ cout << "fn " << fn << endl;
+ cout << "numblocks " << numblocks << endl;
+
+ int blocks = 1;
+ while (blocks <= 1024) {
+ //cout << "fd is " << fd << endl;
+
+ void *buf;
+ ::posix_memalign(&buf, 4096, 4096*blocks);
+
+ int s = blocks*4096;
+
+ double timeper = 0.0;
+ for (int i=0; i<count; i++) {
+ off64_t so, o = (lrand48() % numblocks) * 4096;
+ //cout << "s = " << s << " o = " << o << endl;
+ //::lseek(fd, o, SEEK_SET);
+ lseek64(fd, o, SEEK_SET);
+ int r = ::read(fd, buf, 4096);
+ //int r = ::read(fd, buf, s);
+ if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
+
+ int range = 1000000/4096;
+ so = o + 4096*((rand() % range) );//- range/2);
+ //cout << o << " " << so << " " << (so-o) << endl;
+
+ utime_t start = g_clock.now();
+ lseek64(fd, so, SEEK_SET);
+ r = ::read(fd, buf, blocks*4096);
+ utime_t end = g_clock.now();
+ timeper += (end-start);
+ }
+
+ timeper /= count;
+ cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
+
+ blocks *= 2;
+ free(buf);
+ }
+
+ close(fd);
+
+}
+
--- /dev/null
+
+
+#include "../crush/Bucket.h"
+using namespace crush;
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+
+ostream& operator<<(ostream& out, vector<int>& v)
+{
+ out << "[";
+ for (int i=0; i<v.size(); i++) {
+ if (i) out << " ";
+ out << v[i];
+ }
+ out << "]";
+ return out;
+}
+
+
+int main()
+{
+ Hash h(73);
+
+ vector<int> disks;
+ for (int i=0; i<20; i++)
+ disks.push_back(i);
+
+
+ /*
+ UniformBucket ub(1, 1, 0, 10, disks);
+ ub.make_primes(h);
+ cout << "primes are " << ub.primes << endl;
+ */
+
+ MixedBucket mb(2, 1);
+ for (int i=0;i<20;i++)
+ mb.add_item(i, 10);
+
+ /*
+ MixedBucket b(3, 1);
+ b.add_item(1, ub.get_weight());
+ b.add_item(2, mb.get_weight());
+ */
+ MixedBucket b= mb;
+
+ vector<int> ocount(disks.size());
+ int numrep = 3;
+
+ vector<int> v(numrep);
+ for (int x=1; x<1000000; x++) {
+ //cout << H(x) << "\t" << h(x) << endl;
+ for (int i=0; i<numrep; i++) {
+ int d = b.choose_r(x, i, h);
+ v[i] = d;
+ ocount[d]++;
+ }
+ //cout << v << "\t" << endl;//ocount << endl;
+ }
+
+ for (int i=0; i<ocount.size(); i++) {
+ cout << "disk " << i << " has " << ocount[i] << endl;
+ }
+
+}
--- /dev/null
+
+#include <iostream>
+using namespace std;
+
+#include "include/bufferlist.h"
+
+
+int main()
+{
+
+ bufferptr p1 = new buffer("123456",6);
+ bufferptr p2 = p1;
+
+ cout << "it is '" << p1.c_str() << "'" << endl;
+
+ bufferptr p3 = new buffer("abcdef",6);
+
+ cout << "p3 is " << p3 << endl;
+
+ bufferlist bl;
+ bl.push_back(p2);
+ bl.push_back(p1);
+ bl.push_back(p3);
+
+ cout << "bl is " << bl << endl;
+
+ cout << "len is " << bl.length() << endl;
+
+ bufferlist took;
+ bl.splice(10,4,&took);
+
+ cout << "took out " << took << "leftover is " << bl << endl;
+ //cout << "len is " << bl.length() << endl;
+
+ bufferlist bl2;
+ bl2.substr_of(bl, 3, 5);
+ cout << "bl2 is " << bl2 << endl;
+
+
+}
--- /dev/null
+
+#include "common/DecayCounter.h"
+
+#include <list>
+using namespace std;
+
+struct RealCounter {
+public:
+ list<int> hits;
+
+ void hit(int ms) {
+ hits.push_back(ms);
+ }
+
+ int get(double hl, int now) {
+ trim(now-hl);
+ return hits.size();
+ }
+
+ void trim(int to) {
+ while (!hits.empty() &&
+ hits.front() < to)
+ hits.pop_front();
+ }
+
+
+};
+
+int main(int argc, char **argv)
+{
+ int target;
+ double hl = atof(argv[1]);
+ cerr << "halflife " << hl << endl;
+
+ DecayCounter dc(hl);
+ RealCounter rc;
+
+ utime_t now = g_clock.now();
+
+ for (int ms=0; ms < 300*1000; ms++) {
+ if (ms % 30000 == 0) {
+ target = 1 + (rand() % 10) * 10;
+ if (ms > 200000) target = 0;
+ }
+
+ if (target &&
+ (rand() % (1000/target) == 0)) {
+ dc.hit();
+ rc.hit(ms);
+ }
+
+ if (ms % 500 == 0) dc.get(now);
+ if (ms % 100 == 0) {
+ //dc.get(now);
+ DecayCounter o = dc;
+ cout << ms << "\t"
+ << target*hl << "\t"
+ << rc.get(hl*1000, ms) << "\t"
+ << o.get(now) << "\t"
+ << dc.val << "\t"
+ // << dc.delta << "\t"
+ << o.get_last_vel() << "\t"
+ << o.get_last() + o.get_last_vel() << "\t"
+ << endl;
+ }
+
+ now += .001;
+ }
+
+}
--- /dev/null
+
+
+#include "../crush/crush.h"
+using namespace crush;
+
+#include <math.h>
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+/*
+ostream& operator<<(ostream& out, vector<int>& v)
+{
+ out << "[";
+ for (int i=0; i<v.size(); i++) {
+ if (i) out << " ";
+ out << v[i];
+ }
+ out << "]";
+ return out;
+}
+*/
+
+void make_disks(int n, int& no, vector<int>& d)
+{
+ d.clear();
+ while (n) {
+ d.push_back(no);
+ no++;
+ n--;
+ }
+}
+
+
+Bucket *make_bucket(Crush& c, vector<int>& wid, int h, int& ndisks, int& nbuckets)
+{
+ if (h == 0) {
+ // uniform
+ Hash hash(123);
+ vector<int> disks;
+ for (int i=0; i<wid[h]; i++)
+ disks.push_back(ndisks++);
+ UniformBucket *b = new UniformBucket(nbuckets--, 1, 0, 10, disks);
+ b->make_primes(hash);
+ c.add_bucket(b);
+ //cout << h << " uniformbucket with " << wid[h] << " disks" << endl;
+ return b;
+ } else {
+ // mixed
+ MixedBucket *b = new MixedBucket(nbuckets--, h+1);
+ for (int i=0; i<wid[h]; i++) {
+ Bucket *n = make_bucket(c, wid, h-1, ndisks, nbuckets);
+ b->add_item(n->get_id(), n->get_weight());
+ }
+ c.add_bucket(b);
+ //cout << h << " mixedbucket with " << wid[h] << endl;
+ return b;
+ }
+}
+
+int make_hierarchy(Crush& c, vector<int>& wid, int& ndisks, int& nbuckets)
+{
+ Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks, nbuckets);
+ return b->get_id();
+}
+
+
+
+int main()
+{
+ Hash h(73232313);
+
+ // crush
+ Crush c;
+
+
+ // buckets
+ vector<int> disks;
+ int root = -1;
+ int nbuckets = -1;
+ int ndisks = 0;
+
+ if (0) {
+ make_disks(12, ndisks, disks);
+ UniformBucket ub1(-1, 1, 0, 30, disks);
+ ub1.make_primes(h);
+ cout << "ub1 primes are " << ub1.primes << endl;
+ c.add_bucket(&ub1);
+
+ make_disks(17, ndisks, disks);
+ UniformBucket ub2(-2, 1, 0, 30, disks);
+ ub2.make_primes(h);
+ cout << "ub2 primes are " << ub2.primes << endl;
+ c.add_bucket(&ub2);
+
+ make_disks(4, ndisks, disks);
+ UniformBucket ub3(-3, 1, 0, 30, disks);
+ ub3.make_primes(h);
+ cout << "ub3 primes are " << ub3.primes << endl;
+ c.add_bucket(&ub3);
+
+ make_disks(20, ndisks, disks);
+ MixedBucket umb1(-4, 1);
+ for (int i=0; i<20; i++)
+ umb1.add_item(disks[i], 30);
+ c.add_bucket(&umb1);
+
+ MixedBucket b(-100, 1);
+ //b.add_item(-2, ub1.get_weight());
+ b.add_item(-4, umb1.get_weight());
+ //b.add_item(-2, ub2.get_weight());
+ //b.add_item(-3, ub3.get_weight());
+ }
+
+ if (0) {
+ int bucket = -1;
+ MixedBucket *root = new MixedBucket(bucket--, 2);
+
+ for (int i=0; i<5; i++) {
+ MixedBucket *b = new MixedBucket(bucket--, 1);
+
+ int n = 5;
+
+ if (1) {
+ // add n buckets of n disks
+ for (int j=0; j<n; j++) {
+
+ MixedBucket *d = new MixedBucket(bucket--, 1);
+
+ make_disks(n, ndisks, disks);
+ for (int k=0; k<n; k++)
+ d->add_item(disks[k], 10);
+
+ //b->add_item(disks[j], 10);
+ c.add_bucket(d);
+ b->add_item(d->get_id(), d->get_weight());
+ }
+
+ c.add_bucket(b);
+ root->add_item(b->get_id(), b->get_weight());
+ } else {
+ // add n*n disks
+ make_disks(n*n, ndisks, disks);
+ for (int k=0; k<n*n; k++)
+ b->add_item(disks[k], 10);
+
+ c.add_bucket(b);
+ root->add_item(b->get_id(), b->get_weight());
+ }
+ }
+
+ c.add_bucket(root);
+ }
+
+
+ if (1) {
+ vector<int> wid;
+ for (int d=0; d<5; d++)
+ wid.push_back(10);
+ root = make_hierarchy(c, wid, ndisks, nbuckets);
+ }
+
+
+
+ // rule
+ int numrep = 1;
+
+ Rule rule;
+ if (0) {
+ rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -100));
+ rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0));
+ }
+ if (1) {
+ /*
+ rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -4));
+ rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 2, 0));
+ rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT));
+ */
+ rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root));
+ rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 1, 0));
+ rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT));
+ }
+
+ //c.overload[10] = .1;
+
+
+ int pg_per = 100;
+ int numpg = pg_per*ndisks/numrep;
+
+ vector<int> ocount(ndisks);
+ cout << ndisks << " disks, " << 1-nbuckets << " buckets" << endl;
+ cout << pg_per << " pgs per disk" << endl;
+ cout << numpg << " logical pgs" << endl;
+ cout << "numrep is " << numrep << endl;
+
+
+ int place = 1000000;
+ int times = place / numpg;
+ if (!times) times = 1;
+
+ cout << "looping " << times << " times" << endl;
+
+ float tvar = 0;
+ int tvarnum = 0;
+
+ int x = 0;
+ for (int t=0; t<times; t++) {
+ vector<int> v(numrep);
+
+ for (int z=0; z<ndisks; z++) ocount[z] = 0;
+
+ for (int xx=1; xx<numpg; xx++) {
+ x++;
+
+ //cout << H(x) << "\t" << h(x) << endl;
+ c.do_rule(rule, x, v);
+ //cout << "v = " << v << endl;// " " << v[0] << " " << v[1] << " " << v[2] << endl;
+
+ bool bad = false;
+ for (int i=0; i<numrep; i++) {
+ //int d = b.choose_r(x, i, h);
+ //v[i] = d;
+ ocount[v[i]]++;
+ for (int j=i+1; j<numrep; j++) {
+ if (v[i] == v[j])
+ bad = true;
+ }
+ }
+ if (bad)
+ cout << "bad set " << x << ": " << v << endl;
+
+ //cout << v << "\t" << ocount << endl;
+ }
+
+ /*
+ for (int i=0; i<ocount.size(); i++) {
+ cout << "disk " << i << " has " << ocount[i] << endl;
+ }
+ */
+
+ cout << "collisions: " << c.collisions << endl;
+ cout << "r bumps: " << c.bumps << endl;
+
+
+ float avg = 0.0;
+ for (int i=0; i<ocount.size(); i++)
+ avg += ocount[i];
+ avg /= ocount.size();
+ float var = 0.0;
+ for (int i=0; i<ocount.size(); i++)
+ var += (ocount[i] - avg) * (ocount[i] - avg);
+ var /= ocount.size();
+
+ cout << "avg " << avg << " var " << var << " sd " << sqrt(var) << endl;
+
+ tvar += var;
+ tvarnum++;
+ }
+
+ tvar /= tvarnum;
+
+ cout << "total variance " << tvar << endl;
+
+
+}
--- /dev/null
+
+#include "include/filepath.h"
+#include <iostream>
+using namespace std;
+
+int print(string s) {
+ filepath fp = s;
+ cout << "s = " << s << " filepath = " << fp << endl;
+ cout << " depth " << fp.depth() << endl;
+ for (int i=0; i<fp.depth(); i++) {
+ cout << "\t" << i << " " << fp[i] << endl;
+ }
+}
+
+int main() {
+ filepath p;
+ print("/home/sage");
+ print("a/b/c");
+ print("/a/b/c");
+ print("/a/b/c/");
+ print("/a/b/../d");
+}
--- /dev/null
+#include <sys/stat.h>
+#include <iostream>
+#include <string>
+using namespace std;
+
+#include "config.h"
+#include "messages/MPing.h"
+#include "common/Mutex.h"
+
+#include "msg/MPIMessenger.h"
+
+class Pinger : public Dispatcher {
+public:
+ Messenger *messenger;
+ Pinger(Messenger *m) : messenger(m) {
+ m->set_dispatcher(this);
+ }
+ void dispatch(Message *m) {
+ //dout(1) << "got incoming " << m << endl;
+ delete m;
+
+ }
+};
+
+int main(int argc, char **argv) {
+ int num = 1000;
+
+ int myrank = mpimessenger_init(argc, argv);
+ int world = mpimessenger_world();
+
+ Pinger *p = new Pinger( new MPIMessenger(myrank) );
+
+ mpimessenger_start();
+
+ //while (1) {
+ for (int i=0; i<10000; i++) {
+
+ // ping random nodes
+ int d = rand() % world;
+ if (d != myrank) {
+ //cout << "sending " << i << " to " << d << endl;
+ p->messenger->send_message(new MPing(), d);
+ }
+
+ }
+
+
+ //cout << "shutting down" << endl;
+ //p->messenger->shutdown();
+
+ mpimessenger_wait();
+ mpimessenger_shutdown(); // shutdown MPI
+}
--- /dev/null
+
+#include <list>
+#include <iostream>
+using namespace std;
+
+
+#include "include/newbuffer.h"
+//#include "include/bufferlist.h"
+
+#include "common/Thread.h"
+
+
+ class Th : public Thread {
+ public:
+ bufferlist bl;
+ Th(bufferlist& o) : bl(o) { }
+
+ void *entry() {
+ //cout << "start" << endl;
+ // thrash it a bit.
+ for (int n=0; n<10000; n++) {
+ bufferlist bl2;
+ unsigned off = rand() % (bl.length() -1);
+ unsigned len = 1 + rand() % (bl.length() - off - 1);
+ bl2.substr_of(bl, off, len);
+ bufferlist bl3;
+ bl3.append(bl);
+ bl3.append(bl2);
+ //cout << bl3 << endl;
+ bl2.clear();
+ bl3.clear();
+ }
+ //cout << "end" << endl;
+ }
+ };
+
+int main()
+{
+
+ bufferptr p1 = buffer::copy("123456",7);
+ //bufferptr p1 = new buffer("123456",7);
+ bufferptr p2 = p1;
+
+ cout << "p1 is '" << p1.c_str() << "'" << " " << p1 << endl;
+ cout << "p2 is '" << p2.c_str() << "'" << " " << p2 << endl;
+
+ bufferptr p3 = buffer::copy("abcdef",7);
+ //bufferptr p3 = new buffer("abcdef",7);
+
+ cout << "p3 is " << p3.c_str() << " " << p3 << endl;
+
+ bufferlist bl;
+ bl.push_back(p2);
+ bl.push_back(p1);
+ bl.push_back(p3);
+
+ cout << "bl is " << bl << endl;
+
+ bufferlist took;
+ bl.splice(10,4,&took);
+
+ cout << "took out " << took << ", leftover is " << bl << endl;
+ //cout << "len is " << bl.length() << endl;
+
+ bufferlist bl2;
+ bl2.substr_of(bl, 3, 5);
+ cout << "bl2 is " << bl2 << endl;
+
+
+ cout << "bl before " << bl << endl;
+
+ list<Th*> ls;
+ for (int t=0; t<40; t++) {
+ Th *t = new Th(bl);
+ cout << "create" << endl;
+ t->create();
+ ls.push_back(t);
+ }
+
+ bl.clear();
+
+ while (!ls.empty()) {
+ cout << "join" << endl;
+ ls.front()->join();
+ delete ls.front();
+ ls.pop_front();
+ }
+
+ cout << "bl after " << bl << endl;
+
+}
--- /dev/null
+/* testos.cc -- simple ObjectStore test harness.
+ Copyright (C) 2007 Casey Marshall <csm@soe.ucsc.edu>
+
+Ceph - scalable distributed file system
+
+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 "osd/ObjectStore.h"
+#include "ebofs/Ebofs.h"
+#include "osbdb/OSBDB.h"
+#include "include/buffer.h"
+
+#include <iostream>
+#include <cerrno>
+#include <vector>
+
+#include <fcntl.h>
+#include <sys/mount.h>
+
+using namespace std;
+
+static inline unsigned long long
+to_usec (struct timeval &time)
+{
+ return (((unsigned long long) time.tv_sec * 1000000)
+ + ((unsigned long long) time.tv_usec));
+}
+
+static inline unsigned long long
+to_msec (struct timeval &time)
+{
+ return (((unsigned long long) time.tv_sec * 1000)
+ + ((unsigned long long) time.tv_usec / 1000));
+}
+
+int main (int argc, char **argv)
+{
+ vector<char *> args;
+ char *osd_name = "ebofs";
+ unsigned object_size = 1024;
+ unsigned object_count = 1024;
+ unsigned write_iter = 64;
+ unsigned random_seed = ::time(NULL);
+ char *device = "/tmp/testos";
+ char *mountcmd = "mount /tmp/testos";
+ char *umountcmd = "umount /tmp/testos";
+
+ bool ebofs_raw_device = false;
+ bool inhibit_remount = (getenv("TESTOS_INHIBIT_REMOUNT") != NULL);
+
+ if (argc > 1
+ && (strcmp (argv[1], "-h") == 0
+ || strcmp (argv[1], "-help") == 0
+ || strcmp (argv[1], "--help") == 0))
+ {
+ cout << "usage: " << argv[0] << " [store [object-size [object-count [iterations [seed]]]]]" << endl;
+ cout << endl;
+ cout << "Where the arguments are:" << endl << endl;
+ cout << " store -- store type; default \"ebofs\"" << endl;
+ cout << " object-size -- size of objects; default 1024" << endl;
+ cout << " object-count -- number of objects to write; default 1024"
+ << endl;
+ cout << " iterations -- write the objects that many times; default 5"
+ << endl;
+ cout << " seed -- random seed; default current time" << endl;
+ exit (0);
+ }
+
+ argv_to_vec (argc, argv, args);
+ for (vector<char*>::iterator it = args.begin(); it != args.end();
+ it++)
+ cout << *it << " ";
+ cout << endl;
+ parse_config_options (args);
+ for (vector<char*>::iterator it = args.begin(); it != args.end();
+ it++)
+ cout << *it << " ";
+ cout << endl;
+
+ argc = args.size();
+ if (argc > 0)
+ osd_name = args[0];
+ if (argc > 1)
+ object_size = (unsigned) atol (args[1]);
+ if (argc > 2)
+ object_count = (unsigned) atol (args[2]);
+ if (argc > 3)
+ write_iter = (unsigned) atol (args[3]);
+ if (argc > 4)
+ random_seed = (unsigned) atol (args[4]);
+
+ // algin object size to 'long'
+ object_size = ((object_size + (sizeof (long) - 1)) / sizeof (long)) * sizeof (long);
+
+ char *osd_file = new char[32];
+ strcpy (osd_file, "/tmp/testos/testos.XXXXXX");
+ mktemp (osd_file);
+
+ if (strcasecmp (osd_name, "ebofs") == 0)
+ {
+ char *dev_env = getenv ("TESTOS_EBOFS_DEV");
+ if (dev_env != NULL)
+ {
+ // Assume it is a true device.
+ strncpy (osd_file, dev_env, 32);
+ inhibit_remount = true;
+ ebofs_raw_device = true;
+ }
+ }
+
+ if (!inhibit_remount)
+ {
+ if (system (mountcmd) != 0)
+ {
+ cerr << "mount failed" << endl;
+ exit (1);
+ }
+ }
+
+ ObjectStore *os = NULL;
+ if (strcasecmp (osd_name, "ebofs") == 0)
+ {
+ if (!ebofs_raw_device)
+ {
+ FILE *f = fopen (osd_file, "w");
+ if (f == NULL)
+ {
+ cerr << "failed to open " << osd_file << ": " << strerror (errno)
+ << endl;
+ exit (1);
+ }
+ // 1G file.
+ fseek (f, 1024 * 1024 * 1024, SEEK_SET);
+ fputc ('\0', f);
+ fclose (f);
+ }
+ os = new Ebofs (osd_file);
+ }
+ else if (strcasecmp (osd_name, "osbdb") == 0)
+ {
+ os = new OSBDB (osd_file);
+ }
+ else if (strcasecmp (osd_name, "osbdb-btree") == 0)
+ {
+ g_conf.bdbstore_btree = true;
+ os = new OSBDB (osd_file);
+ }
+ else
+ {
+ cerr << "I don't know about object store \"" << osd_name << "\""
+ << endl;
+ exit (1);
+ }
+
+ cout << "Writing " << object_count << " objects of size "
+ << object_size << " to " << osd_name << endl;
+
+ char *val = (char *) malloc (object_size);
+ char *val2 = (char *) malloc (object_size);
+ auto_ptr<char> valptr (val);
+ auto_ptr<char> valptr2(val2);
+ if (getenv ("TESTOS_UNALIGNED") != NULL)
+ {
+ val = val + 1;
+ val2 = val2 + 1;
+ }
+
+ for (unsigned i = 0; i < object_size; i++)
+ {
+ val[i] = (char) i;
+ val2[i] = (char) i;
+ }
+ object_t *oids = new object_t[object_count];
+
+ utime_t writes[write_iter];
+ utime_t total_write;
+ utime_t reads[write_iter];
+ utime_t total_read;
+ for (unsigned i = 0; i < write_iter; i++)
+ {
+ cerr << "Iteration " << i << endl;
+
+ int ret = os->mkfs();
+ if (ret != 0)
+ {
+ cerr << "mkfs(" << osd_file << "): " << strerror (-ret) << endl;
+ exit (1);
+ }
+ ret = os->mount();
+ if (ret != 0)
+ {
+ cerr << "mount(): " << strerror (-ret) << endl;
+ exit (1);
+ }
+
+ srandom (random_seed + i);
+
+ for (unsigned j = 0; j < object_count; j++)
+ {
+ oids[j].ino = (uint64_t) random() << 32 | random();
+ oids[j].bno = random();
+ }
+
+ utime_t begin = g_clock.now();
+ for (unsigned o = 0; o < object_count; o++)
+ {
+ bufferptr bp (val, object_size);
+ bufferlist bl;
+ bl.push_back (bp);
+ int ret;
+ if ((ret = os->write (oids[o], 0L, object_size, bl, NULL)) < 0)
+ cerr << "write " << oids[o] << " failed: "
+ << strerror (-ret) << endl;
+ }
+ os->sync();
+
+ utime_t end = g_clock.now() - begin;
+
+ cerr << "Write finished in " << end << endl;
+ total_write += end;
+ writes[i] = end;
+
+ os->umount();
+ sync();
+
+ if (!inhibit_remount)
+ {
+ if (system (umountcmd) != 0)
+ {
+ cerr << "umount failed" << endl;
+ exit (1);
+ }
+
+ if (system (mountcmd) != 0)
+ {
+ cerr << "mount(2) failed" << endl;
+ exit (1);
+ }
+ }
+
+ os->mount();
+
+ // Shuffle the OIDs.
+ for (int j = 0; j < object_count; j++)
+ {
+ int x = random() % object_count;
+ if (x < 0)
+ x = -x;
+ object_t o = oids[j];
+ oids[j] = oids[x];
+ oids[x] = o;
+ }
+
+ begin = g_clock.now();
+ for (unsigned o = 0; o < object_count; o++)
+ {
+ bufferptr bp (val2, object_size);
+ bufferlist bl;
+ bl.push_back (bp);
+
+ if (os->read (oids[o], 0L, object_size, bl) < 0)
+ {
+ cerr << "object " << oids[o] << " not found!" << endl;
+ }
+ }
+ end = g_clock.now() - begin;
+
+ cerr << "Read finished in " << end << endl;
+ total_read += end;
+ reads[i] = end;
+
+ os->umount();
+ sync();
+
+ if (!inhibit_remount)
+ {
+ if (system (umountcmd) != 0)
+ {
+ cerr << "umount(2) failed" << endl;
+ exit (1);
+ }
+
+ if (system (mountcmd) != 0)
+ {
+ cerr << "mount(3) failed" << endl;
+ exit (1);
+ }
+ }
+ }
+
+ cerr << "Finished in " << (total_write + total_read) << endl;
+
+ double write_mean = ((double) total_write) / ((double) write_iter);
+ double write_sd = 0.0;
+ for (unsigned i = 0; i < write_iter; i++)
+ {
+ double x = ((double) writes[i]) - write_mean;
+ write_sd += x * x;
+ }
+ write_sd = sqrt (write_sd / ((double) write_iter));
+
+ double read_mean = ((double) total_read) / ((double) write_iter);
+ double read_sd = 0.0;
+ for (unsigned i = 0; i < write_iter; i++)
+ {
+ double x = ((double) reads[i]) - read_mean;
+ write_sd += x * x;
+ }
+ read_sd = sqrt (read_sd / ((double) write_iter));
+
+ cout << "TESTOS: write " << osd_name << ":" << object_size << ":"
+ << object_count << ":" << write_iter << ":" << random_seed
+ << " -- " << write_mean << " " << write_sd << endl;
+
+ cout << "TESTOS: write.raw -- ";
+ for (int i = 0; i < write_iter; i++)
+ cout << ((double) writes[i]) << " ";
+ cout << endl;
+
+ cout << "TESTOS: read " << osd_name << ":" << object_size << ":"
+ << object_count << ":" << write_iter << ":" << random_seed
+ << " -- " << read_mean << " " << read_sd << endl;
+
+ cout << "TESTOS: read.raw -- ";
+ for (int i = 0; i < write_iter; i++)
+ cout << ((double) reads[i]) << " ";
+ cout << endl;
+
+ unlink (osd_file);
+ if (!inhibit_remount)
+ {
+ if (system (umountcmd) != 0)
+ {
+ cerr << "umount(3) failed" << endl;
+ exit (1);
+ }
+ }
+ exit (0);
+}
--- /dev/null
+/* testosbdb.cc -- test OSBDB.
+ Copyright (C) 2007 Casey Marshall <csm@soe.ucsc.edu> */
+
+
+#include <iostream>
+#include "osbdb/OSBDB.h"
+
+using namespace std;
+
+int
+main (int argc, char **argv)
+{
+ vector<char *> args;
+ argv_to_vec (argc, argv, args);
+ parse_config_options (args);
+
+ g_conf.debug_bdbstore = 10;
+ //g_conf.bdbstore_btree = true;
+ char dbfile[256];
+ strncpy (dbfile, "/tmp/testosbdb/db.XXXXXX", 256);
+ mktemp (dbfile);
+ OSBDB *os = new OSBDB(dbfile);
+ auto_ptr<OSBDB> osPtr (os);
+ os->mkfs();
+ os->mount();
+
+ // Put an object.
+ object_t oid (0xDEADBEEF00000000ULL, 0xFEEDFACE);
+
+ cout << "sizeof oid_t is " << sizeof (oid_t) << endl;
+ cout << "offsetof oid_t.id " << offsetof (oid_t, id) << endl;
+
+ cout << sizeof (object_t) << endl;
+ cout << sizeof (oid.ino) << endl;
+ cout << sizeof (oid.bno) << endl;
+ cout << sizeof (oid.rev) << endl;
+
+ // Shouldn't be there.
+ if (os->exists (oid))
+ {
+ cout << "FAIL: oid shouldn't be there " << oid << endl;
+ }
+
+ // Write an object.
+ char *x = (char *) malloc (1024);
+ memset(x, 0xaa, 1024);
+ bufferptr bp (x, 1024);
+ bufferlist bl;
+ bl.push_back (bp);
+
+ if (os->write (oid, 0L, 1024, bl, NULL) != 1024)
+ {
+ cout << "FAIL: writing object" << endl;
+ }
+
+ os->sync();
+
+ // Should be there.
+ if (!os->exists (oid))
+ {
+ cout << "FAIL: oid should be there: " << oid << endl;
+ }
+
+ memset(x, 0, 1024);
+ if (os->read (oid, 0, 1024, bl) != 1024)
+ {
+ cout << "FAIL: reading object" << endl;
+ }
+
+ for (int i = 0; i < 1024; i++)
+ {
+ if ((x[i] & 0xFF) != 0xaa)
+ {
+ cout << "FAIL: data read out is different" << endl;
+ break;
+ }
+ }
+
+ // Set some attributes
+ if (os->setattr (oid, "alpha", "value", strlen ("value")) != 0)
+ {
+ cout << "FAIL: set attribute" << endl;
+ }
+ if (os->setattr (oid, "beta", "value", strlen ("value")) != 0)
+ {
+ cout << "FAIL: set attribute" << endl;
+ }
+ if (os->setattr (oid, "gamma", "value", strlen ("value")) != 0)
+ {
+ cout << "FAIL: set attribute" << endl;
+ }
+ if (os->setattr (oid, "fred", "value", strlen ("value")) != 0)
+ {
+ cout << "FAIL: set attribute" << endl;
+ }
+
+ char *attrs = (char *) malloc (1024);
+ if (os->listattr (oid, attrs, 1024) != 0)
+ {
+ cout << "FAIL: listing attributes" << endl;
+ }
+ else
+ {
+ char *p = attrs;
+ if (strcmp (p, "alpha") != 0)
+ {
+ cout << "FAIL: should be \"alpha:\" \"" << p << "\"" << endl;
+ }
+ p = p + strlen (p) + 1;
+ if (strcmp (p, "beta") != 0)
+ {
+ cout << "FAIL: should be \"beta:\" \"" << p << "\"" << endl;
+ }
+ p = p + strlen (p) + 1;
+ if (strcmp (p, "fred") != 0)
+ {
+ cout << "FAIL: should be \"fred:\" \"" << p << "\"" << endl;
+ }
+ p = p + strlen (p) + 1;
+ if (strcmp (p, "gamma") != 0)
+ {
+ cout << "FAIL: should be \"gamma:\" \"" << p << "\"" << endl;
+ }
+ }
+
+ char attrvalue[256];
+ memset(attrvalue, 0, sizeof (attrvalue));
+ if (os->getattr (oid, "alpha", attrvalue, sizeof(attrvalue)) < 0)
+ {
+ cout << "FAIL: getattr alpha" << endl;
+ }
+ else if (strncmp ("value", attrvalue, strlen("value")) != 0)
+ {
+ cout << "FAIL: read attribute value differs" << endl;
+ }
+ memset(attrvalue, 0, sizeof (attrvalue));
+ if (os->getattr (oid, "fred", attrvalue, sizeof(attrvalue)) < 0)
+ {
+ cout << "FAIL: getattr fred" << endl;
+ }
+ else if (strncmp ("value", attrvalue, strlen("value")) != 0)
+ {
+ cout << "FAIL: read attribute value differs" << endl;
+ }
+ memset(attrvalue, 0, sizeof (attrvalue));
+ if (os->getattr (oid, "beta", attrvalue, sizeof(attrvalue)) < 0)
+ {
+ cout << "FAIL: getattr beta" << endl;
+ }
+ else if (strncmp ("value", attrvalue, strlen("value")) != 0)
+ {
+ cout << "FAIL: read attribute value differs" << endl;
+ }
+ memset(attrvalue, 0, sizeof (attrvalue));
+ if (os->getattr (oid, "gamma", attrvalue, sizeof(attrvalue)) < 0)
+ {
+ cout << "FAIL: getattr gamma" << endl;
+ }
+ else if (strncmp ("value", attrvalue, strlen("value")) != 0)
+ {
+ cout << "FAIL: read attribute value differs" << endl;
+ }
+
+ if (os->setattr (oid, "alpha", "different", strlen("different")) != 0)
+ cout << "FAIL: setattr overwrite" << endl;
+ memset(attrvalue, 0, sizeof (attrvalue));
+ if (os->getattr (oid, "alpha", attrvalue, sizeof(attrvalue)) < 0)
+ {
+ cout << "FAIL: getattr alpha" << endl;
+ }
+ else if (strncmp ("different", attrvalue, strlen("different")) != 0)
+ {
+ cout << "FAIL: read attribute value differs" << endl;
+ }
+
+ if (os->rmattr (oid, "alpha") != 0)
+ {
+ cout << "FAIL: rmattr alpha" << endl;
+ }
+ if (os->rmattr (oid, "fred") != 0)
+ {
+ cout << "FAIL: rmattr fred" << endl;
+ }
+ if (os->rmattr (oid, "beta") != 0)
+ {
+ cout << "FAIL: rmattr beta" << endl;
+ }
+ if (os->rmattr (oid, "gamma") != 0)
+ {
+ cout << "FAIL: rmattr gamma" << endl;
+ }
+
+ coll_t cid = 0xCAFEBABE;
+ if (os->create_collection (cid) != 0)
+ {
+ cout << "FAIL: create_collection" << endl;
+ }
+ if (os->create_collection (cid + 10) != 0)
+ {
+ cout << "FAIL: create_collection" << endl;
+ }
+ if (os->create_collection (cid + 5) != 0)
+ {
+ cout << "FAIL: create_collection" << endl;
+ }
+ if (os->create_collection (42) != 0)
+ {
+ cout << "FAIL: create_collection" << endl;
+ }
+
+ if (os->collection_add (cid, oid) != 0)
+ {
+ cout << "FAIL: collection_add" << endl;
+ }
+
+ list<coll_t> ls;
+ if (os->list_collections (ls) < 0)
+ {
+ cout << "FAIL: list_collections" << endl;
+ }
+ cout << "collections: ";
+ for (list<coll_t>::iterator it = ls.begin(); it != ls.end(); it++)
+ {
+ cout << *it << ", ";
+ }
+ cout << endl;
+
+ if (os->destroy_collection (0xCAFEBABE + 10) != 0)
+ {
+ cout << "FAIL: destroy_collection" << endl;
+ }
+
+ if (os->destroy_collection (0xCAFEBADE + 10) == 0)
+ {
+ cout << "FAIL: destroy_collection" << endl;
+ }
+
+ object_t oid2 (12345, 12345);
+ for (int i = 0; i < 8; i++)
+ {
+ oid2.rev++;
+ if (os->collection_add (cid, oid2) != 0)
+ {
+ cout << "FAIL: collection_add" << endl;
+ }
+ }
+ for (int i = 0; i < 8; i++)
+ {
+ if (os->collection_remove (cid, oid2) != 0)
+ {
+ cout << "FAIL: collection_remove" << endl;
+ }
+ oid2.rev--;
+ }
+
+ if (os->collection_setattr (cid, "alpha", "value", 5) != 0)
+ cout << "FAIL: collection_setattr" << endl;
+ if (os->collection_setattr (cid, "beta", "value", 5) != 0)
+ cout << "FAIL: collection_setattr" << endl;
+ if (os->collection_setattr (cid, "gamma", "value", 5) != 0)
+ cout << "FAIL: collection_setattr" << endl;
+ if (os->collection_setattr (cid, "fred", "value", 5) != 0)
+ cout << "FAIL: collection_setattr" << endl;
+
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "alpha", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "beta", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "gamma", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "fred", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+
+ if (os->collection_setattr (cid, "alpha", "eulavvalue", 10) != 0)
+ cout << "FAIL: collection setattr overwrite" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "alpha", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "eulavvalue", 10) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "beta", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "gamma", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+ memset (attrvalue, 0, sizeof (attrvalue));
+ if (os->collection_getattr (cid, "fred", attrvalue, sizeof (attrvalue)) < 0)
+ cout << "FAIL: collection_getattr" << endl;
+ else if (strncmp (attrvalue, "value", 5) != 0)
+ cout << "FAIL: collection attribute value different" << endl;
+
+ if (os->collection_rmattr (cid, "alpha") != 0)
+ cout << "FAIL: collection_rmattr" << endl;
+ if (os->collection_rmattr (cid, "fred") != 0)
+ cout << "FAIL: collection_rmattr" << endl;
+ if (os->collection_rmattr (cid, "beta") != 0)
+ cout << "FAIL: collection_rmattr" << endl;
+ if (os->collection_rmattr (cid, "gamma") != 0)
+ cout << "FAIL: collection_rmattr" << endl;
+
+ if (os->collection_rmattr (cid, "alpha") == 0)
+ cout << "FAIL: collection_rmattr (nonexistent)" << endl;
+
+ // Truncate the object.
+ if (os->truncate (oid, 512, NULL) != 0)
+ {
+ cout << "FAIL: truncate" << endl;
+ }
+
+ // Expand the object.
+ if (os->truncate (oid, 1200, NULL) != 0)
+ {
+ cout << "FAIL: expand" << endl;
+ }
+
+ // Delete the object.
+ if (os->remove (oid) != 0)
+ {
+ cout << "FAIL: could not remove object" << endl;
+ }
+
+ // Shouldn't be there
+ if (os->exists (oid))
+ {
+ cout << "FAIL: should not be there" << endl;
+ }
+
+ os->sync();
+ exit (0);
+}
--- /dev/null
+
+
+#include "../crush/BinaryTree.h"
+using namespace crush;
+
+#include <iostream>
+#include <vector>
+using namespace std;
+
+int main()
+{
+ BinaryTree t;
+
+ vector<int> nodes;
+
+ for (int i=0; i<30; i++) {
+ cout << "adding " << i << endl;
+ int n = t.add_node(1);
+ nodes.push_back(n);
+ //cout << t << endl;
+ }
+ cout << t << endl;
+
+ for (int k=0; k<10000; k++) {
+ if (rand() % 2) {
+ cout << "adding" << endl;
+ nodes.push_back( t.add_node(1) );
+ } else {
+ if (!nodes.empty()) {
+ //for (int i=0; i<nodes.size(); i++) {
+ int p = rand() % nodes.size();
+ int n = nodes[p];
+ assert (t.exists(n));
+ cout << "removing " << n << endl;
+ t.remove_node(n);
+
+ for (int j=p; j<nodes.size(); j++)
+ nodes[j] = nodes[j+1];
+ nodes.pop_back();
+ }
+ }
+ cout << t << endl;
+ }
+
+
+}
--- /dev/null
+
+#include <iostream>
+using namespace std;
+
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <iostream>
+#include <errno.h>
+#include <dirent.h>
+#include <sys/xattr.h>
+
+int main(int argc, char**argv)
+{
+ int a = 1;
+ int b = 2;
+
+ mknod("test", 0600, 0);
+
+ cout << "setxattr " << setxattr("test", "asdf", &a, sizeof(a), 0) << endl;
+ cout << "errno " << errno << " " << strerror(errno) << endl;
+ cout << "getxattr " << getxattr("test", "asdf", &b, sizeof(b)) << endl;
+ cout << "errno " << errno << " " << strerror(errno) << endl;
+ cout << "a is " << a << " and b is " << b << endl;
+ return 0;
+}
+++ /dev/null
-6
-8 10.0
-4 20.0
-7 30.0
-9 10.0
-8 15.0
-5 11.0
+++ /dev/null
-//
-// $Id$
-//
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "../osd/rush.h"
-
-main (int argc, char *argv[])
-{
- Rush rush;
- char buf[200];
- int i, j, k, numClusters;
- int numKeys = 5;
- int numReplicas = 4;
- int curSize;
- double curWeight;
- int servers[1000];
-
- if (argc > 1) {
- numKeys = atoi (argv[1]);
- }
- if (argc > 2) {
- numReplicas = atoi (argv[2]);
- }
-
- fgets (buf, sizeof (buf) - 2, stdin);
- sscanf (buf, "%d", &numClusters);
- for (i = 0; i < numClusters; i++) {
- fgets (buf, sizeof (buf) - 2, stdin);
- sscanf (buf, "%d %lf", &curSize, &curWeight);
- rush.AddCluster (curSize, curWeight);
- if (rush.Servers () < numReplicas) {
- fprintf (stderr, "ERROR: must have at least %d disks in the system!\n",
- rush.Clusters ());
- exit (-1);
- }
- for (j = 0; j < numKeys; j++) {
- rush.GetServersByKey (j, numReplicas, servers);
-#if 0
- printf ("%-3d %-6d ", i, j);
- for (k = 0; k < numReplicas; k++) {
- printf ("%-5d ", servers[k]);
- }
- putchar ('\n');
-#endif
- }
- }
-}
+++ /dev/null
-
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include <sys/uio.h>
-
-#include "common/Clock.h"
-
-#include <iostream>
-using namespace std;
-
-int main(int argc, char **argv)
-{
- void *buf;
- int fd, count, loop = 0, ret;
-
- if (argc != 4) {
- fprintf(stderr, "Usage: %s device bsize count\n", argv[0]);
- exit (0);
- }
-
- int bsize = atoi(argv[2]);
- count = atoi(argv[3]);
-
- posix_memalign(&buf, sysconf(_SC_PAGESIZE), bsize);
-
- //if ((fd = open(argv[1], O_SYNC|O_RDWR)) < 0) {
- if ((fd = open(argv[1], O_DIRECT|O_RDWR)) < 0) {
-
- fprintf(stderr, "Can't open device %s\n", argv[1]);
- exit (4);
- }
-
-
- utime_t start = g_clock.now();
- while (loop++ < count) {
- ret = ::write(fd, buf, bsize);
- //if ((loop % 100) == 0)
- //fprintf(stderr, ".");
- }
- ::fsync(fd);
- ::close(fd);
- utime_t end = g_clock.now();
- end -= start;
-
-
- char hostname[80];
- gethostname(hostname, 80);
-
- double mb = bsize*count/1024/1024;
-
- cout << hostname << "\t" << mb << " MB\t" << end << " seconds\t" << (mb / (double)end) << " MB/sec" << std::endl;
-}
+++ /dev/null
-#include "include/types.h"
-#include "common/Clock.h"
-
-#include <linux/fs.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-
-int main(int argc, char **argv)
-{
- char *fn = argv[1];
-
- int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
- if (fd < 0) return 1;
-
- uint64_t bytes = 0;
- int r = ioctl(fd, BLKGETSIZE64, &bytes);
- uint64_t numblocks = bytes / 4096;
-
- //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
- int count = 1000;
-
- cout << "fn " << fn << endl;
- cout << "numblocks " << numblocks << endl;
-
- int blocks = 1;
- while (blocks <= 1024) {
- //cout << "fd is " << fd << endl;
-
- void *buf;
- ::posix_memalign(&buf, 4096, 4096*blocks);
-
- int s = blocks*4096;
-
- utime_t start = g_clock.now();
- for (int i=0; i<count; i++) {
- off64_t so, o = (lrand48() % numblocks) * 4096;
- //cout << "s = " << s << " o = " << o << endl;
- //::lseek(fd, o, SEEK_SET);
- lseek64(fd, o, SEEK_SET);
-
- int r = ::read(fd, buf, blocks*4096);
- //int r = ::read(fd, buf, s);
- if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
- }
- utime_t end = g_clock.now();
-
- double timeper = end - start;
- timeper /= count;
- cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
-
- blocks *= 2;
- free(buf);
- }
-
- close(fd);
-
-}
-
+++ /dev/null
-#define __USE_GNU 1
-#include <fcntl.h>
-#include <netinet/in.h>
-#include <linux/types.h>
-#include "include/ceph_fs.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "kernel/ioctl.h"
-
-
-main() {
- struct ceph_file_layout l;
- int fd = open("foo.txt", O_RDONLY);
- int r = ioctl(fd, CEPH_IOC_GET_LAYOUT, &l, sizeof(l));
- printf("get = %d\n", r);
-
- l.fl_stripe_unit = 65536;
- l.fl_object_size = 65536;
-
- r = ioctl(fd, CEPH_IOC_SET_LAYOUT, &l, sizeof(l));
- printf("set = %d\n", r);
-}
+++ /dev/null
-#include "include/types.h"
-#include "common/Clock.h"
-
-#include <linux/fs.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-
-int main(int argc, char **argv)
-{
- char *fn = argv[1];
-
- int fd = ::open(fn, O_RDWR|O_DIRECT);//|O_SYNC|O_DIRECT);
- if (fd < 0) return 1;
-
- uint64_t bytes = 0;
- int r = ioctl(fd, BLKGETSIZE64, &bytes);
- uint64_t numblocks = bytes / 4096;
-
- //uint64_t numblocks = atoll(argv[2]) * 4;// / 4096;
- int count = 1000;
-
- cout << "fn " << fn << endl;
- cout << "numblocks " << numblocks << endl;
-
- int blocks = 1;
- while (blocks <= 1024) {
- //cout << "fd is " << fd << endl;
-
- void *buf;
- ::posix_memalign(&buf, 4096, 4096*blocks);
-
- int s = blocks*4096;
-
- double timeper = 0.0;
- for (int i=0; i<count; i++) {
- off64_t so, o = (lrand48() % numblocks) * 4096;
- //cout << "s = " << s << " o = " << o << endl;
- //::lseek(fd, o, SEEK_SET);
- lseek64(fd, o, SEEK_SET);
- int r = ::read(fd, buf, 4096);
- //int r = ::read(fd, buf, s);
- if (r < 0) cout << "r = " << r << " " << strerror(errno) << endl;
-
- int range = 1000000/4096;
- so = o + 4096*((rand() % range) );//- range/2);
- //cout << o << " " << so << " " << (so-o) << endl;
-
- utime_t start = g_clock.now();
- lseek64(fd, so, SEEK_SET);
- r = ::read(fd, buf, blocks*4096);
- utime_t end = g_clock.now();
- timeper += (end-start);
- }
-
- timeper /= count;
- cout << blocks << "\t" << s << "\t" << (double)timeper << endl;
-
- blocks *= 2;
- free(buf);
- }
-
- close(fd);
-
-}
-
+++ /dev/null
-
-
-#include "../crush/Bucket.h"
-using namespace crush;
-
-#include <iostream>
-#include <vector>
-using namespace std;
-
-
-ostream& operator<<(ostream& out, vector<int>& v)
-{
- out << "[";
- for (int i=0; i<v.size(); i++) {
- if (i) out << " ";
- out << v[i];
- }
- out << "]";
- return out;
-}
-
-
-int main()
-{
- Hash h(73);
-
- vector<int> disks;
- for (int i=0; i<20; i++)
- disks.push_back(i);
-
-
- /*
- UniformBucket ub(1, 1, 0, 10, disks);
- ub.make_primes(h);
- cout << "primes are " << ub.primes << endl;
- */
-
- MixedBucket mb(2, 1);
- for (int i=0;i<20;i++)
- mb.add_item(i, 10);
-
- /*
- MixedBucket b(3, 1);
- b.add_item(1, ub.get_weight());
- b.add_item(2, mb.get_weight());
- */
- MixedBucket b= mb;
-
- vector<int> ocount(disks.size());
- int numrep = 3;
-
- vector<int> v(numrep);
- for (int x=1; x<1000000; x++) {
- //cout << H(x) << "\t" << h(x) << endl;
- for (int i=0; i<numrep; i++) {
- int d = b.choose_r(x, i, h);
- v[i] = d;
- ocount[d]++;
- }
- //cout << v << "\t" << endl;//ocount << endl;
- }
-
- for (int i=0; i<ocount.size(); i++) {
- cout << "disk " << i << " has " << ocount[i] << endl;
- }
-
-}
+++ /dev/null
-
-#include <iostream>
-using namespace std;
-
-#include "include/bufferlist.h"
-
-
-int main()
-{
-
- bufferptr p1 = new buffer("123456",6);
- bufferptr p2 = p1;
-
- cout << "it is '" << p1.c_str() << "'" << endl;
-
- bufferptr p3 = new buffer("abcdef",6);
-
- cout << "p3 is " << p3 << endl;
-
- bufferlist bl;
- bl.push_back(p2);
- bl.push_back(p1);
- bl.push_back(p3);
-
- cout << "bl is " << bl << endl;
-
- cout << "len is " << bl.length() << endl;
-
- bufferlist took;
- bl.splice(10,4,&took);
-
- cout << "took out " << took << "leftover is " << bl << endl;
- //cout << "len is " << bl.length() << endl;
-
- bufferlist bl2;
- bl2.substr_of(bl, 3, 5);
- cout << "bl2 is " << bl2 << endl;
-
-
-}
+++ /dev/null
-
-#include "common/DecayCounter.h"
-
-#include <list>
-using namespace std;
-
-struct RealCounter {
-public:
- list<int> hits;
-
- void hit(int ms) {
- hits.push_back(ms);
- }
-
- int get(double hl, int now) {
- trim(now-hl);
- return hits.size();
- }
-
- void trim(int to) {
- while (!hits.empty() &&
- hits.front() < to)
- hits.pop_front();
- }
-
-
-};
-
-int main(int argc, char **argv)
-{
- int target;
- double hl = atof(argv[1]);
- cerr << "halflife " << hl << endl;
-
- DecayCounter dc(hl);
- RealCounter rc;
-
- utime_t now = g_clock.now();
-
- for (int ms=0; ms < 300*1000; ms++) {
- if (ms % 30000 == 0) {
- target = 1 + (rand() % 10) * 10;
- if (ms > 200000) target = 0;
- }
-
- if (target &&
- (rand() % (1000/target) == 0)) {
- dc.hit();
- rc.hit(ms);
- }
-
- if (ms % 500 == 0) dc.get(now);
- if (ms % 100 == 0) {
- //dc.get(now);
- DecayCounter o = dc;
- cout << ms << "\t"
- << target*hl << "\t"
- << rc.get(hl*1000, ms) << "\t"
- << o.get(now) << "\t"
- << dc.val << "\t"
- // << dc.delta << "\t"
- << o.get_last_vel() << "\t"
- << o.get_last() + o.get_last_vel() << "\t"
- << endl;
- }
-
- now += .001;
- }
-
-}
+++ /dev/null
-
-
-#include "../crush/crush.h"
-using namespace crush;
-
-#include <math.h>
-
-#include <iostream>
-#include <vector>
-using namespace std;
-
-/*
-ostream& operator<<(ostream& out, vector<int>& v)
-{
- out << "[";
- for (int i=0; i<v.size(); i++) {
- if (i) out << " ";
- out << v[i];
- }
- out << "]";
- return out;
-}
-*/
-
-void make_disks(int n, int& no, vector<int>& d)
-{
- d.clear();
- while (n) {
- d.push_back(no);
- no++;
- n--;
- }
-}
-
-
-Bucket *make_bucket(Crush& c, vector<int>& wid, int h, int& ndisks, int& nbuckets)
-{
- if (h == 0) {
- // uniform
- Hash hash(123);
- vector<int> disks;
- for (int i=0; i<wid[h]; i++)
- disks.push_back(ndisks++);
- UniformBucket *b = new UniformBucket(nbuckets--, 1, 0, 10, disks);
- b->make_primes(hash);
- c.add_bucket(b);
- //cout << h << " uniformbucket with " << wid[h] << " disks" << endl;
- return b;
- } else {
- // mixed
- MixedBucket *b = new MixedBucket(nbuckets--, h+1);
- for (int i=0; i<wid[h]; i++) {
- Bucket *n = make_bucket(c, wid, h-1, ndisks, nbuckets);
- b->add_item(n->get_id(), n->get_weight());
- }
- c.add_bucket(b);
- //cout << h << " mixedbucket with " << wid[h] << endl;
- return b;
- }
-}
-
-int make_hierarchy(Crush& c, vector<int>& wid, int& ndisks, int& nbuckets)
-{
- Bucket *b = make_bucket(c, wid, wid.size()-1, ndisks, nbuckets);
- return b->get_id();
-}
-
-
-
-int main()
-{
- Hash h(73232313);
-
- // crush
- Crush c;
-
-
- // buckets
- vector<int> disks;
- int root = -1;
- int nbuckets = -1;
- int ndisks = 0;
-
- if (0) {
- make_disks(12, ndisks, disks);
- UniformBucket ub1(-1, 1, 0, 30, disks);
- ub1.make_primes(h);
- cout << "ub1 primes are " << ub1.primes << endl;
- c.add_bucket(&ub1);
-
- make_disks(17, ndisks, disks);
- UniformBucket ub2(-2, 1, 0, 30, disks);
- ub2.make_primes(h);
- cout << "ub2 primes are " << ub2.primes << endl;
- c.add_bucket(&ub2);
-
- make_disks(4, ndisks, disks);
- UniformBucket ub3(-3, 1, 0, 30, disks);
- ub3.make_primes(h);
- cout << "ub3 primes are " << ub3.primes << endl;
- c.add_bucket(&ub3);
-
- make_disks(20, ndisks, disks);
- MixedBucket umb1(-4, 1);
- for (int i=0; i<20; i++)
- umb1.add_item(disks[i], 30);
- c.add_bucket(&umb1);
-
- MixedBucket b(-100, 1);
- //b.add_item(-2, ub1.get_weight());
- b.add_item(-4, umb1.get_weight());
- //b.add_item(-2, ub2.get_weight());
- //b.add_item(-3, ub3.get_weight());
- }
-
- if (0) {
- int bucket = -1;
- MixedBucket *root = new MixedBucket(bucket--, 2);
-
- for (int i=0; i<5; i++) {
- MixedBucket *b = new MixedBucket(bucket--, 1);
-
- int n = 5;
-
- if (1) {
- // add n buckets of n disks
- for (int j=0; j<n; j++) {
-
- MixedBucket *d = new MixedBucket(bucket--, 1);
-
- make_disks(n, ndisks, disks);
- for (int k=0; k<n; k++)
- d->add_item(disks[k], 10);
-
- //b->add_item(disks[j], 10);
- c.add_bucket(d);
- b->add_item(d->get_id(), d->get_weight());
- }
-
- c.add_bucket(b);
- root->add_item(b->get_id(), b->get_weight());
- } else {
- // add n*n disks
- make_disks(n*n, ndisks, disks);
- for (int k=0; k<n*n; k++)
- b->add_item(disks[k], 10);
-
- c.add_bucket(b);
- root->add_item(b->get_id(), b->get_weight());
- }
- }
-
- c.add_bucket(root);
- }
-
-
- if (1) {
- vector<int> wid;
- for (int d=0; d<5; d++)
- wid.push_back(10);
- root = make_hierarchy(c, wid, ndisks, nbuckets);
- }
-
-
-
- // rule
- int numrep = 1;
-
- Rule rule;
- if (0) {
- rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -100));
- rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, numrep, 0));
- }
- if (1) {
- /*
- rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, -4));
- rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 2, 0));
- rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT));
- */
- rule.steps.push_back(RuleStep(CRUSH_RULE_TAKE, root));
- rule.steps.push_back(RuleStep(CRUSH_RULE_CHOOSE, 1, 0));
- rule.steps.push_back(RuleStep(CRUSH_RULE_EMIT));
- }
-
- //c.overload[10] = .1;
-
-
- int pg_per = 100;
- int numpg = pg_per*ndisks/numrep;
-
- vector<int> ocount(ndisks);
- cout << ndisks << " disks, " << 1-nbuckets << " buckets" << endl;
- cout << pg_per << " pgs per disk" << endl;
- cout << numpg << " logical pgs" << endl;
- cout << "numrep is " << numrep << endl;
-
-
- int place = 1000000;
- int times = place / numpg;
- if (!times) times = 1;
-
- cout << "looping " << times << " times" << endl;
-
- float tvar = 0;
- int tvarnum = 0;
-
- int x = 0;
- for (int t=0; t<times; t++) {
- vector<int> v(numrep);
-
- for (int z=0; z<ndisks; z++) ocount[z] = 0;
-
- for (int xx=1; xx<numpg; xx++) {
- x++;
-
- //cout << H(x) << "\t" << h(x) << endl;
- c.do_rule(rule, x, v);
- //cout << "v = " << v << endl;// " " << v[0] << " " << v[1] << " " << v[2] << endl;
-
- bool bad = false;
- for (int i=0; i<numrep; i++) {
- //int d = b.choose_r(x, i, h);
- //v[i] = d;
- ocount[v[i]]++;
- for (int j=i+1; j<numrep; j++) {
- if (v[i] == v[j])
- bad = true;
- }
- }
- if (bad)
- cout << "bad set " << x << ": " << v << endl;
-
- //cout << v << "\t" << ocount << endl;
- }
-
- /*
- for (int i=0; i<ocount.size(); i++) {
- cout << "disk " << i << " has " << ocount[i] << endl;
- }
- */
-
- cout << "collisions: " << c.collisions << endl;
- cout << "r bumps: " << c.bumps << endl;
-
-
- float avg = 0.0;
- for (int i=0; i<ocount.size(); i++)
- avg += ocount[i];
- avg /= ocount.size();
- float var = 0.0;
- for (int i=0; i<ocount.size(); i++)
- var += (ocount[i] - avg) * (ocount[i] - avg);
- var /= ocount.size();
-
- cout << "avg " << avg << " var " << var << " sd " << sqrt(var) << endl;
-
- tvar += var;
- tvarnum++;
- }
-
- tvar /= tvarnum;
-
- cout << "total variance " << tvar << endl;
-
-
-}
+++ /dev/null
-
-#include "include/filepath.h"
-#include <iostream>
-using namespace std;
-
-int print(string s) {
- filepath fp = s;
- cout << "s = " << s << " filepath = " << fp << endl;
- cout << " depth " << fp.depth() << endl;
- for (int i=0; i<fp.depth(); i++) {
- cout << "\t" << i << " " << fp[i] << endl;
- }
-}
-
-int main() {
- filepath p;
- print("/home/sage");
- print("a/b/c");
- print("/a/b/c");
- print("/a/b/c/");
- print("/a/b/../d");
-}
+++ /dev/null
-#include <sys/stat.h>
-#include <iostream>
-#include <string>
-using namespace std;
-
-#include "config.h"
-#include "messages/MPing.h"
-#include "common/Mutex.h"
-
-#include "msg/MPIMessenger.h"
-
-class Pinger : public Dispatcher {
-public:
- Messenger *messenger;
- Pinger(Messenger *m) : messenger(m) {
- m->set_dispatcher(this);
- }
- void dispatch(Message *m) {
- //dout(1) << "got incoming " << m << endl;
- delete m;
-
- }
-};
-
-int main(int argc, char **argv) {
- int num = 1000;
-
- int myrank = mpimessenger_init(argc, argv);
- int world = mpimessenger_world();
-
- Pinger *p = new Pinger( new MPIMessenger(myrank) );
-
- mpimessenger_start();
-
- //while (1) {
- for (int i=0; i<10000; i++) {
-
- // ping random nodes
- int d = rand() % world;
- if (d != myrank) {
- //cout << "sending " << i << " to " << d << endl;
- p->messenger->send_message(new MPing(), d);
- }
-
- }
-
-
- //cout << "shutting down" << endl;
- //p->messenger->shutdown();
-
- mpimessenger_wait();
- mpimessenger_shutdown(); // shutdown MPI
-}
+++ /dev/null
-
-#include <list>
-#include <iostream>
-using namespace std;
-
-
-#include "include/newbuffer.h"
-//#include "include/bufferlist.h"
-
-#include "common/Thread.h"
-
-
- class Th : public Thread {
- public:
- bufferlist bl;
- Th(bufferlist& o) : bl(o) { }
-
- void *entry() {
- //cout << "start" << endl;
- // thrash it a bit.
- for (int n=0; n<10000; n++) {
- bufferlist bl2;
- unsigned off = rand() % (bl.length() -1);
- unsigned len = 1 + rand() % (bl.length() - off - 1);
- bl2.substr_of(bl, off, len);
- bufferlist bl3;
- bl3.append(bl);
- bl3.append(bl2);
- //cout << bl3 << endl;
- bl2.clear();
- bl3.clear();
- }
- //cout << "end" << endl;
- }
- };
-
-int main()
-{
-
- bufferptr p1 = buffer::copy("123456",7);
- //bufferptr p1 = new buffer("123456",7);
- bufferptr p2 = p1;
-
- cout << "p1 is '" << p1.c_str() << "'" << " " << p1 << endl;
- cout << "p2 is '" << p2.c_str() << "'" << " " << p2 << endl;
-
- bufferptr p3 = buffer::copy("abcdef",7);
- //bufferptr p3 = new buffer("abcdef",7);
-
- cout << "p3 is " << p3.c_str() << " " << p3 << endl;
-
- bufferlist bl;
- bl.push_back(p2);
- bl.push_back(p1);
- bl.push_back(p3);
-
- cout << "bl is " << bl << endl;
-
- bufferlist took;
- bl.splice(10,4,&took);
-
- cout << "took out " << took << ", leftover is " << bl << endl;
- //cout << "len is " << bl.length() << endl;
-
- bufferlist bl2;
- bl2.substr_of(bl, 3, 5);
- cout << "bl2 is " << bl2 << endl;
-
-
- cout << "bl before " << bl << endl;
-
- list<Th*> ls;
- for (int t=0; t<40; t++) {
- Th *t = new Th(bl);
- cout << "create" << endl;
- t->create();
- ls.push_back(t);
- }
-
- bl.clear();
-
- while (!ls.empty()) {
- cout << "join" << endl;
- ls.front()->join();
- delete ls.front();
- ls.pop_front();
- }
-
- cout << "bl after " << bl << endl;
-
-}
+++ /dev/null
-/* testos.cc -- simple ObjectStore test harness.
- Copyright (C) 2007 Casey Marshall <csm@soe.ucsc.edu>
-
-Ceph - scalable distributed file system
-
-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 "osd/ObjectStore.h"
-#include "ebofs/Ebofs.h"
-#include "osbdb/OSBDB.h"
-#include "include/buffer.h"
-
-#include <iostream>
-#include <cerrno>
-#include <vector>
-
-#include <fcntl.h>
-#include <sys/mount.h>
-
-using namespace std;
-
-static inline unsigned long long
-to_usec (struct timeval &time)
-{
- return (((unsigned long long) time.tv_sec * 1000000)
- + ((unsigned long long) time.tv_usec));
-}
-
-static inline unsigned long long
-to_msec (struct timeval &time)
-{
- return (((unsigned long long) time.tv_sec * 1000)
- + ((unsigned long long) time.tv_usec / 1000));
-}
-
-int main (int argc, char **argv)
-{
- vector<char *> args;
- char *osd_name = "ebofs";
- unsigned object_size = 1024;
- unsigned object_count = 1024;
- unsigned write_iter = 64;
- unsigned random_seed = ::time(NULL);
- char *device = "/tmp/testos";
- char *mountcmd = "mount /tmp/testos";
- char *umountcmd = "umount /tmp/testos";
-
- bool ebofs_raw_device = false;
- bool inhibit_remount = (getenv("TESTOS_INHIBIT_REMOUNT") != NULL);
-
- if (argc > 1
- && (strcmp (argv[1], "-h") == 0
- || strcmp (argv[1], "-help") == 0
- || strcmp (argv[1], "--help") == 0))
- {
- cout << "usage: " << argv[0] << " [store [object-size [object-count [iterations [seed]]]]]" << endl;
- cout << endl;
- cout << "Where the arguments are:" << endl << endl;
- cout << " store -- store type; default \"ebofs\"" << endl;
- cout << " object-size -- size of objects; default 1024" << endl;
- cout << " object-count -- number of objects to write; default 1024"
- << endl;
- cout << " iterations -- write the objects that many times; default 5"
- << endl;
- cout << " seed -- random seed; default current time" << endl;
- exit (0);
- }
-
- argv_to_vec (argc, argv, args);
- for (vector<char*>::iterator it = args.begin(); it != args.end();
- it++)
- cout << *it << " ";
- cout << endl;
- parse_config_options (args);
- for (vector<char*>::iterator it = args.begin(); it != args.end();
- it++)
- cout << *it << " ";
- cout << endl;
-
- argc = args.size();
- if (argc > 0)
- osd_name = args[0];
- if (argc > 1)
- object_size = (unsigned) atol (args[1]);
- if (argc > 2)
- object_count = (unsigned) atol (args[2]);
- if (argc > 3)
- write_iter = (unsigned) atol (args[3]);
- if (argc > 4)
- random_seed = (unsigned) atol (args[4]);
-
- // algin object size to 'long'
- object_size = ((object_size + (sizeof (long) - 1)) / sizeof (long)) * sizeof (long);
-
- char *osd_file = new char[32];
- strcpy (osd_file, "/tmp/testos/testos.XXXXXX");
- mktemp (osd_file);
-
- if (strcasecmp (osd_name, "ebofs") == 0)
- {
- char *dev_env = getenv ("TESTOS_EBOFS_DEV");
- if (dev_env != NULL)
- {
- // Assume it is a true device.
- strncpy (osd_file, dev_env, 32);
- inhibit_remount = true;
- ebofs_raw_device = true;
- }
- }
-
- if (!inhibit_remount)
- {
- if (system (mountcmd) != 0)
- {
- cerr << "mount failed" << endl;
- exit (1);
- }
- }
-
- ObjectStore *os = NULL;
- if (strcasecmp (osd_name, "ebofs") == 0)
- {
- if (!ebofs_raw_device)
- {
- FILE *f = fopen (osd_file, "w");
- if (f == NULL)
- {
- cerr << "failed to open " << osd_file << ": " << strerror (errno)
- << endl;
- exit (1);
- }
- // 1G file.
- fseek (f, 1024 * 1024 * 1024, SEEK_SET);
- fputc ('\0', f);
- fclose (f);
- }
- os = new Ebofs (osd_file);
- }
- else if (strcasecmp (osd_name, "osbdb") == 0)
- {
- os = new OSBDB (osd_file);
- }
- else if (strcasecmp (osd_name, "osbdb-btree") == 0)
- {
- g_conf.bdbstore_btree = true;
- os = new OSBDB (osd_file);
- }
- else
- {
- cerr << "I don't know about object store \"" << osd_name << "\""
- << endl;
- exit (1);
- }
-
- cout << "Writing " << object_count << " objects of size "
- << object_size << " to " << osd_name << endl;
-
- char *val = (char *) malloc (object_size);
- char *val2 = (char *) malloc (object_size);
- auto_ptr<char> valptr (val);
- auto_ptr<char> valptr2(val2);
- if (getenv ("TESTOS_UNALIGNED") != NULL)
- {
- val = val + 1;
- val2 = val2 + 1;
- }
-
- for (unsigned i = 0; i < object_size; i++)
- {
- val[i] = (char) i;
- val2[i] = (char) i;
- }
- object_t *oids = new object_t[object_count];
-
- utime_t writes[write_iter];
- utime_t total_write;
- utime_t reads[write_iter];
- utime_t total_read;
- for (unsigned i = 0; i < write_iter; i++)
- {
- cerr << "Iteration " << i << endl;
-
- int ret = os->mkfs();
- if (ret != 0)
- {
- cerr << "mkfs(" << osd_file << "): " << strerror (-ret) << endl;
- exit (1);
- }
- ret = os->mount();
- if (ret != 0)
- {
- cerr << "mount(): " << strerror (-ret) << endl;
- exit (1);
- }
-
- srandom (random_seed + i);
-
- for (unsigned j = 0; j < object_count; j++)
- {
- oids[j].ino = (uint64_t) random() << 32 | random();
- oids[j].bno = random();
- }
-
- utime_t begin = g_clock.now();
- for (unsigned o = 0; o < object_count; o++)
- {
- bufferptr bp (val, object_size);
- bufferlist bl;
- bl.push_back (bp);
- int ret;
- if ((ret = os->write (oids[o], 0L, object_size, bl, NULL)) < 0)
- cerr << "write " << oids[o] << " failed: "
- << strerror (-ret) << endl;
- }
- os->sync();
-
- utime_t end = g_clock.now() - begin;
-
- cerr << "Write finished in " << end << endl;
- total_write += end;
- writes[i] = end;
-
- os->umount();
- sync();
-
- if (!inhibit_remount)
- {
- if (system (umountcmd) != 0)
- {
- cerr << "umount failed" << endl;
- exit (1);
- }
-
- if (system (mountcmd) != 0)
- {
- cerr << "mount(2) failed" << endl;
- exit (1);
- }
- }
-
- os->mount();
-
- // Shuffle the OIDs.
- for (int j = 0; j < object_count; j++)
- {
- int x = random() % object_count;
- if (x < 0)
- x = -x;
- object_t o = oids[j];
- oids[j] = oids[x];
- oids[x] = o;
- }
-
- begin = g_clock.now();
- for (unsigned o = 0; o < object_count; o++)
- {
- bufferptr bp (val2, object_size);
- bufferlist bl;
- bl.push_back (bp);
-
- if (os->read (oids[o], 0L, object_size, bl) < 0)
- {
- cerr << "object " << oids[o] << " not found!" << endl;
- }
- }
- end = g_clock.now() - begin;
-
- cerr << "Read finished in " << end << endl;
- total_read += end;
- reads[i] = end;
-
- os->umount();
- sync();
-
- if (!inhibit_remount)
- {
- if (system (umountcmd) != 0)
- {
- cerr << "umount(2) failed" << endl;
- exit (1);
- }
-
- if (system (mountcmd) != 0)
- {
- cerr << "mount(3) failed" << endl;
- exit (1);
- }
- }
- }
-
- cerr << "Finished in " << (total_write + total_read) << endl;
-
- double write_mean = ((double) total_write) / ((double) write_iter);
- double write_sd = 0.0;
- for (unsigned i = 0; i < write_iter; i++)
- {
- double x = ((double) writes[i]) - write_mean;
- write_sd += x * x;
- }
- write_sd = sqrt (write_sd / ((double) write_iter));
-
- double read_mean = ((double) total_read) / ((double) write_iter);
- double read_sd = 0.0;
- for (unsigned i = 0; i < write_iter; i++)
- {
- double x = ((double) reads[i]) - read_mean;
- write_sd += x * x;
- }
- read_sd = sqrt (read_sd / ((double) write_iter));
-
- cout << "TESTOS: write " << osd_name << ":" << object_size << ":"
- << object_count << ":" << write_iter << ":" << random_seed
- << " -- " << write_mean << " " << write_sd << endl;
-
- cout << "TESTOS: write.raw -- ";
- for (int i = 0; i < write_iter; i++)
- cout << ((double) writes[i]) << " ";
- cout << endl;
-
- cout << "TESTOS: read " << osd_name << ":" << object_size << ":"
- << object_count << ":" << write_iter << ":" << random_seed
- << " -- " << read_mean << " " << read_sd << endl;
-
- cout << "TESTOS: read.raw -- ";
- for (int i = 0; i < write_iter; i++)
- cout << ((double) reads[i]) << " ";
- cout << endl;
-
- unlink (osd_file);
- if (!inhibit_remount)
- {
- if (system (umountcmd) != 0)
- {
- cerr << "umount(3) failed" << endl;
- exit (1);
- }
- }
- exit (0);
-}
+++ /dev/null
-/* testosbdb.cc -- test OSBDB.
- Copyright (C) 2007 Casey Marshall <csm@soe.ucsc.edu> */
-
-
-#include <iostream>
-#include "osbdb/OSBDB.h"
-
-using namespace std;
-
-int
-main (int argc, char **argv)
-{
- vector<char *> args;
- argv_to_vec (argc, argv, args);
- parse_config_options (args);
-
- g_conf.debug_bdbstore = 10;
- //g_conf.bdbstore_btree = true;
- char dbfile[256];
- strncpy (dbfile, "/tmp/testosbdb/db.XXXXXX", 256);
- mktemp (dbfile);
- OSBDB *os = new OSBDB(dbfile);
- auto_ptr<OSBDB> osPtr (os);
- os->mkfs();
- os->mount();
-
- // Put an object.
- object_t oid (0xDEADBEEF00000000ULL, 0xFEEDFACE);
-
- cout << "sizeof oid_t is " << sizeof (oid_t) << endl;
- cout << "offsetof oid_t.id " << offsetof (oid_t, id) << endl;
-
- cout << sizeof (object_t) << endl;
- cout << sizeof (oid.ino) << endl;
- cout << sizeof (oid.bno) << endl;
- cout << sizeof (oid.rev) << endl;
-
- // Shouldn't be there.
- if (os->exists (oid))
- {
- cout << "FAIL: oid shouldn't be there " << oid << endl;
- }
-
- // Write an object.
- char *x = (char *) malloc (1024);
- memset(x, 0xaa, 1024);
- bufferptr bp (x, 1024);
- bufferlist bl;
- bl.push_back (bp);
-
- if (os->write (oid, 0L, 1024, bl, NULL) != 1024)
- {
- cout << "FAIL: writing object" << endl;
- }
-
- os->sync();
-
- // Should be there.
- if (!os->exists (oid))
- {
- cout << "FAIL: oid should be there: " << oid << endl;
- }
-
- memset(x, 0, 1024);
- if (os->read (oid, 0, 1024, bl) != 1024)
- {
- cout << "FAIL: reading object" << endl;
- }
-
- for (int i = 0; i < 1024; i++)
- {
- if ((x[i] & 0xFF) != 0xaa)
- {
- cout << "FAIL: data read out is different" << endl;
- break;
- }
- }
-
- // Set some attributes
- if (os->setattr (oid, "alpha", "value", strlen ("value")) != 0)
- {
- cout << "FAIL: set attribute" << endl;
- }
- if (os->setattr (oid, "beta", "value", strlen ("value")) != 0)
- {
- cout << "FAIL: set attribute" << endl;
- }
- if (os->setattr (oid, "gamma", "value", strlen ("value")) != 0)
- {
- cout << "FAIL: set attribute" << endl;
- }
- if (os->setattr (oid, "fred", "value", strlen ("value")) != 0)
- {
- cout << "FAIL: set attribute" << endl;
- }
-
- char *attrs = (char *) malloc (1024);
- if (os->listattr (oid, attrs, 1024) != 0)
- {
- cout << "FAIL: listing attributes" << endl;
- }
- else
- {
- char *p = attrs;
- if (strcmp (p, "alpha") != 0)
- {
- cout << "FAIL: should be \"alpha:\" \"" << p << "\"" << endl;
- }
- p = p + strlen (p) + 1;
- if (strcmp (p, "beta") != 0)
- {
- cout << "FAIL: should be \"beta:\" \"" << p << "\"" << endl;
- }
- p = p + strlen (p) + 1;
- if (strcmp (p, "fred") != 0)
- {
- cout << "FAIL: should be \"fred:\" \"" << p << "\"" << endl;
- }
- p = p + strlen (p) + 1;
- if (strcmp (p, "gamma") != 0)
- {
- cout << "FAIL: should be \"gamma:\" \"" << p << "\"" << endl;
- }
- }
-
- char attrvalue[256];
- memset(attrvalue, 0, sizeof (attrvalue));
- if (os->getattr (oid, "alpha", attrvalue, sizeof(attrvalue)) < 0)
- {
- cout << "FAIL: getattr alpha" << endl;
- }
- else if (strncmp ("value", attrvalue, strlen("value")) != 0)
- {
- cout << "FAIL: read attribute value differs" << endl;
- }
- memset(attrvalue, 0, sizeof (attrvalue));
- if (os->getattr (oid, "fred", attrvalue, sizeof(attrvalue)) < 0)
- {
- cout << "FAIL: getattr fred" << endl;
- }
- else if (strncmp ("value", attrvalue, strlen("value")) != 0)
- {
- cout << "FAIL: read attribute value differs" << endl;
- }
- memset(attrvalue, 0, sizeof (attrvalue));
- if (os->getattr (oid, "beta", attrvalue, sizeof(attrvalue)) < 0)
- {
- cout << "FAIL: getattr beta" << endl;
- }
- else if (strncmp ("value", attrvalue, strlen("value")) != 0)
- {
- cout << "FAIL: read attribute value differs" << endl;
- }
- memset(attrvalue, 0, sizeof (attrvalue));
- if (os->getattr (oid, "gamma", attrvalue, sizeof(attrvalue)) < 0)
- {
- cout << "FAIL: getattr gamma" << endl;
- }
- else if (strncmp ("value", attrvalue, strlen("value")) != 0)
- {
- cout << "FAIL: read attribute value differs" << endl;
- }
-
- if (os->setattr (oid, "alpha", "different", strlen("different")) != 0)
- cout << "FAIL: setattr overwrite" << endl;
- memset(attrvalue, 0, sizeof (attrvalue));
- if (os->getattr (oid, "alpha", attrvalue, sizeof(attrvalue)) < 0)
- {
- cout << "FAIL: getattr alpha" << endl;
- }
- else if (strncmp ("different", attrvalue, strlen("different")) != 0)
- {
- cout << "FAIL: read attribute value differs" << endl;
- }
-
- if (os->rmattr (oid, "alpha") != 0)
- {
- cout << "FAIL: rmattr alpha" << endl;
- }
- if (os->rmattr (oid, "fred") != 0)
- {
- cout << "FAIL: rmattr fred" << endl;
- }
- if (os->rmattr (oid, "beta") != 0)
- {
- cout << "FAIL: rmattr beta" << endl;
- }
- if (os->rmattr (oid, "gamma") != 0)
- {
- cout << "FAIL: rmattr gamma" << endl;
- }
-
- coll_t cid = 0xCAFEBABE;
- if (os->create_collection (cid) != 0)
- {
- cout << "FAIL: create_collection" << endl;
- }
- if (os->create_collection (cid + 10) != 0)
- {
- cout << "FAIL: create_collection" << endl;
- }
- if (os->create_collection (cid + 5) != 0)
- {
- cout << "FAIL: create_collection" << endl;
- }
- if (os->create_collection (42) != 0)
- {
- cout << "FAIL: create_collection" << endl;
- }
-
- if (os->collection_add (cid, oid) != 0)
- {
- cout << "FAIL: collection_add" << endl;
- }
-
- list<coll_t> ls;
- if (os->list_collections (ls) < 0)
- {
- cout << "FAIL: list_collections" << endl;
- }
- cout << "collections: ";
- for (list<coll_t>::iterator it = ls.begin(); it != ls.end(); it++)
- {
- cout << *it << ", ";
- }
- cout << endl;
-
- if (os->destroy_collection (0xCAFEBABE + 10) != 0)
- {
- cout << "FAIL: destroy_collection" << endl;
- }
-
- if (os->destroy_collection (0xCAFEBADE + 10) == 0)
- {
- cout << "FAIL: destroy_collection" << endl;
- }
-
- object_t oid2 (12345, 12345);
- for (int i = 0; i < 8; i++)
- {
- oid2.rev++;
- if (os->collection_add (cid, oid2) != 0)
- {
- cout << "FAIL: collection_add" << endl;
- }
- }
- for (int i = 0; i < 8; i++)
- {
- if (os->collection_remove (cid, oid2) != 0)
- {
- cout << "FAIL: collection_remove" << endl;
- }
- oid2.rev--;
- }
-
- if (os->collection_setattr (cid, "alpha", "value", 5) != 0)
- cout << "FAIL: collection_setattr" << endl;
- if (os->collection_setattr (cid, "beta", "value", 5) != 0)
- cout << "FAIL: collection_setattr" << endl;
- if (os->collection_setattr (cid, "gamma", "value", 5) != 0)
- cout << "FAIL: collection_setattr" << endl;
- if (os->collection_setattr (cid, "fred", "value", 5) != 0)
- cout << "FAIL: collection_setattr" << endl;
-
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "alpha", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "beta", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "gamma", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "fred", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
-
- if (os->collection_setattr (cid, "alpha", "eulavvalue", 10) != 0)
- cout << "FAIL: collection setattr overwrite" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "alpha", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "eulavvalue", 10) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "beta", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "gamma", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
- memset (attrvalue, 0, sizeof (attrvalue));
- if (os->collection_getattr (cid, "fred", attrvalue, sizeof (attrvalue)) < 0)
- cout << "FAIL: collection_getattr" << endl;
- else if (strncmp (attrvalue, "value", 5) != 0)
- cout << "FAIL: collection attribute value different" << endl;
-
- if (os->collection_rmattr (cid, "alpha") != 0)
- cout << "FAIL: collection_rmattr" << endl;
- if (os->collection_rmattr (cid, "fred") != 0)
- cout << "FAIL: collection_rmattr" << endl;
- if (os->collection_rmattr (cid, "beta") != 0)
- cout << "FAIL: collection_rmattr" << endl;
- if (os->collection_rmattr (cid, "gamma") != 0)
- cout << "FAIL: collection_rmattr" << endl;
-
- if (os->collection_rmattr (cid, "alpha") == 0)
- cout << "FAIL: collection_rmattr (nonexistent)" << endl;
-
- // Truncate the object.
- if (os->truncate (oid, 512, NULL) != 0)
- {
- cout << "FAIL: truncate" << endl;
- }
-
- // Expand the object.
- if (os->truncate (oid, 1200, NULL) != 0)
- {
- cout << "FAIL: expand" << endl;
- }
-
- // Delete the object.
- if (os->remove (oid) != 0)
- {
- cout << "FAIL: could not remove object" << endl;
- }
-
- // Shouldn't be there
- if (os->exists (oid))
- {
- cout << "FAIL: should not be there" << endl;
- }
-
- os->sync();
- exit (0);
-}
+++ /dev/null
-
-
-#include "../crush/BinaryTree.h"
-using namespace crush;
-
-#include <iostream>
-#include <vector>
-using namespace std;
-
-int main()
-{
- BinaryTree t;
-
- vector<int> nodes;
-
- for (int i=0; i<30; i++) {
- cout << "adding " << i << endl;
- int n = t.add_node(1);
- nodes.push_back(n);
- //cout << t << endl;
- }
- cout << t << endl;
-
- for (int k=0; k<10000; k++) {
- if (rand() % 2) {
- cout << "adding" << endl;
- nodes.push_back( t.add_node(1) );
- } else {
- if (!nodes.empty()) {
- //for (int i=0; i<nodes.size(); i++) {
- int p = rand() % nodes.size();
- int n = nodes[p];
- assert (t.exists(n));
- cout << "removing " << n << endl;
- t.remove_node(n);
-
- for (int j=p; j<nodes.size(); j++)
- nodes[j] = nodes[j+1];
- nodes.pop_back();
- }
- }
- cout << t << endl;
- }
-
-
-}
+++ /dev/null
-
-#include <iostream>
-using namespace std;
-
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <iostream>
-#include <errno.h>
-#include <dirent.h>
-#include <sys/xattr.h>
-
-int main(int argc, char**argv)
-{
- int a = 1;
- int b = 2;
-
- mknod("test", 0600, 0);
-
- cout << "setxattr " << setxattr("test", "asdf", &a, sizeof(a), 0) << endl;
- cout << "errno " << errno << " " << strerror(errno) << endl;
- cout << "getxattr " << getxattr("test", "asdf", &b, sizeof(b)) << endl;
- cout << "errno " << errno << " " << strerror(errno) << endl;
- cout << "a is " << a << " and b is " << b << endl;
- return 0;
-}