Whamcloud - gitweb
b=19612
authoranserper <anserper>
Fri, 22 May 2009 19:26:55 +0000 (19:26 +0000)
committeranserper <anserper>
Fri, 22 May 2009 19:26:55 +0000 (19:26 +0000)
i=Johann Lombardi
i=ZhiYong Tian

additional parameter checking for lfs quota and lustre ioctls

lustre/quota/quota_master.c
lustre/tests/sanity-quota.sh
lustre/utils/lfs.c

index b142426..263c701 100644 (file)
@@ -609,6 +609,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);
@@ -654,6 +659,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);
 
@@ -885,6 +895,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);
@@ -920,6 +935,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);
@@ -951,6 +971,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;
@@ -976,6 +1000,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;
@@ -1290,6 +1318,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);
@@ -1484,6 +1516,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)
index 590bfa5..f210515 100644 (file)
@@ -71,7 +71,7 @@ SHOW_QUOTA_USER="$LFS quota -v -u $TSTUSR $DIR"
 SHOW_QUOTA_USER2="$LFS quota -v -u $TSTUSR2 $DIR"
 SHOW_QUOTA_GROUP="$LFS quota -v -g $TSTUSR $DIR"
 SHOW_QUOTA_GROUP2="$LFS quota -v -g $TSTUSR2 $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
@@ -2096,6 +2096,13 @@ test_26() {
 }
 run_test_with_stat 26 "test for false quota error(bz18491) ======================================"
 
+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()
 {
index 0bcc4f7..370b0d1 100644 (file)
@@ -1723,6 +1723,11 @@ int lfs_setquota_times(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;
@@ -2196,8 +2201,10 @@ ug_output:
                              (qctl.qc_type == USRQUOTA) ? USER : GROUP);
                 if (rc)
                         name = "<unknown>";
+        /* 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;
                 }
@@ -2210,7 +2217,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;
         }