Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / librbd / journal / Utils.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 "librbd/journal/Utils.h"
5 #include "common/dout.h"
6 #include "common/errno.h"
7 #include "librbd/journal/Types.h"
8
9 #define dout_subsys ceph_subsys_rbd
10 #undef dout_prefix
11 #define dout_prefix *_dout << "librbd::journal::"
12
13 namespace librbd {
14 namespace journal {
15 namespace util {
16
17 int C_DecodeTag::decode(bufferlist::iterator *it, TagData *tag_data) {
18   try {
19     ::decode(*tag_data, *it);
20   } catch (const buffer::error &err) {
21     return -EBADMSG;
22   }
23   return 0;
24 }
25
26 int C_DecodeTag::process(int r) {
27   if (r < 0) {
28     lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
29                << "failed to allocate tag: " << cpp_strerror(r)
30          << dendl;
31     return r;
32   }
33
34   Mutex::Locker locker(*lock);
35   *tag_tid = tag.tid;
36
37   bufferlist::iterator data_it = tag.data.begin();
38   r = decode(&data_it, tag_data);
39   if (r < 0) {
40     lderr(cct) << "C_DecodeTag: " << this << " " << __func__ << ": "
41                << "failed to decode allocated tag" << dendl;
42     return r;
43   }
44
45   ldout(cct, 20) << "C_DecodeTag: " << this << " " << __func__ << ": "
46                  << "allocated journal tag: "
47                  << "tid=" << tag.tid << ", "
48                  << "data=" << *tag_data << dendl;
49   return 0;
50 }
51
52 int C_DecodeTags::process(int r) {
53   if (r < 0) {
54     lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
55                << "failed to retrieve journal tags: " << cpp_strerror(r)
56                << dendl;
57     return r;
58   }
59
60   if (tags.empty()) {
61     lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
62                << "no journal tags retrieved" << dendl;
63     return -ENOENT;
64   }
65
66   Mutex::Locker locker(*lock);
67   *tag_tid = tags.back().tid;
68   bufferlist::iterator data_it = tags.back().data.begin();
69   r = C_DecodeTag::decode(&data_it, tag_data);
70   if (r < 0) {
71     lderr(cct) << "C_DecodeTags: " << this << " " << __func__ << ": "
72                << "failed to decode journal tag" << dendl;
73     return r;
74   }
75
76   ldout(cct, 20) << "C_DecodeTags: " << this << " " << __func__ << ": "
77                  << "most recent journal tag: "
78                  << "tid=" << *tag_tid << ", "
79                  << "data=" << *tag_data << dendl;
80   return 0;
81 }
82
83 } // namespace util
84 } // namespace journal
85 } // namespace librbd