From 28efa364d061695a852c4639713043110d84257e Mon Sep 17 00:00:00 2001 From: sage Date: Sat, 3 Dec 2005 19:54:56 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@514 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/Makefile | 9 +++++++++ ceph/common/Thread.h | 36 ++++++++++++++++++++++++++++++++++++ ceph/config.cc | 2 +- ceph/ebofs/BlockDevice.cc | 13 +++++++------ ceph/ebofs/Ebofs.cc | 13 ++++++++----- ceph/ebofs/Ebofs.h | 3 ++- ceph/ebofs/Onode.h | 17 +++++++++++++++++ ceph/ebofs/mkfs.ebofs.cc | 2 ++ ceph/include/buffer.h | 4 +++- ceph/include/bufferlist.h | 19 +++++++++++++++++-- 10 files changed, 102 insertions(+), 16 deletions(-) create mode 100644 ceph/common/Thread.h diff --git a/ceph/Makefile b/ceph/Makefile index 7d447503144..55dfa43f64e 100644 --- a/ceph/Makefile +++ b/ceph/Makefile @@ -21,6 +21,11 @@ MPILIBS = ${LIBS} #MPICFLAGS = ${CFLAGS} -I/usr/lib/mpi/include -L/usr/lib/mpi/mpi_gnu/lib #MPILIBS = ${LIBS} -lelan -lmpi +EBOFS_OBJS= \ + ebofs/BlockDevice.o\ + ebofs/BufferCache.o\ + ebofs/Ebofs.o\ + ebofs/Allocator.o MDS_OBJS= \ mds/MDS.o\ @@ -123,6 +128,10 @@ tcpsyn: tcpsyn.cc mds/allmds.o client/Client.o client/Buffercache.o osd/OSD.o ${ obfstest: tcpsyn.cc mds/allmds.o client/Client.o client/Buffercache.o osd/OSD.cc osd/OBFSStore.o msg/TCPMessenger.cc ${COMMON_OBJS} $(SYN_OBJS) ${MPICC} -DUSE_OBFS ${MPICFLAGS} ${MPILIBS} $^ -o $@ ../uofs/uofs.a +# ebofs +mkfs.ebofs: ebofs/mkfs.ebofs.cc config.cc common/Clock.o ${EBOFS_OBJS} + ${CC} -pg ${CFLAGS} ${LIBS} $^ -o $@ + testmpi: test/testmpi.cc msg/MPIMessenger.cc config.o common/Timer.o common/clock.o msg/Messenger.o msg/Dispatcher.o msg/error.o diff --git a/ceph/common/Thread.h b/ceph/common/Thread.h new file mode 100644 index 00000000000..efd9056c838 --- /dev/null +++ b/ceph/common/Thread.h @@ -0,0 +1,36 @@ +#ifndef __THREAD_H +#define __THREAD_H + +#include + +class Thread { + private: + pthread_t thread_id; + + public: + Thread() : thread_id(0) {} + + pthread_t &get_thread_id() { return thread_id; } + bool is_started() { return thread_id != 0; } + + virtual void *entry() = 0; + + private: + static void *_entry_func(void *arg) { + return ((Thread*)arg)->entry(); + } + + public: + int create() { + return pthread_create( &thread_id, NULL, _entry_func, (void*)this ); + } + + int join(void **prval = 0) { + if (thread_id == 0) return -1; // never started. + int status = pthread_join(thread_id, prval); + if (status == 0) thread_id = 0; + return status; + } +}; + +#endif diff --git a/ceph/config.cc b/ceph/config.cc index 8fef763f76c..ea7c8ed3550 100644 --- a/ceph/config.cc +++ b/ceph/config.cc @@ -50,7 +50,7 @@ md_config_t g_conf = { fake_osdmap_expand: 0, fake_osd_sync: true, - debug: 1, + debug: 100, debug_mds_balancer: 1, debug_mds_log: 1, debug_buffer: 0, diff --git a/ceph/ebofs/BlockDevice.cc b/ceph/ebofs/BlockDevice.cc index 31a707d9310..1743170c883 100644 --- a/ceph/ebofs/BlockDevice.cc +++ b/ceph/ebofs/BlockDevice.cc @@ -88,16 +88,17 @@ void BlockDevice::do_io(biovec *bio) r = _read(bio->start, bio->length, bio->bl); } else assert(0); - dout(20) << "do_io finish " << (void*)bio << endl; - if (bio->context) { - bio->context->finish(r); - delete bio->context; - delete bio; - } + dout(20) << "do_io finish " << (void*)bio << " " << bio->start << "+" << bio->length << " " << (void*)bio->cond << " " << (void*)bio->context << endl; + if (bio->cond) { bio->cond->Signal(); bio->rval = r; } + else if (bio->context) { + bio->context->finish(r); + delete bio->context; + delete bio; + } } diff --git a/ceph/ebofs/Ebofs.cc b/ceph/ebofs/Ebofs.cc index d2070f9ec92..f0d1a1808a7 100644 --- a/ceph/ebofs/Ebofs.cc +++ b/ceph/ebofs/Ebofs.cc @@ -129,6 +129,7 @@ int Ebofs::write_super() dout(1) << "write_super v" << super_version << " to b" << bno << endl; // fill in super + memset(&sb, 0, sizeof(sb)); sb.s_magic = EBOFS_MAGIC; sb.version = super_version; sb.num_blocks = dev.get_num_blocks(); @@ -167,7 +168,6 @@ int Ebofs::write_super() Onode* Ebofs::new_onode(object_t oid) { Onode* on = new Onode(oid); - on->oc = new ObjectCache(oid, &bc); assert(onode_map.count(oid) == 0); onode_map[oid] = on; @@ -204,7 +204,6 @@ Onode* Ebofs::get_onode(object_t oid) // parse data block Onode *on = new Onode(oid); - on->oc = new ObjectCache(oid, &bc); struct ebofs_onode *eo = (struct ebofs_onode*)bl.c_str(); on->onode_loc = eo->onode_loc; @@ -228,6 +227,7 @@ Onode* Ebofs::get_onode(object_t oid) p += sizeof(Extent); } + on->get(); return on; } @@ -323,6 +323,8 @@ void Ebofs::trim_onode_cache() onode_map.erase(on->object_id); delete on; } + + dout(10) << "trim_onode_cache " << onode_lru.lru_get_size() << " left" << endl; } @@ -344,6 +346,7 @@ void Ebofs::trim_buffer_cache() Onode *on = get_onode( bh->oc->get_object_id() ); bh_write(on, bh); + put_onode(on); } // trim bufferheads @@ -361,8 +364,7 @@ void Ebofs::trim_buffer_cache() if (oc->is_empty()) { Onode *on = get_onode( oc->get_object_id() ); dout(10) << "trim_buffer_cache closing oc on " << *on << endl; - delete oc; - on->oc = 0; + on->close_oc(); put_onode(on); } } @@ -401,6 +403,7 @@ void Ebofs::flush_all() if (bh->ioh) continue; Onode *on = get_onode(bh->oc->get_object_id()); bh_write(on, bh); + put_onode(on); } dout(1) << "flush_all submitted" << endl; @@ -490,7 +493,7 @@ void Ebofs::bh_write(Onode *on, BufferHead *bh) void Ebofs::apply_write(Onode *on, size_t len, off_t off, bufferlist& bl) { - ObjectCache *oc = on->oc; + ObjectCache *oc = on->get_oc(&bc); // map into blocks off_t opos = off; // byte pos in object diff --git a/ceph/ebofs/Ebofs.h b/ceph/ebofs/Ebofs.h index f160ecf696e..7231baaaf83 100644 --- a/ceph/ebofs/Ebofs.h +++ b/ceph/ebofs/Ebofs.h @@ -61,8 +61,9 @@ class Ebofs { void remove_onode(Onode *on); void put_onode(Onode* o); // put it back down. ref--. + public: void trim_onode_cache(); - + protected: // ** buffer cache ** BufferCache bc; diff --git a/ceph/ebofs/Onode.h b/ceph/ebofs/Onode.h index 46aacba30e6..64d14981c5e 100644 --- a/ceph/ebofs/Onode.h +++ b/ceph/ebofs/Onode.h @@ -69,11 +69,28 @@ public: void get() { if (ref == 0) lru_pin(); ref++; + cout << "onode.get " << ref << endl; } void put() { ref--; if (ref == 0) lru_unpin(); + cout << "onode.put " << ref << endl; } + + ObjectCache *get_oc(BufferCache *bc) { + if (!oc) { + oc = new ObjectCache(object_id, bc); + get(); + } + return oc; + } + void close_oc() { + assert(oc); + delete oc; + oc = 0; + put(); + } + // allocation int map_extents(block_t start, block_t len, vector& ls) { diff --git a/ceph/ebofs/mkfs.ebofs.cc b/ceph/ebofs/mkfs.ebofs.cc index 0c1cb45be6d..46f88014195 100644 --- a/ceph/ebofs/mkfs.ebofs.cc +++ b/ceph/ebofs/mkfs.ebofs.cc @@ -35,8 +35,10 @@ int main(int argc, char **argv) fs.flush_all(); fs.trim_buffer_cache(); + fs.trim_onode_cache(); fs.umount(); + dev.close(); } diff --git a/ceph/include/buffer.h b/ceph/include/buffer.h index 91293b57855..e198800fc05 100644 --- a/ceph/include/buffer.h +++ b/ceph/include/buffer.h @@ -150,6 +150,8 @@ class buffer { return _dataptr; } + bool has_free_func() { return free_func != 0; } + // accessor unsigned alloc_length() { return _alloc_len; @@ -259,7 +261,7 @@ class bufferptr { // accessors for my subset char *c_str() { - return _buffer->_dataptr + _off; + return _buffer->c_str() + _off; } unsigned length() { return _len; diff --git a/ceph/include/bufferlist.h b/ceph/include/bufferlist.h index 60488f78391..5b87a267289 100644 --- a/ceph/include/bufferlist.h +++ b/ceph/include/bufferlist.h @@ -32,8 +32,8 @@ class bufferlist { bufferlist() : _len(0) { bdbout(1) << "bufferlist.cons " << this << endl; } - bufferlist(bufferlist& bl) : _len(0) { - assert(0); // o(n) and stupid + bufferlist(const bufferlist& bl) : _len(0) { + //assert(0); // o(n) and stupid bdbout(1) << "bufferlist.cons " << this << endl; _buffers = bl._buffers; _len = bl._len; @@ -44,6 +44,7 @@ class bufferlist { bufferlist& operator=(bufferlist& bl) { //assert(0); // actually, this should be fine, just slow (O(n)) and stupid. + bdbout(1) << "bufferlist.= " << this << endl; _buffers = bl._buffers; _len = bl._len; return *this; @@ -207,6 +208,19 @@ class bufferlist { assert(curbuf != _buffers.end()); } } + void copy_in(unsigned off, unsigned len, bufferlist& bl) { + unsigned left = len; + for (list::iterator i = bl._buffers.begin(); + i != bl._buffers.end(); + i++) { + unsigned l = (*i).length(); + if (l > left) l = left; + copy_in(off, l, (*i).c_str()); + left -= l; + if (left == 0) break; + off += l; + } + } void append(const char *data, unsigned len) { @@ -265,6 +279,7 @@ class bufferlist { for (list::iterator it = _buffers.begin(); it != _buffers.end(); it++) { + assert((*(*it)).has_free_func() == false); // not allowed if there's a funky free_func.. -sage memcpy(newbuf.c_str() + off, (*it).c_str(), (*it).length()); off += (*it).length();