Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rbd_replay / rbd_loc.hpp
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
7  *
8  * This is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License version 2.1, as published by the Free Software
11  * Foundation.  See file COPYING.
12  *
13  */
14
15 #ifndef _INCLUDED_RBD_REPLAY_RBD_LOC_HPP
16 #define _INCLUDED_RBD_REPLAY_RBD_LOC_HPP
17
18 #include <string>
19
20 namespace rbd_replay {
21
22 /**
23    Stores a pool, image name, and snap name triple.
24    rbd_locs can be converted to/from strings with the format pool/image\@snap.
25    The slash and at signs can be omitted if the pool and snap are empty, respectively.
26    Backslashes can be used to escape slashes and at signs in names.
27    Examples:
28
29    |Pool  | Image | Snap | String             |
30    |------|-------|------|--------------------|
31    |rbd   | vm    | 1    | rbd/vm\@1          |
32    |rbd   | vm    |      | rbd/vm             |
33    |      | vm    | 1    | vm\@1              |
34    |      | vm    |      | vm                 |
35    |rbd   |       | 1    | rbd/\@1            |
36    |rbd\@x| vm/y  | 1    | rbd\\\@x/vm\\/y\@1 |
37
38    (The empty string should obviously be avoided as the image name.)
39
40    Note that the non-canonical forms /vm\@1 and rbd/vm\@ can also be parsed,
41    although they will be formatted as vm\@1 and rbd/vm.
42  */
43 struct rbd_loc {
44   /**
45      Constructs an rbd_loc with the empty string for the pool, image, and snap.
46    */
47   rbd_loc();
48
49   /**
50      Constructs an rbd_loc with the given pool, image, and snap.
51    */
52   rbd_loc(std::string pool, std::string image, std::string snap);
53
54   /**
55      Parses an rbd_loc from the given string.
56      If parsing fails, the contents are unmodified.
57      @retval true if parsing succeeded
58    */
59   bool parse(std::string name_string);
60
61   /**
62      Returns the string representation of the locator.
63    */
64   std::string str() const;
65
66   /**
67      Compares the locators lexicographically by pool, then image, then snap.
68    */
69   int compare(const rbd_loc& rhs) const;
70
71   /**
72      Returns true if the locators have identical pool, image, and snap.
73    */
74   bool operator==(const rbd_loc& rhs) const;
75
76   /**
77      Compares the locators lexicographically by pool, then image, then snap.
78    */
79   bool operator<(const rbd_loc& rhs) const;
80
81   std::string pool;
82
83   std::string image;
84
85   std::string snap;
86 };
87
88 }
89
90 #endif