Skip to content

Commit

Permalink
58216 MDS quota.max_files check when prepare_new_inode
Browse files Browse the repository at this point in the history
Signed-off-by: Jinmyeong Lee <jinmyeong.lee@linecorp.com>
  • Loading branch information
jinmyeonglee committed Dec 8, 2022
1 parent 70a1011 commit c087e2e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/mds/Server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3299,6 +3299,30 @@ CDentry* Server::prepare_stray_dentry(MDRequestRef& mdr, CInode *in)
return straydn;
}

CDir* Server::get_quota_root(CDir *dir) {
auto cur = dir;
while (true) {
if (cur->inode->is_root()) {
return cur;
}
if (cur->inode->get_projected_inode()->quota.is_enable()) {
return cur;
}
cur = cur->get_parent_dir();
}
}

bool Server::is_nfiles_quota_exceeded(CDir *dir) {
auto quota_root = get_quota_root(dir);
auto quota = quota_root->inode->get_projected_inode()->quota;

if(!quota.is_enable()) {
return false;
}
nest_info_t rstat = quota_root->get_projected_fnode()->rstat;
return rstat.rfiles + rstat.rsubdirs >= quota.max_files;
}

/** prepare_new_inode
*
* create a new inode. set c/m/atime. hit dir pop.
Expand Down Expand Up @@ -4546,6 +4570,10 @@ void Server::handle_client_openc(MDRequestRef& mdr)
if (mdr->dn[0].size() == 1)
mds->locker->create_lock_cache(mdr, diri, &mdr->dir_layout);

if (is_nfiles_quota_exceeded(dn->get_dir())) {
respond_to_request(mdr, -EDQUOT);
return;
}
// create inode.
CInode *newi = prepare_new_inode(mdr, dn->get_dir(), inodeno_t(req->head.ino),
req->head.args.open.mode | S_IFREG, &layout);
Expand Down Expand Up @@ -6834,6 +6862,11 @@ void Server::handle_client_mknod(MDRequestRef& mdr)
else
layout = mdcache->default_file_layout;

if (is_nfiles_quota_exceeded(dn->get_dir())) {
respond_to_request(mdr, -EDQUOT);
return;
}

CInode *newi = prepare_new_inode(mdr, dn->get_dir(), inodeno_t(req->head.ino), mode, &layout);
ceph_assert(newi);

Expand Down Expand Up @@ -6933,6 +6966,11 @@ void Server::handle_client_mkdir(MDRequestRef& mdr)
}
dn->set_alternate_name(req->get_alternate_name());

if (is_nfiles_quota_exceeded(dn->get_dir())) {
respond_to_request(mdr, -EDQUOT);
return;
}

// new inode
unsigned mode = req->head.args.mkdir.mode;
mode &= ~S_IFMT;
Expand Down Expand Up @@ -7030,6 +7068,11 @@ void Server::handle_client_symlink(MDRequestRef& mdr)
}
dn->set_alternate_name(req->get_alternate_name());

if (is_nfiles_quota_exceeded(dn->get_dir())) {
respond_to_request(mdr, -EDQUOT);
return;
}

unsigned mode = S_IFLNK | 0777;
CInode *newi = prepare_new_inode(mdr, dir, inodeno_t(req->head.ino), mode);
ceph_assert(newi);
Expand Down
2 changes: 2 additions & 0 deletions src/mds/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ class Server {
* this bypasses the asserts to make sure we're journaling the right
* things on the right nodes */
void _rename_apply(MDRequestRef& mdr, CDentry *srcdn, CDentry *destdn, CDentry *straydn);
CDir* get_quota_root(CDir *dir);
bool is_nfiles_quota_exceeded(CDir *dir);

// slaving
void handle_peer_rename_prep(MDRequestRef& mdr);
Expand Down

0 comments on commit c087e2e

Please sign in to comment.