From 20946a3791fe78fac201d93b2ac0c764a8006890 Mon Sep 17 00:00:00 2001 From: sage Date: Wed, 14 Dec 2005 21:35:29 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@524 29311d96-e01e-0410-9327-a35deaab8ce9 --- ceph/ebofs/BlockDevice.cc | 12 ++++++------ ceph/ebofs/BlockDevice.h | 22 +++++++++++++++------- ceph/ebofs/BufferCache.h | 28 ++++++++++------------------ ceph/ebofs/Ebofs.cc | 31 +++++++++++++++++-------------- ceph/ebofs/Ebofs.h | 4 ++-- ceph/ebofs/nodes.h | 8 ++++---- 6 files changed, 54 insertions(+), 51 deletions(-) diff --git a/ceph/ebofs/BlockDevice.cc b/ceph/ebofs/BlockDevice.cc index c0b3a209a634a..8bfea6a2424f8 100644 --- a/ceph/ebofs/BlockDevice.cc +++ b/ceph/ebofs/BlockDevice.cc @@ -195,9 +195,9 @@ int BlockDevice::complete_thread_entry() if (bio->cond) { bio->cond->Signal(); } - else if (bio->context) { - bio->context->finish((int)bio); // FIXME do i need to pass this?? - delete bio->context; + else if (bio->cb) { + bio->cb->finish((ioh_t)bio, bio->rval); + delete bio->cb; delete bio; } } @@ -405,9 +405,9 @@ int BlockDevice::cancel_io(ioh_t ioh) lock.Unlock(); // FIXME? - if (r == 0 && pbio->context) { - //pbio->context->finish(0); - delete pbio->context; + if (r == 0 && pbio->cb) { + //pbio->cb->finish(ioh, 0); + delete pbio->cb; delete pbio; } diff --git a/ceph/ebofs/BlockDevice.h b/ceph/ebofs/BlockDevice.h index 2bb80df8e2060..87be8860338f3 100644 --- a/ceph/ebofs/BlockDevice.h +++ b/ceph/ebofs/BlockDevice.h @@ -10,10 +10,18 @@ #include "types.h" -typedef void *ioh_t; +typedef void *ioh_t; // opaque handle to an io request. (in actuality, a biovec*) class BlockDevice { + public: + // callback type for io completion notification + class callback { + public: + virtual void finish(ioh_t ioh, int rval) = 0; + }; + + private: char *dev; int fd; block_t num_blocks; @@ -29,14 +37,14 @@ class BlockDevice { char type; block_t start, length; bufferlist bl; - Context *context; + callback *cb; Cond *cond; int rval; - biovec(char t, block_t s, block_t l, bufferlist& b, Context *c) : - type(t), start(s), length(l), bl(b), context(c), cond(0), rval(0) {} + biovec(char t, block_t s, block_t l, bufferlist& b, callback *c) : + type(t), start(s), length(l), bl(b), cb(c), cond(0), rval(0) {} biovec(char t, block_t s, block_t l, bufferlist& b, Cond *c) : - type(t), start(s), length(l), bl(b), context(0), cond(c), rval(0) {} + type(t), start(s), length(l), bl(b), cb(0), cond(c), rval(0) {} }; multimap io_queue; @@ -133,14 +141,14 @@ class BlockDevice { } // ** non-blocking interface ** - ioh_t read(block_t bno, unsigned num, bufferlist& bl, Context *fin) { + ioh_t read(block_t bno, unsigned num, bufferlist& bl, callback *fin) { biovec *pbio = new biovec(biovec::IO_READ, bno, num, bl, fin); lock.Lock(); _submit_io(pbio); lock.Unlock(); return (ioh_t)pbio; } - ioh_t write(block_t bno, unsigned num, bufferlist& bl, Context *fin) { + ioh_t write(block_t bno, unsigned num, bufferlist& bl, callback *fin) { biovec *pbio = new biovec(biovec::IO_WRITE, bno, num, bl, fin); lock.Lock(); _submit_io(pbio); diff --git a/ceph/ebofs/BufferCache.h b/ceph/ebofs/BufferCache.h index b5afccbf5b217..23fda4b8ac407 100644 --- a/ceph/ebofs/BufferCache.h +++ b/ceph/ebofs/BufferCache.h @@ -331,20 +331,18 @@ class ObjectCache { void tear_down(); }; -class C_OC_RxFinish : public Context { +class C_OC_RxFinish : public BlockDevice::callback { ObjectCache *oc; block_t start, length; public: C_OC_RxFinish(ObjectCache *o, block_t s, block_t l) : oc(o), start(s), length(l) {} - void finish(int r) { - ioh_t ioh = (ioh_t)r; - if (ioh) - oc->rx_finish(ioh, start, length); - } + void finish(ioh_t ioh, int r) { + oc->rx_finish(ioh, start, length); + } }; -class C_OC_TxFinish : public Context { +class C_OC_TxFinish : public BlockDevice::callback { ObjectCache *oc; block_t start, length; version_t version; @@ -352,25 +350,19 @@ class C_OC_TxFinish : public Context { public: C_OC_TxFinish(ObjectCache *o, block_t s, block_t l, version_t v, version_t e) : oc(o), start(s), length(l), version(v), epoch(e) {} - void finish(int r) { - ioh_t ioh = (ioh_t)r; - if (ioh) { - oc->tx_finish(ioh, start, length, version, epoch); - } + void finish(ioh_t ioh, int r) { + oc->tx_finish(ioh, start, length, version, epoch); } }; -class C_OC_PartialTxFinish : public Context { +class C_OC_PartialTxFinish : public BlockDevice::callback { ObjectCache *oc; version_t epoch; public: C_OC_PartialTxFinish(ObjectCache *o, version_t e) : oc(o), epoch(e) {} - void finish(int r) { - ioh_t ioh = (ioh_t)r; - if (ioh) { - oc->partial_tx_finish(epoch); - } + void finish(ioh_t ioh, int r) { + oc->partial_tx_finish(epoch); } }; diff --git a/ceph/ebofs/Ebofs.cc b/ceph/ebofs/Ebofs.cc index d7df33de42d03..5bcfb9c2d66cf 100644 --- a/ceph/ebofs/Ebofs.cc +++ b/ceph/ebofs/Ebofs.cc @@ -366,7 +366,16 @@ Onode* Ebofs::get_onode(object_t oid) } -void Ebofs::write_onode(Onode *on, Context *c) +class C_E_InodeFlush : public BlockDevice::callback { + Ebofs *ebofs; +public: + C_E_InodeFlush(Ebofs *e) : ebofs(e) {} + void finish(ioh_t ioh, int r) { + ebofs->flush_inode_finish(); + } +}; + +void Ebofs::write_onode(Onode *on) { // buffer int bytes = sizeof(ebofs_onode) + on->get_attr_bytes() + on->get_extent_bytes(); @@ -418,7 +427,8 @@ void Ebofs::write_onode(Onode *on, Context *c) } // write - dev.write( on->onode_loc.start, on->onode_loc.length, bl, c ); + dev.write( on->onode_loc.start, on->onode_loc.length, bl, + new C_E_InodeFlush(this) ); } void Ebofs::remove_onode(Onode *on) @@ -552,7 +562,7 @@ Cnode* Ebofs::get_cnode(object_t cid) return cn; } -void Ebofs::write_cnode(Cnode *cn, Context *c) +void Ebofs::write_cnode(Cnode *cn) { // allocate buffer int bytes = sizeof(ebofs_cnode) + cn->get_attr_bytes(); @@ -592,7 +602,8 @@ void Ebofs::write_cnode(Cnode *cn, Context *c) } // write - dev.write( cn->cnode_loc.start, cn->cnode_loc.length, bl, c ); + dev.write( cn->cnode_loc.start, cn->cnode_loc.length, bl, + new C_E_InodeFlush(this) ); } void Ebofs::remove_cnode(Cnode *cn) @@ -626,14 +637,6 @@ void Ebofs::dirty_cnode(Cnode *cn) -class C_E_InodeFlush : public Context { - Ebofs *ebofs; -public: - C_E_InodeFlush(Ebofs *e) : ebofs(e) {} - void finish(int r) { - ebofs->flush_inode_finish(); - } -}; void Ebofs::flush_inode_finish() { @@ -656,7 +659,7 @@ void Ebofs::commit_inodes_start() i++) { Onode *on = *i; inodes_flushing++; - write_onode(on, new C_E_InodeFlush(this)); + write_onode(on); on->mark_clean(); on->uncommitted.clear(); // commit allocated blocks } @@ -668,7 +671,7 @@ void Ebofs::commit_inodes_start() i++) { Cnode *cn = *i; inodes_flushing++; - write_cnode(cn, new C_E_InodeFlush(this)); + write_cnode(cn); cn->mark_clean(); } dirty_cnodes.clear(); diff --git a/ceph/ebofs/Ebofs.h b/ceph/ebofs/Ebofs.h index 4ac9d1d1ebb47..0749067f8cba4 100644 --- a/ceph/ebofs/Ebofs.h +++ b/ceph/ebofs/Ebofs.h @@ -91,7 +91,7 @@ class Ebofs : public ObjectStore { Onode* new_onode(object_t oid); // make new onode. ref++. Onode* get_onode(object_t oid); // get cached onode, or read from disk. ref++. - void write_onode(Onode *on, Context *c); + void write_onode(Onode *on); void remove_onode(Onode *on); void put_onode(Onode* o); // put it back down. ref--. void dirty_onode(Onode* o); @@ -105,7 +105,7 @@ class Ebofs : public ObjectStore { Cnode* new_cnode(coll_t cid); Cnode* get_cnode(coll_t cid); - void write_cnode(Cnode *cn, Context *c); + void write_cnode(Cnode *cn); void remove_cnode(Cnode *cn); void put_cnode(Cnode *cn); void dirty_cnode(Cnode *cn); diff --git a/ceph/ebofs/nodes.h b/ceph/ebofs/nodes.h index 6064f9c7e33a2..d81677ba373cf 100644 --- a/ceph/ebofs/nodes.h +++ b/ceph/ebofs/nodes.h @@ -254,12 +254,12 @@ class NodePool { // **** non-blocking i/o **** private: - class C_NP_FlushUsemap : public Context { + class C_NP_FlushUsemap : public BlockDevice::callback { NodePool *pool; public: C_NP_FlushUsemap(NodePool *p) : pool(p) {} - void finish(int r) { + void finish(ioh_t ioh, int r) { pool->flushed_usemap(); } }; @@ -327,13 +327,13 @@ class NodePool { return (flushing > 0); } - class C_NP_FlushNode : public Context { + class C_NP_FlushNode : public BlockDevice::callback { NodePool *pool; nodeid_t nid; public: C_NP_FlushNode(NodePool *p, nodeid_t n) : pool(p), nid(n) {} - void finish(int r) { + void finish(ioh_t ioh, int r) { pool->flushed_node(nid); } }; -- 2.39.5