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