summaryrefslogtreecommitdiffstats
path: root/src/librbd/journal/Utils.cc
blob: 231bcae2d3209e0cb4aaacae7bde806dbd3c72be (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "librbd/journal/Utils.h"
#include "common/dout.h"
#include "common/errno.h"
#include "librbd/journal/Types.h"

#define dout_subsys ceph_subsys_rbd
#undef dout_prefix
#define dout_prefix *_dout << "librbd::journal::"

namespace librbd {
namespace journal {
namespace util {

int C_DecodeTag::decode(bufferlist::const_iterator *it, TagData *tag_data) {
  try {
    using ceph::decode;
    decode(*tag_data, *it);
  } catch (const buffer::error &err) {
    return -EBADMSG;
  }
  return 0;
}

int C_DecodeTag::process(int r) {
  if (r < 0) {
    lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
               << "failed to allocate tag: " << cpp_strerror(r)
      	 << dendl;
    return r;
  }

  std::lock_guard locker{*lock};
  *tag_tid = tag.tid;

  auto data_it = tag.data.cbegin();
  r = decode(&data_it, tag_data);
  if (r < 0) {
    lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
               << "failed to decode allocated tag" << dendl;
    return r;
  }

  ldout(cct, 20) << "C_DecodeTag: " << this << " " << __func__ << ": "
                 << "allocated journal tag: "
                 << "tid=" << tag.tid << ", "
                 << "data=" << *tag_data << dendl;
  return 0;
}

int C_DecodeTags::process(int r) {
  if (r < 0) {
    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
               << "failed to retrieve journal tags: " << cpp_strerror(r)
               << dendl;
    return r;
  }

  if (tags.empty()) {
    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
               << "no journal tags retrieved" << dendl;
    return -ENOENT;
  }

  std::lock_guard locker{*lock};
  *tag_tid = tags.back().tid;
  auto data_it = tags.back().data.cbegin();
  r = C_DecodeTag::decode(&data_it, tag_data);
  if (r < 0) {
    lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
               << "failed to decode journal tag" << dendl;
    return r;
  }

  ldout(cct, 20) << "C_DecodeTags: " << this << " " << __func__ << ": "
                 << "most recent journal tag: "
                 << "tid=" << *tag_tid << ", "
                 << "data=" << *tag_data << dendl;
  return 0;
}

} // namespace util
} // namespace journal
} // namespace librbd