]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
11fdf7f2 | 4 | #include "include/ceph_assert.h" |
7c673cae FG |
5 | #include "librbd/managed_lock/Utils.h" |
6 | #include <sstream> | |
7 | ||
8 | namespace librbd { | |
9 | namespace managed_lock { | |
10 | namespace util { | |
11 | ||
12 | namespace { | |
13 | ||
14 | const std::string WATCHER_LOCK_COOKIE_PREFIX = "auto"; | |
15 | const std::string WATCHER_LOCK_TAG("internal"); | |
16 | ||
17 | } // anonymous namespace | |
18 | ||
19 | const std::string &get_watcher_lock_tag() { | |
20 | return WATCHER_LOCK_TAG; | |
21 | } | |
22 | ||
23 | bool decode_lock_cookie(const std::string &tag, uint64_t *handle) { | |
24 | std::string prefix; | |
25 | std::istringstream ss(tag); | |
26 | if (!(ss >> prefix >> *handle) || prefix != WATCHER_LOCK_COOKIE_PREFIX) { | |
27 | return false; | |
28 | } | |
29 | return true; | |
30 | } | |
31 | ||
32 | std::string encode_lock_cookie(uint64_t watch_handle) { | |
11fdf7f2 | 33 | ceph_assert(watch_handle != 0); |
7c673cae FG |
34 | std::ostringstream ss; |
35 | ss << WATCHER_LOCK_COOKIE_PREFIX << " " << watch_handle; | |
36 | return ss.str(); | |
37 | } | |
38 | ||
39 | } // namespace util | |
40 | } // namespace managed_lock | |
41 | } // namespace librbd | |
42 | ||
43 |