From d4978678b49102226a79a6c8e5d10075d416977d Mon Sep 17 00:00:00 2001 From: Hongchao Zhang Date: Thu, 28 Jul 2022 21:54:00 +0800 Subject: [PATCH] LU-15694 quota: keep grace time while setting default limits The quota grace time should only be changed by "lfs setquota -t", and it should be kept while setting default quota limits. This patch also fixes an issue of not saving the grace time while writing glboal quota record. Signed-off-by: Hongchao Zhag Change-Id: I89ca49d09dc41deffe4bc77e53721b5bb4f4be37 Reviewed-on: https://review.whamcloud.com/46935 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Li Dongyang Reviewed-by: Sergey Cheremencev Reviewed-by: Oleg Drokin --- lustre/quota/qmt_entry.c | 3 ++- lustre/quota/qmt_handler.c | 5 +++++ lustre/tests/sanity-quota.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ lustre/utils/lfs.c | 15 +++++++++------ 4 files changed, 60 insertions(+), 7 deletions(-) diff --git a/lustre/quota/qmt_entry.c b/lustre/quota/qmt_entry.c index a37bf48..92d83b6 100644 --- a/lustre/quota/qmt_entry.c +++ b/lustre/quota/qmt_entry.c @@ -354,7 +354,8 @@ int qmt_glb_write(const struct lu_env *env, struct thandle *th, if (lqe->lqe_is_default) { rec->qbr_hardlimit = 0; rec->qbr_softlimit = 0; - rec->qbr_time = LQUOTA_GRACE_FLAG(0, LQUOTA_FLAG_DEFAULT); + rec->qbr_time = LQUOTA_GRACE_FLAG(lqe->lqe_gracetime, + LQUOTA_FLAG_DEFAULT); } else { rec->qbr_hardlimit = lqe->lqe_hardlimit; rec->qbr_softlimit = lqe->lqe_softlimit; diff --git a/lustre/quota/qmt_handler.c b/lustre/quota/qmt_handler.c index d2789ce..6ef8377 100644 --- a/lustre/quota/qmt_handler.c +++ b/lustre/quota/qmt_handler.c @@ -205,6 +205,10 @@ int qmt_set_with_lqe(const struct lu_env *env, struct qmt_device *qmt, /* change quota limits */ lqe->lqe_hardlimit = hard; lqe->lqe_softlimit = soft; + if (is_default) { + dirtied = true; + GOTO(quota_write, 0); + } quota_set: /* recompute qunit in case it was never initialized */ @@ -248,6 +252,7 @@ quota_set: dirtied = true; } +quota_write: if (dirtied) { if (!is_updated) { /* write new quota settings to disk */ diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 3d8c5aa..f55c009 100755 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -5557,6 +5557,50 @@ test_82() } run_test 82 "verify more than 8 qids for single operation" +test_grace_with_default_quota() +{ + local qtype=$1 + local qdtype=$2 + local bgrace + local igrace + local bgrace2 + local igrace2 + echo "ttt1" + $LFS setquota $qdtype -b 0 -B 0 -i 0 -I 0 $DIR || + error "clear default quota [$qdtype] failed" + echo "ttt2" + $LFS setquota -t $qtype --block-grace 1w --inode-grace 1w $DIR || + error "reset quota [$qdtype] grace failed" + echo "ttt3" + + eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \ + '{printf("bgrace=%s;igrace=%s;", $4, $9)}') + echo "ttt4" + + $LFS setquota $qdtype -B 10G -i 10k $DIR + echo "ttt5" + + eval $($LFS quota -t $qtype $DIR | awk -F "[; ]" \ + '{printf("bgrace2=%s;igrace2=%s;", $4, $9)}') + + [ "$bgrace" == "$bgrace2" ] || + error "set default quota shouldn't affect block grace" + [ "$igrace" == "$igrace2" ] || + error "set default quota shouldn't affect inode grace" + +} + +test_83() +{ + setup_quota_test || error "setup quota failed with $?" + test_grace_with_default_quota "-u" "-U" + test_grace_with_default_quota "-g" "-G" + + is_project_quota_supported || return 0 + test_grace_with_default_quota "-p" "-P" +} +run_test 83 "Setting default quota shouldn't affect grace time" + quota_fini() { do_nodes $(comma_list $(nodes_list)) \ diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 111e4af..e80814d 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -8121,6 +8121,9 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type, char timebuf[40]; char strbuf[STRBUF_LEN]; + dqb->dqb_btime &= LQUOTA_GRACE_MASK; + dqb->dqb_itime &= LQUOTA_GRACE_MASK; + if (dqb->dqb_bhardlimit && lustre_stoqb(dqb->dqb_curspace) >= dqb->dqb_bhardlimit) { bover = 1; @@ -8146,11 +8149,11 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type, else printf("%15s", mnt); - if (bover) - diff2str(dqb->dqb_btime, timebuf, now); - else if (show_default) + if (show_default) snprintf(timebuf, sizeof(timebuf), "%llu", (unsigned long long)dqb->dqb_btime); + else if (bover) + diff2str(dqb->dqb_btime, timebuf, now); kbytes2str(lustre_stoqb(dqb->dqb_curspace), strbuf, sizeof(strbuf), h); @@ -8178,11 +8181,11 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type, numbuf[0], bover ? '*' : ' ', numbuf[1], numbuf[2], bover > 1 ? timebuf : "-"); - if (iover) - diff2str(dqb->dqb_itime, timebuf, now); - else if (show_default) + if (show_default) snprintf(timebuf, sizeof(timebuf), "%llu", (unsigned long long)dqb->dqb_itime); + else if (iover) + diff2str(dqb->dqb_itime, timebuf, now); snprintf(numbuf[0], sizeof(numbuf), (dqb->dqb_valid & QIF_INODES) ? "%ju" : "[%ju]", -- 1.8.3.1