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 {
38 };
39 
40 
41 // Quota operations are defined in terms of basic blocks (512 byte units).
43 {
44 public:
45  // Convert from Bytes to basic blocks. Note that we round up since a partial
46  // block costs a full block to store on disk.
47  explicit BasicBlocks(const Bytes& bytes)
48  : blockCount((bytes.bytes() + BASIC_BLOCK_SIZE - 1) / BASIC_BLOCK_SIZE) {}
49 
50  explicit constexpr BasicBlocks(uint64_t _blockCount)
51  : blockCount(_blockCount) {}
52 
53  bool operator==(const BasicBlocks& that) const
54  {
55  return blockCount == that.blockCount;
56  }
57 
58  bool operator!=(const BasicBlocks& that) const
59  {
60  return blockCount != that.blockCount;
61  }
62 
63  uint64_t blocks() const { return blockCount; }
64  Bytes bytes() const { return Bytes(BASIC_BLOCK_SIZE) * blockCount; }
65 
66 private:
67  uint64_t blockCount;
68 
69  static constexpr unsigned BASIC_BLOCK_SIZE = 512;
70 };
71 
72 
73 enum class QuotaPolicy {
74  ACCOUNTING,
77 };
78 
79 
80 inline bool operator==(const QuotaInfo& left, const QuotaInfo& right)
81 {
82  return
83  left.hardLimit == right.hardLimit &&
84  left.softLimit == right.softLimit &&
85  left.used == right.used;
86 }
87 
88 
90 
91 
92 bool isPathXfs(const std::string& path);
93 
94 
95 // Test whether XFS project quotas are enabled on the filesystem at the
96 // given path. This does not imply that quotas are being enforced, just
97 // that they are enabled.
98 Try<bool> isQuotaEnabled(const std::string& path);
99 
100 
101 // Return the path of the block device backing the given path. If the path
102 // is a filesystem path, then the corresponding block device is resolved. If
103 // the path is already a block device path, then the same path is returned.
104 Try<std::string> getDeviceForPath(const std::string& path);
105 
106 
108  const std::string& path,
109  prid_t projectId);
110 
111 
113  const std::string& path,
114  prid_t projectId,
116  Bytes hardLimit);
117 
118 
120  const std::string& path,
121  prid_t projectId,
122  Bytes hardLimit);
123 
124 
126  const std::string& path,
127  prid_t projectId);
128 
129 
131  const std::string& directory);
132 
133 
135  const std::string& directory,
136  prid_t projectId);
137 
138 
140  const std::string& directory);
141 
142 } // namespace xfs {
143 } // namespace internal {
144 } // namespace mesos {
145 
146 #endif // __XFS_UTILS_HPP__
Definition: path.hpp:26
BasicBlocks(const Bytes &bytes)
Definition: utils.hpp:47
Result< QuotaInfo > getProjectQuota(const std::string &path, prid_t projectId)
Definition: utils.hpp:42
Try< std::string > getDeviceForPath(const std::string &path)
Bytes bytes() const
Definition: utils.hpp:64
Definition: check.hpp:33
Bytes used
Definition: utils.hpp:37
bool operator==(const BasicBlocks &that) const
Definition: utils.hpp:53
Definition: check.hpp:30
bool operator==(const QuotaInfo &left, const QuotaInfo &right)
Definition: utils.hpp:80
Try< Nothing > setProjectQuota(const std::string &path, prid_t projectId, Bytes softLimit, Bytes hardLimit)
Try< Nothing > clearProjectQuota(const std::string &path, prid_t projectId)
Definition: spec.hpp:26
Result< prid_t > getProjectId(const std::string &directory)
QuotaPolicy
Definition: utils.hpp:73
Definition: attributes.hpp:24
bool isPathXfs(const std::string &path)
Bytes softLimit
Definition: utils.hpp:35
Definition: utils.hpp:33
uint64_t blocks() const
Definition: utils.hpp:63
Definition: bytes.hpp:30
Try< bool > isQuotaEnabled(const std::string &path)
Bytes hardLimit
Definition: utils.hpp:36
bool operator!=(const BasicBlocks &that) const
Definition: utils.hpp:58
Try< Nothing > clearProjectId(const std::string &directory)
constexpr BasicBlocks(uint64_t _blockCount)
Definition: utils.hpp:50
Try< Nothing > setProjectId(const std::string &directory, prid_t projectId)
Option< Error > validateProjectIds(const IntervalSet< prid_t > &projectRange)