Skip to content

Commit

Permalink
Merge pull request ceph#6082 from jcsp/wip-client-quota-roots
Browse files Browse the repository at this point in the history
Fix quota enforcement on subdir mounts
  • Loading branch information
ukernel committed Sep 29, 2015
2 parents 04f9ae5 + e52204c commit 95cc154
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 41 deletions.
87 changes: 46 additions & 41 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11034,63 +11034,68 @@ Inode *Client::get_quota_root(Inode *in)
return ancestor->in();
}

bool Client::is_quota_files_exceeded(Inode *in)
/**
* Traverse quota ancestors of the Inode, return true
* if any of them passes the passed function
*/
bool Client::check_quota_condition(
Inode *in, std::function<bool (const Inode &in)> test)
{
if (!cct->_conf->client_quota)
return false;

while (in != root_ancestor) {
quota_info_t *quota = &in->quota;
nest_info_t *rstat = &in->rstat;

if (quota->max_files && rstat->rsize() >= quota->max_files)
while (true) {
assert(in != NULL);
if (test(*in)) {
return true;
}

in = get_quota_root(in);
if (in == root_ancestor) {
// We're done traversing, drop out
return false;
} else {
// Continue up the tree
in = get_quota_root(in);
}
}

return false;
}

bool Client::is_quota_bytes_exceeded(Inode *in, int64_t new_bytes)
bool Client::is_quota_files_exceeded(Inode *in)
{
if (!cct->_conf->client_quota)
return false;

while (in != root_ancestor) {
quota_info_t *quota = &in->quota;
nest_info_t *rstat = &in->rstat;

if (quota->max_bytes && (rstat->rbytes + new_bytes) > quota->max_bytes)
return true;
return check_quota_condition(in,
[](const Inode &in) {
return in.quota.max_files && in.rstat.rsize() >= in.quota.max_files;
});
}

in = get_quota_root(in);
}
return false;
bool Client::is_quota_bytes_exceeded(Inode *in, int64_t new_bytes)
{
return check_quota_condition(in,
[&new_bytes](const Inode &in) {
return in.quota.max_bytes && (in.rstat.rbytes + new_bytes)
> in.quota.max_bytes;
});
}

bool Client::is_quota_bytes_approaching(Inode *in)
{
if (!cct->_conf->client_quota)
return false;

while (in != root_ancestor) {
quota_info_t *quota = &in->quota;
nest_info_t *rstat = &in->rstat;

if (quota->max_bytes) {
if (rstat->rbytes >= quota->max_bytes)
return true;

assert(in->size >= in->reported_size);
uint64_t space = quota->max_bytes - rstat->rbytes;
uint64_t size = in->size - in->reported_size;
if ((space >> 4) < size)
return true;
}

in = get_quota_root(in);
}
return false;
return check_quota_condition(in,
[](const Inode &in) {
if (in.quota.max_bytes) {
if (in.rstat.rbytes >= in.quota.max_bytes) {
return true;
}

assert(in.size >= in.reported_size);
const uint64_t space = in.quota.max_bytes - in.rstat.rbytes;
const uint64_t size = in.size - in.reported_size;
return (space >> 4) < size;
} else {
return false;
}
});
}

enum {
Expand Down
5 changes: 5 additions & 0 deletions src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "include/types.h"

// stl
#include <functional>
#include <string>
#include <memory>
#include <set>
Expand Down Expand Up @@ -484,6 +485,10 @@ class Client : public Dispatcher, public md_config_obs_t {
void put_qtree(Inode *in);
void invalidate_quota_tree(Inode *in);
Inode* get_quota_root(Inode *in);

bool check_quota_condition(
Inode *in,
std::function<bool (const Inode &)> test);
bool is_quota_files_exceeded(Inode *in);
bool is_quota_bytes_exceeded(Inode *in, int64_t new_bytes);
bool is_quota_bytes_approaching(Inode *in);
Expand Down

0 comments on commit 95cc154

Please sign in to comment.