From: Sage Weil Date: Wed, 6 Aug 2008 17:34:53 +0000 (-0700) Subject: os: add collection_getattr that takes a bufferlist X-Git-Tag: v0.4~318^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c6fb7053f83abd6d8e1da82975e9458c80d59d5a;p=ceph.git os: add collection_getattr that takes a bufferlist --- diff --git a/src/ebofs/Ebofs.cc b/src/ebofs/Ebofs.cc index dde78e12755..f72ab8b3f8c 100644 --- a/src/ebofs/Ebofs.cc +++ b/src/ebofs/Ebofs.cc @@ -3698,6 +3698,31 @@ int Ebofs::collection_getattr(coll_t cid, const char *name, void *value, size_t return r; } +int Ebofs::collection_getattr(coll_t cid, const char *name, bufferlist& bl) +{ + ebofs_lock.Lock(); + dout(10) << "collection_setattr " << hex << cid << dec << " '" << name << dendl; + + Cnode *cn = get_cnode(cid); + if (!cn) { + ebofs_lock.Unlock(); + return -ENOENT; + } + + string n(name); + int r; + if (cn->attr.count(n) == 0) { + r = -1; + } else { + bl.push_back(cn->attr[n]); + r = bl.length(); + } + + put_cnode(cn); + ebofs_lock.Unlock(); + return r; +} + int Ebofs::collection_getattrs(coll_t cid, map &aset) { ebofs_lock.Lock(); diff --git a/src/ebofs/Ebofs.h b/src/ebofs/Ebofs.h index 456c2574ff6..4e2d929cf7d 100644 --- a/src/ebofs/Ebofs.h +++ b/src/ebofs/Ebofs.h @@ -293,6 +293,7 @@ protected: int collection_setattr(coll_t cid, const char *name, const void *value, size_t size, Context *onsafe); int collection_setattrs(coll_t cid, map &aset); int collection_getattr(coll_t cid, const char *name, void *value, size_t size); + int collection_getattr(coll_t cid, const char *name, bufferlist& bl); int collection_getattrs(coll_t cid, map &aset); int collection_rmattr(coll_t cid, const char *name, Context *onsafe); int collection_listattr(coll_t oid, vector& attrs); diff --git a/src/os/Fake.h b/src/os/Fake.h index b0b68d5c9de..cd96c6596ad 100644 --- a/src/os/Fake.h +++ b/src/os/Fake.h @@ -132,6 +132,14 @@ class FakeAttrs { } return -1; } + int getattr(const char *name, bufferlist& bl) { + string n = name; + if (attrs.count(n)) { + bl.append(attrs[n]); + return bl.length(); + } + return -1; + } int getattrs(map& aset) { aset = attrs; return 0; @@ -250,6 +258,12 @@ class FakeAttrs { faker_lock.Unlock(); return r; } + int collection_getattr(coll_t c, const char *name, bufferlist& bl) { + faker_lock.Lock(); + int r = fakecattrs[c].getattr(name, bl); + faker_lock.Unlock(); + return r; + } int collection_listattr(coll_t c, char *attrs, size_t size) { faker_lock.Lock(); int r = fakecattrs[c].listattr(attrs,size); diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 5241479e9d4..dc888ca1331 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -1317,6 +1317,23 @@ int FileStore::collection_getattr(coll_t c, const char *name, return r < 0 ? -errno:r; } +int FileStore::collection_getattr(coll_t c, const char *name, bufferlist& bl) +{ + int r; + if (fake_attrs) + r = attrs.collection_getattr(c, name, bl); + else { + char fn[200]; + get_cdir(c, fn); + r = do_getxattr(fn, name, NULL, 0); + if (r > 0) { + bl.push_back(buffer::create(r)); + r = do_getxattr(fn, name, bl.c_str(), r); + } + } + return r < 0 ? -errno:r; +} + int FileStore::collection_setattrs(coll_t cid, map& aset) { int r; diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 4626d61e57c..5eace6bfa4e 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -120,6 +120,7 @@ class FileStore : public JournalingObjectStore { int collection_setattr(coll_t c, const char *name, const void *value, size_t size, Context *onsafe=0); int collection_rmattr(coll_t c, const char *name, Context *onsafe=0); int collection_getattr(coll_t c, const char *name, void *value, size_t size); + int collection_getattr(coll_t c, const char *name, bufferlist& bl); //int collection_listattr(coll_t c, char *attrs, size_t size); int collection_getattrs(coll_t cid, map &aset); int collection_setattrs(coll_t cid, map &aset); diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index f6a7e2a4fbd..6746fab4049 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -197,14 +197,17 @@ public: blen++; } void setattr(coll_t cid, pobject_t oid, const char* name, const void* val, int len) { + bufferlist bl; + bl.append((char*)val, len); + setattr(cid, oid, name, bl); + } + void setattr(coll_t cid, pobject_t oid, const char* name, bufferlist& val) { int op = OP_SETATTR; ops.push_back(op); cids.push_back(cid); oids.push_back(oid); attrnames.push_back(name); - bufferlist bl; - bl.append((char*)val,len); - bls.push_back(bl); + bls.push_back(val); len++; blen++; } @@ -267,16 +270,20 @@ public: blen++; } void collection_setattr(coll_t cid, const char* name, const void* val, int len) { + bufferlist bl; + bl.append((char*)val, len); + collection_setattr(cid, name, bl); + } + void collection_setattr(coll_t cid, const char* name, bufferlist& val) { int op = OP_COLL_SETATTR; ops.push_back(op); cids.push_back(cid); attrnames.push_back(name); - bufferlist bl; - bl.append((char*)val, len); - bls.push_back(bl); + bls.push_back(val); len++; blen++; } + void collection_rmattr(coll_t cid, const char* name) { int op = OP_COLL_RMATTR; ops.push_back(op); @@ -598,6 +605,7 @@ public: Context *onsafe=0) = 0; virtual int collection_getattr(coll_t cid, const char *name, void *value, size_t size) = 0; + virtual int collection_getattr(coll_t cid, const char *name, bufferlist& bl) = 0; virtual int collection_getattrs(coll_t cid, map &aset) = 0; virtual int collection_setattrs(coll_t cid, map &aset) = 0;