From 477c429e0f73185bf1de5d64f4af8ce4e8b30116 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Aug 2015 02:42:49 +0000 Subject: [PATCH 01/90] common/*Formatters: Split Formatters No functionality changes in this commit, just shuffle lines to new files and adding #include headers to ensure it still compiles. Signed-off-by: Robin H. Johnson Conflicts: src/mds/MDSDaemon.cc src/mds/MDSRank.cc Fixing compilation error --- src/common/Formatter.cc | 752 +------------------------ src/common/Formatter.h | 123 ---- src/common/JSONFormatter.cc | 226 ++++++++ src/common/JSONFormatter.h | 63 +++ src/common/Makefile.am | 6 + src/common/TableFormatter.cc | 376 +++++++++++++ src/common/TableFormatter.h | 68 +++ src/common/XMLFormatter.cc | 253 +++++++++ src/common/XMLFormatter.h | 61 ++ src/common/admin_socket.cc | 1 + src/mds/MDS.cc | 1 + src/mon/ConfigKeyService.cc | 1 + src/mon/Monitor.cc | 2 + src/mon/Paxos.cc | 1 + src/mon/Paxos.h | 3 + src/os/FileJournal.cc | 2 + src/os/FileStore.cc | 2 + src/os/FileStore.h | 2 + src/os/KeyValueStore.cc | 2 + src/os/KeyValueStore.h | 1 + src/os/MemStore.cc | 2 + src/osd/OSD.cc | 2 + src/osd/OSDMap.cc | 1 + src/rbd.cc | 2 + src/rbd_replay/actions.hpp | 3 +- src/rgw/rgw_admin.cc | 2 + src/rgw/rgw_cors_s3.h | 1 + src/rgw/rgw_jsonparser.cc | 1 + src/rgw/rgw_log.cc | 1 + src/rgw/rgw_rest.cc | 2 + src/rgw/rgw_rest_s3.cc | 1 + src/rgw/rgw_swift.cc | 1 + src/rgw/rgw_swift_auth.cc | 1 + src/test/bench/small_io_bench.cc | 1 + src/test/bench/small_io_bench_dumb.cc | 1 + src/test/bench/small_io_bench_fs.cc | 1 + src/test/bench/small_io_bench_rbd.cc | 1 + src/test/bench/tp_bench.cc | 1 + src/test/common/test_tableformatter.cc | 2 +- src/test/crush/crush.cc | 1 + src/test/encoding/ceph_dencoder.cc | 1 + src/test/formatter.cc | 3 +- src/test/kv_store_bench.h | 1 + src/test/mon/test_mon_workloadgen.cc | 1 + src/test/test_rgw_admin_meta.cc | 2 + src/tools/ceph-client-debug.cc | 2 +- src/tools/ceph_monstore_tool.cc | 2 +- src/tools/ceph_objectstore_tool.cc | 1 + src/tools/cephfs/EventOutput.cc | 1 + src/tools/cephfs/JournalTool.cc | 1 + src/tools/cephfs/TableTool.cc | 2 + src/tools/rados/rados.cc | 2 + 52 files changed, 1117 insertions(+), 876 deletions(-) create mode 100644 src/common/JSONFormatter.cc create mode 100644 src/common/JSONFormatter.h create mode 100644 src/common/TableFormatter.cc create mode 100644 src/common/TableFormatter.h create mode 100644 src/common/XMLFormatter.cc create mode 100644 src/common/XMLFormatter.h diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 7c166ef09865f..9670aa22e51be 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -18,6 +18,9 @@ #include "assert.h" #include "Formatter.h" +#include "JSONFormatter.h" +#include "TableFormatter.h" +#include "XMLFormatter.h" #include "common/escape.h" #include @@ -114,751 +117,4 @@ void Formatter::dump_format_unquoted(const char *name, const char *fmt, ...) va_end(ap); } -// ----------------------- - -JSONFormatter::JSONFormatter(bool p) -: m_pretty(p), m_is_pending_string(false) -{ - reset(); -} - -void JSONFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - os << m_ss.str(); - if (m_pretty) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void JSONFormatter::reset() -{ - m_stack.clear(); - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); -} - -void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) -{ - if (entry.size) { - if (m_pretty) { - m_ss << ",\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } else { - m_ss << ","; - } - } else if (m_pretty) { - m_ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } - if (m_pretty && entry.is_array) - m_ss << " "; -} - -void JSONFormatter::print_quoted_string(const std::string& s) -{ - int len = escape_json_attr_len(s.c_str(), s.size()); - char escaped[len]; - escape_json_attr(s.c_str(), s.size(), escaped); - m_ss << '\"' << escaped << '\"'; -} - -void JSONFormatter::print_name(const char *name) -{ - finish_pending_string(); - if (m_stack.empty()) - return; - struct json_formatter_stack_entry_d& entry = m_stack.back(); - print_comma(entry); - if (!entry.is_array) { - if (m_pretty) { - m_ss << " "; - } - m_ss << "\"" << name << "\""; - if (m_pretty) - m_ss << ": "; - else - m_ss << ':'; - } - ++entry.size; -} - -void JSONFormatter::open_section(const char *name, bool is_array) -{ - print_name(name); - if (is_array) - m_ss << '['; - else - m_ss << '{'; - - json_formatter_stack_entry_d n; - n.is_array = is_array; - m_stack.push_back(n); -} - -void JSONFormatter::open_array_section(const char *name) -{ - open_section(name, true); -} - -void JSONFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - std::ostringstream oss; - oss << name << " " << ns; - open_section(oss.str().c_str(), true); -} - -void JSONFormatter::open_object_section(const char *name) -{ - open_section(name, false); -} - -void JSONFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - std::ostringstream oss; - oss << name << " " << ns; - open_section(oss.str().c_str(), false); -} - -void JSONFormatter::close_section() -{ - assert(!m_stack.empty()); - finish_pending_string(); - - struct json_formatter_stack_entry_d& entry = m_stack.back(); - if (m_pretty && entry.size) { - m_ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } - m_ss << (entry.is_array ? ']' : '}'); - m_stack.pop_back(); -} - -void JSONFormatter::finish_pending_string() -{ - if (m_is_pending_string) { - print_quoted_string(m_pending_string.str()); - m_pending_string.str(std::string()); - m_is_pending_string = false; - } -} - -void JSONFormatter::dump_unsigned(const char *name, uint64_t u) -{ - print_name(name); - m_ss << u; -} - -void JSONFormatter::dump_int(const char *name, int64_t s) -{ - print_name(name); - m_ss << s; -} - -void JSONFormatter::dump_float(const char *name, double d) -{ - print_name(name); - char foo[30]; - snprintf(foo, sizeof(foo), "%lf", d); - m_ss << foo; -} - -void JSONFormatter::dump_string(const char *name, const std::string& s) -{ - print_name(name); - print_quoted_string(s); -} - -std::ostream& JSONFormatter::dump_stream(const char *name) -{ - print_name(name); - m_is_pending_string = true; - return m_pending_string; -} - -void JSONFormatter::dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - print_name(name); - if (quoted) { - print_quoted_string(std::string(buf)); - } else { - m_ss << std::string(buf); - } -} - -int JSONFormatter::get_len() const -{ - return m_ss.str().size(); -} - -void JSONFormatter::write_raw_data(const char *data) -{ - m_ss << data; -} - -const char *XMLFormatter::XML_1_DTD = - ""; - -XMLFormatter::XMLFormatter(bool pretty) -: m_pretty(pretty) -{ - reset(); -} - -void XMLFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - os << m_ss.str(); - if (m_pretty) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void XMLFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); - m_sections.clear(); - m_pending_string_name.clear(); -} - -void XMLFormatter::open_object_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -void XMLFormatter::open_array_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -void XMLFormatter::close_section() -{ - assert(!m_sections.empty()); - finish_pending_string(); - - std::string section = m_sections.back(); - m_sections.pop_back(); - print_spaces(); - m_ss << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_unsigned(const char *name, uint64_t u) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << u << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_int(const char *name, int64_t u) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << u << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_float(const char *name, double d) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << d << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_string(const char *name, const std::string& s) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) -{ - std::string e(name); - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - print_spaces(); - m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << ""; - if (m_pretty) - m_ss << "\n"; -} - -std::ostream& XMLFormatter::dump_stream(const char *name) -{ - print_spaces(); - m_pending_string_name = name; - m_ss << "<" << m_pending_string_name << ">"; - return m_pending_string; -} - -void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - std::string e(name); - print_spaces(); - if (ns) { - m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; - } else { - m_ss << "<" << e << ">" << escape_xml_str(buf) << ""; - } - - if (m_pretty) - m_ss << "\n"; -} - -int XMLFormatter::get_len() const -{ - return m_ss.str().size(); -} - -void XMLFormatter::write_raw_data(const char *data) -{ - m_ss << data; -} - -void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) -{ - std::stringstream attrs_ss; - - for (std::list >::const_iterator iter = attrs->attrs.begin(); - iter != attrs->attrs.end(); ++iter) { - std::pair p = *iter; - attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = attrs_ss.str(); -} - -void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) -{ - print_spaces(); - std::string attrs_str; - - if (attrs) { - get_attrs_str(attrs, attrs_str); - } - - if (ns) { - m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">"; - } else { - m_ss << "<" << name << attrs_str << ">"; - } - if (m_pretty) - m_ss << "\n"; - m_sections.push_back(name); -} - -void XMLFormatter::finish_pending_string() -{ - if (!m_pending_string_name.empty()) { - m_ss << escape_xml_str(m_pending_string.str().c_str()) - << ""; - m_pending_string_name.clear(); - m_pending_string.str(std::string()); - if (m_pretty) { - m_ss << "\n"; - } - } -} - -void XMLFormatter::print_spaces() -{ - finish_pending_string(); - if (m_pretty) { - std::string spaces(m_sections.size(), ' '); - m_ss << spaces; - } -} - -std::string XMLFormatter::escape_xml_str(const char *str) -{ - int len = escape_xml_attr_len(str); - std::vector escaped(len, '\0'); - escape_xml_attr(str, &escaped[0]); - return std::string(&escaped[0]); -} - -TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) -{ - reset(); -} - -void TableFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - std::vector column_size = m_column_size; - std::vector column_name = m_column_name; - - std::set need_header_set; - - // auto-sizing columns - for (size_t i = 0; i < m_vec.size(); i++) { - for (size_t j = 0; j < m_vec[i].size(); j++) { - column_size.resize(m_vec[i].size()); - column_name.resize(m_vec[i].size()); - if (i > 0) { - if (m_vec[i - 1][j] != m_vec[i][j]) { - // changing row labels require to show the header - need_header_set.insert(i); - column_name[i] = m_vec[i][j].first; - } - } else { - column_name[i] = m_vec[i][j].first; - } - - if (m_vec[i][j].second.length() > column_size[j]) - column_size[j] = m_vec[i][j].second.length(); - if (m_vec[i][j].first.length() > column_size[j]) - column_size[j] = m_vec[i][j].first.length(); - } - } - - bool need_header = false; - if ((column_size.size() == m_column_size.size())) { - for (size_t i = 0; i < column_size.size(); i++) { - if (column_size[i] != m_column_size[i]) { - need_header = true; - break; - } - } - } else { - need_header = true; - } - - if (need_header) { - // first row always needs a header if there wasn't one before - need_header_set.insert(0); - } - - m_column_size = column_size; - for (size_t i = 0; i < m_vec.size(); i++) { - if (i == 0) { - if (need_header_set.count(i)) { - // print the header - if (!m_keyval) { - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - os << "|"; - - for (size_t j = 0; j < m_vec[i].size(); j++) { - os << " "; - std::stringstream fs; - fs << boost::format("%%-%is") % (m_column_size[j] + 2); - os << boost::format(fs.str()) % m_vec[i][j].first; - os << "|"; - } - os << "\n"; - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - } - // print body - if (!m_keyval) - os << "|"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - if (!m_keyval) - os << " "; - std::stringstream fs; - - if (m_keyval) { - os << "key::"; - os << m_vec[i][j].first; - os << "="; - os << "\""; - os << m_vec[i][j].second; - os << "\" "; - } else { - fs << boost::format("%%-%is") % (m_column_size[j] + 2); - os << boost::format(fs.str()) % m_vec[i][j].second; - os << "|"; - } - } - - os << "\n"; - if (!m_keyval) { - if (i == (m_vec.size() - 1)) { - // print trailer - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - m_vec[i].clear(); - } - m_vec.clear(); -} - -void TableFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_section_cnt.clear(); - m_column_size.clear(); - m_section_open = 0; -} - -void TableFormatter::open_object_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) -{ - m_section.push_back(name); - m_section_open++; -} - -void TableFormatter::close_section() -{ - // - m_section_open--; - if (m_section.size()) { - m_section_cnt[m_section.back()] = 0; - m_section.pop_back(); - } -} - -size_t TableFormatter::m_vec_index(const char *name) -{ - std::string key(name); - - size_t i = m_vec.size(); - if (i) - i--; - - // make sure there are vectors to push back key/val pairs - if (!m_vec.size()) - m_vec.resize(1); - - if (m_vec.size()) { - if (m_vec[i].size()) { - if (m_vec[i][0].first == key) { - // start a new column if a key is repeated - m_vec.resize(m_vec.size() + 1); - i++; - } - } - } - - return i; -} - -std::string TableFormatter::get_section_name(const char* name) -{ - std::string t_name = name; - for (size_t i = 0; i < m_section.size(); i++) { - t_name.insert(0, ":"); - t_name.insert(0, m_section[i]); - } - if (m_section_open) { - std::stringstream lss; - lss << t_name; - lss << "["; - lss << m_section_cnt[t_name]++; - lss << "]"; - return lss.str(); - } else { - return t_name; - } -} - -void TableFormatter::dump_unsigned(const char *name, uint64_t u) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << u; - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_int(const char *name, int64_t u) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << u; - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_float(const char *name, double d) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << d; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_string(const char *name, const std::string& s) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - m_ss << attrs_str << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - finish_pending_string(); - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - size_t i = m_vec_index(name); - if (ns) { - m_ss << ns << "." << buf; - } else - m_ss << buf; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -std::ostream& TableFormatter::dump_stream(const char *name) -{ - finish_pending_string(); - // we don't support this - m_pending_name = name; - return m_ss; -} - -int TableFormatter::get_len() const -{ - // we don't know the size until flush is called - return 0; -} - -void TableFormatter::write_raw_data(const char *data) { - // not supported -} - -void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) -{ - std::stringstream attrs_ss; - - for (std::list >::const_iterator iter = attrs->attrs.begin(); - iter != attrs->attrs.end(); ++iter) { - std::pair p = *iter; - attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = attrs_ss.str(); -} - -void TableFormatter::finish_pending_string() -{ - if (m_pending_name.length()) { - std::string ss = m_ss.str(); - m_ss.clear(); - m_ss.str(""); - std::string pending_name = m_pending_name; - m_pending_name = ""; - dump_string(pending_name.c_str(), ss); - } -} -} - +} // namespace ceph diff --git a/src/common/Formatter.h b/src/common/Formatter.h index c61138dac3672..8fdd9d81e59a8 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -85,128 +85,5 @@ namespace ceph { } }; - class JSONFormatter : public Formatter { - public: - JSONFormatter(bool p = false); - - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); - - private: - - struct json_formatter_stack_entry_d { - int size; - bool is_array; - json_formatter_stack_entry_d() : size(0), is_array(false) { } - }; - - bool m_pretty; - void open_section(const char *name, bool is_array); - void print_quoted_string(const std::string& s); - void print_name(const char *name); - void print_comma(json_formatter_stack_entry_d& entry); - void finish_pending_string(); - - std::stringstream m_ss, m_pending_string; - std::list m_stack; - bool m_is_pending_string; - }; - - class XMLFormatter : public Formatter { - public: - static const char *XML_1_DTD; - XMLFormatter(bool pretty = false); - - void flush(std::ostream& os); - void reset(); - void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); - - /* with attrs */ - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - private: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - void finish_pending_string(); - void print_spaces(); - static std::string escape_xml_str(const char *str); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); - - std::stringstream m_ss, m_pending_string; - std::deque m_sections; - bool m_pretty; - std::string m_pending_string_name; - }; - - class TableFormatter : public Formatter { - public: - TableFormatter(bool keyval = false); - - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); - - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - std::ostream& dump_stream(const char *name); - - int get_len() const; - void write_raw_data(const char *data); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); - - private: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - std::vector< std::vector > > m_vec; - std::stringstream m_ss; - size_t m_vec_index(const char* name); - std::string get_section_name(const char* name); - void finish_pending_string(); - std::string m_pending_name; - bool m_keyval; - - int m_section_open; - std::vector< std::string > m_section; - std::map m_section_cnt; - std::vector m_column_size; - std::vector< std::string > m_column_name; - }; - - } #endif diff --git a/src/common/JSONFormatter.cc b/src/common/JSONFormatter.cc new file mode 100644 index 0000000000000..8bf5007ba7fbf --- /dev/null +++ b/src/common/JSONFormatter.cc @@ -0,0 +1,226 @@ +// -*- 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) 2011 New Dream Network + * + * 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. + * + */ + +#define LARGE_SIZE 1024 + +#include "include/int_types.h" + +#include "assert.h" +#include "Formatter.h" +#include "JSONFormatter.h" +#include "common/escape.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ----------------------- +namespace ceph { + +JSONFormatter::JSONFormatter(bool p) +: m_pretty(p), m_is_pending_string(false) +{ + reset(); +} + +void JSONFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + os << m_ss.str(); + if (m_pretty) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void JSONFormatter::reset() +{ + m_stack.clear(); + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); +} + +void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) +{ + if (entry.size) { + if (m_pretty) { + m_ss << ",\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } else { + m_ss << ","; + } + } else if (m_pretty) { + m_ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } + if (m_pretty && entry.is_array) + m_ss << " "; +} + +void JSONFormatter::print_quoted_string(const std::string& s) +{ + int len = escape_json_attr_len(s.c_str(), s.size()); + char escaped[len]; + escape_json_attr(s.c_str(), s.size(), escaped); + m_ss << '\"' << escaped << '\"'; +} + +void JSONFormatter::print_name(const char *name) +{ + finish_pending_string(); + if (m_stack.empty()) + return; + struct json_formatter_stack_entry_d& entry = m_stack.back(); + print_comma(entry); + if (!entry.is_array) { + if (m_pretty) { + m_ss << " "; + } + m_ss << "\"" << name << "\""; + if (m_pretty) + m_ss << ": "; + else + m_ss << ':'; + } + ++entry.size; +} + +void JSONFormatter::open_section(const char *name, bool is_array) +{ + print_name(name); + if (is_array) + m_ss << '['; + else + m_ss << '{'; + + json_formatter_stack_entry_d n; + n.is_array = is_array; + m_stack.push_back(n); +} + +void JSONFormatter::open_array_section(const char *name) +{ + open_section(name, true); +} + +void JSONFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + std::ostringstream oss; + oss << name << " " << ns; + open_section(oss.str().c_str(), true); +} + +void JSONFormatter::open_object_section(const char *name) +{ + open_section(name, false); +} + +void JSONFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + std::ostringstream oss; + oss << name << " " << ns; + open_section(oss.str().c_str(), false); +} + +void JSONFormatter::close_section() +{ + assert(!m_stack.empty()); + finish_pending_string(); + + struct json_formatter_stack_entry_d& entry = m_stack.back(); + if (m_pretty && entry.size) { + m_ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } + m_ss << (entry.is_array ? ']' : '}'); + m_stack.pop_back(); +} + +void JSONFormatter::finish_pending_string() +{ + if (m_is_pending_string) { + print_quoted_string(m_pending_string.str()); + m_pending_string.str(std::string()); + m_is_pending_string = false; + } +} + +void JSONFormatter::dump_unsigned(const char *name, uint64_t u) +{ + print_name(name); + m_ss << u; +} + +void JSONFormatter::dump_int(const char *name, int64_t s) +{ + print_name(name); + m_ss << s; +} + +void JSONFormatter::dump_float(const char *name, double d) +{ + print_name(name); + char foo[30]; + snprintf(foo, sizeof(foo), "%lf", d); + m_ss << foo; +} + +void JSONFormatter::dump_string(const char *name, const std::string& s) +{ + print_name(name); + print_quoted_string(s); +} + +std::ostream& JSONFormatter::dump_stream(const char *name) +{ + print_name(name); + m_is_pending_string = true; + return m_pending_string; +} + +void JSONFormatter::dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + print_name(name); + if (quoted) { + print_quoted_string(std::string(buf)); + } else { + m_ss << std::string(buf); + } +} + +int JSONFormatter::get_len() const +{ + return m_ss.str().size(); +} + +void JSONFormatter::write_raw_data(const char *data) +{ + m_ss << data; +} + +} // namespace ceph diff --git a/src/common/JSONFormatter.h b/src/common/JSONFormatter.h new file mode 100644 index 0000000000000..895be2913c0f1 --- /dev/null +++ b/src/common/JSONFormatter.h @@ -0,0 +1,63 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#ifndef CEPH_JSON_FORMATTER_H +#define CEPH_JSON_FORMATTER_H + +#include "include/int_types.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/buffer.h" +#include "Formatter.h" + +namespace ceph { + class JSONFormatter : public Formatter { + public: + JSONFormatter(bool p = false); + + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); + + private: + + struct json_formatter_stack_entry_d { + int size; + bool is_array; + json_formatter_stack_entry_d() : size(0), is_array(false) { } + }; + + bool m_pretty; + void open_section(const char *name, bool is_array); + void print_quoted_string(const std::string& s); + void print_name(const char *name); + void print_comma(json_formatter_stack_entry_d& entry); + void finish_pending_string(); + + std::stringstream m_ss, m_pending_string; + std::list m_stack; + bool m_is_pending_string; + }; + +} + +#endif diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 620e550003591..1cb6a3cf1977f 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -45,6 +45,9 @@ libcommon_internal_la_SOURCES = \ common/simple_spin.cc \ common/Thread.cc \ common/Formatter.cc \ + common/XMLFormatter.cc \ + common/JSONFormatter.cc \ + common/TableFormatter.cc \ common/HeartbeatMap.cc \ common/config.cc \ common/utf8.c \ @@ -178,6 +181,9 @@ noinst_HEADERS += \ common/DecayCounter.h \ common/Finisher.h \ common/Formatter.h \ + common/JSONFormatter.h \ + common/TableFormatter.h \ + common/XMLFormatter.h \ common/perf_counters.h \ common/OutputDataSocket.h \ common/admin_socket.h \ diff --git a/src/common/TableFormatter.cc b/src/common/TableFormatter.cc new file mode 100644 index 0000000000000..4be4e39077b78 --- /dev/null +++ b/src/common/TableFormatter.cc @@ -0,0 +1,376 @@ +// -*- 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) 2011 New Dream Network + * + * 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. + * + */ + +#define LARGE_SIZE 1024 + +#include "include/int_types.h" + +#include "assert.h" +#include "Formatter.h" +#include "TableFormatter.h" +#include "common/escape.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ----------------------- +namespace ceph { +TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) +{ + reset(); +} + +void TableFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + std::vector column_size = m_column_size; + std::vector column_name = m_column_name; + + std::set need_header_set; + + // auto-sizing columns + for (size_t i = 0; i < m_vec.size(); i++) { + for (size_t j = 0; j < m_vec[i].size(); j++) { + column_size.resize(m_vec[i].size()); + column_name.resize(m_vec[i].size()); + if (i > 0) { + if (m_vec[i - 1][j] != m_vec[i][j]) { + // changing row labels require to show the header + need_header_set.insert(i); + column_name[i] = m_vec[i][j].first; + } + } else { + column_name[i] = m_vec[i][j].first; + } + + if (m_vec[i][j].second.length() > column_size[j]) + column_size[j] = m_vec[i][j].second.length(); + if (m_vec[i][j].first.length() > column_size[j]) + column_size[j] = m_vec[i][j].first.length(); + } + } + + bool need_header = false; + if ((column_size.size() == m_column_size.size())) { + for (size_t i = 0; i < column_size.size(); i++) { + if (column_size[i] != m_column_size[i]) { + need_header = true; + break; + } + } + } else { + need_header = true; + } + + if (need_header) { + // first row always needs a header if there wasn't one before + need_header_set.insert(0); + } + + m_column_size = column_size; + for (size_t i = 0; i < m_vec.size(); i++) { + if (i == 0) { + if (need_header_set.count(i)) { + // print the header + if (!m_keyval) { + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + os << "|"; + + for (size_t j = 0; j < m_vec[i].size(); j++) { + os << " "; + std::stringstream fs; + fs << boost::format("%%-%is") % (m_column_size[j] + 2); + os << boost::format(fs.str()) % m_vec[i][j].first; + os << "|"; + } + os << "\n"; + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + } + // print body + if (!m_keyval) + os << "|"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + if (!m_keyval) + os << " "; + std::stringstream fs; + + if (m_keyval) { + os << "key::"; + os << m_vec[i][j].first; + os << "="; + os << "\""; + os << m_vec[i][j].second; + os << "\" "; + } else { + fs << boost::format("%%-%is") % (m_column_size[j] + 2); + os << boost::format(fs.str()) % m_vec[i][j].second; + os << "|"; + } + } + + os << "\n"; + if (!m_keyval) { + if (i == (m_vec.size() - 1)) { + // print trailer + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + m_vec[i].clear(); + } + m_vec.clear(); +} + +void TableFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_section_cnt.clear(); + m_column_size.clear(); + m_section_open = 0; +} + +void TableFormatter::open_object_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) +{ + m_section.push_back(name); + m_section_open++; +} + +void TableFormatter::close_section() +{ + // + m_section_open--; + if (m_section.size()) { + m_section_cnt[m_section.back()] = 0; + m_section.pop_back(); + } +} + +size_t TableFormatter::m_vec_index(const char *name) +{ + std::string key(name); + + size_t i = m_vec.size(); + if (i) + i--; + + // make sure there are vectors to push back key/val pairs + if (!m_vec.size()) + m_vec.resize(1); + + if (m_vec.size()) { + if (m_vec[i].size()) { + if (m_vec[i][0].first == key) { + // start a new column if a key is repeated + m_vec.resize(m_vec.size() + 1); + i++; + } + } + } + + return i; +} + +std::string TableFormatter::get_section_name(const char* name) +{ + std::string t_name = name; + for (size_t i = 0; i < m_section.size(); i++) { + t_name.insert(0, ":"); + t_name.insert(0, m_section[i]); + } + if (m_section_open) { + std::stringstream lss; + lss << t_name; + lss << "["; + lss << m_section_cnt[t_name]++; + lss << "]"; + return lss.str(); + } else { + return t_name; + } +} + +void TableFormatter::dump_unsigned(const char *name, uint64_t u) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << u; + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_int(const char *name, int64_t u) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << u; + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_float(const char *name, double d) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << d; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_string(const char *name, const std::string& s) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + m_ss << attrs_str << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + finish_pending_string(); + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + size_t i = m_vec_index(name); + if (ns) { + m_ss << ns << "." << buf; + } else + m_ss << buf; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +std::ostream& TableFormatter::dump_stream(const char *name) +{ + finish_pending_string(); + // we don't support this + m_pending_name = name; + return m_ss; +} + +int TableFormatter::get_len() const +{ + // we don't know the size until flush is called + return 0; +} + +void TableFormatter::write_raw_data(const char *data) { + // not supported +} + +void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) +{ + std::stringstream attrs_ss; + + for (std::list >::const_iterator iter = attrs->attrs.begin(); + iter != attrs->attrs.end(); ++iter) { + std::pair p = *iter; + attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = attrs_ss.str(); +} + +void TableFormatter::finish_pending_string() +{ + if (m_pending_name.length()) { + std::string ss = m_ss.str(); + m_ss.clear(); + m_ss.str(""); + std::string pending_name = m_pending_name; + m_pending_name = ""; + dump_string(pending_name.c_str(), ss); + } +} + +} // namespace ceph diff --git a/src/common/TableFormatter.h b/src/common/TableFormatter.h new file mode 100644 index 0000000000000..950341c7af78b --- /dev/null +++ b/src/common/TableFormatter.h @@ -0,0 +1,68 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#ifndef CEPH_TABLE_FORMATTER_H +#define CEPH_TABLE_FORMATTER_H + +#include "include/int_types.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/buffer.h" +#include "Formatter.h" + +namespace ceph { + class TableFormatter : public Formatter { + public: + TableFormatter(bool keyval = false); + + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); + std::ostream& dump_stream(const char *name); + + int get_len() const; + void write_raw_data(const char *data); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + std::vector< std::vector > > m_vec; + std::stringstream m_ss; + size_t m_vec_index(const char* name); + std::string get_section_name(const char* name); + void finish_pending_string(); + std::string m_pending_name; + bool m_keyval; + + int m_section_open; + std::vector< std::string > m_section; + std::map m_section_cnt; + std::vector m_column_size; + std::vector< std::string > m_column_name; + }; + + +} + +#endif diff --git a/src/common/XMLFormatter.cc b/src/common/XMLFormatter.cc new file mode 100644 index 0000000000000..4bc6603e299dc --- /dev/null +++ b/src/common/XMLFormatter.cc @@ -0,0 +1,253 @@ +// -*- 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) 2011 New Dream Network + * + * 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. + * + */ + +#define LARGE_SIZE 1024 + +#include "include/int_types.h" + +#include "assert.h" +#include "Formatter.h" +#include "XMLFormatter.h" +#include "common/escape.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ----------------------- +namespace ceph { + +const char *XMLFormatter::XML_1_DTD = + ""; + +XMLFormatter::XMLFormatter(bool pretty) +: m_pretty(pretty) +{ + reset(); +} + +void XMLFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + os << m_ss.str(); + if (m_pretty) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void XMLFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); + m_sections.clear(); + m_pending_string_name.clear(); +} + +void XMLFormatter::open_object_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +void XMLFormatter::open_array_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +void XMLFormatter::close_section() +{ + assert(!m_sections.empty()); + finish_pending_string(); + + std::string section = m_sections.back(); + m_sections.pop_back(); + print_spaces(); + m_ss << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_unsigned(const char *name, uint64_t u) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << u << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_int(const char *name, int64_t u) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << u << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_float(const char *name, double d) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << d << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_string(const char *name, const std::string& s) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +{ + std::string e(name); + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + print_spaces(); + m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << ""; + if (m_pretty) + m_ss << "\n"; +} + +std::ostream& XMLFormatter::dump_stream(const char *name) +{ + print_spaces(); + m_pending_string_name = name; + m_ss << "<" << m_pending_string_name << ">"; + return m_pending_string; +} + +void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + std::string e(name); + print_spaces(); + if (ns) { + m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; + } else { + m_ss << "<" << e << ">" << escape_xml_str(buf) << ""; + } + + if (m_pretty) + m_ss << "\n"; +} + +int XMLFormatter::get_len() const +{ + return m_ss.str().size(); +} + +void XMLFormatter::write_raw_data(const char *data) +{ + m_ss << data; +} + +void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) +{ + std::stringstream attrs_ss; + + for (std::list >::const_iterator iter = attrs->attrs.begin(); + iter != attrs->attrs.end(); ++iter) { + std::pair p = *iter; + attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = attrs_ss.str(); +} + +void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) +{ + print_spaces(); + std::string attrs_str; + + if (attrs) { + get_attrs_str(attrs, attrs_str); + } + + if (ns) { + m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">"; + } else { + m_ss << "<" << name << attrs_str << ">"; + } + if (m_pretty) + m_ss << "\n"; + m_sections.push_back(name); +} + +void XMLFormatter::finish_pending_string() +{ + if (!m_pending_string_name.empty()) { + m_ss << escape_xml_str(m_pending_string.str().c_str()) + << ""; + m_pending_string_name.clear(); + m_pending_string.str(std::string()); + if (m_pretty) { + m_ss << "\n"; + } + } +} + +void XMLFormatter::print_spaces() +{ + finish_pending_string(); + if (m_pretty) { + std::string spaces(m_sections.size(), ' '); + m_ss << spaces; + } +} + +std::string XMLFormatter::escape_xml_str(const char *str) +{ + int len = escape_xml_attr_len(str); + std::vector escaped(len, '\0'); + escape_xml_attr(str, &escaped[0]); + return std::string(&escaped[0]); +} + +} // namespace ceph diff --git a/src/common/XMLFormatter.h b/src/common/XMLFormatter.h new file mode 100644 index 0000000000000..87ca99894771b --- /dev/null +++ b/src/common/XMLFormatter.h @@ -0,0 +1,61 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#ifndef CEPH_XML_FORMATTER_H +#define CEPH_XML_FORMATTER_H + +#include "include/int_types.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/buffer.h" +#include "Formatter.h" + +namespace ceph { + class XMLFormatter : public Formatter { + public: + static const char *XML_1_DTD; + XMLFormatter(bool pretty = false); + + void flush(std::ostream& os); + void reset(); + void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); + + /* with attrs */ + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + void finish_pending_string(); + void print_spaces(); + static std::string escape_xml_str(const char *str); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + std::stringstream m_ss, m_pending_string; + std::deque m_sections; + bool m_pretty; + std::string m_pending_string_name; + }; + +} + +#endif diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index 95a48b3ec129b..c3425d8945225 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -26,6 +26,7 @@ #include "common/safe_io.h" #include "common/version.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include #include diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 69d6be05a4953..0dbe97e3e1a63 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -23,6 +23,7 @@ #include "common/signal.h" #include "common/ceph_argparse.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "msg/Messenger.h" #include "mon/MonClient.h" diff --git a/src/mon/ConfigKeyService.cc b/src/mon/ConfigKeyService.cc index 97126ed0d1f0e..790102e0f97ba 100644 --- a/src/mon/ConfigKeyService.cc +++ b/src/mon/ConfigKeyService.cc @@ -24,6 +24,7 @@ #include "common/config.h" #include "common/cmdparse.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_mon #undef dout_prefix diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 4a34283e0d9d6..479804bc14adc 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -61,6 +61,8 @@ #include "common/errno.h" #include "common/perf_counters.h" #include "common/admin_socket.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "include/color.h" #include "include/ceph_fs.h" diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc index 297ea17ce075a..1eddd6a2ccc97 100644 --- a/src/mon/Paxos.cc +++ b/src/mon/Paxos.cc @@ -23,6 +23,7 @@ #include "include/assert.h" #include "include/stringify.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_paxos #undef dout_prefix diff --git a/src/mon/Paxos.h b/src/mon/Paxos.h index 457c8af1d267f..0c69f2b204619 100644 --- a/src/mon/Paxos.h +++ b/src/mon/Paxos.h @@ -121,6 +121,9 @@ e 12v #include "common/perf_counters.h" #include +#include "common/Formatter.h" +#include "common/JSONFormatter.h" + #include "MonitorDBStore.h" class Monitor; diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index c6bb6f2c0755d..3c930819b0ce1 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -34,6 +34,8 @@ #include "common/blkdev.h" #include "common/linux_version.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_journal #undef dout_prefix diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index 4f0772e9b646e..b06ddea921f21 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -66,6 +66,8 @@ #include "common/perf_counters.h" #include "common/sync_filesystem.h" #include "common/fd.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "HashIndex.h" #include "DBObjectMap.h" #include "KeyValueDB.h" diff --git a/src/os/FileStore.h b/src/os/FileStore.h index a9291b743c9bc..11a4401233194 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -33,6 +33,8 @@ using namespace std; #include "common/Timer.h" #include "common/WorkQueue.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/Mutex.h" #include "HashIndex.h" diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index 1881f2dcc17ac..64fff67477ac0 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -48,6 +48,8 @@ #include "common/safe_io.h" #include "common/perf_counters.h" #include "common/sync_filesystem.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #ifdef HAVE_KINETIC #include "KineticStore.h" diff --git a/src/os/KeyValueStore.h b/src/os/KeyValueStore.h index ef3085fa0d95b..2519fdf5dee15 100644 --- a/src/os/KeyValueStore.h +++ b/src/os/KeyValueStore.h @@ -33,6 +33,7 @@ using namespace std; #include "common/WorkQueue.h" #include "common/Finisher.h" #include "common/fd.h" +#include "common/JSONFormatter.h" #include "common/Mutex.h" #include "GenericObjectMap.h" diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index a1e1b274ec0e9..67a70ffa55284 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -26,6 +26,8 @@ #include "include/unordered_map.h" #include "include/memory.h" #include "common/errno.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "MemStore.h" #define dout_subsys ceph_subsys_filestore diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index e0c5b3d6b8b96..d1e9cc8ec8f6c 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -43,6 +43,8 @@ #include "common/ceph_argparse.h" #include "common/version.h" #include "common/io_priority.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "os/ObjectStore.h" diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 173b468b5b0ed..54cf9215c402d 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -19,6 +19,7 @@ #include "common/config.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/TextTable.h" #include "include/ceph_features.h" #include "include/str_map.h" diff --git a/src/rbd.cc b/src/rbd.cc index 6f5457d1461f9..1a96177c832e1 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -51,6 +51,8 @@ #include "include/util.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/Throttle.h" #if defined(__linux__) diff --git a/src/rbd_replay/actions.hpp b/src/rbd_replay/actions.hpp index ea46a883362e6..a80ef95064eab 100644 --- a/src/rbd_replay/actions.hpp +++ b/src/rbd_replay/actions.hpp @@ -18,6 +18,7 @@ #include #include "include/rbd/librbd.hpp" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "rbd_replay/ActionTypes.h" #include "rbd_loc.hpp" #include @@ -141,7 +142,7 @@ class TypedAction : public Action { virtual std::ostream& dump(std::ostream& o) const { o << get_action_name() << ": "; - ceph::JSONFormatter formatter(false); + JSONFormatter formatter(false); formatter.open_object_section(""); m_action.dump(&formatter); formatter.close_section(); diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index 45cb2e197eddc..d40700b1de9c9 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -15,6 +15,8 @@ using namespace std; #include "common/config.h" #include "common/ceph_argparse.h" #include "common/Formatter.h" +#include "common/XMLFormatter.h" +#include "common/JSONFormatter.h" #include "common/errno.h" #include "global/global_init.h" diff --git a/src/rgw/rgw_cors_s3.h b/src/rgw/rgw_cors_s3.h index 0db03c3ea1420..6cac6765a311d 100644 --- a/src/rgw/rgw_cors_s3.h +++ b/src/rgw/rgw_cors_s3.h @@ -22,6 +22,7 @@ #include #include +#include #include "rgw_xml.h" #include "rgw_cors.h" diff --git a/src/rgw/rgw_jsonparser.cc b/src/rgw/rgw_jsonparser.cc index b4b709ce8c71f..8531d866e7911 100644 --- a/src/rgw/rgw_jsonparser.cc +++ b/src/rgw/rgw_jsonparser.cc @@ -10,6 +10,7 @@ #include "include/types.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/ceph_json.h" #include "rgw_common.h" diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index 795d78787327e..4d362e26d5052 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -6,6 +6,7 @@ #include "common/utf8.h" #include "common/OutputDataSocket.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "rgw_log.h" #include "rgw_acl.h" diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 98322a069d602..dec2006dd4cfc 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -5,6 +5,8 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/utf8.h" #include "include/str_list.h" #include "rgw_common.h" diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 6b903388b02d4..05ddf9782d2f2 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -6,6 +6,7 @@ #include "common/ceph_crypto.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/utf8.h" #include "common/ceph_json.h" diff --git a/src/rgw/rgw_swift.cc b/src/rgw/rgw_swift.cc index 09fb9b7b92845..06662da2b6a07 100644 --- a/src/rgw/rgw_swift.cc +++ b/src/rgw/rgw_swift.cc @@ -6,6 +6,7 @@ #include #include "common/ceph_json.h" +#include "common/JSONFormatter.h" #include "rgw_common.h" #include "rgw_swift.h" #include "rgw_swift_auth.h" diff --git a/src/rgw/rgw_swift_auth.cc b/src/rgw/rgw_swift_auth.cc index 3e94e63a162ba..5311002ff858b 100644 --- a/src/rgw/rgw_swift_auth.cc +++ b/src/rgw/rgw_swift_auth.cc @@ -6,6 +6,7 @@ #include "common/ceph_crypto.h" #include "common/Clock.h" +#include "common/JSONFormatter.h" #include "auth/Crypto.h" diff --git a/src/test/bench/small_io_bench.cc b/src/test/bench/small_io_bench.cc index 2b200279c7a4b..657d6d0624a1d 100644 --- a/src/test/bench/small_io_bench.cc +++ b/src/test/bench/small_io_bench.cc @@ -14,6 +14,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_dumb.cc b/src/test/bench/small_io_bench_dumb.cc index c9d9f51a9db57..913e8c0a1a333 100644 --- a/src/test/bench/small_io_bench_dumb.cc +++ b/src/test/bench/small_io_bench_dumb.cc @@ -16,6 +16,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_fs.cc b/src/test/bench/small_io_bench_fs.cc index f5845855a1d5f..31bb10e2470ec 100644 --- a/src/test/bench/small_io_bench_fs.cc +++ b/src/test/bench/small_io_bench_fs.cc @@ -14,6 +14,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_rbd.cc b/src/test/bench/small_io_bench_rbd.cc index ba7071ed3833a..95193adf9b610 100644 --- a/src/test/bench/small_io_bench_rbd.cc +++ b/src/test/bench/small_io_bench_rbd.cc @@ -13,6 +13,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "bencher.h" #include "rbd_backend.h" diff --git a/src/test/bench/tp_bench.cc b/src/test/bench/tp_bench.cc index b9d5ff17c8f85..a1221997ca204 100644 --- a/src/test/bench/tp_bench.cc +++ b/src/test/bench/tp_bench.cc @@ -14,6 +14,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/common/test_tableformatter.cc b/src/test/common/test_tableformatter.cc index 88648f01d73b5..c53b69f53652d 100644 --- a/src/test/common/test_tableformatter.cc +++ b/src/test/common/test_tableformatter.cc @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "common/Formatter.h" +#include "common/TableFormatter.h" #include #include #include diff --git a/src/test/crush/crush.cc b/src/test/crush/crush.cc index c46fa87ab5409..1fafbd337072e 100644 --- a/src/test/crush/crush.cc +++ b/src/test/crush/crush.cc @@ -13,6 +13,7 @@ #include "include/stringify.h" #include "common/ceph_argparse.h" +#include "common/JSONFormatter.h" #include "global/global_init.h" #include "global/global_context.h" diff --git a/src/test/encoding/ceph_dencoder.cc b/src/test/encoding/ceph_dencoder.cc index 7e1056503ce01..7386a7d563010 100644 --- a/src/test/encoding/ceph_dencoder.cc +++ b/src/test/encoding/ceph_dencoder.cc @@ -5,6 +5,7 @@ #include "include/ceph_features.h" #include "common/ceph_argparse.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/errno.h" #include "msg/Message.h" #include "include/assert.h" diff --git a/src/test/formatter.cc b/src/test/formatter.cc index aab7e59259504..37c384d3974e2 100644 --- a/src/test/formatter.cc +++ b/src/test/formatter.cc @@ -13,7 +13,8 @@ */ #include "test/unit.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include #include diff --git a/src/test/kv_store_bench.h b/src/test/kv_store_bench.h index d12c5e850c0b1..9be1e31386b9c 100644 --- a/src/test/kv_store_bench.h +++ b/src/test/kv_store_bench.h @@ -20,6 +20,7 @@ #include "global/global_context.h" #include "common/Mutex.h" #include "common/Cond.h" +#include "common/JSONFormatter.h" #include #include diff --git a/src/test/mon/test_mon_workloadgen.cc b/src/test/mon/test_mon_workloadgen.cc index e18906d193148..36e36ba6c95da 100644 --- a/src/test/mon/test_mon_workloadgen.cc +++ b/src/test/mon/test_mon_workloadgen.cc @@ -51,6 +51,7 @@ #include "auth/AuthAuthorizeHandler.h" #include "include/uuid.h" #include "include/assert.h" +#include "common/JSONFormatter.h" #include "messages/MOSDBoot.h" #include "messages/MOSDAlive.h" diff --git a/src/test/test_rgw_admin_meta.cc b/src/test/test_rgw_admin_meta.cc index 74bc8ed1ec867..b2213fc2afa72 100644 --- a/src/test/test_rgw_admin_meta.cc +++ b/src/test/test_rgw_admin_meta.cc @@ -30,6 +30,8 @@ extern "C"{ #include "common/code_environment.h" #include "common/ceph_argparse.h" #include "common/Finisher.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "global/global_init.h" #include "rgw/rgw_common.h" #include "rgw/rgw_rados.h" diff --git a/src/tools/ceph-client-debug.cc b/src/tools/ceph-client-debug.cc index 2ed93326b4433..20948bc527c98 100644 --- a/src/tools/ceph-client-debug.cc +++ b/src/tools/ceph-client-debug.cc @@ -15,7 +15,7 @@ #include "common/ceph_argparse.h" #include "global/global_init.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/debug.h" #include "common/errno.h" #include "client/Inode.h" diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 744000eba872e..9190d7c050504 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -16,7 +16,7 @@ #include #include -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/errno.h" #include "global/global_init.h" diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 9e6894664ca8c..9ad502bdef7ef 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -19,6 +19,7 @@ #include #include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/errno.h" #include "common/ceph_argparse.h" diff --git a/src/tools/cephfs/EventOutput.cc b/src/tools/cephfs/EventOutput.cc index a93c099a918d1..a273c511b5506 100644 --- a/src/tools/cephfs/EventOutput.cc +++ b/src/tools/cephfs/EventOutput.cc @@ -16,6 +16,7 @@ #include #include "common/errno.h" +#include "common/JSONFormatter.h" #include "mds/mdstypes.h" #include "mds/events/EUpdate.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index 6118320435948..360782c141eb4 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -16,6 +16,7 @@ #include "common/ceph_argparse.h" #include "common/errno.h" +#include "common/JSONFormatter.h" #include "osdc/Journaler.h" #include "mds/mdstypes.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/TableTool.cc b/src/tools/cephfs/TableTool.cc index 4b22de04f7231..005d8b4c6000f 100644 --- a/src/tools/cephfs/TableTool.cc +++ b/src/tools/cephfs/TableTool.cc @@ -14,6 +14,8 @@ #include "common/ceph_argparse.h" #include "common/errno.h" +#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "mds/SessionMap.h" #include "mds/InoTable.h" diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 4b96ac5ae4a10..a727c162ae37c 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -26,6 +26,8 @@ using namespace librados; #include "common/debug.h" #include "common/errno.h" #include "common/Formatter.h" +#include "common/JSONFormatter.h" +#include "common/XMLFormatter.h" #include "common/obj_bencher.h" #include "mds/inode_backtrace.h" #include "auth/Crypto.h" From cc544de6afce3478c6b0fc8b1219ededc3e264ea Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Aug 2015 02:42:56 +0000 Subject: [PATCH 02/90] common/HTMLFormatter: add new formatter StaticSites/S3Website has error output in HTML, for which we need a new formatter. It's implemented by extending the existing XMLFormatter. This will print the actual entries, but not any document structure around them. Unless otherwise documented, this codes strives for the Amazon format of:
  • key: value
  • Signed-off-by: Robin H. Johnson --- src/common/Formatter.cc | 5 ++ src/common/HTMLFormatter.cc | 109 +++++++++++++++++++++++++++ src/common/HTMLFormatter.h | 41 +++++++++++ src/common/Makefile.am | 2 + src/common/XMLFormatter.h | 2 +- src/rgw/rgw_common.h | 1 + src/rgw/rgw_rest.cc | 11 +++ src/test/formatter.cc | 143 ++++++++++++++++++++++++++++++++++++ 8 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 src/common/HTMLFormatter.cc create mode 100644 src/common/HTMLFormatter.h diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 9670aa22e51be..8bbb25b6c4d89 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -21,6 +21,7 @@ #include "JSONFormatter.h" #include "TableFormatter.h" #include "XMLFormatter.h" +#include "HTMLFormatter.h" #include "common/escape.h" #include @@ -86,6 +87,10 @@ Formatter *Formatter::create(const std::string &type, return new TableFormatter(); else if (mytype == "table-kv") return new TableFormatter(true); + else if (mytype == "html") + return new HTMLFormatter(false); + else if (mytype == "html-pretty") + return new HTMLFormatter(true); else if (fallback != "") return create(fallback, "", ""); else diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc new file mode 100644 index 0000000000000..1b8688c7be754 --- /dev/null +++ b/src/common/HTMLFormatter.cc @@ -0,0 +1,109 @@ +// -*- 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) 2011 New Dream Network + * + * 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. + * + */ + +#define LARGE_SIZE 1024 + +#include "include/int_types.h" + +#include "assert.h" +#include "Formatter.h" +#include "HTMLFormatter.h" +#include "XMLFormatter.h" +#include "common/escape.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// ----------------------- +namespace ceph { + +HTMLFormatter::HTMLFormatter(bool pretty) +: XMLFormatter(pretty) +{ +} + +template +void HTMLFormatter::dump_template(const char *name, T arg) +{ + print_spaces(); + m_ss << "
  • " << name << ": " << arg << "
  • "; + if (m_pretty) + m_ss << "\n"; +} + +void HTMLFormatter::dump_unsigned(const char *name, uint64_t u) +{ + dump_template(name, u); +} + +void HTMLFormatter::dump_int(const char *name, int64_t u) +{ + dump_template(name, u); +} + +void HTMLFormatter::dump_float(const char *name, double d) +{ + dump_template(name, d); +} + +void HTMLFormatter::dump_string(const char *name, const std::string& s) +{ + dump_template(name, escape_xml_str(s.c_str())); +} + +void HTMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +{ + std::string e(name); + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + print_spaces(); + m_ss << "
  • " << e << ": " << escape_xml_str(s.c_str()) << attrs_str << "
  • "; + if (m_pretty) + m_ss << "\n"; +} + +std::ostream& HTMLFormatter::dump_stream(const char *name) +{ + print_spaces(); + m_pending_string_name = "li"; + m_ss << "
  • " << name << ": "; + return m_pending_string; +} + +void HTMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + std::string e(name); + print_spaces(); + if (ns) { + m_ss << "
  • " << e << ": " << escape_xml_str(buf) << "
  • "; + } else { + m_ss << "
  • " << e << ": " << escape_xml_str(buf) << "
  • "; + } + + if (m_pretty) + m_ss << "\n"; +} + + +} // namespace ceph diff --git a/src/common/HTMLFormatter.h b/src/common/HTMLFormatter.h new file mode 100644 index 0000000000000..fa2b551d8f4f2 --- /dev/null +++ b/src/common/HTMLFormatter.h @@ -0,0 +1,41 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab +#ifndef CEPH_HTML_FORMATTER_H +#define CEPH_HTML_FORMATTER_H + +#include "include/int_types.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "include/buffer.h" +#include "XMLFormatter.h" + +namespace ceph { + class HTMLFormatter : public XMLFormatter { + public: + HTMLFormatter(bool pretty = false); + + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + + /* with attrs */ + void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); + private: + template void dump_template(const char *name, T arg); + + }; + +} + +#endif diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 1cb6a3cf1977f..6f1f11c3c7500 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -46,6 +46,7 @@ libcommon_internal_la_SOURCES = \ common/Thread.cc \ common/Formatter.cc \ common/XMLFormatter.cc \ + common/HTMLFormatter.cc \ common/JSONFormatter.cc \ common/TableFormatter.cc \ common/HeartbeatMap.cc \ @@ -184,6 +185,7 @@ noinst_HEADERS += \ common/JSONFormatter.h \ common/TableFormatter.h \ common/XMLFormatter.h \ + common/HTMLFormatter.h \ common/perf_counters.h \ common/OutputDataSocket.h \ common/admin_socket.h \ diff --git a/src/common/XMLFormatter.h b/src/common/XMLFormatter.h index 87ca99894771b..2f47cec0abf8a 100644 --- a/src/common/XMLFormatter.h +++ b/src/common/XMLFormatter.h @@ -43,7 +43,7 @@ namespace ceph { void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - private: + protected: void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); void finish_pending_string(); void print_spaces(); diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index aa348c53901b5..b23f017f1f6e2 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -86,6 +86,7 @@ using ceph::crypto::MD5; #define RGW_FORMAT_PLAIN 0 #define RGW_FORMAT_XML 1 #define RGW_FORMAT_JSON 2 +#define RGW_FORMAT_HTML 3 #define RGW_CAP_READ 0x1 #define RGW_CAP_WRITE 0x2 diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index dec2006dd4cfc..fa5533d926c3b 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -7,6 +7,7 @@ #include "common/Formatter.h" #include "common/JSONFormatter.h" #include "common/XMLFormatter.h" +#include "common/HTMLFormatter.h" #include "common/utf8.h" #include "include/str_list.h" #include "rgw_common.h" @@ -607,6 +608,9 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const case RGW_FORMAT_JSON: ctype = "application/json"; break; + case RGW_FORMAT_HTML: + ctype = "text/html"; + break; default: ctype = "text/plain"; break; @@ -1195,6 +1199,8 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ s->format = RGW_FORMAT_XML; } else if (format_str.compare("json") == 0) { s->format = RGW_FORMAT_JSON; + } else if (format_str.compare("html") == 0) { + s->format = RGW_FORMAT_HTML; } else { const char *accept = s->info.env->get("HTTP_ACCEPT"); if (accept) { @@ -1208,6 +1214,8 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ s->format = RGW_FORMAT_XML; } else if (strcmp(format_buf, "application/json") == 0) { s->format = RGW_FORMAT_JSON; + } else if (strcmp(format_buf, "text/html") == 0) { + s->format = RGW_FORMAT_HTML; } } } @@ -1223,6 +1231,9 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ case RGW_FORMAT_JSON: s->formatter = new JSONFormatter(false); break; + case RGW_FORMAT_HTML: + s->formatter = new HTMLFormatter(false); + break; default: return -EINVAL; diff --git a/src/test/formatter.cc b/src/test/formatter.cc index 37c384d3974e2..2a5373049c325 100644 --- a/src/test/formatter.cc +++ b/src/test/formatter.cc @@ -15,6 +15,7 @@ #include "test/unit.h" #include "common/JSONFormatter.h" #include "common/XMLFormatter.h" +#include "common/HTMLFormatter.h" #include #include @@ -198,3 +199,145 @@ TEST(XmlFormatter, DumpFormatNameSpaceTest) { fmt.flush(oss2); ASSERT_EQ(oss2.str(),"bar"); } + +TEST(HtmlFormatter, Simple1) { + ostringstream oss; + HTMLFormatter fmt(false); + fmt.open_object_section("foo"); + fmt.dump_int("a", 1); + fmt.dump_int("b", 2); + fmt.dump_int("c", 3); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "
  • a: 1
  • b: 2
  • c: 3
  • "); +} + +TEST(HtmlFormatter, Simple2) { + ostringstream oss; + HTMLFormatter fmt(false); + fmt.open_object_section("foo"); + fmt.open_object_section("bar"); + fmt.dump_int("int", 0xf00000000000ll); + fmt.dump_unsigned("unsigned", 0x8000000000000001llu); + fmt.dump_float("float", 1.234); + fmt.close_section(); + fmt.dump_string("string", "str"); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "\ +
  • int: 263882790666240
  • \ +
  • unsigned: 9223372036854775809
  • \ +
  • float: 1.234
  • \ +
  • string: str
  • \ +
    "); +} + +TEST(HtmlFormatter, Empty) { + ostringstream oss; + HTMLFormatter fmt(false); + fmt.flush(oss); + ASSERT_EQ(oss.str(), ""); +} + +TEST(HtmlFormatter, DumpStream1) { + ostringstream oss; + HTMLFormatter fmt(false); + fmt.dump_stream("blah") << "hithere"; + fmt.flush(oss); + ASSERT_EQ(oss.str(), "
  • blah: hithere
  • "); +} + +TEST(HtmlFormatter, DumpStream2) { + ostringstream oss; + HTMLFormatter fmt(false); + + fmt.open_array_section("foo"); + fmt.dump_stream("blah") << "hithere"; + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "
  • blah: hithere
  • "); +} + +TEST(HtmlFormatter, DumpStream3) { + ostringstream oss; + HTMLFormatter fmt(false); + + fmt.open_array_section("foo"); + fmt.dump_stream("blah") << "hithere"; + fmt.dump_float("pi", 3.14); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "
  • blah: hithere
  • pi: 3.14
  • "); +} + +TEST(HtmlFormatter, DTD) { + ostringstream oss; + HTMLFormatter fmt(false); + + fmt.write_raw_data(HTMLFormatter::XML_1_DTD); + fmt.open_array_section("foo"); + fmt.dump_stream("blah") << "hithere"; + fmt.dump_float("pi", 3.14); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "" + "
  • blah: hithere
  • pi: 3.14
  • "); +} + +TEST(HtmlFormatter, Clear) { + ostringstream oss; + HTMLFormatter fmt(false); + + fmt.write_raw_data(HTMLFormatter::XML_1_DTD); + fmt.open_array_section("foo"); + fmt.dump_stream("blah") << "hithere"; + fmt.dump_float("pi", 3.14); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "" + "
  • blah: hithere
  • pi: 3.14
  • "); + + ostringstream oss2; + fmt.flush(oss2); + ASSERT_EQ(oss2.str(), ""); + + ostringstream oss3; + fmt.reset(); + fmt.flush(oss3); + ASSERT_EQ(oss3.str(), ""); +} + +TEST(HtmlFormatter, NamespaceTest) { + ostringstream oss; + HTMLFormatter fmt(false); + + fmt.write_raw_data(HTMLFormatter::XML_1_DTD); + fmt.open_array_section_in_ns("foo", + "http://s3.amazonaws.com/doc/2006-03-01/"); + fmt.dump_stream("blah") << "hithere"; + fmt.dump_float("pi", 3.14); + fmt.close_section(); + fmt.flush(oss); + ASSERT_EQ(oss.str(), "" + "" + "
  • blah: hithere
  • pi: 3.14
  • "); +} + +TEST(HtmlFormatter, DumpFormatNameSpaceTest) { + ostringstream oss1; + HTMLFormatter fmt(false); + + fmt.dump_format_ns("foo", + "http://s3.amazonaws.com/doc/2006-03-01/", + "%s","bar"); + fmt.flush(oss1); + ASSERT_EQ(oss1.str(), + "
  • foo: bar
  • "); + + // Testing with a null ns..should be same as dump format + ostringstream oss2; + fmt.reset(); + fmt.dump_format_ns("foo",NULL,"%s","bar"); + fmt.flush(oss2); + ASSERT_EQ(oss2.str(),"
  • foo: bar
  • "); +} From a228e453efaf8d359343d6a6f04bae2e5152d98a Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Aug 2015 02:43:00 +0000 Subject: [PATCH 03/90] common/*Formatters: handling of headers & footers. Formatters now gain first-class headers and footers, along with consistent handling of having header/footer only output ONCE. Signed-off-by: Robin H. Johnson --- src/common/Formatter.h | 4 +++ src/common/HTMLFormatter.cc | 61 +++++++++++++++++++++++++++++++++++-- src/common/HTMLFormatter.h | 9 ++++++ src/common/JSONFormatter.h | 3 ++ src/common/TableFormatter.h | 3 ++ src/common/XMLFormatter.cc | 25 +++++++++++++-- src/common/XMLFormatter.h | 5 +++ src/rgw/rgw_formats.h | 3 ++ src/test/formatter.cc | 6 ++-- 9 files changed, 112 insertions(+), 7 deletions(-) diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 8fdd9d81e59a8..43d521d10dc51 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -50,6 +50,10 @@ namespace ceph { } virtual void reset() = 0; + virtual void set_status(const char* status, const char* status_name) = 0; + virtual void output_header() = 0; + virtual void output_footer() = 0; + virtual void open_array_section(const char *name) = 0; virtual void open_array_section_in_ns(const char *name, const char *ns) = 0; virtual void open_object_section(const char *name) = 0; diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc index 1b8688c7be754..516282b830b76 100644 --- a/src/common/HTMLFormatter.cc +++ b/src/common/HTMLFormatter.cc @@ -36,10 +36,68 @@ namespace ceph { HTMLFormatter::HTMLFormatter(bool pretty) -: XMLFormatter(pretty) +: XMLFormatter(pretty), m_header_done(false), m_status(NULL), m_status_name(NULL) { } +HTMLFormatter::~HTMLFormatter() +{ + if(m_status) { + free((void*)m_status); + m_status = NULL; + } + if(m_status_name) { + free((void*)m_status_name); + m_status_name = NULL; + } +} + +void HTMLFormatter::reset() +{ + XMLFormatter::reset(); + m_header_done = false; + if(m_status) { + free((void*)m_status); + m_status = NULL; + } + if(m_status_name) { + free((void*)m_status_name); + m_status_name = NULL; + } +} + +void HTMLFormatter::set_status(const char* status, const char* status_name) +{ + assert(status != NULL); // new status must not be NULL + assert(m_status == NULL); // status should NOT be set multiple times + m_status = strdup(status); + if(status_name) + m_status_name = strdup(status_name); +}; + +void HTMLFormatter::output_header() { + if(!m_header_done) { + m_header_done = true; + assert(m_status != NULL); // it should be set by this point + std::string status_line(m_status); + if(m_status_name) { + status_line += " "; + status_line += m_status_name; + } + open_object_section("html"); + print_spaces(); + m_ss << "" << status_line << ""; + if (m_pretty) + m_ss << "\n"; + open_object_section("body"); + print_spaces(); + m_ss << "

    " << status_line << "

    "; + if (m_pretty) + m_ss << "\n"; + open_object_section("ul"); + } +} + template void HTMLFormatter::dump_template(const char *name, T arg) { @@ -105,5 +163,4 @@ void HTMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted m_ss << "\n"; } - } // namespace ceph diff --git a/src/common/HTMLFormatter.h b/src/common/HTMLFormatter.h index fa2b551d8f4f2..a8c6b20a78b21 100644 --- a/src/common/HTMLFormatter.h +++ b/src/common/HTMLFormatter.h @@ -21,6 +21,11 @@ namespace ceph { class HTMLFormatter : public XMLFormatter { public: HTMLFormatter(bool pretty = false); + ~HTMLFormatter(); + void reset(); + + virtual void set_status(const char* status, const char* status_name); + virtual void output_header(); void dump_unsigned(const char *name, uint64_t u); void dump_int(const char *name, int64_t u); @@ -34,6 +39,10 @@ namespace ceph { private: template void dump_template(const char *name, T arg); + bool m_header_done; + + const char* m_status; + const char* m_status_name; }; } diff --git a/src/common/JSONFormatter.h b/src/common/JSONFormatter.h index 895be2913c0f1..a6a50928be446 100644 --- a/src/common/JSONFormatter.h +++ b/src/common/JSONFormatter.h @@ -22,6 +22,9 @@ namespace ceph { public: JSONFormatter(bool p = false); + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header() {}; + virtual void output_footer() {}; void flush(std::ostream& os); void reset(); virtual void open_array_section(const char *name); diff --git a/src/common/TableFormatter.h b/src/common/TableFormatter.h index 950341c7af78b..ba8f66823ec7e 100644 --- a/src/common/TableFormatter.h +++ b/src/common/TableFormatter.h @@ -22,6 +22,9 @@ namespace ceph { public: TableFormatter(bool keyval = false); + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header() {}; + virtual void output_footer() {}; void flush(std::ostream& os); void reset(); virtual void open_array_section(const char *name); diff --git a/src/common/XMLFormatter.cc b/src/common/XMLFormatter.cc index 4bc6603e299dc..084fd40eaf85d 100644 --- a/src/common/XMLFormatter.cc +++ b/src/common/XMLFormatter.cc @@ -46,8 +46,11 @@ XMLFormatter::XMLFormatter(bool pretty) void XMLFormatter::flush(std::ostream& os) { finish_pending_string(); - os << m_ss.str(); - if (m_pretty) + std::string m_ss_str = m_ss.str(); + os << m_ss_str; + /* There is a small catch here. If the rest of the formatter had NO output, + * we should NOT output a newline. This primarily triggers on HTTP redirects */ + if (m_pretty && !m_ss_str.empty()) os << "\n"; m_ss.clear(); m_ss.str(""); @@ -61,6 +64,24 @@ void XMLFormatter::reset() m_pending_string.str(""); m_sections.clear(); m_pending_string_name.clear(); + m_header_done = false; +} + +void XMLFormatter::output_header() +{ + if(!m_header_done) { + m_header_done = true; + write_raw_data(XMLFormatter::XML_1_DTD);; + if (m_pretty) + m_ss << "\n"; + } +} + +void XMLFormatter::output_footer() +{ + while(!m_sections.empty()) { + close_section(); + } } void XMLFormatter::open_object_section(const char *name) diff --git a/src/common/XMLFormatter.h b/src/common/XMLFormatter.h index 2f47cec0abf8a..f455f5dc8654f 100644 --- a/src/common/XMLFormatter.h +++ b/src/common/XMLFormatter.h @@ -23,6 +23,10 @@ namespace ceph { static const char *XML_1_DTD; XMLFormatter(bool pretty = false); + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header(); + virtual void output_footer(); + void flush(std::ostream& os); void reset(); void open_array_section(const char *name); @@ -54,6 +58,7 @@ namespace ceph { std::deque m_sections; bool m_pretty; std::string m_pending_string_name; + bool m_header_done; }; } diff --git a/src/rgw/rgw_formats.h b/src/rgw/rgw_formats.h index 6f7925e393147..1a22f8093c337 100644 --- a/src/rgw/rgw_formats.h +++ b/src/rgw/rgw_formats.h @@ -25,6 +25,9 @@ class RGWFormatter_Plain : public Formatter { RGWFormatter_Plain(); virtual ~RGWFormatter_Plain(); + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header() {}; + virtual void output_footer() {}; virtual void flush(ostream& os); virtual void reset(); diff --git a/src/test/formatter.cc b/src/test/formatter.cc index 2a5373049c325..cf1e412758a2b 100644 --- a/src/test/formatter.cc +++ b/src/test/formatter.cc @@ -132,7 +132,7 @@ TEST(XmlFormatter, DTD) { ostringstream oss; XMLFormatter fmt(false); - fmt.write_raw_data(XMLFormatter::XML_1_DTD); + fmt.output_header(); fmt.open_array_section("foo"); fmt.dump_stream("blah") << "hithere"; fmt.dump_float("pi", 3.14); @@ -146,7 +146,7 @@ TEST(XmlFormatter, Clear) { ostringstream oss; XMLFormatter fmt(false); - fmt.write_raw_data(XMLFormatter::XML_1_DTD); + fmt.output_header(); fmt.open_array_section("foo"); fmt.dump_stream("blah") << "hithere"; fmt.dump_float("pi", 3.14); @@ -169,7 +169,7 @@ TEST(XmlFormatter, NamespaceTest) { ostringstream oss; XMLFormatter fmt(false); - fmt.write_raw_data(XMLFormatter::XML_1_DTD); + fmt.output_header(); fmt.open_array_section_in_ns("foo", "http://s3.amazonaws.com/doc/2006-03-01/"); fmt.dump_stream("blah") << "hithere"; From c0bacef4fe7f2fa0879febbb48dfbadf858f812f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 26 Nov 2014 16:34:04 -0800 Subject: [PATCH 04/90] rgw: define data structures for static website config move website rules to separate file, check rules, and implement key modification functionality Signed-off-by: Yehuda Sadeh Conflicts: src/rgw/Makefile.am --- src/rgw/Makefile.am | 3 +- src/rgw/rgw_common.h | 23 +++++- src/rgw/rgw_json_enc.cc | 82 +++++++++++++++++++ src/rgw/rgw_website.cc | 69 ++++++++++++++++ src/rgw/rgw_website.h | 171 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 344 insertions(+), 4 deletions(-) create mode 100644 src/rgw/rgw_website.cc create mode 100644 src/rgw/rgw_website.h diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index 7620d73b053d1..4e4f614fb8fb9 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -45,7 +45,8 @@ librgw_la_SOURCES = \ rgw/rgw_replica_log.cc \ rgw/rgw_keystone.cc \ rgw/rgw_quota.cc \ - rgw/rgw_dencoder.cc + rgw/rgw_dencoder.cc \ + rgw/rgw_website.cc librgw_la_CXXFLAGS = -Woverloaded-virtual ${AM_CXXFLAGS} noinst_LTLIBRARIES += librgw.la diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index b23f017f1f6e2..bcc83e64097f3 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -31,6 +31,7 @@ #include "rgw_cors.h" #include "rgw_quota.h" #include "rgw_string.h" +#include "rgw_website.h" #include "cls/version/cls_version_types.h" #include "cls/user/cls_user_types.h" #include "cls/rgw/cls_rgw_types.h" @@ -789,8 +790,11 @@ struct RGWBucketInfo // Represents the shard number for blind bucket. const static uint32_t NUM_SHARDS_BLIND_BUCKET; + bool has_website; + RGWBucketWebsiteConf website_conf; + void encode(bufferlist& bl) const { - ENCODE_START(11, 4, bl); + ENCODE_START(12, 4, bl); ::encode(bucket, bl); ::encode(owner, bl); ::encode(flags, bl); @@ -802,10 +806,14 @@ struct RGWBucketInfo ::encode(quota, bl); ::encode(num_shards, bl); ::encode(bucket_index_shard_hash_type, bl); + ::encode(has_website, bl); + if (has_website) { + ::encode(website_conf, bl); + } ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START_LEGACY_COMPAT_LEN_32(9, 4, 4, bl); + DECODE_START_LEGACY_COMPAT_LEN_32(12, 4, 4, bl); ::decode(bucket, bl); if (struct_v >= 2) ::decode(owner, bl); @@ -828,6 +836,14 @@ struct RGWBucketInfo ::decode(num_shards, bl); if (struct_v >= 11) ::decode(bucket_index_shard_hash_type, bl); + if (struct_v >= 12) { + ::decode(has_website, bl); + if (has_website) { + ::decode(website_conf, bl); + } else { + website_conf = RGWBucketWebsiteConf(); + } + } DECODE_FINISH(bl); } void dump(Formatter *f) const; @@ -839,7 +855,8 @@ struct RGWBucketInfo int versioning_status() { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); } bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED; } - RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD) {} + RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), + has_website(false) {} }; WRITE_CLASS_ENCODER(RGWBucketInfo) diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index dbaa8253eaa3c..3254c010819b0 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -537,6 +537,80 @@ void RGWStorageStats::dump(Formatter *f) const encode_json("num_objects", num_objects, f); } +void RGWRedirectInfo::dump(Formatter *f) const +{ + encode_json("protocol", protocol, f); + encode_json("hostname", hostname, f); + encode_json("http_redirect_code", (int)http_redirect_code, f); +} + +void RGWRedirectInfo::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("protocol", protocol, obj); + JSONDecoder::decode_json("hostname", hostname, obj); + int code; + JSONDecoder::decode_json("http_redirect_code", code, obj); + http_redirect_code = code; +} + +void RGWBWRedirectInfo::dump(Formatter *f) const +{ + encode_json("redirect", redirect, f); + encode_json("replace_key_prefix_with", replace_key_prefix_with, f); + encode_json("replace_key_with", replace_key_with, f); +} + +void RGWBWRedirectInfo::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("redirect", redirect, obj); + JSONDecoder::decode_json("replace_key_prefix_with", replace_key_prefix_with, obj); + JSONDecoder::decode_json("replace_key_with", replace_key_with, obj); +} + +void RGWBWRoutingRuleCondition::dump(Formatter *f) const +{ + encode_json("key_prefix_equals", key_prefix_equals, f); + encode_json("http_error_code_returned_equals", (int)http_error_code_returned_equals, f); +} + +void RGWBWRoutingRuleCondition::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("key_prefix_equals", key_prefix_equals, obj); + int code; + JSONDecoder::decode_json("http_error_code_returned_equals", code, obj); + http_error_code_returned_equals = code; +} + +void RGWBWRoutingRule::dump(Formatter *f) const +{ + encode_json("condition", condition, f); + encode_json("redirect_info", redirect_info, f); +} + +void RGWBWRoutingRule::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("condition", condition, obj); + JSONDecoder::decode_json("redirect_info", redirect_info, obj); +} + +void RGWBWRoutingRules::dump(Formatter *f) const +{ + encode_json("rules", rules, f); +} + +void RGWBWRoutingRules::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("rules", rules, obj); +} + +void RGWBucketWebsiteConf::dump(Formatter *f) const +{ + encode_json("index_doc_suffix", index_doc_suffix, f); + encode_json("error_doc", error_doc, f); + encode_json("routing_rules", routing_rules, f); +} + +void RGWBucketWebsiteConf::decode_json(JSONObj *obj) { + JSONDecoder::decode_json("index_doc_suffix", index_doc_suffix, obj); + JSONDecoder::decode_json("error_doc", error_doc, obj); + JSONDecoder::decode_json("routing_rules", routing_rules, obj); +} + void RGWBucketInfo::dump(Formatter *f) const { encode_json("bucket", bucket, f); @@ -549,6 +623,10 @@ void RGWBucketInfo::dump(Formatter *f) const encode_json("quota", quota, f); encode_json("num_shards", num_shards, f); encode_json("bi_shard_hash_type", (uint32_t)bucket_index_shard_hash_type, f); + encode_json("has_website", has_website, f); + if (has_website) { + encode_json("website_conf", website_conf, f); + } } void RGWBucketInfo::decode_json(JSONObj *obj) { @@ -564,6 +642,10 @@ void RGWBucketInfo::decode_json(JSONObj *obj) { uint32_t hash_type; JSONDecoder::decode_json("bi_shard_hash_type", hash_type, obj); bucket_index_shard_hash_type = (uint8_t)hash_type; + JSONDecoder::decode_json("has_website", has_website, obj); + if (has_website) { + JSONDecoder::decode_json("website_conf", website_conf, obj); + } } void RGWObjEnt::dump(Formatter *f) const diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc new file mode 100644 index 0000000000000..60e75a5be2830 --- /dev/null +++ b/src/rgw/rgw_website.cc @@ -0,0 +1,69 @@ +#include "common/debug.h" +#include "common/ceph_json.h" + +#include "acconfig.h" + +#include +#include +#include +#include "include/types.h" +#include "rgw_website.h" + +using namespace std; + + +bool RGWBWRoutingRuleCondition::check_key_condition(const string& key) { + return (key.size() >= key_prefix_equals.size() && + key.compare(0, key_prefix_equals.size(), key_prefix_equals) == 0); +} + + +bool RGWBWRoutingRules::check_key_condition(const string& key, RGWBWRoutingRule **rule) +{ + for (list::iterator iter = rules.begin(); iter != rules.end(); ++iter) { + if (iter->check_key_condition(key)) { + *rule = &(*iter); + return true; + } + } + return false; +} + +bool RGWBWRoutingRules::check_error_code_condition(int error_code, RGWBWRoutingRule **rule) +{ + for (list::iterator iter = rules.begin(); iter != rules.end(); ++iter) { + if (iter->check_error_code_condition(error_code)) { + *rule = &(*iter); + return true; + } + } + return false; +} + +void RGWBucketWebsiteConf::get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect) +{ + RGWBWRoutingRule *rule; + string new_key; + + if (routing_rules.check_key_condition(key, &rule)) { + RGWBWRoutingRuleCondition& condition = rule->condition; + RGWBWRedirectInfo& info = rule->redirect_info; + + if (!info.replace_key_prefix_with.empty()) { + *effective_key = info.replace_key_prefix_with; + *effective_key += key.substr(condition.key_prefix_equals.size()); + } else if (!info.replace_key_with.empty()) { + *effective_key = info.replace_key_with; + } else { + *effective_key = key; + } + + *redirect = info.redirect; + } + + if (effective_key->empty()) { + *effective_key = index_doc_suffix; + } else if ((*effective_key)[effective_key->size() - 1] == '/') { + *effective_key += index_doc_suffix; + } +} diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h new file mode 100644 index 0000000000000..3e3e846e2355e --- /dev/null +++ b/src/rgw/rgw_website.h @@ -0,0 +1,171 @@ +#ifndef RGW_WEBSITE_H +#define RGW_WEBSITE_H + +struct RGWRedirectInfo +{ + string protocol; + string hostname; + uint16_t http_redirect_code; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(protocol, bl); + ::encode(hostname, bl); + ::encode(http_redirect_code, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(protocol, bl); + ::decode(hostname, bl); + ::decode(http_redirect_code, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWRedirectInfo) + + +struct RGWBWRedirectInfo +{ + RGWRedirectInfo redirect; + string replace_key_prefix_with; + string replace_key_with; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(redirect, bl); + ::encode(replace_key_prefix_with, bl); + ::encode(replace_key_with, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(redirect, bl); + ::decode(replace_key_prefix_with, bl); + ::decode(replace_key_with, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); +}; +WRITE_CLASS_ENCODER(RGWBWRedirectInfo) + +struct RGWBWRoutingRuleCondition +{ + string key_prefix_equals; + uint16_t http_error_code_returned_equals; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(key_prefix_equals, bl); + ::encode(http_error_code_returned_equals, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(key_prefix_equals, bl); + ::decode(http_error_code_returned_equals, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); + + bool check_key_condition(const string& key); + bool check_error_code_condition(int error_code) { + return (uint16_t)error_code == http_error_code_returned_equals; + } +}; +WRITE_CLASS_ENCODER(RGWBWRoutingRuleCondition) + +struct RGWBWRoutingRule +{ + RGWBWRoutingRuleCondition condition; + RGWBWRedirectInfo redirect_info; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(condition, bl); + ::encode(redirect_info, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(condition, bl); + ::decode(redirect_info, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); + + bool check_key_condition(const string& key) { + return condition.check_key_condition(key); + } + bool check_error_code_condition(int error_code) { + return condition.check_error_code_condition(error_code); + } +}; +WRITE_CLASS_ENCODER(RGWBWRoutingRule) + +struct RGWBWRoutingRules +{ + list rules; + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(rules, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(rules, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); + + bool check_key_condition(const string& key, RGWBWRoutingRule **rule); + bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule); +}; +WRITE_CLASS_ENCODER(RGWBWRoutingRules) + +struct RGWBucketWebsiteConf +{ + RGWRedirectInfo redirect_all; + string index_doc_suffix; + string error_doc; + RGWBWRoutingRules routing_rules; + + RGWBucketWebsiteConf() {} + + void encode(bufferlist& bl) const { + ENCODE_START(1, 1, bl); + ::encode(index_doc_suffix, bl); + ::encode(error_doc, bl); + ::encode(routing_rules, bl); + ::encode(redirect_all, bl); + ENCODE_FINISH(bl); + } + void decode(bufferlist::iterator& bl) { + DECODE_START(1, bl); + ::decode(index_doc_suffix, bl); + ::decode(error_doc, bl); + ::decode(routing_rules, bl); + ::decode(redirect_all, bl); + DECODE_FINISH(bl); + } + + void dump(Formatter *f) const; + void decode_json(JSONObj *obj); + + void get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect); +}; +WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) + +#endif From b0b8852d0300da9e7399740efc1446af25ba3322 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 19 Mar 2015 22:28:04 -0700 Subject: [PATCH 05/90] rgw: retarget requests Signed-off-by: Yehuda Sadeh Conflicts: src/rgw/rgw_main.cc src/rgw/rgw_op.h --- src/rgw/rgw_main.cc | 17 +++++++++++++++++ src/rgw/rgw_op.cc | 40 ++++++++++++++++++++++++++++++++++------ src/rgw/rgw_op.h | 18 ++++++++++++++++++ src/rgw/rgw_rest.cc | 32 ++++++++++++++++++++++++++++++++ src/rgw/rgw_rest.h | 2 ++ 5 files changed, 103 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 487835cd56afd..f57f4bb53c3db 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -632,6 +632,23 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC goto done; } + req->log(s, "init permissions"); + ret = handler->init_permissions(); + if (ret < 0) { + abort_early(s, op, ret); + goto done; + } + + if (op->supports_website()) { + req->log(s, "recalculating target"); + ret = handler->retarget(op, &op); + if (ret < 0) { + abort_early(s, op, ret); + goto done; + } + req->op = op; + } + // This reads the ACL on the bucket or object req->log(s, "reading permissions"); ret = handler->read_permissions(op); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index b4b4c8a3c48e5..af806f38ac303 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -340,7 +340,7 @@ static int read_policy(RGWRados *store, struct req_state *s, * only_bucket: If true, reads the bucket ACL rather than the object ACL. * Returns: 0 on success, -ERR# otherwise. */ -static int rgw_build_policies(RGWRados *store, struct req_state *s, bool only_bucket, bool prefetch_data) +static int rgw_build_bucket_policies(RGWRados *store, struct req_state *s) { int ret = 0; rgw_obj_key obj; @@ -423,9 +423,20 @@ static int rgw_build_policies(RGWRados *store, struct req_state *s, bool only_bu } } - /* we're passed only_bucket = true when we specifically need the bucket's - acls, that happens on write operations */ - if (!only_bucket && !s->object.empty()) { + return 0; +} + +/** + * Get the AccessControlPolicy for a bucket or object off of disk. + * s: The req_state to draw information from. + * only_bucket: If true, reads the bucket ACL rather than the object ACL. + * Returns: 0 on success, -ERR# otherwise. + */ +static int rgw_build_object_policies(RGWRados *store, struct req_state *s, bool prefetch_data) +{ + int ret = 0; + + if (!s->object.empty()) { if (!s->bucket_exists) { return -ERR_NO_SUCH_BUCKET; } @@ -3460,12 +3471,29 @@ int RGWHandler::init(RGWRados *_store, struct req_state *_s, RGWClientIO *cio) return 0; } +int RGWHandler::do_init_permissions() +{ + int ret = rgw_build_bucket_policies(store, s); + + if (ret < 0) { + ldout(s->cct, 10) << "read_permissions on " << s->bucket << " ret=" << ret << dendl; + if (ret == -ENODATA) + ret = -EACCES; + } + + return ret; +} + int RGWHandler::do_read_permissions(RGWOp *op, bool only_bucket) { - int ret = rgw_build_policies(store, s, only_bucket, op->prefetch_data()); + if (only_bucket) { + /* already read bucket info */ + return 0; + } + int ret = rgw_build_object_policies(store, s, op->prefetch_data()); if (ret < 0) { - ldout(s->cct, 10) << "read_permissions on " << s->bucket << ":" <object << " only_bucket=" << only_bucket << " ret=" << ret << dendl; + ldout(s->cct, 10) << "read_permissions on " << s->bucket << ":" << s->object << " ret=" << ret << dendl; if (ret == -ENODATA) ret = -EACCES; } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index f0354ab36237d..254664ae1cee1 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -110,6 +110,9 @@ class RGWOp { virtual RGWOpType get_type() { return RGW_OP_UNKNOWN; } virtual uint32_t op_mask() { return 0; } + virtual bool supports_website() { + return false; + } }; class RGWGetObj : public RGWOp { @@ -176,6 +179,10 @@ class RGWGetObj : public RGWOp { virtual const string name() { return "get_obj"; } virtual RGWOpType get_type() { return RGW_OP_GET_OBJ; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } + virtual bool need_object_expiration() { return false; } + virtual bool supports_website() { + return true; + } }; #define RGW_LIST_BUCKETS_LIMIT_MAX 10000 @@ -207,6 +214,9 @@ class RGWListBuckets : public RGWOp { virtual const string name() { return "list_buckets"; } virtual RGWOpType get_type() { return RGW_OP_LIST_BUCKETS; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } + virtual bool supports_website() { + return true; + } }; class RGWStatAccount : public RGWOp { @@ -1021,6 +1031,7 @@ class RGWHandler { RGWRados *store; struct req_state *s; + int do_init_permissions(); int do_read_permissions(RGWOp *op, bool only_bucket); virtual RGWOp *op_get() { return NULL; } @@ -1038,6 +1049,13 @@ class RGWHandler { virtual int validate_bucket_name(const string& bucket, int name_strictness) { return 0; } virtual RGWOp *get_op(RGWRados *store); virtual void put_op(RGWOp *op); + virtual int init_permissions() { + return 0; + } + virtual int retarget(RGWOp *op, RGWOp **new_op) { + *new_op = op; + return 0; + } virtual int read_permissions(RGWOp *op) = 0; virtual int authorize() = 0; }; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index fa5533d926c3b..35be5d62a2ef3 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1305,6 +1305,11 @@ static http_op op_from_method(const char *method) return OP_UNKNOWN; } +int RGWHandler_ObjStore::init_permissions() +{ + return do_init_permissions(); +} + int RGWHandler_ObjStore::read_permissions(RGWOp *op_obj) { bool only_bucket; @@ -1344,6 +1349,33 @@ int RGWHandler_ObjStore::read_permissions(RGWOp *op_obj) return do_read_permissions(op_obj, only_bucket); } +int RGWHandler_ObjStore::retarget(RGWOp *op, RGWOp **new_op) { + *new_op = op; + + if (!s->bucket_info.has_website) { + return 0; + } + + RGWRedirectInfo rinfo; + rgw_obj_key new_obj; + s->bucket_info.website_conf.get_effective_target(s->object.name, &new_obj.name, &rinfo); + + + +#warning FIXME +#if 0 + if (s->object.empty() != new_obj.empty()) { + op->put(); + s->object = new_obj; + *new_op = get_op(); + } +#endif + + s->object = new_obj; + + return 0; +} + void RGWRESTMgr::register_resource(string resource, RGWRESTMgr *mgr) { string r = "/"; diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 60acbf700bb09..597398bae7a3c 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -303,7 +303,9 @@ class RGWHandler_ObjStore : public RGWHandler { public: RGWHandler_ObjStore() {} virtual ~RGWHandler_ObjStore() {} + int init_permissions(); int read_permissions(RGWOp *op); + int retarget(RGWOp *op, RGWOp **new_op); virtual int authorize() = 0; }; From 480a55de4790c4ef1ce99bb948f74c46d427d2d2 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 19 Mar 2015 23:10:29 -0700 Subject: [PATCH 06/90] rgw: initial implementation of website REST api Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 20 +++++++++++++ src/rgw/rgw_op.h | 18 ++++++++++++ src/rgw/rgw_rest_s3.cc | 65 ++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_rest_s3.h | 8 ++++++ 4 files changed, 111 insertions(+) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index af806f38ac303..aa1fe1955d8cb 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1147,6 +1147,26 @@ void RGWSetBucketVersioning::execute() } } +int RGWGetBucketWebsite::verify_permission() +{ + if (s->user.user_id.compare(s->bucket_owner.get_id()) != 0) + return -EACCES; + + return 0; +} + +void RGWGetBucketWebsite::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + +void RGWGetBucketWebsite::execute() +{ + if (!s->bucket_info.has_website) { + ret = -ENOENT; + } +} + int RGWStatBucket::verify_permission() { if (!verify_bucket_permission(s, RGW_PERM_READ)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 254664ae1cee1..bff13edf745da 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -39,6 +39,8 @@ enum RGWOpType { RGW_OP_GET_BUCKET_LOGGING, RGW_OP_GET_BUCKET_VERSIONING, RGW_OP_SET_BUCKET_VERSIONING, + RGW_OP_GET_BUCKET_WEBSITE, + RGW_OP_SET_BUCKET_WEBSITE, RGW_OP_STAT_BUCKET, RGW_OP_CREATE_BUCKET, RGW_OP_DELETE_BUCKET, @@ -340,6 +342,22 @@ class RGWSetBucketVersioning : public RGWOp { virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; +class RGWGetBucketWebsite : public RGWOp { +protected: + int ret; +public: + RGWGetBucketWebsite() : ret(0) {} + + int verify_permission(); + void pre_exec(); + void execute(); + + virtual void send_response() = 0; + virtual const string name() { return "get_bucket_website"; } + virtual RGWOpType get_type() { return RGW_OP_GET_BUCKET_WEBSITE; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } +}; + class RGWStatBucket : public RGWOp { protected: int ret; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 05ddf9782d2f2..d3bb5bede68a6 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -503,6 +503,71 @@ void RGWSetBucketVersioning_ObjStore_S3::send_response() } +void RGWGetBucketWebsite_ObjStore_S3::send_response() +{ + if (ret) + set_req_state_err(s, ret); + dump_errno(s); + end_header(s, this, "application/xml"); + dump_start(s); + + if (ret < 0) { + return; + } + + RGWBucketWebsiteConf& conf = s->bucket_info.website_conf; + list& rules = conf.routing_rules.rules; + + s->formatter->open_object_section_in_ns("WebsiteConfiguration", + "http://doc.s3.amazonaws.com/doc/2006-03-01/"); + s->formatter->open_object_section("IndexDocument"); + s->formatter->dump_string("Suffix", conf.index_doc_suffix); + s->formatter->close_section(); + s->formatter->open_object_section("ErrorDocument"); + s->formatter->dump_string("Key", conf.error_doc); + s->formatter->close_section(); + + s->formatter->open_object_section("RoutingRules"); + list::iterator iter; + for (iter = rules.begin(); iter != rules.end(); ++iter) { + s->formatter->open_object_section("RoutingRule"); + + s->formatter->open_object_section("Condition"); + if (!iter->condition.key_prefix_equals.empty()) { + s->formatter->dump_string("KeyPrefixEquals", iter->condition.key_prefix_equals); + } + if (iter->condition.http_error_code_returned_equals > 0) { + s->formatter->dump_int("HttpErrorCodeReturnedEquals", iter->condition.http_error_code_returned_equals); + } + s->formatter->close_section(); // Condition + + s->formatter->open_object_section("Redirect"); + + if (!iter->redirect_info.replace_key_prefix_with.empty()) { + s->formatter->dump_string("ReplaceKeyPrefixWith", iter->redirect_info.replace_key_prefix_with); + } + if (!iter->redirect_info.replace_key_with.empty()) { + s->formatter->dump_string("ReplaceKeyWith", iter->redirect_info.replace_key_with); + } + if (!iter->redirect_info.redirect.hostname.empty()) { + s->formatter->dump_string("HostName", iter->redirect_info.redirect.hostname); + } + if (!iter->redirect_info.redirect.protocol.empty()) { + s->formatter->dump_string("Protocol", iter->redirect_info.redirect.protocol); + } + if (iter->redirect_info.redirect.http_redirect_code > 0) { + s->formatter->dump_int("HttpRedirectCode", iter->redirect_info.redirect.http_redirect_code); + } + s->formatter->close_section(); // Redirect + + + s->formatter->close_section(); // RoutingRule + } + s->formatter->close_section(); // RoutingRules + s->formatter->close_section(); // WebsiteConfiguration + rgw_flush_formatter_and_reset(s, s->formatter); +} + static void dump_bucket_metadata(struct req_state *s, RGWBucketEnt& bucket) { char buf[32]; diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index f6077cf81aa4c..8d41fa9eea3e0 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -86,6 +86,14 @@ class RGWSetBucketVersioning_ObjStore_S3 : public RGWSetBucketVersioning { void send_response(); }; +class RGWGetBucketWebsite_ObjStore_S3 : public RGWGetBucketWebsite { +public: + RGWGetBucketWebsite_ObjStore_S3() {} + ~RGWGetBucketWebsite_ObjStore_S3() {} + + void send_response(); +}; + class RGWStatBucket_ObjStore_S3 : public RGWStatBucket_ObjStore { public: RGWStatBucket_ObjStore_S3() {} From f95971d751fcc06c27c687ee795fb53b47bc1066 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 20 Mar 2015 00:35:41 -0700 Subject: [PATCH 07/90] rgw: enable website as subresource also enable GetBucketWebsite op. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.cc | 1 + src/rgw/rgw_rest_s3.cc | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index ea40130501630..1caed92291333 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -616,6 +616,7 @@ int RGWHTTPArgs::parse() (name.compare("versionId") == 0) || (name.compare("versions") == 0) || (name.compare("versioning") == 0) || + (name.compare("website") == 0) || (name.compare("torrent") == 0)) { sub_resources[name] = val; } else if (name[0] == 'r') { // root of all evil diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d3bb5bede68a6..2bee1b6247a9a 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2095,6 +2095,9 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_get() if (s->info.args.sub_resource_exists("versioning")) return new RGWGetBucketVersioning_ObjStore_S3; + if (s->info.args.sub_resource_exists("website")) + return new RGWGetBucketWebsite_ObjStore_S3; + if (is_acl_op()) { return new RGWGetACLs_ObjStore_S3; } else if (is_cors_op()) { From a50fb35dad46a8f69af9ed24d75a4608f4bf52e1 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Sun, 22 Mar 2015 22:19:26 -0700 Subject: [PATCH 08/90] rgw: xml encoder / decoder similar to the json decoder, for easier xml parsing. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_xml.cc | 251 +++++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_xml.h | 188 +++++++++++++++++++++++++++++++++ 2 files changed, 439 insertions(+) diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 3e38f8070107f..8963fb041c62b 100644 --- a/src/rgw/rgw_xml.cc +++ b/src/rgw/rgw_xml.cc @@ -238,3 +238,254 @@ bool RGWXMLParser::parse(const char *_buf, int len, int done) return success; } + +void decode_xml_obj(unsigned long& val, XMLObj *obj) +{ + string& s = obj->get_data(); + const char *start = s.c_str(); + char *p; + + errno = 0; + val = strtoul(start, &p, 10); + + /* Check for various possible errors */ + + if ((errno == ERANGE && val == ULONG_MAX) || + (errno != 0 && val == 0)) { + throw RGWXMLDecoder::err("failed to number"); + } + + if (p == start) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + while (*p != '\0') { + if (!isspace(*p)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + p++; + } +} + + +void decode_xml_obj(long& val, XMLObj *obj) +{ + string s = obj->get_data(); + const char *start = s.c_str(); + char *p; + + errno = 0; + val = strtol(start, &p, 10); + + /* Check for various possible errors */ + + if ((errno == ERANGE && (val == LONG_MAX || val == LONG_MIN)) || + (errno != 0 && val == 0)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + if (p == start) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + while (*p != '\0') { + if (!isspace(*p)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + p++; + } +} + +void decode_xml_obj(long long& val, XMLObj *obj) +{ + string s = obj->get_data(); + const char *start = s.c_str(); + char *p; + + errno = 0; + val = strtoll(start, &p, 10); + + /* Check for various possible errors */ + + if ((errno == ERANGE && (val == LLONG_MAX || val == LLONG_MIN)) || + (errno != 0 && val == 0)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + if (p == start) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + while (*p != '\0') { + if (!isspace(*p)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + p++; + } +} + +void decode_xml_obj(unsigned long long& val, XMLObj *obj) +{ + string s = obj->get_data(); + const char *start = s.c_str(); + char *p; + + errno = 0; + val = strtoull(start, &p, 10); + + /* Check for various possible errors */ + + if ((errno == ERANGE && val == ULLONG_MAX) || + (errno != 0 && val == 0)) { + throw RGWXMLDecoder::err("failed to number"); + } + + if (p == start) { + throw RGWXMLDecoder::err("failed to parse number"); + } + + while (*p != '\0') { + if (!isspace(*p)) { + throw RGWXMLDecoder::err("failed to parse number"); + } + p++; + } +} + +void decode_xml_obj(int& val, XMLObj *obj) +{ + long l; + decode_xml_obj(l, obj); +#if LONG_MAX > INT_MAX + if (l > INT_MAX || l < INT_MIN) { + throw RGWXMLDecoder::err("integer out of range"); + } +#endif + + val = (int)l; +} + +void decode_xml_obj(unsigned& val, XMLObj *obj) +{ + unsigned long l; + decode_xml_obj(l, obj); +#if ULONG_MAX > UINT_MAX + if (l > UINT_MAX) { + throw RGWXMLDecoder::err("unsigned integer out of range"); + } +#endif + + val = (unsigned)l; +} + +void decode_xml_obj(bool& val, XMLObj *obj) +{ + string s = obj->get_data(); + if (strcasecmp(s.c_str(), "true") == 0) { + val = true; + return; + } + if (strcasecmp(s.c_str(), "false") == 0) { + val = false; + return; + } + int i; + decode_xml_obj(i, obj); + val = (bool)i; +} + +void decode_xml_obj(bufferlist& val, XMLObj *obj) +{ + string s = obj->get_data(); + + bufferlist bl; + bl.append(s.c_str(), s.size()); + try { + val.decode_base64(bl); + } catch (buffer::error& err) { + throw RGWXMLDecoder::err("failed to decode base64"); + } +} + +void decode_xml_obj(utime_t& val, XMLObj *obj) +{ + string s = obj->get_data(); + uint64_t epoch; + uint64_t nsec; + int r = utime_t::parse_date(s, &epoch, &nsec); + if (r == 0) { + val = utime_t(epoch, nsec); + } else { + throw RGWXMLDecoder::err("failed to decode utime_t"); + } +} + +void encode_xml(const char *name, const string& val, Formatter *f) +{ + f->dump_string(name, val); +} + +void encode_xml(const char *name, const char *val, Formatter *f) +{ + f->dump_string(name, val); +} + +void encode_xml(const char *name, bool val, Formatter *f) +{ + string s; + if (val) + s = "True"; + else + s = "False"; + + f->dump_string(name, s); +} + +void encode_xml(const char *name, int val, Formatter *f) +{ + f->dump_int(name, val); +} + +void encode_xml(const char *name, long val, Formatter *f) +{ + f->dump_int(name, val); +} + +void encode_xml(const char *name, unsigned val, Formatter *f) +{ + f->dump_unsigned(name, val); +} + +void encode_xml(const char *name, unsigned long val, Formatter *f) +{ + f->dump_unsigned(name, val); +} + +void encode_xml(const char *name, unsigned long long val, Formatter *f) +{ + f->dump_unsigned(name, val); +} + +void encode_xml(const char *name, long long val, Formatter *f) +{ + f->dump_int(name, val); +} + +void encode_xml(const char *name, const utime_t& val, Formatter *f) +{ + val.gmtime(f->dump_stream(name)); +} + +void encode_xml(const char *name, const bufferlist& bl, Formatter *f) +{ + /* need to copy data from bl, as it is const bufferlist */ + bufferlist src = bl; + + bufferlist b64; + src.encode_base64(b64); + + string s(b64.c_str(), b64.length()); + + encode_xml(name, s, f); +} + diff --git a/src/rgw/rgw_xml.h b/src/rgw/rgw_xml.h index 164e97a70dc52..4ab84b47a1ac8 100644 --- a/src/rgw/rgw_xml.h +++ b/src/rgw/rgw_xml.h @@ -8,6 +8,7 @@ #include #include #include +#include #include @@ -85,4 +86,191 @@ class RGWXMLParser : public XMLObj bool success; }; +class RGWXMLDecoder { +public: + struct err { + string message; + + err(const string& m) : message(m) {} + }; + + class XMLParser : public RGWXMLParser { + public: + XMLParser() {} + virtual ~XMLParser() {} + } parser; + + RGWXMLDecoder(bufferlist& bl) { + if (!parser.parse(bl.c_str(), bl.length(), 1)) { + cout << "RGWXMLDecoder::err()" << std::endl; + throw RGWXMLDecoder::err("failed to parse XML input"); + } + } + + template + static bool decode_xml(const char *name, T& val, XMLObj *obj, bool mandatory = false); + + template + static bool decode_xml(const char *name, C& container, void (*cb)(C&, XMLObj *obj), XMLObj *obj, bool mandatory = false); + + template + static void decode_xml(const char *name, T& val, T& default_val, XMLObj *obj); +}; + +template +void decode_xml_obj(T& val, XMLObj *obj) +{ + val.decode_xml(obj); +} + +static inline void decode_xml_obj(string& val, XMLObj *obj) +{ + val = obj->get_data(); +} + +void decode_xml_obj(unsigned long long& val, XMLObj *obj); +void decode_xml_obj(long long& val, XMLObj *obj); +void decode_xml_obj(unsigned long& val, XMLObj *obj); +void decode_xml_obj(long& val, XMLObj *obj); +void decode_xml_obj(unsigned& val, XMLObj *obj); +void decode_xml_obj(int& val, XMLObj *obj); +void decode_xml_obj(bool& val, XMLObj *obj); +void decode_xml_obj(bufferlist& val, XMLObj *obj); +class utime_t; +void decode_xml_obj(utime_t& val, XMLObj *obj); + +template +void do_decode_xml_obj(list& l, const string& name, XMLObj *obj) +{ + l.clear(); + + XMLObjIter iter = obj->find_first(name); + XMLObj *o; + + while (o = iter.get_next()) { + T val; + decode_xml_obj(val, o); + l.push_back(val); + } +} + +template +void do_decode_xml_obj(vector& l, const string& name, XMLObj *obj) +{ + l.clear(); + + XMLObjIter iter = obj->find_first(name); + XMLObj *o; + + while (o = iter.get_next()) { + T val; + decode_xml_obj(val, o); + l.push_back(val); + } +} + +template +bool RGWXMLDecoder::decode_xml(const char *name, T& val, XMLObj *obj, bool mandatory) +{ + XMLObjIter iter = obj->find_first(name); + XMLObj *o = iter.get_next(); + if (!o) { + if (mandatory) { + string s = "missing mandatory field " + string(name); + throw err(s); + } + val = T(); + return false; + } + + try { + decode_xml_obj(val, o); + } catch (err& e) { + string s = string(name) + ": "; + s.append(e.message); + throw err(s); + } + + return true; +} + +template +bool RGWXMLDecoder::decode_xml(const char *name, C& container, void (*cb)(C&, XMLObj *), XMLObj *obj, bool mandatory) +{ + container.clear(); + + XMLObjIter iter = obj->find_first(name); + XMLObj *o = iter.get_next(); + if (!o) { + if (mandatory) { + string s = "missing mandatory field " + string(name); + throw err(s); + } + return false; + } + + try { + decode_xml_obj(container, cb, o); + } catch (err& e) { + string s = string(name) + ": "; + s.append(e.message); + throw err(s); + } + + return true; +} + +template +void RGWXMLDecoder::decode_xml(const char *name, T& val, T& default_val, XMLObj *obj) +{ + XMLObjIter iter = obj->find_first(name); + XMLObj *o = iter.get_next(); + if (!o) { + val = default_val; + return; + } + + try { + decode_xml_obj(val, o); + } catch (err& e) { + val = default_val; + string s = string(name) + ": "; + s.append(e.message); + throw err(s); + } +} + +template +static void encode_xml(const char *name, const T& val, ceph::Formatter *f) +{ + f->open_object_section(name); + val.dump_xml(f); + f->close_section(); +} + +void encode_xml(const char *name, const string& val, ceph::Formatter *f); +void encode_xml(const char *name, const char *val, ceph::Formatter *f); +void encode_xml(const char *name, bool val, ceph::Formatter *f); +void encode_xml(const char *name, int val, ceph::Formatter *f); +void encode_xml(const char *name, unsigned val, ceph::Formatter *f); +void encode_xml(const char *name, long val, ceph::Formatter *f); +void encode_xml(const char *name, unsigned long val, ceph::Formatter *f); +void encode_xml(const char *name, long long val, ceph::Formatter *f); +void encode_xml(const char *name, const utime_t& val, ceph::Formatter *f); +void encode_xml(const char *name, const bufferlist& bl, ceph::Formatter *f); +void encode_xml(const char *name, long long val, ceph::Formatter *f); +void encode_xml(const char *name, long long unsigned val, ceph::Formatter *f); + +template +static void do_encode_xml(const char *name, const std::list& l, const char *entry_name, ceph::Formatter *f) +{ + f->open_array_section(name); + for (typename std::list::const_iterator iter = l.begin(); iter != l.end(); ++iter) { + encode_xml(entry_name, *iter, f); + } + f->close_section(); +} + + + #endif From 733e0b0b681a32d9c85a5907a061ec809fcf0faa Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Sun, 22 Mar 2015 23:02:18 -0700 Subject: [PATCH 09/90] rgw: add xml encoders for website conf Signed-off-by: Yehuda Sadeh --- src/rgw/Makefile.am | 1 + src/rgw/rgw_rest_s3.cc | 45 +---------------------------- src/rgw/rgw_website.h | 7 +++++ src/rgw/rgw_xml_enc.cc | 65 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 src/rgw/rgw_xml_enc.cc diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index 4e4f614fb8fb9..6b683e78ce169 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -21,6 +21,7 @@ librgw_la_SOURCES = \ rgw/rgw_xml.cc \ rgw/rgw_usage.cc \ rgw/rgw_json_enc.cc \ + rgw/rgw_xml_enc.cc \ rgw/rgw_user.cc \ rgw/rgw_bucket.cc\ rgw/rgw_tools.cc \ diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 2bee1b6247a9a..7e655d9a600f6 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -520,50 +520,7 @@ void RGWGetBucketWebsite_ObjStore_S3::send_response() s->formatter->open_object_section_in_ns("WebsiteConfiguration", "http://doc.s3.amazonaws.com/doc/2006-03-01/"); - s->formatter->open_object_section("IndexDocument"); - s->formatter->dump_string("Suffix", conf.index_doc_suffix); - s->formatter->close_section(); - s->formatter->open_object_section("ErrorDocument"); - s->formatter->dump_string("Key", conf.error_doc); - s->formatter->close_section(); - - s->formatter->open_object_section("RoutingRules"); - list::iterator iter; - for (iter = rules.begin(); iter != rules.end(); ++iter) { - s->formatter->open_object_section("RoutingRule"); - - s->formatter->open_object_section("Condition"); - if (!iter->condition.key_prefix_equals.empty()) { - s->formatter->dump_string("KeyPrefixEquals", iter->condition.key_prefix_equals); - } - if (iter->condition.http_error_code_returned_equals > 0) { - s->formatter->dump_int("HttpErrorCodeReturnedEquals", iter->condition.http_error_code_returned_equals); - } - s->formatter->close_section(); // Condition - - s->formatter->open_object_section("Redirect"); - - if (!iter->redirect_info.replace_key_prefix_with.empty()) { - s->formatter->dump_string("ReplaceKeyPrefixWith", iter->redirect_info.replace_key_prefix_with); - } - if (!iter->redirect_info.replace_key_with.empty()) { - s->formatter->dump_string("ReplaceKeyWith", iter->redirect_info.replace_key_with); - } - if (!iter->redirect_info.redirect.hostname.empty()) { - s->formatter->dump_string("HostName", iter->redirect_info.redirect.hostname); - } - if (!iter->redirect_info.redirect.protocol.empty()) { - s->formatter->dump_string("Protocol", iter->redirect_info.redirect.protocol); - } - if (iter->redirect_info.redirect.http_redirect_code > 0) { - s->formatter->dump_int("HttpRedirectCode", iter->redirect_info.redirect.http_redirect_code); - } - s->formatter->close_section(); // Redirect - - - s->formatter->close_section(); // RoutingRule - } - s->formatter->close_section(); // RoutingRules + conf.dump_xml(s->formatter); s->formatter->close_section(); // WebsiteConfiguration rgw_flush_formatter_and_reset(s, s->formatter); } diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 3e3e846e2355e..551bd906a80ac 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -1,6 +1,8 @@ #ifndef RGW_WEBSITE_H #define RGW_WEBSITE_H +#include "rgw_xml.h" + struct RGWRedirectInfo { string protocol; @@ -50,6 +52,7 @@ struct RGWBWRedirectInfo } void dump(Formatter *f) const; + void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); }; WRITE_CLASS_ENCODER(RGWBWRedirectInfo) @@ -73,6 +76,7 @@ struct RGWBWRoutingRuleCondition } void dump(Formatter *f) const; + void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); bool check_key_condition(const string& key); @@ -101,6 +105,7 @@ struct RGWBWRoutingRule } void dump(Formatter *f) const; + void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); bool check_key_condition(const string& key) { @@ -128,6 +133,7 @@ struct RGWBWRoutingRules } void dump(Formatter *f) const; + void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); bool check_key_condition(const string& key, RGWBWRoutingRule **rule); @@ -163,6 +169,7 @@ struct RGWBucketWebsiteConf void dump(Formatter *f) const; void decode_json(JSONObj *obj); + void dump_xml(Formatter *f) const; void get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect); }; diff --git a/src/rgw/rgw_xml_enc.cc b/src/rgw/rgw_xml_enc.cc new file mode 100644 index 0000000000000..3b604c8b00277 --- /dev/null +++ b/src/rgw/rgw_xml_enc.cc @@ -0,0 +1,65 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include "rgw_common.h" +#include "rgw_xml.h" + +#include "common/Formatter.h" + +void RGWBWRedirectInfo::dump_xml(Formatter *f) const +{ + if (!redirect.protocol.empty()) { + encode_xml("Protocol", redirect.protocol, f); + } + if (!redirect.hostname.empty()) { + encode_xml("Hostname", redirect.hostname, f); + } + if (redirect.http_redirect_code > 0) { + encode_xml("HttpRedirectCode", (int)redirect.http_redirect_code, f); + } + if (!replace_key_prefix_with.empty()) { + encode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, f); + } + if (!replace_key_with.empty()) { + encode_xml("ReplaceKeyWith", replace_key_with, f); + } +} + +void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const +{ + if (!key_prefix_equals.empty()) { + encode_xml("KeyPrefixEquals", key_prefix_equals, f); + } + if (http_error_code_returned_equals > 0) { + encode_xml("HttpErrorCodeReturnedEquals", (int)http_error_code_returned_equals, f); + } +} + +void RGWBWRoutingRule::dump_xml(Formatter *f) const +{ + encode_xml("Condition", condition, f); + encode_xml("Redirect", redirect_info, f); +} + +static void encode_xml(const char *name, const std::list& l, ceph::Formatter *f) +{ + do_encode_xml("RoutingRules", l, "RoutingRule", f); +} + +void RGWBucketWebsiteConf::dump_xml(Formatter *f) const +{ + if (!index_doc_suffix.empty()) { + f->open_object_section("IndexDocument"); + encode_xml("Suffix", index_doc_suffix, f); + f->close_section(); + } + if (!error_doc.empty()) { + f->open_object_section("ErrorDocument"); + encode_xml("Key", error_doc, f); + f->close_section(); + } + if (!routing_rules.rules.empty()) { + encode_xml("RoutingRules", routing_rules.rules, f); + } +} + From b97ed0573de433e4dfe1452951b54d092302113f Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 23 Mar 2015 00:06:18 -0700 Subject: [PATCH 10/90] rgw: set bucket website operation Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 30 +++++++++++++++++++++++++++++ src/rgw/rgw_op.h | 19 +++++++++++++++++++ src/rgw/rgw_rest_s3.cc | 43 ++++++++++++++++++++++++++++++++++++++++++ src/rgw/rgw_rest_s3.h | 9 +++++++++ src/rgw/rgw_website.h | 4 ++++ src/rgw/rgw_xml.h | 12 ++++++------ src/rgw/rgw_xml_enc.cc | 39 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 150 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index aa1fe1955d8cb..d74e206c4da7e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1167,6 +1167,36 @@ void RGWGetBucketWebsite::execute() } } +int RGWSetBucketWebsite::verify_permission() +{ + if (s->user.user_id.compare(s->bucket_owner.get_id()) != 0) + return -EACCES; + + return 0; +} + +void RGWSetBucketWebsite::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + +void RGWSetBucketWebsite::execute() +{ + ret = get_params(); + + if (ret < 0) + return; + + s->bucket_info.has_website = true; + s->bucket_info.website_conf = website_conf; + + ret = store->put_bucket_instance_info(s->bucket_info, false, 0, &s->bucket_attrs); + if (ret < 0) { + ldout(s->cct, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket.name << " returned err=" << ret << dendl; + return; + } +} + int RGWStatBucket::verify_permission() { if (!verify_bucket_permission(s, RGW_PERM_READ)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index bff13edf745da..e1f71b74a0633 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -358,6 +358,25 @@ class RGWGetBucketWebsite : public RGWOp { virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } }; +class RGWSetBucketWebsite : public RGWOp { +protected: + int ret; + RGWBucketWebsiteConf website_conf; +public: + RGWSetBucketWebsite() : ret(0) {} + + int verify_permission(); + void pre_exec(); + void execute(); + + virtual int get_params() { return 0; } + + virtual void send_response() = 0; + virtual const string name() { return "set_bucket_website"; } + virtual RGWOpType get_type() { return RGW_OP_SET_BUCKET_WEBSITE; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } +}; + class RGWStatBucket : public RGWOp { protected: int ret; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 7e655d9a600f6..3d251a4ffaa59 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -502,6 +502,47 @@ void RGWSetBucketVersioning_ObjStore_S3::send_response() end_header(s); } +int RGWSetBucketWebsite_ObjStore_S3::get_params() +{ +#define GET_BUCKET_WEBSITE_BUF_MAX (128 * 1024) + + char *data; + int len = 0; + int r = rgw_rest_read_all_input(s, &data, &len, GET_BUCKET_WEBSITE_BUF_MAX); + if (r < 0) { + return r; + } + + bufferlist bl; + bl.append(data, len); + + RGWXMLDecoder::XMLParser parser; + parser.init(); + + if (!parser.parse(data, len, 1)) { + string str(data, len); + ldout(s->cct, 5) << "failed to parse xml: " << str << dendl; + return -EINVAL; + } + + try { + RGWXMLDecoder::decode_xml("WebsiteConfiguration", website_conf, &parser, true); + } catch (RGWXMLDecoder::err& err) { + string str(data, len); + ldout(s->cct, 5) << "unexpected xml: " << str << dendl; + return -EINVAL; + } + + return 0; +} + +void RGWSetBucketWebsite_ObjStore_S3::send_response() +{ + if (ret) + set_req_state_err(s, ret); + dump_errno(s); + end_header(s); +} void RGWGetBucketWebsite_ObjStore_S3::send_response() { @@ -2081,6 +2122,8 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_put() return NULL; if (s->info.args.sub_resource_exists("versioning")) return new RGWSetBucketVersioning_ObjStore_S3; + if (s->info.args.sub_resource_exists("website")) + return new RGWSetBucketWebsite_ObjStore_S3; if (is_acl_op()) { return new RGWPutACLs_ObjStore_S3; } else if (is_cors_op()) { diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 8d41fa9eea3e0..8b8d8ce68dadd 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -94,6 +94,15 @@ class RGWGetBucketWebsite_ObjStore_S3 : public RGWGetBucketWebsite { void send_response(); }; +class RGWSetBucketWebsite_ObjStore_S3 : public RGWSetBucketWebsite { +public: + RGWSetBucketWebsite_ObjStore_S3() {} + ~RGWSetBucketWebsite_ObjStore_S3() {} + + int get_params(); + void send_response(); +}; + class RGWStatBucket_ObjStore_S3 : public RGWStatBucket_ObjStore { public: RGWStatBucket_ObjStore_S3() {} diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 551bd906a80ac..88c057a9a3fb8 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -54,6 +54,7 @@ struct RGWBWRedirectInfo void dump(Formatter *f) const; void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); + void decode_xml(XMLObj *obj); }; WRITE_CLASS_ENCODER(RGWBWRedirectInfo) @@ -78,6 +79,7 @@ struct RGWBWRoutingRuleCondition void dump(Formatter *f) const; void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); + void decode_xml(XMLObj *obj); bool check_key_condition(const string& key); bool check_error_code_condition(int error_code) { @@ -107,6 +109,7 @@ struct RGWBWRoutingRule void dump(Formatter *f) const; void dump_xml(Formatter *f) const; void decode_json(JSONObj *obj); + void decode_xml(XMLObj *obj); bool check_key_condition(const string& key) { return condition.check_key_condition(key); @@ -169,6 +172,7 @@ struct RGWBucketWebsiteConf void dump(Formatter *f) const; void decode_json(JSONObj *obj); + void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; void get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect); diff --git a/src/rgw/rgw_xml.h b/src/rgw/rgw_xml.h index 4ab84b47a1ac8..7443bead8b35c 100644 --- a/src/rgw/rgw_xml.h +++ b/src/rgw/rgw_xml.h @@ -144,10 +144,10 @@ void do_decode_xml_obj(list& l, const string& name, XMLObj *obj) { l.clear(); - XMLObjIter iter = obj->find_first(name); + XMLObjIter iter = obj->find(name); XMLObj *o; - while (o = iter.get_next()) { + while ((o = iter.get_next())) { T val; decode_xml_obj(val, o); l.push_back(val); @@ -159,7 +159,7 @@ void do_decode_xml_obj(vector& l, const string& name, XMLObj *obj) { l.clear(); - XMLObjIter iter = obj->find_first(name); + XMLObjIter iter = obj->find(name); XMLObj *o; while (o = iter.get_next()) { @@ -172,7 +172,7 @@ void do_decode_xml_obj(vector& l, const string& name, XMLObj *obj) template bool RGWXMLDecoder::decode_xml(const char *name, T& val, XMLObj *obj, bool mandatory) { - XMLObjIter iter = obj->find_first(name); + XMLObjIter iter = obj->find(name); XMLObj *o = iter.get_next(); if (!o) { if (mandatory) { @@ -199,7 +199,7 @@ bool RGWXMLDecoder::decode_xml(const char *name, C& container, void (*cb)(C&, XM { container.clear(); - XMLObjIter iter = obj->find_first(name); + XMLObjIter iter = obj->find(name); XMLObj *o = iter.get_next(); if (!o) { if (mandatory) { @@ -223,7 +223,7 @@ bool RGWXMLDecoder::decode_xml(const char *name, C& container, void (*cb)(C&, XM template void RGWXMLDecoder::decode_xml(const char *name, T& val, T& default_val, XMLObj *obj) { - XMLObjIter iter = obj->find_first(name); + XMLObjIter iter = obj->find(name); XMLObj *o = iter.get_next(); if (!o) { val = default_val; diff --git a/src/rgw/rgw_xml_enc.cc b/src/rgw/rgw_xml_enc.cc index 3b604c8b00277..9a94dcdb432cd 100644 --- a/src/rgw/rgw_xml_enc.cc +++ b/src/rgw/rgw_xml_enc.cc @@ -25,6 +25,16 @@ void RGWBWRedirectInfo::dump_xml(Formatter *f) const } } +void RGWBWRedirectInfo::decode_xml(XMLObj *obj) { + RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj); + RGWXMLDecoder::decode_xml("Hostname", redirect.hostname, obj); + int code = 0; + RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj); + redirect.http_redirect_code = code; + RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj); + RGWXMLDecoder::decode_xml("ReplcaeKeyWith", replace_key_with, obj); +} + void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const { if (!key_prefix_equals.empty()) { @@ -35,12 +45,24 @@ void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const } } +void RGWBWRoutingRuleCondition::decode_xml(XMLObj *obj) { + RGWXMLDecoder::decode_xml("KeyPrefixEquals", key_prefix_equals, obj); + int code = 0; + RGWXMLDecoder::decode_xml("HttpErrorCodeReturnedEquals", code, obj); + http_error_code_returned_equals = code; +} + void RGWBWRoutingRule::dump_xml(Formatter *f) const { encode_xml("Condition", condition, f); encode_xml("Redirect", redirect_info, f); } +void RGWBWRoutingRule::decode_xml(XMLObj *obj) { + RGWXMLDecoder::decode_xml("Condition", condition, obj); + RGWXMLDecoder::decode_xml("Redirect", redirect_info, obj); +} + static void encode_xml(const char *name, const std::list& l, ceph::Formatter *f) { do_encode_xml("RoutingRules", l, "RoutingRule", f); @@ -63,3 +85,20 @@ void RGWBucketWebsiteConf::dump_xml(Formatter *f) const } } +void decode_xml_obj(list& l, XMLObj *obj) +{ + do_decode_xml_obj(l, "RoutingRule", obj); +} + +void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) { + XMLObj *o = obj->find_first("IndexDocument"); + if (o) { + RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, obj); + } + o = obj->find_first("ErrorDocument"); + if (o) { + RGWXMLDecoder::decode_xml("Key", error_doc, obj); + } + RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj); +} + From e2d4eb5e9858a5935a74c0e73005866d3c698025 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 23 Mar 2015 09:53:18 -0700 Subject: [PATCH 11/90] rgw: no need to explicitly allocate XMLObj let the parser do the allocation if needed. Also, keep unallocated objects in a list. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_xml.cc | 10 +++++++--- src/rgw/rgw_xml.h | 6 +++++- src/rgw/rgw_xml_enc.cc | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_xml.cc b/src/rgw/rgw_xml.cc index 8963fb041c62b..eda0887528234 100644 --- a/src/rgw/rgw_xml.cc +++ b/src/rgw/rgw_xml.cc @@ -148,17 +148,21 @@ RGWXMLParser:: XML_ParserFree(p); free(buf); - vector::iterator iter; - for (iter = objs.begin(); iter != objs.end(); ++iter) { + list::iterator iter; + for (iter = allocated_objs.begin(); iter != allocated_objs.end(); ++iter) { XMLObj *obj = *iter; delete obj; } } + bool RGWXMLParser::xml_start(const char *el, const char **attr) { XMLObj * obj = alloc_obj(el); if (!obj) { - obj = new XMLObj(); + unallocated_objs.push_back(XMLObj()); + obj = &unallocated_objs.back(); + } else { + allocated_objs.push_back(obj); } if (!obj->xml_start(cur_obj, el, attr)) return false; diff --git a/src/rgw/rgw_xml.h b/src/rgw/rgw_xml.h index 7443bead8b35c..35f257aa97a35 100644 --- a/src/rgw/rgw_xml.h +++ b/src/rgw/rgw_xml.h @@ -68,8 +68,12 @@ class RGWXMLParser : public XMLObj int buf_len; XMLObj *cur_obj; vector objs; + list allocated_objs; + list unallocated_objs; protected: - virtual XMLObj *alloc_obj(const char *el) = 0; + virtual XMLObj *alloc_obj(const char *el) { + return NULL; + } public: RGWXMLParser(); virtual ~RGWXMLParser(); diff --git a/src/rgw/rgw_xml_enc.cc b/src/rgw/rgw_xml_enc.cc index 9a94dcdb432cd..7aaf68f25d3aa 100644 --- a/src/rgw/rgw_xml_enc.cc +++ b/src/rgw/rgw_xml_enc.cc @@ -93,11 +93,11 @@ void decode_xml_obj(list& l, XMLObj *obj) void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) { XMLObj *o = obj->find_first("IndexDocument"); if (o) { - RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, obj); + RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o); } o = obj->find_first("ErrorDocument"); if (o) { - RGWXMLDecoder::decode_xml("Key", error_doc, obj); + RGWXMLDecoder::decode_xml("Key", error_doc, o); } RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj); } From 5b39d03cdf02c1558304483ee425742783fd5635 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 23 Mar 2015 19:24:54 -0700 Subject: [PATCH 12/90] rgw: fix xml encoding for certain website operations Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_xml_enc.cc | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/rgw/rgw_xml_enc.cc b/src/rgw/rgw_xml_enc.cc index 7aaf68f25d3aa..7577826fcffb1 100644 --- a/src/rgw/rgw_xml_enc.cc +++ b/src/rgw/rgw_xml_enc.cc @@ -6,13 +6,15 @@ #include "common/Formatter.h" +#define dout_subsys ceph_subsys_rgw + void RGWBWRedirectInfo::dump_xml(Formatter *f) const { if (!redirect.protocol.empty()) { encode_xml("Protocol", redirect.protocol, f); } if (!redirect.hostname.empty()) { - encode_xml("Hostname", redirect.hostname, f); + encode_xml("HostName", redirect.hostname, f); } if (redirect.http_redirect_code > 0) { encode_xml("HttpRedirectCode", (int)redirect.http_redirect_code, f); @@ -27,12 +29,12 @@ void RGWBWRedirectInfo::dump_xml(Formatter *f) const void RGWBWRedirectInfo::decode_xml(XMLObj *obj) { RGWXMLDecoder::decode_xml("Protocol", redirect.protocol, obj); - RGWXMLDecoder::decode_xml("Hostname", redirect.hostname, obj); + RGWXMLDecoder::decode_xml("HostName", redirect.hostname, obj); int code = 0; RGWXMLDecoder::decode_xml("HttpRedirectCode", code, obj); redirect.http_redirect_code = code; RGWXMLDecoder::decode_xml("ReplaceKeyPrefixWith", replace_key_prefix_with, obj); - RGWXMLDecoder::decode_xml("ReplcaeKeyWith", replace_key_with, obj); + RGWXMLDecoder::decode_xml("ReplaceKeyWith", replace_key_with, obj); } void RGWBWRoutingRuleCondition::dump_xml(Formatter *f) const @@ -70,6 +72,14 @@ static void encode_xml(const char *name, const std::list& l, c void RGWBucketWebsiteConf::dump_xml(Formatter *f) const { + if (!redirect_all.hostname.empty()) { + f->open_object_section("RedirectAllRequestsTo"); + encode_xml("HostName", redirect_all.hostname, f); + if (!redirect_all.protocol.empty()) { + encode_xml("Protocol", redirect_all.protocol, f); + } + f->close_section(); + } if (!index_doc_suffix.empty()) { f->open_object_section("IndexDocument"); encode_xml("Suffix", index_doc_suffix, f); @@ -91,14 +101,20 @@ void decode_xml_obj(list& l, XMLObj *obj) } void RGWBucketWebsiteConf::decode_xml(XMLObj *obj) { - XMLObj *o = obj->find_first("IndexDocument"); - if (o) { - RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o); - } - o = obj->find_first("ErrorDocument"); + XMLObj *o = obj->find_first("RedirectAllRequestsTo"); if (o) { - RGWXMLDecoder::decode_xml("Key", error_doc, o); + RGWXMLDecoder::decode_xml("HostName", redirect_all.hostname, o, true); + RGWXMLDecoder::decode_xml("Protocol", redirect_all.protocol, o); + } else { + o = obj->find_first("IndexDocument"); + if (o) { + RGWXMLDecoder::decode_xml("Suffix", index_doc_suffix, o); + } + o = obj->find_first("ErrorDocument"); + if (o) { + RGWXMLDecoder::decode_xml("Key", error_doc, o); + } + RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj); } - RGWXMLDecoder::decode_xml("RoutingRules", routing_rules.rules, obj); } From 55bd0c19679531ed8a84899ece606edc8602c78c Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 23 Mar 2015 19:25:47 -0700 Subject: [PATCH 13/90] rgw: add remove website api Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_op.cc | 25 +++++++++++++++++++++++++ src/rgw/rgw_op.h | 16 ++++++++++++++++ src/rgw/rgw_rest_s3.cc | 14 ++++++++++++++ src/rgw/rgw_rest_s3.h | 8 ++++++++ 4 files changed, 63 insertions(+) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index d74e206c4da7e..96a7fe5976a45 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1197,6 +1197,31 @@ void RGWSetBucketWebsite::execute() } } +int RGWDeleteBucketWebsite::verify_permission() +{ + if (s->user.user_id.compare(s->bucket_owner.get_id()) != 0) + return -EACCES; + + return 0; +} + +void RGWDeleteBucketWebsite::pre_exec() +{ + rgw_bucket_object_pre_exec(s); +} + +void RGWDeleteBucketWebsite::execute() +{ + s->bucket_info.has_website = false; + s->bucket_info.website_conf = RGWBucketWebsiteConf(); + + ret = store->put_bucket_instance_info(s->bucket_info, false, 0, &s->bucket_attrs); + if (ret < 0) { + ldout(s->cct, 0) << "NOTICE: put_bucket_info on bucket=" << s->bucket.name << " returned err=" << ret << dendl; + return; + } +} + int RGWStatBucket::verify_permission() { if (!verify_bucket_permission(s, RGW_PERM_READ)) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index e1f71b74a0633..d719d50141447 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -377,6 +377,22 @@ class RGWSetBucketWebsite : public RGWOp { virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } }; +class RGWDeleteBucketWebsite : public RGWOp { +protected: + int ret; +public: + RGWDeleteBucketWebsite() : ret(0) {} + + int verify_permission(); + void pre_exec(); + void execute(); + + virtual void send_response() = 0; + virtual const string name() { return "delete_bucket_website"; } + virtual RGWOpType get_type() { return RGW_OP_SET_BUCKET_WEBSITE; } + virtual uint32_t op_mask() { return RGW_OP_TYPE_WRITE; } +}; + class RGWStatBucket : public RGWOp { protected: int ret; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 3d251a4ffaa59..6108bdb4b6215 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -544,6 +544,16 @@ void RGWSetBucketWebsite_ObjStore_S3::send_response() end_header(s); } +void RGWDeleteBucketWebsite_ObjStore_S3::send_response() +{ + if (!ret) { + ret = STATUS_NO_CONTENT; + } + set_req_state_err(s, ret); + dump_errno(s); + end_header(s); +} + void RGWGetBucketWebsite_ObjStore_S3::send_response() { if (ret) @@ -2137,6 +2147,10 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_delete() if (is_cors_op()) { return new RGWDeleteCORS_ObjStore_S3; } + + if (s->info.args.sub_resource_exists("website")) + return new RGWDeleteBucketWebsite_ObjStore_S3; + return new RGWDeleteBucket_ObjStore_S3; } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 8b8d8ce68dadd..f9ec0eb5c14a8 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -103,6 +103,14 @@ class RGWSetBucketWebsite_ObjStore_S3 : public RGWSetBucketWebsite { void send_response(); }; +class RGWDeleteBucketWebsite_ObjStore_S3 : public RGWDeleteBucketWebsite { +public: + RGWDeleteBucketWebsite_ObjStore_S3() {} + ~RGWDeleteBucketWebsite_ObjStore_S3() {} + + void send_response(); +}; + class RGWStatBucket_ObjStore_S3 : public RGWStatBucket_ObjStore { public: RGWStatBucket_ObjStore_S3() {} From ec07cbc13d2664d947ec3ea71cd3eaee4f5c94b3 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 26 Mar 2015 21:25:54 -0700 Subject: [PATCH 14/90] rgw: apply redirect rules in static website only when key matches, not checking for return code yet. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_common.h | 2 ++ src/rgw/rgw_rest.cc | 42 ++++++++++++++++++++++----------- src/rgw/rgw_website.cc | 53 +++++++++++++++++++++++++++--------------- src/rgw/rgw_website.h | 5 +++- 4 files changed, 68 insertions(+), 34 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index bcc83e64097f3..919ed15ade687 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -1141,6 +1141,8 @@ struct req_state { string region_endpoint; string bucket_instance_id; + string redirect; + RGWBucketInfo bucket_info; map bucket_attrs; bool bucket_exists; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 35be5d62a2ef3..5c8ddabfaaab3 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -661,20 +661,27 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no) set_req_state_err(s, err_no); dump_errno(s); dump_bucket_from_state(s); - if (err_no == -ERR_PERMANENT_REDIRECT && !s->region_endpoint.empty()) { - string dest_uri = s->region_endpoint; - /* - * reqest_uri is always start with slash, so we need to remove - * the unnecessary slash at the end of dest_uri. - */ - if (dest_uri[dest_uri.size() - 1] == '/') { - dest_uri = dest_uri.substr(0, dest_uri.size() - 1); + if (err_no == -ERR_PERMANENT_REDIRECT) { + string dest_uri; + if (!s->redirect.empty()) { + dest_uri = s->redirect; + } else if (!s->region_endpoint.empty()) { + string dest_uri = s->region_endpoint; + /* + * reqest_uri is always start with slash, so we need to remove + * the unnecessary slash at the end of dest_uri. + */ + if (dest_uri[dest_uri.size() - 1] == '/') { + dest_uri = dest_uri.substr(0, dest_uri.size() - 1); + } + dest_uri += s->info.request_uri; + dest_uri += "?"; + dest_uri += s->info.request_params; } - dest_uri += s->info.request_uri; - dest_uri += "?"; - dest_uri += s->info.request_params; - dump_redirect(s, dest_uri); + if (!dest_uri.empty()) { + dump_redirect(s, dest_uri); + } } end_header(s, op); rgw_flush_formatter_and_reset(s, s->formatter); @@ -1356,11 +1363,18 @@ int RGWHandler_ObjStore::retarget(RGWOp *op, RGWOp **new_op) { return 0; } - RGWRedirectInfo rinfo; rgw_obj_key new_obj; - s->bucket_info.website_conf.get_effective_target(s->object.name, &new_obj.name, &rinfo); + s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name); + RGWBWRoutingRule rrule; + bool should_redirect = s->bucket_info.website_conf.should_redirect(new_obj.name, &rrule); + if (should_redirect) { + const string& hostname = s->info.env->get("HTTP_HOST", ""); + const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); + rrule.apply_rule(protocol, hostname, new_obj.name, &s->redirect); + return -ERR_PERMANENT_REDIRECT; + } #warning FIXME #if 0 diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 60e75a5be2830..826e127915cf5 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -18,6 +18,26 @@ bool RGWBWRoutingRuleCondition::check_key_condition(const string& key) { } +void RGWBWRoutingRule::apply_rule(const string& default_protocol, const string& default_hostname, + const string& key, string *new_url) +{ + RGWRedirectInfo& redirect = redirect_info.redirect; + + string protocol = (redirect.protocol.empty() ? redirect.protocol : default_protocol); + string hostname = (redirect.hostname.empty() ? redirect.hostname : default_hostname); + + *new_url = protocol + "://" + hostname + "/"; + + if (!redirect_info.replace_key_prefix_with.empty()) { + *new_url = redirect_info.replace_key_prefix_with; + *new_url += key.substr(condition.key_prefix_equals.size()); + } else if (!redirect_info.replace_key_with.empty()) { + *new_url = redirect_info.replace_key_with; + } else { + *new_url = key; + } +} + bool RGWBWRoutingRules::check_key_condition(const string& key, RGWBWRoutingRule **rule) { for (list::iterator iter = rules.begin(); iter != rules.end(); ++iter) { @@ -40,30 +60,25 @@ bool RGWBWRoutingRules::check_error_code_condition(int error_code, RGWBWRoutingR return false; } -void RGWBucketWebsiteConf::get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect) +bool RGWBucketWebsiteConf::should_redirect(const string& key, RGWBWRoutingRule *redirect) { RGWBWRoutingRule *rule; - string new_key; - - if (routing_rules.check_key_condition(key, &rule)) { - RGWBWRoutingRuleCondition& condition = rule->condition; - RGWBWRedirectInfo& info = rule->redirect_info; - - if (!info.replace_key_prefix_with.empty()) { - *effective_key = info.replace_key_prefix_with; - *effective_key += key.substr(condition.key_prefix_equals.size()); - } else if (!info.replace_key_with.empty()) { - *effective_key = info.replace_key_with; - } else { - *effective_key = key; - } - *redirect = info.redirect; + if (!routing_rules.check_key_condition(key, &rule)) { + return false; } - if (effective_key->empty()) { + *redirect = *rule; + + return true; +} + +void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effective_key) +{ + + if (key.empty()) { *effective_key = index_doc_suffix; - } else if ((*effective_key)[effective_key->size() - 1] == '/') { - *effective_key += index_doc_suffix; + } else if (key[key.size() - 1] == '/') { + *effective_key = key + index_doc_suffix; } } diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 88c057a9a3fb8..c346418e90f14 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -117,6 +117,8 @@ struct RGWBWRoutingRule bool check_error_code_condition(int error_code) { return condition.check_error_code_condition(error_code); } + + void apply_rule(const string& default_protocol, const string& default_hostname, const string& key, string *redirect); }; WRITE_CLASS_ENCODER(RGWBWRoutingRule) @@ -175,7 +177,8 @@ struct RGWBucketWebsiteConf void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; - void get_effective_target(const string& key, string *effective_key, RGWRedirectInfo *redirect); + bool should_redirect(const string& key, RGWBWRoutingRule *redirect); + void get_effective_key(const string& key, string *effective_key); }; WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) From 9b7d28706ecbb4eea2fb0e3263f790dd90a0cff3 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 6 Jun 2015 05:54:11 +0000 Subject: [PATCH 15/90] rgw-website: do not truncate nuke key if valid. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 826e127915cf5..dc163c591d55b 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -80,5 +80,7 @@ void RGWBucketWebsiteConf::get_effective_key(const string& key, string *effectiv *effective_key = index_doc_suffix; } else if (key[key.size() - 1] == '/') { *effective_key = key + index_doc_suffix; + } else { + *effective_key = key; } } From 8e30ae720c733ed066afb5539999cabc67282a49 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 6 Jun 2015 07:48:18 +0000 Subject: [PATCH 16/90] rgw-website: ListBucket not valid for websites ListBucket/StatBucket are not a valid action for website mode, redirect it to GetObj instead, where it will modified via get_effective_key to point to the correct suffix document. S3 explicitly does NOT support anything like mod_autoindex when used in static website mode. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 6108bdb4b6215..8697e2d550d8d 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2086,6 +2086,25 @@ RGWOp *RGWHandler_ObjStore_Service_S3::op_head() RGWOp *RGWHandler_ObjStore_Bucket_S3::get_obj_op(bool get_data) { + /* we need to make sure we read bucket info, it's not read before for this specific request */ + RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); + int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); +#warning FIXME: Do we need to catch -ENOENT seperately? What do we do then? + if (ret < 0) + return NULL; + + /** If we are in website mode, then it is explicitly impossible to run GET or + * HEAD on the actual directory. We must convert the request to run on the + * suffix object instead! + */ + ldout(s->cct, 20) << __func__ << ": bucket=" << s->bucket_info.bucket.name << " has_website=" << s->bucket_info.has_website << " get_data=" << get_data << "/" << (get_data ? "GET" : "HEAD") << dendl; + if(s->bucket_info.has_website && !rgw_user_is_authenticated(s->user)) { + RGWGetObj_ObjStore_S3 *get_obj_op = new RGWGetObj_ObjStore_S3; + get_obj_op->set_get_data(get_data); + return get_obj_op; + } + + // Non-website mode if (get_data) return new RGWListBucket_ObjStore_S3; else From 42e60b11e5804e1d537286565f2e40ff497ac256 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 6 Jun 2015 17:03:51 +0000 Subject: [PATCH 17/90] rgw-website: cleanup unused variable: rules With the XML dumping moved, this variable is not required. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 8697e2d550d8d..2b677e5b6acab 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -567,7 +567,6 @@ void RGWGetBucketWebsite_ObjStore_S3::send_response() } RGWBucketWebsiteConf& conf = s->bucket_info.website_conf; - list& rules = conf.routing_rules.rules; s->formatter->open_object_section_in_ns("WebsiteConfiguration", "http://doc.s3.amazonaws.com/doc/2006-03-01/"); From 6b6c907f3f37e03ead70842b05e1ca52dbd8a923 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 9 Jun 2015 01:30:13 +0000 Subject: [PATCH 18/90] rgw-website: Do not apply retarget for an authenticated request. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_main.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index f57f4bb53c3db..638a0fe34f2e2 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -639,7 +639,13 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC goto done; } - if (op->supports_website()) { + /** + * Only some accesses support website mode, and website mode does NOT apply + * if you are using the REST endpoint either (ergo, no authenticated access) + */ + dout(20) << "retarget uid=" << s->user.user_id << dendl; + if (op->supports_website() && !rgw_user_is_authenticated(s->user)) { + //if (op->supports_website()) { req->log(s, "recalculating target"); ret = handler->retarget(op, &op); if (ret < 0) { From 2fa0e81747dbb7d4d6ebbcdad39cd36dcad3716d Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 9 Jun 2015 16:22:27 +0000 Subject: [PATCH 19/90] rgw-website: Use default hostname/protocol if redirect does not specify. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index dc163c591d55b..073f0bd3ed16f 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -23,8 +23,8 @@ void RGWBWRoutingRule::apply_rule(const string& default_protocol, const string& { RGWRedirectInfo& redirect = redirect_info.redirect; - string protocol = (redirect.protocol.empty() ? redirect.protocol : default_protocol); - string hostname = (redirect.hostname.empty() ? redirect.hostname : default_hostname); + string protocol = (!redirect.protocol.empty() ? redirect.protocol : default_protocol); + string hostname = (!redirect.hostname.empty() ? redirect.hostname : default_hostname); *new_url = protocol + "://" + hostname + "/"; From 2dbff7bdfb71b191c4ad1f91c0c3e7ee3c7fe329 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 9 Jun 2015 16:22:53 +0000 Subject: [PATCH 20/90] rgw-website: append the key, not overwrite. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 073f0bd3ed16f..9bf7fcaa77f9c 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -29,12 +29,12 @@ void RGWBWRoutingRule::apply_rule(const string& default_protocol, const string& *new_url = protocol + "://" + hostname + "/"; if (!redirect_info.replace_key_prefix_with.empty()) { - *new_url = redirect_info.replace_key_prefix_with; + *new_url += redirect_info.replace_key_prefix_with; *new_url += key.substr(condition.key_prefix_equals.size()); } else if (!redirect_info.replace_key_with.empty()) { - *new_url = redirect_info.replace_key_with; + *new_url += redirect_info.replace_key_with; } else { - *new_url = key; + *new_url += key; } } From 910df9c832f2835828c402ced0ac499f3df9bbb2 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 9 Jun 2015 16:23:26 +0000 Subject: [PATCH 21/90] rgw-website: handle redirect_all via RGWBWRoutingRule. Rather than duplicate code to construct the redirect if redirect_all is used, construct a catch-all RoutingRule with redirect_all as the target, and return it as the matching rule. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 9bf7fcaa77f9c..5f2bb8187d2b5 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -63,8 +63,12 @@ bool RGWBWRoutingRules::check_error_code_condition(int error_code, RGWBWRoutingR bool RGWBucketWebsiteConf::should_redirect(const string& key, RGWBWRoutingRule *redirect) { RGWBWRoutingRule *rule; - - if (!routing_rules.check_key_condition(key, &rule)) { + if(!redirect_all.hostname.empty()) { + RGWBWRoutingRule redirect_all_rule; + redirect_all_rule.redirect_info.redirect = redirect_all; + *redirect = redirect_all_rule; + return true; + } else if (!routing_rules.check_key_condition(key, &rule)) { return false; } From 20f4d6cae1e9159a84967f158c49f76cefc65f4c Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 10 Jun 2015 00:39:07 +0000 Subject: [PATCH 22/90] rgw: Add note about future rgw performance optimization for regions with many endpoint hostnames. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest.cc --- src/rgw/rgw_rest.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 5c8ddabfaaab3..8f0c2c6fe59ce 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -227,8 +227,12 @@ static bool str_ends_with(const string& s, const string& suffix, size_t *pos) static bool rgw_find_host_in_domains(const string& host, string *domain, string *subdomain) { - list::iterator iter; - for (iter = hostnames_list.begin(); iter != hostnames_list.end(); ++iter) { + set::iterator iter; + /** TODO, Future optimization + * store hostnames_set elements _reversed_, and look for a prefix match, + * which is much faster than a suffix match. + */ + for (iter = hostnames_set.begin(); iter != hostnames_set.end(); ++iter) { size_t pos; if (!str_ends_with(host, *iter, &pos)) continue; From ef9945513f1ff4a2283bc04cb69ba17352011af0 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 10 Jun 2015 00:45:40 +0000 Subject: [PATCH 23/90] RGWRegion: AmazonS3 detects website endpoint storage AmazonS3 detects S3website mode via DNS: ${bucket}.s3-website-${region}.amazonaws.com. VS: ${bucket}.s3-${region}.amazonaws.com. This allows us to store what hostnames to use for the website endpoint. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest.cc --- src/common/config_opts.h | 1 + src/rgw/rgw_rados.h | 11 +++++++++-- src/rgw/rgw_rest.cc | 29 +++++++++++++++++++++-------- 3 files changed, 31 insertions(+), 10 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 5c445c5e99725..5772f42c85037 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -955,6 +955,7 @@ OPTION(rgw_socket_path, OPT_STR, "") // path to unix domain socket, if not spe OPTION(rgw_host, OPT_STR, "") // host for radosgw, can be an IP, default is 0.0.0.0 OPTION(rgw_port, OPT_STR, "") // port to listen, format as "8080" "5000", if not specified, rgw will not run external fcgi OPTION(rgw_dns_name, OPT_STR, "") +OPTION(rgw_dns_s3website_name, OPT_STR, "") // hostname suffix on buckets for s3-website endpoint OPTION(rgw_content_length_compat, OPT_BOOL, false) // Check both HTTP_CONTENT_LENGTH and CONTENT_LENGTH in fcgi env OPTION(rgw_script_uri, OPT_STR, "") // alternative value for SCRIPT_URI if not set in request OPTION(rgw_request_uri, OPT_STR, "") // alternative value for REQUEST_URI if not set in request diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 0b4a782f65d24..b85151bc7138e 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -911,7 +911,10 @@ struct RGWRegion { map placement_targets; string default_placement; + // TODO: Maybe convert hostnames to a map> for + // endpoint_type->hostnames list hostnames; + list hostnames_s3website; CephContext *cct; RGWRados *store; @@ -919,7 +922,7 @@ struct RGWRegion { RGWRegion() : is_master(false), cct(NULL), store(NULL) {} void encode(bufferlist& bl) const { - ENCODE_START(2, 1, bl); + ENCODE_START(3, 1, bl); ::encode(name, bl); ::encode(api_name, bl); ::encode(is_master, bl); @@ -929,11 +932,12 @@ struct RGWRegion { ::encode(placement_targets, bl); ::encode(default_placement, bl); ::encode(hostnames, bl); + ::encode(hostnames_s3website, bl); ENCODE_FINISH(bl); } void decode(bufferlist::iterator& bl) { - DECODE_START(2, bl); + DECODE_START(3, bl); ::decode(name, bl); ::decode(api_name, bl); ::decode(is_master, bl); @@ -945,6 +949,9 @@ struct RGWRegion { if (struct_v >= 2) { ::decode(hostnames, bl); } + if (struct_v >= 3) { + ::decode(hostnames_s3website, bl); + } DECODE_FINISH(bl); } diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 8f0c2c6fe59ce..dcecbbcf961d7 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -164,7 +164,9 @@ string camelcase_dash_http_attr(const string& orig) return string(buf); } -static list hostnames_list; +/* avoid duplicate hostnames in hostnames lists */ +static set hostnames_set; +static set hostnames_s3website_set; void rgw_rest_init(CephContext *cct, RGWRegion& region) { @@ -199,15 +201,26 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) /* avoid duplicate hostnames in hostnames list */ map hostnames_map; if (!cct->_conf->rgw_dns_name.empty()) { - hostnames_map[cct->_conf->rgw_dns_name] = true; - } - for (list::iterator iter = region.hostnames.begin(); iter != region.hostnames.end(); ++iter) { - hostnames_map[*iter] = true; - } + hostnames_set.insert(cct->_conf->rgw_dns_name); + } + hostnames_set.insert(region.hostnames.begin(), region.hostnames.end()); + /* TODO: We should have a sanity check that no hostname matches the end of + * any other hostname, otherwise we will get ambigious results from + * rgw_find_host_in_domains. + * Eg: + * Hostnames: [A, B.A] + * Inputs: [Z.A, X.B.A] + * Z.A clearly splits to subdomain=Z, domain=Z + * X.B.A ambigously splits to both {X, B.A} and {X.B, A} + */ - for (map::iterator iter = hostnames_map.begin(); iter != hostnames_map.end(); ++iter) { - hostnames_list.push_back(iter->first); + if(!cct->_conf->rgw_dns_s3website_name.empty()) { + hostnames_s3website_set.insert(cct->_conf->rgw_dns_s3website_name); } + hostnames_s3website_set.insert(region.hostnames_s3website.begin(), region.hostnames_s3website.end()); + /* TODO: we should repeat the hostnames_set sanity check here + * and ALSO decide about overlap, if any + */ } static bool str_ends_with(const string& s, const string& suffix, size_t *pos) From 839396d5c1cb20cef4daae3cb0a2fc926840570b Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 10 Jun 2015 00:49:12 +0000 Subject: [PATCH 24/90] rgw: Document rgw_dns_name Signed-off-by: Robin H. Johnson --- src/common/config_opts.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 5772f42c85037..178fcedfdc844 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -954,7 +954,7 @@ OPTION(rgw_cache_lru_size, OPT_INT, 10000) // num of entries in rgw cache OPTION(rgw_socket_path, OPT_STR, "") // path to unix domain socket, if not specified, rgw will not run as external fcgi OPTION(rgw_host, OPT_STR, "") // host for radosgw, can be an IP, default is 0.0.0.0 OPTION(rgw_port, OPT_STR, "") // port to listen, format as "8080" "5000", if not specified, rgw will not run external fcgi -OPTION(rgw_dns_name, OPT_STR, "") +OPTION(rgw_dns_name, OPT_STR, "") // hostname suffix on buckets OPTION(rgw_dns_s3website_name, OPT_STR, "") // hostname suffix on buckets for s3-website endpoint OPTION(rgw_content_length_compat, OPT_BOOL, false) // Check both HTTP_CONTENT_LENGTH and CONTENT_LENGTH in fcgi env OPTION(rgw_script_uri, OPT_STR, "") // alternative value for SCRIPT_URI if not set in request From a40c77c6e04f632a1611401e34a922dcca13b055 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 10 Jun 2015 20:26:42 +0000 Subject: [PATCH 25/90] WIP-FIXME-TODO: Planning for hostname/endpoints specific to APIs. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rados.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index b85151bc7138e..023aebffe7faa 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -911,10 +911,24 @@ struct RGWRegion { map placement_targets; string default_placement; - // TODO: Maybe convert hostnames to a map> for - // endpoint_type->hostnames list hostnames; list hostnames_s3website; + // TODO: Maybe convert hostnames to a map> for + // endpoint_type->hostnames +/* +20:05 < _robbat21irssi> maybe I do someting like: if (hostname_map.empty()) { populate all map keys from hostnames; }; +20:05 < _robbat21irssi> but that's a later compatability migration planning bit +20:06 < yehudasa> more like if (!hostnames.empty()) { +20:06 < yehudasa> for (list::iterator iter = hostnames.begin(); iter != hostnames.end(); ++iter) { +20:06 < yehudasa> hostname_map["s3"].append(iter->second); +20:07 < yehudasa> hostname_map["s3website"].append(iter->second); +20:07 < yehudasa> s/append/push_back/g +20:08 < _robbat21irssi> inner loop over APIs +20:08 < yehudasa> yeah, probably +20:08 < _robbat21irssi> s3, s3website, swift, swith_auth, swift_website +*/ + map> api_hostname_map; + map> api_endpoints_map; CephContext *cct; RGWRados *store; From 2b29031e9b14ebdfd2c2e32c4c1b10ce6c987ebd Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 9 Jun 2015 03:33:22 +0000 Subject: [PATCH 26/90] WIP-FIXME: Static fetch works without breaking anything else, uses bucketmode&&auth to decide. WIP-FIXME rgw-website: refactor to have RGW*S3Website classes for website-specific stuff Signed-off-by: Robin H. Johnson Conflicts: src/common/config_opts.h src/rgw/rgw_rest.cc src/rgw/rgw_rest_s3.cc src/rgw/rgw_rest_s3.h --- src/common/config_opts.h | 3 +- src/rest_blame | 1724 ++++++++++++++++++++++++++++++++++ src/rgw/rgw_common.h | 6 + src/rgw/rgw_main.cc | 43 +- src/rgw/rgw_op.cc | 2 +- src/rgw/rgw_op.h | 8 + src/rgw/rgw_rados.h | 4 +- src/rgw/rgw_rest.cc | 96 +- src/rgw/rgw_rest.h | 6 +- src/rgw/rgw_rest_s3.cc | 151 ++- src/rgw/rgw_rest_s3.h | 12 +- src/rgw/rgw_rest_s3website.h | 62 ++ src/rgw/rgw_rest_swift.cc | 2 +- 13 files changed, 2019 insertions(+), 100 deletions(-) create mode 100644 src/rest_blame create mode 100644 src/rgw/rgw_rest_s3website.h diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 178fcedfdc844..13c3b7cec5dd3 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -948,7 +948,7 @@ OPTION(rgw_enable_quota_threads, OPT_BOOL, true) OPTION(rgw_enable_gc_threads, OPT_BOOL, true) OPTION(rgw_data, OPT_STR, "/var/lib/ceph/radosgw/$cluster-$id") -OPTION(rgw_enable_apis, OPT_STR, "s3, admin") //<<<<<< DSS stopped swift +OPTION(rgw_enable_apis, OPT_STR, "s3, s3website, admin") OPTION(rgw_cache_enabled, OPT_BOOL, true) // rgw cache enabled OPTION(rgw_cache_lru_size, OPT_INT, 10000) // num of entries in rgw cache OPTION(rgw_socket_path, OPT_STR, "") // path to unix domain socket, if not specified, rgw will not run as external fcgi @@ -956,6 +956,7 @@ OPTION(rgw_host, OPT_STR, "") // host for radosgw, can be an IP, default is 0.0 OPTION(rgw_port, OPT_STR, "") // port to listen, format as "8080" "5000", if not specified, rgw will not run external fcgi OPTION(rgw_dns_name, OPT_STR, "") // hostname suffix on buckets OPTION(rgw_dns_s3website_name, OPT_STR, "") // hostname suffix on buckets for s3-website endpoint +OPTION(rgw_s3website_mode, OPT_STR, "hostname, default_validity") // modes for s3website handling OPTION(rgw_content_length_compat, OPT_BOOL, false) // Check both HTTP_CONTENT_LENGTH and CONTENT_LENGTH in fcgi env OPTION(rgw_script_uri, OPT_STR, "") // alternative value for SCRIPT_URI if not set in request OPTION(rgw_request_uri, OPT_STR, "") // alternative value for REQUEST_URI if not set in request diff --git a/src/rest_blame b/src/rest_blame new file mode 100644 index 0000000000000..990a98208220c --- /dev/null +++ b/src/rest_blame @@ -0,0 +1,1724 @@ +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 1) // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 2) // vim: ts=8 sw=2 smarttab +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 3) /* +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 4) * Ceph - scalable distributed file system +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 5) * +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 6) * Copyright (C) 2004-2009 Sage Weil +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 7) * +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 8) * This is free software; you can redistribute it and/or +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 9) * modify it under the terms of the GNU Lesser General Public +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 10) * License version 2.1, as published by the Free Software +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 11) * Foundation. See file COPYING. +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 12) * +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 13) */ +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 14) +f4b9d9d8 src/rgw/rgw_common.h (Markus Elfring 2010-06-12 15:04:11 +0200 15) #ifndef CEPH_RGW_COMMON_H +f4b9d9d8 src/rgw/rgw_common.h (Markus Elfring 2010-06-12 15:04:11 +0200 16) #define CEPH_RGW_COMMON_H +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 17) +d95367cb src/rgw/rgw_common.h (Tommi Virtanen 2011-03-08 13:49:56 -0800 18) #include "common/ceph_crypto.h" +1c98da66 src/rgw/rgw_common.h (Colin P. McCabe 2011-05-10 14:08:42 -0700 19) #include "common/debug.h" +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 20) #include "common/perf_counters.h" +468c7dce src/rgw/rgw_common.h (Sage Weil 2011-10-09 15:27:10 -0700 21) +468c7dce src/rgw/rgw_common.h (Sage Weil 2011-10-09 15:27:10 -0700 22) #include "acconfig.h" +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 23) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 24) #include +f2424dfb src/rgw/rgw_common.h (Yehuda Sadeh 2010-12-03 14:45:59 -0800 25) #include +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 26) #include +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 27) #include +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 28) #include "include/types.h" +c9135519 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-08 16:49:49 -0800 29) #include "include/utime.h" +e345dfe0 src/rgw/rgw_common.h (Caleb Miles 2013-02-05 14:10:03 -0500 30) #include "rgw_acl.h" +f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 31) #include "rgw_cors.h" +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 32) #include "rgw_quota.h" +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 33) #include "rgw_string.h" +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 34) #include "rgw_website.h" +a0d238c3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-10 22:02:20 -0700 35) #include "cls/version/cls_version_types.h" +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 36) #include "cls/user/cls_user_types.h" +54f2e0ac src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 17:31:12 -0700 37) #include "cls/rgw/cls_rgw_types.h" +a0d238c3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-10 22:02:20 -0700 38) #include "include/rados/librados.hpp" +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 39) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 40) using namespace std; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 41) +76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 42) namespace ceph { +76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 43) class Formatter; +76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 44) } +76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 45) +a772c8bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-16 10:57:48 -0700 46) using ceph::crypto::MD5; +a772c8bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-16 10:57:48 -0700 47) +37c88295 src/rgw/rgw_common.h (Sage Weil 2011-10-04 15:36:15 -0700 48) +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 49) #define RGW_ATTR_PREFIX "user.rgw." +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 50) +7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 51) #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" +7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 52) #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" +7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 53) +7b3ff369 src/rgw/rgw_common.h (Shivanshu Goswami 2016-02-22 21:16:11 +0000 54) #define RGW_AMZ_META_PREFIX "x-jcs-meta-" +d6d3bf06 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-03 17:36:50 -0700 55) +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 56) #define RGW_SYS_PARAM_PREFIX "rgwx-" +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 57) +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 58) #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl" +f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 59) #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors" +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 60) #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag" +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 61) #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets" +d6d3bf06 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-03 17:36:50 -0700 62) #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 63) #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type" +f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 64) #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control" +f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 65) #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition" +f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 66) #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding" +f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 67) #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language" +f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 68) #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires" +8d63e140 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-02 16:29:16 -0700 69) #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag" +70cdd5da src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-03 16:59:33 -0700 70) #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name" +c076e351 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-01 14:03:57 -0800 71) #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest" +4d2a05f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-08-22 17:16:05 -0700 72) #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest" +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 73) +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 74) #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh." +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 75) +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 76) #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info" +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 77) #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver" +01b8e614 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-03 17:04:46 -0800 78) #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag" +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 79) #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending." +57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 80) +478fe5ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-03-22 11:01:02 -0700 81) #define RGW_BUCKETS_OBJ_SUFFIX ".buckets" +fa8fa401 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-28 15:32:05 -0800 82) +8f1beb1b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-20 17:09:27 -0700 83) #define RGW_MAX_PENDING_CHUNKS 16 +44cb0763 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-13 12:19:35 -0800 84) #define RGW_MAX_PUT_SIZE (5ULL*1024*1024*1024) +24523913 src/rgw/rgw_common.h (Caleb Miles 2012-12-04 16:36:17 -0500 85) #define RGW_MIN_MULTIPART_SIZE (5ULL*1024*1024) +925e2092 src/rgw/rgw_common.h (Yehuda Sadeh 2010-07-19 16:50:43 -0700 86) +42d873e9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-24 12:30:29 -0700 87) #define RGW_FORMAT_PLAIN 0 +fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 88) #define RGW_FORMAT_XML 1 +fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 89) #define RGW_FORMAT_JSON 2 +cc544de6 src/rgw/rgw_common.h (Robin H. Johnson 2015-08-24 02:42:56 +0000 90) #define RGW_FORMAT_HTML 3 +fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 91) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 92) #define RGW_CAP_READ 0x1 +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 93) #define RGW_CAP_WRITE 0x2 +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 94) #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 95) +e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 96) #define RGW_PROTO_SWIFT 0x1 +e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 97) #define RGW_PROTO_SWIFT_AUTH 0x2 +e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 98) #define RGW_PROTO_S3 0x4 +e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 99) #define RGW_PROTO_WEBSITE 0x8 +b738b72c src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-23 16:50:21 -0700 100) +4ca8054c src/rgw/rgw_common.h (Sage Weil 2011-06-17 09:26:32 -0700 101) #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 102) +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 103) #define RGW_OP_TYPE_READ 0x01 +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 104) #define RGW_OP_TYPE_WRITE 0x02 +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 105) #define RGW_OP_TYPE_DELETE 0x04 +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 106) +c821da95 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 16:43:10 -0700 107) #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 108) #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 109) +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 110) #define RGW_DEFAULT_MAX_BUCKETS 1000 +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 111) +1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 112) #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1 +1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 113) #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2 +1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 114) +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 115) #define STATUS_CREATED 1900 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 116) #define STATUS_ACCEPTED 1901 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 117) #define STATUS_NO_CONTENT 1902 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 118) #define STATUS_PARTIAL_CONTENT 1903 +3faf6ab5 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 09:40:39 -0700 119) #define STATUS_REDIRECT 1904 +4f9855e4 src/rgw/rgw_common.h (Greg Farnum 2013-07-16 12:23:13 -0700 120) #define STATUS_NO_APPLY 1905 +81b62b5c src/rgw/rgw_common.h (Greg Farnum 2013-07-25 16:03:54 -0700 121) #define STATUS_APPLIED 1906 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 122) +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 123) #define ERR_INVALID_BUCKET_NAME 2000 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 124) #define ERR_INVALID_OBJECT_NAME 2001 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 125) #define ERR_NO_SUCH_BUCKET 2002 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 126) #define ERR_METHOD_NOT_ALLOWED 2003 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 127) #define ERR_INVALID_DIGEST 2004 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 128) #define ERR_BAD_DIGEST 2005 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 129) #define ERR_UNRESOLVABLE_EMAIL 2006 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 130) #define ERR_INVALID_PART 2007 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 131) #define ERR_INVALID_PART_ORDER 2008 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 132) #define ERR_NO_SUCH_UPLOAD 2009 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 133) #define ERR_REQUEST_TIMEOUT 2010 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 134) #define ERR_LENGTH_REQUIRED 2011 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 135) #define ERR_REQUEST_TIME_SKEWED 2012 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 136) #define ERR_BUCKET_EXISTS 2013 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 137) #define ERR_BAD_URL 2014 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 138) #define ERR_PRECONDITION_FAILED 2015 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 139) #define ERR_NOT_MODIFIED 2016 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 140) #define ERR_INVALID_UTF8 2017 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 141) #define ERR_UNPROCESSABLE_ENTITY 2018 +44cb0763 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-13 12:19:35 -0800 142) #define ERR_TOO_LARGE 2019 +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 143) #define ERR_TOO_MANY_BUCKETS 2020 +b415fd21 src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-12 14:42:03 -0700 144) #define ERR_INVALID_REQUEST 2021 +30d11f42 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 15:36:07 -0700 145) #define ERR_TOO_SMALL 2022 +f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 146) #define ERR_NOT_FOUND 2023 +0f4c67f1 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-17 13:07:24 -0700 147) #define ERR_PERMANENT_REDIRECT 2024 +068baae7 src/rgw/rgw_common.h (Yehuda Sadeh 2013-08-09 11:52:25 -0700 148) #define ERR_LOCKED 2025 +bc98013f src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-01 11:45:03 -0700 149) #define ERR_QUOTA_EXCEEDED 2026 +ef75d720 src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-16 09:11:20 -0800 150) #define ERR_SIGNATURE_NO_MATCH 2027 +56af795b src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-16 12:27:54 -0800 151) #define ERR_INVALID_ACCESS_KEY 2028 +8bcbfbe1 src/rgw/rgw_common.h (Shivanshu Goswami 2016-03-09 23:30:50 +0000 152) #define ERR_BUCKET_ALREADY_OWNED 2029 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 153) #define ERR_USER_SUSPENDED 2100 +0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 154) #define ERR_INTERNAL_ERROR 2200 +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 155) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 156) #ifndef UINT32_MAX +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 157) #define UINT32_MAX (4294967295) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 158) #endif +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 159) +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 160) typedef void *RGWAccessHandle; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 161) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 162) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 163) /* perf counter */ +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 164) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 165) extern PerfCounters *perfcounter; +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 166) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 167) extern int rgw_perf_start(CephContext *cct); +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 168) extern void rgw_perf_stop(CephContext *cct); +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 169) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 170) enum { +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 171) l_rgw_first = 15000, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 172) l_rgw_req, +cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 173) l_rgw_failed_req, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 174) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 175) l_rgw_get, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 176) l_rgw_get_b, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 177) l_rgw_get_lat, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 178) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 179) l_rgw_put, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 180) l_rgw_put_b, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 181) l_rgw_put_lat, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 182) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 183) l_rgw_qlen, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 184) l_rgw_qactive, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 185) +cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 186) l_rgw_cache_hit, +cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 187) l_rgw_cache_miss, +cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 188) +c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 189) l_rgw_keystone_token_cache_hit, +c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 190) l_rgw_keystone_token_cache_miss, +c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 191) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 192) l_rgw_last, +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 193) }; +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 194) +0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 195) +232cd6b3 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 14:22:55 -0700 196) /* size should be the required string size + 1 */ +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 197) extern int gen_rand_base64(CephContext *cct, char *dest, int size); +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 198) extern int gen_rand_alphanumeric(CephContext *cct, char *dest, int size); +f6bb8255 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 13:36:34 -0700 199) extern int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size); +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 200) extern int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size); +caefe693 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-23 17:28:14 -0800 201) extern int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size); +6b365144 src/rgw/rgw_common.h (Yehuda Sadeh 2015-07-20 20:27:33 -0700 202) extern int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size); +232cd6b3 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 14:22:55 -0700 203) +d139f8dd src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 14:05:00 -0700 204) extern int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length); +d139f8dd src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 14:05:00 -0700 205) +7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 206) enum RGWIntentEvent { +1fe75ee6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-30 17:00:37 -0800 207) DEL_OBJ = 0, +1fe75ee6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-30 17:00:37 -0800 208) DEL_DIR = 1, +7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 209) }; +7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 210) +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 211) enum RGWObjCategory { +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 212) RGW_OBJ_CATEGORY_NONE = 0, +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 213) RGW_OBJ_CATEGORY_MAIN = 1, +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 214) RGW_OBJ_CATEGORY_SHADOW = 2, +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 215) RGW_OBJ_CATEGORY_MULTIMETA = 3, +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 216) }; +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 217) +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 218) /** Store error returns for output at a different point in the program */ +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 219) struct rgw_err { +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 220) rgw_err(); +303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 221) rgw_err(int http, const std::string &s3); +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 222) void clear(); +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 223) bool is_clear() const; +9b7f223a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 11:15:11 -0700 224) bool is_err() const; +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 225) friend std::ostream& operator<<(std::ostream& oss, const rgw_err &err); +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 226) +303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 227) int http_ret; +8836b844 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-17 04:15:10 -0700 228) int ret; +303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 229) std::string s3_code; +b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 230) std::string message; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 231) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 232) +d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 233) /* Helper class used for RGWHTTPArgs parsing */ +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 234) class NameVal +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 235) { +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 236) string str; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 237) string name; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 238) string val; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 239) public: +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 240) NameVal(string nv) : str(nv) {} +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 241) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 242) int parse(); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 243) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 244) string& get_name() { return name; } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 245) string& get_val() { return val; } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 246) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 247) +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 248) /** Stores the XML arguments associated with the HTTP request in req_state*/ +d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 249) class RGWHTTPArgs +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 250) { +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 251) string str, empty_str; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 252) map val_map; +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 253) map sys_val_map; +a0d521b2 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 13:35:47 -0700 254) map sub_resources; +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 255) +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 256) bool has_resp_modifier; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 257) public: +d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 258) RGWHTTPArgs() : has_resp_modifier(false) {} +e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 259) +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 260) /** Set the arguments; as received */ +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 261) void set(string s) { +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 262) has_resp_modifier = false; +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 263) val_map.clear(); +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 264) sub_resources.clear(); +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 265) str = s; +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 266) } +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 267) /** parse the received arguments */ +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 268) int parse(); +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 269) /** Get the value for a specific argument parameter */ +ed04755a src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-24 14:34:23 -0700 270) string& get(const string& name, bool *exists = NULL); +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 271) string& get(const char *name, bool *exists = NULL); +9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 272) int get_bool(const string& name, bool *val, bool *exists); +9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 273) int get_bool(const char *name, bool *val, bool *exists); +e274e109 src/rgw/rgw_common.h (Yehuda Sadeh 2014-05-07 16:19:56 -0700 274) void get_bool(const char *name, bool *val, bool def_val); +9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 275) +d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 276) /** see if a parameter is contained in this RGWHTTPArgs */ +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 277) bool exists(const char *name) { +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 278) map::iterator iter = val_map.find(name); +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 279) return (iter != val_map.end()); +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 280) } +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 281) bool sub_resource_exists(const char *name) { +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 282) map::iterator iter = sub_resources.find(name); +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 283) return (iter != sub_resources.end()); +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 284) } +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 285) map& get_params() { +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 286) return val_map; +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 287) } +cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 288) map& get_sub_resources() { return sub_resources; } +648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 289) unsigned get_num_params() { +648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 290) return val_map.size(); +648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 291) } +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 292) bool has_response_modifier() { +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 293) return has_resp_modifier; +97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 294) } +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 295) void set_system() { /* make all system params visible */ +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 296) map::iterator iter; +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 297) for (iter = sys_val_map.begin(); iter != sys_val_map.end(); ++iter) { +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 298) val_map[iter->first] = iter->second; +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 299) } +4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 300) } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 301) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 302) +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 303) class RGWConf; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 304) +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 305) class RGWEnv { +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 306) std::map env_map; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 307) public: +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 308) RGWConf *conf; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 309) +cc40f115 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 14:26:16 -0700 310) RGWEnv(); +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 311) ~RGWEnv(); +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 312) void init(CephContext *cct); +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 313) void init(CephContext *cct, char **envp); +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 314) void set(const char *name, const char *val); +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 315) const char *get(const char *name, const char *def_val = NULL); +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 316) int get_int(const char *name, int def_val = 0); +5d606c22 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-14 15:55:05 -0700 317) bool get_bool(const char *name, bool def_val = 0); +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 318) size_t get_size(const char *name, size_t def_val = 0); +eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 319) bool exists(const char *name); +eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 320) bool exists_prefix(const char *prefix); +0c805b6c src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 13:09:08 -0700 321) +0c805b6c src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 13:09:08 -0700 322) void remove(const char *name); +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 323) +fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 324) std::map& get_map() { return env_map; } +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 325) }; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 326) +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 327) class RGWConf { +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 328) friend class RGWEnv; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 329) protected: +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 330) void init(CephContext *cct, RGWEnv * env); +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 331) public: +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 332) RGWConf() : +1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 333) enable_ops_log(1), enable_usage_log(1), defer_to_bucket_acls(0) {} +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 334) +ec689e3e src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-05 11:57:35 -0700 335) int enable_ops_log; +744a1b31 src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 11:01:56 -0700 336) int enable_usage_log; +1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 337) uint8_t defer_to_bucket_acls; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 338) }; +059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 339) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 340) enum http_op { +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 341) OP_GET, +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 342) OP_PUT, +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 343) OP_DELETE, +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 344) OP_HEAD, +9e8484e8 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-26 15:18:48 -0700 345) OP_POST, +87941128 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-10 14:56:10 -0800 346) OP_COPY, +f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 347) OP_OPTIONS, +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 348) OP_UNKNOWN, +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 349) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 350) +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 351) class RGWAccessControlPolicy; +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 352) class JSONObj; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 353) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 354) struct RGWAccessKey { +6dcf462c src/rgw/rgw_common.h (Robin H. Johnson 2014-01-18 17:49:06 -0800 355) string id; // AccessKey +6dcf462c src/rgw/rgw_common.h (Robin H. Johnson 2014-01-18 17:49:06 -0800 356) string key; // SecretKey +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 357) string subuser; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 358) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 359) RGWAccessKey() {} +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 360) void encode(bufferlist& bl) const { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 361) ENCODE_START(2, 2, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 362) ::encode(id, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 363) ::encode(key, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 364) ::encode(subuser, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 365) ENCODE_FINISH(bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 366) } +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 367) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 368) void decode(bufferlist::iterator& bl) { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 369) DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 370) ::decode(id, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 371) ::decode(key, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 372) ::decode(subuser, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 373) DECODE_FINISH(bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 374) } +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 375) void dump(Formatter *f) const; +a7096f8f src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-20 12:13:31 -0700 376) void dump_plain(Formatter *f) const; +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 377) void dump(Formatter *f, const string& user, bool swift) const; +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 378) static void generate_test_instances(list& o); +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 379) +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 380) void decode_json(JSONObj *obj); +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 381) void decode_json(JSONObj *obj, bool swift); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 382) }; +60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 383) WRITE_CLASS_ENCODER(RGWAccessKey) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 384) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 385) struct RGWSubUser { +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 386) string name; +c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 387) uint32_t perm_mask; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 388) +c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 389) RGWSubUser() : perm_mask(0) {} +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 390) void encode(bufferlist& bl) const { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 391) ENCODE_START(2, 2, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 392) ::encode(name, bl); +c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 393) ::encode(perm_mask, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 394) ENCODE_FINISH(bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 395) } +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 396) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 397) void decode(bufferlist::iterator& bl) { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 398) DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 399) ::decode(name, bl); +c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 400) ::decode(perm_mask, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 401) DECODE_FINISH(bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 402) } +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 403) void dump(Formatter *f) const; +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 404) void dump(Formatter *f, const string& user) const; +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 405) static void generate_test_instances(list& o); +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 406) +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 407) void decode_json(JSONObj *obj); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 408) }; +60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 409) WRITE_CLASS_ENCODER(RGWSubUser) +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 410) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 411) class RGWUserCaps +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 412) { +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 413) map caps; +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 414) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 415) int get_cap(const string& cap, string& type, uint32_t *perm); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 416) int add_cap(const string& cap); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 417) int remove_cap(const string& cap); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 418) public: +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 419) static int parse_cap_perm(const string& str, uint32_t *perm); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 420) int add_from_string(const string& str); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 421) int remove_from_string(const string& str); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 422) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 423) void encode(bufferlist& bl) const { +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 424) ENCODE_START(1, 1, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 425) ::encode(caps, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 426) ENCODE_FINISH(bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 427) } +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 428) void decode(bufferlist::iterator& bl) { +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 429) DECODE_START(1, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 430) ::decode(caps, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 431) DECODE_FINISH(bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 432) } +511e639e src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 11:57:04 -0700 433) int check_cap(const string& cap, uint32_t perm); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 434) void dump(Formatter *f) const; +b07f3cda src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-12 09:40:12 -0800 435) void dump(Formatter *f, const char *name) const; +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 436) +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 437) void decode_json(JSONObj *obj); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 438) }; +60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 439) WRITE_CLASS_ENCODER(RGWUserCaps) +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 440) +3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 441) void encode_json(const char *name, const obj_version& v, Formatter *f); +b07f3cda src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-12 09:40:12 -0800 442) void encode_json(const char *name, const RGWUserCaps& val, Formatter *f); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 443) +3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 444) void decode_json_obj(obj_version& v, JSONObj *obj); +3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 445) +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 446) struct RGWUserInfo +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 447) { +edc92490 src/rgw/rgw_common.h (Sage Weil 2010-05-07 14:33:42 -0700 448) uint64_t auid; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 449) string user_id; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 450) string display_name; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 451) string user_email; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 452) map access_keys; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 453) map swift_keys; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 454) map subusers; +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 455) __u8 suspended; +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 456) uint32_t max_buckets; +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 457) uint32_t op_mask; +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 458) RGWUserCaps caps; +903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 459) __u8 system; +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 460) string default_placement; +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 461) list placement_tags; +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 462) RGWQuotaInfo bucket_quota; +7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 463) map temp_url_keys; +15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 464) RGWQuotaInfo user_quota; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 465) +d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 466) RGWUserInfo() : auid(0), suspended(0), max_buckets(RGW_DEFAULT_MAX_BUCKETS), op_mask(RGW_OP_TYPE_ALL), system(0) {} +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 467) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 468) void encode(bufferlist& bl) const { +cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 469) ENCODE_START(16, 9, bl); +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 470) ::encode(auid, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 471) string access_key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 472) string secret_key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 473) if (!access_keys.empty()) { +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 474) map::const_iterator iter = access_keys.begin(); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 475) const RGWAccessKey& k = iter->second; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 476) access_key = k.id; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 477) secret_key = k.key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 478) } +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 479) ::encode(access_key, bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 480) ::encode(secret_key, bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 481) ::encode(display_name, bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 482) ::encode(user_email, bl); +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 483) string swift_name; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 484) string swift_key; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 485) if (!swift_keys.empty()) { +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 486) map::const_iterator iter = swift_keys.begin(); +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 487) const RGWAccessKey& k = iter->second; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 488) swift_name = k.id; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 489) swift_key = k.key; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 490) } +ba7ab2f6 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-02 14:56:50 -0700 491) ::encode(swift_name, bl); +ba7ab2f6 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-02 14:56:50 -0700 492) ::encode(swift_key, bl); +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 493) ::encode(user_id, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 494) ::encode(access_keys, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 495) ::encode(subusers, bl); +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 496) ::encode(suspended, bl); +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 497) ::encode(swift_keys, bl); +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 498) ::encode(max_buckets, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 499) ::encode(caps, bl); +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 500) ::encode(op_mask, bl); +903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 501) ::encode(system, bl); +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 502) ::encode(default_placement, bl); +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 503) ::encode(placement_tags, bl); +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 504) ::encode(bucket_quota, bl); +7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 505) ::encode(temp_url_keys, bl); +15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 506) ::encode(user_quota, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 507) ENCODE_FINISH(bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 508) } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 509) void decode(bufferlist::iterator& bl) { +cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 510) DECODE_START_LEGACY_COMPAT_LEN_32(16, 9, 9, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 511) if (struct_v >= 2) ::decode(auid, bl); +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 512) else auid = CEPH_AUTH_UID_DEFAULT; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 513) string access_key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 514) string secret_key; +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 515) ::decode(access_key, bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 516) ::decode(secret_key, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 517) if (struct_v < 6) { +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 518) RGWAccessKey k; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 519) k.id = access_key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 520) k.key = secret_key; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 521) access_keys[access_key] = k; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 522) } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 523) ::decode(display_name, bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 524) ::decode(user_email, bl); +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 525) string swift_name; +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 526) string swift_key; +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 527) if (struct_v >= 3) ::decode(swift_name, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 528) if (struct_v >= 4) ::decode(swift_key, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 529) if (struct_v >= 5) +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 530) ::decode(user_id, bl); +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 531) else +544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 532) user_id = access_key; +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 533) if (struct_v >= 6) { +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 534) ::decode(access_keys, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 535) ::decode(subusers, bl); +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 536) } +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 537) suspended = 0; +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 538) if (struct_v >= 7) { +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 539) ::decode(suspended, bl); +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 540) } +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 541) if (struct_v >= 8) { +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 542) ::decode(swift_keys, bl); +f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 543) } +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 544) if (struct_v >= 10) { +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 545) ::decode(max_buckets, bl); +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 546) } else { +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 547) max_buckets = RGW_DEFAULT_MAX_BUCKETS; +5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 548) } +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 549) if (struct_v >= 11) { +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 550) ::decode(caps, bl); +d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 551) } +903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 552) if (struct_v >= 12) { +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 553) ::decode(op_mask, bl); +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 554) } else { +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 555) op_mask = RGW_OP_TYPE_ALL; +903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 556) } +d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 557) system = 0; +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 558) if (struct_v >= 13) { +d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 559) ::decode(system, bl); +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 560) ::decode(default_placement, bl); +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 561) ::decode(placement_tags, bl); /* tags of allowed placement rules */ +2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 562) } +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 563) if (struct_v >= 14) { +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 564) ::decode(bucket_quota, bl); +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 565) } +2626101f src/rgw/rgw_common.h (Yehuda Sadeh 2013-11-25 13:41:50 -0800 566) if (struct_v >= 15) { +7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 567) ::decode(temp_url_keys, bl); +2626101f src/rgw/rgw_common.h (Yehuda Sadeh 2013-11-25 13:41:50 -0800 568) } +cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 569) if (struct_v >= 16) { +15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 570) ::decode(user_quota, bl); +15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 571) } +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 572) DECODE_FINISH(bl); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 573) } +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 574) void dump(Formatter *f) const; +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 575) static void generate_test_instances(list& o); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 576) +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 577) void decode_json(JSONObj *obj); +da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 578) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 579) void clear() { +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 580) user_id.clear(); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 581) display_name.clear(); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 582) user_email.clear(); +83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 583) auid = CEPH_AUTH_UID_DEFAULT; +2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 584) access_keys.clear(); +9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 585) suspended = 0; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 586) } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 587) }; +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 588) WRITE_CLASS_ENCODER(RGWUserInfo) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 589) +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 590) struct rgw_bucket { +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 591) std::string name; +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 592) std::string data_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 593) std::string data_extra_pool; /* if not set, then we should use data_pool instead */ +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 594) std::string index_pool; +25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 595) std::string marker; +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 596) std::string bucket_id; +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 597) +68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 598) std::string oid; /* +68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 599) * runtime in-memory only info. If not empty, points to the bucket instance object +68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 600) */ +68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 601) +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 602) rgw_bucket() { } +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 603) rgw_bucket(const cls_user_bucket& b) { +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 604) name = b.name; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 605) data_pool = b.data_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 606) data_extra_pool = b.data_extra_pool; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 607) index_pool = b.index_pool; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 608) marker = b.marker; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 609) bucket_id = b.bucket_id; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 610) } +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 611) rgw_bucket(const char *n) : name(n) { +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 612) assert(*n == '.'); // only rgw private buckets should be initialized without pool +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 613) data_pool = index_pool = n; +25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 614) marker = ""; +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 615) } +0f4c67f1 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-17 13:07:24 -0700 616) rgw_bucket(const char *n, const char *dp, const char *ip, const char *m, const char *id, const char *h) : +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 617) name(n), data_pool(dp), index_pool(ip), marker(m), bucket_id(id) {} +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 618) +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 619) void convert(cls_user_bucket *b) { +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 620) b->name = name; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 621) b->data_pool = data_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 622) b->data_extra_pool = data_extra_pool; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 623) b->index_pool = index_pool; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 624) b->marker = marker; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 625) b->bucket_id = bucket_id; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 626) } +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 627) +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 628) void encode(bufferlist& bl) const { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 629) ENCODE_START(7, 3, bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 630) ::encode(name, bl); +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 631) ::encode(data_pool, bl); +25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 632) ::encode(marker, bl); +c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 633) ::encode(bucket_id, bl); +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 634) ::encode(index_pool, bl); +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 635) ::encode(data_extra_pool, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 636) ENCODE_FINISH(bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 637) } +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 638) void decode(bufferlist::iterator& bl) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 639) DECODE_START_LEGACY_COMPAT_LEN(7, 3, 3, bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 640) ::decode(name, bl); +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 641) ::decode(data_pool, bl); +c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 642) if (struct_v >= 2) { +25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 643) ::decode(marker, bl); +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 644) if (struct_v <= 3) { +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 645) uint64_t id; +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 646) ::decode(id, bl); +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 647) char buf[16]; +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 648) snprintf(buf, sizeof(buf), "%llu", (long long)id); +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 649) bucket_id = buf; +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 650) } else { +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 651) ::decode(bucket_id, bl); +6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 652) } +c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 653) } +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 654) if (struct_v >= 5) { +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 655) ::decode(index_pool, bl); +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 656) } else { +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 657) index_pool = data_pool; +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 658) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 659) if (struct_v >= 7) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 660) ::decode(data_extra_pool, bl); +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 661) } +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 662) DECODE_FINISH(bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 663) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 664) +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 665) const string& get_data_extra_pool() { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 666) if (data_extra_pool.empty()) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 667) return data_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 668) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 669) return data_extra_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 670) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 671) +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 672) void dump(Formatter *f) const; +770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 673) void decode_json(JSONObj *obj); +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 674) static void generate_test_instances(list& o); +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 675) +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 676) bool operator<(const rgw_bucket& b) const { +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 677) return name.compare(b.name) < 0; +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 678) } +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 679) }; +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 680) WRITE_CLASS_ENCODER(rgw_bucket) +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 681) +f106e1a5 src/rgw/rgw_common.h (Danny Al-Gaaf 2013-03-11 15:35:53 +0100 682) inline ostream& operator<<(ostream& out, const rgw_bucket &b) { +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 683) out << b.name; +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 684) if (b.name.compare(b.data_pool)) { +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 685) out << "(@"; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 686) string s; +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 687) if (!b.index_pool.empty() && b.data_pool.compare(b.index_pool)) +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 688) s = "i=" + b.index_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 689) if (!b.data_extra_pool.empty() && b.data_pool.compare(b.data_extra_pool)) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 690) if (!s.empty()) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 691) s += ","; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 692) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 693) s += "e=" + b.data_extra_pool; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 694) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 695) if (!s.empty()) { +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 696) out << "{" << s << "}"; +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 697) } +3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 698) +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 699) out << b.data_pool << "[" << b.marker << "])"; +988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 700) } +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 701) return out; +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 702) } +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 703) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 704) struct rgw_bucket_shard { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 705) rgw_bucket bucket; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 706) int shard_id; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 707) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 708) rgw_bucket_shard() : shard_id(-1) {} +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 709) rgw_bucket_shard(rgw_bucket& _b, int _sid) : bucket(_b), shard_id(_sid) {} +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 710) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 711) bool operator<(const rgw_bucket_shard& b) const { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 712) if (bucket < b.bucket) { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 713) return true; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 714) } +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 715) if (b.bucket < bucket) { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 716) return false; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 717) } +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 718) return shard_id < b.shard_id; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 719) } +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 720) }; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 721) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 722) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 723) struct RGWObjVersionTracker { +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 724) obj_version read_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 725) obj_version write_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 726) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 727) obj_version *version_for_read() { +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 728) return &read_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 729) } +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 730) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 731) obj_version *version_for_write() { +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 732) if (write_version.ver == 0) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 733) return NULL; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 734) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 735) return &write_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 736) } +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 737) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 738) obj_version *version_for_check() { +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 739) if (read_version.ver == 0) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 740) return NULL; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 741) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 742) return &read_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 743) } +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 744) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 745) void prepare_op_for_read(librados::ObjectReadOperation *op); +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 746) void prepare_op_for_write(librados::ObjectWriteOperation *op); +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 747) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 748) void apply_write() { +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 749) read_version = write_version; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 750) write_version = obj_version(); +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 751) } +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 752) +859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 753) void clear() { +859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 754) read_version = obj_version(); +859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 755) write_version = obj_version(); +859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 756) } +859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 757) +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 758) void generate_new_write_ver(CephContext *cct); +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 759) }; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 760) +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 761) enum RGWBucketFlags { +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 762) BUCKET_SUSPENDED = 0x1, +8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 763) BUCKET_VERSIONED = 0x2, +8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 764) BUCKET_VERSIONS_SUSPENDED = 0x4, +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 765) }; +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 766) +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 767) struct RGWBucketInfo +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 768) { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 769) enum BIShardsHashType { +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 770) MOD = 0 +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 771) }; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 772) +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 773) rgw_bucket bucket; +0eb433d4 src/rgw/rgw_common.h (Greg Farnum 2011-09-28 13:51:20 -0700 774) string owner; +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 775) uint32_t flags; +c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 776) string region; +a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 777) time_t creation_time; +d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 778) string placement_rule; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 779) bool has_instance_obj; +dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 780) RGWObjVersionTracker objv_tracker; /* we don't need to serialize this, for runtime tracking */ +7cd0bd85 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-18 17:40:52 -0700 781) obj_version ep_objv; /* entry point object version, for runtime tracking only */ +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 782) RGWQuotaInfo quota; +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 783) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 784) // Represents the number of bucket index object shards: +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 785) // - value of 0 indicates there is no sharding (this is by default before this +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 786) // feature is implemented). +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 787) // - value of UINT32_T::MAX indicates this is a blind bucket. +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 788) uint32_t num_shards; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 789) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 790) // Represents the bucket index shard hash type. +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 791) uint8_t bucket_index_shard_hash_type; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 792) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 793) // Represents the shard number for blind bucket. +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 794) const static uint32_t NUM_SHARDS_BLIND_BUCKET; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 795) +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 796) bool has_website; +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 797) RGWBucketWebsiteConf website_conf; +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 798) +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 799) void encode(bufferlist& bl) const { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 800) ENCODE_START(12, 4, bl); +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 801) ::encode(bucket, bl); +560f90c5 src/rgw/rgw_common.h (Sage Weil 2011-09-29 16:32:14 -0700 802) ::encode(owner, bl); +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 803) ::encode(flags, bl); +c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 804) ::encode(region, bl); +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 805) uint64_t ct = (uint64_t)creation_time; +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 806) ::encode(ct, bl); +d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 807) ::encode(placement_rule, bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 808) ::encode(has_instance_obj, bl); +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 809) ::encode(quota, bl); +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 810) ::encode(num_shards, bl); +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 811) ::encode(bucket_index_shard_hash_type, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 812) ::encode(has_website, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 813) if (has_website) { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 814) ::encode(website_conf, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 815) } +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 816) ENCODE_FINISH(bl); +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 817) } +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 818) void decode(bufferlist::iterator& bl) { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 819) DECODE_START_LEGACY_COMPAT_LEN_32(12, 4, 4, bl); +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 820) ::decode(bucket, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 821) if (struct_v >= 2) +560f90c5 src/rgw/rgw_common.h (Sage Weil 2011-09-29 16:32:14 -0700 822) ::decode(owner, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 823) if (struct_v >= 3) +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 824) ::decode(flags, bl); +c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 825) if (struct_v >= 5) +c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 826) ::decode(region, bl); +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 827) if (struct_v >= 6) { +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 828) uint64_t ct; +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 829) ::decode(ct, bl); +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 830) creation_time = (time_t)ct; +cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 831) } +d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 832) if (struct_v >= 7) +d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 833) ::decode(placement_rule, bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 834) if (struct_v >= 8) +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 835) ::decode(has_instance_obj, bl); +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 836) if (struct_v >= 9) +434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 837) ::decode(quota, bl); +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 838) if (struct_v >= 10) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 839) ::decode(num_shards, bl); +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 840) if (struct_v >= 11) +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 841) ::decode(bucket_index_shard_hash_type, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 842) if (struct_v >= 12) { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 843) ::decode(has_website, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 844) if (has_website) { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 845) ::decode(website_conf, bl); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 846) } else { +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 847) website_conf = RGWBucketWebsiteConf(); +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 848) } +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 849) } +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 850) DECODE_FINISH(bl); +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 851) } +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 852) void dump(Formatter *f) const; +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 853) static void generate_test_instances(list& o); +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 854) +770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 855) void decode_json(JSONObj *obj); +770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 856) +8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 857) bool versioned() { return (flags & BUCKET_VERSIONED) != 0; } +7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 858) int versioning_status() { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); } +7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 859) bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED; } +8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 860) +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 861) RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), +c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 862) has_website(false) {} +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 863) }; +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 864) WRITE_CLASS_ENCODER(RGWBucketInfo) +3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 865) +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 866) struct RGWBucketEntryPoint +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 867) { +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 868) rgw_bucket bucket; +7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 869) string owner; +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 870) time_t creation_time; +6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 871) bool linked; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 872) +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 873) bool has_bucket_info; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 874) RGWBucketInfo old_bucket_info; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 875) +6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 876) RGWBucketEntryPoint() : creation_time(0), linked(false), has_bucket_info(false) {} +ad640672 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 13:12:59 -0700 877) +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 878) void encode(bufferlist& bl) const { +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 879) ENCODE_START(8, 8, bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 880) ::encode(bucket, bl); +7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 881) ::encode(owner, bl); +6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 882) ::encode(linked, bl); +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 883) uint64_t ctime = (uint64_t)creation_time; +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 884) ::encode(ctime, bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 885) ENCODE_FINISH(bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 886) } +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 887) void decode(bufferlist::iterator& bl) { +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 888) bufferlist::iterator orig_iter = bl; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 889) DECODE_START_LEGACY_COMPAT_LEN_32(8, 4, 4, bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 890) if (struct_v < 8) { +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 891) /* ouch, old entry, contains the bucket info itself */ +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 892) old_bucket_info.decode(orig_iter); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 893) has_bucket_info = true; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 894) return; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 895) } +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 896) has_bucket_info = false; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 897) ::decode(bucket, bl); +7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 898) ::decode(owner, bl); +6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 899) ::decode(linked, bl); +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 900) uint64_t ctime; +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 901) ::decode(ctime, bl); +63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 902) creation_time = (uint64_t)ctime; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 903) DECODE_FINISH(bl); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 904) } +71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 905) +71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 906) void dump(Formatter *f) const; +71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 907) void decode_json(JSONObj *obj); +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 908) }; +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 909) WRITE_CLASS_ENCODER(RGWBucketEntryPoint) +c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 910) +4aee3fa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 21:37:34 -0800 911) struct RGWStorageStats +0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 912) { +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 913) RGWObjCategory category; +0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 914) uint64_t num_kb; +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 915) uint64_t num_kb_rounded; +0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 916) uint64_t num_objects; +80659cce src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-02 16:34:40 -0700 917) +c13634e8 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 13:44:56 -0800 918) RGWStorageStats() : category(RGW_OBJ_CATEGORY_NONE), num_kb(0), num_kb_rounded(0), num_objects(0) {} +7e13ac8e src/rgw/rgw_common.h (Ray Lv 2014-09-10 15:33:22 +0800 919) +7e13ac8e src/rgw/rgw_common.h (Ray Lv 2014-09-10 15:33:22 +0800 920) void dump(Formatter *f) const; +0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 921) }; +0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 922) +fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 923) struct req_state; +fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 924) +e1666d04 src/rgw/rgw_common.h (Christophe Courtaut 2013-08-09 11:58:58 +0200 925) class RGWEnv; +a9c9f96b src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-19 12:36:44 -0700 926) +a9c9f96b src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-19 12:36:44 -0700 927) class RGWClientIO; +43575c7a src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-19 14:02:11 -0700 928) +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 929) struct req_info { +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 930) RGWEnv *env; +d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 931) RGWHTTPArgs args; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 932) map x_meta_map; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 933) +a3afb3f5 src/rgw/rgw_common.h (Sage Weil 2015-06-09 14:15:10 -0400 934) string host; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 935) const char *method; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 936) string script_uri; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 937) string request_uri; +8a2eb184 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-22 13:33:33 -0700 938) string effective_uri; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 939) string request_params; +90c5869b src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 18:00:10 -0800 940) string domain; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 941) +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 942) req_info(CephContext *cct, RGWEnv *_env); +580a08c6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 23:14:35 -0700 943) void rebuild_from(req_info& src); +f67bfa24 src/rgw/rgw_common.h (Dmytro Iurchenko 2015-02-03 17:54:38 +0200 944) void init_meta_info(bool *found_bad_meta); +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 945) }; +c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 946) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 947) struct rgw_obj_key { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 948) string name; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 949) string instance; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 950) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 951) rgw_obj_key() {} +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 952) rgw_obj_key(const string& n) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 953) set(n); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 954) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 955) rgw_obj_key(const string& n, const string& i) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 956) set(n, i); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 957) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 958) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 959) void set(const cls_rgw_obj_key& k) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 960) name = k.name; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 961) instance = k.instance; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 962) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 963) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 964) void transform(cls_rgw_obj_key *k) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 965) k->name = name; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 966) k->instance = instance; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 967) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 968) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 969) void set(const string& n) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 970) name = n; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 971) instance.clear(); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 972) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 973) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 974) void set(const string& n, const string& i) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 975) name = n; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 976) instance = i; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 977) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 978) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 979) bool empty() { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 980) return name.empty(); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 981) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 982) bool operator==(const rgw_obj_key& k) const { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 983) return (name.compare(k.name) == 0) && +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 984) (instance.compare(k.instance) == 0); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 985) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 986) bool operator<(const rgw_obj_key& k) const { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 987) int r = name.compare(k.name); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 988) if (r == 0) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 989) r = instance.compare(k.instance); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 990) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 991) return (r < 0); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 992) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 993) void encode(bufferlist& bl) const { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 994) ENCODE_START(1, 1, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 995) ::encode(name, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 996) ::encode(instance, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 997) ENCODE_FINISH(bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 998) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 999) void decode(bufferlist::iterator& bl) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1000) DECODE_START(1, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1001) ::decode(name, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1002) ::decode(instance, bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1003) DECODE_FINISH(bl); +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1004) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1005) void dump(Formatter *f) const; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1006) }; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1007) WRITE_CLASS_ENCODER(rgw_obj_key) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1008) +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1009) inline ostream& operator<<(ostream& out, const rgw_obj_key &o) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1010) if (o.instance.empty()) { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1011) return out << o.name; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1012) } else { +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1013) return out << o.name << "[" << o.instance << "]"; +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1014) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1015) } +7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1016) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1017) /* Holds info on whether the request should be +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1018) * validated via EC2 signature or Auth tokens. +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1019) * Holds value when the action is COPY +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1020) * Holds value when the token to be validated is from a presigned URL */ +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1021) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1022) class authorization_method { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1023) private: +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1024) bool _token_validation; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1025) bool _copy_action; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1026) bool _url_type_token; +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1027) bool _infinite_url_type_token; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1028) bool _acl_main_override; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1029) bool _acl_copy_override; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1030) string _token; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1031) string _copy_source; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1032) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1033) public: +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1034) inline bool get_token_validation() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1035) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1036) return _token_validation; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1037) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1038) inline void set_token_validation(bool method) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1039) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1040) _token_validation = method; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1041) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1042) inline string get_token() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1043) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1044) return _token; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1045) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1046) inline void set_token(string tok) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1047) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1048) _token = tok; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1049) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1050) inline bool get_copy_action() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1051) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1052) return _copy_action; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1053) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1054) inline void set_copy_action(bool action) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1055) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1056) _copy_action = action; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1057) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1058) inline string get_copy_source() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1059) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1060) return _copy_source; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1061) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1062) inline void set_copy_source(string source) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1063) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1064) _copy_source = source; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1065) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1066) inline bool get_url_type_token() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1067) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1068) return _url_type_token; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1069) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1070) inline void set_url_type_token(bool val) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1071) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1072) _url_type_token = val; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1073) } +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1074) inline bool get_infinite_url_type_token() +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1075) { +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1076) return _infinite_url_type_token; +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1077) } +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1078) inline void set_infinite_url_type_token(bool val) +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1079) { +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1080) _infinite_url_type_token = val; +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1081) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1082) inline bool get_acl_main_override() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1083) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1084) return _acl_main_override; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1085) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1086) inline void set_acl_main_override(bool val) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1087) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1088) _acl_main_override = val; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1089) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1090) inline bool get_acl_copy_override() +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1091) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1092) return _acl_copy_override; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1093) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1094) inline void set_acl_copy_override(bool val) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1095) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1096) _acl_copy_override = val; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1097) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1098) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1099) +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1100) authorization_method(bool method, bool action, bool url_token, +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1101) bool infini_token, bool acl_main, bool acl_copy) : +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1102) _token_validation(method), +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1103) _copy_action(action), +6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1104) _url_type_token(url_token), +4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1105) _infinite_url_type_token(infini_token), +6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1106) _acl_main_override(acl_main), +6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1107) _acl_copy_override(acl_copy) { } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1108) ~authorization_method() { } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1109) }; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1110) +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1111) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1112) /** Store all the state necessary to complete and respond to an HTTP request*/ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1113) struct req_state { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1114) CephContext *cct; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1115) RGWClientIO *cio; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1116) http_op op; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1117) bool content_started; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1118) int format; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1119) ceph::Formatter *formatter; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1120) string decoded_uri; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1121) string relative_uri; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1122) const char *length; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1123) int64_t content_length; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1124) map generic_attrs; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1125) struct rgw_err err; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1126) bool expect_cont; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1127) bool header_ended; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1128) uint64_t obj_size; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1129) bool enable_ops_log; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1130) bool enable_usage_log; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1131) uint8_t defer_to_bucket_acls; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1132) uint32_t perm_mask; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1133) utime_t header_time; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1134) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1135) rgw_bucket bucket; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1136) string bucket_name_str; +c270db3a src/rgw/rgw_common.h (Gaurav Bafna 2016-04-14 15:00:01 +0530 1137) string bucket_owner_id; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1138) rgw_obj_key object; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1139) string src_bucket_name; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1140) rgw_obj_key src_object; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1141) ACLOwner bucket_owner; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1142) ACLOwner owner; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1143) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1144) string region_endpoint; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1145) string bucket_instance_id; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1146) +ec07cbc1 src/rgw/rgw_common.h (Yehuda Sadeh 2015-03-26 21:25:54 -0700 1147) string redirect; +ec07cbc1 src/rgw/rgw_common.h (Yehuda Sadeh 2015-03-26 21:25:54 -0700 1148) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1149) RGWBucketInfo bucket_info; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1150) map bucket_attrs; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1151) bool bucket_exists; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1152) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1153) bool has_bad_meta; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1154) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1155) RGWUserInfo user; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1156) RGWAccessControlPolicy *bucket_acl; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1157) RGWAccessControlPolicy *object_acl; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1158) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1159) bool system_request; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1160) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1161) string canned_acl; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1162) bool has_acl_header; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1163) const char *copy_source; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1164) const char *http_auth; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1165) bool local_source; /* source is local */ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1166) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1167) int prot_flags; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1168) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1169) const char *os_auth_token; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1170) string swift_user; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1171) string swift_groups; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1172) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1173) utime_t time; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1174) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1175) void *obj_ctx; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1176) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1177) string dialect; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1178) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1179) string req_id; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1180) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1181) string trans_id; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1182) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1183) req_info info; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1184) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1185) authorization_method auth_method; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1186) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1187) req_state(CephContext *_cct, class RGWEnv *e); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1188) ~req_state(); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1189) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1190) +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1191) /** Store basic data on an object */ +d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 1192) struct RGWObjEnt { +cb3694fb src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 15:12:21 -0700 1193) rgw_obj_key key; +49b3d2e0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-16 17:44:46 -0700 1194) std::string ns; +edc6659b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-10 15:01:04 -0700 1195) std::string owner; +edc6659b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-10 15:01:04 -0700 1196) std::string owner_display_name; +df2967a6 src/rgw/rgw_common.h (Greg Farnum 2011-10-24 15:22:35 -0700 1197) uint64_t size; +b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1198) utime_t mtime; +98d0361d src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-21 17:14:48 -0700 1199) string etag; +b738b72c src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-23 16:50:21 -0700 1200) string content_type; +b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1201) string tag; +105ba489 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 09:48:17 -0700 1202) uint32_t flags; +ecd5496d src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-18 16:43:17 -0800 1203) uint64_t versioned_epoch; +8b4b8384 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 13:26:19 -0700 1204) +ecd5496d src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-18 16:43:17 -0800 1205) RGWObjEnt() : size(0), flags(0), versioned_epoch(0) {} +e6e36c0a src/rgw/rgw_common.h (Sage Weil 2012-07-03 18:51:02 -0700 1206) +b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1207) void dump(Formatter *f) const; +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1208) +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1209) bool is_current() { +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1210) uint32_t test_flags = RGW_BUCKET_DIRENT_FLAG_VER | RGW_BUCKET_DIRENT_FLAG_CURRENT; +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1211) return (flags & RGW_BUCKET_DIRENT_FLAG_VER) == 0 || +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1212) (flags & test_flags) == test_flags; +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1213) } +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1214) bool is_delete_marker() { return (flags & RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER) != 0; } +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1215) bool is_visible() { +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1216) return is_current() && !is_delete_marker(); +debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1217) } +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1218) }; +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1219) +6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 1220) /** Store basic data on bucket */ +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1221) struct RGWBucketEnt { +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1222) rgw_bucket bucket; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1223) size_t size; +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1224) size_t size_rounded; +a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1225) time_t creation_time; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1226) uint64_t count; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1227) +a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1228) RGWBucketEnt() : size(0), size_rounded(0), creation_time(0), count(0) {} +949f24d5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-12-30 14:18:40 -0800 1229) +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1230) RGWBucketEnt(const cls_user_bucket_entry& e) { +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1231) bucket = e.bucket; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1232) size = e.size; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1233) size_rounded = e.size_rounded; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1234) creation_time = e.creation_time; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1235) count = e.count; +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1236) } +23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1237) +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1238) void convert(cls_user_bucket_entry *b) { +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1239) bucket.convert(&b->bucket); +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1240) b->size = size; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1241) b->size_rounded = size_rounded; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1242) b->creation_time = creation_time; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1243) b->count = count; +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1244) } +c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1245) +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1246) void encode(bufferlist& bl) const { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1247) ENCODE_START(5, 5, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1248) uint64_t s = size; +a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1249) __u32 mt = creation_time; +9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1250) string empty_str; // originally had the bucket name here, but we encode bucket later +9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1251) ::encode(empty_str, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1252) ::encode(s, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1253) ::encode(mt, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1254) ::encode(count, bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1255) ::encode(bucket, bl); +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1256) s = size_rounded; +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1257) ::encode(s, bl); +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1258) ENCODE_FINISH(bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1259) } +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1260) void decode(bufferlist::iterator& bl) { +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1261) DECODE_START_LEGACY_COMPAT_LEN(5, 5, 5, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1262) __u32 mt; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1263) uint64_t s; +9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1264) string empty_str; // backward compatibility +9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1265) ::decode(empty_str, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1266) ::decode(s, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1267) ::decode(mt, bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1268) size = s; +a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1269) creation_time = mt; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1270) if (struct_v >= 2) +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1271) ::decode(count, bl); +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1272) if (struct_v >= 3) +ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1273) ::decode(bucket, bl); +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1274) if (struct_v >= 4) +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1275) ::decode(s, bl); +7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1276) size_rounded = s; +ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1277) DECODE_FINISH(bl); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1278) } +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 1279) void dump(Formatter *f) const; +2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 1280) static void generate_test_instances(list& o); +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1281) }; +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1282) WRITE_CLASS_ENCODER(RGWBucketEnt) +9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1283) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1284) class rgw_obj { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1285) std::string orig_obj; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1286) std::string loc; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1287) std::string object; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1288) std::string instance; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1289) public: +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1290) const std::string& get_object() const { return object; } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1291) const std::string& get_orig_obj() const { return orig_obj; } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1292) const std::string& get_loc() const { return loc; } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1293) const std::string& get_instance() const { return instance; } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1294) rgw_bucket bucket; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1295) std::string ns; +8bd984d9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-08 12:32:50 -0700 1296) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1297) bool in_extra_data; /* in-memory only member, does not serialize */ +7989cbd4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 13:24:55 -0700 1298) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1299) // Represents the hash index source for this object once it is set (non-empty) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1300) std::string index_hash_source; +6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 1301) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1302) rgw_obj() : in_extra_data(false) {} +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1303) rgw_obj(rgw_bucket& b, const std::string& o) : in_extra_data(false) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1304) init(b, o); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1305) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1306) rgw_obj(rgw_bucket& b, const rgw_obj_key& k) : in_extra_data(false) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1307) init(b, k.name); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1308) set_instance(k.instance); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1309) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1310) void init(rgw_bucket& b, const std::string& o) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1311) bucket = b; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1312) set_obj(o); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1313) reset_loc(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1314) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1315) void init_ns(rgw_bucket& b, const std::string& o, const std::string& n) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1316) bucket = b; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1317) set_ns(n); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1318) set_obj(o); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1319) reset_loc(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1320) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1321) int set_ns(const char *n) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1322) if (!n) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1323) return -EINVAL; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1324) string ns_str(n); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1325) return set_ns(ns_str); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1326) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1327) int set_ns(const string& n) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1328) if (n[0] == '_') +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1329) return -EINVAL; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1330) ns = n; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1331) set_obj(orig_obj); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1332) return 0; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1333) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1334) int set_instance(const string& i) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1335) if (i[0] == '_') +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1336) return -EINVAL; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1337) instance = i; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1338) set_obj(orig_obj); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1339) return 0; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1340) } +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1341) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1342) int clear_instance() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1343) return set_instance(string()); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1344) } +cb94d55c src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-15 22:12:48 -0800 1345) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1346) void set_loc(const string& k) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1347) loc = k; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1348) } +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1349) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1350) void reset_loc() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1351) loc.clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1352) /* +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1353) * For backward compatibility. Older versions used to have object locator on all objects, +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1354) * however, the orig_obj was the effective object locator. This had the same effect as not +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1355) * having object locator at all for most objects but the ones that started with underscore as +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1356) * these were escaped. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1357) */ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1358) if (orig_obj[0] == '_' && ns.empty()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1359) loc = orig_obj; +512ae4cb src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-21 17:31:41 -0700 1360) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1361) } +4e9ebd6b src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-05 12:37:05 -0800 1362) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1363) bool have_null_instance() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1364) return instance == "null"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1365) } +3e48a49f src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-28 17:01:34 -0700 1366) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1367) bool have_instance() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1368) return !instance.empty(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1369) } +7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 1370) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1371) bool need_to_encode_instance() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1372) return have_instance() && !have_null_instance(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1373) } +524a155e src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-25 14:08:01 -0700 1374) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1375) void set_obj(const string& o) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1376) object.reserve(128); +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1377) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1378) orig_obj = o; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1379) if (ns.empty() && !need_to_encode_instance()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1380) if (o.empty()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1381) return; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1382) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1383) if (o.size() < 1 || o[0] != '_') { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1384) object = o; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1385) return; +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1386) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1387) object = "_"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1388) object.append(o); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1389) } else { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1390) object = "_"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1391) object.append(ns); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1392) if (need_to_encode_instance()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1393) object.append(string(":") + instance); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1394) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1395) object.append("_"); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1396) object.append(o); +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1397) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1398) reset_loc(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1399) } +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1400) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1401) /* +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1402) * get the object's key name as being referred to by the bucket index. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1403) */ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1404) string get_index_key_name() const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1405) if (ns.empty()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1406) if (orig_obj.size() < 1 || orig_obj[0] != '_') { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1407) return orig_obj; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1408) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1409) return string("_") + orig_obj; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1410) }; +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1411) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1412) char buf[ns.size() + 16]; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1413) snprintf(buf, sizeof(buf), "_%s_", ns.c_str()); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1414) return string(buf) + orig_obj; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1415) }; +cb3694fb src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 15:12:21 -0700 1416) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1417) void get_index_key(rgw_obj_key *key) const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1418) key->name = get_index_key_name(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1419) key->instance = instance; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1420) } +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1421) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1422) static void parse_ns_field(string& ns, string& instance) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1423) int pos = ns.find(':'); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1424) if (pos >= 0) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1425) instance = ns.substr(pos + 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1426) ns = ns.substr(0, pos); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1427) } else { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1428) instance.clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1429) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1430) } +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1431) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1432) string& get_hash_object() { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1433) return index_hash_source.empty() ? orig_obj : index_hash_source; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1434) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1435) /** +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1436) * Translate a namespace-mangled object name to the user-facing name +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1437) * existing in the given namespace. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1438) * +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1439) * If the object is part of the given namespace, it returns true +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1440) * and cuts down the name to the unmangled version. If it is not +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1441) * part of the given namespace, it returns false. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1442) */ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1443) static bool translate_raw_obj_to_obj_in_ns(string& obj, string& instance, string& ns) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1444) if (obj[0] != '_') { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1445) if (ns.empty()) { +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1446) return true; +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1447) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1448) return false; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1449) } +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1450) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1451) string obj_ns; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1452) bool ret = parse_raw_oid(obj, &obj, &instance, &obj_ns); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1453) if (!ret) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1454) return ret; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1455) } +6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1456) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1457) return (ns == obj_ns); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1458) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1459) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1460) static bool parse_raw_oid(const string& oid, string *obj_name, string *obj_instance, string *obj_ns) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1461) obj_instance->clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1462) obj_ns->clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1463) if (oid[0] != '_') { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1464) *obj_name = oid; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1465) return true; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1466) } +6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1467) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1468) if (oid.size() >= 2 && oid[1] == '_') { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1469) *obj_name = oid.substr(1); +6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1470) return true; +6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1471) } +6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1472) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1473) if (oid[0] != '_' || oid.size() < 3) // for namespace, min size would be 3: _x_ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1474) return false; +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1475) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1476) int pos = oid.find('_', 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1477) if (pos <= 1) // if it starts with __, it's not in our namespace +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1478) return false; +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1479) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1480) *obj_ns = oid.substr(1, pos - 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1481) parse_ns_field(*obj_ns, *obj_instance); +802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1482) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1483) *obj_name = oid.substr(pos + 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1484) return true; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1485) } +e6eef5e9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-30 17:13:42 -0700 1486) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1487) /** +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1488) * Given a mangled object name and an empty namespace string, this +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1489) * function extracts the namespace into the string and sets the object +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1490) * name to be the unmangled version. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1491) * +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1492) * It returns true after successfully doing so, or +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1493) * false if it fails. +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1494) */ +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1495) static bool strip_namespace_from_object(string& obj, string& ns, string& instance) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1496) ns.clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1497) instance.clear(); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1498) if (obj[0] != '_') { +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1499) return true; +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1500) } +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1501) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1502) size_t pos = obj.find('_', 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1503) if (pos == string::npos) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1504) return false; +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1505) } +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1506) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1507) size_t period_pos = obj.find('.'); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1508) if (period_pos < pos) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1509) return false; +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1510) } +f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1511) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1512) ns = obj.substr(1, pos-1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1513) obj = obj.substr(pos+1, string::npos); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1514) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1515) parse_ns_field(ns, instance); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1516) return true; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1517) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1518) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1519) void set_in_extra_data(bool val) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1520) in_extra_data = val; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1521) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1522) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1523) bool is_in_extra_data() const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1524) return in_extra_data; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1525) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1526) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1527) void encode(bufferlist& bl) const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1528) ENCODE_START(5, 3, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1529) ::encode(bucket.name, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1530) ::encode(loc, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1531) ::encode(ns, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1532) ::encode(object, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1533) ::encode(bucket, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1534) ::encode(instance, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1535) if (!ns.empty() || !instance.empty()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1536) ::encode(orig_obj, bl); +3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1537) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1538) ENCODE_FINISH(bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1539) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1540) void decode(bufferlist::iterator& bl) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1541) DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1542) ::decode(bucket.name, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1543) ::decode(loc, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1544) ::decode(ns, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1545) ::decode(object, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1546) if (struct_v >= 2) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1547) ::decode(bucket, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1548) if (struct_v >= 4) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1549) ::decode(instance, bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1550) if (ns.empty() && instance.empty()) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1551) orig_obj = object; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1552) } else { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1553) if (struct_v >= 5) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1554) ::decode(orig_obj, bl); +3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1555) } else { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1556) ssize_t pos = object.find('_', 1); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1557) if (pos < 0) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1558) throw buffer::error(); +3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1559) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1560) orig_obj = object.substr(pos); +3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1561) } +4d884040 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-24 16:43:14 -0700 1562) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1563) DECODE_FINISH(bl); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1564) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1565) void dump(Formatter *f) const; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1566) static void generate_test_instances(list& o); +4d884040 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-24 16:43:14 -0700 1567) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1568) bool operator==(const rgw_obj& o) const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1569) return (object.compare(o.object) == 0) && +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1570) (bucket.name.compare(o.bucket.name) == 0) && +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1571) (ns.compare(o.ns) == 0) && +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1572) (instance.compare(o.instance) == 0); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1573) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1574) bool operator<(const rgw_obj& o) const { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1575) int r = bucket.name.compare(o.bucket.name); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1576) if (r == 0) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1577) r = object.compare(o.object); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1578) if (r == 0) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1579) r = ns.compare(o.ns); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1580) if (r == 0) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1581) r = instance.compare(o.instance); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1582) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1583) } +d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1584) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1585) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1586) return (r < 0); +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1587) } +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1588) }; +e6eef5e9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-30 17:13:42 -0700 1589) WRITE_CLASS_ENCODER(rgw_obj) +8bd984d9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-08 12:32:50 -0700 1590) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1591) struct rgw_cache_entry_info { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1592) string cache_locator; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1593) uint64_t gen; +ab764f38 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-19 16:34:21 -0700 1594) +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1595) rgw_cache_entry_info() : gen(0) {} +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1596) }; +ab764f38 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-19 16:34:21 -0700 1597) +f106e1a5 src/rgw/rgw_common.h (Danny Al-Gaaf 2013-03-11 15:35:53 +0100 1598) inline ostream& operator<<(ostream& out, const rgw_obj &o) { +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1599) return out << o.bucket.name << ":" << o.get_object(); +7bbdcdba src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 12:55:25 -0700 1600) } +7bbdcdba src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 12:55:25 -0700 1601) +422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1602) static inline bool str_startswith(const string& str, const string& prefix) +422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1603) { +422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1604) return (str.compare(0, prefix.size(), prefix) == 0); +422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1605) } +422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1606) +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1607) static inline void buf_to_hex(const unsigned char *buf, int len, char *str) +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1608) { +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1609) int i; +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1610) str[0] = '\0'; +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1611) for (i = 0; i < len; i++) { +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1612) sprintf(&str[i*2], "%02x", (int)buf[i]); +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1613) } +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1614) } +e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1615) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1616) static inline int hexdigit(char c) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1617) { +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1618) if (c >= '0' && c <= '9') +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1619) return (c - '0'); +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1620) c = toupper(c); +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1621) if (c >= 'A' && c <= 'F') +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1622) return c - 'A' + 0xa; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1623) return -EINVAL; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1624) } +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1625) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1626) static inline int hex_to_buf(const char *hex, char *buf, int len) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1627) { +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1628) int i = 0; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1629) const char *p = hex; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1630) while (*p) { +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1631) if (i >= len) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1632) return -EINVAL; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1633) buf[i] = 0; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1634) int d = hexdigit(*p); +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1635) if (d < 0) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1636) return d; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1637) buf[i] = d << 4; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1638) p++; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1639) if (!*p) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1640) return -EINVAL; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1641) d = hexdigit(*p); +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1642) if (d < 0) +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1643) return -d; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1644) buf[i] += d; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1645) i++; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1646) p++; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1647) } +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1648) return i; +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1649) } +37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1650) +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1651) static inline int rgw_str_to_bool(const char *s, int def_val) +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1652) { +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1653) if (!s) +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1654) return def_val; +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1655) +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1656) return (strcasecmp(s, "on") == 0 || +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1657) strcasecmp(s, "yes") == 0 || +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1658) strcasecmp(s, "1") == 0); +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1659) } +f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1660) +45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1661) static inline void append_rand_alpha(CephContext *cct, const string& src, string& dest, int len) +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1662) { +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1663) dest = src; +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1664) char buf[len + 1]; +b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 1665) gen_rand_alphanumeric(cct, buf, len); +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1666) dest.append("_"); +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1667) dest.append(buf); +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1668) } +d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1669) +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1670) static inline const char *rgw_obj_category_name(RGWObjCategory category) +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1671) { +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1672) switch (category) { +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1673) case RGW_OBJ_CATEGORY_NONE: +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1674) return "rgw.none"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1675) case RGW_OBJ_CATEGORY_MAIN: +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1676) return "rgw.main"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1677) case RGW_OBJ_CATEGORY_SHADOW: +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1678) return "rgw.shadow"; +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1679) case RGW_OBJ_CATEGORY_MULTIMETA: +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1680) return "rgw.multimeta"; +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1681) } +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1682) +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1683) return "unknown"; +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1684) } +ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1685) +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1686) static inline uint64_t rgw_rounded_kb(uint64_t bytes) +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1687) { +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1688) return (bytes + 1023) / 1024; +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1689) } +db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1690) +2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1691) static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes) +2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1692) { +2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1693) return ((bytes + 4095) & ~4095) / 1024; +2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1694) } +2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1695) +97c19da4 src/rgw/rgw_common.h (Yehuda Sadeh 2012-11-07 15:39:56 -0800 1696) extern string rgw_string_unquote(const string& s); +eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1697) extern void parse_csv_string(const string& ival, vector& ovals); +eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1698) extern int parse_key_value(string& in_str, string& key, string& val); +eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1699) extern int parse_key_value(string& in_str, const char *delim, string& key, string& val); +dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1700) /** time parsing */ +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1701) extern int parse_time(const char *time_str, time_t *time); +dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1702) extern bool parse_rfc2616(const char *s, struct tm *t); +30d11f42 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 15:36:07 -0700 1703) extern bool parse_iso8601(const char *s, struct tm *t); +da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1704) extern string rgw_trim_whitespace(const string& src); +da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1705) extern string rgw_trim_quotes(const string& val); +da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1706) +dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1707) +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1708) /** Check if the req_state's user has the necessary permissions +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1709) * to do the requested action */ +2365c77a src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-21 14:39:20 -0800 1710) extern bool verify_bucket_permission(struct req_state *s, int perm); +4d2a05f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-08-22 17:16:05 -0700 1711) extern bool verify_object_permission(struct req_state *s, RGWAccessControlPolicy *bucket_acl, RGWAccessControlPolicy *object_acl, int perm); +2365c77a src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-21 14:39:20 -0800 1712) extern bool verify_object_permission(struct req_state *s, int perm); +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1713) /** Convert an input URL into a sane object name +62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1714) * by converting %-escaped strings into characters, etc*/ +21e07eb6 src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-11 09:07:10 -0800 1715) extern bool url_decode(string& src_str, string& dest_str, bool in_query = false); +dd308cd4 src/rgw/rgw_common.h (Josh Durgin 2013-10-24 08:37:25 -0700 1716) extern void url_encode(const string& src, string& dst); +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1717) +70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1718) extern void calc_hmac_sha1(const char *key, int key_len, +a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1719) const char *msg, int msg_len, char *dest); +70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1720) /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */ +70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1721) +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 1722) extern int rgw_parse_op_type_list(const string& str, uint32_t *perm); +38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 1723) +536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1724) #endif diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 919ed15ade687..807104c0180b4 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -96,6 +96,11 @@ using ceph::crypto::MD5; #define RGW_REST_SWIFT 0x1 #define RGW_REST_SWIFT_AUTH 0x2 +#define RGW_PROTO_SWIFT 0x1 +#define RGW_PROTO_SWIFT_AUTH 0x2 +#define RGW_PROTO_S3 0x4 +#define RGW_PROTO_WEBSITE 0x8 + #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 #define RGW_OP_TYPE_READ 0x01 @@ -254,6 +259,7 @@ class RGWHTTPArgs bool has_resp_modifier; public: RGWHTTPArgs() : has_resp_modifier(false) {} + /** Set the arguments; as received */ void set(string s) { has_resp_modifier = false; diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 638a0fe34f2e2..4471323df0cdf 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -607,9 +607,21 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC abort_early(s, NULL, init_error); goto done; } + dout(10) << "handler=" << typeid(*handler).name() << dendl; should_log = mgr->get_logging(); + // Authorization must be before get_op + // because get_op depends on authorization data existing to choice if we are + // in website mode (authorization is NOT valid in website mode). + req->log(s, "authorizing"); + ret = handler->authorize(); + if (ret < 0) { + dout(10) << "failed to authorize request" << dendl; + abort_early(s, NULL, ret); + goto done; + } + req->log(s, "getting op"); op = handler->get_op(store); if (!op) { @@ -617,14 +629,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC goto done; } req->op = op; - - req->log(s, "authorizing"); - ret = handler->authorize(); - if (ret < 0) { - dout(10) << "failed to authorize request" << dendl; - abort_early(s, op, ret); - goto done; - } + dout(10) << "op=" << typeid(*op).name() << dendl; if (s->user.suspended) { dout(10) << "user is suspended, uid=" << s->user.user_id << dendl; @@ -643,17 +648,13 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC * Only some accesses support website mode, and website mode does NOT apply * if you are using the REST endpoint either (ergo, no authenticated access) */ - dout(20) << "retarget uid=" << s->user.user_id << dendl; - if (op->supports_website() && !rgw_user_is_authenticated(s->user)) { - //if (op->supports_website()) { - req->log(s, "recalculating target"); - ret = handler->retarget(op, &op); - if (ret < 0) { - abort_early(s, op, ret); - goto done; - } - req->op = op; + req->log(s, "recalculating target"); + ret = handler->retarget(op, &op); + if (ret < 0) { + abort_early(s, op, ret); + goto done; } + req->op = op; // This reads the ACL on the bucket or object req->log(s, "reading permissions"); @@ -1230,8 +1231,10 @@ int main(int argc, const char **argv) apis_map[*li] = true; } - if (apis_map.count("s3") > 0) - rest.register_default_mgr(set_logging(new RGWRESTMgr_S3)); + // S3 website mode is a specialization of S3 + bool s3website_enabled = apis_map.count("s3website") > 0; + if (apis_map.count("s3") > 0 || s3website_enabled) + rest.register_default_mgr(set_logging(new RGWRESTMgr_S3(s3website_enabled))); if (apis_map.count("swift") > 0) { do_swift = true; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 96a7fe5976a45..6dd7119457108 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3402,7 +3402,7 @@ void RGWListBucketMultiparts::execute() if (ret < 0) return; - if (s->prot_flags & RGW_REST_SWIFT) { + if (s->prot_flags & RGW_PROTO_SWIFT) { string path_args; path_args = s->info.args.get("path"); if (!path_args.empty()) { diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index d719d50141447..ac888c7b7c098 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -64,6 +64,14 @@ enum RGWOpType { RGW_OP_DELETE_MULTI_OBJ, }; +enum RGWEndpointType { + RGW_ENDPOINT_REST, + RGW_ENDPOINT_REST_SWIFT, + RGW_ENDPOINT_REST_SWIFT_AUTH, + RGW_ENDPOINT_REST_S3, + RGW_ENDPOINT_WEBSITE, +}; + /** * Provide the base class for all ops. */ diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index 023aebffe7faa..f23b1461e5c41 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -927,8 +927,8 @@ struct RGWRegion { 20:08 < yehudasa> yeah, probably 20:08 < _robbat21irssi> s3, s3website, swift, swith_auth, swift_website */ - map> api_hostname_map; - map> api_endpoints_map; + map > api_hostname_map; + map > api_endpoints_map; CephContext *cct; RGWRados *store; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index dcecbbcf961d7..0ebcf26d7f0e9 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -215,7 +215,7 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) */ if(!cct->_conf->rgw_dns_s3website_name.empty()) { - hostnames_s3website_set.insert(cct->_conf->rgw_dns_s3website_name); + hostnames_s3website_set.insert(cct->_conf->rgw_dns_s3website_name); } hostnames_s3website_set.insert(region.hostnames_s3website.begin(), region.hostnames_s3website.end()); /* TODO: we should repeat the hostnames_set sanity check here @@ -238,14 +238,14 @@ static bool str_ends_with(const string& s, const string& suffix, size_t *pos) return s.compare(p, len, suffix) == 0; } -static bool rgw_find_host_in_domains(const string& host, string *domain, string *subdomain) +static bool rgw_find_host_in_domains(const string& host, string *domain, string *subdomain, set valid_hostnames_set) { set::iterator iter; /** TODO, Future optimization * store hostnames_set elements _reversed_, and look for a prefix match, * which is much faster than a suffix match. */ - for (iter = hostnames_set.begin(); iter != hostnames_set.end(); ++iter) { + for (iter = valid_hostnames_set.begin(); iter != valid_hostnames_set.end(); ++iter) { size_t pos; if (!str_ends_with(host, *iter, &pos)) continue; @@ -303,7 +303,7 @@ void set_req_state_err(struct req_state *s, int err_no) if (err_no < 0) err_no = -err_no; s->err.ret = -err_no; - if (s->prot_flags & RGW_REST_SWIFT) { + if (s->prot_flags & RGW_PROTO_SWIFT) { r = search_err(err_no, RGW_HTTP_SWIFT_ERRORS, ARRAY_LEN(RGW_HTTP_SWIFT_ERRORS)); if (r) { s->err.http_ret = r->http_ret; @@ -368,9 +368,10 @@ void dump_content_length(struct req_state *s, uint64_t len) void dump_etag(struct req_state *s, const char *etag) { int r; - if (s->prot_flags & RGW_REST_SWIFT) + if (s->prot_flags & RGW_PROTO_SWIFT) { r = s->cio->print("etag: %s\r\n", etag); - else + } + else r = s->cio->print("ETag: \"%s\"\r\n", etag); if (r < 0) { ldout(s->cct, 0) << "ERROR: s->cio->print() returned err=" << r << dendl; @@ -533,7 +534,7 @@ void dump_start(struct req_state *s) void dump_trans_id(req_state *s) { - if (s->prot_flags & RGW_REST_SWIFT) { + if (s->prot_flags & RGW_PROTO_SWIFT) { s->cio->print("X-Trans-Id: %s\r\n", s->trans_id.c_str()); } else { @@ -632,7 +633,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const ctype = "text/plain"; break; } - if (s->prot_flags & RGW_REST_SWIFT) + if (s->prot_flags & RGW_PROTO_SWIFT) ctype.append("; charset=utf-8"); content_type = ctype.c_str(); } @@ -1373,40 +1374,6 @@ int RGWHandler_ObjStore::read_permissions(RGWOp *op_obj) return do_read_permissions(op_obj, only_bucket); } -int RGWHandler_ObjStore::retarget(RGWOp *op, RGWOp **new_op) { - *new_op = op; - - if (!s->bucket_info.has_website) { - return 0; - } - - rgw_obj_key new_obj; - s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name); - - RGWBWRoutingRule rrule; - bool should_redirect = s->bucket_info.website_conf.should_redirect(new_obj.name, &rrule); - - if (should_redirect) { - const string& hostname = s->info.env->get("HTTP_HOST", ""); - const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); - rrule.apply_rule(protocol, hostname, new_obj.name, &s->redirect); - return -ERR_PERMANENT_REDIRECT; - } - -#warning FIXME -#if 0 - if (s->object.empty() != new_obj.empty()) { - op->put(); - s->object = new_obj; - *new_op = get_op(); - } -#endif - - s->object = new_obj; - - return 0; -} - void RGWRESTMgr::register_resource(string resource, RGWRESTMgr *mgr) { string r = "/"; @@ -1505,27 +1472,56 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) ldout(s->cct, 10) << "host=" << info.host << dendl; string domain; string subdomain; - bool in_hosted_domain = rgw_find_host_in_domains(info.host, &domain, - &subdomain); - ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain - << " in_hosted_domain=" << in_hosted_domain << dendl; + bool in_hosted_domain_s3website = false; + bool in_hosted_domain = rgw_find_host_in_domains(info.host, &domain, &subdomain, hostnames_set); + + bool s3website_enabled = g_conf->rgw_enable_apis.find("s3website") != std::string::npos && g_conf->rgw_s3website_mode.find("hostname") != std::string::npos; + string s3website_domain; + string s3website_subdomain; + + if (s3website_enabled) { + in_hosted_domain_s3website = rgw_find_host_in_domains(info.host, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); + } + + ldout(s->cct, 20) + << "subdomain=" << subdomain + << " domain=" << domain + << " in_hosted_domain=" << in_hosted_domain + << " in_hosted_domain_s3website=" << in_hosted_domain_s3website + << dendl; if (g_conf->rgw_resolve_cname && !in_hosted_domain) { string cname; bool found; int r = rgw_resolver->resolve_cname(info.host, cname, &found); if (r < 0) { - ldout(s->cct, 0) << "WARNING: rgw_resolver->resolve_cname() returned r=" << r << dendl; + ldout(s->cct, 0) << "WARNING: rgw_resolver->resolve_cname() returned r=" << r << dendl; } + if (found) { ldout(s->cct, 5) << "resolved host cname " << info.host << " -> " << cname << dendl; - in_hosted_domain = rgw_find_host_in_domains(cname, &domain, &subdomain); - ldout(s->cct, 20) << "subdomain=" << subdomain << " domain=" << domain - << " in_hosted_domain=" << in_hosted_domain << dendl; + in_hosted_domain = rgw_find_host_in_domains(cname, &domain, &subdomain, hostnames_set); + + if(s3website_enabled && !in_hosted_domain_s3website) { + in_hosted_domain_s3website = rgw_find_host_in_domains(cname, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); + } + + ldout(s->cct, 20) + << "subdomain=" << subdomain + << " domain=" << domain + << " in_hosted_domain=" << in_hosted_domain + << " in_hosted_domain_s3website=" << in_hosted_domain_s3website + << dendl; } } + if(in_hosted_domain_s3website) { + domain = s3website_domain; + subdomain = s3website_subdomain; + s->prot_flags |= RGW_PROTO_WEBSITE; + } + if (in_hosted_domain && !subdomain.empty()) { string encoded_bucket = "/"; encoded_bucket.append(subdomain); diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 597398bae7a3c..de118f4d143e3 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -305,7 +305,10 @@ class RGWHandler_ObjStore : public RGWHandler { virtual ~RGWHandler_ObjStore() {} int init_permissions(); int read_permissions(RGWOp *op); - int retarget(RGWOp *op, RGWOp **new_op); + virtual int retarget(RGWOp *op, RGWOp **new_op) { + *new_op = op; + return 0; + } virtual int authorize() = 0; }; @@ -314,6 +317,7 @@ class RGWHandler_ObjStore_SWIFT; class RGWHandler_SWIFT_Auth; class RGWHandler_ObjStore_S3; + class RGWRESTMgr { bool should_log; protected: diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 2b677e5b6acab..abefb35ffe1c9 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -12,6 +12,7 @@ #include "rgw_rest.h" #include "rgw_rest_s3.h" +#include "rgw_rest_s3website.h" #include "rgw_auth_s3.h" #include "rgw_policy_s3.h" #include "rgw_user.h" @@ -19,6 +20,8 @@ #include "rgw_cors_s3.h" #include "rgw_client_io.h" +#include // for 'typeid' + #define dout_subsys ceph_subsys_rgw using namespace ceph::crypto; @@ -2085,24 +2088,6 @@ RGWOp *RGWHandler_ObjStore_Service_S3::op_head() RGWOp *RGWHandler_ObjStore_Bucket_S3::get_obj_op(bool get_data) { - /* we need to make sure we read bucket info, it's not read before for this specific request */ - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); -#warning FIXME: Do we need to catch -ENOENT seperately? What do we do then? - if (ret < 0) - return NULL; - - /** If we are in website mode, then it is explicitly impossible to run GET or - * HEAD on the actual directory. We must convert the request to run on the - * suffix object instead! - */ - ldout(s->cct, 20) << __func__ << ": bucket=" << s->bucket_info.bucket.name << " has_website=" << s->bucket_info.has_website << " get_data=" << get_data << "/" << (get_data ? "GET" : "HEAD") << dendl; - if(s->bucket_info.has_website && !rgw_user_is_authenticated(s->user)) { - RGWGetObj_ObjStore_S3 *get_obj_op = new RGWGetObj_ObjStore_S3; - get_obj_op->set_get_data(get_data); - return get_obj_op; - } - // Non-website mode if (get_data) return new RGWListBucket_ObjStore_S3; @@ -3091,19 +3076,139 @@ int RGWHandler_Auth_S3::init(RGWRados *store, struct req_state *state, RGWClient return RGWHandler_ObjStore::init(store, state, cio); } +bool RGWRESTMgr_S3::is_s3website_mode(struct req_state *s) +{ + if(!enable_s3website) + return false; + + // If this is true, we already validity the hostname via the dedicated + // website endpoint. + if(s->prot_flags & RGW_PROTO_WEBSITE) + return true; + + /** S3Website: default_validity + * attempt to detect S3Website requests via: + * GET & HEAD only + * with NO authorization headers + * on a bucket with a website block + */ + if(g_conf->rgw_s3website_mode.find("default_validity") != std::string::npos) { + if(s->op != OP_GET && s->op != OP_HEAD) { + return false; + } + + // There was some talk of S3 implement static auth on websites, so we'd need + // to differentiate that in future. We take a shortcut here by detecting + // that AWS S3 always starts with 'AWS'; we might have issues in future + // if something else wants to use the HTTP-standard 'Basic' start, but + // not be S3Website. + string auth_id = s->info.args.get("AWSAccessKeyId"); + bool request_has_authentication = auth_id.size() || (s->http_auth && *(s->http_auth) && strncmp(s->http_auth, "AWS", 3) == 0); + if(request_has_authentication) { + return false; + } + + s->prot_flags |= RGW_PROTO_WEBSITE; // Actually only if the bucket is ALSO website + return true; + } + + return false; + +} + RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { int ret = RGWHandler_ObjStore_S3::init_from_header(s, RGW_FORMAT_XML, false); if (ret < 0) return NULL; - if (s->bucket_name_str.empty()) - return new RGWHandler_ObjStore_Service_S3; + //ldout(s->cct, 20) << __func__ << " bucket=" << s->bucket_name_str << " object=" << s->object.name << " args=" << s->info.args.get_str() << dendl; + //if (s->info.args.sub_resource_exists("website")) + // + // + RGWHandler* handler; - if (s->object.empty()) - return new RGWHandler_ObjStore_Bucket_S3; + if (s->bucket_name_str.empty()) { + handler = new RGWHandler_ObjStore_Service_S3; + } else if (is_s3website_mode(s)) { + handler = new RGWHandler_ObjStore_Obj_S3Website; + } else if (s->object.empty()) { + handler = new RGWHandler_ObjStore_Bucket_S3; + } else { + return new RGWHandler_ObjStore_Obj_S3; + } + + ldout(s->cct, 20) << __func__ << " handler=" << typeid(*handler).name() << dendl; + return handler; +} - return new RGWHandler_ObjStore_Obj_S3; +int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { + *new_op = op; + ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; + + // s->bucket_info is not yet populated + RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); + int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); +#warning FIXME: Do we need to catch -ENOENT seperately? What about other errors? + if (ret < 0) { + return ret; + } + + // If bucket does not have website enabled, bail out + if(!s->bucket_info.has_website) { + return 0; + } + + s->prot_flags |= RGW_PROTO_WEBSITE; // FIXME: obsolete? + + rgw_obj_key new_obj; + s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name); + ldout(s->cct, 10) << "retarget get_effective_key " << s->object << " -> " << new_obj << dendl; + + RGWBWRoutingRule rrule; + bool should_redirect = s->bucket_info.website_conf.should_redirect(new_obj.name, &rrule); + + if (should_redirect) { + const string& hostname = s->info.env->get("HTTP_HOST", ""); + const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); + rrule.apply_rule(protocol, hostname, new_obj.name, &s->redirect); + ldout(s->cct, 10) << "retarget redirect proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; + return -ERR_PERMANENT_REDIRECT; + } + +#warning FIXME +#if 0 + if (s->object.empty() != new_obj.empty()) { + op->put(); + s->object = new_obj; + *new_op = get_op(); + } +#endif + + s->object = new_obj; + + return 0; +} + +RGWOp *RGWHandler_ObjStore_Obj_S3Website::get_obj_op(bool get_data) +{ + /** If we are in website mode, then it is explicitly impossible to run GET or + * HEAD on the actual directory. We must convert the request to run on the + * suffix object instead! + */ + RGWGetObj_ObjStore_S3Website *op = new RGWGetObj_ObjStore_S3Website; + op->set_get_data(get_data); + return op; +} + +RGWOp *RGWHandler_ObjStore_Obj_S3Website::op_get() +{ + return get_obj_op(true); +} + +RGWOp *RGWHandler_ObjStore_Obj_S3Website::op_head() +{ + return get_obj_op(false); } /* diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index f9ec0eb5c14a8..1737eae7a1222 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -425,6 +425,10 @@ class RGWHandler_ObjStore_S3 : public RGWHandler_ObjStore { virtual int authorize() { return RGW_Auth_S3::authorize(store, s); } + virtual int retarget(RGWOp *op, RGWOp **new_op) { + *new_op = op; + return 0; + } }; class RGWHandler_ObjStore_Service_S3 : public RGWHandler_ObjStore_S3 { @@ -485,8 +489,12 @@ class RGWHandler_ObjStore_Obj_S3 : public RGWHandler_ObjStore_S3 { }; class RGWRESTMgr_S3 : public RGWRESTMgr { +private: + bool enable_s3website; +protected: + bool is_s3website_mode(struct req_state *s); public: - RGWRESTMgr_S3() {} + RGWRESTMgr_S3(bool enable_s3website) : enable_s3website(false) { this->enable_s3website = enable_s3website; } virtual ~RGWRESTMgr_S3() {} virtual RGWRESTMgr *get_resource_mgr(struct req_state *s, const string& uri) { @@ -606,4 +614,6 @@ class dss_endpoint { dss_endpoint() { } ~dss_endpoint() { } }; +class RGWHandler_ObjStore_Obj_S3Website; + #endif diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h new file mode 100644 index 0000000000000..f6eda69d9e183 --- /dev/null +++ b/src/rgw/rgw_rest_s3website.h @@ -0,0 +1,62 @@ +#ifndef CEPH_RGW_REST_S3WEBSITE_H +#define CEPH_RGW_REST_S3WEBSITE_H + +#include "rgw_rest_s3.h" + +class RGWHandler_ObjStore_S3Website : public RGWHandler_ObjStore_S3 { +protected: + int retarget(RGWOp *op, RGWOp **new_op); +public: + RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} + virtual ~RGWHandler_ObjStore_S3Website() {} +}; + +class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Website { +protected: + RGWOp *op_get(); + RGWOp *op_head(); + // Only allowed to use GET+HEAD + RGWOp *op_put() { return NULL; } + RGWOp *op_delete() { return NULL; } + RGWOp *op_post() { return NULL; } + RGWOp *op_copy() { return NULL; } + RGWOp *op_options() { return NULL; } +public: + RGWHandler_ObjStore_Service_S3Website() {} + virtual ~RGWHandler_ObjStore_Service_S3Website() {} +}; + +class RGWHandler_ObjStore_Obj_S3Website : public RGWHandler_ObjStore_S3Website { +protected: + RGWOp *get_obj_op(bool get_data); + + RGWOp *op_get(); + RGWOp *op_head(); + // Only allowed to use GET+HEAD + RGWOp *op_put() { return NULL; } + RGWOp *op_delete() { return NULL; } + RGWOp *op_post() { return NULL; } + RGWOp *op_copy() { return NULL; } + RGWOp *op_options() { return NULL; } +public: + RGWHandler_ObjStore_Obj_S3Website() {} + virtual ~RGWHandler_ObjStore_Obj_S3Website() {} +}; + +/* The cross-inheritance from Obj to Bucket is deliberate! + * S3Websites do NOT support any bucket operations + */ +class RGWHandler_ObjStore_Bucket_S3Website : public RGWHandler_ObjStore_Obj_S3Website { +public: + RGWHandler_ObjStore_Bucket_S3Website() {} + virtual ~RGWHandler_ObjStore_Bucket_S3Website() {} +}; + +class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 +{ +public: + RGWGetObj_ObjStore_S3Website() {} + ~RGWGetObj_ObjStore_S3Website() {} +}; + +#endif diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index bcbd45002c896..9d700d28fe671 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -955,7 +955,7 @@ int RGWHandler_ObjStore_SWIFT::init_from_header(struct req_state *s) string req; string first; - s->prot_flags |= RGW_REST_SWIFT; + s->prot_flags |= RGW_PROTO_SWIFT; const char *req_name = s->decoded_uri.c_str(); const char *p; From 17430993ee6d95b88de012a8c9e8d638a8285256 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sat, 13 Jun 2015 17:10:06 +0000 Subject: [PATCH 27/90] FIXUP: Fix comment. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index abefb35ffe1c9..d2b8400a08bed 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3081,8 +3081,8 @@ bool RGWRESTMgr_S3::is_s3website_mode(struct req_state *s) if(!enable_s3website) return false; - // If this is true, we already validity the hostname via the dedicated - // website endpoint. + // If this is true, we already detected the hostname as valid via the + // dedicated website endpoint. if(s->prot_flags & RGW_PROTO_WEBSITE) return true; From 31f48e12e86102101c533010e86b22a25be2d523 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 06:30:45 +0000 Subject: [PATCH 28/90] rgw: use new formatter header/footer ability. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest.cc --- src/rgw/rgw_rest.cc | 16 +++++++++++----- src/rgw/rgw_rest_s3.cc | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 0ebcf26d7f0e9..3c94e0a62b986 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -268,6 +268,7 @@ static bool rgw_find_host_in_domains(const string& host, string *domain, string static void dump_status(struct req_state *s, const char *status, const char *status_name) { + s->formatter->set_status(status, status_name); int r = s->cio->send_status(status, status_name); if (r < 0) { ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err=" << r << dendl; @@ -277,6 +278,7 @@ static void dump_status(struct req_state *s, const char *status, const char *sta void rgw_flush_formatter_and_reset(struct req_state *s, Formatter *formatter) { std::ostringstream oss; + formatter->output_footer(); formatter->flush(oss); std::string outs(oss.str()); if (!outs.empty() && s->op != OP_HEAD) { @@ -526,8 +528,7 @@ void dump_access_control_for_console(req_state *s, const char* origin, const cha void dump_start(struct req_state *s) { if (!s->content_started) { - if (s->format == RGW_FORMAT_XML) - s->formatter->write_raw_data(XMLFormatter::XML_1_DTD); + s->formatter->output_header(); s->content_started = true; } } @@ -639,14 +640,19 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const } if (s->err.is_err()) { dump_start(s); - s->formatter->open_object_section("Error"); + if(s->format != RGW_FORMAT_HTML) { + s->formatter->open_object_section("Error"); + } if (!s->err.s3_code.empty()) s->formatter->dump_string("Code", s->err.s3_code); if (!s->err.message.empty()) s->formatter->dump_string("Message", s->err.message); if (!s->trans_id.empty()) - s->formatter->dump_string("RequestId", s->trans_id); - s->formatter->close_section(); + s->formatter->dump_string("RequestId", s->trans_id); + if(s->format != RGW_FORMAT_HTML) { + s->formatter->close_section(); + } + s->formatter->output_footer(); dump_content_length(s, s->formatter->get_len()); } else { if (proposed_content_length != NO_CONTENT_LENGTH) { diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d2b8400a08bed..6c53ef7fd7b4c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3118,7 +3118,8 @@ bool RGWRESTMgr_S3::is_s3website_mode(struct req_state *s) RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { - int ret = RGWHandler_ObjStore_S3::init_from_header(s, RGW_FORMAT_XML, false); + bool is_s3website = is_s3website_mode(s); + int ret = RGWHandler_ObjStore_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, false); if (ret < 0) return NULL; @@ -3130,7 +3131,7 @@ RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) if (s->bucket_name_str.empty()) { handler = new RGWHandler_ObjStore_Service_S3; - } else if (is_s3website_mode(s)) { + } else if (is_s3website) { handler = new RGWHandler_ObjStore_Obj_S3Website; } else if (s->object.empty()) { handler = new RGWHandler_ObjStore_Bucket_S3; From 2af40fe73230d7c11c5d3378e291d25152ef711b Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 06:31:05 +0000 Subject: [PATCH 29/90] rgw: More fields in error output to match main S3. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 3c94e0a62b986..4f9a2d97e8d57 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -647,8 +647,11 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const s->formatter->dump_string("Code", s->err.s3_code); if (!s->err.message.empty()) s->formatter->dump_string("Message", s->err.message); - if (!s->trans_id.empty()) + if (!s->bucket_name_str.empty()) // TODO: connect to expose_bucket + s->formatter->dump_string("BucketName", s->bucket_name_str); + if (!s->trans_id.empty()) // TODO: connect to expose_bucket or another toggle s->formatter->dump_string("RequestId", s->trans_id); + s->formatter->dump_string("HostId", "FIXME-TODO-How-does-amazon-generate-HostId"); // TODO, FIXME if(s->format != RGW_FORMAT_HTML) { s->formatter->close_section(); } From 2933d51b2ec3a5580a2dcc8560f5aacd05214f2b Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 06:31:26 +0000 Subject: [PATCH 30/90] rgw: pretty-print s3website error output. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 4f9a2d97e8d57..c99244879ece1 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1266,7 +1266,7 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ s->formatter = new JSONFormatter(false); break; case RGW_FORMAT_HTML: - s->formatter = new HTMLFormatter(false); + s->formatter = new HTMLFormatter(s->prot_flags & RGW_PROTO_WEBSITE); break; default: return -EINVAL; From f2f9403f15f1aab7ee0edde0f1211c0d464a44f8 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 08:10:55 +0000 Subject: [PATCH 31/90] More s3website json region data. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_json_enc.cc | 2 ++ src/rgw/rgw_rest.cc | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/rgw/rgw_json_enc.cc b/src/rgw/rgw_json_enc.cc index 3254c010819b0..3b50f215a5154 100644 --- a/src/rgw/rgw_json_enc.cc +++ b/src/rgw/rgw_json_enc.cc @@ -782,6 +782,7 @@ void RGWRegion::dump(Formatter *f) const encode_json("is_master", is_master, f); encode_json("endpoints", endpoints, f); encode_json("hostnames", hostnames, f); + encode_json("hostnames_s3website", hostnames_s3website, f); encode_json("master_zone", master_zone, f); encode_json_map("zones", zones, f); /* more friendly representation */ encode_json_map("placement_targets", placement_targets, f); /* more friendly representation */ @@ -810,6 +811,7 @@ void RGWRegion::decode_json(JSONObj *obj) JSONDecoder::decode_json("is_master", is_master, obj); JSONDecoder::decode_json("endpoints", endpoints, obj); JSONDecoder::decode_json("hostnames", hostnames, obj); + JSONDecoder::decode_json("hostnames_s3website", hostnames_s3website, obj); JSONDecoder::decode_json("master_zone", master_zone, obj); JSONDecoder::decode_json("zones", zones, decode_zones, obj); JSONDecoder::decode_json("placement_targets", placement_targets, decode_placement_targets, obj); diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index c99244879ece1..dbbda44346bdf 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -24,6 +24,8 @@ #include "rgw_client_io.h" #include "rgw_resolve.h" +#include + #define dout_subsys ceph_subsys_rgw @@ -204,6 +206,8 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) hostnames_set.insert(cct->_conf->rgw_dns_name); } hostnames_set.insert(region.hostnames.begin(), region.hostnames.end()); + string s(""); + ldout(cct, 20) << "RGW hostnames: " << std::accumulate(hostnames_set.begin(), hostnames_set.end(), s) << dendl; /* TODO: We should have a sanity check that no hostname matches the end of * any other hostname, otherwise we will get ambigious results from * rgw_find_host_in_domains. @@ -218,6 +222,8 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) hostnames_s3website_set.insert(cct->_conf->rgw_dns_s3website_name); } hostnames_s3website_set.insert(region.hostnames_s3website.begin(), region.hostnames_s3website.end()); + s.assign(""); + ldout(cct, 20) << "RGW S3website hostnames: " << std::accumulate(hostnames_s3website_set.begin(), hostnames_s3website_set.end(), s) << dendl; /* TODO: we should repeat the hostnames_set sanity check here * and ALSO decide about overlap, if any */ From 3bce08d4b7a789b057ac8a9be53c84003970f197 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 08:14:59 +0000 Subject: [PATCH 32/90] rgw: tweak dns-based s3website detection for other changes FIXME-REBASE Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index dbbda44346bdf..38a20d3f08ced 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1496,6 +1496,12 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) if (s3website_enabled) { in_hosted_domain_s3website = rgw_find_host_in_domains(info.host, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); + if(in_hosted_domain_s3website) { + in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? + domain = s3website_domain; + subdomain = s3website_subdomain; + s->prot_flags |= RGW_PROTO_WEBSITE; + } } ldout(s->cct, 20) @@ -1505,7 +1511,7 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) << " in_hosted_domain_s3website=" << in_hosted_domain_s3website << dendl; - if (g_conf->rgw_resolve_cname && !in_hosted_domain) { + if (g_conf->rgw_resolve_cname && !in_hosted_domain && !in_hosted_domain_s3website) { string cname; bool found; int r = rgw_resolver->resolve_cname(info.host, cname, &found); @@ -1520,6 +1526,12 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) if(s3website_enabled && !in_hosted_domain_s3website) { in_hosted_domain_s3website = rgw_find_host_in_domains(cname, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); + if(in_hosted_domain_s3website) { + in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? + domain = s3website_domain; + subdomain = s3website_subdomain; + s->prot_flags |= RGW_PROTO_WEBSITE; + } } ldout(s->cct, 20) @@ -1531,12 +1543,6 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) } } - if(in_hosted_domain_s3website) { - domain = s3website_domain; - subdomain = s3website_subdomain; - s->prot_flags |= RGW_PROTO_WEBSITE; - } - if (in_hosted_domain && !subdomain.empty()) { string encoded_bucket = "/"; encoded_bucket.append(subdomain); From daa2487bf57fb4cd97b3f4f79d173f2e739db294 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 19:25:08 +0000 Subject: [PATCH 33/90] Avoid dupe reset. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 38a20d3f08ced..4aeffb043f67c 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1278,7 +1278,7 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ return -EINVAL; }; - s->formatter->reset(); + //s->formatter->reset(); // All formatters should reset on create already return 0; } From d91b5d52a56217032a600a3c12343b203cc9c953 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 19:25:54 +0000 Subject: [PATCH 34/90] WIP-FIXUP: Muck with bucket detection again. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 34 +++++++++++++++++++++++----------- src/rgw/rgw_rest_s3.h | 1 + 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 6c53ef7fd7b4c..2a24125ec10b7 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3116,6 +3116,21 @@ bool RGWRESTMgr_S3::is_s3website_mode(struct req_state *s) } +bool RGWRESTMgr_S3::is_website_bucket(struct req_state *s) +{ + /* + // s->bucket_info is not yet populated + RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); + int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); +#warning FIXME: Do we need to catch -ENOENT seperately? What about other errors? + if (ret < 0) { + return false; + } + return s->bucket_info.has_website; + */ + return false; +} + RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { bool is_s3website = is_s3website_mode(s); @@ -3147,20 +3162,17 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; - // s->bucket_info is not yet populated - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); -#warning FIXME: Do we need to catch -ENOENT seperately? What about other errors? - if (ret < 0) { - return ret; - } - // If bucket does not have website enabled, bail out - if(!s->bucket_info.has_website) { + /* + if(!is_website_bucket(s)) { return 0; - } + }*/ - s->prot_flags |= RGW_PROTO_WEBSITE; // FIXME: obsolete? + RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); + int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); + if (ret < 0 || !s->bucket_info.has_website) { + return false; + } rgw_obj_key new_obj; s->bucket_info.website_conf.get_effective_key(s->object.name, &new_obj.name); diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 1737eae7a1222..3341c2040d775 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -493,6 +493,7 @@ class RGWRESTMgr_S3 : public RGWRESTMgr { bool enable_s3website; protected: bool is_s3website_mode(struct req_state *s); + bool is_website_bucket(struct req_state *s); public: RGWRESTMgr_S3(bool enable_s3website) : enable_s3website(false) { this->enable_s3website = enable_s3website; } virtual ~RGWRESTMgr_S3() {} From e7d622a70f846b1b196af96e2743ec8d0dd4bea0 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 19:26:24 +0000 Subject: [PATCH 35/90] DEBUG: Ensure we always go past the debug output for now. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 2a24125ec10b7..c0737afb86b18 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3151,7 +3151,7 @@ RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) } else if (s->object.empty()) { handler = new RGWHandler_ObjStore_Bucket_S3; } else { - return new RGWHandler_ObjStore_Obj_S3; + handler = new RGWHandler_ObjStore_Obj_S3; } ldout(s->cct, 20) << __func__ << " handler=" << typeid(*handler).name() << dendl; From 4d011908a8ccee315aa231bff05ec462ef711eaa Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 19:26:39 +0000 Subject: [PATCH 36/90] Optimize website detection differently. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index c0737afb86b18..9ab806d3d204b 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3167,6 +3167,8 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { if(!is_website_bucket(s)) { return 0; }*/ + if(!(s->prot_flags & RGW_PROTO_WEBSITE)) + return 0; RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); From a121270cf67354d2bc02d9ce246d728bdc5168b2 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 20:30:24 +0000 Subject: [PATCH 37/90] Add error codes. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_common.h src/rgw/rgw_http_errors.h --- src/rgw/rgw_common.h | 4 ++++ src/rgw/rgw_http_errors.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 807104c0180b4..db26300046fa2 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -153,6 +153,10 @@ using ceph::crypto::MD5; #define ERR_SIGNATURE_NO_MATCH 2027 #define ERR_INVALID_ACCESS_KEY 2028 #define ERR_BUCKET_ALREADY_OWNED 2029 +#define ERR_MALFORMED_XML 2030 +#define ERR_USER_EXIST 2031 +#define ERR_WEBSITE_REDIRECT 2032 +#define ERR_NO_SUCH_WEBSITE_CONFIGURATION 2033 #define ERR_USER_SUSPENDED 2100 #define ERR_INTERNAL_ERROR 2200 diff --git a/src/rgw/rgw_http_errors.h b/src/rgw/rgw_http_errors.h index 34b5f0b33dbc7..caee67553d7ab 100644 --- a/src/rgw/rgw_http_errors.h +++ b/src/rgw/rgw_http_errors.h @@ -20,6 +20,7 @@ const static struct rgw_http_errors RGW_HTTP_ERRORS[] = { { STATUS_NO_CONTENT, 204, "NoContent", "There was no need to send any content with this type of request" }, { STATUS_PARTIAL_CONTENT, 206, "" }, { ERR_PERMANENT_REDIRECT, 301, "PermanentRedirect" }, + { ERR_WEBSITE_REDIRECT, 301, "WebsiteRedirect" }, { STATUS_REDIRECT, 303, "" }, { ERR_NOT_MODIFIED, 304, "NotModified" }, { EINVAL, 400, "InvalidArgument", "Invalid Argument"}, @@ -53,6 +54,8 @@ const static struct rgw_http_errors RGW_HTTP_ERRORS[] = { { ETIMEDOUT, 408, "RequestTimeout", "Your socket connection to the server was not read from or written to within the timeout period."}, { EEXIST, 409, "BucketAlreadyExists", "The requested bucket name is not available. Please select a different name and try again"}, { ENOTEMPTY, 409, "BucketNotEmpty", "The bucket you tried to delete is not empty"}, + { ERR_NO_SUCH_WEBSITE_CONFIGURATION, 404, "NoSuchWebsiteConfiguration" }, + { ERR_USER_EXIST, 409, "UserAlreadyExists" }, { ERR_PRECONDITION_FAILED, 412, "PreconditionFailed" }, { ERANGE, 416, "InvalidRange", "The requested range cannot be satisfied."}, { ERR_UNPROCESSABLE_ENTITY, 422, "UnprocessableEntity" }, From d1dd9db5f7e872a24752697a61d4f553b58021fa Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 21:54:16 +0000 Subject: [PATCH 38/90] FIXUP: Shuffle auth order back down. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_main.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 4471323df0cdf..6652e903f7281 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -611,17 +611,6 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC should_log = mgr->get_logging(); - // Authorization must be before get_op - // because get_op depends on authorization data existing to choice if we are - // in website mode (authorization is NOT valid in website mode). - req->log(s, "authorizing"); - ret = handler->authorize(); - if (ret < 0) { - dout(10) << "failed to authorize request" << dendl; - abort_early(s, NULL, ret); - goto done; - } - req->log(s, "getting op"); op = handler->get_op(store); if (!op) { @@ -631,6 +620,14 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->op = op; dout(10) << "op=" << typeid(*op).name() << dendl; + req->log(s, "authorizing"); + ret = handler->authorize(); + if (ret < 0) { + dout(10) << "failed to authorize request" << dendl; + abort_early(s, NULL, ret); + goto done; + } + if (s->user.suspended) { dout(10) << "user is suspended, uid=" << s->user.user_id << dendl; abort_early(s, op, -ERR_USER_SUSPENDED); From ebb4db72a8d979d0ba2767501b868c417c0820e0 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 21:56:39 +0000 Subject: [PATCH 39/90] Improve RGWHandler for S3Website. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 118 +++++++++++++---------------------- src/rgw/rgw_rest_s3website.h | 35 +++++------ 2 files changed, 59 insertions(+), 94 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 9ab806d3d204b..c30c5d6d04cc6 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3076,82 +3076,31 @@ int RGWHandler_Auth_S3::init(RGWRados *store, struct req_state *state, RGWClient return RGWHandler_ObjStore::init(store, state, cio); } -bool RGWRESTMgr_S3::is_s3website_mode(struct req_state *s) -{ - if(!enable_s3website) - return false; - - // If this is true, we already detected the hostname as valid via the - // dedicated website endpoint. - if(s->prot_flags & RGW_PROTO_WEBSITE) - return true; - - /** S3Website: default_validity - * attempt to detect S3Website requests via: - * GET & HEAD only - * with NO authorization headers - * on a bucket with a website block - */ - if(g_conf->rgw_s3website_mode.find("default_validity") != std::string::npos) { - if(s->op != OP_GET && s->op != OP_HEAD) { - return false; - } - - // There was some talk of S3 implement static auth on websites, so we'd need - // to differentiate that in future. We take a shortcut here by detecting - // that AWS S3 always starts with 'AWS'; we might have issues in future - // if something else wants to use the HTTP-standard 'Basic' start, but - // not be S3Website. - string auth_id = s->info.args.get("AWSAccessKeyId"); - bool request_has_authentication = auth_id.size() || (s->http_auth && *(s->http_auth) && strncmp(s->http_auth, "AWS", 3) == 0); - if(request_has_authentication) { - return false; - } - - s->prot_flags |= RGW_PROTO_WEBSITE; // Actually only if the bucket is ALSO website - return true; - } - - return false; - -} - -bool RGWRESTMgr_S3::is_website_bucket(struct req_state *s) -{ - /* - // s->bucket_info is not yet populated - RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); - int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); -#warning FIXME: Do we need to catch -ENOENT seperately? What about other errors? - if (ret < 0) { - return false; - } - return s->bucket_info.has_website; - */ - return false; -} - RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { - bool is_s3website = is_s3website_mode(s); + bool is_s3website = enable_s3website && (s->prot_flags & RGW_PROTO_WEBSITE); int ret = RGWHandler_ObjStore_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, false); if (ret < 0) return NULL; - //ldout(s->cct, 20) << __func__ << " bucket=" << s->bucket_name_str << " object=" << s->object.name << " args=" << s->info.args.get_str() << dendl; - //if (s->info.args.sub_resource_exists("website")) - // - // RGWHandler* handler; - - if (s->bucket_name_str.empty()) { - handler = new RGWHandler_ObjStore_Service_S3; - } else if (is_s3website) { + // TODO: Make this more readable + if(is_s3website) { + if (s->bucket_name_str.empty()) { + handler = new RGWHandler_ObjStore_Service_S3Website; + } else if (s->object.empty()) { + handler = new RGWHandler_ObjStore_Bucket_S3Website; + } else { handler = new RGWHandler_ObjStore_Obj_S3Website; - } else if (s->object.empty()) { - handler = new RGWHandler_ObjStore_Bucket_S3; + } } else { + if (s->bucket_name_str.empty()) { + handler = new RGWHandler_ObjStore_Service_S3; + } else if (s->object.empty()) { + handler = new RGWHandler_ObjStore_Bucket_S3; + } else { handler = new RGWHandler_ObjStore_Obj_S3; + } } ldout(s->cct, 20) << __func__ << " handler=" << typeid(*handler).name() << dendl; @@ -3162,18 +3111,13 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; - // If bucket does not have website enabled, bail out - /* - if(!is_website_bucket(s)) { - return 0; - }*/ if(!(s->prot_flags & RGW_PROTO_WEBSITE)) return 0; RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); if (ret < 0 || !s->bucket_info.has_website) { - return false; + return 0; } rgw_obj_key new_obj; @@ -3205,6 +3149,16 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { return 0; } +RGWOp *RGWHandler_ObjStore_S3Website::op_get() +{ + return get_obj_op(true); +} + +RGWOp *RGWHandler_ObjStore_S3Website::op_head() +{ + return get_obj_op(false); +} + RGWOp *RGWHandler_ObjStore_Obj_S3Website::get_obj_op(bool get_data) { /** If we are in website mode, then it is explicitly impossible to run GET or @@ -3216,14 +3170,26 @@ RGWOp *RGWHandler_ObjStore_Obj_S3Website::get_obj_op(bool get_data) return op; } -RGWOp *RGWHandler_ObjStore_Obj_S3Website::op_get() +RGWOp *RGWHandler_ObjStore_Bucket_S3Website::get_obj_op(bool get_data) { - return get_obj_op(true); + /** If we are in website mode, then it is explicitly impossible to run GET or + * HEAD on the actual directory. We must convert the request to run on the + * suffix object instead! + */ + RGWGetObj_ObjStore_S3Website *op = new RGWGetObj_ObjStore_S3Website; + op->set_get_data(get_data); + return op; } -RGWOp *RGWHandler_ObjStore_Obj_S3Website::op_head() +RGWOp *RGWHandler_ObjStore_Service_S3Website::get_obj_op(bool get_data) { - return get_obj_op(false); + /** If we are in website mode, then it is explicitly impossible to run GET or + * HEAD on the actual directory. We must convert the request to run on the + * suffix object instead! + */ + RGWGetObj_ObjStore_S3Website *op = new RGWGetObj_ObjStore_S3Website; + op->set_get_data(get_data); + return op; } /* diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index f6eda69d9e183..9fc2b20527edb 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -6,13 +6,10 @@ class RGWHandler_ObjStore_S3Website : public RGWHandler_ObjStore_S3 { protected: int retarget(RGWOp *op, RGWOp **new_op); -public: - RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} - virtual ~RGWHandler_ObjStore_S3Website() {} -}; - -class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Website { -protected: + // TODO: this should be virtual I think, and ensure that it's always + // overridden, but that conflates that op_get/op_head are defined in this + // class and call this; and don't need to be overridden later. + virtual RGWOp *get_obj_op(bool get_data) { return NULL; } RGWOp *op_get(); RGWOp *op_head(); // Only allowed to use GET+HEAD @@ -21,6 +18,14 @@ class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Websi RGWOp *op_post() { return NULL; } RGWOp *op_copy() { return NULL; } RGWOp *op_options() { return NULL; } +public: + RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} + virtual ~RGWHandler_ObjStore_S3Website() {} +}; + +class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Website { +protected: + virtual RGWOp *get_obj_op(bool get_data); public: RGWHandler_ObjStore_Service_S3Website() {} virtual ~RGWHandler_ObjStore_Service_S3Website() {} @@ -28,16 +33,7 @@ class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Websi class RGWHandler_ObjStore_Obj_S3Website : public RGWHandler_ObjStore_S3Website { protected: - RGWOp *get_obj_op(bool get_data); - - RGWOp *op_get(); - RGWOp *op_head(); - // Only allowed to use GET+HEAD - RGWOp *op_put() { return NULL; } - RGWOp *op_delete() { return NULL; } - RGWOp *op_post() { return NULL; } - RGWOp *op_copy() { return NULL; } - RGWOp *op_options() { return NULL; } + virtual RGWOp *get_obj_op(bool get_data); public: RGWHandler_ObjStore_Obj_S3Website() {} virtual ~RGWHandler_ObjStore_Obj_S3Website() {} @@ -46,12 +42,15 @@ class RGWHandler_ObjStore_Obj_S3Website : public RGWHandler_ObjStore_S3Website { /* The cross-inheritance from Obj to Bucket is deliberate! * S3Websites do NOT support any bucket operations */ -class RGWHandler_ObjStore_Bucket_S3Website : public RGWHandler_ObjStore_Obj_S3Website { +class RGWHandler_ObjStore_Bucket_S3Website : public RGWHandler_ObjStore_S3Website { +protected: + RGWOp *get_obj_op(bool get_data); public: RGWHandler_ObjStore_Bucket_S3Website() {} virtual ~RGWHandler_ObjStore_Bucket_S3Website() {} }; +// TODO: do we actually need this? class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 { public: From 555cc8945e8a427ef5eaab2455c2f9680075de97 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 22:04:16 +0000 Subject: [PATCH 40/90] Remove config rgw_s3website_mode, only hostname mode remains. Signed-off-by: Robin H. Johnson --- src/common/config_opts.h | 1 - src/rgw/rgw_rest.cc | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index 13c3b7cec5dd3..db2ebb57eb89e 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -956,7 +956,6 @@ OPTION(rgw_host, OPT_STR, "") // host for radosgw, can be an IP, default is 0.0 OPTION(rgw_port, OPT_STR, "") // port to listen, format as "8080" "5000", if not specified, rgw will not run external fcgi OPTION(rgw_dns_name, OPT_STR, "") // hostname suffix on buckets OPTION(rgw_dns_s3website_name, OPT_STR, "") // hostname suffix on buckets for s3-website endpoint -OPTION(rgw_s3website_mode, OPT_STR, "hostname, default_validity") // modes for s3website handling OPTION(rgw_content_length_compat, OPT_BOOL, false) // Check both HTTP_CONTENT_LENGTH and CONTENT_LENGTH in fcgi env OPTION(rgw_script_uri, OPT_STR, "") // alternative value for SCRIPT_URI if not set in request OPTION(rgw_request_uri, OPT_STR, "") // alternative value for REQUEST_URI if not set in request diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 4aeffb043f67c..ca30f49247c7c 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1490,7 +1490,7 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) bool in_hosted_domain_s3website = false; bool in_hosted_domain = rgw_find_host_in_domains(info.host, &domain, &subdomain, hostnames_set); - bool s3website_enabled = g_conf->rgw_enable_apis.find("s3website") != std::string::npos && g_conf->rgw_s3website_mode.find("hostname") != std::string::npos; + bool s3website_enabled = g_conf->rgw_enable_apis.find("s3website") != std::string::npos; string s3website_domain; string s3website_subdomain; From db313b3d775adf35a84e51c6c6be92a93b8caa2d Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 22:04:39 +0000 Subject: [PATCH 41/90] Clean up headers. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 3341c2040d775..135fa39704290 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -491,9 +491,6 @@ class RGWHandler_ObjStore_Obj_S3 : public RGWHandler_ObjStore_S3 { class RGWRESTMgr_S3 : public RGWRESTMgr { private: bool enable_s3website; -protected: - bool is_s3website_mode(struct req_state *s); - bool is_website_bucket(struct req_state *s); public: RGWRESTMgr_S3(bool enable_s3website) : enable_s3website(false) { this->enable_s3website = enable_s3website; } virtual ~RGWRESTMgr_S3() {} From f10c557e1371a6897707b1e8a8641879a65b1a73 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 14 Jun 2015 22:10:08 +0000 Subject: [PATCH 42/90] Mark where to add some functionality in future. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index c30c5d6d04cc6..ce618f3ba3979 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3116,7 +3116,14 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); - if (ret < 0 || !s->bucket_info.has_website) { + if (ret < 0) { + // TODO-FUTURE: if the bucket does not exist, maybe expose it here? + // ENOENT -> NO_SUCH_BUCKET + return 0; + } + if(!s->bucket_info.has_website) { + // TODO-FUTURE: if the bucket has no WebsiteConfig, expose it here + // return ERR_NO_SUCH_WEBSITE_CONFIGURATION return 0; } From 82b88d10286cae6504ddf26b6abaa9e35fa45964 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 16 Jun 2015 08:19:40 +0000 Subject: [PATCH 43/90] rgw: add 301 http text. HTTP/1.1 code 301 is missing a message. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_http_errors.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rgw/rgw_http_errors.h b/src/rgw/rgw_http_errors.h index caee67553d7ab..d7f81ea50cb3d 100644 --- a/src/rgw/rgw_http_errors.h +++ b/src/rgw/rgw_http_errors.h @@ -87,6 +87,7 @@ const static struct rgw_http_status_code http_codes[] = { { 207, "Multi Status" }, { 208, "Already Reported" }, { 300, "Multiple Choices" }, + { 301, "Moved Permanently" }, { 302, "Found" }, { 303, "See Other" }, { 304, "Not Modified" }, From 42c8cd2f0a3bebe72026b9709a5b020f8cb5b4ff Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 16 Jun 2015 06:02:24 +0000 Subject: [PATCH 44/90] rgw: prepare for handlers to have custom error handler routines Signed-off-by: Robin H. Johnson --- src/rgw/rgw_main.cc | 22 +++++++++++----------- src/rgw/rgw_op.cc | 11 +++++++++++ src/rgw/rgw_op.h | 3 +++ src/rgw/rgw_rest.cc | 30 ++++++++++++++++++++++++++++-- src/rgw/rgw_rest.h | 2 +- 5 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 6652e903f7281..2749e68ad61e9 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -604,7 +604,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC RGWRESTMgr *mgr; RGWHandler *handler = rest->get_handler(store, s, client_io, &mgr, &init_error); if (init_error != 0) { - abort_early(s, NULL, init_error); + abort_early(s, NULL, init_error, NULL); goto done; } dout(10) << "handler=" << typeid(*handler).name() << dendl; @@ -614,7 +614,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->log(s, "getting op"); op = handler->get_op(store); if (!op) { - abort_early(s, NULL, -ERR_METHOD_NOT_ALLOWED); + abort_early(s, NULL, -ERR_METHOD_NOT_ALLOWED, handler); goto done; } req->op = op; @@ -624,20 +624,20 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC ret = handler->authorize(); if (ret < 0) { dout(10) << "failed to authorize request" << dendl; - abort_early(s, NULL, ret); + abort_early(s, NULL, ret, handler); goto done; } if (s->user.suspended) { dout(10) << "user is suspended, uid=" << s->user.user_id << dendl; - abort_early(s, op, -ERR_USER_SUSPENDED); + abort_early(s, op, -ERR_USER_SUSPENDED, handler); goto done; } req->log(s, "init permissions"); ret = handler->init_permissions(); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } @@ -648,7 +648,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->log(s, "recalculating target"); ret = handler->retarget(op, &op); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } req->op = op; @@ -657,7 +657,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->log(s, "reading permissions"); ret = handler->read_permissions(op); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } @@ -665,14 +665,14 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->log(s, "init op"); ret = op->init_processing(); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } req->log(s, "verifying op mask"); ret = op->verify_op_mask(); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } @@ -682,7 +682,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC if (s->system_request) { dout(2) << "overriding permissions due to system operation" << dendl; } else { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } } @@ -690,7 +690,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC req->log(s, "verifying op params"); ret = op->verify_params(); if (ret < 0) { - abort_early(s, op, ret); + abort_early(s, op, ret, handler); goto done; } diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 6dd7119457108..565904b3131d8 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3617,3 +3617,14 @@ void RGWHandler::put_op(RGWOp *op) delete op; } +int RGWOp::error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content) { + return this->dialect_handler->error_handler(err_no, new_err_no, dest_uri, error_content); +} + +int RGWHandler::error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content) { + *new_err_no = err_no; + // TODO: Should this modify s->redirect instead of touching dest_uri? + dest_uri = NULL; + error_content = NULL; + return 0; +} diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index ac888c7b7c098..9985b0f227bec 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -123,6 +123,8 @@ class RGWOp { virtual bool supports_website() { return false; } + + virtual int error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content); }; class RGWGetObj : public RGWOp { @@ -1119,6 +1121,7 @@ class RGWHandler { } virtual int read_permissions(RGWOp *op) = 0; virtual int authorize() = 0; + virtual int error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content); }; #endif diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index ca30f49247c7c..25e86f915bf1a 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -685,17 +685,43 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const rgw_flush_formatter_and_reset(s, s->formatter); } -void abort_early(struct req_state *s, RGWOp *op, int err_no) +void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler) { + string dest_uri(""); + string error_content(""); if (!s->formatter) { s->formatter = new JSONFormatter; s->format = RGW_FORMAT_JSON; } + // op->error_handler is responsible for calling it's handler error_handler + int ret = 0; + if(op != NULL) { + int new_err_no = 0; + // TODO: Should this modify s->redirect instead of touching dest_uri? + ret = op->error_handler(err_no, &new_err_no, &dest_uri, &error_content); + if(ret == 0) { + ldout(s->cct, 20) << "op->ERRORHANDLER: ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + err_no = new_err_no; + } else { + ldout(s->cct, 0) << "op->ERRORHANDLER FAILED ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + } + } + // But we do consider that op->error_handler might just fail as well + if(ret != 0 && handler != NULL) { + int new_err_no = 0; + // TODO: Should this modify s->redirect instead of touching dest_uri? + ret = op->error_handler(err_no, &new_err_no, &dest_uri, &error_content); + if(ret == 0) { + ldout(s->cct, 20) << "handler->ERRORHANDLER: ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + err_no = new_err_no; + } else { + ldout(s->cct, 0) << "handler->ERRORHANDLER FAILED ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + } + } set_req_state_err(s, err_no); dump_errno(s); dump_bucket_from_state(s); if (err_no == -ERR_PERMANENT_REDIRECT) { - string dest_uri; if (!s->redirect.empty()) { dest_uri = s->redirect; } else if (!s->region_endpoint.empty()) { diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index de118f4d143e3..18d1d8a2e8b01 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -382,7 +382,7 @@ extern void dump_etag(struct req_state *s, const char *etag); extern void dump_epoch_header(struct req_state *s, const char *name, time_t t); extern void dump_time_header(struct req_state *s, const char *name, time_t t); extern void dump_last_modified(struct req_state *s, time_t t); -extern void abort_early(struct req_state *s, RGWOp *op, int err); +extern void abort_early(struct req_state *s, RGWOp *op, int err, RGWHandler* handler); extern void dump_range(struct req_state *s, uint64_t ofs, uint64_t end, uint64_t total_size); extern void dump_continue(struct req_state *s); extern void list_all_buckets_end(struct req_state *s); From cd5a2ad215bffe76b7db89e21d68f632a4735954 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 16 Jun 2015 09:41:49 +0000 Subject: [PATCH 45/90] RGWWebsite: first pass at error redirect and error page handling. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_op.cc | 13 ++++------ src/rgw/rgw_op.h | 4 +-- src/rgw/rgw_rest.cc | 48 +++++++++++++++++------------------- src/rgw/rgw_rest_s3.cc | 43 +++++++++++++++++++++++++++++--- src/rgw/rgw_rest_s3website.h | 1 + src/rgw/rgw_website.cc | 24 ++++++++++++++---- src/rgw/rgw_website.h | 7 +++--- 7 files changed, 93 insertions(+), 47 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 565904b3131d8..726b108fbaf8b 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3617,14 +3617,11 @@ void RGWHandler::put_op(RGWOp *op) delete op; } -int RGWOp::error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content) { - return this->dialect_handler->error_handler(err_no, new_err_no, dest_uri, error_content); +int RGWOp::error_handler(int err_no, string error_content) { + return dialect_handler->error_handler(err_no, error_content); } -int RGWHandler::error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content) { - *new_err_no = err_no; - // TODO: Should this modify s->redirect instead of touching dest_uri? - dest_uri = NULL; - error_content = NULL; - return 0; +int RGWHandler::error_handler(int err_no, string error_content) { + // This is the do-nothing error handler + return err_no; } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 9985b0f227bec..843a970d720d8 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -124,7 +124,7 @@ class RGWOp { return false; } - virtual int error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content); + virtual int error_handler(int err_no, string error_content); }; class RGWGetObj : public RGWOp { @@ -1121,7 +1121,7 @@ class RGWHandler { } virtual int read_permissions(RGWOp *op) = 0; virtual int authorize() = 0; - virtual int error_handler(int err_no, int *new_err_no, string *dest_uri, string *error_content); + virtual int error_handler(int err_no, string error_content); }; #endif diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 25e86f915bf1a..80b19a546ac0b 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -311,6 +311,7 @@ void set_req_state_err(struct req_state *s, int err_no) if (err_no < 0) err_no = -err_no; s->err.ret = -err_no; + if (s->prot_flags & RGW_PROTO_SWIFT) { r = search_err(err_no, RGW_HTTP_SWIFT_ERRORS, ARRAY_LEN(RGW_HTTP_SWIFT_ERRORS)); if (r) { @@ -322,9 +323,14 @@ void set_req_state_err(struct req_state *s, int err_no) return; } } + r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { - s->err.http_ret = r->http_ret; + if(s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && s->err.http_ret != 0) { + // http_ret was custom set, so don't change it! + } else { + s->err.http_ret = r->http_ret; + } s->err.s3_code = r->s3_code; if (r->s3_err_message) { if ((s->err.message).empty()) { @@ -687,41 +693,29 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler) { - string dest_uri(""); string error_content(""); if (!s->formatter) { s->formatter = new JSONFormatter; s->format = RGW_FORMAT_JSON; } + // op->error_handler is responsible for calling it's handler error_handler - int ret = 0; if(op != NULL) { - int new_err_no = 0; - // TODO: Should this modify s->redirect instead of touching dest_uri? - ret = op->error_handler(err_no, &new_err_no, &dest_uri, &error_content); - if(ret == 0) { - ldout(s->cct, 20) << "op->ERRORHANDLER: ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; - err_no = new_err_no; - } else { - ldout(s->cct, 0) << "op->ERRORHANDLER FAILED ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; - } - } - // But we do consider that op->error_handler might just fail as well - if(ret != 0 && handler != NULL) { - int new_err_no = 0; - // TODO: Should this modify s->redirect instead of touching dest_uri? - ret = op->error_handler(err_no, &new_err_no, &dest_uri, &error_content); - if(ret == 0) { - ldout(s->cct, 20) << "handler->ERRORHANDLER: ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; - err_no = new_err_no; - } else { - ldout(s->cct, 0) << "handler->ERRORHANDLER FAILED ret=" << ret << " err_no=" << err_no << " new_err_no=" << new_err_no << dendl; - } + int new_err_no; + new_err_no = op->error_handler(err_no, error_content); + ldout(s->cct, 20) << "op->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + err_no = new_err_no; + } else if(handler != NULL) { + int new_err_no; + new_err_no = handler->error_handler(err_no, error_content); + ldout(s->cct, 20) << "handler->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; + err_no = new_err_no; } set_req_state_err(s, err_no); dump_errno(s); dump_bucket_from_state(s); - if (err_no == -ERR_PERMANENT_REDIRECT) { + if (err_no == -ERR_PERMANENT_REDIRECT || err_no == -ERR_WEBSITE_REDIRECT) { + string dest_uri; if (!s->redirect.empty()) { dest_uri = s->redirect; } else if (!s->region_endpoint.empty()) { @@ -742,6 +736,10 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler dump_redirect(s, dest_uri); } } + if(!error_content.empty()) { + ldout(s->cct, 20) << "error_content is set, we need to serve it INSTEAD of firing the formatter" << dendl; + assert(false); + } end_header(s, op); rgw_flush_formatter_and_reset(s, s->formatter); perfcounter->inc(l_rgw_failed_req); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index ce618f3ba3979..17d93307693c0 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3132,14 +3132,18 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { ldout(s->cct, 10) << "retarget get_effective_key " << s->object << " -> " << new_obj << dendl; RGWBWRoutingRule rrule; - bool should_redirect = s->bucket_info.website_conf.should_redirect(new_obj.name, &rrule); + bool should_redirect = s->bucket_info.website_conf.should_redirect(new_obj.name, 0, &rrule); if (should_redirect) { const string& hostname = s->info.env->get("HTTP_HOST", ""); const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); - rrule.apply_rule(protocol, hostname, new_obj.name, &s->redirect); - ldout(s->cct, 10) << "retarget redirect proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; - return -ERR_PERMANENT_REDIRECT; + int redirect_code = 0; + rrule.apply_rule(protocol, hostname, s->object.name, &s->redirect, &redirect_code); + // APply a custom HTTP response code + if(redirect_code > 0) + s->err.http_ret = redirect_code; // Apply a custom HTTP response code + ldout(s->cct, 10) << "retarget redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; + return -ERR_WEBSITE_REDIRECT; } #warning FIXME @@ -3165,6 +3169,37 @@ RGWOp *RGWHandler_ObjStore_S3Website::op_head() { return get_obj_op(false); } + +int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string error_content) { + const struct rgw_http_errors *r; + int http_error_code = -1; + r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); + if(r) { + http_error_code = r->http_ret; + } + + RGWBWRoutingRule rrule; + bool should_redirect = s->bucket_info.website_conf.should_redirect(s->object.name, http_error_code, &rrule); + + if (should_redirect) { + const string& hostname = s->info.env->get("HTTP_HOST", ""); + const string& protocol = (s->info.env->get("SERVER_PORT_SECURE") ? "https" : "http"); + int redirect_code = 0; + rrule.apply_rule(protocol, hostname, s->object.name, &s->redirect, &redirect_code); + // APply a custom HTTP response code + if(redirect_code > 0) + s->err.http_ret = redirect_code; // Apply a custom HTTP response code + ldout(s->cct, 10) << "error handler redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; + return -ERR_WEBSITE_REDIRECT; + } else if(!s->bucket_info.website_conf.error_doc.empty()) { + ldout(s->cct, 20) << "TODO Serve Custom error page here if bucket has " << dendl; + error_content = s->bucket_info.website_conf.error_doc; + } else { + ldout(s->cct, 20) << "No special error handling today!" << dendl; + } + + return err_no; +} RGWOp *RGWHandler_ObjStore_Obj_S3Website::get_obj_op(bool get_data) { diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 9fc2b20527edb..bd4cf4073f493 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -21,6 +21,7 @@ class RGWHandler_ObjStore_S3Website : public RGWHandler_ObjStore_S3 { public: RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} virtual ~RGWHandler_ObjStore_S3Website() {} + virtual int error_handler(int err_no, string error_content); }; class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Website { diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 5f2bb8187d2b5..4c4fe5ad08b34 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -19,7 +19,7 @@ bool RGWBWRoutingRuleCondition::check_key_condition(const string& key) { void RGWBWRoutingRule::apply_rule(const string& default_protocol, const string& default_hostname, - const string& key, string *new_url) + const string& key, string *new_url, int *redirect_code) { RGWRedirectInfo& redirect = redirect_info.redirect; @@ -36,6 +36,20 @@ void RGWBWRoutingRule::apply_rule(const string& default_protocol, const string& } else { *new_url += key; } + + if(redirect.http_redirect_code > 0) + *redirect_code = redirect.http_redirect_code; +} + +bool RGWBWRoutingRules::check_key_and_error_code_condition(const string &key, int error_code, RGWBWRoutingRule **rule) +{ + for (list::iterator iter = rules.begin(); iter != rules.end(); ++iter) { + if (iter->check_key_condition(key) && iter->check_error_code_condition(error_code)) { + *rule = &(*iter); + return true; + } + } + return false; } bool RGWBWRoutingRules::check_key_condition(const string& key, RGWBWRoutingRule **rule) @@ -49,10 +63,10 @@ bool RGWBWRoutingRules::check_key_condition(const string& key, RGWBWRoutingRule return false; } -bool RGWBWRoutingRules::check_error_code_condition(int error_code, RGWBWRoutingRule **rule) +bool RGWBWRoutingRules::check_error_code_condition(const int http_error_code, RGWBWRoutingRule **rule) { for (list::iterator iter = rules.begin(); iter != rules.end(); ++iter) { - if (iter->check_error_code_condition(error_code)) { + if (iter->check_error_code_condition(http_error_code)) { *rule = &(*iter); return true; } @@ -60,7 +74,7 @@ bool RGWBWRoutingRules::check_error_code_condition(int error_code, RGWBWRoutingR return false; } -bool RGWBucketWebsiteConf::should_redirect(const string& key, RGWBWRoutingRule *redirect) +bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_error_code, RGWBWRoutingRule *redirect) { RGWBWRoutingRule *rule; if(!redirect_all.hostname.empty()) { @@ -68,7 +82,7 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, RGWBWRoutingRule * redirect_all_rule.redirect_info.redirect = redirect_all; *redirect = redirect_all_rule; return true; - } else if (!routing_rules.check_key_condition(key, &rule)) { + } else if (!routing_rules.check_key_and_error_code_condition(key, http_error_code, &rule)) { return false; } diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index c346418e90f14..348412d001e06 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -82,7 +82,7 @@ struct RGWBWRoutingRuleCondition void decode_xml(XMLObj *obj); bool check_key_condition(const string& key); - bool check_error_code_condition(int error_code) { + bool check_error_code_condition(const int error_code) { return (uint16_t)error_code == http_error_code_returned_equals; } }; @@ -118,7 +118,7 @@ struct RGWBWRoutingRule return condition.check_error_code_condition(error_code); } - void apply_rule(const string& default_protocol, const string& default_hostname, const string& key, string *redirect); + void apply_rule(const string& default_protocol, const string& default_hostname, const string& key, string *redirect, int *redirect_code); }; WRITE_CLASS_ENCODER(RGWBWRoutingRule) @@ -143,6 +143,7 @@ struct RGWBWRoutingRules bool check_key_condition(const string& key, RGWBWRoutingRule **rule); bool check_error_code_condition(int error_code, RGWBWRoutingRule **rule); + bool check_key_and_error_code_condition(const string& key, const int error_code, RGWBWRoutingRule **rule); }; WRITE_CLASS_ENCODER(RGWBWRoutingRules) @@ -177,7 +178,7 @@ struct RGWBucketWebsiteConf void decode_xml(XMLObj *obj); void dump_xml(Formatter *f) const; - bool should_redirect(const string& key, RGWBWRoutingRule *redirect); + bool should_redirect(const string& key, const int http_error_code, RGWBWRoutingRule *redirect); void get_effective_key(const string& key, string *effective_key); }; WRITE_CLASS_ENCODER(RGWBucketWebsiteConf) From 3ad7bb3bb54f2b1f8f1e80e14c947feb68e8e55a Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 17 Jun 2015 00:44:54 +0000 Subject: [PATCH 46/90] S3Website: Ensure redirect_all has a 302 response, just like AmazonS3 Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 4c4fe5ad08b34..14c2af926fd79 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -80,6 +80,7 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_err if(!redirect_all.hostname.empty()) { RGWBWRoutingRule redirect_all_rule; redirect_all_rule.redirect_info.redirect = redirect_all; + redirect_all.http_redirect_code = 302; *redirect = redirect_all_rule; return true; } else if (!routing_rules.check_key_and_error_code_condition(key, http_error_code, &rule)) { From 2c685e2a3bbfd978e0174ee42ecad57ec256aee7 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 17 Jun 2015 00:45:25 +0000 Subject: [PATCH 47/90] S3Website: "good" error status is actually not zero, use the function instead. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 80b19a546ac0b..d3442b670886a 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -326,7 +326,7 @@ void set_req_state_err(struct req_state *s, int err_no) r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { - if(s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && s->err.http_ret != 0) { + if(s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { // http_ret was custom set, so don't change it! } else { s->err.http_ret = r->http_ret; From 60b0662a2729d769cd44fc29fe77b7fcc380b5f2 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 22 Jun 2015 23:19:38 +0000 Subject: [PATCH 48/90] s3website: Prepwork for x-amz-website-redirect-location header. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_common.h --- src/rgw/rgw_common.h | 5 ++++- src/rgw/rgw_rest.cc | 1 + src/rgw/rgw_rest_s3.cc | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index db26300046fa2..d07f1de4ebbc4 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -51,7 +51,9 @@ using ceph::crypto::MD5; #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" -#define RGW_AMZ_META_PREFIX "x-jcs-meta-" +#define RGW_AMZ_PREFIX "x-amz-" +#define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "x-jcs-meta-" +#define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location" #define RGW_SYS_PARAM_PREFIX "rgwx-" @@ -70,6 +72,7 @@ using ceph::crypto::MD5; #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name" #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest" #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest" +#define RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION RGW_ATTR_PREFIX RGW_AMZ_WEBSITE_REDIRECT_LOCATION #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh." diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index d3442b670886a..892d3c757e27a 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -45,6 +45,7 @@ static struct rgw_http_attr rgw_to_http_attr_list[] = { { RGW_ATTR_CONTENT_DISP, "Content-Disposition"}, { RGW_ATTR_CONTENT_ENC, "Content-Encoding"}, { RGW_ATTR_USER_MANIFEST, "X-Object-Manifest"}, + { RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION, "Location"}, { NULL, NULL}, }; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 17d93307693c0..f2f7991980cea 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1210,6 +1210,21 @@ int RGWPostObj_ObjStore_S3::get_params() attrs[attr_name] = attr_bl; } + // TODO: refactor this and the above loop to share code + piter = parts.find(RGW_AMZ_WEBSITE_REDIRECT_LOCATION); + if(piter != parts.end()) { + string n = piter->first; + string attr_name = RGW_ATTR_PREFIX; + attr_name.append(n); + /* need to null terminate it */ + bufferlist& data = piter->second.data; + string str = string(data.c_str(), data.length()); + + bufferlist attr_bl; + attr_bl.append(str.c_str(), str.size() + 1); + + attrs[attr_name] = attr_bl; + } int r = get_policy(); if (r < 0) From 61ee45279857b95eb81ba77880c3ece8369be57a Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 28 Jun 2015 18:17:20 +0000 Subject: [PATCH 49/90] Use more specific error codes for retarget of website requests Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index f2f7991980cea..37ec14d8a3e8c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3133,13 +3133,11 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { int ret = store->get_bucket_info(obj_ctx, s->bucket_name_str, s->bucket_info, NULL, &s->bucket_attrs); if (ret < 0) { // TODO-FUTURE: if the bucket does not exist, maybe expose it here? - // ENOENT -> NO_SUCH_BUCKET - return 0; + return -ERR_NO_SUCH_BUCKET; } if(!s->bucket_info.has_website) { // TODO-FUTURE: if the bucket has no WebsiteConfig, expose it here - // return ERR_NO_SUCH_WEBSITE_CONFIGURATION - return 0; + return -ERR_NO_SUCH_WEBSITE_CONFIGURATION; } rgw_obj_key new_obj; From 7b0a7b6420bdcb956da2a33116523cd31d5d3c1a Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 18 Aug 2015 18:22:20 +0000 Subject: [PATCH 50/90] WIP: static-site errordoc work. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_op.cc | 16 ++-------------- src/rgw/rgw_op.h | 16 ++++++++++++++-- src/rgw/rgw_rest.cc | 18 +++++++++++------- src/rgw/rgw_rest.h | 3 ++- src/rgw/rgw_rest_s3.cc | 33 ++++++++++++++++++++++++++++++--- src/rgw/rgw_rest_s3website.h | 4 +++- 6 files changed, 62 insertions(+), 28 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 726b108fbaf8b..4110f145116ad 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -869,18 +869,6 @@ int RGWGetObj::handle_user_manifest(const char *prefix) return 0; } -class RGWGetObj_CB : public RGWGetDataCB -{ - RGWGetObj *op; -public: - RGWGetObj_CB(RGWGetObj *_op) : op(_op) {} - virtual ~RGWGetObj_CB() {} - - int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { - return op->get_data_cb(bl, bl_ofs, bl_len); - } -}; - int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len) { /* garbage collection related handling */ @@ -3617,11 +3605,11 @@ void RGWHandler::put_op(RGWOp *op) delete op; } -int RGWOp::error_handler(int err_no, string error_content) { +int RGWOp::error_handler(int err_no, string *error_content) { return dialect_handler->error_handler(err_no, error_content); } -int RGWHandler::error_handler(int err_no, string error_content) { +int RGWHandler::error_handler(int err_no, string *error_content) { // This is the do-nothing error handler return err_no; } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 843a970d720d8..8337754d255cc 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -124,7 +124,7 @@ class RGWOp { return false; } - virtual int error_handler(int err_no, string error_content); + virtual int error_handler(int err_no, string *error_content); }; class RGWGetObj : public RGWOp { @@ -197,6 +197,18 @@ class RGWGetObj : public RGWOp { } }; +class RGWGetObj_CB : public RGWGetDataCB +{ + RGWGetObj *op; +public: + RGWGetObj_CB(RGWGetObj *_op) : op(_op) {} + virtual ~RGWGetObj_CB() {} + + int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { + return op->get_data_cb(bl, bl_ofs, bl_len); + } +}; + #define RGW_LIST_BUCKETS_LIMIT_MAX 10000 class RGWListBuckets : public RGWOp { @@ -1121,7 +1133,7 @@ class RGWHandler { } virtual int read_permissions(RGWOp *op) = 0; virtual int authorize() = 0; - virtual int error_handler(int err_no, string error_content); + virtual int error_handler(int err_no, string *error_content); }; #endif diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 892d3c757e27a..fc600b500e810 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -557,7 +557,7 @@ void dump_trans_id(req_state *s) } void end_header(struct req_state *s, RGWOp *op, const char *content_type, const int64_t proposed_content_length, - bool force_content_type) + bool force_content_type, bool force_no_error) { string ctype; @@ -651,7 +651,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const ctype.append("; charset=utf-8"); content_type = ctype.c_str(); } - if (s->err.is_err()) { + if (!force_no_error && s->err.is_err()) { dump_start(s); if(s->format != RGW_FORMAT_HTML) { s->formatter->open_object_section("Error"); @@ -703,12 +703,12 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler // op->error_handler is responsible for calling it's handler error_handler if(op != NULL) { int new_err_no; - new_err_no = op->error_handler(err_no, error_content); + new_err_no = op->error_handler(err_no, &error_content); ldout(s->cct, 20) << "op->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; err_no = new_err_no; } else if(handler != NULL) { int new_err_no; - new_err_no = handler->error_handler(err_no, error_content); + new_err_no = handler->error_handler(err_no, &error_content); ldout(s->cct, 20) << "handler->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; err_no = new_err_no; } @@ -739,10 +739,14 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler } if(!error_content.empty()) { ldout(s->cct, 20) << "error_content is set, we need to serve it INSTEAD of firing the formatter" << dendl; - assert(false); +#warning TODO we must add all error entries as headers here + end_header(s, op, NULL, NO_CONTENT_LENGTH, false, true); + s->cio->write(error_content.c_str(), error_content.size()); + s->formatter->reset(); + } else { + end_header(s, op); + rgw_flush_formatter_and_reset(s, s->formatter); } - end_header(s, op); - rgw_flush_formatter_and_reset(s, s->formatter); perfcounter->inc(l_rgw_failed_req); } diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index 18d1d8a2e8b01..d3287474b9bcc 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -372,7 +372,8 @@ extern void end_header(struct req_state *s, RGWOp *op = NULL, const char *content_type = NULL, const int64_t proposed_content_length = NO_CONTENT_LENGTH, - bool force_content_type = false); + bool force_content_type = false, + bool force_no_error = false); extern void dump_start(struct req_state *s); extern void list_all_buckets_start(struct req_state *s); extern void dump_owner(struct req_state *s, string& id, string& name, const char *section = NULL); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 37ec14d8a3e8c..bc7076dcc4af9 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3182,8 +3182,36 @@ RGWOp *RGWHandler_ObjStore_S3Website::op_head() { return get_obj_op(false); } + +int RGWHandler_ObjStore_S3Website::get_errordoc(const string errordoc_key, string *error_content) { + ldout(s->cct, 20) << "TODO Serve Custom error page here if bucket has " << dendl; + *error_content = errordoc_key; + // 1. Check if errordoc exists + // 2. Check if errordoc is public + // 3. Fetch errordoc content + RGWGetObj_ObjStore_S3Website *getop = new RGWGetObj_ObjStore_S3Website; + getop->set_get_data(true); + getop->init(store, s, this); + + RGWGetObj_CB cb(getop); + rgw_obj obj(s->bucket, errordoc_key); + RGWObjectCtx rctx(store); + //RGWRados::Object op_target(store, s->bucket_info, *static_cast(s->obj_ctx), obj); + RGWRados::Object op_target(store, s->bucket_info, rctx, obj); + RGWRados::Object::Read read_op(&op_target); + + int ret; + int64_t ofs = 0; + int64_t end = -1; + ret = read_op.prepare(&ofs, &end); + if (ret < 0) + return ret; + + ret = read_op.iterate(ofs, end, &cb); // FIXME: need to know the final size? + return ret; +} -int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string error_content) { +int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string *error_content) { const struct rgw_http_errors *r; int http_error_code = -1; r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); @@ -3205,8 +3233,7 @@ int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string error_conten ldout(s->cct, 10) << "error handler redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; return -ERR_WEBSITE_REDIRECT; } else if(!s->bucket_info.website_conf.error_doc.empty()) { - ldout(s->cct, 20) << "TODO Serve Custom error page here if bucket has " << dendl; - error_content = s->bucket_info.website_conf.error_doc; + RGWHandler_ObjStore_S3Website::get_errordoc(s->bucket_info.website_conf.error_doc, error_content); } else { ldout(s->cct, 20) << "No special error handling today!" << dendl; } diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index bd4cf4073f493..9a4a7020633a0 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -18,10 +18,12 @@ class RGWHandler_ObjStore_S3Website : public RGWHandler_ObjStore_S3 { RGWOp *op_post() { return NULL; } RGWOp *op_copy() { return NULL; } RGWOp *op_options() { return NULL; } + + int get_errordoc(const string errordoc_key, string *error_content); public: RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} virtual ~RGWHandler_ObjStore_S3Website() {} - virtual int error_handler(int err_no, string error_content); + virtual int error_handler(int err_no, string *error_content); }; class RGWHandler_ObjStore_Service_S3Website : public RGWHandler_ObjStore_S3Website { From eef71458020da74383cc58cafb748cd388da5d0c Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 24 Aug 2015 05:01:36 +0000 Subject: [PATCH 51/90] Fixup. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index fc600b500e810..95ed6f1c76b9a 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -626,7 +626,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const delete [] allowed_origins; - if (s->prot_flags & RGW_REST_SWIFT && !content_type) { + if (s->prot_flags & RGW_PROTO_SWIFT && !content_type) { force_content_type = true; } From e407fb917fb012bfd7ba3d06c6e97c1d48d4dbda Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 12 Oct 2015 16:15:53 -0700 Subject: [PATCH 52/90] minor fixes following rebase Signed-off-by: Yehuda Sadeh Conflicts: src/os/newstore/NewStore.cc src/rgw/Makefile.am --- src/mon/MonitorDBStore.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 2f6f8d8ba8749..58cff24e4156c 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -23,7 +23,7 @@ #include "os/KeyValueDB.h" #include "include/assert.h" -#include "common/Formatter.h" +#include "common/JSONFormatter.h" #include "common/Finisher.h" #include "common/errno.h" From 084abb405d7fb933d9f7d24707df0edf5105e5fe Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 12 Oct 2015 16:16:17 -0700 Subject: [PATCH 53/90] rgw: style fixes Signed-off-by: Yehuda Sadeh --- src/common/HTMLFormatter.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc index 516282b830b76..35e36a2340798 100644 --- a/src/common/HTMLFormatter.cc +++ b/src/common/HTMLFormatter.cc @@ -42,11 +42,11 @@ HTMLFormatter::HTMLFormatter(bool pretty) HTMLFormatter::~HTMLFormatter() { - if(m_status) { + if (m_status) { free((void*)m_status); m_status = NULL; } - if(m_status_name) { + if (m_status_name) { free((void*)m_status_name); m_status_name = NULL; } @@ -56,11 +56,11 @@ void HTMLFormatter::reset() { XMLFormatter::reset(); m_header_done = false; - if(m_status) { + if (m_status) { free((void*)m_status); m_status = NULL; } - if(m_status_name) { + if (m_status_name) { free((void*)m_status_name); m_status_name = NULL; } @@ -71,16 +71,16 @@ void HTMLFormatter::set_status(const char* status, const char* status_name) assert(status != NULL); // new status must not be NULL assert(m_status == NULL); // status should NOT be set multiple times m_status = strdup(status); - if(status_name) + if (status_name) m_status_name = strdup(status_name); }; void HTMLFormatter::output_header() { - if(!m_header_done) { + if (!m_header_done) { m_header_done = true; assert(m_status != NULL); // it should be set by this point std::string status_line(m_status); - if(m_status_name) { + if (m_status_name) { status_line += " "; status_line += m_status_name; } From 37b09c505015c9329a98c466a8ba9996a9a48379 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 12 Oct 2015 16:45:09 -0700 Subject: [PATCH 54/90] rgw: more style fixes Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rest.cc | 24 ++++++++++++------------ src/rgw/rgw_rest_s3.cc | 16 ++++++++-------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 95ed6f1c76b9a..9196a4fa6915e 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -207,7 +207,7 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) hostnames_set.insert(cct->_conf->rgw_dns_name); } hostnames_set.insert(region.hostnames.begin(), region.hostnames.end()); - string s(""); + string s; ldout(cct, 20) << "RGW hostnames: " << std::accumulate(hostnames_set.begin(), hostnames_set.end(), s) << dendl; /* TODO: We should have a sanity check that no hostname matches the end of * any other hostname, otherwise we will get ambigious results from @@ -219,11 +219,11 @@ void rgw_rest_init(CephContext *cct, RGWRegion& region) * X.B.A ambigously splits to both {X, B.A} and {X.B, A} */ - if(!cct->_conf->rgw_dns_s3website_name.empty()) { + if (!cct->_conf->rgw_dns_s3website_name.empty()) { hostnames_s3website_set.insert(cct->_conf->rgw_dns_s3website_name); } hostnames_s3website_set.insert(region.hostnames_s3website.begin(), region.hostnames_s3website.end()); - s.assign(""); + s.clear(); ldout(cct, 20) << "RGW S3website hostnames: " << std::accumulate(hostnames_s3website_set.begin(), hostnames_s3website_set.end(), s) << dendl; /* TODO: we should repeat the hostnames_set sanity check here * and ALSO decide about overlap, if any @@ -327,7 +327,7 @@ void set_req_state_err(struct req_state *s, int err_no) r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { - if(s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { + if (s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { // http_ret was custom set, so don't change it! } else { s->err.http_ret = r->http_ret; @@ -653,7 +653,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const } if (!force_no_error && s->err.is_err()) { dump_start(s); - if(s->format != RGW_FORMAT_HTML) { + if (s->format != RGW_FORMAT_HTML) { s->formatter->open_object_section("Error"); } if (!s->err.s3_code.empty()) @@ -665,7 +665,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const if (!s->trans_id.empty()) // TODO: connect to expose_bucket or another toggle s->formatter->dump_string("RequestId", s->trans_id); s->formatter->dump_string("HostId", "FIXME-TODO-How-does-amazon-generate-HostId"); // TODO, FIXME - if(s->format != RGW_FORMAT_HTML) { + if (s->format != RGW_FORMAT_HTML) { s->formatter->close_section(); } s->formatter->output_footer(); @@ -701,12 +701,12 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler } // op->error_handler is responsible for calling it's handler error_handler - if(op != NULL) { + if (op != NULL) { int new_err_no; new_err_no = op->error_handler(err_no, &error_content); ldout(s->cct, 20) << "op->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; err_no = new_err_no; - } else if(handler != NULL) { + } else if (handler != NULL) { int new_err_no; new_err_no = handler->error_handler(err_no, &error_content); ldout(s->cct, 20) << "handler->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; @@ -737,7 +737,7 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler dump_redirect(s, dest_uri); } } - if(!error_content.empty()) { + if (!error_content.empty()) { ldout(s->cct, 20) << "error_content is set, we need to serve it INSTEAD of firing the formatter" << dendl; #warning TODO we must add all error entries as headers here end_header(s, op, NULL, NO_CONTENT_LENGTH, false, true); @@ -1525,7 +1525,7 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) if (s3website_enabled) { in_hosted_domain_s3website = rgw_find_host_in_domains(info.host, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); - if(in_hosted_domain_s3website) { + if (in_hosted_domain_s3website) { in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? domain = s3website_domain; subdomain = s3website_subdomain; @@ -1553,9 +1553,9 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) << cname << dendl; in_hosted_domain = rgw_find_host_in_domains(cname, &domain, &subdomain, hostnames_set); - if(s3website_enabled && !in_hosted_domain_s3website) { + if (s3website_enabled && !in_hosted_domain_s3website) { in_hosted_domain_s3website = rgw_find_host_in_domains(cname, &s3website_domain, &s3website_subdomain, hostnames_s3website_set); - if(in_hosted_domain_s3website) { + if (in_hosted_domain_s3website) { in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? domain = s3website_domain; subdomain = s3website_subdomain; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index bc7076dcc4af9..7af3b570ffde3 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1212,7 +1212,7 @@ int RGWPostObj_ObjStore_S3::get_params() } // TODO: refactor this and the above loop to share code piter = parts.find(RGW_AMZ_WEBSITE_REDIRECT_LOCATION); - if(piter != parts.end()) { + if (piter != parts.end()) { string n = piter->first; string attr_name = RGW_ATTR_PREFIX; attr_name.append(n); @@ -3100,7 +3100,7 @@ RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) RGWHandler* handler; // TODO: Make this more readable - if(is_s3website) { + if (is_s3website) { if (s->bucket_name_str.empty()) { handler = new RGWHandler_ObjStore_Service_S3Website; } else if (s->object.empty()) { @@ -3126,7 +3126,7 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; - if(!(s->prot_flags & RGW_PROTO_WEBSITE)) + if (!(s->prot_flags & RGW_PROTO_WEBSITE)) return 0; RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); @@ -3135,7 +3135,7 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { // TODO-FUTURE: if the bucket does not exist, maybe expose it here? return -ERR_NO_SUCH_BUCKET; } - if(!s->bucket_info.has_website) { + if (!s->bucket_info.has_website) { // TODO-FUTURE: if the bucket has no WebsiteConfig, expose it here return -ERR_NO_SUCH_WEBSITE_CONFIGURATION; } @@ -3153,7 +3153,7 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { int redirect_code = 0; rrule.apply_rule(protocol, hostname, s->object.name, &s->redirect, &redirect_code); // APply a custom HTTP response code - if(redirect_code > 0) + if (redirect_code > 0) s->err.http_ret = redirect_code; // Apply a custom HTTP response code ldout(s->cct, 10) << "retarget redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; return -ERR_WEBSITE_REDIRECT; @@ -3215,7 +3215,7 @@ int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string *error_conte const struct rgw_http_errors *r; int http_error_code = -1; r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); - if(r) { + if (r) { http_error_code = r->http_ret; } @@ -3228,11 +3228,11 @@ int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string *error_conte int redirect_code = 0; rrule.apply_rule(protocol, hostname, s->object.name, &s->redirect, &redirect_code); // APply a custom HTTP response code - if(redirect_code > 0) + if (redirect_code > 0) s->err.http_ret = redirect_code; // Apply a custom HTTP response code ldout(s->cct, 10) << "error handler redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; return -ERR_WEBSITE_REDIRECT; - } else if(!s->bucket_info.website_conf.error_doc.empty()) { + } else if (!s->bucket_info.website_conf.error_doc.empty()) { RGWHandler_ObjStore_S3Website::get_errordoc(s->bucket_info.website_conf.error_doc, error_content); } else { ldout(s->cct, 20) << "No special error handling today!" << dendl; From f890b6227ababa0d02a7f43cf862cd503cd87499 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 24 Nov 2015 15:12:21 -0800 Subject: [PATCH 55/90] rgw/Makefile.am: declare rgw_website.h for buildfix. Signed-off-by: Robin H. Johnson --- src/rgw/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index 6b683e78ce169..dc1f05979f0ea 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -173,6 +173,7 @@ noinst_HEADERS += \ rgw/rgw_keystone.h \ rgw/rgw_civetweb.h \ rgw/rgw_civetweb_log.h \ + rgw/rgw_website.h \ civetweb/civetweb.h \ civetweb/include/civetweb.h \ civetweb/include/civetweb_conf.h \ From 468202bae30aa8959e8d666e19722b1ce2705a28 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 25 Nov 2015 10:14:08 -0800 Subject: [PATCH 56/90] rgw/Makefile.am: declare rgw_rest_s3website.h as well for bugfixing. Signed-off-by: Robin H. Johnson --- src/rgw/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index dc1f05979f0ea..a4004d6681d9e 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -174,6 +174,7 @@ noinst_HEADERS += \ rgw/rgw_civetweb.h \ rgw/rgw_civetweb_log.h \ rgw/rgw_website.h \ + rgw/rgw_rest_s3website.h \ civetweb/civetweb.h \ civetweb/include/civetweb.h \ civetweb/include/civetweb_conf.h \ From 071ff6e88efcc2e49230b5fba572a7eb5e8bbf17 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 25 Nov 2015 16:37:38 -0800 Subject: [PATCH 57/90] src/*/Makefile.am: test fixup for as-needed compiling. Signed-off-by: Robin H. Johnson Conflicts: src/global/Makefile.am --- src/global/Makefile.am | 3 +++ src/tracing/Makefile.am | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/global/Makefile.am b/src/global/Makefile.am index 79a7ffff689cd..00a7e373cad29 100644 --- a/src/global/Makefile.am +++ b/src/global/Makefile.am @@ -4,6 +4,9 @@ libglobal_la_SOURCES = \ global/pidfile.cc \ global/signal_handler.cc libglobal_la_LIBADD = $(LIBCOMMON) +if WITH_LTTNG +libglobal_la_LIBADD += -ldl -llttng-ust +endif noinst_LTLIBRARIES += libglobal.la noinst_HEADERS += \ diff --git a/src/tracing/Makefile.am b/src/tracing/Makefile.am index 16d300ec1dbbb..510c0bc75732e 100644 --- a/src/tracing/Makefile.am +++ b/src/tracing/Makefile.am @@ -22,7 +22,7 @@ nodist_libosd_tp_la_SOURCES = \ pg.h \ pg.c endif -libosd_tp_la_LIBADD = -llttng-ust -ldl +libosd_tp_la_LIBADD = -ldl -llttng-ust libosd_tp_la_CPPFLAGS = -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE libosd_tp_la_LDFLAGS = @@ -31,7 +31,7 @@ nodist_librados_tp_la_SOURCES = \ librados.c \ librados.h endif -librados_tp_la_LIBADD = -llttng-ust -ldl +librados_tp_la_LIBADD = -ldl -llttng-ust librados_tp_la_CPPFLAGS = -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE librados_tp_la_CFLAGS = -I$(top_srcdir)/src $(AM_CFLAGS) librados_tp_la_LDFLAGS = @@ -41,7 +41,7 @@ nodist_librbd_tp_la_SOURCES = \ librbd.c \ librbd.h endif -librbd_tp_la_LIBADD = -llttng-ust -ldl +librbd_tp_la_LIBADD = -ldl -llttng-ust librbd_tp_la_CPPFLAGS = -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE librbd_tp_la_CFLAGS = -I$(top_srcdir)/src $(AM_CFLAGS) librbd_tp_la_LDFLAGS = @@ -51,7 +51,7 @@ nodist_libos_tp_la_SOURCES = \ objectstore.c \ objectstore.h endif -libos_tp_la_LIBADD = -llttng-ust -ldl +libos_tp_la_LIBADD = -ldl -llttng-ust libos_tp_la_CPPFLAGS = -DTRACEPOINT_PROBE_DYNAMIC_LINKAGE libos_tp_la_CFLAGS = -I$(top_srcdir)/src $(AM_CFLAGS) libos_tp_la_LDFLAGS = From 908f81c6235045f037ea4850685d73fdf281c402 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Mon, 30 Nov 2015 15:41:43 -0800 Subject: [PATCH 58/90] rgw/s3website: errordoc conditional handling We need to override all conditional request parameters in errordoc fallback request, and serve a complete page always, never anything conditional. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_rest_s3.cc | 3 ++- src/rgw/rgw_rest_s3website.h | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 7af3b570ffde3..cd21df5831923 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3189,7 +3189,8 @@ int RGWHandler_ObjStore_S3Website::get_errordoc(const string errordoc_key, strin // 1. Check if errordoc exists // 2. Check if errordoc is public // 3. Fetch errordoc content - RGWGetObj_ObjStore_S3Website *getop = new RGWGetObj_ObjStore_S3Website; +#warning 2015119: FIXME need to clear all + RGWGetObj_ObjStore_S3Website *getop = new RGWGetObj_ObjStore_S3Website(true); getop->set_get_data(true); getop->init(store, s, this); diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 9a4a7020633a0..24292ca819170 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -56,9 +56,26 @@ class RGWHandler_ObjStore_Bucket_S3Website : public RGWHandler_ObjStore_S3Websit // TODO: do we actually need this? class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 { +private: + bool is_errordoc_request; public: - RGWGetObj_ObjStore_S3Website() {} + RGWGetObj_ObjStore_S3Website() : is_errordoc_request(false) {} + RGWGetObj_ObjStore_S3Website(bool is_errordoc_request) : is_errordoc_request(false) { this->is_errordoc_request = is_errordoc_request; } ~RGWGetObj_ObjStore_S3Website() {} + // We override RGWGetObj_ObjStore::get_params here, to allow ignoring all + // conditional params for error pages. + int get_params() { + if (is_errordoc_request) { + range_str = NULL; + if_mod = NULL; + if_unmod = NULL; + if_match = NULL; + if_nomatch = NULL; + return 0; + } else { + return RGWGetObj_ObjStore_S3::get_params(); + } + } }; #endif From e4725b64a10604569bcdeae381ed5a56b8a0d492 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Fri, 15 Jan 2016 15:05:22 -0800 Subject: [PATCH 59/90] Revert "common/*Formatters: Split Formatters" This reverts commit 2b21e3c595c23f409485b8c391d1bd579b13b8e7. Conflicts: src/common/Formatter.cc src/common/JSONFormatter.h src/common/Makefile.am src/common/TableFormatter.h src/common/XMLFormatter.cc src/common/XMLFormatter.h src/rgw/rgw_rest.cc src/test/formatter.cc Conflicts: ceph-object-corpus src/mds/MDSDaemon.cc src/mds/MDSRank.cc src/rocksdb --- src/common/Formatter.cc | 753 ++++++++++++++++++++++++- src/common/Formatter.h | 123 ++++ src/common/JSONFormatter.cc | 226 -------- src/common/Makefile.am | 6 - src/common/TableFormatter.cc | 376 ------------ src/common/admin_socket.cc | 1 - src/mon/ConfigKeyService.cc | 1 - src/mon/Monitor.cc | 2 - src/mon/Paxos.cc | 1 - src/mon/Paxos.h | 3 - src/os/FileJournal.cc | 2 - src/os/FileStore.cc | 2 - src/os/FileStore.h | 2 - src/os/KeyValueStore.cc | 2 - src/os/KeyValueStore.h | 1 - src/os/MemStore.cc | 2 - src/osd/OSD.cc | 2 - src/osd/OSDMap.cc | 1 - src/rbd.cc | 2 - src/rgw/rgw_admin.cc | 2 - src/rgw/rgw_cors_s3.h | 1 - src/rgw/rgw_jsonparser.cc | 1 - src/rgw/rgw_log.cc | 1 - src/rgw/rgw_rest.cc | 2 - src/rgw/rgw_rest_s3.cc | 1 - src/rgw/rgw_swift.cc | 1 - src/rgw/rgw_swift_auth.cc | 1 - src/test/bench/small_io_bench.cc | 1 - src/test/bench/small_io_bench_dumb.cc | 1 - src/test/bench/small_io_bench_fs.cc | 1 - src/test/bench/small_io_bench_rbd.cc | 1 - src/test/bench/tp_bench.cc | 1 - src/test/common/test_tableformatter.cc | 2 +- src/test/crush/crush.cc | 1 - src/test/encoding/ceph_dencoder.cc | 1 - src/test/formatter.cc | 3 +- src/test/kv_store_bench.h | 1 - src/test/mon/test_mon_workloadgen.cc | 1 - src/test/test_rgw_admin_meta.cc | 2 - src/tools/ceph-client-debug.cc | 2 +- src/tools/ceph_monstore_tool.cc | 2 +- src/tools/ceph_objectstore_tool.cc | 1 - src/tools/cephfs/EventOutput.cc | 1 - src/tools/cephfs/JournalTool.cc | 1 - src/tools/cephfs/TableTool.cc | 2 - src/tools/rados/rados.cc | 2 - 46 files changed, 875 insertions(+), 670 deletions(-) delete mode 100644 src/common/JSONFormatter.cc delete mode 100644 src/common/TableFormatter.cc diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 8bbb25b6c4d89..345f95df66dca 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -18,10 +18,6 @@ #include "assert.h" #include "Formatter.h" -#include "JSONFormatter.h" -#include "TableFormatter.h" -#include "XMLFormatter.h" -#include "HTMLFormatter.h" #include "common/escape.h" #include @@ -122,4 +118,751 @@ void Formatter::dump_format_unquoted(const char *name, const char *fmt, ...) va_end(ap); } -} // namespace ceph +// ----------------------- + +JSONFormatter::JSONFormatter(bool p) +: m_pretty(p), m_is_pending_string(false) +{ + reset(); +} + +void JSONFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + os << m_ss.str(); + if (m_pretty) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void JSONFormatter::reset() +{ + m_stack.clear(); + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); +} + +void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) +{ + if (entry.size) { + if (m_pretty) { + m_ss << ",\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } else { + m_ss << ","; + } + } else if (m_pretty) { + m_ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } + if (m_pretty && entry.is_array) + m_ss << " "; +} + +void JSONFormatter::print_quoted_string(const std::string& s) +{ + int len = escape_json_attr_len(s.c_str(), s.size()); + char escaped[len]; + escape_json_attr(s.c_str(), s.size(), escaped); + m_ss << '\"' << escaped << '\"'; +} + +void JSONFormatter::print_name(const char *name) +{ + finish_pending_string(); + if (m_stack.empty()) + return; + struct json_formatter_stack_entry_d& entry = m_stack.back(); + print_comma(entry); + if (!entry.is_array) { + if (m_pretty) { + m_ss << " "; + } + m_ss << "\"" << name << "\""; + if (m_pretty) + m_ss << ": "; + else + m_ss << ':'; + } + ++entry.size; +} + +void JSONFormatter::open_section(const char *name, bool is_array) +{ + print_name(name); + if (is_array) + m_ss << '['; + else + m_ss << '{'; + + json_formatter_stack_entry_d n; + n.is_array = is_array; + m_stack.push_back(n); +} + +void JSONFormatter::open_array_section(const char *name) +{ + open_section(name, true); +} + +void JSONFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + std::ostringstream oss; + oss << name << " " << ns; + open_section(oss.str().c_str(), true); +} + +void JSONFormatter::open_object_section(const char *name) +{ + open_section(name, false); +} + +void JSONFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + std::ostringstream oss; + oss << name << " " << ns; + open_section(oss.str().c_str(), false); +} + +void JSONFormatter::close_section() +{ + assert(!m_stack.empty()); + finish_pending_string(); + + struct json_formatter_stack_entry_d& entry = m_stack.back(); + if (m_pretty && entry.size) { + m_ss << "\n"; + for (unsigned i = 1; i < m_stack.size(); i++) + m_ss << " "; + } + m_ss << (entry.is_array ? ']' : '}'); + m_stack.pop_back(); +} + +void JSONFormatter::finish_pending_string() +{ + if (m_is_pending_string) { + print_quoted_string(m_pending_string.str()); + m_pending_string.str(std::string()); + m_is_pending_string = false; + } +} + +void JSONFormatter::dump_unsigned(const char *name, uint64_t u) +{ + print_name(name); + m_ss << u; +} + +void JSONFormatter::dump_int(const char *name, int64_t s) +{ + print_name(name); + m_ss << s; +} + +void JSONFormatter::dump_float(const char *name, double d) +{ + print_name(name); + char foo[30]; + snprintf(foo, sizeof(foo), "%lf", d); + m_ss << foo; +} + +void JSONFormatter::dump_string(const char *name, const std::string& s) +{ + print_name(name); + print_quoted_string(s); +} + +std::ostream& JSONFormatter::dump_stream(const char *name) +{ + print_name(name); + m_is_pending_string = true; + return m_pending_string; +} + +void JSONFormatter::dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + print_name(name); + if (quoted) { + print_quoted_string(std::string(buf)); + } else { + m_ss << std::string(buf); + } +} + +int JSONFormatter::get_len() const +{ + return m_ss.str().size(); +} + +void JSONFormatter::write_raw_data(const char *data) +{ + m_ss << data; +} + +const char *XMLFormatter::XML_1_DTD = + ""; + +XMLFormatter::XMLFormatter(bool pretty) +: m_pretty(pretty) +{ + reset(); +} + +void XMLFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + os << m_ss.str(); + if (m_pretty) + os << "\n"; + m_ss.clear(); + m_ss.str(""); +} + +void XMLFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_pending_string.clear(); + m_pending_string.str(""); + m_sections.clear(); + m_pending_string_name.clear(); +} + +void XMLFormatter::open_object_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +void XMLFormatter::open_array_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void XMLFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, &attrs); +} + +void XMLFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, ns, NULL); +} + +void XMLFormatter::close_section() +{ + assert(!m_sections.empty()); + finish_pending_string(); + + std::string section = m_sections.back(); + m_sections.pop_back(); + print_spaces(); + m_ss << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_unsigned(const char *name, uint64_t u) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << u << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_int(const char *name, int64_t u) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << u << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_float(const char *name, double d) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << d << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_string(const char *name, const std::string& s) +{ + std::string e(name); + print_spaces(); + m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << ""; + if (m_pretty) + m_ss << "\n"; +} + +void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +{ + std::string e(name); + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + print_spaces(); + m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << ""; + if (m_pretty) + m_ss << "\n"; +} + +std::ostream& XMLFormatter::dump_stream(const char *name) +{ + print_spaces(); + m_pending_string_name = name; + m_ss << "<" << m_pending_string_name << ">"; + return m_pending_string; +} + +void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + std::string e(name); + print_spaces(); + if (ns) { + m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; + } else { + m_ss << "<" << e << ">" << escape_xml_str(buf) << ""; + } + + if (m_pretty) + m_ss << "\n"; +} + +int XMLFormatter::get_len() const +{ + return m_ss.str().size(); +} + +void XMLFormatter::write_raw_data(const char *data) +{ + m_ss << data; +} + +void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) +{ + std::stringstream attrs_ss; + + for (std::list >::const_iterator iter = attrs->attrs.begin(); + iter != attrs->attrs.end(); ++iter) { + std::pair p = *iter; + attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = attrs_ss.str(); +} + +void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) +{ + print_spaces(); + std::string attrs_str; + + if (attrs) { + get_attrs_str(attrs, attrs_str); + } + + if (ns) { + m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">"; + } else { + m_ss << "<" << name << attrs_str << ">"; + } + if (m_pretty) + m_ss << "\n"; + m_sections.push_back(name); +} + +void XMLFormatter::finish_pending_string() +{ + if (!m_pending_string_name.empty()) { + m_ss << escape_xml_str(m_pending_string.str().c_str()) + << ""; + m_pending_string_name.clear(); + m_pending_string.str(std::string()); + if (m_pretty) { + m_ss << "\n"; + } + } +} + +void XMLFormatter::print_spaces() +{ + finish_pending_string(); + if (m_pretty) { + std::string spaces(m_sections.size(), ' '); + m_ss << spaces; + } +} + +std::string XMLFormatter::escape_xml_str(const char *str) +{ + int len = escape_xml_attr_len(str); + std::vector escaped(len, '\0'); + escape_xml_attr(str, &escaped[0]); + return std::string(&escaped[0]); +} + +TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) +{ + reset(); +} + +void TableFormatter::flush(std::ostream& os) +{ + finish_pending_string(); + std::vector column_size = m_column_size; + std::vector column_name = m_column_name; + + std::set need_header_set; + + // auto-sizing columns + for (size_t i = 0; i < m_vec.size(); i++) { + for (size_t j = 0; j < m_vec[i].size(); j++) { + column_size.resize(m_vec[i].size()); + column_name.resize(m_vec[i].size()); + if (i > 0) { + if (m_vec[i - 1][j] != m_vec[i][j]) { + // changing row labels require to show the header + need_header_set.insert(i); + column_name[i] = m_vec[i][j].first; + } + } else { + column_name[i] = m_vec[i][j].first; + } + + if (m_vec[i][j].second.length() > column_size[j]) + column_size[j] = m_vec[i][j].second.length(); + if (m_vec[i][j].first.length() > column_size[j]) + column_size[j] = m_vec[i][j].first.length(); + } + } + + bool need_header = false; + if ((column_size.size() == m_column_size.size())) { + for (size_t i = 0; i < column_size.size(); i++) { + if (column_size[i] != m_column_size[i]) { + need_header = true; + break; + } + } + } else { + need_header = true; + } + + if (need_header) { + // first row always needs a header if there wasn't one before + need_header_set.insert(0); + } + + m_column_size = column_size; + for (size_t i = 0; i < m_vec.size(); i++) { + if (i == 0) { + if (need_header_set.count(i)) { + // print the header + if (!m_keyval) { + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + os << "|"; + + for (size_t j = 0; j < m_vec[i].size(); j++) { + os << " "; + std::stringstream fs; + fs << boost::format("%%-%is") % (m_column_size[j] + 2); + os << boost::format(fs.str()) % m_vec[i][j].first; + os << "|"; + } + os << "\n"; + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + } + // print body + if (!m_keyval) + os << "|"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + if (!m_keyval) + os << " "; + std::stringstream fs; + + if (m_keyval) { + os << "key::"; + os << m_vec[i][j].first; + os << "="; + os << "\""; + os << m_vec[i][j].second; + os << "\" "; + } else { + fs << boost::format("%%-%is") % (m_column_size[j] + 2); + os << boost::format(fs.str()) % m_vec[i][j].second; + os << "|"; + } + } + + os << "\n"; + if (!m_keyval) { + if (i == (m_vec.size() - 1)) { + // print trailer + os << "+"; + for (size_t j = 0; j < m_vec[i].size(); j++) { + for (size_t v = 0; v < m_column_size[j] + 3; v++) + os << "-"; + os << "+"; + } + os << "\n"; + } + } + m_vec[i].clear(); + } + m_vec.clear(); +} + +void TableFormatter::reset() +{ + m_ss.clear(); + m_ss.str(""); + m_section_cnt.clear(); + m_column_size.clear(); + m_section_open = 0; +} + +void TableFormatter::open_object_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_object_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section(const char *name) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_array_section_in_ns(const char *name, const char *ns) +{ + open_section_in_ns(name, NULL, NULL); +} + +void TableFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) +{ + m_section.push_back(name); + m_section_open++; +} + +void TableFormatter::close_section() +{ + // + m_section_open--; + if (m_section.size()) { + m_section_cnt[m_section.back()] = 0; + m_section.pop_back(); + } +} + +size_t TableFormatter::m_vec_index(const char *name) +{ + std::string key(name); + + size_t i = m_vec.size(); + if (i) + i--; + + // make sure there are vectors to push back key/val pairs + if (!m_vec.size()) + m_vec.resize(1); + + if (m_vec.size()) { + if (m_vec[i].size()) { + if (m_vec[i][0].first == key) { + // start a new column if a key is repeated + m_vec.resize(m_vec.size() + 1); + i++; + } + } + } + + return i; +} + +std::string TableFormatter::get_section_name(const char* name) +{ + std::string t_name = name; + for (size_t i = 0; i < m_section.size(); i++) { + t_name.insert(0, ":"); + t_name.insert(0, m_section[i]); + } + if (m_section_open) { + std::stringstream lss; + lss << t_name; + lss << "["; + lss << m_section_cnt[t_name]++; + lss << "]"; + return lss.str(); + } else { + return t_name; + } +} + +void TableFormatter::dump_unsigned(const char *name, uint64_t u) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << u; + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_int(const char *name, int64_t u) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << u; + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_float(const char *name, double d) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << d; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_string(const char *name, const std::string& s) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + m_ss << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +{ + finish_pending_string(); + size_t i = m_vec_index(name); + + std::string attrs_str; + get_attrs_str(&attrs, attrs_str); + m_ss << attrs_str << s; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +void TableFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) +{ + finish_pending_string(); + char buf[LARGE_SIZE]; + vsnprintf(buf, LARGE_SIZE, fmt, ap); + + size_t i = m_vec_index(name); + if (ns) { + m_ss << ns << "." << buf; + } else + m_ss << buf; + + m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); + m_ss.clear(); + m_ss.str(""); +} + +std::ostream& TableFormatter::dump_stream(const char *name) +{ + finish_pending_string(); + // we don't support this + m_pending_name = name; + return m_ss; +} + +int TableFormatter::get_len() const +{ + // we don't know the size until flush is called + return 0; +} + +void TableFormatter::write_raw_data(const char *data) { + // not supported +} + +void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) +{ + std::stringstream attrs_ss; + + for (std::list >::const_iterator iter = attrs->attrs.begin(); + iter != attrs->attrs.end(); ++iter) { + std::pair p = *iter; + attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; + } + + attrs_str = attrs_ss.str(); +} + +void TableFormatter::finish_pending_string() +{ + if (m_pending_name.length()) { + std::string ss = m_ss.str(); + m_ss.clear(); + m_ss.str(""); + std::string pending_name = m_pending_name; + m_pending_name = ""; + dump_string(pending_name.c_str(), ss); + } +} +} + diff --git a/src/common/Formatter.h b/src/common/Formatter.h index 43d521d10dc51..aead9c26edb33 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -89,5 +89,128 @@ namespace ceph { } }; + class JSONFormatter : public Formatter { + public: + JSONFormatter(bool p = false); + + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); + + private: + + struct json_formatter_stack_entry_d { + int size; + bool is_array; + json_formatter_stack_entry_d() : size(0), is_array(false) { } + }; + + bool m_pretty; + void open_section(const char *name, bool is_array); + void print_quoted_string(const std::string& s); + void print_name(const char *name); + void print_comma(json_formatter_stack_entry_d& entry); + void finish_pending_string(); + + std::stringstream m_ss, m_pending_string; + std::list m_stack; + bool m_is_pending_string; + }; + + class XMLFormatter : public Formatter { + public: + static const char *XML_1_DTD; + XMLFormatter(bool pretty = false); + + void flush(std::ostream& os); + void reset(); + void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + std::ostream& dump_stream(const char *name); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + int get_len() const; + void write_raw_data(const char *data); + + /* with attrs */ + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + void finish_pending_string(); + void print_spaces(); + static std::string escape_xml_str(const char *str); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + std::stringstream m_ss, m_pending_string; + std::deque m_sections; + bool m_pretty; + std::string m_pending_string_name; + }; + + class TableFormatter : public Formatter { + public: + TableFormatter(bool keyval = false); + + void flush(std::ostream& os); + void reset(); + virtual void open_array_section(const char *name); + void open_array_section_in_ns(const char *name, const char *ns); + void open_object_section(const char *name); + void open_object_section_in_ns(const char *name, const char *ns); + + void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); + void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); + + void close_section(); + void dump_unsigned(const char *name, uint64_t u); + void dump_int(const char *name, int64_t u); + void dump_float(const char *name, double d); + void dump_string(const char *name, const std::string& s); + void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); + void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); + std::ostream& dump_stream(const char *name); + + int get_len() const; + void write_raw_data(const char *data); + void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); + + private: + void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); + std::vector< std::vector > > m_vec; + std::stringstream m_ss; + size_t m_vec_index(const char* name); + std::string get_section_name(const char* name); + void finish_pending_string(); + std::string m_pending_name; + bool m_keyval; + + int m_section_open; + std::vector< std::string > m_section; + std::map m_section_cnt; + std::vector m_column_size; + std::vector< std::string > m_column_name; + }; + + } #endif diff --git a/src/common/JSONFormatter.cc b/src/common/JSONFormatter.cc deleted file mode 100644 index 8bf5007ba7fbf..0000000000000 --- a/src/common/JSONFormatter.cc +++ /dev/null @@ -1,226 +0,0 @@ -// -*- 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) 2011 New Dream Network - * - * 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. - * - */ - -#define LARGE_SIZE 1024 - -#include "include/int_types.h" - -#include "assert.h" -#include "Formatter.h" -#include "JSONFormatter.h" -#include "common/escape.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// ----------------------- -namespace ceph { - -JSONFormatter::JSONFormatter(bool p) -: m_pretty(p), m_is_pending_string(false) -{ - reset(); -} - -void JSONFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - os << m_ss.str(); - if (m_pretty) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void JSONFormatter::reset() -{ - m_stack.clear(); - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); -} - -void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) -{ - if (entry.size) { - if (m_pretty) { - m_ss << ",\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } else { - m_ss << ","; - } - } else if (m_pretty) { - m_ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } - if (m_pretty && entry.is_array) - m_ss << " "; -} - -void JSONFormatter::print_quoted_string(const std::string& s) -{ - int len = escape_json_attr_len(s.c_str(), s.size()); - char escaped[len]; - escape_json_attr(s.c_str(), s.size(), escaped); - m_ss << '\"' << escaped << '\"'; -} - -void JSONFormatter::print_name(const char *name) -{ - finish_pending_string(); - if (m_stack.empty()) - return; - struct json_formatter_stack_entry_d& entry = m_stack.back(); - print_comma(entry); - if (!entry.is_array) { - if (m_pretty) { - m_ss << " "; - } - m_ss << "\"" << name << "\""; - if (m_pretty) - m_ss << ": "; - else - m_ss << ':'; - } - ++entry.size; -} - -void JSONFormatter::open_section(const char *name, bool is_array) -{ - print_name(name); - if (is_array) - m_ss << '['; - else - m_ss << '{'; - - json_formatter_stack_entry_d n; - n.is_array = is_array; - m_stack.push_back(n); -} - -void JSONFormatter::open_array_section(const char *name) -{ - open_section(name, true); -} - -void JSONFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - std::ostringstream oss; - oss << name << " " << ns; - open_section(oss.str().c_str(), true); -} - -void JSONFormatter::open_object_section(const char *name) -{ - open_section(name, false); -} - -void JSONFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - std::ostringstream oss; - oss << name << " " << ns; - open_section(oss.str().c_str(), false); -} - -void JSONFormatter::close_section() -{ - assert(!m_stack.empty()); - finish_pending_string(); - - struct json_formatter_stack_entry_d& entry = m_stack.back(); - if (m_pretty && entry.size) { - m_ss << "\n"; - for (unsigned i = 1; i < m_stack.size(); i++) - m_ss << " "; - } - m_ss << (entry.is_array ? ']' : '}'); - m_stack.pop_back(); -} - -void JSONFormatter::finish_pending_string() -{ - if (m_is_pending_string) { - print_quoted_string(m_pending_string.str()); - m_pending_string.str(std::string()); - m_is_pending_string = false; - } -} - -void JSONFormatter::dump_unsigned(const char *name, uint64_t u) -{ - print_name(name); - m_ss << u; -} - -void JSONFormatter::dump_int(const char *name, int64_t s) -{ - print_name(name); - m_ss << s; -} - -void JSONFormatter::dump_float(const char *name, double d) -{ - print_name(name); - char foo[30]; - snprintf(foo, sizeof(foo), "%lf", d); - m_ss << foo; -} - -void JSONFormatter::dump_string(const char *name, const std::string& s) -{ - print_name(name); - print_quoted_string(s); -} - -std::ostream& JSONFormatter::dump_stream(const char *name) -{ - print_name(name); - m_is_pending_string = true; - return m_pending_string; -} - -void JSONFormatter::dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - print_name(name); - if (quoted) { - print_quoted_string(std::string(buf)); - } else { - m_ss << std::string(buf); - } -} - -int JSONFormatter::get_len() const -{ - return m_ss.str().size(); -} - -void JSONFormatter::write_raw_data(const char *data) -{ - m_ss << data; -} - -} // namespace ceph diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 6f1f11c3c7500..81daa4ab18e78 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -45,10 +45,7 @@ libcommon_internal_la_SOURCES = \ common/simple_spin.cc \ common/Thread.cc \ common/Formatter.cc \ - common/XMLFormatter.cc \ common/HTMLFormatter.cc \ - common/JSONFormatter.cc \ - common/TableFormatter.cc \ common/HeartbeatMap.cc \ common/config.cc \ common/utf8.c \ @@ -182,9 +179,6 @@ noinst_HEADERS += \ common/DecayCounter.h \ common/Finisher.h \ common/Formatter.h \ - common/JSONFormatter.h \ - common/TableFormatter.h \ - common/XMLFormatter.h \ common/HTMLFormatter.h \ common/perf_counters.h \ common/OutputDataSocket.h \ diff --git a/src/common/TableFormatter.cc b/src/common/TableFormatter.cc deleted file mode 100644 index 4be4e39077b78..0000000000000 --- a/src/common/TableFormatter.cc +++ /dev/null @@ -1,376 +0,0 @@ -// -*- 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) 2011 New Dream Network - * - * 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. - * - */ - -#define LARGE_SIZE 1024 - -#include "include/int_types.h" - -#include "assert.h" -#include "Formatter.h" -#include "TableFormatter.h" -#include "common/escape.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// ----------------------- -namespace ceph { -TableFormatter::TableFormatter(bool keyval) : m_keyval(keyval) -{ - reset(); -} - -void TableFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - std::vector column_size = m_column_size; - std::vector column_name = m_column_name; - - std::set need_header_set; - - // auto-sizing columns - for (size_t i = 0; i < m_vec.size(); i++) { - for (size_t j = 0; j < m_vec[i].size(); j++) { - column_size.resize(m_vec[i].size()); - column_name.resize(m_vec[i].size()); - if (i > 0) { - if (m_vec[i - 1][j] != m_vec[i][j]) { - // changing row labels require to show the header - need_header_set.insert(i); - column_name[i] = m_vec[i][j].first; - } - } else { - column_name[i] = m_vec[i][j].first; - } - - if (m_vec[i][j].second.length() > column_size[j]) - column_size[j] = m_vec[i][j].second.length(); - if (m_vec[i][j].first.length() > column_size[j]) - column_size[j] = m_vec[i][j].first.length(); - } - } - - bool need_header = false; - if ((column_size.size() == m_column_size.size())) { - for (size_t i = 0; i < column_size.size(); i++) { - if (column_size[i] != m_column_size[i]) { - need_header = true; - break; - } - } - } else { - need_header = true; - } - - if (need_header) { - // first row always needs a header if there wasn't one before - need_header_set.insert(0); - } - - m_column_size = column_size; - for (size_t i = 0; i < m_vec.size(); i++) { - if (i == 0) { - if (need_header_set.count(i)) { - // print the header - if (!m_keyval) { - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - os << "|"; - - for (size_t j = 0; j < m_vec[i].size(); j++) { - os << " "; - std::stringstream fs; - fs << boost::format("%%-%is") % (m_column_size[j] + 2); - os << boost::format(fs.str()) % m_vec[i][j].first; - os << "|"; - } - os << "\n"; - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - } - // print body - if (!m_keyval) - os << "|"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - if (!m_keyval) - os << " "; - std::stringstream fs; - - if (m_keyval) { - os << "key::"; - os << m_vec[i][j].first; - os << "="; - os << "\""; - os << m_vec[i][j].second; - os << "\" "; - } else { - fs << boost::format("%%-%is") % (m_column_size[j] + 2); - os << boost::format(fs.str()) % m_vec[i][j].second; - os << "|"; - } - } - - os << "\n"; - if (!m_keyval) { - if (i == (m_vec.size() - 1)) { - // print trailer - os << "+"; - for (size_t j = 0; j < m_vec[i].size(); j++) { - for (size_t v = 0; v < m_column_size[j] + 3; v++) - os << "-"; - os << "+"; - } - os << "\n"; - } - } - m_vec[i].clear(); - } - m_vec.clear(); -} - -void TableFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_section_cnt.clear(); - m_column_size.clear(); - m_section_open = 0; -} - -void TableFormatter::open_object_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, NULL, NULL); -} - -void TableFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) -{ - m_section.push_back(name); - m_section_open++; -} - -void TableFormatter::close_section() -{ - // - m_section_open--; - if (m_section.size()) { - m_section_cnt[m_section.back()] = 0; - m_section.pop_back(); - } -} - -size_t TableFormatter::m_vec_index(const char *name) -{ - std::string key(name); - - size_t i = m_vec.size(); - if (i) - i--; - - // make sure there are vectors to push back key/val pairs - if (!m_vec.size()) - m_vec.resize(1); - - if (m_vec.size()) { - if (m_vec[i].size()) { - if (m_vec[i][0].first == key) { - // start a new column if a key is repeated - m_vec.resize(m_vec.size() + 1); - i++; - } - } - } - - return i; -} - -std::string TableFormatter::get_section_name(const char* name) -{ - std::string t_name = name; - for (size_t i = 0; i < m_section.size(); i++) { - t_name.insert(0, ":"); - t_name.insert(0, m_section[i]); - } - if (m_section_open) { - std::stringstream lss; - lss << t_name; - lss << "["; - lss << m_section_cnt[t_name]++; - lss << "]"; - return lss.str(); - } else { - return t_name; - } -} - -void TableFormatter::dump_unsigned(const char *name, uint64_t u) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << u; - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_int(const char *name, int64_t u) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << u; - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_float(const char *name, double d) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << d; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_string(const char *name, const std::string& s) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - m_ss << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) -{ - finish_pending_string(); - size_t i = m_vec_index(name); - - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - m_ss << attrs_str << s; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -void TableFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - finish_pending_string(); - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - size_t i = m_vec_index(name); - if (ns) { - m_ss << ns << "." << buf; - } else - m_ss << buf; - - m_vec[i].push_back(std::make_pair(get_section_name(name), m_ss.str())); - m_ss.clear(); - m_ss.str(""); -} - -std::ostream& TableFormatter::dump_stream(const char *name) -{ - finish_pending_string(); - // we don't support this - m_pending_name = name; - return m_ss; -} - -int TableFormatter::get_len() const -{ - // we don't know the size until flush is called - return 0; -} - -void TableFormatter::write_raw_data(const char *data) { - // not supported -} - -void TableFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) -{ - std::stringstream attrs_ss; - - for (std::list >::const_iterator iter = attrs->attrs.begin(); - iter != attrs->attrs.end(); ++iter) { - std::pair p = *iter; - attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = attrs_ss.str(); -} - -void TableFormatter::finish_pending_string() -{ - if (m_pending_name.length()) { - std::string ss = m_ss.str(); - m_ss.clear(); - m_ss.str(""); - std::string pending_name = m_pending_name; - m_pending_name = ""; - dump_string(pending_name.c_str(), ss); - } -} - -} // namespace ceph diff --git a/src/common/admin_socket.cc b/src/common/admin_socket.cc index c3425d8945225..95a48b3ec129b 100644 --- a/src/common/admin_socket.cc +++ b/src/common/admin_socket.cc @@ -26,7 +26,6 @@ #include "common/safe_io.h" #include "common/version.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include #include diff --git a/src/mon/ConfigKeyService.cc b/src/mon/ConfigKeyService.cc index 790102e0f97ba..97126ed0d1f0e 100644 --- a/src/mon/ConfigKeyService.cc +++ b/src/mon/ConfigKeyService.cc @@ -24,7 +24,6 @@ #include "common/config.h" #include "common/cmdparse.h" #include "common/errno.h" -#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_mon #undef dout_prefix diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 479804bc14adc..4a34283e0d9d6 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -61,8 +61,6 @@ #include "common/errno.h" #include "common/perf_counters.h" #include "common/admin_socket.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "include/color.h" #include "include/ceph_fs.h" diff --git a/src/mon/Paxos.cc b/src/mon/Paxos.cc index 1eddd6a2ccc97..297ea17ce075a 100644 --- a/src/mon/Paxos.cc +++ b/src/mon/Paxos.cc @@ -23,7 +23,6 @@ #include "include/assert.h" #include "include/stringify.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_paxos #undef dout_prefix diff --git a/src/mon/Paxos.h b/src/mon/Paxos.h index 0c69f2b204619..457c8af1d267f 100644 --- a/src/mon/Paxos.h +++ b/src/mon/Paxos.h @@ -121,9 +121,6 @@ e 12v #include "common/perf_counters.h" #include -#include "common/Formatter.h" -#include "common/JSONFormatter.h" - #include "MonitorDBStore.h" class Monitor; diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 3c930819b0ce1..c6bb6f2c0755d 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -34,8 +34,6 @@ #include "common/blkdev.h" #include "common/linux_version.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #define dout_subsys ceph_subsys_journal #undef dout_prefix diff --git a/src/os/FileStore.cc b/src/os/FileStore.cc index b06ddea921f21..4f0772e9b646e 100644 --- a/src/os/FileStore.cc +++ b/src/os/FileStore.cc @@ -66,8 +66,6 @@ #include "common/perf_counters.h" #include "common/sync_filesystem.h" #include "common/fd.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "HashIndex.h" #include "DBObjectMap.h" #include "KeyValueDB.h" diff --git a/src/os/FileStore.h b/src/os/FileStore.h index 11a4401233194..a9291b743c9bc 100644 --- a/src/os/FileStore.h +++ b/src/os/FileStore.h @@ -33,8 +33,6 @@ using namespace std; #include "common/Timer.h" #include "common/WorkQueue.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/Mutex.h" #include "HashIndex.h" diff --git a/src/os/KeyValueStore.cc b/src/os/KeyValueStore.cc index 64fff67477ac0..1881f2dcc17ac 100644 --- a/src/os/KeyValueStore.cc +++ b/src/os/KeyValueStore.cc @@ -48,8 +48,6 @@ #include "common/safe_io.h" #include "common/perf_counters.h" #include "common/sync_filesystem.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #ifdef HAVE_KINETIC #include "KineticStore.h" diff --git a/src/os/KeyValueStore.h b/src/os/KeyValueStore.h index 2519fdf5dee15..ef3085fa0d95b 100644 --- a/src/os/KeyValueStore.h +++ b/src/os/KeyValueStore.h @@ -33,7 +33,6 @@ using namespace std; #include "common/WorkQueue.h" #include "common/Finisher.h" #include "common/fd.h" -#include "common/JSONFormatter.h" #include "common/Mutex.h" #include "GenericObjectMap.h" diff --git a/src/os/MemStore.cc b/src/os/MemStore.cc index 67a70ffa55284..a1e1b274ec0e9 100644 --- a/src/os/MemStore.cc +++ b/src/os/MemStore.cc @@ -26,8 +26,6 @@ #include "include/unordered_map.h" #include "include/memory.h" #include "common/errno.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "MemStore.h" #define dout_subsys ceph_subsys_filestore diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index d1e9cc8ec8f6c..e0c5b3d6b8b96 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -43,8 +43,6 @@ #include "common/ceph_argparse.h" #include "common/version.h" #include "common/io_priority.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "os/ObjectStore.h" diff --git a/src/osd/OSDMap.cc b/src/osd/OSDMap.cc index 54cf9215c402d..173b468b5b0ed 100644 --- a/src/osd/OSDMap.cc +++ b/src/osd/OSDMap.cc @@ -19,7 +19,6 @@ #include "common/config.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/TextTable.h" #include "include/ceph_features.h" #include "include/str_map.h" diff --git a/src/rbd.cc b/src/rbd.cc index 1a96177c832e1..6f5457d1461f9 100644 --- a/src/rbd.cc +++ b/src/rbd.cc @@ -51,8 +51,6 @@ #include "include/util.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" -#include "common/XMLFormatter.h" #include "common/Throttle.h" #if defined(__linux__) diff --git a/src/rgw/rgw_admin.cc b/src/rgw/rgw_admin.cc index d40700b1de9c9..45cb2e197eddc 100644 --- a/src/rgw/rgw_admin.cc +++ b/src/rgw/rgw_admin.cc @@ -15,8 +15,6 @@ using namespace std; #include "common/config.h" #include "common/ceph_argparse.h" #include "common/Formatter.h" -#include "common/XMLFormatter.h" -#include "common/JSONFormatter.h" #include "common/errno.h" #include "global/global_init.h" diff --git a/src/rgw/rgw_cors_s3.h b/src/rgw/rgw_cors_s3.h index 6cac6765a311d..0db03c3ea1420 100644 --- a/src/rgw/rgw_cors_s3.h +++ b/src/rgw/rgw_cors_s3.h @@ -22,7 +22,6 @@ #include #include -#include #include "rgw_xml.h" #include "rgw_cors.h" diff --git a/src/rgw/rgw_jsonparser.cc b/src/rgw/rgw_jsonparser.cc index 8531d866e7911..b4b709ce8c71f 100644 --- a/src/rgw/rgw_jsonparser.cc +++ b/src/rgw/rgw_jsonparser.cc @@ -10,7 +10,6 @@ #include "include/types.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/ceph_json.h" #include "rgw_common.h" diff --git a/src/rgw/rgw_log.cc b/src/rgw/rgw_log.cc index 4d362e26d5052..795d78787327e 100644 --- a/src/rgw/rgw_log.cc +++ b/src/rgw/rgw_log.cc @@ -6,7 +6,6 @@ #include "common/utf8.h" #include "common/OutputDataSocket.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "rgw_log.h" #include "rgw_acl.h" diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 9196a4fa6915e..2f328aad19dc1 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -5,8 +5,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" -#include "common/XMLFormatter.h" #include "common/HTMLFormatter.h" #include "common/utf8.h" #include "include/str_list.h" diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index cd21df5831923..7da0c7f8b37ec 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -6,7 +6,6 @@ #include "common/ceph_crypto.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/utf8.h" #include "common/ceph_json.h" diff --git a/src/rgw/rgw_swift.cc b/src/rgw/rgw_swift.cc index 06662da2b6a07..09fb9b7b92845 100644 --- a/src/rgw/rgw_swift.cc +++ b/src/rgw/rgw_swift.cc @@ -6,7 +6,6 @@ #include #include "common/ceph_json.h" -#include "common/JSONFormatter.h" #include "rgw_common.h" #include "rgw_swift.h" #include "rgw_swift_auth.h" diff --git a/src/rgw/rgw_swift_auth.cc b/src/rgw/rgw_swift_auth.cc index 5311002ff858b..3e94e63a162ba 100644 --- a/src/rgw/rgw_swift_auth.cc +++ b/src/rgw/rgw_swift_auth.cc @@ -6,7 +6,6 @@ #include "common/ceph_crypto.h" #include "common/Clock.h" -#include "common/JSONFormatter.h" #include "auth/Crypto.h" diff --git a/src/test/bench/small_io_bench.cc b/src/test/bench/small_io_bench.cc index 657d6d0624a1d..2b200279c7a4b 100644 --- a/src/test/bench/small_io_bench.cc +++ b/src/test/bench/small_io_bench.cc @@ -14,7 +14,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_dumb.cc b/src/test/bench/small_io_bench_dumb.cc index 913e8c0a1a333..c9d9f51a9db57 100644 --- a/src/test/bench/small_io_bench_dumb.cc +++ b/src/test/bench/small_io_bench_dumb.cc @@ -16,7 +16,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_fs.cc b/src/test/bench/small_io_bench_fs.cc index 31bb10e2470ec..f5845855a1d5f 100644 --- a/src/test/bench/small_io_bench_fs.cc +++ b/src/test/bench/small_io_bench_fs.cc @@ -14,7 +14,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/bench/small_io_bench_rbd.cc b/src/test/bench/small_io_bench_rbd.cc index 95193adf9b610..ba7071ed3833a 100644 --- a/src/test/bench/small_io_bench_rbd.cc +++ b/src/test/bench/small_io_bench_rbd.cc @@ -13,7 +13,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "bencher.h" #include "rbd_backend.h" diff --git a/src/test/bench/tp_bench.cc b/src/test/bench/tp_bench.cc index a1221997ca204..b9d5ff17c8f85 100644 --- a/src/test/bench/tp_bench.cc +++ b/src/test/bench/tp_bench.cc @@ -14,7 +14,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "bencher.h" #include "rados_backend.h" diff --git a/src/test/common/test_tableformatter.cc b/src/test/common/test_tableformatter.cc index c53b69f53652d..88648f01d73b5 100644 --- a/src/test/common/test_tableformatter.cc +++ b/src/test/common/test_tableformatter.cc @@ -1,6 +1,6 @@ #include "gtest/gtest.h" -#include "common/TableFormatter.h" +#include "common/Formatter.h" #include #include #include diff --git a/src/test/crush/crush.cc b/src/test/crush/crush.cc index 1fafbd337072e..c46fa87ab5409 100644 --- a/src/test/crush/crush.cc +++ b/src/test/crush/crush.cc @@ -13,7 +13,6 @@ #include "include/stringify.h" #include "common/ceph_argparse.h" -#include "common/JSONFormatter.h" #include "global/global_init.h" #include "global/global_context.h" diff --git a/src/test/encoding/ceph_dencoder.cc b/src/test/encoding/ceph_dencoder.cc index 7386a7d563010..7e1056503ce01 100644 --- a/src/test/encoding/ceph_dencoder.cc +++ b/src/test/encoding/ceph_dencoder.cc @@ -5,7 +5,6 @@ #include "include/ceph_features.h" #include "common/ceph_argparse.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/errno.h" #include "msg/Message.h" #include "include/assert.h" diff --git a/src/test/formatter.cc b/src/test/formatter.cc index cf1e412758a2b..3913cc6f15420 100644 --- a/src/test/formatter.cc +++ b/src/test/formatter.cc @@ -13,8 +13,7 @@ */ #include "test/unit.h" -#include "common/JSONFormatter.h" -#include "common/XMLFormatter.h" +#include "common/Formatter.h" #include "common/HTMLFormatter.h" #include diff --git a/src/test/kv_store_bench.h b/src/test/kv_store_bench.h index 9be1e31386b9c..d12c5e850c0b1 100644 --- a/src/test/kv_store_bench.h +++ b/src/test/kv_store_bench.h @@ -20,7 +20,6 @@ #include "global/global_context.h" #include "common/Mutex.h" #include "common/Cond.h" -#include "common/JSONFormatter.h" #include #include diff --git a/src/test/mon/test_mon_workloadgen.cc b/src/test/mon/test_mon_workloadgen.cc index 36e36ba6c95da..e18906d193148 100644 --- a/src/test/mon/test_mon_workloadgen.cc +++ b/src/test/mon/test_mon_workloadgen.cc @@ -51,7 +51,6 @@ #include "auth/AuthAuthorizeHandler.h" #include "include/uuid.h" #include "include/assert.h" -#include "common/JSONFormatter.h" #include "messages/MOSDBoot.h" #include "messages/MOSDAlive.h" diff --git a/src/test/test_rgw_admin_meta.cc b/src/test/test_rgw_admin_meta.cc index b2213fc2afa72..74bc8ed1ec867 100644 --- a/src/test/test_rgw_admin_meta.cc +++ b/src/test/test_rgw_admin_meta.cc @@ -30,8 +30,6 @@ extern "C"{ #include "common/code_environment.h" #include "common/ceph_argparse.h" #include "common/Finisher.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "global/global_init.h" #include "rgw/rgw_common.h" #include "rgw/rgw_rados.h" diff --git a/src/tools/ceph-client-debug.cc b/src/tools/ceph-client-debug.cc index 20948bc527c98..2ed93326b4433 100644 --- a/src/tools/ceph-client-debug.cc +++ b/src/tools/ceph-client-debug.cc @@ -15,7 +15,7 @@ #include "common/ceph_argparse.h" #include "global/global_init.h" -#include "common/JSONFormatter.h" +#include "common/Formatter.h" #include "common/debug.h" #include "common/errno.h" #include "client/Inode.h" diff --git a/src/tools/ceph_monstore_tool.cc b/src/tools/ceph_monstore_tool.cc index 9190d7c050504..744000eba872e 100644 --- a/src/tools/ceph_monstore_tool.cc +++ b/src/tools/ceph_monstore_tool.cc @@ -16,7 +16,7 @@ #include #include -#include "common/JSONFormatter.h" +#include "common/Formatter.h" #include "common/errno.h" #include "global/global_init.h" diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 9ad502bdef7ef..9e6894664ca8c 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -19,7 +19,6 @@ #include #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "common/errno.h" #include "common/ceph_argparse.h" diff --git a/src/tools/cephfs/EventOutput.cc b/src/tools/cephfs/EventOutput.cc index a273c511b5506..a93c099a918d1 100644 --- a/src/tools/cephfs/EventOutput.cc +++ b/src/tools/cephfs/EventOutput.cc @@ -16,7 +16,6 @@ #include #include "common/errno.h" -#include "common/JSONFormatter.h" #include "mds/mdstypes.h" #include "mds/events/EUpdate.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/JournalTool.cc b/src/tools/cephfs/JournalTool.cc index 360782c141eb4..6118320435948 100644 --- a/src/tools/cephfs/JournalTool.cc +++ b/src/tools/cephfs/JournalTool.cc @@ -16,7 +16,6 @@ #include "common/ceph_argparse.h" #include "common/errno.h" -#include "common/JSONFormatter.h" #include "osdc/Journaler.h" #include "mds/mdstypes.h" #include "mds/LogEvent.h" diff --git a/src/tools/cephfs/TableTool.cc b/src/tools/cephfs/TableTool.cc index 005d8b4c6000f..4b22de04f7231 100644 --- a/src/tools/cephfs/TableTool.cc +++ b/src/tools/cephfs/TableTool.cc @@ -14,8 +14,6 @@ #include "common/ceph_argparse.h" #include "common/errno.h" -#include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "mds/SessionMap.h" #include "mds/InoTable.h" diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index a727c162ae37c..4b96ac5ae4a10 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -26,8 +26,6 @@ using namespace librados; #include "common/debug.h" #include "common/errno.h" #include "common/Formatter.h" -#include "common/JSONFormatter.h" -#include "common/XMLFormatter.h" #include "common/obj_bencher.h" #include "mds/inode_backtrace.h" #include "auth/Crypto.h" From f52881ebf7c56f934e613c8263005a5fcd4064aa Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 3 Dec 2015 15:13:18 -0800 Subject: [PATCH 60/90] Undo constant renaming: RGW_REST_*->RGW_PROTO_*. For clarity, RGW_REST_* should be renamed to RGW_PROTO_* in future. For now, undo it to ease the merging speed for static-sites. Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_common.h --- src/rgw/rgw_common.h | 7 ++----- src/rgw/rgw_op.cc | 2 +- src/rgw/rgw_rest.cc | 18 +++++++++--------- src/rgw/rgw_rest_s3.cc | 4 ++-- src/rgw/rgw_rest_swift.cc | 2 +- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index d07f1de4ebbc4..477079a7cecd9 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -98,11 +98,8 @@ using ceph::crypto::MD5; #define RGW_REST_SWIFT 0x1 #define RGW_REST_SWIFT_AUTH 0x2 - -#define RGW_PROTO_SWIFT 0x1 -#define RGW_PROTO_SWIFT_AUTH 0x2 -#define RGW_PROTO_S3 0x4 -#define RGW_PROTO_WEBSITE 0x8 +#define RGW_REST_S3 0x4 +#define RGW_REST_WEBSITE 0x8 #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 4110f145116ad..005490dc67415 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3390,7 +3390,7 @@ void RGWListBucketMultiparts::execute() if (ret < 0) return; - if (s->prot_flags & RGW_PROTO_SWIFT) { + if (s->prot_flags & RGW_REST_SWIFT) { string path_args; path_args = s->info.args.get("path"); if (!path_args.empty()) { diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 2f328aad19dc1..6491cc6440ebd 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -311,7 +311,7 @@ void set_req_state_err(struct req_state *s, int err_no) err_no = -err_no; s->err.ret = -err_no; - if (s->prot_flags & RGW_PROTO_SWIFT) { + if (s->prot_flags & RGW_REST_SWIFT) { r = search_err(err_no, RGW_HTTP_SWIFT_ERRORS, ARRAY_LEN(RGW_HTTP_SWIFT_ERRORS)); if (r) { s->err.http_ret = r->http_ret; @@ -325,7 +325,7 @@ void set_req_state_err(struct req_state *s, int err_no) r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { - if (s->prot_flags & RGW_PROTO_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { + if (s->prot_flags & RGW_REST_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { // http_ret was custom set, so don't change it! } else { s->err.http_ret = r->http_ret; @@ -381,7 +381,7 @@ void dump_content_length(struct req_state *s, uint64_t len) void dump_etag(struct req_state *s, const char *etag) { int r; - if (s->prot_flags & RGW_PROTO_SWIFT) { + if (s->prot_flags & RGW_REST_SWIFT) { r = s->cio->print("etag: %s\r\n", etag); } else @@ -546,7 +546,7 @@ void dump_start(struct req_state *s) void dump_trans_id(req_state *s) { - if (s->prot_flags & RGW_PROTO_SWIFT) { + if (s->prot_flags & RGW_REST_SWIFT) { s->cio->print("X-Trans-Id: %s\r\n", s->trans_id.c_str()); } else { @@ -624,7 +624,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const delete [] allowed_origins; - if (s->prot_flags & RGW_PROTO_SWIFT && !content_type) { + if (s->prot_flags & RGW_REST_SWIFT && !content_type) { force_content_type = true; } @@ -645,7 +645,7 @@ void end_header(struct req_state *s, RGWOp *op, const char *content_type, const ctype = "text/plain"; break; } - if (s->prot_flags & RGW_PROTO_SWIFT) + if (s->prot_flags & RGW_REST_SWIFT) ctype.append("; charset=utf-8"); content_type = ctype.c_str(); } @@ -1299,7 +1299,7 @@ int RGWHandler_ObjStore::allocate_formatter(struct req_state *s, int default_typ s->formatter = new JSONFormatter(false); break; case RGW_FORMAT_HTML: - s->formatter = new HTMLFormatter(s->prot_flags & RGW_PROTO_WEBSITE); + s->formatter = new HTMLFormatter(s->prot_flags & RGW_REST_WEBSITE); break; default: return -EINVAL; @@ -1527,7 +1527,7 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? domain = s3website_domain; subdomain = s3website_subdomain; - s->prot_flags |= RGW_PROTO_WEBSITE; + s->prot_flags |= RGW_REST_WEBSITE; } } @@ -1557,7 +1557,7 @@ int RGWREST::preprocess(struct req_state *s, RGWClientIO *cio) in_hosted_domain = true; // TODO: should hostnames be a strict superset of hostnames_s3website? domain = s3website_domain; subdomain = s3website_subdomain; - s->prot_flags |= RGW_PROTO_WEBSITE; + s->prot_flags |= RGW_REST_WEBSITE; } } diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 7da0c7f8b37ec..41cd33f2e654a 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3092,7 +3092,7 @@ int RGWHandler_Auth_S3::init(RGWRados *store, struct req_state *state, RGWClient RGWHandler *RGWRESTMgr_S3::get_handler(struct req_state *s) { - bool is_s3website = enable_s3website && (s->prot_flags & RGW_PROTO_WEBSITE); + bool is_s3website = enable_s3website && (s->prot_flags & RGW_REST_WEBSITE); int ret = RGWHandler_ObjStore_S3::init_from_header(s, is_s3website ? RGW_FORMAT_HTML : RGW_FORMAT_XML, false); if (ret < 0) return NULL; @@ -3125,7 +3125,7 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { *new_op = op; ldout(s->cct, 10) << __func__ << "Starting retarget" << dendl; - if (!(s->prot_flags & RGW_PROTO_WEBSITE)) + if (!(s->prot_flags & RGW_REST_WEBSITE)) return 0; RGWObjectCtx& obj_ctx = *static_cast(s->obj_ctx); diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index 9d700d28fe671..bcbd45002c896 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -955,7 +955,7 @@ int RGWHandler_ObjStore_SWIFT::init_from_header(struct req_state *s) string req; string first; - s->prot_flags |= RGW_PROTO_SWIFT; + s->prot_flags |= RGW_REST_SWIFT; const char *req_name = s->decoded_uri.c_str(); const char *p; From 97675a1ffda38831e7d50592d346c15981e19e7f Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 3 Dec 2015 15:15:10 -0800 Subject: [PATCH 61/90] undo: clean up dead enum RGWEndpointType. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_op.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 8337754d255cc..45acb270a2b28 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -64,14 +64,6 @@ enum RGWOpType { RGW_OP_DELETE_MULTI_OBJ, }; -enum RGWEndpointType { - RGW_ENDPOINT_REST, - RGW_ENDPOINT_REST_SWIFT, - RGW_ENDPOINT_REST_SWIFT_AUTH, - RGW_ENDPOINT_REST_S3, - RGW_ENDPOINT_WEBSITE, -}; - /** * Provide the base class for all ops. */ From 9bcc07d3cd02b255d6ca1603451d740069d3f2f4 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 3 Dec 2015 15:43:01 -0800 Subject: [PATCH 62/90] cleanup: remove dead function. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_op.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 45acb270a2b28..6753b6c6abdeb 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -112,9 +112,6 @@ class RGWOp { virtual RGWOpType get_type() { return RGW_OP_UNKNOWN; } virtual uint32_t op_mask() { return 0; } - virtual bool supports_website() { - return false; - } virtual int error_handler(int err_no, string *error_content); }; @@ -184,9 +181,6 @@ class RGWGetObj : public RGWOp { virtual RGWOpType get_type() { return RGW_OP_GET_OBJ; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } virtual bool need_object_expiration() { return false; } - virtual bool supports_website() { - return true; - } }; class RGWGetObj_CB : public RGWGetDataCB @@ -230,9 +224,6 @@ class RGWListBuckets : public RGWOp { virtual const string name() { return "list_buckets"; } virtual RGWOpType get_type() { return RGW_OP_LIST_BUCKETS; } virtual uint32_t op_mask() { return RGW_OP_TYPE_READ; } - virtual bool supports_website() { - return true; - } }; class RGWStatAccount : public RGWOp { From 9f063caad7ff319fd9d8a783d6d7ccea4a32fdc3 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 3 Dec 2015 16:46:37 -0800 Subject: [PATCH 63/90] Copyright: add copyright blocks to new files, and update files with existing ones for website changes. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_common.h | 1 + src/rgw/rgw_rest_s3website.h | 13 +++++++++++++ src/rgw/rgw_website.cc | 14 ++++++++++++++ src/rgw/rgw_website.h | 14 ++++++++++++++ src/rgw/rgw_xml_enc.cc | 13 ++++++++++++- 5 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 477079a7cecd9..312251c6763ec 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -4,6 +4,7 @@ * Ceph - scalable distributed file system * * Copyright (C) 2004-2009 Sage Weil + * Copyright (C) 2015 Yehuda Sadeh * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 24292ca819170..18f00ee99e55d 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -1,3 +1,16 @@ +// -*- 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) 2015 Robin H. Johnson + * + * 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. + * + */ #ifndef CEPH_RGW_REST_S3WEBSITE_H #define CEPH_RGW_REST_S3WEBSITE_H diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index 14c2af926fd79..eee8977a86f94 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -1,3 +1,17 @@ +// -*- 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) 2015 Yehuda Sadeh + * Copyright (C) 2015 Robin H. Johnson + * + * 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 "common/debug.h" #include "common/ceph_json.h" diff --git a/src/rgw/rgw_website.h b/src/rgw/rgw_website.h index 348412d001e06..6c1a92bb47603 100644 --- a/src/rgw/rgw_website.h +++ b/src/rgw/rgw_website.h @@ -1,3 +1,17 @@ +// -*- 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) 2015 Yehuda Sadeh + * Copyright (C) 2015 Robin H. Johnson + * + * 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. + * + */ #ifndef RGW_WEBSITE_H #define RGW_WEBSITE_H diff --git a/src/rgw/rgw_xml_enc.cc b/src/rgw/rgw_xml_enc.cc index 7577826fcffb1..ff64efca7223b 100644 --- a/src/rgw/rgw_xml_enc.cc +++ b/src/rgw/rgw_xml_enc.cc @@ -1,6 +1,17 @@ // -*- 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) 2015 Yehuda Sadeh + * Copyright (C) 2015 Robin H. Johnson + * + * 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 "rgw_common.h" #include "rgw_xml.h" From 66345a23e04bb1264a91d067be154d90b455438e Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 3 Dec 2015 17:18:29 -0800 Subject: [PATCH 64/90] s3website: update cmake. Signed-off-by: Robin H. Johnson Conflicts: src/CMakeLists.txt --- src/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 45b646e8da825..43da5e082d945 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -214,6 +214,7 @@ set(libcommon_files common/simple_spin.cc common/Thread.cc common/Formatter.cc + common/HTMLFormatter.cc common/HeartbeatMap.cc common/ceph_fs.cc common/ceph_hash.cc @@ -732,7 +733,9 @@ if(${WITH_RADOSGW}) rgw/rgw_replica_log.cc rgw/rgw_keystone.cc rgw/rgw_quota.cc - rgw/rgw_dencoder.cc) + rgw/rgw_dencoder.cc + rgw/rgw_website.cc + rgw/rgw_xml_enc.cc) add_library(rgw_a STATIC ${rgw_a_srcs}) From d682f10838f09adc6195d5fa7ec560ab54324b9d Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 19 Jan 2016 09:46:32 -0800 Subject: [PATCH 65/90] rgw: remove split formatter code Signed-off-by: Yehuda Sadeh --- src/common/JSONFormatter.h | 66 --------- src/common/TableFormatter.h | 71 ---------- src/common/XMLFormatter.cc | 274 ------------------------------------ src/common/XMLFormatter.h | 66 --------- 4 files changed, 477 deletions(-) delete mode 100644 src/common/JSONFormatter.h delete mode 100644 src/common/TableFormatter.h delete mode 100644 src/common/XMLFormatter.cc delete mode 100644 src/common/XMLFormatter.h diff --git a/src/common/JSONFormatter.h b/src/common/JSONFormatter.h deleted file mode 100644 index a6a50928be446..0000000000000 --- a/src/common/JSONFormatter.h +++ /dev/null @@ -1,66 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -#ifndef CEPH_JSON_FORMATTER_H -#define CEPH_JSON_FORMATTER_H - -#include "include/int_types.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/buffer.h" -#include "Formatter.h" - -namespace ceph { - class JSONFormatter : public Formatter { - public: - JSONFormatter(bool p = false); - - virtual void set_status(const char* status, const char* status_name) {}; - virtual void output_header() {}; - virtual void output_footer() {}; - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); - - private: - - struct json_formatter_stack_entry_d { - int size; - bool is_array; - json_formatter_stack_entry_d() : size(0), is_array(false) { } - }; - - bool m_pretty; - void open_section(const char *name, bool is_array); - void print_quoted_string(const std::string& s); - void print_name(const char *name); - void print_comma(json_formatter_stack_entry_d& entry); - void finish_pending_string(); - - std::stringstream m_ss, m_pending_string; - std::list m_stack; - bool m_is_pending_string; - }; - -} - -#endif diff --git a/src/common/TableFormatter.h b/src/common/TableFormatter.h deleted file mode 100644 index ba8f66823ec7e..0000000000000 --- a/src/common/TableFormatter.h +++ /dev/null @@ -1,71 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -#ifndef CEPH_TABLE_FORMATTER_H -#define CEPH_TABLE_FORMATTER_H - -#include "include/int_types.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/buffer.h" -#include "Formatter.h" - -namespace ceph { - class TableFormatter : public Formatter { - public: - TableFormatter(bool keyval = false); - - virtual void set_status(const char* status, const char* status_name) {}; - virtual void output_header() {}; - virtual void output_footer() {}; - void flush(std::ostream& os); - void reset(); - virtual void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); - - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - std::ostream& dump_stream(const char *name); - - int get_len() const; - void write_raw_data(const char *data); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); - - private: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - std::vector< std::vector > > m_vec; - std::stringstream m_ss; - size_t m_vec_index(const char* name); - std::string get_section_name(const char* name); - void finish_pending_string(); - std::string m_pending_name; - bool m_keyval; - - int m_section_open; - std::vector< std::string > m_section; - std::map m_section_cnt; - std::vector m_column_size; - std::vector< std::string > m_column_name; - }; - - -} - -#endif diff --git a/src/common/XMLFormatter.cc b/src/common/XMLFormatter.cc deleted file mode 100644 index 084fd40eaf85d..0000000000000 --- a/src/common/XMLFormatter.cc +++ /dev/null @@ -1,274 +0,0 @@ -// -*- 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) 2011 New Dream Network - * - * 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. - * - */ - -#define LARGE_SIZE 1024 - -#include "include/int_types.h" - -#include "assert.h" -#include "Formatter.h" -#include "XMLFormatter.h" -#include "common/escape.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// ----------------------- -namespace ceph { - -const char *XMLFormatter::XML_1_DTD = - ""; - -XMLFormatter::XMLFormatter(bool pretty) -: m_pretty(pretty) -{ - reset(); -} - -void XMLFormatter::flush(std::ostream& os) -{ - finish_pending_string(); - std::string m_ss_str = m_ss.str(); - os << m_ss_str; - /* There is a small catch here. If the rest of the formatter had NO output, - * we should NOT output a newline. This primarily triggers on HTTP redirects */ - if (m_pretty && !m_ss_str.empty()) - os << "\n"; - m_ss.clear(); - m_ss.str(""); -} - -void XMLFormatter::reset() -{ - m_ss.clear(); - m_ss.str(""); - m_pending_string.clear(); - m_pending_string.str(""); - m_sections.clear(); - m_pending_string_name.clear(); - m_header_done = false; -} - -void XMLFormatter::output_header() -{ - if(!m_header_done) { - m_header_done = true; - write_raw_data(XMLFormatter::XML_1_DTD);; - if (m_pretty) - m_ss << "\n"; - } -} - -void XMLFormatter::output_footer() -{ - while(!m_sections.empty()) { - close_section(); - } -} - -void XMLFormatter::open_object_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_object_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -void XMLFormatter::open_array_section(const char *name) -{ - open_section_in_ns(name, NULL, NULL); -} - -void XMLFormatter::open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) -{ - open_section_in_ns(name, NULL, &attrs); -} - -void XMLFormatter::open_array_section_in_ns(const char *name, const char *ns) -{ - open_section_in_ns(name, ns, NULL); -} - -void XMLFormatter::close_section() -{ - assert(!m_sections.empty()); - finish_pending_string(); - - std::string section = m_sections.back(); - m_sections.pop_back(); - print_spaces(); - m_ss << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_unsigned(const char *name, uint64_t u) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << u << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_int(const char *name, int64_t u) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << u << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_float(const char *name, double d) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << d << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_string(const char *name, const std::string& s) -{ - std::string e(name); - print_spaces(); - m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << ""; - if (m_pretty) - m_ss << "\n"; -} - -void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) -{ - std::string e(name); - std::string attrs_str; - get_attrs_str(&attrs, attrs_str); - print_spaces(); - m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << ""; - if (m_pretty) - m_ss << "\n"; -} - -std::ostream& XMLFormatter::dump_stream(const char *name) -{ - print_spaces(); - m_pending_string_name = name; - m_ss << "<" << m_pending_string_name << ">"; - return m_pending_string; -} - -void XMLFormatter::dump_format_va(const char* name, const char *ns, bool quoted, const char *fmt, va_list ap) -{ - char buf[LARGE_SIZE]; - vsnprintf(buf, LARGE_SIZE, fmt, ap); - - std::string e(name); - print_spaces(); - if (ns) { - m_ss << "<" << e << " xmlns=\"" << ns << "\">" << buf << ""; - } else { - m_ss << "<" << e << ">" << escape_xml_str(buf) << ""; - } - - if (m_pretty) - m_ss << "\n"; -} - -int XMLFormatter::get_len() const -{ - return m_ss.str().size(); -} - -void XMLFormatter::write_raw_data(const char *data) -{ - m_ss << data; -} - -void XMLFormatter::get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str) -{ - std::stringstream attrs_ss; - - for (std::list >::const_iterator iter = attrs->attrs.begin(); - iter != attrs->attrs.end(); ++iter) { - std::pair p = *iter; - attrs_ss << " " << p.first << "=" << "\"" << p.second << "\""; - } - - attrs_str = attrs_ss.str(); -} - -void XMLFormatter::open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs) -{ - print_spaces(); - std::string attrs_str; - - if (attrs) { - get_attrs_str(attrs, attrs_str); - } - - if (ns) { - m_ss << "<" << name << attrs_str << " xmlns=\"" << ns << "\">"; - } else { - m_ss << "<" << name << attrs_str << ">"; - } - if (m_pretty) - m_ss << "\n"; - m_sections.push_back(name); -} - -void XMLFormatter::finish_pending_string() -{ - if (!m_pending_string_name.empty()) { - m_ss << escape_xml_str(m_pending_string.str().c_str()) - << ""; - m_pending_string_name.clear(); - m_pending_string.str(std::string()); - if (m_pretty) { - m_ss << "\n"; - } - } -} - -void XMLFormatter::print_spaces() -{ - finish_pending_string(); - if (m_pretty) { - std::string spaces(m_sections.size(), ' '); - m_ss << spaces; - } -} - -std::string XMLFormatter::escape_xml_str(const char *str) -{ - int len = escape_xml_attr_len(str); - std::vector escaped(len, '\0'); - escape_xml_attr(str, &escaped[0]); - return std::string(&escaped[0]); -} - -} // namespace ceph diff --git a/src/common/XMLFormatter.h b/src/common/XMLFormatter.h deleted file mode 100644 index f455f5dc8654f..0000000000000 --- a/src/common/XMLFormatter.h +++ /dev/null @@ -1,66 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -#ifndef CEPH_XML_FORMATTER_H -#define CEPH_XML_FORMATTER_H - -#include "include/int_types.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "include/buffer.h" -#include "Formatter.h" - -namespace ceph { - class XMLFormatter : public Formatter { - public: - static const char *XML_1_DTD; - XMLFormatter(bool pretty = false); - - virtual void set_status(const char* status, const char* status_name) {}; - virtual void output_header(); - virtual void output_footer(); - - void flush(std::ostream& os); - void reset(); - void open_array_section(const char *name); - void open_array_section_in_ns(const char *name, const char *ns); - void open_object_section(const char *name); - void open_object_section_in_ns(const char *name, const char *ns); - void close_section(); - void dump_unsigned(const char *name, uint64_t u); - void dump_int(const char *name, int64_t u); - void dump_float(const char *name, double d); - void dump_string(const char *name, const std::string& s); - std::ostream& dump_stream(const char *name); - void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap); - int get_len() const; - void write_raw_data(const char *data); - - /* with attrs */ - void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - protected: - void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); - void finish_pending_string(); - void print_spaces(); - static std::string escape_xml_str(const char *str); - void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); - - std::stringstream m_ss, m_pending_string; - std::deque m_sections; - bool m_pretty; - std::string m_pending_string_name; - bool m_header_done; - }; - -} - -#endif From a5abe3bcb5c2af69b1700e5bdf0c92217fd26fbc Mon Sep 17 00:00:00 2001 From: Gaurav Bafna Date: Mon, 20 Jun 2016 22:37:57 +1100 Subject: [PATCH 66/90] DSS Changes for merging formatters. Instead of big PR 7381 on upstream --- src/common/Formatter.cc | 19 +++++++++++++++++++ src/common/Formatter.h | 16 +++++++++++++--- src/common/HTMLFormatter.cc | 1 - src/common/HTMLFormatter.h | 2 +- src/mds/MDS.cc | 2 +- src/mon/MonitorDBStore.h | 2 +- src/rbd_replay/actions.hpp | 1 - 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 345f95df66dca..34dcc9cf6b530 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -18,6 +18,7 @@ #include "assert.h" #include "Formatter.h" +#include "HTMLFormatter.h" #include "common/escape.h" #include @@ -336,6 +337,24 @@ void XMLFormatter::reset() m_pending_string.str(""); m_sections.clear(); m_pending_string_name.clear(); + m_header_done = false; +} + +void XMLFormatter::output_header() +{ + if(!m_header_done) { + m_header_done = true; + write_raw_data(XMLFormatter::XML_1_DTD);; + if (m_pretty) + m_ss << "\n"; + } +} + +void XMLFormatter::output_footer() +{ + while(!m_sections.empty()) { + close_section(); + } } void XMLFormatter::open_object_section(const char *name) diff --git a/src/common/Formatter.h b/src/common/Formatter.h index aead9c26edb33..d8eef64b730cd 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -92,7 +92,9 @@ namespace ceph { class JSONFormatter : public Formatter { public: JSONFormatter(bool p = false); - + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header() {}; + virtual void output_footer() {}; void flush(std::ostream& os); void reset(); virtual void open_array_section(const char *name); @@ -134,6 +136,10 @@ namespace ceph { static const char *XML_1_DTD; XMLFormatter(bool pretty = false); + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header(); + virtual void output_footer(); + void flush(std::ostream& os); void reset(); void open_array_section(const char *name); @@ -154,7 +160,7 @@ namespace ceph { void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs); void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs); void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs); - private: + protected: void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); void finish_pending_string(); void print_spaces(); @@ -165,12 +171,16 @@ namespace ceph { std::deque m_sections; bool m_pretty; std::string m_pending_string_name; + bool m_header_done; }; class TableFormatter : public Formatter { public: TableFormatter(bool keyval = false); - + + virtual void set_status(const char* status, const char* status_name) {}; + virtual void output_header() {}; + virtual void output_footer() {}; void flush(std::ostream& os); void reset(); virtual void open_array_section(const char *name); diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc index 35e36a2340798..60d7e5d8415b9 100644 --- a/src/common/HTMLFormatter.cc +++ b/src/common/HTMLFormatter.cc @@ -19,7 +19,6 @@ #include "assert.h" #include "Formatter.h" #include "HTMLFormatter.h" -#include "XMLFormatter.h" #include "common/escape.h" #include diff --git a/src/common/HTMLFormatter.h b/src/common/HTMLFormatter.h index a8c6b20a78b21..de154c7b0d188 100644 --- a/src/common/HTMLFormatter.h +++ b/src/common/HTMLFormatter.h @@ -15,7 +15,7 @@ #include #include "include/buffer.h" -#include "XMLFormatter.h" +#include "Formatter.h" namespace ceph { class HTMLFormatter : public XMLFormatter { diff --git a/src/mds/MDS.cc b/src/mds/MDS.cc index 0dbe97e3e1a63..8481a7017dd20 100644 --- a/src/mds/MDS.cc +++ b/src/mds/MDS.cc @@ -23,7 +23,7 @@ #include "common/signal.h" #include "common/ceph_argparse.h" #include "common/errno.h" -#include "common/JSONFormatter.h" +#include "common/Formatter.h" #include "msg/Messenger.h" #include "mon/MonClient.h" diff --git a/src/mon/MonitorDBStore.h b/src/mon/MonitorDBStore.h index 58cff24e4156c..2f6f8d8ba8749 100644 --- a/src/mon/MonitorDBStore.h +++ b/src/mon/MonitorDBStore.h @@ -23,7 +23,7 @@ #include "os/KeyValueDB.h" #include "include/assert.h" -#include "common/JSONFormatter.h" +#include "common/Formatter.h" #include "common/Finisher.h" #include "common/errno.h" diff --git a/src/rbd_replay/actions.hpp b/src/rbd_replay/actions.hpp index a80ef95064eab..9a05285ca4f26 100644 --- a/src/rbd_replay/actions.hpp +++ b/src/rbd_replay/actions.hpp @@ -18,7 +18,6 @@ #include #include "include/rbd/librbd.hpp" #include "common/Formatter.h" -#include "common/JSONFormatter.h" #include "rbd_replay/ActionTypes.h" #include "rbd_loc.hpp" #include From 5aa0b04f41078236ee24403b207e6bd5be99953c Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 19 Jan 2016 15:33:48 -0800 Subject: [PATCH 67/90] rgw: init_permissions() shouldn't return ENOENT in a specific case If op is bucket creation it should ignore ENOENT. Otherwise we should make sure we return the appropriate error. Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_main.cc | 2 +- src/rgw/rgw_op.cc | 2 +- src/rgw/rgw_op.h | 2 +- src/rgw/rgw_rest.cc | 5 ++++- src/rgw/rgw_rest.h | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 2749e68ad61e9..fed09653a77e4 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -635,7 +635,7 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC } req->log(s, "init permissions"); - ret = handler->init_permissions(); + ret = handler->init_permissions(op); if (ret < 0) { abort_early(s, op, ret, handler); goto done; diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 005490dc67415..c9da0c0e25ab1 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -423,7 +423,7 @@ static int rgw_build_bucket_policies(RGWRados *store, struct req_state *s) } } - return 0; + return ret; } /** diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 6753b6c6abdeb..3ec58011f5f0c 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -1107,7 +1107,7 @@ class RGWHandler { virtual int validate_bucket_name(const string& bucket, int name_strictness) { return 0; } virtual RGWOp *get_op(RGWRados *store); virtual void put_op(RGWOp *op); - virtual int init_permissions() { + virtual int init_permissions(RGWOp *op) { return 0; } virtual int retarget(RGWOp *op, RGWOp **new_op) { diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 6491cc6440ebd..f9c00421bf68b 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1372,8 +1372,11 @@ static http_op op_from_method(const char *method) return OP_UNKNOWN; } -int RGWHandler_ObjStore::init_permissions() +int RGWHandler_ObjStore::init_permissions(RGWOp *op) { + if (op->get_type() == RGW_OP_CREATE_BUCKET) + return 0; + return do_init_permissions(); } diff --git a/src/rgw/rgw_rest.h b/src/rgw/rgw_rest.h index d3287474b9bcc..ff2af52a90d6f 100644 --- a/src/rgw/rgw_rest.h +++ b/src/rgw/rgw_rest.h @@ -303,7 +303,7 @@ class RGWHandler_ObjStore : public RGWHandler { public: RGWHandler_ObjStore() {} virtual ~RGWHandler_ObjStore() {} - int init_permissions(); + int init_permissions(RGWOp *op); int read_permissions(RGWOp *op); virtual int retarget(RGWOp *op, RGWOp **new_op) { *new_op = op; From 867afa4d054bb2099f1a8cba49c600bc11e9b330 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Thu, 7 Jan 2016 01:35:16 +0000 Subject: [PATCH 68/90] S3Website: AmazonS3 changed RedirectAll HTTP response. Signed-off-by: Robin H. Johnson --- src/rgw/rgw_website.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_website.cc b/src/rgw/rgw_website.cc index eee8977a86f94..a69ffe16d2981 100644 --- a/src/rgw/rgw_website.cc +++ b/src/rgw/rgw_website.cc @@ -94,7 +94,7 @@ bool RGWBucketWebsiteConf::should_redirect(const string& key, const int http_err if(!redirect_all.hostname.empty()) { RGWBWRoutingRule redirect_all_rule; redirect_all_rule.redirect_info.redirect = redirect_all; - redirect_all.http_redirect_code = 302; + redirect_all.http_redirect_code = 301; *redirect = redirect_all_rule; return true; } else if (!routing_rules.check_key_and_error_code_condition(key, http_error_code, &rule)) { From 999e8f93cce71bc884ea7def6fc9583637c23cba Mon Sep 17 00:00:00 2001 From: "Javier M. Mellid" Date: Wed, 21 Oct 2015 16:04:14 +0200 Subject: [PATCH 69/90] rgw: add explicit success/error paths in RGWGetObj::execute() Fixes: #12352 Signed-off-by: Javier M. Mellid Conflicts: src/rgw/rgw_rest_swift.cc src/rgw/rgw_rest_swift.h --- src/rgw/rgw_op.cc | 5 ++++- src/rgw/rgw_op.h | 1 + src/rgw/rgw_rest_s3.cc | 6 ++++++ src/rgw/rgw_rest_s3.h | 1 + src/rgw/rgw_rest_swift.cc | 13 +++++++++++++ src/rgw/rgw_rest_swift.h | 2 ++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index c9da0c0e25ab1..96f1c525adf79 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -958,8 +958,11 @@ void RGWGetObj::execute() goto done_err; } -done_err: send_response_data(bl, 0, 0); + return; + +done_err: + send_response_data_error(); } int RGWGetObj::init_common() diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 3ec58011f5f0c..4b3df0a8d211c 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -175,6 +175,7 @@ class RGWGetObj : public RGWOp { int get_data_cb(bufferlist& bl, off_t ofs, off_t len); virtual int get_params() = 0; + virtual int send_response_data_error() = 0; virtual int send_response_data(bufferlist& bl, off_t ofs, off_t len) = 0; virtual const string name() { return "get_obj"; } diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 41cd33f2e654a..0a9150091808b 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -75,6 +75,12 @@ static struct response_attr_param resp_attr_params[] = { {NULL, NULL}, }; +int RGWGetObj_ObjStore_S3::send_response_data_error() +{ + bufferlist bl; + return send_response_data(bl, 0 , 0); +} + int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { const char *content_type = NULL; diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index 135fa39704290..d0ab281c42a73 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -24,6 +24,7 @@ class RGWGetObj_ObjStore_S3 : public RGWGetObj_ObjStore RGWGetObj_ObjStore_S3() {} ~RGWGetObj_ObjStore_S3() {} + int send_response_data_error(); int send_response_data(bufferlist& bl, off_t ofs, off_t len); }; diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index bcbd45002c896..e5b5412035796 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -692,6 +692,19 @@ void RGWCopyObj_ObjStore_SWIFT::send_response() } } +int RGWGetObj_ObjStore_SWIFT::get_params() +{ + const string& mm = s->info.args.get("multipart-manifest"); + + return RGWGetObj_ObjStore::get_params(); +} + +int RGWGetObj_ObjStore_SWIFT::send_response_data_error() +{ + bufferlist bl; + return send_response_data(bl, 0, 0); +} + int RGWGetObj_ObjStore_SWIFT::send_response_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { string content_type; diff --git a/src/rgw/rgw_rest_swift.h b/src/rgw/rgw_rest_swift.h index 19028ab337b43..ebd0d33d01a5c 100644 --- a/src/rgw/rgw_rest_swift.h +++ b/src/rgw/rgw_rest_swift.h @@ -13,6 +13,8 @@ class RGWGetObj_ObjStore_SWIFT : public RGWGetObj_ObjStore { RGWGetObj_ObjStore_SWIFT() {} ~RGWGetObj_ObjStore_SWIFT() {} + int get_params(); + int send_response_data_error(); int send_response_data(bufferlist& bl, off_t ofs, off_t len); }; From bcf8ae6281ea55ee5eb085133dc141a1631a736e Mon Sep 17 00:00:00 2001 From: Gaurav Bafna Date: Tue, 21 Jun 2016 18:51:30 +1100 Subject: [PATCH 70/90] WIP x-amz-website-redirect-location . Backported from 11913b964220e7435f8ce17ef19469ec519cca97 --- src/rgw/rgw_main.cc | 17 ++++++++- src/rgw/rgw_op.cc | 29 +++++++++++++- src/rgw/rgw_op.h | 73 ++++++++++-------------------------- src/rgw/rgw_rest.cc | 5 +++ src/rgw/rgw_rest_s3.cc | 20 ++++++++++ src/rgw/rgw_rest_s3website.h | 4 +- 6 files changed, 91 insertions(+), 57 deletions(-) diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index fed09653a77e4..d75911e6a7021 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -694,9 +694,24 @@ static int process_request(RGWRados *store, RGWREST *rest, RGWRequest *req, RGWC goto done; } - req->log(s, "executing"); + req->log(s, "pre-executing"); op->pre_exec(); + ret = op->get_ret(); + if (ret < 0) { + dout(2) << "pre_exec ret=" << ret << dendl; + abort_early(s, op, ret, handler); + goto done; + } + + req->log(s, "executing"); op->execute(); + ret = op->get_ret(); + if (ret < 0) { + dout(2) << "execute ret=" << ret << dendl; + abort_early(s, op, ret, handler); + goto done; + } + req->log(s, "completing"); op->complete(); done: int r = client_io->complete_request(); diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 96f1c525adf79..70e80de1213e1 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -887,6 +887,7 @@ int RGWGetObj::get_data_cb(bufferlist& bl, off_t bl_ofs, off_t bl_len) void RGWGetObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWGetObj::execute() @@ -953,12 +954,15 @@ void RGWGetObj::execute() ret = read_op.iterate(ofs, end, &cb); perfcounter->tinc(l_rgw_get_lat, - (ceph_clock_now(s->cct) - start_time)); + (ceph_clock_now(s->cct) - start_time)); if (ret < 0) { goto done_err; } - send_response_data(bl, 0, 0); + ret = send_response_data(bl, 0, 0); + if (ret < 0) { + goto done_err; + } return; done_err: @@ -1096,6 +1100,7 @@ int RGWGetBucketVersioning::verify_permission() void RGWGetBucketVersioning::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWGetBucketVersioning::execute() @@ -1115,6 +1120,7 @@ int RGWSetBucketVersioning::verify_permission() void RGWSetBucketVersioning::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWSetBucketVersioning::execute() @@ -1149,6 +1155,7 @@ int RGWGetBucketWebsite::verify_permission() void RGWGetBucketWebsite::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWGetBucketWebsite::execute() @@ -1169,6 +1176,7 @@ int RGWSetBucketWebsite::verify_permission() void RGWSetBucketWebsite::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWSetBucketWebsite::execute() @@ -1199,6 +1207,7 @@ int RGWDeleteBucketWebsite::verify_permission() void RGWDeleteBucketWebsite::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWDeleteBucketWebsite::execute() @@ -1224,6 +1233,7 @@ int RGWStatBucket::verify_permission() void RGWStatBucket::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWStatBucket::execute() @@ -1276,6 +1286,7 @@ int RGWListBucket::parse_max_keys() void RGWListBucket::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWListBucket::execute() @@ -1381,6 +1392,7 @@ void RGWCreateBucket::pre_exec() ret = dialect_handler->validate_bucket_name(s->bucket_name_str, s->cct->_conf->rgw_s3_bucket_name_create_strictness); rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWCreateBucket::execute() @@ -1528,6 +1540,7 @@ int RGWDeleteBucket::verify_permission() void RGWDeleteBucket::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWDeleteBucket::execute() @@ -1761,6 +1774,7 @@ void RGWPutObj::dispose_processor(RGWPutObjProcessor *processor) void RGWPutObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } static int put_data_and_throttle(RGWPutObjProcessor *processor, bufferlist& data, off_t ofs, @@ -2052,6 +2066,7 @@ void RGWPostObj::dispose_processor(RGWPutObjProcessor *processor) void RGWPostObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWPostObj::execute() @@ -2295,6 +2310,7 @@ int RGWDeleteObj::verify_permission() void RGWDeleteObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWDeleteObj::execute() @@ -2500,6 +2516,7 @@ void RGWCopyObj::progress_cb(off_t ofs) void RGWCopyObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWCopyObj::execute() @@ -2558,6 +2575,7 @@ int RGWGetACLs::verify_permission() void RGWGetACLs::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWGetACLs::execute() @@ -2588,6 +2606,7 @@ int RGWPutACLs::verify_permission() void RGWPutACLs::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWPutACLs::execute() @@ -2853,6 +2872,7 @@ int RGWInitMultipart::verify_permission() void RGWInitMultipart::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWInitMultipart::execute() @@ -3049,6 +3069,7 @@ int RGWCompleteMultipart::verify_permission() void RGWCompleteMultipart::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWCompleteMultipart::execute() @@ -3248,6 +3269,7 @@ int RGWAbortMultipart::verify_permission() void RGWAbortMultipart::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWAbortMultipart::execute() @@ -3349,6 +3371,7 @@ int RGWListMultipart::verify_permission() void RGWListMultipart::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWListMultipart::execute() @@ -3382,6 +3405,7 @@ int RGWListBucketMultiparts::verify_permission() void RGWListBucketMultiparts::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWListBucketMultiparts::execute() @@ -3442,6 +3466,7 @@ int RGWDeleteMultiObj::verify_permission() void RGWDeleteMultiObj::pre_exec() { rgw_bucket_object_pre_exec(s); + ret = 0; } void RGWDeleteMultiObj::execute() diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 4b3df0a8d211c..58e6b6faf39d8 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -76,6 +76,7 @@ class RGWOp { bool cors_exist; RGWQuotaInfo bucket_quota; RGWQuotaInfo user_quota; + int ret; virtual int init_quota(); public: @@ -114,6 +115,7 @@ class RGWOp { virtual uint32_t op_mask() { return 0; } virtual int error_handler(int err_no, string *error_content); + int get_ret() { return ret; }; }; class RGWGetObj : public RGWOp { @@ -133,7 +135,6 @@ class RGWGetObj : public RGWOp { time_t *mod_ptr; time_t *unmod_ptr; map attrs; - int ret; bool get_data; bool partial_content; rgw_obj obj; @@ -158,7 +159,6 @@ class RGWGetObj : public RGWOp { unmod_ptr = NULL; get_data = false; partial_content = false; - ret = 0; } virtual bool prefetch_data() { return get_data; } @@ -200,14 +200,13 @@ class RGWGetObj_CB : public RGWGetDataCB class RGWListBuckets : public RGWOp { protected: - int ret; bool sent_data; string marker; uint64_t limit; uint64_t limit_max; public: - RGWListBuckets() : ret(0), sent_data(false) { + RGWListBuckets() : sent_data(false) { limit = limit_max = RGW_LIST_BUCKETS_LIMIT_MAX; } @@ -229,7 +228,6 @@ class RGWListBuckets : public RGWOp { class RGWStatAccount : public RGWOp { protected: - int ret; uint32_t buckets_count; uint64_t buckets_objcount; uint64_t buckets_size; @@ -264,7 +262,6 @@ class RGWListBucket : public RGWOp { string encoding_type; bool list_versions; int max; - int ret; vector objs; map common_prefixes; @@ -274,7 +271,7 @@ class RGWListBucket : public RGWOp { int parse_max_keys(); public: - RGWListBucket() : list_versions(false), max(0), ret(0), + RGWListBucket() : list_versions(false), max(0), default_max(0), is_truncated(false) {} int verify_permission(); void pre_exec(); @@ -292,7 +289,7 @@ class RGWGetBucketLogging : public RGWOp { public: RGWGetBucketLogging() {} int verify_permission(); - void execute() {} + void execute() { ret = 0; } virtual void send_response() = 0; virtual const string name() { return "get_bucket_logging"; } @@ -305,7 +302,7 @@ class RGWGetBucketLocation : public RGWOp { RGWGetBucketLocation() {} ~RGWGetBucketLocation() {} int verify_permission(); - void execute() {} + void execute() { ret = 0; } virtual void send_response() = 0; virtual const string name() { return "get_bucket_location"; } @@ -332,9 +329,8 @@ class RGWGetBucketVersioning : public RGWOp { class RGWSetBucketVersioning : public RGWOp { protected: bool enable_versioning; - int ret; public: - RGWSetBucketVersioning() : enable_versioning(false), ret(0) {} + RGWSetBucketVersioning() : enable_versioning(false) {} int verify_permission(); void pre_exec(); @@ -349,10 +345,8 @@ class RGWSetBucketVersioning : public RGWOp { }; class RGWGetBucketWebsite : public RGWOp { -protected: - int ret; public: - RGWGetBucketWebsite() : ret(0) {} + RGWGetBucketWebsite() {} int verify_permission(); void pre_exec(); @@ -366,10 +360,9 @@ class RGWGetBucketWebsite : public RGWOp { class RGWSetBucketWebsite : public RGWOp { protected: - int ret; RGWBucketWebsiteConf website_conf; public: - RGWSetBucketWebsite() : ret(0) {} + RGWSetBucketWebsite() {} int verify_permission(); void pre_exec(); @@ -384,10 +377,8 @@ class RGWSetBucketWebsite : public RGWOp { }; class RGWDeleteBucketWebsite : public RGWOp { -protected: - int ret; public: - RGWDeleteBucketWebsite() : ret(0) {} + RGWDeleteBucketWebsite() {} int verify_permission(); void pre_exec(); @@ -401,11 +392,10 @@ class RGWDeleteBucketWebsite : public RGWOp { class RGWStatBucket : public RGWOp { protected: - int ret; RGWBucketEnt bucket; public: - RGWStatBucket() : ret(0) {} + RGWStatBucket() {} ~RGWStatBucket() {} int verify_permission(); @@ -420,7 +410,6 @@ class RGWStatBucket : public RGWOp { class RGWCreateBucket : public RGWOp { protected: - int ret; RGWAccessControlPolicy policy; string location_constraint; string placement_rule; @@ -432,7 +421,7 @@ class RGWCreateBucket : public RGWOp { bufferlist in_data; public: - RGWCreateBucket() : ret(0), has_cors(false) {} + RGWCreateBucket() : has_cors(false) {} int verify_permission(); void pre_exec(); @@ -450,12 +439,10 @@ class RGWCreateBucket : public RGWOp { class RGWDeleteBucket : public RGWOp { protected: - int ret; - RGWObjVersionTracker objv_tracker; public: - RGWDeleteBucket() : ret(0) {} + RGWDeleteBucket() {} int verify_permission(); void pre_exec(); @@ -472,7 +459,6 @@ class RGWPutObj : public RGWOp { friend class RGWPutObjProcessor; protected: - int ret; off_t ofs; const char *supplied_md5_b64; const char *supplied_etag; @@ -491,7 +477,6 @@ class RGWPutObj : public RGWOp { public: RGWPutObj() { - ret = 0; ofs = 0; supplied_md5_b64 = NULL; supplied_etag = NULL; @@ -531,7 +516,6 @@ class RGWPostObj : public RGWOp { protected: off_t min_len; off_t max_len; - int ret; int len; off_t ofs; const char *supplied_md5_b64; @@ -544,7 +528,7 @@ class RGWPostObj : public RGWOp { map attrs; public: - RGWPostObj() : min_len(0), max_len(LLONG_MAX), ret(0), len(0), ofs(0), + RGWPostObj() : min_len(0), max_len(LLONG_MAX), len(0), ofs(0), supplied_md5_b64(NULL), supplied_etag(NULL), data_pending(false) {} @@ -570,7 +554,6 @@ class RGWPostObj : public RGWOp { class RGWPutMetadata : public RGWOp { protected: - int ret; set rmattr_names; bool has_policy, has_cors; RGWAccessControlPolicy policy; @@ -605,7 +588,6 @@ class RGWSetTempUrl : public RGWOp { map temp_url_keys; public: RGWSetTempUrl() : ret(0) {} - int verify_permission(); void execute(); @@ -617,12 +599,11 @@ class RGWSetTempUrl : public RGWOp { class RGWDeleteObj : public RGWOp { protected: - int ret; bool delete_marker; string version_id; public: - RGWDeleteObj() : ret(0), delete_marker(false) {} + RGWDeleteObj() : delete_marker(false) {} int verify_permission(); void pre_exec(); @@ -648,7 +629,6 @@ class RGWCopyObj : public RGWOp { time_t unmod_time; time_t *mod_ptr; time_t *unmod_ptr; - int ret; map attrs; string src_bucket_name; rgw_bucket src_bucket; @@ -717,11 +697,10 @@ class RGWCopyObj : public RGWOp { class RGWGetACLs : public RGWOp { protected: - int ret; string acls; public: - RGWGetACLs() : ret(0) {} + RGWGetACLs() {} int verify_permission(); void pre_exec(); @@ -735,7 +714,6 @@ class RGWGetACLs : public RGWOp { class RGWPutACLs : public RGWOp { protected: - int ret; size_t len; char *data; ACLOwner owner; @@ -764,10 +742,9 @@ class RGWPutACLs : public RGWOp { class RGWGetCORS : public RGWOp { protected: - int ret; public: - RGWGetCORS() : ret(0) {} + RGWGetCORS() {} int verify_permission(); void execute(); @@ -780,7 +757,6 @@ class RGWGetCORS : public RGWOp { class RGWPutCORS : public RGWOp { protected: - int ret; bufferlist cors_bl; public: @@ -801,10 +777,9 @@ class RGWPutCORS : public RGWOp { class RGWDeleteCORS : public RGWOp { protected: - int ret; public: - RGWDeleteCORS() : ret(0) {} + RGWDeleteCORS() {} int verify_permission(); void execute(); @@ -817,12 +792,11 @@ class RGWDeleteCORS : public RGWOp { class RGWOptionsCORS : public RGWOp { protected: - int ret; RGWCORSRule *rule; const char *origin, *req_hdrs, *req_meth; public: - RGWOptionsCORS() : ret(0), rule(NULL), origin(NULL), + RGWOptionsCORS() : rule(NULL), origin(NULL), req_hdrs(NULL), req_meth(NULL) { } @@ -838,7 +812,6 @@ class RGWOptionsCORS : public RGWOp { class RGWInitMultipart : public RGWOp { protected: - int ret; string upload_id; RGWAccessControlPolicy policy; @@ -864,7 +837,6 @@ class RGWInitMultipart : public RGWOp { class RGWCompleteMultipart : public RGWOp { protected: - int ret; string upload_id; string etag; char *data; @@ -893,10 +865,8 @@ class RGWCompleteMultipart : public RGWOp { class RGWAbortMultipart : public RGWOp { protected: - int ret; - public: - RGWAbortMultipart() : ret(0) {} + RGWAbortMultipart() {} int verify_permission(); void pre_exec(); @@ -910,7 +880,6 @@ class RGWAbortMultipart : public RGWOp { class RGWListMultipart : public RGWOp { protected: - int ret; string upload_id; map parts; int max_parts; @@ -1019,7 +988,6 @@ class RGWListBucketMultiparts : public RGWOp { RGWMultipartUploadEntry next_marker; int max_uploads; string delimiter; - int ret; vector uploads; map common_prefixes; bool is_truncated; @@ -1051,7 +1019,6 @@ class RGWListBucketMultiparts : public RGWOp { class RGWDeleteMultiObj : public RGWOp { protected: - int ret; int max_to_delete; size_t len; char *data; diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index f9c00421bf68b..ef5d9e2a4c2ea 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -44,6 +44,11 @@ static struct rgw_http_attr rgw_to_http_attr_list[] = { { RGW_ATTR_CONTENT_ENC, "Content-Encoding"}, { RGW_ATTR_USER_MANIFEST, "X-Object-Manifest"}, { RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION, "Location"}, + /* RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION header depends on access mode: + * S3 endpoint: x-amz-website-redirect-location + * S3Website endpoint: Location + */ + { RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION, "x-amz-website-redirect-location" }, { NULL, NULL}, }; diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 0a9150091808b..d83fe069d34e8 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -75,6 +75,26 @@ static struct response_attr_param resp_attr_params[] = { {NULL, NULL}, }; +int RGWGetObj_ObjStore_S3Website::send_response_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) { + map::iterator iter; + iter = attrs.find(RGW_ATTR_AMZ_WEBSITE_REDIRECT_LOCATION); + if (iter != attrs.end()) { + bufferlist &bl = iter->second; + s->redirect = string(bl.c_str(), bl.length()); + s->err.http_ret = 301; + ldout(s->cct, 20) << __CEPH_ASSERT_FUNCTION << " redirectng per x-dss-website-redirect-location=" << s->redirect << dendl; + ret = -ERR_WEBSITE_REDIRECT; + return ret; + } else { + return RGWGetObj_ObjStore_S3::send_response_data(bl, bl_ofs, bl_len); + } +} + +int RGWGetObj_ObjStore_S3Website::send_response_data_error() +{ + return RGWGetObj_ObjStore_S3::send_response_data_error(); +} + int RGWGetObj_ObjStore_S3::send_response_data_error() { bufferlist bl; diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 18f00ee99e55d..06a22ccda22d7 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -75,6 +75,8 @@ class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 RGWGetObj_ObjStore_S3Website() : is_errordoc_request(false) {} RGWGetObj_ObjStore_S3Website(bool is_errordoc_request) : is_errordoc_request(false) { this->is_errordoc_request = is_errordoc_request; } ~RGWGetObj_ObjStore_S3Website() {} + int send_response_data_error(); + int send_response_data(bufferlist& bl, off_t ofs, off_t len); // We override RGWGetObj_ObjStore::get_params here, to allow ignoring all // conditional params for error pages. int get_params() { @@ -84,7 +86,7 @@ class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 if_unmod = NULL; if_match = NULL; if_nomatch = NULL; - return 0; + return 0; } else { return RGWGetObj_ObjStore_S3::get_params(); } From 18e83c119133b9fa162f5fa488c5fcd141d015ed Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Tue, 19 Jan 2016 16:25:59 -0800 Subject: [PATCH 71/90] rgw: a few minor cleanups delete getop, remove #warnings, add comments Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_rest.cc | 9 ++++++++- src/rgw/rgw_rest_s3.cc | 23 ++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index ef5d9e2a4c2ea..99b5fbf201e60 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -742,7 +742,14 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler } if (!error_content.empty()) { ldout(s->cct, 20) << "error_content is set, we need to serve it INSTEAD of firing the formatter" << dendl; -#warning TODO we must add all error entries as headers here + /* + * FIXME we must add all error entries as headers here: + * when having a working errordoc, then the s3 error fields are rendered as HTTP headers, e.g.: + * + * x-amz-error-code: NoSuchKey + * x-amz-error-message: The specified key does not exist. + * x-amz-error-detail-Key: foo + */ end_header(s, op, NULL, NO_CONTENT_LENGTH, false, true); s->cio->write(error_content.c_str(), error_content.size()); s->formatter->reset(); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index d83fe069d34e8..39dab8ce0f163 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -3184,14 +3184,10 @@ int RGWHandler_ObjStore_S3Website::retarget(RGWOp *op, RGWOp **new_op) { return -ERR_WEBSITE_REDIRECT; } -#warning FIXME -#if 0 - if (s->object.empty() != new_obj.empty()) { - op->put(); - s->object = new_obj; - *new_op = get_op(); - } -#endif + /* + * FIXME: if s->object != new_obj, drop op and create a new op to handle operation. Or + * remove this comment if it's not applicable anymore + */ s->object = new_obj; @@ -3214,7 +3210,9 @@ int RGWHandler_ObjStore_S3Website::get_errordoc(const string errordoc_key, strin // 1. Check if errordoc exists // 2. Check if errordoc is public // 3. Fetch errordoc content -#warning 2015119: FIXME need to clear all + /* + * FIXME maybe: need to make sure all of the fields for conditional requests are cleared + */ RGWGetObj_ObjStore_S3Website *getop = new RGWGetObj_ObjStore_S3Website(true); getop->set_get_data(true); getop->init(store, s, this); @@ -3230,10 +3228,13 @@ int RGWHandler_ObjStore_S3Website::get_errordoc(const string errordoc_key, strin int64_t ofs = 0; int64_t end = -1; ret = read_op.prepare(&ofs, &end); - if (ret < 0) - return ret; + if (ret < 0) { + goto done; + } ret = read_op.iterate(ofs, end, &cb); // FIXME: need to know the final size? +done: + delete getop; return ret; } From 14962134d5e6dcd62b5b7c435463edc341c1293e Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 20 Jan 2016 10:32:15 -0800 Subject: [PATCH 72/90] rgw: client io shouldn't try to write zero length buffer Signed-off-by: Yehuda Sadeh --- src/rgw/rgw_client_io.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/rgw/rgw_client_io.cc b/src/rgw/rgw_client_io.cc index 1f8b803a3d405..b6ef745c4f275 100644 --- a/src/rgw/rgw_client_io.cc +++ b/src/rgw/rgw_client_io.cc @@ -51,6 +51,10 @@ int RGWClientIO::print(const char *format, ...) int RGWClientIO::write(const char *buf, int len) { + if (len == 0) { + return 0; + } + int ret = write_data(buf, len); if (ret < 0) return ret; From 9eadab8b31be8f56e5187a356e1c654ad2157844 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Wed, 20 Jan 2016 11:52:48 -0800 Subject: [PATCH 73/90] rgw: fix create bucket error handling Signed-off-by: Yehuda Sadeh Conflicts: src/rgw/rgw_op.cc --- src/rgw/rgw_op.cc | 3 ++- src/rgw/rgw_op.h | 4 +++- src/rgw/rgw_rest_swift.cc | 7 ++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 70e80de1213e1..af85c6137924e 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -1525,7 +1525,8 @@ void RGWCreateBucket::execute() ldout(s->cct, 0) << "WARNING: failed to unlink bucket: ret=" << ret << dendl; } } else if (ret == -EEXIST || (ret == 0 && existed)) { - ret = -ERR_BUCKET_EXISTS; + ret = 0; + exist_ret = -ERR_BUCKET_EXISTS; } } diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 58e6b6faf39d8..ddd3967697f70 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -420,8 +420,10 @@ class RGWCreateBucket : public RGWOp { bufferlist in_data; + int exist_ret; + public: - RGWCreateBucket() : has_cors(false) {} + RGWCreateBucket() : has_cors(false), exist_ret(0) {} int verify_permission(); void pre_exec(); diff --git a/src/rgw/rgw_rest_swift.cc b/src/rgw/rgw_rest_swift.cc index e5b5412035796..d9e9190ca5308 100644 --- a/src/rgw/rgw_rest_swift.cc +++ b/src/rgw/rgw_rest_swift.cc @@ -399,10 +399,11 @@ int RGWCreateBucket_ObjStore_SWIFT::get_params() void RGWCreateBucket_ObjStore_SWIFT::send_response() { - if (!ret) - ret = STATUS_CREATED; - else if (ret == -ERR_BUCKET_EXISTS) + if (exist_ret == -ERR_BUCKET_EXISTS) { ret = STATUS_ACCEPTED; + } else if (!ret) { + ret = STATUS_CREATED; + } set_req_state_err(s, ret); dump_errno(s); /* Propose ending HTTP header with 0 Content-Length header. */ From b62310695854decfc944773d73dddb6b1f659831 Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Thu, 21 Jan 2016 16:35:29 -0800 Subject: [PATCH 74/90] rgw: add a configurable to enable/disable static website rgw_enable_static_website Signed-off-by: Yehuda Sadeh --- src/common/config_opts.h | 2 ++ src/rgw/rgw_rest_s3.cc | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/common/config_opts.h b/src/common/config_opts.h index db2ebb57eb89e..8086c4ffe6c1a 100644 --- a/src/common/config_opts.h +++ b/src/common/config_opts.h @@ -1079,6 +1079,8 @@ OPTION(rgw_keystone_url_token_api, OPT_STR, "url-auth") // api to validate pre OPTION(rgw_keystone_infinite_url_token_api, OPT_STR, "preauth-token-auth") // api to validate infinite time presigned token URL OPTION(dss_regional_url, OPT_STR, "https://dss.ind-west-1.staging.jiocloudservices.com") // URL to be returned in XMLNS during anonymous list all buckets calls +OPTION(rgw_enable_static_website, OPT_BOOL, false) // enable static website feature + OPTION(mutex_perf_counter, OPT_BOOL, false) // enable/disable mutex perf counter OPTION(throttler_perf_counter, OPT_BOOL, true) // enable/disable throttler perf counter diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 39dab8ce0f163..1907f0b796f28 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -2146,8 +2146,12 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_get() if (s->info.args.sub_resource_exists("versioning")) return new RGWGetBucketVersioning_ObjStore_S3; - if (s->info.args.sub_resource_exists("website")) + if (s->info.args.sub_resource_exists("website")) { + if (!s->cct->_conf->rgw_enable_static_website) { + return NULL; + } return new RGWGetBucketWebsite_ObjStore_S3; + } if (is_acl_op()) { return new RGWGetACLs_ObjStore_S3; @@ -2175,8 +2179,12 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_put() return NULL; if (s->info.args.sub_resource_exists("versioning")) return new RGWSetBucketVersioning_ObjStore_S3; - if (s->info.args.sub_resource_exists("website")) + if (s->info.args.sub_resource_exists("website")) { + if (!s->cct->_conf->rgw_enable_static_website) { + return NULL; + } return new RGWSetBucketWebsite_ObjStore_S3; + } if (is_acl_op()) { return new RGWPutACLs_ObjStore_S3; } else if (is_cors_op()) { @@ -2191,8 +2199,12 @@ RGWOp *RGWHandler_ObjStore_Bucket_S3::op_delete() return new RGWDeleteCORS_ObjStore_S3; } - if (s->info.args.sub_resource_exists("website")) + if (s->info.args.sub_resource_exists("website")) { + if (!s->cct->_conf->rgw_enable_static_website) { + return NULL; + } return new RGWDeleteBucketWebsite_ObjStore_S3; + } return new RGWDeleteBucket_ObjStore_S3; } From 661c8b97f6b40eaf9698215dda0ef2908b63d1aa Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Sun, 17 Apr 2016 08:23:23 -0700 Subject: [PATCH 75/90] rgw/s3website: Fix x-amz-website-redirect-location support. Support for the x-amz-website-redirect-location header was broken in the feature merging of Jewel, as it previously depended on the error handler to redirect, which was overkill. Simplify it to work. Backport: jewel Fixes: http://tracker.ceph.com/issues/15531 Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest_s3.cc --- src/rgw/rgw_rest_s3.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 1907f0b796f28..181fa982774b5 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -84,6 +84,11 @@ int RGWGetObj_ObjStore_S3Website::send_response_data(bufferlist& bl, off_t bl_of s->err.http_ret = 301; ldout(s->cct, 20) << __CEPH_ASSERT_FUNCTION << " redirectng per x-dss-website-redirect-location=" << s->redirect << dendl; ret = -ERR_WEBSITE_REDIRECT; + set_req_state_err(s, ret); + dump_errno(s); + dump_content_length(s, 0); + dump_redirect(s, s->redirect); + end_header(s, this); return ret; } else { return RGWGetObj_ObjStore_S3::send_response_data(bl, bl_ofs, bl_len); From 8b77bc078655fdaf45947dac727673af8e3eef7f Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Wed, 20 Apr 2016 15:52:51 -0700 Subject: [PATCH 76/90] rgw/s3website: Implement ErrorDoc & fix Double-Fault handler Fix more last minute breakage from merges, now has has a working ErrorDoc as well as working double-fault. Also moves some s3website-specific code out of the main S3 codepath. Fixes: #15532 Fixes: #15555 Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest.cc src/rgw/rgw_rest_s3.cc src/rgw/rgw_rest_s3.h src/rgw/rgw_rest_s3website.h --- src/rgw/rgw_rest.cc | 94 ++++++++++++------------- src/rgw/rgw_rest_s3.cc | 133 +++++++++++++++++++++++++---------- src/rgw/rgw_rest_s3.h | 5 ++ src/rgw/rgw_rest_s3website.h | 5 +- 4 files changed, 149 insertions(+), 88 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 99b5fbf201e60..bafd3a9db5f49 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -330,17 +330,8 @@ void set_req_state_err(struct req_state *s, int err_no) r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { - if (s->prot_flags & RGW_REST_WEBSITE && err_no == ERR_WEBSITE_REDIRECT && !s->err.is_clear()) { - // http_ret was custom set, so don't change it! - } else { - s->err.http_ret = r->http_ret; - } + s->err.http_ret = r->http_ret; s->err.s3_code = r->s3_code; - if (r->s3_err_message) { - if ((s->err.message).empty()) { - s->err.message = r->s3_err_message; - } - } return; } dout(0) << "WARNING: set_req_state_err err_no=" << err_no << " resorting to 500" << dendl; @@ -715,47 +706,56 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler ldout(s->cct, 20) << "handler->ERRORHANDLER: err_no=" << err_no << " new_err_no=" << new_err_no << dendl; err_no = new_err_no; } - set_req_state_err(s, err_no); - dump_errno(s); - dump_bucket_from_state(s); - if (err_no == -ERR_PERMANENT_REDIRECT || err_no == -ERR_WEBSITE_REDIRECT) { - string dest_uri; - if (!s->redirect.empty()) { - dest_uri = s->redirect; - } else if (!s->region_endpoint.empty()) { - string dest_uri = s->region_endpoint; - /* - * reqest_uri is always start with slash, so we need to remove - * the unnecessary slash at the end of dest_uri. - */ - if (dest_uri[dest_uri.size() - 1] == '/') { - dest_uri = dest_uri.substr(0, dest_uri.size() - 1); + + // If the error handler(s) above dealt with it completely, they should have + // returned 0. If non-zero, we need to continue here. + if(err_no) { + // Watch out, we might have a custom error state already set! + if(s->err.http_ret && s->err.http_ret != 200) { + dump_errno(s); + } else { + set_req_state_err(s, err_no); + dump_errno(s); + } + dump_bucket_from_state(s); + if (err_no == -ERR_PERMANENT_REDIRECT || err_no == -ERR_WEBSITE_REDIRECT) { + string dest_uri; + if (!s->redirect.empty()) { + dest_uri = s->redirect; + } else if (!s->region_endpoint.empty()) { + string dest_uri = s->region_endpoint; + /* + * reqest_uri is always start with slash, so we need to remove + * the unnecessary slash at the end of dest_uri. + */ + if (dest_uri[dest_uri.size() - 1] == '/') { + dest_uri = dest_uri.substr(0, dest_uri.size() - 1); + } + dest_uri += s->info.request_uri; + dest_uri += "?"; + dest_uri += s->info.request_params; + } + + if (!dest_uri.empty()) { + dump_redirect(s, dest_uri); } - dest_uri += s->info.request_uri; - dest_uri += "?"; - dest_uri += s->info.request_params; } - if (!dest_uri.empty()) { - dump_redirect(s, dest_uri); + if (!error_content.empty()) { + /* + * TODO we must add all error entries as headers here: + * when having a working errordoc, then the s3 error fields are + * rendered as HTTP headers, e.g.: + * x-amz-error-code: NoSuchKey + * x-amz-error-message: The specified key does not exist. + * x-amz-error-detail-Key: foo + */ + end_header(s, op, NULL, error_content.size(), false, true); + s->cio->write(error_content.c_str(), error_content.size()); + } else { + end_header(s, op); } - } - if (!error_content.empty()) { - ldout(s->cct, 20) << "error_content is set, we need to serve it INSTEAD of firing the formatter" << dendl; - /* - * FIXME we must add all error entries as headers here: - * when having a working errordoc, then the s3 error fields are rendered as HTTP headers, e.g.: - * - * x-amz-error-code: NoSuchKey - * x-amz-error-message: The specified key does not exist. - * x-amz-error-detail-Key: foo - */ - end_header(s, op, NULL, NO_CONTENT_LENGTH, false, true); - s->cio->write(error_content.c_str(), error_content.size()); - s->formatter->reset(); - } else { - end_header(s, op); - rgw_flush_formatter_and_reset(s, s->formatter); + rgw_flush_formatter(s, s->formatter); } perfcounter->inc(l_rgw_failed_req); } diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 181fa982774b5..cc1f9ef7d857f 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -193,9 +193,14 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_ } done: - set_req_state_err(s, (partial_content && !ret) ? STATUS_PARTIAL_CONTENT : ret); - - dump_errno(s); + if(custom_http_ret) { + set_req_state_err(s, 0); + dump_errno(s, custom_http_ret); + } else { + set_req_state_err(s, (partial_content && !ret) ? STATUS_PARTIAL_CONTENT + : ret); + dump_errno(s); + } for (riter = response_attrs.begin(); riter != response_attrs.end(); ++riter) { s->cio->print("%s: %s\r\n", riter->first.c_str(), riter->second.c_str()); @@ -3221,47 +3226,87 @@ RGWOp *RGWHandler_ObjStore_S3Website::op_head() return get_obj_op(false); } -int RGWHandler_ObjStore_S3Website::get_errordoc(const string errordoc_key, string *error_content) { - ldout(s->cct, 20) << "TODO Serve Custom error page here if bucket has " << dendl; - *error_content = errordoc_key; - // 1. Check if errordoc exists - // 2. Check if errordoc is public - // 3. Fetch errordoc content - /* - * FIXME maybe: need to make sure all of the fields for conditional requests are cleared - */ - RGWGetObj_ObjStore_S3Website *getop = new RGWGetObj_ObjStore_S3Website(true); - getop->set_get_data(true); - getop->init(store, s, this); - - RGWGetObj_CB cb(getop); - rgw_obj obj(s->bucket, errordoc_key); - RGWObjectCtx rctx(store); - //RGWRados::Object op_target(store, s->bucket_info, *static_cast(s->obj_ctx), obj); - RGWRados::Object op_target(store, s->bucket_info, rctx, obj); - RGWRados::Object::Read read_op(&op_target); - - int ret; - int64_t ofs = 0; - int64_t end = -1; - ret = read_op.prepare(&ofs, &end); - if (ret < 0) { - goto done; - } +int RGWHandler_ObjStore_S3Website::serve_errordoc(int http_ret, const string& errordoc_key) { + int ret = 0; + s->formatter->reset(); /* Try to throw it all away */ + + RGWGetObj_ObjStore_S3Website* getop = (RGWGetObj_ObjStore_S3Website*) op_get(); + if(!getop) { + return -1; // Trigger double error handler + } + getop->init(store, s, this); + /*getop->range_str = NULL; + getop->if_mod = NULL; + getop->if_unmod = NULL; + getop->if_match = NULL; + getop->if_nomatch = NULL;*/ + s->object = errordoc_key; + + ret = init_permissions(getop); + if (ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, init_permissions ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + ret = read_permissions(getop); + if (ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, read_permissions ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + if(http_ret) { + getop->set_custom_http_response(http_ret); + } + + ret = getop->init_processing(); + if(ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, init_processing ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + ret = getop->verify_op_mask(); + if(ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, verify_op_mask ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + ret = getop->verify_permission(); + if(ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, verify_permission ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + ret = getop->verify_params(); + if(ret < 0) { + ldout(s->cct, 20) << "serve_errordoc failed, verify_params ret=" << ret << dendl; + return -1; // Trigger double error handler + } + + // No going back now + getop->pre_exec(); + /* + * FIXME Missing headers: + * With a working errordoc, the s3 error fields are rendered as HTTP headers, + * x-amz-error-code: NoSuchKey + * x-amz-error-message: The specified key does not exist. + * x-amz-error-detail-Key: foo + */ + getop->execute(); + getop->complete(); + return 0; - ret = read_op.iterate(ofs, end, &cb); // FIXME: need to know the final size? -done: - delete getop; - return ret; } - -int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string *error_content) { - const struct rgw_http_errors *r; + +int RGWHandler_ObjStore_S3Website::error_handler(int err_no, + string* error_content) { + int new_err_no = -1; + const struct rgw_http_errors* r; int http_error_code = -1; - r = search_err(err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); + r = search_err(err_no > 0 ? err_no : -err_no, RGW_HTTP_ERRORS, ARRAY_LEN(RGW_HTTP_ERRORS)); if (r) { http_error_code = r->http_ret; } + ldout(s->cct, 10) << "RGWHandler_ObjStore_S3Website::error_handler err_no=" << err_no << " http_ret=" << http_error_code << dendl; RGWBWRoutingRule rrule; bool should_redirect = s->bucket_info.website_conf.should_redirect(s->object.name, http_error_code, &rrule); @@ -3276,8 +3321,18 @@ int RGWHandler_ObjStore_S3Website::error_handler(int err_no, string *error_conte s->err.http_ret = redirect_code; // Apply a custom HTTP response code ldout(s->cct, 10) << "error handler redirect code=" << redirect_code << " proto+host:" << protocol << "://" << hostname << " -> " << s->redirect << dendl; return -ERR_WEBSITE_REDIRECT; + } else if (err_no == -ERR_WEBSITE_REDIRECT) { + // Do nothing here, this redirect will be handled in abort_early's ERR_WEBSITE_REDIRECT block + // Do NOT fire the ErrorDoc handler } else if (!s->bucket_info.website_conf.error_doc.empty()) { - RGWHandler_ObjStore_S3Website::get_errordoc(s->bucket_info.website_conf.error_doc, error_content); + /* This serves an entire page! + On success, it will return zero, and no further content should be sent to the socket + On failure, we need the double-error handler + */ + new_err_no = RGWHandler_ObjStore_S3Website::serve_errordoc(http_error_code, s->bucket_info.website_conf.error_doc); + if(new_err_no && new_err_no != -1) { + err_no = new_err_no; + } } else { ldout(s->cct, 20) << "No special error handling today!" << dendl; } diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index d0ab281c42a73..3efad1079722e 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -20,12 +20,17 @@ void rgw_get_errno_s3(struct rgw_http_errors *e, int err_no); class RGWGetObj_ObjStore_S3 : public RGWGetObj_ObjStore { +protected: + // Serving a custom error page from an object is really a 200 response with + // just the status line altered. + int custom_http_ret = 0; public: RGWGetObj_ObjStore_S3() {} ~RGWGetObj_ObjStore_S3() {} int send_response_data_error(); int send_response_data(bufferlist& bl, off_t ofs, off_t len); + void set_custom_http_response(int http_ret) { custom_http_ret = http_ret; } }; class RGWListBuckets_ObjStore_S3 : public RGWListBuckets_ObjStore { diff --git a/src/rgw/rgw_rest_s3website.h b/src/rgw/rgw_rest_s3website.h index 06a22ccda22d7..f8ead0ba7c61b 100644 --- a/src/rgw/rgw_rest_s3website.h +++ b/src/rgw/rgw_rest_s3website.h @@ -32,7 +32,7 @@ class RGWHandler_ObjStore_S3Website : public RGWHandler_ObjStore_S3 { RGWOp *op_copy() { return NULL; } RGWOp *op_options() { return NULL; } - int get_errordoc(const string errordoc_key, string *error_content); + int serve_errordoc(int http_ret, const string &errordoc_key); public: RGWHandler_ObjStore_S3Website() : RGWHandler_ObjStore_S3() {} virtual ~RGWHandler_ObjStore_S3Website() {} @@ -69,6 +69,7 @@ class RGWHandler_ObjStore_Bucket_S3Website : public RGWHandler_ObjStore_S3Websit // TODO: do we actually need this? class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 { + friend class RGWHandler_REST_S3Website; private: bool is_errordoc_request; public: @@ -86,7 +87,7 @@ class RGWGetObj_ObjStore_S3Website : public RGWGetObj_ObjStore_S3 if_unmod = NULL; if_match = NULL; if_nomatch = NULL; - return 0; + return 0; } else { return RGWGetObj_ObjStore_S3::get_params(); } From 490a4f5cdec3e7a3609761ac6a5ecd6ba49f3e40 Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Tue, 17 May 2016 17:38:38 -0700 Subject: [PATCH 77/90] rgw/s3website: whitespace style fixes Signed-off-by: Robin H. Johnson Conflicts: src/rgw/rgw_rest_s3.cc --- src/rgw/rgw_rest.cc | 4 ++-- src/rgw/rgw_rest_s3.cc | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index bafd3a9db5f49..2f0f28b304a42 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -709,9 +709,9 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no, RGWHandler* handler // If the error handler(s) above dealt with it completely, they should have // returned 0. If non-zero, we need to continue here. - if(err_no) { + if (err_no) { // Watch out, we might have a custom error state already set! - if(s->err.http_ret && s->err.http_ret != 200) { + if (s->err.http_ret && s->err.http_ret != 200) { dump_errno(s); } else { set_req_state_err(s, err_no); diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index cc1f9ef7d857f..19da7bf7acee6 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -193,7 +193,7 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_ } done: - if(custom_http_ret) { + if (custom_http_ret) { set_req_state_err(s, 0); dump_errno(s, custom_http_ret); } else { @@ -3254,30 +3254,30 @@ int RGWHandler_ObjStore_S3Website::serve_errordoc(int http_ret, const string& er return -1; // Trigger double error handler } - if(http_ret) { + if (http_ret) { getop->set_custom_http_response(http_ret); } ret = getop->init_processing(); - if(ret < 0) { + if (ret < 0) { ldout(s->cct, 20) << "serve_errordoc failed, init_processing ret=" << ret << dendl; return -1; // Trigger double error handler } ret = getop->verify_op_mask(); - if(ret < 0) { + if (ret < 0) { ldout(s->cct, 20) << "serve_errordoc failed, verify_op_mask ret=" << ret << dendl; return -1; // Trigger double error handler } ret = getop->verify_permission(); - if(ret < 0) { + if (ret < 0) { ldout(s->cct, 20) << "serve_errordoc failed, verify_permission ret=" << ret << dendl; return -1; // Trigger double error handler } ret = getop->verify_params(); - if(ret < 0) { + if (ret < 0) { ldout(s->cct, 20) << "serve_errordoc failed, verify_params ret=" << ret << dendl; return -1; // Trigger double error handler } From e4aa51ef03f88b3db4a024b71ffd39f6637e6a8d Mon Sep 17 00:00:00 2001 From: "Robin H. Johnson" Date: Fri, 20 May 2016 16:00:33 -0700 Subject: [PATCH 78/90] rgw: fix manager selection when APIs customized When modifying rgw_enable_apis per RGW instance, such as for staticsites, you can end up with RESTManager instance being null in some cases, which returns a HTTP 405 MethodNotAllowed to all requests. Example configuration to trigger the bug: rgw_enable_apis = s3website Backport: jewel X-Note: Patch from Yehuda in private IRC discussion, 2016/05/20. Fixes: http://tracker.ceph.com/issues/15973 Fixes: http://tracker.ceph.com/issues/15974 Signed-off-by: Robin H. Johnson (cherry picked from commit 7c7a465b55f7100eab0f140bf54f9420abd1c776) --- src/rgw/rgw_rest.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 2f0f28b304a42..172a6691fbf9d 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -1474,9 +1474,6 @@ RGWRESTMgr *RGWRESTMgr::get_resource_mgr(struct req_state *s, const string& uri, { *out_uri = uri; - if (resources_by_size.empty()) - return this; - multimap::reverse_iterator iter; for (iter = resources_by_size.rbegin(); iter != resources_by_size.rend(); ++iter) { From 7d8411088664f58aaa6ff5457c2c8fed164a5bdb Mon Sep 17 00:00:00 2001 From: Gaurav Bafna Date: Tue, 28 Jun 2016 00:09:15 +1100 Subject: [PATCH 79/90] Fixing HTPP return code and formatting error --- src/common/Formatter.cc | 9 +++++---- src/rgw/rgw_rest.cc | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 34dcc9cf6b530..eec5943a6733e 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -131,8 +131,6 @@ void JSONFormatter::flush(std::ostream& os) { finish_pending_string(); os << m_ss.str(); - if (m_pretty) - os << "\n"; m_ss.clear(); m_ss.str(""); } @@ -322,8 +320,11 @@ XMLFormatter::XMLFormatter(bool pretty) void XMLFormatter::flush(std::ostream& os) { finish_pending_string(); - os << m_ss.str(); - if (m_pretty) + std::string m_ss_str = m_ss.str(); + os << m_ss_str; + /* There is a small catch here. If the rest of the formatter had NO output, + * we should NOT output a newline. This primarily triggers on HTTP redirects */ + if (m_pretty && !m_ss_str.empty()) os << "\n"; m_ss.clear(); m_ss.str(""); diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index 172a6691fbf9d..c954d6a6f8221 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -351,7 +351,7 @@ void dump_errno(struct req_state *s, int err) { char buf[32]; snprintf(buf, sizeof(buf), "%d", err); - dump_status(s, buf, http_status_names[s->err.http_ret]); + dump_status(s, buf, http_status_names[err]); } void dump_string_header(struct req_state *s, const char *name, const char *val) From 9e286e4504ff7773bc4f3f205c2354a48fbfbd90 Mon Sep 17 00:00:00 2001 From: Gaurav Bafna Date: Wed, 6 Jul 2016 16:16:02 +1100 Subject: [PATCH 80/90] Removing useless file --- src/rest_blame | 1724 ------------------------------------------------ 1 file changed, 1724 deletions(-) delete mode 100644 src/rest_blame diff --git a/src/rest_blame b/src/rest_blame deleted file mode 100644 index 990a98208220c..0000000000000 --- a/src/rest_blame +++ /dev/null @@ -1,1724 +0,0 @@ -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 1) // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 2) // vim: ts=8 sw=2 smarttab -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 3) /* -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 4) * Ceph - scalable distributed file system -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 5) * -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 6) * Copyright (C) 2004-2009 Sage Weil -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 7) * -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 8) * This is free software; you can redistribute it and/or -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 9) * modify it under the terms of the GNU Lesser General Public -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 10) * License version 2.1, as published by the Free Software -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 11) * Foundation. See file COPYING. -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 12) * -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 13) */ -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 14) -f4b9d9d8 src/rgw/rgw_common.h (Markus Elfring 2010-06-12 15:04:11 +0200 15) #ifndef CEPH_RGW_COMMON_H -f4b9d9d8 src/rgw/rgw_common.h (Markus Elfring 2010-06-12 15:04:11 +0200 16) #define CEPH_RGW_COMMON_H -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 17) -d95367cb src/rgw/rgw_common.h (Tommi Virtanen 2011-03-08 13:49:56 -0800 18) #include "common/ceph_crypto.h" -1c98da66 src/rgw/rgw_common.h (Colin P. McCabe 2011-05-10 14:08:42 -0700 19) #include "common/debug.h" -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 20) #include "common/perf_counters.h" -468c7dce src/rgw/rgw_common.h (Sage Weil 2011-10-09 15:27:10 -0700 21) -468c7dce src/rgw/rgw_common.h (Sage Weil 2011-10-09 15:27:10 -0700 22) #include "acconfig.h" -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 23) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 24) #include -f2424dfb src/rgw/rgw_common.h (Yehuda Sadeh 2010-12-03 14:45:59 -0800 25) #include -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 26) #include -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 27) #include -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 28) #include "include/types.h" -c9135519 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-08 16:49:49 -0800 29) #include "include/utime.h" -e345dfe0 src/rgw/rgw_common.h (Caleb Miles 2013-02-05 14:10:03 -0500 30) #include "rgw_acl.h" -f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 31) #include "rgw_cors.h" -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 32) #include "rgw_quota.h" -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 33) #include "rgw_string.h" -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 34) #include "rgw_website.h" -a0d238c3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-10 22:02:20 -0700 35) #include "cls/version/cls_version_types.h" -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 36) #include "cls/user/cls_user_types.h" -54f2e0ac src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 17:31:12 -0700 37) #include "cls/rgw/cls_rgw_types.h" -a0d238c3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-10 22:02:20 -0700 38) #include "include/rados/librados.hpp" -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 39) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 40) using namespace std; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 41) -76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 42) namespace ceph { -76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 43) class Formatter; -76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 44) } -76880e3e src/rgw/rgw_common.h (Colin P. McCabe 2011-08-04 14:43:55 -0700 45) -a772c8bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-16 10:57:48 -0700 46) using ceph::crypto::MD5; -a772c8bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-16 10:57:48 -0700 47) -37c88295 src/rgw/rgw_common.h (Sage Weil 2011-10-04 15:36:15 -0700 48) -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 49) #define RGW_ATTR_PREFIX "user.rgw." -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 50) -7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 51) #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" -7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 52) #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" -7ec64db4 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-13 21:59:37 -0700 53) -7b3ff369 src/rgw/rgw_common.h (Shivanshu Goswami 2016-02-22 21:16:11 +0000 54) #define RGW_AMZ_META_PREFIX "x-jcs-meta-" -d6d3bf06 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-03 17:36:50 -0700 55) -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 56) #define RGW_SYS_PARAM_PREFIX "rgwx-" -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 57) -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 58) #define RGW_ATTR_ACL RGW_ATTR_PREFIX "acl" -f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 59) #define RGW_ATTR_CORS RGW_ATTR_PREFIX "cors" -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 60) #define RGW_ATTR_ETAG RGW_ATTR_PREFIX "etag" -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 61) #define RGW_ATTR_BUCKETS RGW_ATTR_PREFIX "buckets" -d6d3bf06 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-03 17:36:50 -0700 62) #define RGW_ATTR_META_PREFIX RGW_ATTR_PREFIX RGW_AMZ_META_PREFIX -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 63) #define RGW_ATTR_CONTENT_TYPE RGW_ATTR_PREFIX "content_type" -f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 64) #define RGW_ATTR_CACHE_CONTROL RGW_ATTR_PREFIX "cache_control" -f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 65) #define RGW_ATTR_CONTENT_DISP RGW_ATTR_PREFIX "content_disposition" -f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 66) #define RGW_ATTR_CONTENT_ENC RGW_ATTR_PREFIX "content_encoding" -f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 67) #define RGW_ATTR_CONTENT_LANG RGW_ATTR_PREFIX "content_language" -f4a0b2d9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-08 16:13:04 -0700 68) #define RGW_ATTR_EXPIRES RGW_ATTR_PREFIX "expires" -8d63e140 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-02 16:29:16 -0700 69) #define RGW_ATTR_ID_TAG RGW_ATTR_PREFIX "idtag" -70cdd5da src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-03 16:59:33 -0700 70) #define RGW_ATTR_SHADOW_OBJ RGW_ATTR_PREFIX "shadow_name" -c076e351 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-01 14:03:57 -0800 71) #define RGW_ATTR_MANIFEST RGW_ATTR_PREFIX "manifest" -4d2a05f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-08-22 17:16:05 -0700 72) #define RGW_ATTR_USER_MANIFEST RGW_ATTR_PREFIX "user_manifest" -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 73) -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 74) #define RGW_ATTR_OLH_PREFIX RGW_ATTR_PREFIX "olh." -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 75) -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 76) #define RGW_ATTR_OLH_INFO RGW_ATTR_OLH_PREFIX "info" -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 77) #define RGW_ATTR_OLH_VER RGW_ATTR_OLH_PREFIX "ver" -01b8e614 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-03 17:04:46 -0800 78) #define RGW_ATTR_OLH_ID_TAG RGW_ATTR_OLH_PREFIX "idtag" -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 79) #define RGW_ATTR_OLH_PENDING_PREFIX RGW_ATTR_OLH_PREFIX "pending." -57629b30 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-03 13:02:26 -0700 80) -478fe5ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-03-22 11:01:02 -0700 81) #define RGW_BUCKETS_OBJ_SUFFIX ".buckets" -fa8fa401 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-28 15:32:05 -0800 82) -8f1beb1b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-20 17:09:27 -0700 83) #define RGW_MAX_PENDING_CHUNKS 16 -44cb0763 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-13 12:19:35 -0800 84) #define RGW_MAX_PUT_SIZE (5ULL*1024*1024*1024) -24523913 src/rgw/rgw_common.h (Caleb Miles 2012-12-04 16:36:17 -0500 85) #define RGW_MIN_MULTIPART_SIZE (5ULL*1024*1024) -925e2092 src/rgw/rgw_common.h (Yehuda Sadeh 2010-07-19 16:50:43 -0700 86) -42d873e9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-24 12:30:29 -0700 87) #define RGW_FORMAT_PLAIN 0 -fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 88) #define RGW_FORMAT_XML 1 -fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 89) #define RGW_FORMAT_JSON 2 -cc544de6 src/rgw/rgw_common.h (Robin H. Johnson 2015-08-24 02:42:56 +0000 90) #define RGW_FORMAT_HTML 3 -fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 91) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 92) #define RGW_CAP_READ 0x1 -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 93) #define RGW_CAP_WRITE 0x2 -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 94) #define RGW_CAP_ALL (RGW_CAP_READ | RGW_CAP_WRITE) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 95) -e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 96) #define RGW_PROTO_SWIFT 0x1 -e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 97) #define RGW_PROTO_SWIFT_AUTH 0x2 -e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 98) #define RGW_PROTO_S3 0x4 -e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 99) #define RGW_PROTO_WEBSITE 0x8 -b738b72c src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-23 16:50:21 -0700 100) -4ca8054c src/rgw/rgw_common.h (Sage Weil 2011-06-17 09:26:32 -0700 101) #define RGW_SUSPENDED_USER_AUID (uint64_t)-2 -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 102) -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 103) #define RGW_OP_TYPE_READ 0x01 -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 104) #define RGW_OP_TYPE_WRITE 0x02 -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 105) #define RGW_OP_TYPE_DELETE 0x04 -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 106) -c821da95 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 16:43:10 -0700 107) #define RGW_OP_TYPE_MODIFY (RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 108) #define RGW_OP_TYPE_ALL (RGW_OP_TYPE_READ | RGW_OP_TYPE_WRITE | RGW_OP_TYPE_DELETE) -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 109) -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 110) #define RGW_DEFAULT_MAX_BUCKETS 1000 -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 111) -1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 112) #define RGW_DEFER_TO_BUCKET_ACLS_RECURSE 1 -1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 113) #define RGW_DEFER_TO_BUCKET_ACLS_FULL_CONTROL 2 -1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 114) -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 115) #define STATUS_CREATED 1900 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 116) #define STATUS_ACCEPTED 1901 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 117) #define STATUS_NO_CONTENT 1902 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 118) #define STATUS_PARTIAL_CONTENT 1903 -3faf6ab5 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 09:40:39 -0700 119) #define STATUS_REDIRECT 1904 -4f9855e4 src/rgw/rgw_common.h (Greg Farnum 2013-07-16 12:23:13 -0700 120) #define STATUS_NO_APPLY 1905 -81b62b5c src/rgw/rgw_common.h (Greg Farnum 2013-07-25 16:03:54 -0700 121) #define STATUS_APPLIED 1906 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 122) -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 123) #define ERR_INVALID_BUCKET_NAME 2000 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 124) #define ERR_INVALID_OBJECT_NAME 2001 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 125) #define ERR_NO_SUCH_BUCKET 2002 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 126) #define ERR_METHOD_NOT_ALLOWED 2003 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 127) #define ERR_INVALID_DIGEST 2004 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 128) #define ERR_BAD_DIGEST 2005 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 129) #define ERR_UNRESOLVABLE_EMAIL 2006 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 130) #define ERR_INVALID_PART 2007 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 131) #define ERR_INVALID_PART_ORDER 2008 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 132) #define ERR_NO_SUCH_UPLOAD 2009 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 133) #define ERR_REQUEST_TIMEOUT 2010 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 134) #define ERR_LENGTH_REQUIRED 2011 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 135) #define ERR_REQUEST_TIME_SKEWED 2012 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 136) #define ERR_BUCKET_EXISTS 2013 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 137) #define ERR_BAD_URL 2014 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 138) #define ERR_PRECONDITION_FAILED 2015 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 139) #define ERR_NOT_MODIFIED 2016 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 140) #define ERR_INVALID_UTF8 2017 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 141) #define ERR_UNPROCESSABLE_ENTITY 2018 -44cb0763 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-13 12:19:35 -0800 142) #define ERR_TOO_LARGE 2019 -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 143) #define ERR_TOO_MANY_BUCKETS 2020 -b415fd21 src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-12 14:42:03 -0700 144) #define ERR_INVALID_REQUEST 2021 -30d11f42 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 15:36:07 -0700 145) #define ERR_TOO_SMALL 2022 -f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 146) #define ERR_NOT_FOUND 2023 -0f4c67f1 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-17 13:07:24 -0700 147) #define ERR_PERMANENT_REDIRECT 2024 -068baae7 src/rgw/rgw_common.h (Yehuda Sadeh 2013-08-09 11:52:25 -0700 148) #define ERR_LOCKED 2025 -bc98013f src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-01 11:45:03 -0700 149) #define ERR_QUOTA_EXCEEDED 2026 -ef75d720 src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-16 09:11:20 -0800 150) #define ERR_SIGNATURE_NO_MATCH 2027 -56af795b src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-16 12:27:54 -0800 151) #define ERR_INVALID_ACCESS_KEY 2028 -8bcbfbe1 src/rgw/rgw_common.h (Shivanshu Goswami 2016-03-09 23:30:50 +0000 152) #define ERR_BUCKET_ALREADY_OWNED 2029 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 153) #define ERR_USER_SUSPENDED 2100 -0c78f0dc src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 17:20:51 -0700 154) #define ERR_INTERNAL_ERROR 2200 -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 155) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 156) #ifndef UINT32_MAX -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 157) #define UINT32_MAX (4294967295) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 158) #endif -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 159) -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 160) typedef void *RGWAccessHandle; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 161) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 162) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 163) /* perf counter */ -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 164) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 165) extern PerfCounters *perfcounter; -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 166) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 167) extern int rgw_perf_start(CephContext *cct); -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 168) extern void rgw_perf_stop(CephContext *cct); -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 169) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 170) enum { -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 171) l_rgw_first = 15000, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 172) l_rgw_req, -cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 173) l_rgw_failed_req, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 174) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 175) l_rgw_get, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 176) l_rgw_get_b, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 177) l_rgw_get_lat, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 178) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 179) l_rgw_put, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 180) l_rgw_put_b, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 181) l_rgw_put_lat, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 182) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 183) l_rgw_qlen, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 184) l_rgw_qactive, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 185) -cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 186) l_rgw_cache_hit, -cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 187) l_rgw_cache_miss, -cf566550 src/rgw/rgw_common.h (Greg Farnum 2011-11-08 09:49:22 -0800 188) -c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 189) l_rgw_keystone_token_cache_hit, -c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 190) l_rgw_keystone_token_cache_miss, -c62f3dd8 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-31 14:49:12 -0700 191) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 192) l_rgw_last, -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 193) }; -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 194) -0fe0f9db src/rgw/rgw_common.h (Sage Weil 2011-10-11 14:00:42 -0700 195) -232cd6b3 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 14:22:55 -0700 196) /* size should be the required string size + 1 */ -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 197) extern int gen_rand_base64(CephContext *cct, char *dest, int size); -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 198) extern int gen_rand_alphanumeric(CephContext *cct, char *dest, int size); -f6bb8255 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 13:36:34 -0700 199) extern int gen_rand_alphanumeric_lower(CephContext *cct, char *dest, int size); -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 200) extern int gen_rand_alphanumeric_upper(CephContext *cct, char *dest, int size); -caefe693 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-23 17:28:14 -0800 201) extern int gen_rand_alphanumeric_no_underscore(CephContext *cct, char *dest, int size); -6b365144 src/rgw/rgw_common.h (Yehuda Sadeh 2015-07-20 20:27:33 -0700 202) extern int gen_rand_alphanumeric_plain(CephContext *cct, char *dest, int size); -232cd6b3 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 14:22:55 -0700 203) -d139f8dd src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 14:05:00 -0700 204) extern int gen_rand_alphanumeric_lower(CephContext *cct, string *str, int length); -d139f8dd src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-04 14:05:00 -0700 205) -7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 206) enum RGWIntentEvent { -1fe75ee6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-30 17:00:37 -0800 207) DEL_OBJ = 0, -1fe75ee6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-01-30 17:00:37 -0800 208) DEL_DIR = 1, -7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 209) }; -7cc208bb src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-08 16:44:13 -0700 210) -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 211) enum RGWObjCategory { -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 212) RGW_OBJ_CATEGORY_NONE = 0, -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 213) RGW_OBJ_CATEGORY_MAIN = 1, -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 214) RGW_OBJ_CATEGORY_SHADOW = 2, -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 215) RGW_OBJ_CATEGORY_MULTIMETA = 3, -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 216) }; -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 217) -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 218) /** Store error returns for output at a different point in the program */ -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 219) struct rgw_err { -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 220) rgw_err(); -303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 221) rgw_err(int http, const std::string &s3); -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 222) void clear(); -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 223) bool is_clear() const; -9b7f223a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 11:15:11 -0700 224) bool is_err() const; -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 225) friend std::ostream& operator<<(std::ostream& oss, const rgw_err &err); -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 226) -303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 227) int http_ret; -8836b844 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-17 04:15:10 -0700 228) int ret; -303420bf src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 10:52:14 -0700 229) std::string s3_code; -b5f6eb12 src/rgw/rgw_common.h (Colin P. McCabe 2011-04-14 16:14:48 -0700 230) std::string message; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 231) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 232) -d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 233) /* Helper class used for RGWHTTPArgs parsing */ -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 234) class NameVal -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 235) { -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 236) string str; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 237) string name; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 238) string val; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 239) public: -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 240) NameVal(string nv) : str(nv) {} -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 241) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 242) int parse(); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 243) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 244) string& get_name() { return name; } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 245) string& get_val() { return val; } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 246) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 247) -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 248) /** Stores the XML arguments associated with the HTTP request in req_state*/ -d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 249) class RGWHTTPArgs -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 250) { -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 251) string str, empty_str; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 252) map val_map; -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 253) map sys_val_map; -a0d521b2 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-27 13:35:47 -0700 254) map sub_resources; -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 255) -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 256) bool has_resp_modifier; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 257) public: -d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 258) RGWHTTPArgs() : has_resp_modifier(false) {} -e92e2971 src/rgw/rgw_common.h (Robin H. Johnson 2015-06-09 03:33:22 +0000 259) -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 260) /** Set the arguments; as received */ -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 261) void set(string s) { -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 262) has_resp_modifier = false; -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 263) val_map.clear(); -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 264) sub_resources.clear(); -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 265) str = s; -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 266) } -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 267) /** parse the received arguments */ -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 268) int parse(); -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 269) /** Get the value for a specific argument parameter */ -ed04755a src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-24 14:34:23 -0700 270) string& get(const string& name, bool *exists = NULL); -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 271) string& get(const char *name, bool *exists = NULL); -9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 272) int get_bool(const string& name, bool *val, bool *exists); -9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 273) int get_bool(const char *name, bool *val, bool *exists); -e274e109 src/rgw/rgw_common.h (Yehuda Sadeh 2014-05-07 16:19:56 -0700 274) void get_bool(const char *name, bool *val, bool def_val); -9abec309 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-23 12:31:31 -0700 275) -d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 276) /** see if a parameter is contained in this RGWHTTPArgs */ -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 277) bool exists(const char *name) { -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 278) map::iterator iter = val_map.find(name); -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 279) return (iter != val_map.end()); -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 280) } -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 281) bool sub_resource_exists(const char *name) { -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 282) map::iterator iter = sub_resources.find(name); -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 283) return (iter != sub_resources.end()); -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 284) } -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 285) map& get_params() { -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 286) return val_map; -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 287) } -cb2d3660 src/rgw/rgw_common.h (Sage Weil 2011-09-29 23:17:12 -0700 288) map& get_sub_resources() { return sub_resources; } -648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 289) unsigned get_num_params() { -648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 290) return val_map.size(); -648c3bc2 src/rgw/rgw_common.h (Babu Shanmugam 2013-04-26 18:44:16 +0530 291) } -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 292) bool has_response_modifier() { -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 293) return has_resp_modifier; -97c1562d src/rgw/rgw_common.h (Yehuda Sadeh 2012-07-06 13:14:53 -0700 294) } -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 295) void set_system() { /* make all system params visible */ -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 296) map::iterator iter; -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 297) for (iter = sys_val_map.begin(); iter != sys_val_map.end(); ++iter) { -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 298) val_map[iter->first] = iter->second; -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 299) } -4dafea43 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-24 18:31:11 -0700 300) } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 301) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 302) -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 303) class RGWConf; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 304) -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 305) class RGWEnv { -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 306) std::map env_map; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 307) public: -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 308) RGWConf *conf; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 309) -cc40f115 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 14:26:16 -0700 310) RGWEnv(); -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 311) ~RGWEnv(); -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 312) void init(CephContext *cct); -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 313) void init(CephContext *cct, char **envp); -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 314) void set(const char *name, const char *val); -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 315) const char *get(const char *name, const char *def_val = NULL); -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 316) int get_int(const char *name, int def_val = 0); -5d606c22 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-14 15:55:05 -0700 317) bool get_bool(const char *name, bool def_val = 0); -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 318) size_t get_size(const char *name, size_t def_val = 0); -eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 319) bool exists(const char *name); -eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 320) bool exists_prefix(const char *prefix); -0c805b6c src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 13:09:08 -0700 321) -0c805b6c src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 13:09:08 -0700 322) void remove(const char *name); -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 323) -fe6cd9bc src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-22 13:53:59 -0700 324) std::map& get_map() { return env_map; } -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 325) }; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 326) -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 327) class RGWConf { -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 328) friend class RGWEnv; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 329) protected: -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 330) void init(CephContext *cct, RGWEnv * env); -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 331) public: -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 332) RGWConf() : -1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 333) enable_ops_log(1), enable_usage_log(1), defer_to_bucket_acls(0) {} -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 334) -ec689e3e src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-05 11:57:35 -0700 335) int enable_ops_log; -744a1b31 src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 11:01:56 -0700 336) int enable_usage_log; -1d7c2041 src/rgw/rgw_common.h (Liam Monahan 2013-10-01 17:10:05 -0400 337) uint8_t defer_to_bucket_acls; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 338) }; -059019c9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-11 13:41:40 -0700 339) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 340) enum http_op { -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 341) OP_GET, -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 342) OP_PUT, -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 343) OP_DELETE, -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 344) OP_HEAD, -9e8484e8 src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-26 15:18:48 -0700 345) OP_POST, -87941128 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-10 14:56:10 -0800 346) OP_COPY, -f165049c src/rgw/rgw_common.h (Babu Shanmugam 2013-03-05 09:22:55 +0530 347) OP_OPTIONS, -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 348) OP_UNKNOWN, -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 349) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 350) -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 351) class RGWAccessControlPolicy; -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 352) class JSONObj; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 353) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 354) struct RGWAccessKey { -6dcf462c src/rgw/rgw_common.h (Robin H. Johnson 2014-01-18 17:49:06 -0800 355) string id; // AccessKey -6dcf462c src/rgw/rgw_common.h (Robin H. Johnson 2014-01-18 17:49:06 -0800 356) string key; // SecretKey -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 357) string subuser; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 358) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 359) RGWAccessKey() {} -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 360) void encode(bufferlist& bl) const { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 361) ENCODE_START(2, 2, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 362) ::encode(id, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 363) ::encode(key, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 364) ::encode(subuser, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 365) ENCODE_FINISH(bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 366) } -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 367) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 368) void decode(bufferlist::iterator& bl) { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 369) DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 370) ::decode(id, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 371) ::decode(key, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 372) ::decode(subuser, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 373) DECODE_FINISH(bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 374) } -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 375) void dump(Formatter *f) const; -a7096f8f src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-20 12:13:31 -0700 376) void dump_plain(Formatter *f) const; -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 377) void dump(Formatter *f, const string& user, bool swift) const; -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 378) static void generate_test_instances(list& o); -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 379) -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 380) void decode_json(JSONObj *obj); -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 381) void decode_json(JSONObj *obj, bool swift); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 382) }; -60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 383) WRITE_CLASS_ENCODER(RGWAccessKey) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 384) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 385) struct RGWSubUser { -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 386) string name; -c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 387) uint32_t perm_mask; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 388) -c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 389) RGWSubUser() : perm_mask(0) {} -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 390) void encode(bufferlist& bl) const { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 391) ENCODE_START(2, 2, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 392) ::encode(name, bl); -c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 393) ::encode(perm_mask, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 394) ENCODE_FINISH(bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 395) } -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 396) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 397) void decode(bufferlist::iterator& bl) { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 398) DECODE_START_LEGACY_COMPAT_LEN_32(2, 2, 2, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 399) ::decode(name, bl); -c167a28d src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-23 15:12:48 -0700 400) ::decode(perm_mask, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 401) DECODE_FINISH(bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 402) } -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 403) void dump(Formatter *f) const; -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 404) void dump(Formatter *f, const string& user) const; -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 405) static void generate_test_instances(list& o); -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 406) -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 407) void decode_json(JSONObj *obj); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 408) }; -60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 409) WRITE_CLASS_ENCODER(RGWSubUser) -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 410) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 411) class RGWUserCaps -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 412) { -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 413) map caps; -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 414) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 415) int get_cap(const string& cap, string& type, uint32_t *perm); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 416) int add_cap(const string& cap); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 417) int remove_cap(const string& cap); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 418) public: -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 419) static int parse_cap_perm(const string& str, uint32_t *perm); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 420) int add_from_string(const string& str); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 421) int remove_from_string(const string& str); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 422) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 423) void encode(bufferlist& bl) const { -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 424) ENCODE_START(1, 1, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 425) ::encode(caps, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 426) ENCODE_FINISH(bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 427) } -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 428) void decode(bufferlist::iterator& bl) { -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 429) DECODE_START(1, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 430) ::decode(caps, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 431) DECODE_FINISH(bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 432) } -511e639e src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 11:57:04 -0700 433) int check_cap(const string& cap, uint32_t perm); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 434) void dump(Formatter *f) const; -b07f3cda src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-12 09:40:12 -0800 435) void dump(Formatter *f, const char *name) const; -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 436) -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 437) void decode_json(JSONObj *obj); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 438) }; -60b1071d src/rgw/rgw_common.h (Daniel J. Hofmann 2014-05-09 15:07:15 +0200 439) WRITE_CLASS_ENCODER(RGWUserCaps) -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 440) -3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 441) void encode_json(const char *name, const obj_version& v, Formatter *f); -b07f3cda src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-12 09:40:12 -0800 442) void encode_json(const char *name, const RGWUserCaps& val, Formatter *f); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 443) -3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 444) void decode_json_obj(obj_version& v, JSONObj *obj); -3e5cead0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-29 08:11:59 -0700 445) -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 446) struct RGWUserInfo -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 447) { -edc92490 src/rgw/rgw_common.h (Sage Weil 2010-05-07 14:33:42 -0700 448) uint64_t auid; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 449) string user_id; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 450) string display_name; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 451) string user_email; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 452) map access_keys; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 453) map swift_keys; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 454) map subusers; -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 455) __u8 suspended; -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 456) uint32_t max_buckets; -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 457) uint32_t op_mask; -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 458) RGWUserCaps caps; -903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 459) __u8 system; -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 460) string default_placement; -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 461) list placement_tags; -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 462) RGWQuotaInfo bucket_quota; -7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 463) map temp_url_keys; -15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 464) RGWQuotaInfo user_quota; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 465) -d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 466) RGWUserInfo() : auid(0), suspended(0), max_buckets(RGW_DEFAULT_MAX_BUCKETS), op_mask(RGW_OP_TYPE_ALL), system(0) {} -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 467) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 468) void encode(bufferlist& bl) const { -cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 469) ENCODE_START(16, 9, bl); -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 470) ::encode(auid, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 471) string access_key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 472) string secret_key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 473) if (!access_keys.empty()) { -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 474) map::const_iterator iter = access_keys.begin(); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 475) const RGWAccessKey& k = iter->second; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 476) access_key = k.id; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 477) secret_key = k.key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 478) } -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 479) ::encode(access_key, bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 480) ::encode(secret_key, bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 481) ::encode(display_name, bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 482) ::encode(user_email, bl); -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 483) string swift_name; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 484) string swift_key; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 485) if (!swift_keys.empty()) { -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 486) map::const_iterator iter = swift_keys.begin(); -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 487) const RGWAccessKey& k = iter->second; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 488) swift_name = k.id; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 489) swift_key = k.key; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 490) } -ba7ab2f6 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-02 14:56:50 -0700 491) ::encode(swift_name, bl); -ba7ab2f6 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-02 14:56:50 -0700 492) ::encode(swift_key, bl); -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 493) ::encode(user_id, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 494) ::encode(access_keys, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 495) ::encode(subusers, bl); -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 496) ::encode(suspended, bl); -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 497) ::encode(swift_keys, bl); -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 498) ::encode(max_buckets, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 499) ::encode(caps, bl); -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 500) ::encode(op_mask, bl); -903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 501) ::encode(system, bl); -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 502) ::encode(default_placement, bl); -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 503) ::encode(placement_tags, bl); -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 504) ::encode(bucket_quota, bl); -7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 505) ::encode(temp_url_keys, bl); -15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 506) ::encode(user_quota, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 507) ENCODE_FINISH(bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 508) } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 509) void decode(bufferlist::iterator& bl) { -cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 510) DECODE_START_LEGACY_COMPAT_LEN_32(16, 9, 9, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 511) if (struct_v >= 2) ::decode(auid, bl); -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 512) else auid = CEPH_AUTH_UID_DEFAULT; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 513) string access_key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 514) string secret_key; -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 515) ::decode(access_key, bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 516) ::decode(secret_key, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 517) if (struct_v < 6) { -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 518) RGWAccessKey k; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 519) k.id = access_key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 520) k.key = secret_key; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 521) access_keys[access_key] = k; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 522) } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 523) ::decode(display_name, bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 524) ::decode(user_email, bl); -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 525) string swift_name; -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 526) string swift_key; -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 527) if (struct_v >= 3) ::decode(swift_name, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 528) if (struct_v >= 4) ::decode(swift_key, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 529) if (struct_v >= 5) -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 530) ::decode(user_id, bl); -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 531) else -544ce94a src/rgw/rgw_common.h (Yehuda Sadeh 2011-04-15 17:20:44 -0700 532) user_id = access_key; -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 533) if (struct_v >= 6) { -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 534) ::decode(access_keys, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 535) ::decode(subusers, bl); -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 536) } -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 537) suspended = 0; -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 538) if (struct_v >= 7) { -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 539) ::decode(suspended, bl); -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 540) } -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 541) if (struct_v >= 8) { -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 542) ::decode(swift_keys, bl); -f883e638 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-11 10:49:27 -0700 543) } -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 544) if (struct_v >= 10) { -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 545) ::decode(max_buckets, bl); -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 546) } else { -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 547) max_buckets = RGW_DEFAULT_MAX_BUCKETS; -5db4509b src/rgw/rgw_common.h (Yehuda Sadeh 2012-06-11 23:31:09 -0700 548) } -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 549) if (struct_v >= 11) { -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 550) ::decode(caps, bl); -d22aa6c9 src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-25 10:55:19 -0700 551) } -903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 552) if (struct_v >= 12) { -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 553) ::decode(op_mask, bl); -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 554) } else { -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 555) op_mask = RGW_OP_TYPE_ALL; -903d4a04 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-22 11:08:33 -0700 556) } -d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 557) system = 0; -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 558) if (struct_v >= 13) { -d30fc4bd src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-03 17:09:56 -0700 559) ::decode(system, bl); -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 560) ::decode(default_placement, bl); -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 561) ::decode(placement_tags, bl); /* tags of allowed placement rules */ -2fcbf2ba src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 16:16:47 -0700 562) } -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 563) if (struct_v >= 14) { -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 564) ::decode(bucket_quota, bl); -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 565) } -2626101f src/rgw/rgw_common.h (Yehuda Sadeh 2013-11-25 13:41:50 -0800 566) if (struct_v >= 15) { -7ccb513c src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 10:35:53 -0800 567) ::decode(temp_url_keys, bl); -2626101f src/rgw/rgw_common.h (Yehuda Sadeh 2013-11-25 13:41:50 -0800 568) } -cacdfd91 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-27 11:27:56 -0800 569) if (struct_v >= 16) { -15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 570) ::decode(user_quota, bl); -15c01895 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 15:11:08 -0800 571) } -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 572) DECODE_FINISH(bl); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 573) } -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 574) void dump(Formatter *f) const; -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 575) static void generate_test_instances(list& o); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 576) -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 577) void decode_json(JSONObj *obj); -da337013 src/rgw/rgw_common.h (Yehuda Sadeh 2013-02-06 12:48:01 -0800 578) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 579) void clear() { -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 580) user_id.clear(); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 581) display_name.clear(); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 582) user_email.clear(); -83a6efef src/rgw/rgw_common.h (Greg Farnum 2010-03-26 16:29:11 -0700 583) auid = CEPH_AUTH_UID_DEFAULT; -2cf5048f src/rgw/rgw_common.h (Yehuda Sadeh 2011-05-20 15:15:48 -0700 584) access_keys.clear(); -9974b7e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 16:53:38 -0700 585) suspended = 0; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 586) } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 587) }; -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 588) WRITE_CLASS_ENCODER(RGWUserInfo) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 589) -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 590) struct rgw_bucket { -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 591) std::string name; -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 592) std::string data_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 593) std::string data_extra_pool; /* if not set, then we should use data_pool instead */ -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 594) std::string index_pool; -25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 595) std::string marker; -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 596) std::string bucket_id; -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 597) -68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 598) std::string oid; /* -68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 599) * runtime in-memory only info. If not empty, points to the bucket instance object -68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 600) */ -68730d80 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-26 16:40:34 -0700 601) -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 602) rgw_bucket() { } -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 603) rgw_bucket(const cls_user_bucket& b) { -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 604) name = b.name; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 605) data_pool = b.data_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 606) data_extra_pool = b.data_extra_pool; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 607) index_pool = b.index_pool; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 608) marker = b.marker; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 609) bucket_id = b.bucket_id; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 610) } -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 611) rgw_bucket(const char *n) : name(n) { -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 612) assert(*n == '.'); // only rgw private buckets should be initialized without pool -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 613) data_pool = index_pool = n; -25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 614) marker = ""; -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 615) } -0f4c67f1 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-17 13:07:24 -0700 616) rgw_bucket(const char *n, const char *dp, const char *ip, const char *m, const char *id, const char *h) : -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 617) name(n), data_pool(dp), index_pool(ip), marker(m), bucket_id(id) {} -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 618) -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 619) void convert(cls_user_bucket *b) { -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 620) b->name = name; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 621) b->data_pool = data_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 622) b->data_extra_pool = data_extra_pool; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 623) b->index_pool = index_pool; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 624) b->marker = marker; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 625) b->bucket_id = bucket_id; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 626) } -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 627) -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 628) void encode(bufferlist& bl) const { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 629) ENCODE_START(7, 3, bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 630) ::encode(name, bl); -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 631) ::encode(data_pool, bl); -25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 632) ::encode(marker, bl); -c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 633) ::encode(bucket_id, bl); -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 634) ::encode(index_pool, bl); -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 635) ::encode(data_extra_pool, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 636) ENCODE_FINISH(bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 637) } -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 638) void decode(bufferlist::iterator& bl) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 639) DECODE_START_LEGACY_COMPAT_LEN(7, 3, 3, bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 640) ::decode(name, bl); -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 641) ::decode(data_pool, bl); -c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 642) if (struct_v >= 2) { -25499b64 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-19 16:41:44 -0700 643) ::decode(marker, bl); -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 644) if (struct_v <= 3) { -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 645) uint64_t id; -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 646) ::decode(id, bl); -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 647) char buf[16]; -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 648) snprintf(buf, sizeof(buf), "%llu", (long long)id); -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 649) bucket_id = buf; -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 650) } else { -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 651) ::decode(bucket_id, bl); -6a5cbec3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-20 15:15:09 -0700 652) } -c2fbde4d src/rgw/rgw_common.h (Greg Farnum 2011-09-28 10:50:48 -0700 653) } -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 654) if (struct_v >= 5) { -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 655) ::decode(index_pool, bl); -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 656) } else { -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 657) index_pool = data_pool; -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 658) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 659) if (struct_v >= 7) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 660) ::decode(data_extra_pool, bl); -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 661) } -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 662) DECODE_FINISH(bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 663) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 664) -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 665) const string& get_data_extra_pool() { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 666) if (data_extra_pool.empty()) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 667) return data_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 668) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 669) return data_extra_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 670) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 671) -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 672) void dump(Formatter *f) const; -770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 673) void decode_json(JSONObj *obj); -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 674) static void generate_test_instances(list& o); -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 675) -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 676) bool operator<(const rgw_bucket& b) const { -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 677) return name.compare(b.name) < 0; -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 678) } -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 679) }; -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 680) WRITE_CLASS_ENCODER(rgw_bucket) -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 681) -f106e1a5 src/rgw/rgw_common.h (Danny Al-Gaaf 2013-03-11 15:35:53 +0100 682) inline ostream& operator<<(ostream& out, const rgw_bucket &b) { -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 683) out << b.name; -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 684) if (b.name.compare(b.data_pool)) { -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 685) out << "(@"; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 686) string s; -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 687) if (!b.index_pool.empty() && b.data_pool.compare(b.index_pool)) -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 688) s = "i=" + b.index_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 689) if (!b.data_extra_pool.empty() && b.data_pool.compare(b.data_extra_pool)) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 690) if (!s.empty()) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 691) s += ","; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 692) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 693) s += "e=" + b.data_extra_pool; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 694) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 695) if (!s.empty()) { -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 696) out << "{" << s << "}"; -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 697) } -3677076b src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 12:01:31 -0700 698) -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 699) out << b.data_pool << "[" << b.marker << "])"; -988dab3e src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-18 14:31:50 -0700 700) } -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 701) return out; -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 702) } -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 703) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 704) struct rgw_bucket_shard { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 705) rgw_bucket bucket; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 706) int shard_id; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 707) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 708) rgw_bucket_shard() : shard_id(-1) {} -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 709) rgw_bucket_shard(rgw_bucket& _b, int _sid) : bucket(_b), shard_id(_sid) {} -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 710) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 711) bool operator<(const rgw_bucket_shard& b) const { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 712) if (bucket < b.bucket) { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 713) return true; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 714) } -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 715) if (b.bucket < bucket) { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 716) return false; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 717) } -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 718) return shard_id < b.shard_id; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 719) } -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 720) }; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 721) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 722) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 723) struct RGWObjVersionTracker { -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 724) obj_version read_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 725) obj_version write_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 726) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 727) obj_version *version_for_read() { -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 728) return &read_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 729) } -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 730) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 731) obj_version *version_for_write() { -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 732) if (write_version.ver == 0) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 733) return NULL; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 734) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 735) return &write_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 736) } -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 737) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 738) obj_version *version_for_check() { -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 739) if (read_version.ver == 0) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 740) return NULL; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 741) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 742) return &read_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 743) } -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 744) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 745) void prepare_op_for_read(librados::ObjectReadOperation *op); -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 746) void prepare_op_for_write(librados::ObjectWriteOperation *op); -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 747) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 748) void apply_write() { -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 749) read_version = write_version; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 750) write_version = obj_version(); -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 751) } -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 752) -859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 753) void clear() { -859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 754) read_version = obj_version(); -859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 755) write_version = obj_version(); -859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 756) } -859ed33e src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 08:11:56 -0800 757) -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 758) void generate_new_write_ver(CephContext *cct); -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 759) }; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 760) -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 761) enum RGWBucketFlags { -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 762) BUCKET_SUSPENDED = 0x1, -8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 763) BUCKET_VERSIONED = 0x2, -8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 764) BUCKET_VERSIONS_SUSPENDED = 0x4, -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 765) }; -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 766) -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 767) struct RGWBucketInfo -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 768) { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 769) enum BIShardsHashType { -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 770) MOD = 0 -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 771) }; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 772) -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 773) rgw_bucket bucket; -0eb433d4 src/rgw/rgw_common.h (Greg Farnum 2011-09-28 13:51:20 -0700 774) string owner; -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 775) uint32_t flags; -c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 776) string region; -a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 777) time_t creation_time; -d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 778) string placement_rule; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 779) bool has_instance_obj; -dab57ef8 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 18:52:39 -0700 780) RGWObjVersionTracker objv_tracker; /* we don't need to serialize this, for runtime tracking */ -7cd0bd85 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-18 17:40:52 -0700 781) obj_version ep_objv; /* entry point object version, for runtime tracking only */ -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 782) RGWQuotaInfo quota; -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 783) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 784) // Represents the number of bucket index object shards: -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 785) // - value of 0 indicates there is no sharding (this is by default before this -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 786) // feature is implemented). -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 787) // - value of UINT32_T::MAX indicates this is a blind bucket. -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 788) uint32_t num_shards; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 789) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 790) // Represents the bucket index shard hash type. -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 791) uint8_t bucket_index_shard_hash_type; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 792) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 793) // Represents the shard number for blind bucket. -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 794) const static uint32_t NUM_SHARDS_BLIND_BUCKET; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 795) -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 796) bool has_website; -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 797) RGWBucketWebsiteConf website_conf; -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 798) -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 799) void encode(bufferlist& bl) const { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 800) ENCODE_START(12, 4, bl); -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 801) ::encode(bucket, bl); -560f90c5 src/rgw/rgw_common.h (Sage Weil 2011-09-29 16:32:14 -0700 802) ::encode(owner, bl); -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 803) ::encode(flags, bl); -c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 804) ::encode(region, bl); -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 805) uint64_t ct = (uint64_t)creation_time; -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 806) ::encode(ct, bl); -d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 807) ::encode(placement_rule, bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 808) ::encode(has_instance_obj, bl); -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 809) ::encode(quota, bl); -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 810) ::encode(num_shards, bl); -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 811) ::encode(bucket_index_shard_hash_type, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 812) ::encode(has_website, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 813) if (has_website) { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 814) ::encode(website_conf, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 815) } -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 816) ENCODE_FINISH(bl); -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 817) } -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 818) void decode(bufferlist::iterator& bl) { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 819) DECODE_START_LEGACY_COMPAT_LEN_32(12, 4, 4, bl); -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 820) ::decode(bucket, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 821) if (struct_v >= 2) -560f90c5 src/rgw/rgw_common.h (Sage Weil 2011-09-29 16:32:14 -0700 822) ::decode(owner, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 823) if (struct_v >= 3) -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 824) ::decode(flags, bl); -c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 825) if (struct_v >= 5) -c8ac2879 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-14 18:26:37 -0700 826) ::decode(region, bl); -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 827) if (struct_v >= 6) { -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 828) uint64_t ct; -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 829) ::decode(ct, bl); -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 830) creation_time = (time_t)ct; -cfc1f2ee src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-01 11:01:39 -0700 831) } -d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 832) if (struct_v >= 7) -d7af5e14 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-21 20:54:28 -0700 833) ::decode(placement_rule, bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 834) if (struct_v >= 8) -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 835) ::decode(has_instance_obj, bl); -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 836) if (struct_v >= 9) -434ad764 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-27 14:51:43 -0700 837) ::decode(quota, bl); -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 838) if (struct_v >= 10) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 839) ::decode(num_shards, bl); -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 840) if (struct_v >= 11) -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 841) ::decode(bucket_index_shard_hash_type, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 842) if (struct_v >= 12) { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 843) ::decode(has_website, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 844) if (has_website) { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 845) ::decode(website_conf, bl); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 846) } else { -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 847) website_conf = RGWBucketWebsiteConf(); -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 848) } -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 849) } -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 850) DECODE_FINISH(bl); -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 851) } -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 852) void dump(Formatter *f) const; -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 853) static void generate_test_instances(list& o); -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 854) -770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 855) void decode_json(JSONObj *obj); -770d94d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-08 20:40:48 -0700 856) -8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 857) bool versioned() { return (flags & BUCKET_VERSIONED) != 0; } -7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 858) int versioning_status() { return flags & (BUCKET_VERSIONED | BUCKET_VERSIONS_SUSPENDED); } -7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 859) bool versioning_enabled() { return versioning_status() == BUCKET_VERSIONED; } -8d25ec63 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-29 15:10:02 -0700 860) -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 861) RGWBucketInfo() : flags(0), creation_time(0), has_instance_obj(false), num_shards(0), bucket_index_shard_hash_type(MOD), -c0bacef4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-26 16:34:04 -0800 862) has_website(false) {} -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 863) }; -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 864) WRITE_CLASS_ENCODER(RGWBucketInfo) -3ebe6b77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-18 13:21:31 -0700 865) -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 866) struct RGWBucketEntryPoint -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 867) { -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 868) rgw_bucket bucket; -7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 869) string owner; -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 870) time_t creation_time; -6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 871) bool linked; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 872) -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 873) bool has_bucket_info; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 874) RGWBucketInfo old_bucket_info; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 875) -6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 876) RGWBucketEntryPoint() : creation_time(0), linked(false), has_bucket_info(false) {} -ad640672 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 13:12:59 -0700 877) -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 878) void encode(bufferlist& bl) const { -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 879) ENCODE_START(8, 8, bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 880) ::encode(bucket, bl); -7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 881) ::encode(owner, bl); -6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 882) ::encode(linked, bl); -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 883) uint64_t ctime = (uint64_t)creation_time; -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 884) ::encode(ctime, bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 885) ENCODE_FINISH(bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 886) } -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 887) void decode(bufferlist::iterator& bl) { -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 888) bufferlist::iterator orig_iter = bl; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 889) DECODE_START_LEGACY_COMPAT_LEN_32(8, 4, 4, bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 890) if (struct_v < 8) { -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 891) /* ouch, old entry, contains the bucket info itself */ -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 892) old_bucket_info.decode(orig_iter); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 893) has_bucket_info = true; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 894) return; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 895) } -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 896) has_bucket_info = false; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 897) ::decode(bucket, bl); -7e41c103 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 17:27:34 -0700 898) ::decode(owner, bl); -6673b2d3 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 14:00:59 -0700 899) ::decode(linked, bl); -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 900) uint64_t ctime; -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 901) ::decode(ctime, bl); -63e81afe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-24 23:43:50 -0700 902) creation_time = (uint64_t)ctime; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 903) DECODE_FINISH(bl); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 904) } -71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 905) -71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 906) void dump(Formatter *f) const; -71869c4b src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-23 21:00:00 -0700 907) void decode_json(JSONObj *obj); -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 908) }; -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 909) WRITE_CLASS_ENCODER(RGWBucketEntryPoint) -c3260b27 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-22 22:47:48 -0700 910) -4aee3fa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-09 21:37:34 -0800 911) struct RGWStorageStats -0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 912) { -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 913) RGWObjCategory category; -0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 914) uint64_t num_kb; -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 915) uint64_t num_kb_rounded; -0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 916) uint64_t num_objects; -80659cce src/rgw/rgw_common.h (Yehuda Sadeh 2013-10-02 16:34:40 -0700 917) -c13634e8 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-10 13:44:56 -0800 918) RGWStorageStats() : category(RGW_OBJ_CATEGORY_NONE), num_kb(0), num_kb_rounded(0), num_objects(0) {} -7e13ac8e src/rgw/rgw_common.h (Ray Lv 2014-09-10 15:33:22 +0800 919) -7e13ac8e src/rgw/rgw_common.h (Ray Lv 2014-09-10 15:33:22 +0800 920) void dump(Formatter *f) const; -0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 921) }; -0b1ad608 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-24 16:41:10 -0700 922) -fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 923) struct req_state; -fc63d973 src/rgw/rgw_common.h (Yehuda Sadeh 2011-02-15 17:30:07 -0800 924) -e1666d04 src/rgw/rgw_common.h (Christophe Courtaut 2013-08-09 11:58:58 +0200 925) class RGWEnv; -a9c9f96b src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-19 12:36:44 -0700 926) -a9c9f96b src/rgw/rgw_common.h (Yehuda Sadeh 2012-09-19 12:36:44 -0700 927) class RGWClientIO; -43575c7a src/rgw/rgw_common.h (Yehuda Sadeh 2011-07-19 14:02:11 -0700 928) -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 929) struct req_info { -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 930) RGWEnv *env; -d57cdd0c src/rgw/rgw_common.h (Yehuda Sadeh 2014-11-18 13:48:11 -0800 931) RGWHTTPArgs args; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 932) map x_meta_map; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 933) -a3afb3f5 src/rgw/rgw_common.h (Sage Weil 2015-06-09 14:15:10 -0400 934) string host; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 935) const char *method; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 936) string script_uri; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 937) string request_uri; -8a2eb184 src/rgw/rgw_common.h (Yehuda Sadeh 2013-07-22 13:33:33 -0700 938) string effective_uri; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 939) string request_params; -90c5869b src/rgw/rgw_common.h (Yehuda Sadeh 2014-02-19 18:00:10 -0800 940) string domain; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 941) -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 942) req_info(CephContext *cct, RGWEnv *_env); -580a08c6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 23:14:35 -0700 943) void rebuild_from(req_info& src); -f67bfa24 src/rgw/rgw_common.h (Dmytro Iurchenko 2015-02-03 17:54:38 +0200 944) void init_meta_info(bool *found_bad_meta); -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 945) }; -c812bb51 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-23 11:39:13 -0700 946) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 947) struct rgw_obj_key { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 948) string name; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 949) string instance; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 950) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 951) rgw_obj_key() {} -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 952) rgw_obj_key(const string& n) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 953) set(n); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 954) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 955) rgw_obj_key(const string& n, const string& i) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 956) set(n, i); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 957) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 958) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 959) void set(const cls_rgw_obj_key& k) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 960) name = k.name; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 961) instance = k.instance; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 962) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 963) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 964) void transform(cls_rgw_obj_key *k) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 965) k->name = name; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 966) k->instance = instance; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 967) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 968) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 969) void set(const string& n) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 970) name = n; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 971) instance.clear(); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 972) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 973) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 974) void set(const string& n, const string& i) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 975) name = n; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 976) instance = i; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 977) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 978) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 979) bool empty() { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 980) return name.empty(); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 981) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 982) bool operator==(const rgw_obj_key& k) const { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 983) return (name.compare(k.name) == 0) && -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 984) (instance.compare(k.instance) == 0); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 985) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 986) bool operator<(const rgw_obj_key& k) const { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 987) int r = name.compare(k.name); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 988) if (r == 0) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 989) r = instance.compare(k.instance); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 990) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 991) return (r < 0); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 992) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 993) void encode(bufferlist& bl) const { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 994) ENCODE_START(1, 1, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 995) ::encode(name, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 996) ::encode(instance, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 997) ENCODE_FINISH(bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 998) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 999) void decode(bufferlist::iterator& bl) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1000) DECODE_START(1, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1001) ::decode(name, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1002) ::decode(instance, bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1003) DECODE_FINISH(bl); -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1004) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1005) void dump(Formatter *f) const; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1006) }; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1007) WRITE_CLASS_ENCODER(rgw_obj_key) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1008) -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1009) inline ostream& operator<<(ostream& out, const rgw_obj_key &o) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1010) if (o.instance.empty()) { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1011) return out << o.name; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1012) } else { -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1013) return out << o.name << "[" << o.instance << "]"; -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1014) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1015) } -7f26ab76 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 14:18:41 -0700 1016) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1017) /* Holds info on whether the request should be -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1018) * validated via EC2 signature or Auth tokens. -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1019) * Holds value when the action is COPY -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1020) * Holds value when the token to be validated is from a presigned URL */ -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1021) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1022) class authorization_method { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1023) private: -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1024) bool _token_validation; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1025) bool _copy_action; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1026) bool _url_type_token; -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1027) bool _infinite_url_type_token; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1028) bool _acl_main_override; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1029) bool _acl_copy_override; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1030) string _token; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1031) string _copy_source; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1032) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1033) public: -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1034) inline bool get_token_validation() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1035) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1036) return _token_validation; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1037) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1038) inline void set_token_validation(bool method) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1039) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1040) _token_validation = method; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1041) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1042) inline string get_token() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1043) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1044) return _token; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1045) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1046) inline void set_token(string tok) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1047) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1048) _token = tok; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1049) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1050) inline bool get_copy_action() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1051) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1052) return _copy_action; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1053) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1054) inline void set_copy_action(bool action) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1055) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1056) _copy_action = action; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1057) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1058) inline string get_copy_source() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1059) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1060) return _copy_source; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1061) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1062) inline void set_copy_source(string source) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1063) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1064) _copy_source = source; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1065) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1066) inline bool get_url_type_token() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1067) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1068) return _url_type_token; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1069) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1070) inline void set_url_type_token(bool val) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1071) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1072) _url_type_token = val; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1073) } -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1074) inline bool get_infinite_url_type_token() -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1075) { -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1076) return _infinite_url_type_token; -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1077) } -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1078) inline void set_infinite_url_type_token(bool val) -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1079) { -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1080) _infinite_url_type_token = val; -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1081) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1082) inline bool get_acl_main_override() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1083) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1084) return _acl_main_override; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1085) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1086) inline void set_acl_main_override(bool val) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1087) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1088) _acl_main_override = val; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1089) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1090) inline bool get_acl_copy_override() -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1091) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1092) return _acl_copy_override; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1093) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1094) inline void set_acl_copy_override(bool val) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1095) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1096) _acl_copy_override = val; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1097) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1098) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1099) -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1100) authorization_method(bool method, bool action, bool url_token, -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1101) bool infini_token, bool acl_main, bool acl_copy) : -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1102) _token_validation(method), -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1103) _copy_action(action), -6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1104) _url_type_token(url_token), -4da7376c src/rgw/rgw_common.h (Shivanshu Goswami 2016-04-26 10:14:00 +0000 1105) _infinite_url_type_token(infini_token), -6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1106) _acl_main_override(acl_main), -6fc470eb src/rgw/rgw_common.h (root 2016-04-08 18:17:45 +0530 1107) _acl_copy_override(acl_copy) { } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1108) ~authorization_method() { } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1109) }; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1110) -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1111) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1112) /** Store all the state necessary to complete and respond to an HTTP request*/ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1113) struct req_state { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1114) CephContext *cct; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1115) RGWClientIO *cio; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1116) http_op op; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1117) bool content_started; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1118) int format; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1119) ceph::Formatter *formatter; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1120) string decoded_uri; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1121) string relative_uri; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1122) const char *length; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1123) int64_t content_length; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1124) map generic_attrs; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1125) struct rgw_err err; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1126) bool expect_cont; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1127) bool header_ended; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1128) uint64_t obj_size; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1129) bool enable_ops_log; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1130) bool enable_usage_log; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1131) uint8_t defer_to_bucket_acls; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1132) uint32_t perm_mask; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1133) utime_t header_time; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1134) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1135) rgw_bucket bucket; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1136) string bucket_name_str; -c270db3a src/rgw/rgw_common.h (Gaurav Bafna 2016-04-14 15:00:01 +0530 1137) string bucket_owner_id; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1138) rgw_obj_key object; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1139) string src_bucket_name; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1140) rgw_obj_key src_object; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1141) ACLOwner bucket_owner; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1142) ACLOwner owner; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1143) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1144) string region_endpoint; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1145) string bucket_instance_id; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1146) -ec07cbc1 src/rgw/rgw_common.h (Yehuda Sadeh 2015-03-26 21:25:54 -0700 1147) string redirect; -ec07cbc1 src/rgw/rgw_common.h (Yehuda Sadeh 2015-03-26 21:25:54 -0700 1148) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1149) RGWBucketInfo bucket_info; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1150) map bucket_attrs; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1151) bool bucket_exists; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1152) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1153) bool has_bad_meta; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1154) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1155) RGWUserInfo user; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1156) RGWAccessControlPolicy *bucket_acl; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1157) RGWAccessControlPolicy *object_acl; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1158) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1159) bool system_request; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1160) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1161) string canned_acl; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1162) bool has_acl_header; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1163) const char *copy_source; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1164) const char *http_auth; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1165) bool local_source; /* source is local */ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1166) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1167) int prot_flags; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1168) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1169) const char *os_auth_token; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1170) string swift_user; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1171) string swift_groups; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1172) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1173) utime_t time; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1174) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1175) void *obj_ctx; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1176) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1177) string dialect; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1178) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1179) string req_id; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1180) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1181) string trans_id; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1182) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1183) req_info info; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1184) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1185) authorization_method auth_method; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1186) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1187) req_state(CephContext *_cct, class RGWEnv *e); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1188) ~req_state(); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1189) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1190) -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1191) /** Store basic data on an object */ -d0f58ad8 src/radosgw/rgw_common.h (Yehuda Sadeh 2009-08-07 10:46:29 -0700 1192) struct RGWObjEnt { -cb3694fb src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 15:12:21 -0700 1193) rgw_obj_key key; -49b3d2e0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-16 17:44:46 -0700 1194) std::string ns; -edc6659b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-10 15:01:04 -0700 1195) std::string owner; -edc6659b src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-10 15:01:04 -0700 1196) std::string owner_display_name; -df2967a6 src/rgw/rgw_common.h (Greg Farnum 2011-10-24 15:22:35 -0700 1197) uint64_t size; -b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1198) utime_t mtime; -98d0361d src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-21 17:14:48 -0700 1199) string etag; -b738b72c src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-23 16:50:21 -0700 1200) string content_type; -b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1201) string tag; -105ba489 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 09:48:17 -0700 1202) uint32_t flags; -ecd5496d src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-18 16:43:17 -0800 1203) uint64_t versioned_epoch; -8b4b8384 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-16 13:26:19 -0700 1204) -ecd5496d src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-18 16:43:17 -0800 1205) RGWObjEnt() : size(0), flags(0), versioned_epoch(0) {} -e6e36c0a src/rgw/rgw_common.h (Sage Weil 2012-07-03 18:51:02 -0700 1206) -b295c649 src/rgw/rgw_common.h (Yehuda Sadeh 2013-04-15 22:49:26 -0700 1207) void dump(Formatter *f) const; -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1208) -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1209) bool is_current() { -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1210) uint32_t test_flags = RGW_BUCKET_DIRENT_FLAG_VER | RGW_BUCKET_DIRENT_FLAG_CURRENT; -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1211) return (flags & RGW_BUCKET_DIRENT_FLAG_VER) == 0 || -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1212) (flags & test_flags) == test_flags; -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1213) } -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1214) bool is_delete_marker() { return (flags & RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER) != 0; } -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1215) bool is_visible() { -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1216) return is_current() && !is_delete_marker(); -debee800 src/rgw/rgw_common.h (Yehuda Sadeh 2014-09-26 11:11:17 -0700 1217) } -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1218) }; -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1219) -6752babd src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-26 14:30:26 -0700 1220) /** Store basic data on bucket */ -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1221) struct RGWBucketEnt { -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1222) rgw_bucket bucket; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1223) size_t size; -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1224) size_t size_rounded; -a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1225) time_t creation_time; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1226) uint64_t count; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1227) -a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1228) RGWBucketEnt() : size(0), size_rounded(0), creation_time(0), count(0) {} -949f24d5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-12-30 14:18:40 -0800 1229) -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1230) RGWBucketEnt(const cls_user_bucket_entry& e) { -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1231) bucket = e.bucket; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1232) size = e.size; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1233) size_rounded = e.size_rounded; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1234) creation_time = e.creation_time; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1235) count = e.count; -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1236) } -23aa65f6 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 15:22:37 -0800 1237) -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1238) void convert(cls_user_bucket_entry *b) { -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1239) bucket.convert(&b->bucket); -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1240) b->size = size; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1241) b->size_rounded = size_rounded; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1242) b->creation_time = creation_time; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1243) b->count = count; -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1244) } -c7b4d008 src/rgw/rgw_common.h (Yehuda Sadeh 2013-12-06 16:23:33 -0800 1245) -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1246) void encode(bufferlist& bl) const { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1247) ENCODE_START(5, 5, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1248) uint64_t s = size; -a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1249) __u32 mt = creation_time; -9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1250) string empty_str; // originally had the bucket name here, but we encode bucket later -9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1251) ::encode(empty_str, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1252) ::encode(s, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1253) ::encode(mt, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1254) ::encode(count, bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1255) ::encode(bucket, bl); -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1256) s = size_rounded; -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1257) ::encode(s, bl); -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1258) ENCODE_FINISH(bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1259) } -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1260) void decode(bufferlist::iterator& bl) { -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1261) DECODE_START_LEGACY_COMPAT_LEN(5, 5, 5, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1262) __u32 mt; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1263) uint64_t s; -9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1264) string empty_str; // backward compatibility -9065dbd3 src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-13 12:07:17 -0800 1265) ::decode(empty_str, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1266) ::decode(s, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1267) ::decode(mt, bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1268) size = s; -a2cf14fe src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-15 18:41:21 -0700 1269) creation_time = mt; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1270) if (struct_v >= 2) -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1271) ::decode(count, bl); -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1272) if (struct_v >= 3) -ff9537e5 src/rgw/rgw_common.h (Yehuda Sadeh 2011-08-17 17:11:55 -0700 1273) ::decode(bucket, bl); -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1274) if (struct_v >= 4) -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1275) ::decode(s, bl); -7a32cc60 src/rgw/rgw_common.h (Yehuda Sadeh 2011-11-08 13:42:55 -0800 1276) size_rounded = s; -ffcf62f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-07 16:29:11 -0800 1277) DECODE_FINISH(bl); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1278) } -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 1279) void dump(Formatter *f) const; -2277fb45 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-08 16:58:00 -0800 1280) static void generate_test_instances(list& o); -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1281) }; -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1282) WRITE_CLASS_ENCODER(RGWBucketEnt) -9bd627d1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-03 14:14:19 -0800 1283) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1284) class rgw_obj { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1285) std::string orig_obj; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1286) std::string loc; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1287) std::string object; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1288) std::string instance; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1289) public: -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1290) const std::string& get_object() const { return object; } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1291) const std::string& get_orig_obj() const { return orig_obj; } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1292) const std::string& get_loc() const { return loc; } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1293) const std::string& get_instance() const { return instance; } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1294) rgw_bucket bucket; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1295) std::string ns; -8bd984d9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-08 12:32:50 -0700 1296) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1297) bool in_extra_data; /* in-memory only member, does not serialize */ -7989cbd4 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-11 13:24:55 -0700 1298) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1299) // Represents the hash index source for this object once it is set (non-empty) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1300) std::string index_hash_source; -6f44f7a0 src/rgw/rgw_common.h (Yehuda Sadeh 2015-01-21 17:30:32 -0800 1301) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1302) rgw_obj() : in_extra_data(false) {} -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1303) rgw_obj(rgw_bucket& b, const std::string& o) : in_extra_data(false) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1304) init(b, o); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1305) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1306) rgw_obj(rgw_bucket& b, const rgw_obj_key& k) : in_extra_data(false) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1307) init(b, k.name); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1308) set_instance(k.instance); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1309) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1310) void init(rgw_bucket& b, const std::string& o) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1311) bucket = b; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1312) set_obj(o); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1313) reset_loc(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1314) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1315) void init_ns(rgw_bucket& b, const std::string& o, const std::string& n) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1316) bucket = b; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1317) set_ns(n); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1318) set_obj(o); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1319) reset_loc(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1320) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1321) int set_ns(const char *n) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1322) if (!n) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1323) return -EINVAL; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1324) string ns_str(n); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1325) return set_ns(ns_str); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1326) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1327) int set_ns(const string& n) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1328) if (n[0] == '_') -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1329) return -EINVAL; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1330) ns = n; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1331) set_obj(orig_obj); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1332) return 0; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1333) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1334) int set_instance(const string& i) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1335) if (i[0] == '_') -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1336) return -EINVAL; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1337) instance = i; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1338) set_obj(orig_obj); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1339) return 0; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1340) } -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1341) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1342) int clear_instance() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1343) return set_instance(string()); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1344) } -cb94d55c src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-15 22:12:48 -0800 1345) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1346) void set_loc(const string& k) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1347) loc = k; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1348) } -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1349) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1350) void reset_loc() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1351) loc.clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1352) /* -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1353) * For backward compatibility. Older versions used to have object locator on all objects, -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1354) * however, the orig_obj was the effective object locator. This had the same effect as not -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1355) * having object locator at all for most objects but the ones that started with underscore as -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1356) * these were escaped. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1357) */ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1358) if (orig_obj[0] == '_' && ns.empty()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1359) loc = orig_obj; -512ae4cb src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-21 17:31:41 -0700 1360) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1361) } -4e9ebd6b src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-05 12:37:05 -0800 1362) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1363) bool have_null_instance() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1364) return instance == "null"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1365) } -3e48a49f src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-28 17:01:34 -0700 1366) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1367) bool have_instance() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1368) return !instance.empty(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1369) } -7f139286 src/rgw/rgw_common.h (Yehuda Sadeh 2014-10-27 17:09:57 -0700 1370) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1371) bool need_to_encode_instance() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1372) return have_instance() && !have_null_instance(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1373) } -524a155e src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-25 14:08:01 -0700 1374) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1375) void set_obj(const string& o) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1376) object.reserve(128); -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1377) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1378) orig_obj = o; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1379) if (ns.empty() && !need_to_encode_instance()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1380) if (o.empty()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1381) return; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1382) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1383) if (o.size() < 1 || o[0] != '_') { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1384) object = o; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1385) return; -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1386) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1387) object = "_"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1388) object.append(o); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1389) } else { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1390) object = "_"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1391) object.append(ns); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1392) if (need_to_encode_instance()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1393) object.append(string(":") + instance); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1394) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1395) object.append("_"); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1396) object.append(o); -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1397) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1398) reset_loc(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1399) } -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1400) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1401) /* -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1402) * get the object's key name as being referred to by the bucket index. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1403) */ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1404) string get_index_key_name() const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1405) if (ns.empty()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1406) if (orig_obj.size() < 1 || orig_obj[0] != '_') { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1407) return orig_obj; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1408) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1409) return string("_") + orig_obj; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1410) }; -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1411) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1412) char buf[ns.size() + 16]; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1413) snprintf(buf, sizeof(buf), "_%s_", ns.c_str()); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1414) return string(buf) + orig_obj; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1415) }; -cb3694fb src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 15:12:21 -0700 1416) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1417) void get_index_key(rgw_obj_key *key) const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1418) key->name = get_index_key_name(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1419) key->instance = instance; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1420) } -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1421) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1422) static void parse_ns_field(string& ns, string& instance) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1423) int pos = ns.find(':'); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1424) if (pos >= 0) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1425) instance = ns.substr(pos + 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1426) ns = ns.substr(0, pos); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1427) } else { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1428) instance.clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1429) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1430) } -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1431) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1432) string& get_hash_object() { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1433) return index_hash_source.empty() ? orig_obj : index_hash_source; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1434) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1435) /** -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1436) * Translate a namespace-mangled object name to the user-facing name -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1437) * existing in the given namespace. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1438) * -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1439) * If the object is part of the given namespace, it returns true -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1440) * and cuts down the name to the unmangled version. If it is not -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1441) * part of the given namespace, it returns false. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1442) */ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1443) static bool translate_raw_obj_to_obj_in_ns(string& obj, string& instance, string& ns) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1444) if (obj[0] != '_') { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1445) if (ns.empty()) { -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1446) return true; -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1447) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1448) return false; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1449) } -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1450) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1451) string obj_ns; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1452) bool ret = parse_raw_oid(obj, &obj, &instance, &obj_ns); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1453) if (!ret) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1454) return ret; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1455) } -6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1456) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1457) return (ns == obj_ns); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1458) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1459) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1460) static bool parse_raw_oid(const string& oid, string *obj_name, string *obj_instance, string *obj_ns) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1461) obj_instance->clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1462) obj_ns->clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1463) if (oid[0] != '_') { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1464) *obj_name = oid; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1465) return true; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1466) } -6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1467) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1468) if (oid.size() >= 2 && oid[1] == '_') { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1469) *obj_name = oid.substr(1); -6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1470) return true; -6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1471) } -6c6aa5dd src/rgw/rgw_common.h (Yehuda Sadeh 2015-04-29 17:12:00 -0700 1472) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1473) if (oid[0] != '_' || oid.size() < 3) // for namespace, min size would be 3: _x_ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1474) return false; -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1475) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1476) int pos = oid.find('_', 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1477) if (pos <= 1) // if it starts with __, it's not in our namespace -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1478) return false; -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1479) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1480) *obj_ns = oid.substr(1, pos - 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1481) parse_ns_field(*obj_ns, *obj_instance); -802e9e5a src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-09 13:25:46 -0700 1482) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1483) *obj_name = oid.substr(pos + 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1484) return true; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1485) } -e6eef5e9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-30 17:13:42 -0700 1486) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1487) /** -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1488) * Given a mangled object name and an empty namespace string, this -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1489) * function extracts the namespace into the string and sets the object -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1490) * name to be the unmangled version. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1491) * -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1492) * It returns true after successfully doing so, or -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1493) * false if it fails. -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1494) */ -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1495) static bool strip_namespace_from_object(string& obj, string& ns, string& instance) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1496) ns.clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1497) instance.clear(); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1498) if (obj[0] != '_') { -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1499) return true; -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1500) } -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1501) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1502) size_t pos = obj.find('_', 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1503) if (pos == string::npos) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1504) return false; -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1505) } -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1506) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1507) size_t period_pos = obj.find('.'); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1508) if (period_pos < pos) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1509) return false; -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1510) } -f57c33df src/rgw/rgw_common.h (Greg Farnum 2011-10-20 16:26:15 -0700 1511) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1512) ns = obj.substr(1, pos-1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1513) obj = obj.substr(pos+1, string::npos); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1514) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1515) parse_ns_field(ns, instance); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1516) return true; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1517) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1518) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1519) void set_in_extra_data(bool val) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1520) in_extra_data = val; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1521) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1522) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1523) bool is_in_extra_data() const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1524) return in_extra_data; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1525) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1526) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1527) void encode(bufferlist& bl) const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1528) ENCODE_START(5, 3, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1529) ::encode(bucket.name, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1530) ::encode(loc, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1531) ::encode(ns, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1532) ::encode(object, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1533) ::encode(bucket, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1534) ::encode(instance, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1535) if (!ns.empty() || !instance.empty()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1536) ::encode(orig_obj, bl); -3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1537) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1538) ENCODE_FINISH(bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1539) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1540) void decode(bufferlist::iterator& bl) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1541) DECODE_START_LEGACY_COMPAT_LEN(5, 3, 3, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1542) ::decode(bucket.name, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1543) ::decode(loc, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1544) ::decode(ns, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1545) ::decode(object, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1546) if (struct_v >= 2) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1547) ::decode(bucket, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1548) if (struct_v >= 4) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1549) ::decode(instance, bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1550) if (ns.empty() && instance.empty()) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1551) orig_obj = object; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1552) } else { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1553) if (struct_v >= 5) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1554) ::decode(orig_obj, bl); -3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1555) } else { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1556) ssize_t pos = object.find('_', 1); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1557) if (pos < 0) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1558) throw buffer::error(); -3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1559) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1560) orig_obj = object.substr(pos); -3e54acbc src/rgw/rgw_common.h (Yehuda Sadeh 2015-02-09 18:16:13 -0800 1561) } -4d884040 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-24 16:43:14 -0700 1562) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1563) DECODE_FINISH(bl); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1564) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1565) void dump(Formatter *f) const; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1566) static void generate_test_instances(list& o); -4d884040 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-24 16:43:14 -0700 1567) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1568) bool operator==(const rgw_obj& o) const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1569) return (object.compare(o.object) == 0) && -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1570) (bucket.name.compare(o.bucket.name) == 0) && -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1571) (ns.compare(o.ns) == 0) && -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1572) (instance.compare(o.instance) == 0); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1573) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1574) bool operator<(const rgw_obj& o) const { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1575) int r = bucket.name.compare(o.bucket.name); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1576) if (r == 0) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1577) r = object.compare(o.object); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1578) if (r == 0) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1579) r = ns.compare(o.ns); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1580) if (r == 0) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1581) r = instance.compare(o.instance); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1582) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1583) } -d6641cb4 src/rgw/rgw_common.h (root 2016-04-08 15:28:18 +0530 1584) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1585) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1586) return (r < 0); -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1587) } -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1588) }; -e6eef5e9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-30 17:13:42 -0700 1589) WRITE_CLASS_ENCODER(rgw_obj) -8bd984d9 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-08 12:32:50 -0700 1590) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1591) struct rgw_cache_entry_info { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1592) string cache_locator; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1593) uint64_t gen; -ab764f38 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-19 16:34:21 -0700 1594) -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1595) rgw_cache_entry_info() : gen(0) {} -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1596) }; -ab764f38 src/rgw/rgw_common.h (Yehuda Sadeh 2014-03-19 16:34:21 -0700 1597) -f106e1a5 src/rgw/rgw_common.h (Danny Al-Gaaf 2013-03-11 15:35:53 +0100 1598) inline ostream& operator<<(ostream& out, const rgw_obj &o) { -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1599) return out << o.bucket.name << ":" << o.get_object(); -7bbdcdba src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 12:55:25 -0700 1600) } -7bbdcdba src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 12:55:25 -0700 1601) -422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1602) static inline bool str_startswith(const string& str, const string& prefix) -422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1603) { -422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1604) return (str.compare(0, prefix.size(), prefix) == 0); -422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1605) } -422bb6d0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-25 11:03:12 -0700 1606) -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1607) static inline void buf_to_hex(const unsigned char *buf, int len, char *str) -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1608) { -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1609) int i; -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1610) str[0] = '\0'; -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1611) for (i = 0; i < len; i++) { -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1612) sprintf(&str[i*2], "%02x", (int)buf[i]); -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1613) } -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1614) } -e2100bce src/s3/s3common.h (Yehuda Sadeh 2009-07-20 16:41:25 -0700 1615) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1616) static inline int hexdigit(char c) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1617) { -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1618) if (c >= '0' && c <= '9') -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1619) return (c - '0'); -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1620) c = toupper(c); -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1621) if (c >= 'A' && c <= 'F') -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1622) return c - 'A' + 0xa; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1623) return -EINVAL; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1624) } -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1625) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1626) static inline int hex_to_buf(const char *hex, char *buf, int len) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1627) { -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1628) int i = 0; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1629) const char *p = hex; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1630) while (*p) { -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1631) if (i >= len) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1632) return -EINVAL; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1633) buf[i] = 0; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1634) int d = hexdigit(*p); -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1635) if (d < 0) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1636) return d; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1637) buf[i] = d << 4; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1638) p++; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1639) if (!*p) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1640) return -EINVAL; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1641) d = hexdigit(*p); -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1642) if (d < 0) -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1643) return -d; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1644) buf[i] += d; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1645) i++; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1646) p++; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1647) } -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1648) return i; -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1649) } -37fd3b58 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-07 14:13:59 -0700 1650) -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1651) static inline int rgw_str_to_bool(const char *s, int def_val) -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1652) { -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1653) if (!s) -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1654) return def_val; -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1655) -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1656) return (strcasecmp(s, "on") == 0 || -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1657) strcasecmp(s, "yes") == 0 || -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1658) strcasecmp(s, "1") == 0); -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1659) } -f04b6adc src/rgw/rgw_common.h (Yehuda Sadeh 2011-03-10 10:01:24 -0800 1660) -45586aa2 src/rgw/rgw_common.h (Yehuda Sadeh 2014-08-06 12:49:55 -0700 1661) static inline void append_rand_alpha(CephContext *cct, const string& src, string& dest, int len) -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1662) { -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1663) dest = src; -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1664) char buf[len + 1]; -b9097619 src/rgw/rgw_common.h (Yehuda Sadeh 2012-03-13 14:59:00 -0700 1665) gen_rand_alphanumeric(cct, buf, len); -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1666) dest.append("_"); -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1667) dest.append(buf); -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1668) } -d0340426 src/rgw/rgw_common.h (Yehuda Sadeh 2011-06-24 14:50:01 -0700 1669) -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1670) static inline const char *rgw_obj_category_name(RGWObjCategory category) -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1671) { -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1672) switch (category) { -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1673) case RGW_OBJ_CATEGORY_NONE: -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1674) return "rgw.none"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1675) case RGW_OBJ_CATEGORY_MAIN: -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1676) return "rgw.main"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1677) case RGW_OBJ_CATEGORY_SHADOW: -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1678) return "rgw.shadow"; -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1679) case RGW_OBJ_CATEGORY_MULTIMETA: -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1680) return "rgw.multimeta"; -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1681) } -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1682) -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1683) return "unknown"; -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1684) } -ca77ba77 src/rgw/rgw_common.h (Yehuda Sadeh 2011-09-23 17:11:49 -0700 1685) -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1686) static inline uint64_t rgw_rounded_kb(uint64_t bytes) -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1687) { -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1688) return (bytes + 1023) / 1024; -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1689) } -db5bbdd0 src/rgw/rgw_common.h (Yehuda Sadeh 2013-09-26 13:24:48 -0700 1690) -2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1691) static inline uint64_t rgw_rounded_objsize_kb(uint64_t bytes) -2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1692) { -2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1693) return ((bytes + 4095) & ~4095) / 1024; -2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1694) } -2f9a93d3 src/rgw/rgw_common.h (Yehuda Sadeh 2014-01-14 00:18:52 -0800 1695) -97c19da4 src/rgw/rgw_common.h (Yehuda Sadeh 2012-11-07 15:39:56 -0800 1696) extern string rgw_string_unquote(const string& s); -eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1697) extern void parse_csv_string(const string& ival, vector& ovals); -eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1698) extern int parse_key_value(string& in_str, string& key, string& val); -eb0f49d4 src/rgw/rgw_common.h (Caleb Miles 2013-02-19 12:15:30 -0500 1699) extern int parse_key_value(string& in_str, const char *delim, string& key, string& val); -dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1700) /** time parsing */ -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1701) extern int parse_time(const char *time_str, time_t *time); -dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1702) extern bool parse_rfc2616(const char *s, struct tm *t); -30d11f42 src/rgw/rgw_common.h (Yehuda Sadeh 2012-10-11 15:36:07 -0700 1703) extern bool parse_iso8601(const char *s, struct tm *t); -da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1704) extern string rgw_trim_whitespace(const string& src); -da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1705) extern string rgw_trim_quotes(const string& val); -da5e443c src/rgw/rgw_common.h (Yehuda Sadeh 2013-06-10 21:58:02 -0700 1706) -dd3282c1 src/rgw/rgw_common.h (Yehuda Sadeh 2011-10-14 13:20:20 -0700 1707) -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1708) /** Check if the req_state's user has the necessary permissions -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1709) * to do the requested action */ -2365c77a src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-21 14:39:20 -0800 1710) extern bool verify_bucket_permission(struct req_state *s, int perm); -4d2a05f6 src/rgw/rgw_common.h (Yehuda Sadeh 2012-08-22 17:16:05 -0700 1711) extern bool verify_object_permission(struct req_state *s, RGWAccessControlPolicy *bucket_acl, RGWAccessControlPolicy *object_acl, int perm); -2365c77a src/rgw/rgw_common.h (Yehuda Sadeh 2012-02-21 14:39:20 -0800 1712) extern bool verify_object_permission(struct req_state *s, int perm); -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1713) /** Convert an input URL into a sane object name -62e11112 src/rgw/rgw_common.h (Greg Farnum 2010-03-11 14:49:27 -0800 1714) * by converting %-escaped strings into characters, etc*/ -21e07eb6 src/rgw/rgw_common.h (Yehuda Sadeh 2014-12-11 09:07:10 -0800 1715) extern bool url_decode(string& src_str, string& dest_str, bool in_query = false); -dd308cd4 src/rgw/rgw_common.h (Josh Durgin 2013-10-24 08:37:25 -0700 1716) extern void url_encode(const string& src, string& dst); -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1717) -70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1718) extern void calc_hmac_sha1(const char *key, int key_len, -a96dd147 src/rgw/rgw_common.h (root 2016-04-08 15:50:30 +0530 1719) const char *msg, int msg_len, char *dest); -70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1720) /* destination should be CEPH_CRYPTO_HMACSHA1_DIGESTSIZE bytes long */ -70b021d4 src/rgw/rgw_common.h (Colin P. McCabe 2011-03-23 22:42:02 -0700 1721) -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 1722) extern int rgw_parse_op_type_list(const string& str, uint32_t *perm); -38464515 src/rgw/rgw_common.h (Yehuda Sadeh 2013-05-02 21:05:21 -0700 1723) -536a8b64 src/s3/s3common.h (Yehuda Sadeh 2009-07-17 17:49:59 -0700 1724) #endif From 72c48ee55241dbad3f40ef08177ac924bb495fa5 Mon Sep 17 00:00:00 2001 From: Gaurav Bafna Date: Thu, 7 Jul 2016 18:25:24 +1100 Subject: [PATCH 81/90] Fixing the prefix to jcs --- src/rgw/rgw_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.h b/src/rgw/rgw_common.h index 312251c6763ec..ed5f4e596e240 100644 --- a/src/rgw/rgw_common.h +++ b/src/rgw/rgw_common.h @@ -52,7 +52,7 @@ using ceph::crypto::MD5; #define RGW_HTTP_RGWX_ATTR_PREFIX "RGWX_ATTR_" #define RGW_HTTP_RGWX_ATTR_PREFIX_OUT "Rgwx-Attr-" -#define RGW_AMZ_PREFIX "x-amz-" +#define RGW_AMZ_PREFIX "x-jcs-" #define RGW_AMZ_META_PREFIX RGW_AMZ_PREFIX "x-jcs-meta-" #define RGW_AMZ_WEBSITE_REDIRECT_LOCATION RGW_AMZ_PREFIX "website-redirect-location" From 37eadf87010859d18da2e2f39e9595edcee067ff Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Thu, 4 Aug 2016 22:30:36 +1100 Subject: [PATCH 82/90] Fixing the bug in rename API where original name contains '%' character Signed-off-by: Harshal Gupta --- src/rgw/rgw_op.cc | 16 ++++++++++++---- src/rgw/rgw_op.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 7107d995d9c7c..9ca1037850225 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -2265,7 +2265,6 @@ bool RGWCopyObj::parse_copy_location(const string& url_src, string& bucket_name, string dec_src; - url_decode(name_str, dec_src); const char *src = dec_src.c_str(); @@ -3535,7 +3534,7 @@ void RGWRenameObj::execute() s->err.ret = 0; rgw_obj_key orig_object, new_obj; orig_object.dss_duplicate(&(s->object)); - string copysource; + string copysource, raw_copy_source; int ret_orig, ret_newobj; RGWCopyObj_ObjStore_S3* copy_op = NULL; RGWDeleteObj_ObjStore_S3* del_op = NULL; @@ -3558,7 +3557,7 @@ void RGWRenameObj::execute() s->err.ret = -ERR_RENAME_OBJ_EXISTS; return; } - + raw_copy_source = get_raw_copy_source(); copysource = s->bucket_name_str; copysource.append("/"); copysource.append(orig_object.name); @@ -3568,7 +3567,7 @@ void RGWRenameObj::execute() s->info.env->set("HTTP_X_JCS_METADATA_DIRECTIVE", "COPY"); s->copy_source = s->info.env->get("HTTP_X_JCS_COPY_SOURCE"); if (s->copy_source) { - ret = RGWCopyObj::parse_copy_location(s->copy_source, s->src_bucket_name, s->src_object); + ret = RGWCopyObj::parse_copy_location(raw_copy_source, s->src_bucket_name, s->src_object); if (!ret) { //Surprizingly returns bool ldout(s->cct, 0) << "DSS INFO: Rename op failed to parse copy location" << dendl; s->err.ret = -ERR_RENAME_FAILED; @@ -3724,3 +3723,12 @@ void RGWRenameObj::delete_rgw_object(RGWOp* del_op) return; } +string RGWRenameObj::get_raw_copy_source() +{ + string uri = s->info.request_uri; + int start = uri.find('/'); + int end = uri.find('?'); + string raw_copy_source = uri.substr(start+1, end); + return raw_copy_source; +} + diff --git a/src/rgw/rgw_op.h b/src/rgw/rgw_op.h index 40e629d3af7c6..5429f387891a7 100644 --- a/src/rgw/rgw_op.h +++ b/src/rgw/rgw_op.h @@ -578,6 +578,7 @@ class RGWRenameObj : public RGWOp { void perform_external_op(RGWOp*); void delete_rgw_object(RGWOp*); int check_obj(rgw_obj_key&); + string get_raw_copy_source(); virtual const string name() { return "Rename_obj"; } }; From 5ca2d024f384459e1f782f53dc3ce1ea69c1bf36 Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Fri, 5 Aug 2016 01:15:27 +1100 Subject: [PATCH 83/90] Adding some additional logs for testing Rename API Signed-off-by: Harshal Gupta --- src/rgw/rgw_op.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 9ca1037850225..39b9045c5fbc9 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3566,10 +3566,12 @@ void RGWRenameObj::execute() s->info.env->set("HTTP_X_JCS_COPY_SOURCE", copysource.c_str()); s->info.env->set("HTTP_X_JCS_METADATA_DIRECTIVE", "COPY"); s->copy_source = s->info.env->get("HTTP_X_JCS_COPY_SOURCE"); + ldout(s->cct, 0) << "DSS INFO: The raw copy location to be parsed: " << raw_copy_source <copy_source) { ret = RGWCopyObj::parse_copy_location(raw_copy_source, s->src_bucket_name, s->src_object); + ldout(s->cct, 0) << "DSS INFO: final source key name: " << s->src_object << "and bucket name: " << s->src_bucket_name << dendl; if (!ret) { //Surprizingly returns bool - ldout(s->cct, 0) << "DSS INFO: Rename op failed to parse copy location" << dendl; + ldout(s->cct, 0) << "DSS ERROR: Rename op failed to parse copy location" << dendl; s->err.ret = -ERR_RENAME_FAILED; s->err.http_ret = 403; return; From 077662d9acc7ad1d98f35018137a9893cfefbce5 Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Fri, 5 Aug 2016 01:29:03 +1100 Subject: [PATCH 84/90] fixing some typo in the previous commit --- src/rgw/rgw_op.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rgw/rgw_op.cc b/src/rgw/rgw_op.cc index 39b9045c5fbc9..97d7b5449bf2d 100644 --- a/src/rgw/rgw_op.cc +++ b/src/rgw/rgw_op.cc @@ -3569,7 +3569,7 @@ void RGWRenameObj::execute() ldout(s->cct, 0) << "DSS INFO: The raw copy location to be parsed: " << raw_copy_source <copy_source) { ret = RGWCopyObj::parse_copy_location(raw_copy_source, s->src_bucket_name, s->src_object); - ldout(s->cct, 0) << "DSS INFO: final source key name: " << s->src_object << "and bucket name: " << s->src_bucket_name << dendl; + ldout(s->cct, 0) << "DSS INFO: final source key name: " << s->src_object << " and bucket name: " << s->src_bucket_name << dendl; if (!ret) { //Surprizingly returns bool ldout(s->cct, 0) << "DSS ERROR: Rename op failed to parse copy location" << dendl; s->err.ret = -ERR_RENAME_FAILED; From fd1e8ee120177adcee52f486898df7769790338c Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Tue, 11 Oct 2016 07:17:10 +1100 Subject: [PATCH 85/90] Fixing an issue where 'x-jcs-*' headers are modified and all 'x-*' prefix in x-jcs/x-amz type headers are replaced with 'x-amz'. Because of this x-jcs headers are not passed as it is and causes an issue in creating cannonical string for authentication with IAM. Fix: 1. Added x-jcs in the mix with other x-* type headers so that it wont be ignored. 2. We are retaining original prefix and not replacing it with x-amz. --- src/rgw/rgw_common.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index ea40130501630..b00a8b40701a6 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -193,6 +193,7 @@ struct str_len { #define STR_LEN_ENTRY(s) { s, sizeof(s) - 1 } struct str_len meta_prefixes[] = { STR_LEN_ENTRY("HTTP_X_AMZ"), + STR_LEN_ENTRY("HTTP_X_JCS"), STR_LEN_ENTRY("HTTP_X_GOOG"), STR_LEN_ENTRY("HTTP_X_DHO"), STR_LEN_ENTRY("HTTP_X_RGW"), @@ -223,7 +224,7 @@ void req_info::init_meta_info(bool *found_bad_meta) *found_bad_meta = true; char name_low[meta_prefixes[0].len + name_len + 1]; - snprintf(name_low, meta_prefixes[0].len - 5 + name_len + 1, "%s%s", meta_prefixes[0].str + 5 /* skip HTTP_ */, name); // normalize meta prefix + snprintf(name_low, meta_prefixes[prefix_num].len - 5 + name_len + 1, "%s%s", meta_prefixes[prefix_num].str + 5 /* skip HTTP_ */, name); // normalize meta prefix but retain the original 'x-*' prefix. We need both amz and jcs type headers for now. int j; for (j = 0; name_low[j]; j++) { if (name_low[j] != '_') From 0a8bc3c555beefeb4b465728aa3021de2a8cfc0d Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Wed, 12 Oct 2016 21:55:40 +1100 Subject: [PATCH 86/90] Logging Source IP of user and sending it to IAM --- src/rgw/rgw_rest_s3.cc | 15 +++++++++++---- src/rgw/rgw_rest_s3.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index 989f38d4648a7..fd897393ad86c 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -1244,10 +1244,13 @@ int RGWPostObj_ObjStore_S3::get_policy() } dout(1) << "DSS API LOGGING: Action="<< resource_info.getAction() <<" Resource="<< resource_info.getResourceName() << " Tenant=" << resource_info.getTenantName() << dendl; + string source_ip = s->info.env->get("HTTP_X_FORWARDED_FOR","0.0.0.0"); + keystone_validator.append_header("X-Forwarded-For",source_ip); if (isTokenBasedAuth) { keystone_result = keystone_validator.validate_request(resource_info.getAction(), resource_info.getResourceName(), resource_info.getTenantName(), + source_ip, false, /* Is sign auth */ false, /* Is copy */ false, /* Is cross account */ @@ -1265,6 +1268,7 @@ int RGWPostObj_ObjStore_S3::get_policy() keystone_result = keystone_validator.validate_request(resource_info.getAction(), resource_info.getResourceName(), resource_info.getTenantName(), + source_ip, true, /* Is sign auth */ false, /* Is copy */ false, /* Is cross account */ @@ -2436,6 +2440,7 @@ int RGWHandler_ObjStore_S3::init(RGWRados *store, struct req_state *s, RGWClient int RGW_Auth_S3_Keystone_ValidateToken::validate_request(const string& action, const string& resource_name, const string& tenant_name, + const string& source_ip, const bool& is_sign_auth, const bool& is_copy, const bool& is_cross_account, @@ -2470,7 +2475,6 @@ int RGW_Auth_S3_Keystone_ValidateToken::validate_request(const string& action, << localAction << dendl; return -ENOTRECOVERABLE; } - /* Set required headers for keystone request * Recursive calls already have headers set */ if (!is_copy && !is_cross_account) { @@ -2486,6 +2490,7 @@ int RGW_Auth_S3_Keystone_ValidateToken::validate_request(const string& action, append_header("Content-Type", "application/json"); } + append_header("X-Forwarded-For",source_ip); /* Handle special case of copy */ bool isCopyAction = false; isCopyAction = (localAction.compare("CopyObject") == 0); @@ -2497,7 +2502,7 @@ int RGW_Auth_S3_Keystone_ValidateToken::validate_request(const string& action, string copy_src_str = copy_src.substr(0, pos); string copy_src_tenant = copy_src.substr(pos + 1); dout(0) << "DSS INFO: Validating for copy source" << dendl; - ret = validate_request(localAction, copy_src_str, copy_src_tenant, is_sign_auth, + ret = validate_request(localAction, copy_src_str, copy_src_tenant, source_ip, is_sign_auth, true, is_cross_account, is_url_token, is_infini_url_token, copy_src, token, auth_id, auth_token, auth_sign, objectname, iamerror); if (ret < 0) { @@ -2641,7 +2646,7 @@ int RGW_Auth_S3_Keystone_ValidateToken::validate_request(const string& action, // This case requires cross account validation. // Make recursive call with is_cross_account set to true dout(0) << "DSS INFO: Validating for cross account access" << dendl; - ret = validate_request(localAction, resource_name, tenant_name, + ret = validate_request(localAction, resource_name, tenant_name, source_ip, is_sign_auth, is_copy, true, is_url_token, is_infini_url_token, copy_src, token, auth_id, auth_token, auth_sign, objectname, iamerror); @@ -2883,16 +2888,17 @@ int RGW_Auth_S3::authorize(RGWRados *store, struct req_state *s) if (s != NULL) { resource_object_name = s->object.name; } + string source_ip = s->info.env->get("HTTP_X_FORWARDED_FOR","0.0.0.0"); dout(1) << "DSS API LOGGING: Action=" << resource_info.getAction() << " Resource="<< resource_info.getResourceName() << " Tenant=" << resource_info.getTenantName() << " Object=" << resource_object_name << dendl; - if (isTokenBasedAuth) { keystone_result = keystone_validator.validate_request(resource_info.getAction(), resource_info.getResourceName(), resource_info.getTenantName(), + source_ip, false, /* Is sign auth */ false, /* Is copy */ false, /* Is cross account */ @@ -2910,6 +2916,7 @@ int RGW_Auth_S3::authorize(RGWRados *store, struct req_state *s) keystone_result = keystone_validator.validate_request(resource_info.getAction(), resource_info.getResourceName(), resource_info.getTenantName(), + source_ip, true, /* Is sign auth */ false, /* Is copy */ false, /* Is cross account */ diff --git a/src/rgw/rgw_rest_s3.h b/src/rgw/rgw_rest_s3.h index a792764402f10..c2b8070b7c629 100644 --- a/src/rgw/rgw_rest_s3.h +++ b/src/rgw/rgw_rest_s3.h @@ -352,6 +352,7 @@ class RGW_Auth_S3_Keystone_ValidateToken : public RGWHTTPClient { int validate_request(const string& action, const string& resource_name, const string& tenant_name, + const string& source_ip, const bool& is_sign_auth, const bool& is_copy, const bool& is_cross_account, From b395c16e8a6b0ff62690878403c9ca79367c6a18 Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Sat, 22 Oct 2016 01:01:15 +1100 Subject: [PATCH 87/90] Adding a header for encrypted objects Get/Head Ops --- src/rgw/rgw_rest_s3.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/rgw/rgw_rest_s3.cc b/src/rgw/rgw_rest_s3.cc index e84bd84487e6a..5d48dc165b2dd 100644 --- a/src/rgw/rgw_rest_s3.cc +++ b/src/rgw/rgw_rest_s3.cc @@ -177,6 +177,9 @@ int RGWGetObj_ObjStore_S3::send_response_data(bufferlist& bl, off_t bl_ofs, off_ } } + if (kmsdata) + s->cio->print("x-jcs-server-side-encryption: \"%s\"\r\n", "AES256"); + for (struct response_attr_param *p = resp_attr_params; p->param; p++) { bool exists; string val = s->info.args.get(p->param, &exists); From 32037428e6c3152c89c65ceff18a4da190c06187 Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Wed, 26 Oct 2016 21:17:16 +1100 Subject: [PATCH 88/90] Adding x-jcs-server-side-encryption as a special case header which will be used in signature. --- src/rgw/rgw_common.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index b00a8b40701a6..55e532a64dc13 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -193,7 +193,6 @@ struct str_len { #define STR_LEN_ENTRY(s) { s, sizeof(s) - 1 } struct str_len meta_prefixes[] = { STR_LEN_ENTRY("HTTP_X_AMZ"), - STR_LEN_ENTRY("HTTP_X_JCS"), STR_LEN_ENTRY("HTTP_X_GOOG"), STR_LEN_ENTRY("HTTP_X_DHO"), STR_LEN_ENTRY("HTTP_X_RGW"), @@ -224,7 +223,7 @@ void req_info::init_meta_info(bool *found_bad_meta) *found_bad_meta = true; char name_low[meta_prefixes[0].len + name_len + 1]; - snprintf(name_low, meta_prefixes[prefix_num].len - 5 + name_len + 1, "%s%s", meta_prefixes[prefix_num].str + 5 /* skip HTTP_ */, name); // normalize meta prefix but retain the original 'x-*' prefix. We need both amz and jcs type headers for now. + snprintf(name_low, meta_prefixes[0].len - 5 + name_len + 1, "%s%s", meta_prefixes[0].str + 5 /* skip HTTP_ */, name); // normalize meta prefix int j; for (j = 0; name_low[j]; j++) { if (name_low[j] != '_') @@ -247,6 +246,9 @@ void req_info::init_meta_info(bool *found_bad_meta) x_meta_map[name_low] = val; } } + if (strncmp(header_name.c_str(), "HTTP_X_JCS_SERVER_SIDE_ENCRYPTION", strlen(header_name.c_str())) == 0) { + x_meta_map["x-jcs-server-side-encryption"] = "AES256"; + } } } for (iter = x_meta_map.begin(); iter != x_meta_map.end(); ++iter) { From 9d2101c5d44c49b1757d2810b4b6484601c12b0c Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Thu, 27 Oct 2016 01:12:47 +1100 Subject: [PATCH 89/90] adding error code for wrong encryption header --- src/rgw/rgw_common.cc | 2 +- src/rgw/rgw_http_errors.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_common.cc b/src/rgw/rgw_common.cc index 55e532a64dc13..95c35ac26bf2b 100644 --- a/src/rgw/rgw_common.cc +++ b/src/rgw/rgw_common.cc @@ -247,7 +247,7 @@ void req_info::init_meta_info(bool *found_bad_meta) } } if (strncmp(header_name.c_str(), "HTTP_X_JCS_SERVER_SIDE_ENCRYPTION", strlen(header_name.c_str())) == 0) { - x_meta_map["x-jcs-server-side-encryption"] = "AES256"; + x_meta_map["x-jcs-server-side-encryption"] = val; } } } diff --git a/src/rgw/rgw_http_errors.h b/src/rgw/rgw_http_errors.h index efa431e78d04f..0cc154643144e 100644 --- a/src/rgw/rgw_http_errors.h +++ b/src/rgw/rgw_http_errors.h @@ -65,6 +65,7 @@ const static struct rgw_http_errors RGW_HTTP_ERRORS[] = { { ERR_RENAME_COPY_FAILED, 500, "RenameFailed", "Object copy failed during rename. Please file a bug." }, { ERR_RENAME_DATA_LOST, 500, "DataLost", "Rename operation lost the original data. Please file a bug." }, { ERR_RENAME_NEW_OBJ_DEL_FAILED, 500, "RenameFailed", "Rename operation failed. Please delete the duplicated object with name same as new name for the object, manually. Please file a bug." }, + {ERR_INVALID_ENC_ALGO, 400, "InvalidEncryptionAlgorithmError", "The encryption request you specified is not valid. The valid value is AES256." }, }; const static struct rgw_http_errors RGW_HTTP_SWIFT_ERRORS[] = { From ef1fed4d4ba2952119a0ee5f88828606e5b28006 Mon Sep 17 00:00:00 2001 From: Harshal Gupta Date: Thu, 29 Dec 2016 19:30:30 +1100 Subject: [PATCH 90/90] Overriding denial of permission by ACL --- src/rgw/rgw_acl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/rgw/rgw_acl.cc b/src/rgw/rgw_acl.cc index 669a83d10ea88..ece88c15b480f 100644 --- a/src/rgw/rgw_acl.cc +++ b/src/rgw/rgw_acl.cc @@ -114,7 +114,8 @@ bool RGWAccessControlPolicy::verify_permission(string& uid, int user_perm_mask, ldout(cct, 10) << " uid=" << uid << " requested perm (type)=" << perm << ", policy perm=" << policy_perm << ", user_perm_mask=" << user_perm_mask << ", acl perm=" << acl_perm << dendl; - return (perm == acl_perm); + return true; + //return (perm == acl_perm); }