2 * Ceph - scalable distributed file system
4 * Copyright (C) 2015 CERN
6 * Author: Joaquim Rocha <joaquim.rocha@cern.ch>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
15 #include "cls/numops/cls_numops_client.h"
16 #include "include/encoding.h"
17 #include "include/rados/librados.hpp"
26 int add(librados::IoCtx *ioctx,
27 const std::string& oid,
28 const std::string& key,
34 std::stringstream stream;
35 stream << value_to_add;
37 ::encode(stream.str(), in);
39 return ioctx->exec(oid, "numops", "add", in, out);
42 int sub(librados::IoCtx *ioctx,
43 const std::string& oid,
44 const std::string& key,
45 double value_to_subtract)
47 return add(ioctx, oid, key, -value_to_subtract);
50 int mul(librados::IoCtx *ioctx,
51 const std::string& oid,
52 const std::string& key,
53 double value_to_multiply)
58 std::stringstream stream;
59 stream << value_to_multiply;
61 ::encode(stream.str(), in);
63 return ioctx->exec(oid, "numops", "mul", in, out);
66 int div(librados::IoCtx *ioctx,
67 const std::string& oid,
68 const std::string& key,
69 double value_to_divide)
71 if (value_to_divide == 0)
74 return mul(ioctx, oid, key, 1 / value_to_divide);