diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:54:28 +0000 |
commit | e6918187568dbd01842d8d1d2c808ce16a894239 (patch) | |
tree | 64f88b554b444a49f656b6c656111a145cbbaa28 /src/cls/cmpomap/client.h | |
parent | Initial commit. (diff) | |
download | ceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip |
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cls/cmpomap/client.h')
-rw-r--r-- | src/cls/cmpomap/client.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/cls/cmpomap/client.h b/src/cls/cmpomap/client.h new file mode 100644 index 000000000..013d85cc7 --- /dev/null +++ b/src/cls/cmpomap/client.h @@ -0,0 +1,68 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab ft=cpp + +/* + * Ceph - scalable distributed file system + * + * Copyright (C) 2020 Red Hat, Inc + * + * 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. + */ + +#pragma once + +#include <optional> +#include "include/rados/librados_fwd.hpp" +#include "types.h" + +namespace cls::cmpomap { + +/// requests with too many key comparisons will be rejected with -E2BIG +static constexpr uint32_t max_keys = 1000; + +/// process each of the omap value comparisons according to the same rules as +/// cmpxattr(), and return -ECANCELED if a comparison is unsuccessful. for +/// comparisons with Mode::U64, failure to decode an input value is reported +/// as -EINVAL, an empty stored value is compared as 0, and failure to decode +/// a stored value is reported as -EIO +[[nodiscard]] int cmp_vals(librados::ObjectReadOperation& op, + Mode mode, Op comparison, ComparisonMap values, + std::optional<ceph::bufferlist> default_value); + +/// process each of the omap value comparisons according to the same rules as +/// cmpxattr(). any key/value pairs that compare successfully are overwritten +/// with the corresponding input value. for comparisons with Mode::U64, failure +/// to decode an input value is reported as -EINVAL. an empty stored value is +/// compared as 0, while decode failure of a stored value is treated as an +/// unsuccessful comparison and is not reported as an error +[[nodiscard]] int cmp_set_vals(librados::ObjectWriteOperation& writeop, + Mode mode, Op comparison, ComparisonMap values, + std::optional<ceph::bufferlist> default_value); + +/// process each of the omap value comparisons according to the same rules as +/// cmpxattr(). any key/value pairs that compare successfully are removed. for +/// comparisons with Mode::U64, failure to decode an input value is reported as +/// -EINVAL. an empty stored value is compared as 0, while decode failure of a +/// stored value is treated as an unsuccessful comparison and is not reported +/// as an error +[[nodiscard]] int cmp_rm_keys(librados::ObjectWriteOperation& writeop, + Mode mode, Op comparison, ComparisonMap values); + + +// bufferlist factories for comparison values +inline ceph::bufferlist string_buffer(std::string_view value) { + ceph::bufferlist bl; + bl.append(value); + return bl; +} +inline ceph::bufferlist u64_buffer(uint64_t value) { + ceph::bufferlist bl; + using ceph::encode; + encode(value, bl); + return bl; +} + +} // namespace cls::cmpomap |