X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;ds=sidebyside;f=lustre%2Fquota%2Flproc_quota.c;h=6f0114aabdafd2e9e93c5039f544c8a1fe9af3c4;hb=cc580d67ee72fce637374891714885c889dce026;hp=93a28828deb64fe0f221900c6d96dc648205a404;hpb=7661294557774975dbd7aa90014f4ab1610db7df;p=fs%2Flustre-release.git diff --git a/lustre/quota/lproc_quota.c b/lustre/quota/lproc_quota.c index 93a2882..6f0114a 100644 --- a/lustre/quota/lproc_quota.c +++ b/lustre/quota/lproc_quota.c @@ -202,72 +202,83 @@ int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count, } EXPORT_SYMBOL(lprocfs_quota_rd_type); -static int auto_quota_on(struct obd_device *obd, int type, - struct super_block *sb, int is_master) +/* + * generic_quota_on is very lazy and tolerant about current quota settings + * @global means to turn on quotas on each OST additionally to local quotas; + * should not be called from filter_quota_ctl on MDS nodes (as it starts + * admin quotas on MDS nodes). + */ +int generic_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl, int global) { - struct obd_quotactl *oqctl; + struct obd_device_target *obt = &obd->u.obt; struct lvfs_run_ctxt saved; - int rc = 0, id; - struct obd_device_target *obt; - ENTRY; + int id, is_master, rc = 0, local; /* means we need a local quotaon */ - LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA); - - obt = &obd->u.obt; + cfs_down(&obt->obt_quotachecking); + id = UGQUOTA2LQC(oqctl->qc_type); + local = (obt->obt_qctxt.lqc_flags & id) != id; - OBD_ALLOC_PTR(oqctl); - if (!oqctl) - RETURN(-ENOMEM); + oqctl->qc_cmd = Q_QUOTAON; + oqctl->qc_id = obt->obt_qfmt; - if (!atomic_dec_and_test(&obt->obt_quotachecking)) { - CDEBUG(D_INFO, "other people are doing quotacheck\n"); - atomic_inc(&obt->obt_quotachecking); - RETURN(-EBUSY); + is_master = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME); + if (is_master) { + cfs_down(&obd->u.mds.mds_qonoff_sem); + if (local) { + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + /* turn on cluster wide quota */ + rc = mds_admin_quota_on(obd, oqctl); + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + if (rc && rc != -ENOENT) + CERROR("%s: %s admin quotaon failed. rc=%d\n", + obd->obd_name, global ? "global":"local", + rc); + } } - id = UGQUOTA2LQC(type); - /* quota already turned on */ - if ((obt->obt_qctxt.lqc_flags & id) == id) { - rc = 0; - goto out; - } - if (obt->obt_qctxt.lqc_immutable) { - LCONSOLE_ERROR("Failed to turn Quota on, immutable mode " - "(is SOM enabled?)\n"); - goto out; + if (rc == 0) { + if (local) { + push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + rc = fsfilt_quotactl(obd, obt->obt_sb, oqctl); + if (rc) { + if (rc != -ENOENT) + CERROR("%s: %s quotaon failed with" + " rc=%d\n", obd->obd_name, + global ? "global" : "local", rc); + } else { + obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(oqctl->qc_type); + build_lqs(obd); + } + pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + } + + if (rc == 0 && global && is_master) + rc = obd_quotactl(obd->u.mds.mds_osc_exp, oqctl); } - oqctl->qc_type = type; - oqctl->qc_cmd = Q_QUOTAON; - oqctl->qc_id = obt->obt_qfmt; + if (is_master) + cfs_up(&obd->u.mds.mds_qonoff_sem); - push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); - if (is_master) { - struct mds_obd *mds = &obd->u.mds; + cfs_up(&obt->obt_quotachecking); - down(&mds->mds_qonoff_sem); - /* turn on cluster wide quota */ - rc = mds_admin_quota_on(obd, oqctl); - if (rc) - CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR, - "auto-enable admin quota failed. rc=%d\n", rc); - up(&mds->mds_qonoff_sem); + return rc; +} - } - if (!rc) { - /* turn on local quota */ - rc = fsfilt_quotactl(obd, sb, oqctl); - if (rc) - CDEBUG(rc == -ENOENT ? D_QUOTA : D_ERROR, - "auto-enable local quota failed. rc=%d\n", rc); - else - obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(type); - } +static int auto_quota_on(struct obd_device *obd, int type) +{ + struct obd_quotactl *oqctl; + int rc; + ENTRY; - pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); + LASSERT(type == USRQUOTA || type == GRPQUOTA || type == UGQUOTA); -out: - atomic_inc(&obt->obt_quotachecking); + OBD_ALLOC_PTR(oqctl); + if (!oqctl) + RETURN(-ENOMEM); + + oqctl->qc_type = type; + + rc = generic_quota_on(obd, oqctl, 0); OBD_FREE_PTR(oqctl); RETURN(rc); @@ -291,7 +302,7 @@ int lprocfs_quota_wr_type(struct file *file, const char *buffer, if (count > MAX_STYPE_SIZE) return -EINVAL; - if (copy_from_user(stype, buffer, count)) + if (cfs_copy_from_user(stype, buffer, count)) return -EFAULT; for (i = 0 ; i < count ; i++) { @@ -314,8 +325,10 @@ int lprocfs_quota_wr_type(struct file *file, const char *buffer, } if (type != 0) { - auto_quota_on(obd, type - 1, obt->obt_sb, is_mds); - build_lqs(obd); + int rc = auto_quota_on(obd, type - 1); + + if (rc && rc != -EALREADY && rc != -ENOENT) + return rc; } return count; @@ -583,8 +596,8 @@ int lquota_proc_setup(struct obd_device *obd, int is_master) lprocfs_quota_common_vars, obd); if (IS_ERR(qctxt->lqc_proc_dir)) { rc = PTR_ERR(qctxt->lqc_proc_dir); - CERROR("error %d setting up lprocfs for %s\n", rc, - obd->obd_name); + CERROR("%s: error %d setting up lprocfs\n", + obd->obd_name, rc); qctxt->lqc_proc_dir = NULL; GOTO(out, rc); } @@ -593,8 +606,8 @@ int lquota_proc_setup(struct obd_device *obd, int is_master) rc = lprocfs_add_vars(qctxt->lqc_proc_dir, lprocfs_quota_master_vars, obd); if (rc) { - CERROR("error %d setting up lprocfs for %s" - "(quota master)\n", rc, obd->obd_name); + CERROR("%s: error %d setting up lprocfs for " + "quota master\n", obd->obd_name, rc); GOTO(out_free_proc, rc); } }