]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: check for writes to snapshots
authorJosh Durgin <josh.durgin@dreamhost.com>
Thu, 5 Apr 2012 20:54:24 +0000 (13:54 -0700)
committerSage Weil <sage.weil@dreamhost.com>
Sat, 14 Apr 2012 03:46:34 +0000 (20:46 -0700)
librados does this for us normally, but caching does not check for this.
We might as well check early to avoid scheduling a bunch of aios anyway.

Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
src/librbd.cc

index 5da704e1cd5d344ec14f2ad6cc0ffef740e8be6c..a39049517664d5d967503f31026aebf55bc738f5 100644 (file)
@@ -1456,9 +1456,13 @@ ssize_t write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf)
   uint64_t start_block = get_block_num(ictx->header, off);
   uint64_t end_block = get_block_num(ictx->header, off + len - 1);
   uint64_t block_size = get_block_size(ictx->header);
+  snapid_t snap = ictx->snapid;
   ictx->lock.Unlock();
   uint64_t left = len;
 
+  if (snap != CEPH_NOSNAP)
+    return -EROFS;
+
   for (uint64_t i = start_block; i <= end_block; i++) {
     bufferlist bl;
     ictx->lock.Lock();
@@ -1632,6 +1636,7 @@ int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
   uint64_t start_block = get_block_num(ictx->header, off);
   uint64_t end_block = get_block_num(ictx->header, off + len - 1);
   uint64_t block_size = get_block_size(ictx->header);
+  snapid_t snap = ictx->snapid;
   ictx->lock.Unlock();
   uint64_t left = len;
 
@@ -1639,6 +1644,9 @@ int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
   if (r < 0)
     return r;
 
+  if (snap != CEPH_NOSNAP)
+    return -EROFS;
+
   c->get();
   for (uint64_t i = start_block; i <= end_block; i++) {
     ictx->lock.Lock();