summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSage Weil <sage@newdream.net>2012-05-05 16:31:57 -0700
committerSage Weil <sage@newdream.net>2012-05-05 16:31:57 -0700
commit38edd3bb07cba4733d654209af4d3a63bc1f5224 (patch)
tree3c6a07b73e1ca888f9af4242d2caa91b4062e2f7
parentc8bd471b59aee862add90013c76e3d83bcbe08f0 (diff)
downloadceph-38edd3bb07cba4733d654209af4d3a63bc1f5224.tar.gz
objectcacher: user helper to get starting point in buffer map
A common pattern is to search for the first buffer intersecting or following an object offset. Use a helper for that. Signed-off-by: Sage Weil <sage@newdream.net>
-rw-r--r--src/osdc/ObjectCacher.cc68
-rw-r--r--src/osdc/ObjectCacher.h17
2 files changed, 27 insertions, 58 deletions
diff --git a/src/osdc/ObjectCacher.cc b/src/osdc/ObjectCacher.cc
index bab8fcb3db2..483d329dbbf 100644
--- a/src/osdc/ObjectCacher.cc
+++ b/src/osdc/ObjectCacher.cc
@@ -131,15 +131,7 @@ void ObjectCacher::Object::try_merge_bh(BufferHead *bh)
*/
bool ObjectCacher::Object::is_cached(loff_t cur, loff_t left)
{
- map<loff_t, BufferHead*>::iterator p = data.lower_bound(cur);
-
- if (p != data.begin() &&
- (p == data.end() || p->first > cur)) {
- p--; // might overlap!
- if (p->first + p->second->length() <= cur)
- p++; // doesn't overlap.
- }
-
+ map<loff_t, BufferHead*>::iterator p = data_lower_bound(cur);
while (left > 0) {
if (p == data.end())
return false;
@@ -179,19 +171,10 @@ int ObjectCacher::Object::map_read(OSDRead *rd,
ldout(oc->cct, 10) << "map_read " << ex_it->oid
<< " " << ex_it->offset << "~" << ex_it->length << dendl;
- map<loff_t, BufferHead*>::iterator p = data.lower_bound(ex_it->offset);
- // p->first >= start
-
loff_t cur = ex_it->offset;
loff_t left = ex_it->length;
-
- if (p != data.begin() &&
- (p == data.end() || p->first > cur)) {
- p--; // might overlap!
- if (p->first + p->second->length() <= cur)
- p++; // doesn't overlap.
- }
-
+
+ map<loff_t, BufferHead*>::iterator p = data_lower_bound(ex_it->offset);
while (left > 0) {
// at end?
if (p == data.end()) {
@@ -264,33 +247,16 @@ ObjectCacher::BufferHead *ObjectCacher::Object::map_write(OSDWrite *wr)
for (vector<ObjectExtent>::iterator ex_it = wr->extents.begin();
ex_it != wr->extents.end();
ex_it++) {
-
+
if (ex_it->oid != oid.oid) continue;
-
+
ldout(oc->cct, 10) << "map_write oex " << ex_it->oid
<< " " << ex_it->offset << "~" << ex_it->length << dendl;
-
- map<loff_t, BufferHead*>::iterator p = data.lower_bound(ex_it->offset);
- // p->first >= start
-
+
loff_t cur = ex_it->offset;
loff_t left = ex_it->length;
-
- if (p != data.begin() &&
- (p == data.end() || p->first > cur)) {
- p--; // might overlap or butt up!
-
- /*// dirty and butts up?
- if (p->first + p->second->length() == cur &&
- p->second->is_dirty()) {
- ldout(oc->cct, 10) << "map_write will append to tail of " << *p->second << dendl;
- final = p->second;
- }
- */
- if (p->first + p->second->length() <= cur)
- p++; // doesn't overlap.
- }
-
+
+ map<loff_t, BufferHead*>::iterator p = data_lower_bound(ex_it->offset);
while (left > 0) {
loff_t max = left;
@@ -412,14 +378,7 @@ void ObjectCacher::Object::discard(loff_t off, loff_t len)
{
ldout(oc->cct, 10) << "discard " << *this << " " << off << "~" << len << dendl;
- map<loff_t, BufferHead*>::iterator p = data.lower_bound(off);
- if (p != data.begin() &&
- (p == data.end() || p->first > off)) {
- p--; // might overlap!
- if (p->first + p->second->length() <= off)
- p++; // doesn't overlap.
- }
-
+ map<loff_t, BufferHead*>::iterator p = data_lower_bound(off);
while (p != data.end()) {
BufferHead *bh = p->second;
if (bh->start() >= off + len)
@@ -1430,14 +1389,7 @@ bool ObjectCacher::flush(Object *ob, loff_t offset, loff_t length)
{
bool clean = true;
ldout(cct, 10) << "flush " << *ob << " " << offset << "~" << length << dendl;
- map<loff_t,BufferHead*>::iterator p = ob->data.lower_bound(offset);
- if (p != ob->data.begin() &&
- (p == ob->data.end() || p->first > offset)) {
- p--; // might overlap!
- if (p->first + p->second->length() <= offset)
- p++; // doesn't overlap.
- }
- for ( ; p != ob->data.end(); p++) {
+ for (map<loff_t,BufferHead*>::iterator p = ob->data_lower_bound(offset); p != ob->data.end(); p++) {
BufferHead *bh = p->second;
ldout(cct, 20) << "flush " << *bh << dendl;
if (length && bh->start() > offset+length) {
diff --git a/src/osdc/ObjectCacher.h b/src/osdc/ObjectCacher.h
index db02727c6d2..83738a2ec16 100644
--- a/src/osdc/ObjectCacher.h
+++ b/src/osdc/ObjectCacher.h
@@ -224,6 +224,23 @@ class ObjectCacher {
dirty_or_tx == 0;
}
+ /**
+ * find first buffer that includes or follows an offset
+ *
+ * @param offset object byte offset
+ * @return iterator pointing to buffer, or data.end()
+ */
+ map<loff_t,BufferHead*>::iterator data_lower_bound(loff_t offset) {
+ map<loff_t,BufferHead*>::iterator p = data.lower_bound(offset);
+ if (p != data.begin() &&
+ (p == data.end() || p->first > offset)) {
+ p--; // might overlap!
+ if (p->first + p->second->length() <= offset)
+ p++; // doesn't overlap.
+ }
+ return p;
+ }
+
// bh
// add to my map
void add_bh(BufferHead *bh) {