Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / tools / rbd_ggate / Watcher.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "common/debug.h"
5 #include "common/errno.h"
6 #include "Driver.h"
7 #include "Watcher.h"
8
9 #define dout_context g_ceph_context
10 #define dout_subsys ceph_subsys_rbd
11 #undef dout_prefix
12 #define dout_prefix *_dout << "rbd::ggate::Watcher: " << this \
13                            << " " << __func__ << ": "
14
15 namespace rbd {
16 namespace ggate {
17
18 Watcher::Watcher(Driver *drv, librados::IoCtx &ioctx, librbd::Image &image,
19                  size_t size)
20   : m_drv(drv), m_ioctx(ioctx), m_image(image), m_size(size) {
21 }
22
23 void Watcher::handle_notify() {
24   dout(20) << dendl;
25
26   librbd::image_info_t info;
27
28   if (m_image.stat(info, sizeof(info)) == 0) {
29     size_t new_size = info.size;
30
31     if (new_size != m_size) {
32       int r = m_drv->resize(new_size);
33       if (r < 0) {
34         derr << "resize failed: " << cpp_strerror(r) << dendl;
35         m_drv->shut_down();
36       }
37       r = m_image.invalidate_cache();
38       if (r < 0) {
39         derr << "invalidate rbd cache failed: " << cpp_strerror(r) << dendl;
40         m_drv->shut_down();
41       }
42       m_size = new_size;
43     }
44   }
45 }
46
47 } // namespace ggate
48 } // namespace rbd