X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Frbd_replay%2FImageNameMap.cc;fp=src%2Fceph%2Fsrc%2Frbd_replay%2FImageNameMap.cc;h=f542657185fbbe5e303a42a6877c406bdd213ad6;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/rbd_replay/ImageNameMap.cc b/src/ceph/src/rbd_replay/ImageNameMap.cc new file mode 100644 index 0000000..f542657 --- /dev/null +++ b/src/ceph/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 + * + * 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::const_iterator p(m_map.find(name)); + if (p == m_map.end()) { + return name; + } else { + return p->second; + } +}