From 613b7085bb48cde1e464b7a97c00b8751e0e917f Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Wed, 27 Mar 2013 17:30:42 -0700 Subject: [PATCH] librbd: flush cache when set_snap() is called If there are writes pending, they should be sent while the image is still writeable. If the image becomes read-only, flushing the cache will just mark everything dirty again due to -EROFS. Fixes: #4525 Backport: bobtail Signed-off-by: Josh Durgin --- src/librbd/internal.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 24a3444a85946..9c4f3c24d4579 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1898,6 +1898,12 @@ reprotect_and_return_err: // ignore return value, since we may be set to a non-existent // snapshot and the user is trying to fix that ictx_check(ictx); + if (ictx->object_cacher) { + // complete pending writes before we're set to a snapshot and + // get -EROFS for writes + RWLock::WLocker l(ictx->md_lock); + ictx->flush_cache(); + } return _snap_set(ictx, snap_name); } -- 2.39.5