From 1ffaa3614542580c578581d57e396170054e68bd Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Mon, 26 Aug 2024 12:22:13 -0400 Subject: [PATCH] mds,include: add charmap optmetadata Signed-off-by: Patrick Donnelly Fixes: https://tracker.ceph.com/issues/66373 --- src/include/cephfs/types.h | 110 +++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/src/include/cephfs/types.h b/src/include/cephfs/types.h index 0527c7b010db6..5940621abed56 100644 --- a/src/include/cephfs/types.h +++ b/src/include/cephfs/types.h @@ -243,6 +243,93 @@ inline bool operator<(const vinodeno_t &l, const vinodeno_t &r) { (l.ino == r.ino && l.snapid < r.snapid); } +template class Allocator> +class charmap_md_t { +public: + static constexpr int STRUCT_V = 1; + static constexpr int COMPAT_V = 1; + + using str_t = std::basic_string, Allocator>; + + charmap_md_t() = default; + charmap_md_t(auto const& cimd) { + casesensitive = cimd.casesensitive; + normalization = cimd.normalization; + encoding = cimd.encoding; + } + charmap_md_t& operator=(auto const& other) { + casesensitive = other.is_casesensitive(); + normalization = other.get_normalization(); + encoding = other.get_encoding(); + return *this; + } + + void encode(ceph::buffer::list& bl, uint64_t features) const { + ENCODE_START(STRUCT_V, COMPAT_V, bl); + ceph::encode(casesensitive, bl); + ceph::encode(normalization, bl); + ceph::encode(encoding, bl); + ENCODE_FINISH(bl); + } + void decode(ceph::buffer::list::const_iterator& p) { + DECODE_START(STRUCT_V, p); + ceph::decode(casesensitive, p); + ceph::decode(normalization, p); + ceph::decode(encoding, p); + DECODE_FINISH(p); + } + + void print(std::ostream& os) const { + os << "charmap_md_t(s=" << casesensitive << " f=" << normalization << " e=" << encoding << ")"; + } + + std::string_view get_normalization() const { + return std::string_view(normalization); + } + std::string_view get_encoding() const { + return std::string_view(encoding); + } + void set_normalization(std::string_view sv) { + normalization = sv; + } + void set_encoding(std::string_view sv) { + encoding = sv; + } + void mark_casesensitive() { + casesensitive = true; + } + void mark_caseinsensitive() { + casesensitive = false; + } + bool is_casesensitive() const { + return casesensitive; + } + + void dump(ceph::Formatter* f) const { + f->dump_bool("casesensitive", casesensitive); + f->dump_string("normalization", normalization); + f->dump_string("encoding", encoding); + } + + constexpr std::string_view get_default_normalization() const { + return DEFAULT_NORMALIZATION; + } + + constexpr std::string_view get_default_encoding() const { + return DEFAULT_ENCODING; + } + +private: + static constexpr std::string_view DEFAULT_NORMALIZATION = "nfd"; + static constexpr std::string_view DEFAULT_ENCODING = "utf8"; + + bool casesensitive = true; + str_t normalization{DEFAULT_NORMALIZATION}; + str_t encoding{DEFAULT_ENCODING}; +}; + + + typedef enum { QUOTA_MAX_FILES, QUOTA_MAX_BYTES, @@ -412,9 +499,11 @@ template class Allocator> struct optmetadata_server_t { using opts = std::variant< unknown_md_t, + charmap_md_t >; enum kind_t : uint64_t { UNKNOWN, + CHARMAP, _MAX }; }; @@ -423,9 +512,11 @@ template class Allocator> struct optmetadata_client_t { using opts = std::variant< unknown_md_t, + charmap_md_t >; enum kind_t : uint64_t { UNKNOWN, + CHARMAP, _MAX }; }; @@ -729,6 +820,25 @@ struct inode_t { return get_flag(F_QUIESCE_BLOCK); } + bool has_charmap() const { + return optmetadata.has_opt(optmetadata_singleton_server_t::kind_t::CHARMAP); + } + auto& get_charmap() const { + auto& opt = optmetadata.get_opt(optmetadata_singleton_server_t::kind_t::CHARMAP); + return opt.template get_meta< charmap_md_t >(); + } + auto& get_charmap() { + auto& opt = optmetadata.get_opt(optmetadata_singleton_server_t::kind_t::CHARMAP); + return opt.template get_meta< charmap_md_t >(); + } + auto& set_charmap() { + auto& opt = optmetadata.get_or_create_opt(optmetadata_singleton_server_t::kind_t::CHARMAP); + return opt.template get_meta< charmap_md_t >(); + } + void del_charmap() { + optmetadata.del_opt(optmetadata_singleton_server_t::kind_t::CHARMAP); + } + void encode(ceph::buffer::list &bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; -- 2.39.5