From 7d34187b26285de10a3726059d639e9207c77937 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 27 Feb 2008 13:51:05 -0800 Subject: [PATCH] fakestore: more journaling bits, fixes --- src/osd/FakeStore.cc | 221 ++++++++++++++++++++------------ src/osd/JournalingObjectStore.h | 14 +- 2 files changed, 148 insertions(+), 87 deletions(-) diff --git a/src/osd/FakeStore.cc b/src/osd/FakeStore.cc index f9b32c1e59d17..0d33dc22d871e 100644 --- a/src/osd/FakeStore.cc +++ b/src/osd/FakeStore.cc @@ -41,7 +41,7 @@ #include "config.h" -#define dout(l) if (true || l<=g_conf.debug) *_dout << dbeginl << g_clock.now() << " fakestore(" << basedir << ") " +#define dout(l) if (l<=g_conf.debug) *_dout << dbeginl << g_clock.now() << " fakestore(" << basedir << ") " #define derr(l) if (l<=g_conf.debug) *_derr << dbeginl << g_clock.now() << " fakestore(" << basedir << ") " #include "include/buffer.h" @@ -218,6 +218,7 @@ int FakeStore::mount() #endif journal_start(); + sync_thread.create(); // all okay. return 0; @@ -230,6 +231,12 @@ int FakeStore::umount() sync(); journal_stop(); + lock.Lock(); + stop = true; + sync_cond.Signal(); + lock.Unlock(); + sync_thread.join(); + if (g_conf.fakestore_dev) { char cmd[100]; dout(0) << "umounting" << dendl; @@ -436,12 +443,14 @@ int FakeStore::setattr(pobject_t oid, const char *name, const void *value, size_t size, Context *onsafe) { - if (fake_attrs) return attrs.setattr(oid, name, value, size, onsafe); - - int r = 0; - char fn[100]; - get_oname(oid, fn); - r = ::setxattr(fn, name, value, size, 0); + int r; + if (fake_attrs) + r = attrs.setattr(oid, name, value, size, onsafe); + else { + char fn[100]; + get_oname(oid, fn); + r = ::setxattr(fn, name, value, size, 0); + } if (r >= 0) journal_setattr(oid, name, value, size, onsafe); else @@ -451,69 +460,77 @@ int FakeStore::setattr(pobject_t oid, const char *name, int FakeStore::setattrs(pobject_t oid, map& aset) { - if (fake_attrs) return attrs.setattrs(oid, aset); - - char fn[100]; - get_oname(oid, fn); - int r = 0; - for (map::iterator p = aset.begin(); - p != aset.end(); - ++p) { - r = ::setxattr(fn, p->first.c_str(), p->second.c_str(), p->second.length(), 0); - if (r < 0) { - cerr << "error setxattr " << strerror(errno) << std::endl; - break; + int r; + if (fake_attrs) + r = attrs.setattrs(oid, aset); + else { + char fn[100]; + get_oname(oid, fn); + r = 0; + for (map::iterator p = aset.begin(); + p != aset.end(); + ++p) { + r = ::setxattr(fn, p->first.c_str(), p->second.c_str(), p->second.length(), 0); + if (r < 0) { + cerr << "error setxattr " << strerror(errno) << std::endl; + break; + } } } + if (r >= 0) + journal_setattrs(oid, aset, 0); return r; } int FakeStore::getattr(pobject_t oid, const char *name, void *value, size_t size) { - if (fake_attrs) return attrs.getattr(oid, name, value, size); - int r = 0; -#ifndef __CYGWIN__ - char fn[100]; - get_oname(oid, fn); - r = ::getxattr(fn, name, value, size); -#endif + int r; + if (fake_attrs) + r = attrs.getattr(oid, name, value, size); + else { + char fn[100]; + get_oname(oid, fn); + r = ::getxattr(fn, name, value, size); + } return r; } int FakeStore::getattrs(pobject_t oid, map& aset) { - if (fake_attrs) return attrs.getattrs(oid, aset); - -#ifndef __CYGWIN__ - char fn[100]; - get_oname(oid, fn); - - char val[1000]; - char names[1000]; - int num = ::listxattr(fn, names, 1000); - - char *name = names; - for (int i=0; i= 0) journal_rmattr(oid, name, onsafe); else @@ -529,24 +546,50 @@ int FakeStore::collection_setattr(coll_t c, const char *name, void *value, size_t size, Context *onsafe) { - if (fake_attrs) return attrs.collection_setattr(c, name, value, size, onsafe); - return 0; + int r; + if (fake_attrs) + r = attrs.collection_setattr(c, name, value, size, onsafe); + else { + char fn[200]; + get_cdir(c, fn); + r = ::setxattr(fn, name, value, size, 0); + } + if (r >= 0) + journal_collection_setattr(c, name, value, size, onsafe); + else + delete onsafe; + return r; } int FakeStore::collection_rmattr(coll_t c, const char *name, Context *onsafe) { - if (fake_attrs) return attrs.collection_rmattr(c, name, onsafe); + int r; + if (fake_attrs) + r = attrs.collection_rmattr(c, name, onsafe); + else { + char fn[200]; + get_cdir(c, fn); + r = ::removexattr(fn, name); + } return 0; } int FakeStore::collection_getattr(coll_t c, const char *name, void *value, size_t size) { - if (fake_attrs) return attrs.collection_getattr(c, name, value, size); - return 0; + int r; + if (fake_attrs) + r = attrs.collection_getattr(c, name, value, size); + else { + char fn[200]; + get_cdir(c, fn); + r = ::getxattr(fn, name, value, size); + } + return r; } +/* int FakeStore::collection_setattrs(coll_t cid, map& aset) { if (fake_attrs) return attrs.collection_setattrs(cid, aset); @@ -562,31 +605,36 @@ int FakeStore::collection_setattrs(coll_t cid, map& aset) if (r < 0) break; } #endif + if (r >= 0) + journal_collection_setattrs(cid, aset, 0); return r; } +*/ int FakeStore::collection_getattrs(coll_t cid, map& aset) { - if (fake_attrs) return attrs.collection_getattrs(cid, aset); - -#ifndef __CYGWIN__ - char fn[100]; - get_cdir(cid, fn); - - char val[1000]; - char names[1000]; - int num = ::listxattr(fn, names, 1000); - - char *name = names; - for (int i=0; i= 0) + journal_create_collection(c, onsafe); + else + delete onsafe; return r; } @@ -670,8 +721,12 @@ int FakeStore::destroy_collection(coll_t c, char cmd[200]; sprintf(cmd, "test -d %s && rm -r %s", fn, fn); system(cmd); + int r = 0; // fixme - if (onsafe) sync(onsafe); + if (r >= 0) + journal_destroy_collection(c, onsafe); + else + delete onsafe; return 0; } @@ -704,7 +759,10 @@ int FakeStore::collection_add(coll_t c, pobject_t o, get_oname(o, of); int r = ::link(of, cof); - if (onsafe) sync(onsafe); + if (r >= 0) + journal_collection_add(c, o, onsafe); + else + delete onsafe; return r; } @@ -717,7 +775,10 @@ int FakeStore::collection_remove(coll_t c, pobject_t o, get_coname(c, o, cof); int r = ::unlink(cof); - if (onsafe) sync(onsafe); + if (r >= 0) + journal_collection_remove(c, o, onsafe); + else + delete onsafe; return r; } diff --git a/src/osd/JournalingObjectStore.h b/src/osd/JournalingObjectStore.h index 64b4b39561f72..a6f33b4b4b38a 100644 --- a/src/osd/JournalingObjectStore.h +++ b/src/osd/JournalingObjectStore.h @@ -157,11 +157,11 @@ protected: } else queue_commit_waiter(onsafe); } - - void journal_collection_remove(coll_t cid, pobject_t oid, Context *onsafe) { + + void journal_collection_add(coll_t cid, pobject_t oid, Context *onsafe) { if (journal) { Transaction t; - t.collection_remove(cid, oid); + t.collection_add(cid, oid); bufferlist bl; t._encode(bl); journal->submit_entry(super_epoch, bl, onsafe); @@ -169,10 +169,10 @@ protected: queue_commit_waiter(onsafe); } - void journal_collection_setattr(coll_t cid, const char *name, const void *value, size_t size, Context *onsafe) { + void journal_collection_remove(coll_t cid, pobject_t oid, Context *onsafe) { if (journal) { Transaction t; - t.collection_setattr(cid, name, value, size); + t.collection_remove(cid, oid); bufferlist bl; t._encode(bl); journal->submit_entry(super_epoch, bl, onsafe); @@ -180,10 +180,10 @@ protected: queue_commit_waiter(onsafe); } - void journal_collection_setattrs(coll_t cid, const char *name, Context *onsafe) { + void journal_collection_setattr(coll_t cid, const char *name, const void *value, size_t size, Context *onsafe) { if (journal) { Transaction t; - t.collection_rmattr(cid, name); + t.collection_setattr(cid, name, value, size); bufferlist bl; t._encode(bl); journal->submit_entry(super_epoch, bl, onsafe); -- 2.39.5