Commit 2470a89d authored by Georgios Bitzes's avatar Georgios Bitzes

NS: Add getUids, getGids, meld to QuotaNodeCore

parent b564edc3
......@@ -98,9 +98,9 @@ uint64_t QuotaNodeCore::getNumFilesByGroup(gid_t gid) {
return it->second.files;
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Account a new file.
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
void QuotaNodeCore::addFile(uid_t uid, gid_t gid, uint64_t size,
uint64_t physicalSize) {
......@@ -117,9 +117,9 @@ void QuotaNodeCore::addFile(uid_t uid, gid_t gid, uint64_t size,
group.files++;
}
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Remove a file.
//----------------------------------------------------------------------------
//------------------------------------------------------------------------------
void QuotaNodeCore::removeFile(uid_t uid, gid_t gid, uint64_t size,
uint64_t physicalSize) {
......@@ -134,6 +134,59 @@ void QuotaNodeCore::removeFile(uid_t uid, gid_t gid, uint64_t size,
user.files--;
group.files--;
if(user == UsageInfo()) {
mUserInfo.erase(uid);
}
if(group == UsageInfo()) {
mGroupInfo.erase(gid);
}
}
//------------------------------------------------------------------------------
// Get the set of uids for which information is stored in the current quota
// node.
//
// @return set of uids
//------------------------------------------------------------------------------
std::unordered_set<uint64_t> QuotaNodeCore::getUids() {
std::unordered_set<uint64_t> uids;
for (auto it = mUserInfo.begin(); it != mUserInfo.end(); ++it) {
uids.insert(it->first);
}
return uids;
}
//------------------------------------------------------------------------------
// Get the set of gids for which information is stored in the current quota
// node.
//
// @return set of gids
//------------------------------------------------------------------------------
std::unordered_set<uint64_t> QuotaNodeCore::getGids() {
std::unordered_set<uint64_t> gids;
for (auto it = mGroupInfo.begin(); it != mGroupInfo.end(); ++it) {
gids.insert(it->first);
}
return gids;
}
//------------------------------------------------------------------------------
// Meld in another quota node core
//------------------------------------------------------------------------------
void QuotaNodeCore::meld(const QuotaNodeCore& other) {
for (auto it = other.mUserInfo.begin(); it != other.mUserInfo.end(); it++) {
mUserInfo[it->first] += it->second;
}
for (auto it = other.mGroupInfo.begin(); it != other.mGroupInfo.end(); it++) {
mGroupInfo[it->first] += it->second;
}
}
EOSNSNAMESPACE_END
......@@ -27,6 +27,7 @@
#include "namespace/Namespace.hh"
#include "namespace/interface/Identifiers.hh"
#include <map>
#include <unordered_set>
EOSNSNAMESPACE_BEGIN
......@@ -46,6 +47,13 @@ public:
files += other.files;
return *this;
}
bool operator==(const UsageInfo& other) const {
return (space == other.space) &&
(physicalSpace == other.physicalSpace) &&
(files == other.files);
}
uint64_t space;
uint64_t physicalSpace;
uint64_t files;
......@@ -97,6 +105,27 @@ public:
//----------------------------------------------------------------------------
void removeFile(uid_t uid, gid_t gid, uint64_t size, uint64_t physicalSize);
//----------------------------------------------------------------------------
//! Meld in another quota node core
//----------------------------------------------------------------------------
void meld(const QuotaNodeCore& other);
//----------------------------------------------------------------------------
//! Get the set of uids for which information is stored in the current quota
//! node.
//!
//! @return set of uids
//----------------------------------------------------------------------------
std::unordered_set<uint64_t> getUids();
//----------------------------------------------------------------------------
//! Get the set of gids for which information is stored in the current quota
//! node.
//!
//! @return set of gids
//----------------------------------------------------------------------------
std::unordered_set<uint64_t> getGids();
private:
std::map<uid_t, UsageInfo> mUserInfo;
std::map<gid_t, UsageInfo> mGroupInfo;
......
......@@ -520,6 +520,9 @@ TEST(SysMask, BasicSanity) {
TEST(QuotaNodeCore, BasicSanity) {
QuotaNodeCore qn;
std::unordered_set<uint64_t> uids;
std::unordered_set<uint64_t> gids;
ASSERT_EQ(qn.getNumFilesByUser(12), 0u);
ASSERT_EQ(qn.getNumFilesByGroup(12), 0u);
......@@ -535,6 +538,11 @@ TEST(QuotaNodeCore, BasicSanity) {
ASSERT_EQ(qn.getPhysicalSpaceByGroup(12), 0);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(13), 2048);
uids.emplace(12);
gids.emplace(13);
ASSERT_EQ(qn.getUids(), uids);
ASSERT_EQ(qn.getGids(), gids);
qn.addFile(12, 12, 1, 2);
ASSERT_EQ(qn.getPhysicalSpaceByUser(12), 2050);
......@@ -547,12 +555,20 @@ TEST(QuotaNodeCore, BasicSanity) {
ASSERT_EQ(qn.getNumFilesByGroup(12), 1u);
ASSERT_EQ(qn.getNumFilesByGroup(13), 1u);
gids.emplace(12);
ASSERT_EQ(qn.getUids(), uids);
ASSERT_EQ(qn.getGids(), gids);
qn.removeFile(12, 13, 1024, 2048);
ASSERT_EQ(qn.getPhysicalSpaceByUser(12), 2);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(12), 2);
ASSERT_EQ(qn.getPhysicalSpaceByGroup(13), 0);
gids.erase(13);
ASSERT_EQ(qn.getUids(), uids);
ASSERT_EQ(qn.getGids(), gids);
qn.removeFile(12, 12, 1, 2);
ASSERT_EQ(qn.getPhysicalSpaceByUser(12), 0);
......@@ -564,4 +580,10 @@ TEST(QuotaNodeCore, BasicSanity) {
ASSERT_EQ(qn.getNumFilesByGroup(12), 0u);
ASSERT_EQ(qn.getNumFilesByGroup(13), 0u);
uids.clear();
gids.clear();
ASSERT_EQ(qn.getUids(), uids);
ASSERT_EQ(qn.getGids(), gids);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment