]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os: add collection_getattr that takes a bufferlist
authorSage Weil <sage@newdream.net>
Wed, 6 Aug 2008 17:34:53 +0000 (10:34 -0700)
committerSage Weil <sage@newdream.net>
Wed, 6 Aug 2008 17:36:46 +0000 (10:36 -0700)
src/ebofs/Ebofs.cc
src/ebofs/Ebofs.h
src/os/Fake.h
src/os/FileStore.cc
src/os/FileStore.h
src/os/ObjectStore.h

index dde78e12755267b1ed0db20b9f91ca7e7ac0d309..f72ab8b3f8c8d82e3d947d35ca2b536bd259c166 100644 (file)
@@ -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<string,bufferptr> &aset)
 {
   ebofs_lock.Lock();
index 456c2574ff6f21bab5229d096d128b5dea5cb753..4e2d929cf7d63e24ea78892626aa45990ff2d2bc 100644 (file)
@@ -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<string,bufferptr> &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<string,bufferptr> &aset);
   int collection_rmattr(coll_t cid, const char *name, Context *onsafe);
   int collection_listattr(coll_t oid, vector<string>& attrs);
index b0b68d5c9deca84304fdef9980d5edd6c976b52d..cd96c6596ad27264185cff002369b88d741d5e07 100644 (file)
@@ -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<string,bufferptr>& 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);
index 5241479e9d4fcceee1328d862f58832689bd4214..dc888ca13311ed624eee33d83c34c448c1bcdbd3 100644 (file)
@@ -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<string,bufferptr>& aset) 
 {
   int r;
index 4626d61e57c94a74dc6eb3b70618dc917ec909e2..5eace6bfa4e2d53f47e496746a9c06fc28bb6994 100644 (file)
@@ -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<string,bufferptr> &aset);
   int collection_setattrs(coll_t cid, map<string,bufferptr> &aset);
index f6a7e2a4fbd33d8bfb202f48a66421998eed3910..6746fab4049b34a0a56bb65146cbba0616b3918e 100644 (file)
@@ -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<string,bufferptr> &aset) = 0;
   virtual int collection_setattrs(coll_t cid, map<string,bufferptr> &aset) = 0;