diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 18:24:20 +0000 |
commit | 483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch) | |
tree | e5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/rbd_replay/ImageNameMap.cc | |
parent | Initial commit. (diff) | |
download | ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip |
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/rbd_replay/ImageNameMap.cc')
-rw-r--r-- | src/rbd_replay/ImageNameMap.cc | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/rbd_replay/ImageNameMap.cc b/src/rbd_replay/ImageNameMap.cc new file mode 100644 index 00000000..f5426571 --- /dev/null +++ b/src/rbd_replay/ImageNameMap.cc @@ -0,0 +1,69 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com> + * + * This is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software + * Foundation. See file COPYING. + * + */ + +#include "ImageNameMap.hpp" + + +using namespace std; +using namespace rbd_replay; + + +bool ImageNameMap::parse_mapping(string mapping_string, Mapping *mapping) const { + string fields[2]; + int field = 0; + for (size_t i = 0, n = mapping_string.length(); i < n; i++) { + char c = mapping_string[i]; + switch (c) { + case '\\': + if (i != n - 1 && mapping_string[i + 1] == '=') { + i++; + fields[field].push_back('='); + } else { + fields[field].push_back('\\'); + } + break; + case '=': + if (field == 1) { + return false; + } + field = 1; + break; + default: + fields[field].push_back(c); + } + } + if (field == 0) { + return false; + } + if (!mapping->first.parse(fields[0])) { + return false; + } + if (!mapping->second.parse(fields[1])) { + return false; + } + return true; +} + +void ImageNameMap::add_mapping(const Mapping& mapping) { + m_map.insert(mapping); +} + +rbd_loc ImageNameMap::map(const rbd_loc& name) const { + std::map<rbd_loc, rbd_loc>::const_iterator p(m_map.find(name)); + if (p == m_map.end()) { + return name; + } else { + return p->second; + } +} |