summaryrefslogtreecommitdiffstats
path: root/src/tools/rbd_ggate/Watcher.cc
blob: 57b3f960e45b8c84fcd8c73ab549b1787c740f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "common/debug.h"
#include "common/errno.h"
#include "Driver.h"
#include "Watcher.h"

#define dout_context g_ceph_context
#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "rbd::ggate::Watcher: " << this \
                           << " " << __func__ << ": "

namespace rbd {
namespace ggate {

Watcher::Watcher(Driver *drv, librados::IoCtx &ioctx, librbd::Image &image,
                 size_t size)
  : m_drv(drv), m_ioctx(ioctx), m_image(image), m_size(size) {
}

void Watcher::handle_notify() {
  dout(20) << dendl;

  librbd::image_info_t info;

  if (m_image.stat(info, sizeof(info)) == 0) {
    size_t new_size = info.size;

    if (new_size != m_size) {
      int r = m_drv->resize(new_size);
      if (r < 0) {
        derr << "resize failed: " << cpp_strerror(r) << dendl;
        m_drv->shut_down();
      }
      r = m_image.invalidate_cache();
      if (r < 0) {
        derr << "invalidate rbd cache failed: " << cpp_strerror(r) << dendl;
        m_drv->shut_down();
      }
      m_size = new_size;
    }
  }
}

} // namespace ggate
} // namespace rbd