]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/cmpomap/client.h
import ceph 16.2.6
[ceph.git] / ceph / src / cls / cmpomap / client.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2020 Red Hat, Inc
8 *
9 * This is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License version 2.1, as published by the Free Software
12 * Foundation. See file COPYING.
13 */
14
15 #pragma once
16
17 #include <optional>
18 #include "include/rados/librados_fwd.hpp"
19 #include "types.h"
20
21 namespace cls::cmpomap {
22
23 /// requests with too many key comparisons will be rejected with -E2BIG
24 static constexpr uint32_t max_keys = 1000;
25
26 /// process each of the omap value comparisons according to the same rules as
27 /// cmpxattr(), and return -ECANCELED if a comparison is unsuccessful. for
28 /// comparisons with Mode::U64, failure to decode an input value is reported
29 /// as -EINVAL, an empty stored value is compared as 0, and failure to decode
30 /// a stored value is reported as -EIO
31 [[nodiscard]] int cmp_vals(librados::ObjectReadOperation& op,
32 Mode mode, Op comparison, ComparisonMap values,
33 std::optional<ceph::bufferlist> default_value);
34
35 /// process each of the omap value comparisons according to the same rules as
36 /// cmpxattr(). any key/value pairs that compare successfully are overwritten
37 /// with the corresponding input value. for comparisons with Mode::U64, failure
38 /// to decode an input value is reported as -EINVAL. an empty stored value is
39 /// compared as 0, while decode failure of a stored value is treated as an
40 /// unsuccessful comparison and is not reported as an error
41 [[nodiscard]] int cmp_set_vals(librados::ObjectWriteOperation& writeop,
42 Mode mode, Op comparison, ComparisonMap values,
43 std::optional<ceph::bufferlist> default_value);
44
45 /// process each of the omap value comparisons according to the same rules as
46 /// cmpxattr(). any key/value pairs that compare successfully are removed. for
47 /// comparisons with Mode::U64, failure to decode an input value is reported as
48 /// -EINVAL. an empty stored value is compared as 0, while decode failure of a
49 /// stored value is treated as an unsuccessful comparison and is not reported
50 /// as an error
51 [[nodiscard]] int cmp_rm_keys(librados::ObjectWriteOperation& writeop,
52 Mode mode, Op comparison, ComparisonMap values);
53
54
55 // bufferlist factories for comparison values
56 inline ceph::bufferlist string_buffer(std::string_view value) {
57 ceph::bufferlist bl;
58 bl.append(value);
59 return bl;
60 }
61 inline ceph::bufferlist u64_buffer(uint64_t value) {
62 ceph::bufferlist bl;
63 using ceph::encode;
64 encode(value, bl);
65 return bl;
66 }
67
68 } // namespace cls::cmpomap