#define LIBRBD_SUPPORTS_WATCH 0
#define LIBRBD_SUPPORTS_AIO_FLUSH 1
+#define LIBRBD_SUPPORTS_INVALIDATE 1
typedef void *rbd_snap_t;
typedef void *rbd_image_t;
*/
int rbd_aio_flush(rbd_image_t image, rbd_completion_t c);
+/**
+ * Drop any cached data for an image
+ *
+ * @param image the image to invalidate cached data for
+ * @returns 0 on success, negative error code on failure
+ */
+int rbd_invalidate_cache(rbd_image_t image);
+
#ifdef __cplusplus
}
#endif
*/
int aio_flush(RBD::AioCompletion *c);
+ /**
+ * Drop any cached data for an image
+ *
+ * @param image the image to invalidate cached data for
+ * @returns 0 on success, negative error code on failure
+ */
+ int invalidate_cache();
+
private:
friend class RBD;
return r;
}
+ int invalidate_cache(ImageCtx *ictx)
+ {
+ CephContext *cct = ictx->cct;
+ ldout(cct, 20) << "invalidate_cache " << ictx << dendl;
+
+ int r = ictx_check(ictx);
+ if (r < 0)
+ return r;
+
+ RWLock::WLocker l(ictx->md_lock);
+ return ictx->invalidate_cache();
+ }
+
int aio_write(ImageCtx *ictx, uint64_t off, size_t len, const char *buf,
AioCompletion *c)
{
int aio_flush(ImageCtx *ictx, AioCompletion *c);
int flush(ImageCtx *ictx);
int _flush(ImageCtx *ictx);
+ int invalidate_cache(ImageCtx *ictx);
ssize_t handle_sparse_read(CephContext *cct,
ceph::bufferlist data_bl,
return librbd::aio_flush(ictx, (librbd::AioCompletion *)c->pc);
}
+ int Image::invalidate_cache()
+ {
+ ImageCtx *ictx = (ImageCtx *)ctx;
+ return librbd::invalidate_cache(ictx);
+ }
+
} // namespace librbd
extern "C" void rbd_version(int *major, int *minor, int *extra)
return librbd::aio_flush(ictx, (librbd::AioCompletion *)comp->pc);
}
+extern "C" int rbd_invalidate_cache(rbd_image_t image)
+{
+ librbd::ImageCtx *ictx = (librbd::ImageCtx *)image;
+ return librbd::invalidate_cache(ictx);
+}
+
extern "C" int rbd_aio_is_complete(rbd_completion_t c)
{
librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c;
if ret < 0:
raise make_ex(ret, 'error flushing image')
+ def invalidate_cache(self):
+ """
+ Drop any cached data for the image.
+ """
+ ret = self.librbd.rbd_invalidate_cache(self.image)
+ if ret < 0:
+ raise make_ex(ret, 'error invalidating cache')
+
def stripe_unit(self):
"""
Returns the stripe unit used for the image.
self.image.close()
remove_image()
+ def test_invalidate_cache(self):
+ self.image.write('abc', 0)
+ eq('abc', self.image.read(0, 3))
+ self.image.invalidate_cache()
+ eq('abc', self.image.read(0, 3))
+
def test_stat(self):
info = self.image.stat()
check_stat(info, IMG_SIZE, IMG_ORDER)