Apache Mesos
utils.hpp
Go to the documentation of this file.
1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements. See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership. The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License. You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #ifndef __XFS_UTILS_HPP__
18 #define __XFS_UTILS_HPP__
19 
20 #include <string>
21 
22 #include <stout/bytes.hpp>
23 #include <stout/interval.hpp>
24 #include <stout/nothing.hpp>
25 #include <stout/try.hpp>
26 
27 #include <xfs/xfs_types.h>
28 
29 namespace mesos {
30 namespace internal {
31 namespace xfs {
32 
33 struct QuotaInfo
34 {
37 };
38 
39 
40 // Quota operations are defined in terms of basic blocks (512 byte units).
42 {
43 public:
44  // Convert from Bytes to basic blocks. Note that we round up since a partial
45  // block costs a full block to store on disk.
46  explicit BasicBlocks(const Bytes& bytes)
47  : blockCount((bytes.bytes() + BASIC_BLOCK_SIZE - 1) / BASIC_BLOCK_SIZE) {}
48 
49  explicit constexpr BasicBlocks(uint64_t _blockCount)
50  : blockCount(_blockCount) {}
51 
52  bool operator==(const BasicBlocks& that) const
53  {
54  return blockCount == that.blockCount;
55  }
56 
57  bool operator!=(const BasicBlocks& that) const
58  {
59  return blockCount != that.blockCount;
60  }
61 
62  uint64_t blocks() const { return blockCount; }
63  Bytes bytes() const { return Bytes(BASIC_BLOCK_SIZE) * blockCount; }
64 
65 private:
66  uint64_t blockCount;
67 
68  static constexpr unsigned BASIC_BLOCK_SIZE = 512;
69 };
70 
71 
72 enum class QuotaPolicy {
73  ENFORCING,
74  ACCOUNTING,
75 };
76 
77 
78 inline bool operator==(const QuotaInfo& left, const QuotaInfo& right)
79 {
80  return left.limit == right.limit && left.used == right.used;
81 }
82 
83 
85 
86 
87 bool isPathXfs(const std::string& path);
88 
89 
90 // Test whether XFS project quotas are enabled on the filesystem at the
91 // given path. This does not imply that quotas are being enforced, just
92 // that they are enabled.
93 Try<bool> isQuotaEnabled(const std::string& path);
94 
95 
97  const std::string& path,
98  prid_t projectId);
99 
100 
102  const std::string& path,
103  prid_t projectId,
104  Bytes limit);
105 
106 
108  const std::string& path,
109  prid_t projectId);
110 
111 
113  const std::string& directory);
114 
115 
117  const std::string& directory,
118  prid_t projectId);
119 
120 
122  const std::string& directory);
123 
124 } // namespace xfs {
125 } // namespace internal {
126 } // namespace mesos {
127 
128 #endif // __XFS_UTILS_HPP__
BasicBlocks(const Bytes &bytes)
Definition: utils.hpp:46
Result< QuotaInfo > getProjectQuota(const std::string &path, prid_t projectId)
Definition: utils.hpp:41
Bytes bytes() const
Definition: utils.hpp:63
Definition: try.hpp:34
Bytes limit
Definition: utils.hpp:35
Bytes used
Definition: utils.hpp:36
bool operator==(const BasicBlocks &that) const
Definition: utils.hpp:52
Definition: result.hpp:40
bool operator==(const QuotaInfo &left, const QuotaInfo &right)
Definition: utils.hpp:78
Try< Nothing > clearProjectQuota(const std::string &path, prid_t projectId)
Result< prid_t > getProjectId(const std::string &directory)
QuotaPolicy
Definition: utils.hpp:72
bool isPathXfs(const std::string &path)
Definition: utils.hpp:33
uint64_t blocks() const
Definition: utils.hpp:62
Definition: bytes.hpp:30
Try< bool > isQuotaEnabled(const std::string &path)
bool operator!=(const BasicBlocks &that) const
Definition: utils.hpp:57
Try< Nothing > clearProjectId(const std::string &directory)
constexpr BasicBlocks(uint64_t _blockCount)
Definition: utils.hpp:49
Try< Nothing > setProjectId(const std::string &directory, prid_t projectId)
Option< Error > validateProjectIds(const IntervalSet< prid_t > &projectRange)
Try< Nothing > setProjectQuota(const std::string &path, prid_t projectId, Bytes limit)