From: anserper Date: Fri, 22 May 2009 16:08:36 +0000 (+0000) Subject: b=19612 X-Git-Tag: v1_6_7_2~5 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=7a97892d8695e6dbab26d1bf09a57ce7246b42e9;p=fs%2Flustre-release.git b=19612 i=Johann Lombardi i=ZhiYong Tian additional parameter checking for lfs quota and lustre ioctls --- diff --git a/lustre/quota/quota_master.c b/lustre/quota/quota_master.c index adcdd3c..53ce5c2 100644 --- a/lustre/quota/quota_master.c +++ b/lustre/quota/quota_master.c @@ -613,6 +613,11 @@ int mds_quota_invalidate(struct obd_device *obd, struct obd_quotactl *oqctl) char name[64]; struct lvfs_run_ctxt saved; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + return -EINVAL; + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); @@ -658,6 +663,11 @@ int mds_quota_finvalidate(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; struct lvfs_run_ctxt saved; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); @@ -889,6 +899,11 @@ int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + if (!atomic_dec_and_test(&obt->obt_quotachecking)) { CDEBUG(D_INFO, "other people are doing quotacheck\n"); atomic_inc(&obt->obt_quotachecking); @@ -924,6 +939,11 @@ int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl) int rc, rc2; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA && + oqctl->qc_type != UGQUOTA) + RETURN(-EINVAL); + if (!atomic_dec_and_test(&obt->obt_quotachecking)) { CDEBUG(D_INFO, "other people are doing quotacheck\n"); atomic_inc(&obt->obt_quotachecking); @@ -955,6 +975,10 @@ int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); if (qinfo->qi_files[oqctl->qc_type] == NULL) { rc = -ESRCH; @@ -980,6 +1004,10 @@ int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl) int rc = 0; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); if (qinfo->qi_files[oqctl->qc_type] == NULL) { rc = -ESRCH; @@ -1265,6 +1293,10 @@ int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl) int rc, rc2 = 0, flag = 0; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + OBD_ALLOC_PTR(oqaq); if (!oqaq) RETURN(-ENOMEM); @@ -1459,6 +1491,10 @@ int mds_get_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl) int rc; ENTRY; + if (oqctl->qc_type != USRQUOTA && + oqctl->qc_type != GRPQUOTA) + RETURN(-EINVAL); + down(&mds->mds_qonoff_sem); dqblk->dqb_valid = 0; if (qinfo->qi_files[oqctl->qc_type] == NULL) diff --git a/lustre/tests/sanity-quota.sh b/lustre/tests/sanity-quota.sh index 28ee95a..882c289 100644 --- a/lustre/tests/sanity-quota.sh +++ b/lustre/tests/sanity-quota.sh @@ -67,7 +67,7 @@ OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd` SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR" SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR" -SHOW_QUOTA_INFO="$LFS quota -t $DIR" +SHOW_QUOTA_INFO="$LFS quota -t -u $DIR; $LFS quota -t -g $DIR" # control the time of tests cycle=30 @@ -1816,6 +1816,13 @@ test_24() { } run_test_with_stat 24 "test if lfs draws an asterix when limit is reached (16646) ===========" +test_27() { + $LFS quota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed" + $LFS setquota $TSTUSR $DIR && error "lfs succeeded with no type, but should have failed" + return 0 +} +run_test_with_stat 27 "lfs quota/setquota should handle wrong arguments (19612) =================" + # turn off quota test_99() { diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 4bfdf22..78b0903 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -1778,6 +1778,11 @@ int lfs_setquota(int argc, char **argv) return CMD_HELP; } + if (limit_mask == 0) { + fprintf(stderr, "error: at least one limit must be specified\n"); + return CMD_HELP; + } + if (optind != argc - 1) { fprintf(stderr, "error: unexpected parameters encountered\n"); return CMD_HELP; @@ -2121,8 +2126,10 @@ ug_output: (qctl.qc_type == USRQUOTA) ? USER : GROUP); if (rc) name = ""; + /* lfs quota -u username /path/to/lustre/mount */ } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) { - if (optind + 2 != argc) { + /* options should be followed by u/g-name and mntpoint */ + if (optind + 2 != argc || qctl.qc_type == UGQUOTA) { fprintf(stderr, "error: missing quota argument(s)\n"); return CMD_HELP; } @@ -2135,7 +2142,7 @@ ug_output: name, strerror(errno)); return CMD_HELP; } - } else if (optind + 1 != argc) { + } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) { fprintf(stderr, "error: missing quota info argument(s)\n"); return CMD_HELP; }