]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: added a write-full method.
authorGreg Farnum <gregf@hq.newdream.net>
Tue, 16 Jun 2009 23:39:10 +0000 (16:39 -0700)
committerGreg Farnum <gregf@hq.newdream.net>
Tue, 16 Jun 2009 23:56:47 +0000 (16:56 -0700)
Switched ./rados to use it for put.

src/include/librados.h
src/librados.cc
src/osdc/Objecter.h
src/rados.cc

index dad9c33ac52dcaf7ffb2bcb14d4aa317f22ca111..0d2dccd365b74b4ee0d6aa5a49e4dee91faab082 100644 (file)
@@ -97,6 +97,7 @@ public:
   void set_snap(rados_pool_t pool, snapid_t seq);
 
   int write(rados_pool_t pool, const object_t& oid, off_t off, bufferlist& bl, size_t len);
+  int write_full(rados_pool_t pool, const object_t& oid, bufferlist& bl);
   int read(rados_pool_t pool, const object_t& oid, off_t off, bufferlist& bl, size_t len);
   int remove(rados_pool_t pool, const object_t& oid);
 
index dcb3f84303088a63d573e03693abe1381593570f..99b59fe3800c68e6335ed6da1d59cdf557f81860 100644 (file)
@@ -100,6 +100,7 @@ public:
 
   // io
   int write(PoolCtx& pool, const object_t& oid, off_t off, bufferlist& bl, size_t len);
+  int write_full(PoolCtx& pool, const object_t& oid, bufferlist& bl);
   int read(PoolCtx& pool, const object_t& oid, off_t off, bufferlist& bl, size_t len);
   int remove(PoolCtx& pool, const object_t& oid);
 
@@ -672,6 +673,40 @@ int RadosClient::write(PoolCtx& pool, const object_t& oid, off_t off, bufferlist
   return len;
 }
 
+int RadosClient::write_full(PoolCtx& pool, const object_t& oid, bufferlist& bl)
+{
+  utime_t ut = g_clock.now();
+
+  /* can't write to a snapshot */
+  if (pool.snap_seq != CEPH_NOSNAP)
+    return -EINVAL;
+
+  Mutex mylock("RadosClient::write_full::mylock");
+  Cond cond;
+  bool done;
+  int r;
+
+  Context *onack = new C_SafeCond(&mylock, &cond, &done, &r);
+
+  dout(0) << "going to write_full" << dendl;
+
+  lock.Lock();
+  ceph_object_layout layout = objecter->osdmap->make_object_layout(oid, pool.poolid);
+  objecter->write_full(oid, layout,
+                 pool.snapc, bl, ut, 0,
+                 onack, NULL);
+  lock.Unlock();
+
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+
+  dout(0) << "did write_full" << dendl;
+
+  return r;
+}
+
 int RadosClient::aio_read(PoolCtx& pool, const object_t oid, off_t off, bufferlist *pbl, size_t len,
                          AioCompletion **pc)
 {
@@ -890,6 +925,14 @@ int Rados::write(rados_pool_t pool, const object_t& oid, off_t off, bufferlist&
   return client->write(*(RadosClient::PoolCtx *)pool, oid, off, bl, len);
 }
 
+int Rados::write_full(rados_pool_t pool, const object_t& oid, bufferlist& bl)
+{
+  if (!client)
+    return -EINVAL;
+
+  return client->write_full(*(RadosClient::PoolCtx *)pool, oid, bl);
+}
+
 int Rados::remove(rados_pool_t pool, const object_t& oid)
 {
   if (!client)
index 2d279d0e8244cb2df0e890d39f85bda4afde4cb0..bef8233ad93bd1d81ac7653e47ca15415aa89260 100644 (file)
@@ -430,7 +430,7 @@ private:
     return op_submit(o);
   }
   tid_t write_full(const object_t& oid, ceph_object_layout ol,
-                  const SnapContext& snapc, bufferlist &bl, utime_t mtime, int flags,
+                  const SnapContext& snapc, const bufferlist &bl, utime_t mtime, int flags,
                   Context *onack, Context *oncommit) {
     vector<OSDOp> ops(1);
     ops[0].op.op = CEPH_OSD_OP_WRITEFULL;
index 2819049df23282eb66db89096771dda948025e85..e3da86fbea1d3be4abe026c2b369a7f8667026a7 100644 (file)
@@ -375,7 +375,7 @@ int main(int argc, const char **argv)
       usage();
     }
     object_t oid(nargs[1]);
-    int r = rados.write(p, oid, 0, indata, indata.length());
+    int r = rados.write_full(p, oid, indata);
     if (r < 0) {
       cerr << "error writing " << oid << " to pool " << pool << ": " << strerror(-r) << std::endl;
       exit(0);