From 579d30b6174d5c581d236afb3ee09465d238ea15 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Thu, 5 Apr 2012 13:54:24 -0700 Subject: [PATCH] librbd: check for writes to snapshots 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 --- src/librbd.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/librbd.cc b/src/librbd.cc index 5da704e1cd5d3..a39049517664d 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -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(); -- 2.39.5