-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
* GPL HEADER START
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
* Author: Niu YaWei <niu@clusterfs.com>
*/
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
#define DEBUG_SUBSYSTEM S_LQUOTA
#include <linux/version.h>
#include "quota_internal.h"
-#ifdef HAVE_QUOTA_SUPPORT
-
-/* lock ordering: mds->mds_qonoff_sem > dquot->dq_sem */
+/* lock ordering: mds->mds_qonoff_sem > dquot->dq_mutex > lqs->lqs_lock */
static cfs_list_t lustre_dquot_hash[NR_DQHASH];
-static cfs_spinlock_t dquot_hash_lock = CFS_SPIN_LOCK_UNLOCKED;
+static DEFINE_RWLOCK(dquot_hash_lock);
cfs_mem_cache_t *lustre_dquot_cachep;
struct lustre_dquot *dquot;
ENTRY;
- LASSERT_SPIN_LOCKED(&dquot_hash_lock);
cfs_list_for_each_entry(dquot, &lustre_dquot_hash[hashent], dq_hash) {
if (dquot->dq_info == lqi &&
dquot->dq_id == id && dquot->dq_type == type)
RETURN(NULL);
CFS_INIT_LIST_HEAD(&dquot->dq_hash);
- cfs_init_mutex_locked(&dquot->dq_sem);
- dquot->dq_refcnt = 1;
+ cfs_mutex_init(&dquot->dq_mutex);
+ cfs_mutex_lock(&dquot->dq_mutex);
+ cfs_atomic_set(&dquot->dq_refcnt, 1);
dquot->dq_info = lqi;
dquot->dq_id = id;
dquot->dq_type = type;
- dquot->dq_status = DQ_STATUS_AVAIL;
RETURN(dquot);
}
static void lustre_dqput(struct lustre_dquot *dquot)
{
ENTRY;
- cfs_spin_lock(&dquot_hash_lock);
- LASSERT(dquot->dq_refcnt);
- dquot->dq_refcnt--;
- if (!dquot->dq_refcnt) {
+ cfs_write_lock(&dquot_hash_lock);
+ LASSERT(cfs_atomic_read(&dquot->dq_refcnt));
+ cfs_atomic_dec(&dquot->dq_refcnt);
+ if (cfs_atomic_read(&dquot->dq_refcnt) == 0) {
remove_dquot_nolock(dquot);
free_dquot(dquot);
}
- cfs_spin_unlock(&dquot_hash_lock);
+ cfs_write_unlock(&dquot_hash_lock);
EXIT;
}
static struct lustre_dquot *lustre_dqget(struct obd_device *obd,
struct lustre_quota_info *lqi,
- qid_t id, int type)
+ qid_t id, int type, int can_fake)
{
unsigned int hashent = dquot_hashfn(lqi, id, type);
struct lustre_dquot *dquot, *empty;
+ int free_dq = 0;
ENTRY;
if ((empty = alloc_dquot(lqi, id, type)) == NULL)
RETURN(ERR_PTR(-ENOMEM));
- cfs_spin_lock(&dquot_hash_lock);
+ cfs_read_lock(&dquot_hash_lock);
if ((dquot = find_dquot(hashent, lqi, id, type)) != NULL) {
- dquot->dq_refcnt++;
- cfs_spin_unlock(&dquot_hash_lock);
- free_dquot(empty);
+ cfs_atomic_inc(&dquot->dq_refcnt);
+ cfs_read_unlock(&dquot_hash_lock);
+ cfs_mutex_unlock(&empty->dq_mutex);
+ free_dq = 1;
} else {
int rc;
- dquot = empty;
- insert_dquot_nolock(dquot);
- cfs_spin_unlock(&dquot_hash_lock);
+ cfs_read_unlock(&dquot_hash_lock);
+ dquot = empty;
rc = fsfilt_dquot(obd, dquot, QFILE_RD_DQUOT);
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
if (rc) {
CERROR("can't read dquot from admin quotafile! "
"(rc:%d)\n", rc);
- lustre_dqput(dquot);
+ free_dquot(dquot);
RETURN(ERR_PTR(rc));
+ } else {
+ cfs_write_lock(&dquot_hash_lock);
+ if ((dquot = find_dquot(hashent, lqi, id, type)) != NULL) {
+ cfs_atomic_inc(&dquot->dq_refcnt);
+ free_dq = 1;
+ } else {
+ dquot = empty;
+ insert_dquot_nolock(dquot);
+ }
+ cfs_write_unlock(&dquot_hash_lock);
}
}
LASSERT(dquot);
+ if (!can_fake && cfs_test_bit(DQ_FAKE_B, &dquot->dq_flags)) {
+ DQUOT_DEBUG(dquot, "It is a fake dquot: unexpected!\n");
+ lustre_dqput(dquot);
+ dquot = ERR_PTR(-ENOENT);
+ }
+
+ if (free_dq)
+ free_dquot(empty);
+
+
RETURN(dquot);
}
LASSERT(mds);
cfs_down_read(&mds->mds_qonoff_sem);
- dquot = lustre_dqget(obd, info, id, type);
+ dquot = lustre_dqget(obd, info, id, type, 0);
if (IS_ERR(dquot))
RETURN(PTR_ERR(dquot));
if (!oqaq)
GOTO(out, rc = -ENOMEM);
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
init_oqaq(oqaq, qctxt, id, type);
rc = dquot_create_oqaq(qctxt, dquot, ost_num, mdt_num,
else
qid[USRQUOTA] = dquot->dq_id;
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
rc = qctxt_adjust_qunit(obd, qctxt, qid, is_blk, 0, NULL);
if (rc == -EDQUOT || rc == -EBUSY) {
/* only when block qunit is reduced, boardcast to osts */
if ((adjust_res & LQS_BLK_DECREASE) && QAQ_IS_ADJBLK(oqaq))
- rc = obd_quota_adjust_qunit(mds->mds_lov_exp, oqaq, qctxt);
+ rc = obd_quota_adjust_qunit(mds->mds_lov_exp, oqaq, qctxt, NULL);
out:
lustre_dqput(dquot);
RETURN(rc);
out_sem:
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
goto out;
}
if (OBD_FAIL_CHECK(OBD_FAIL_OBD_DQACQ))
RETURN(-EIO);
+ if (!ll_sb_has_quota_active(qctxt->lqc_sb,
+ QDATA_IS_GRP(qdata) ? GRPQUOTA : USRQUOTA))
+ RETURN(-EIO);
+
+ lqs = quota_search_lqs(LQS_KEY(QDATA_IS_GRP(qdata), qdata->qd_id),
+ qctxt, 0);
+ if (lqs == NULL)
+ rc = -ENOENT;
+ if (IS_ERR(lqs))
+ rc = PTR_ERR(lqs);
+ if (rc)
+ RETURN(rc);
+
+ cfs_spin_lock(&lqs->lqs_lock);
+ if (LQS_IS_RECOVERY(lqs)) {
+ cfs_spin_unlock(&lqs->lqs_lock);
+ LQS_DEBUG(lqs, "this lqs is under recovery\n");
+ GOTO(skip, rc = -EBUSY);
+ }
+ cfs_spin_unlock(&lqs->lqs_lock);
+
cfs_down_write(&mds->mds_qonoff_sem);
- dquot = lustre_dqget(obd, info, qdata->qd_id, QDATA_IS_GRP(qdata));
+ dquot = lustre_dqget(obd, info, qdata->qd_id, QDATA_IS_GRP(qdata), 0);
if (IS_ERR(dquot)) {
cfs_up_write(&mds->mds_qonoff_sem);
- RETURN(PTR_ERR(dquot));
+ GOTO(skip, rc = PTR_ERR(dquot));
}
DQUOT_DEBUG(dquot, "get dquot in dqacq_handler\n");
QINFO_DEBUG(dquot->dq_info, "get dquot in dqadq_handler\n");
- cfs_down(&dquot->dq_sem);
-
- if (dquot->dq_status & DQ_STATUS_RECOVERY) {
- DQUOT_DEBUG(dquot, "this dquot is under recovering.\n");
- GOTO(out, rc = -EBUSY);
- }
+ cfs_mutex_lock(&dquot->dq_mutex);
if (QDATA_IS_BLK(qdata)) {
grace = info->qi_info[QDATA_IS_GRP(qdata)].dqi_bgrace;
case QUOTA_DQREL:
/* The usage in administrative file might be incorrect before
* recovery done */
- if (*usage - qdata->qd_count < 0)
+ if (*usage < qdata->qd_count)
*usage = 0;
else
*usage -= qdata->qd_count;
rc = fsfilt_dquot(obd, dquot, QFILE_WR_DQUOT);
EXIT;
out:
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
cfs_up_write(&mds->mds_qonoff_sem);
lustre_dqput(dquot);
if (rc != -EDQUOT)
dqacq_adjust_qunit_sz(obd, qdata->qd_id, QDATA_IS_GRP(qdata),
QDATA_IS_BLK(qdata));
- lqs = quota_search_lqs(LQS_KEY(QDATA_IS_GRP(qdata), qdata->qd_id),
- qctxt, 0);
- if (lqs == NULL || IS_ERR(lqs)) {
- CDEBUG(D_INFO, "Can't find the lustre qunit size!\n");
- qdata->qd_qunit = QDATA_IS_BLK(qdata) ? qctxt->lqc_bunit_sz :
- qctxt->lqc_iunit_sz;
- } else {
- cfs_spin_lock(&lqs->lqs_lock);
- qdata->qd_qunit = QDATA_IS_BLK(qdata) ? lqs->lqs_bunit_sz :
- lqs->lqs_iunit_sz;
- cfs_spin_unlock(&lqs->lqs_lock);
- }
+
+ cfs_spin_lock(&lqs->lqs_lock);
+ qdata->qd_qunit = QDATA_IS_BLK(qdata) ? lqs->lqs_bunit_sz :
+ lqs->lqs_iunit_sz;
+ cfs_spin_unlock(&lqs->lqs_lock);
if (QDATA_IS_BLK(qdata))
QDATA_SET_ADJBLK(qdata);
QDATA_SET_ADJINO(qdata);
QDATA_DEBUG(qdata, "alloc/release qunit in dqacq_handler\n");
- if (lqs)
- lqs_putref(lqs);
+skip:
+ lqs_putref(lqs);
return rc;
}
if (!Q_TYPESET(oqctl, i))
continue;
if (qinfo->qi_files[i] == NULL) {
- CWARN("quota[%d] is off already\n", i);
+ CDEBUG(D_QUOTA, "quota[%d] is off already\n", i);
rc = -EALREADY;
continue;
}
EXIT;
out:
+ CDEBUG(D_QUOTA, "%s: quotaoff type:flags:rc %u:%lu:%d\n",
+ obd->obd_name, oqctl->qc_type, qctxt->lqc_flags, rc);
cfs_up_write(&mds->mds_qonoff_sem);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
return rc ? : (rc1 ? : rc2);
if (!dquot || !oqaq)
RETURN(-EINVAL);
- LASSERT_SEM_LOCKED(&dquot->dq_sem);
+ LASSERT_MUTEX_LOCKED(&dquot->dq_mutex);
LASSERT(oqaq->qaq_iunit_sz);
LASSERT(oqaq->qaq_bunit_sz);
oqaq->qaq_bunit_sz =
QUSG(oqaq->qaq_bunit_sz * cqs_factor, 1)
<< QUOTABLOCK_BITS;
+ if (oqaq->qaq_bunit_sz >= qctxt->lqc_bunit_sz)
+ break;
b_limitation = oqaq->qaq_bunit_sz * (ost_num + 1) *
shrink_qunit_limit;
}
while (ilimit > dquot->dq_dqb.dqb_curinodes
+ 2 * i_limitation) {
oqaq->qaq_iunit_sz = oqaq->qaq_iunit_sz * cqs_factor;
+ if (oqaq->qaq_iunit_sz >= qctxt->lqc_iunit_sz)
+ break;
i_limitation = oqaq->qaq_iunit_sz * mdt_num *
shrink_qunit_limit;
}
/* adjust remote lqs */
if (QAQ_IS_ADJBLK(qaq)) {
- rc = obd_quota_adjust_qunit(obd->u.mds.mds_lov_exp, qaq, qctxt);
+ rc = obd_quota_adjust_qunit(obd->u.mds.mds_lov_exp, qaq, qctxt, NULL);
if (rc < 0)
CERROR("adjust slaves' qunit size failed!(rc=%d)\n", rc);
/* orig_set means if quota was set before; now_set means we are
* setting/cancelling quota */
int orig_set, now_set;
- int rc, rc2 = 0, flag = 0;
+ struct lustre_qunit_size *lqs;
+ int rc = 0, rc2 = 0, flag = 0;
ENTRY;
if (oqctl->qc_type != USRQUOTA &&
GOTO(out_sem, rc = -ESRCH);
}
- dquot = lustre_dqget(obd, qinfo, oqctl->qc_id, oqctl->qc_type);
+ dquot = lustre_dqget(obd, qinfo, oqctl->qc_id, oqctl->qc_type, 1);
if (IS_ERR(dquot))
GOTO(out_sem, rc = PTR_ERR(dquot));
DQUOT_DEBUG(dquot, "get dquot in mds_set_blk\n");
QINFO_DEBUG(dquot->dq_info, "get dquot in mds_set_blk\n");
- cfs_down(&dquot->dq_sem);
+ lqs = quota_search_lqs(LQS_KEY(oqctl->qc_type, oqctl->qc_id), qctxt, 1);
+ if (lqs == NULL)
+ rc = -ENOENT;
+ if (IS_ERR(lqs))
+ rc = PTR_ERR(lqs);
+ if (rc)
+ GOTO(out, rc);
- if (dquot->dq_status) {
- cfs_up(&dquot->dq_sem);
- lustre_dqput(dquot);
- GOTO(out_sem, rc = -EBUSY);
+ cfs_mutex_lock(&dquot->dq_mutex);
+ cfs_spin_lock(&lqs->lqs_lock);
+ if (LQS_IS_SETQUOTA(lqs) || LQS_IS_RECOVERY(lqs)) {
+ cfs_spin_unlock(&lqs->lqs_lock);
+ cfs_mutex_unlock(&dquot->dq_mutex);
+ GOTO(skip, rc = -EBUSY);
}
- dquot->dq_status |= DQ_STATUS_SET;
+ LQS_SET_SETQUOTA(lqs);
+ cfs_spin_unlock(&lqs->lqs_lock);
ihardlimit = dquot->dq_dqb.dqb_ihardlimit;
isoftlimit = dquot->dq_dqb.dqb_isoftlimit;
rc = fsfilt_dquot(obd, dquot, QFILE_WR_DQUOT);
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
if (rc) {
CERROR("set limit failed! (rc:%d)\n", rc);
- goto out;
+ GOTO(update_fail, rc);
}
cfs_up_write(&mds->mds_qonoff_sem);
orig_set = ihardlimit || isoftlimit;
now_set = dqblk->dqb_ihardlimit || dqblk->dqb_isoftlimit;
if (dqblk->dqb_valid & QIF_ILIMITS && orig_set != now_set) {
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
dquot->dq_dqb.dqb_curinodes = 0;
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
rc = mds_init_slave_ilimits(obd, oqctl, orig_set);
if (rc) {
CERROR("init slave ilimits failed! (rc:%d)\n", rc);
orig_set = bhardlimit || bsoftlimit;
now_set = dqblk->dqb_bhardlimit || dqblk->dqb_bsoftlimit;
if (dqblk->dqb_valid & QIF_BLIMITS && orig_set != now_set) {
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
dquot->dq_dqb.dqb_curspace = 0;
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
rc = mds_init_slave_blimits(obd, oqctl, orig_set);
if (rc) {
CERROR("init slave blimits failed! (rc:%d)\n", rc);
revoke_out:
cfs_down_write(&mds->mds_qonoff_sem);
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
if (rc) {
/* cancel previous setting */
dquot->dq_dqb.dqb_ihardlimit = ihardlimit;
dquot->dq_dqb.dqb_itime = itime;
}
rc2 = fsfilt_dquot(obd, dquot, QFILE_WR_DQUOT);
- cfs_up(&dquot->dq_sem);
-
+ cfs_mutex_unlock(&dquot->dq_mutex);
+update_fail:
+ cfs_spin_lock(&lqs->lqs_lock);
+ LQS_CLEAR_SETQUOTA(lqs);
+ cfs_spin_unlock(&lqs->lqs_lock);
+skip:
+ lqs_putref(lqs);
out:
- cfs_down(&dquot->dq_sem);
- dquot->dq_status &= ~DQ_STATUS_SET;
- cfs_up(&dquot->dq_sem);
lustre_dqput(dquot);
EXIT;
out_sem:
GOTO(out, rc = -ESRCH);
}
- dquot = lustre_dqget(obd, qinfo, oqctl->qc_id, oqctl->qc_type);
+ dquot = lustre_dqget(obd, qinfo, oqctl->qc_id, oqctl->qc_type, 1);
if (IS_ERR(dquot))
GOTO(out, rc = PTR_ERR(dquot));
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
dqblk->dqb_ihardlimit = dquot->dq_dqb.dqb_ihardlimit;
dqblk->dqb_isoftlimit = dquot->dq_dqb.dqb_isoftlimit;
dqblk->dqb_bhardlimit = dquot->dq_dqb.dqb_bhardlimit;
dqblk->dqb_btime = dquot->dq_dqb.dqb_btime;
dqblk->dqb_itime = dquot->dq_dqb.dqb_itime;
dqblk->dqb_valid |= QIF_LIMITS | QIF_TIMES;
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
lustre_dqput(dquot);
cfs_up_read(&mds->mds_qonoff_sem);
dqblk->dqb_curinodes = 0;
dqblk->dqb_curspace = 0;
rc = mds_get_space(obd, oqctl);
+
RETURN(rc);
out:
dquot_recovery(struct obd_device *obd, unsigned int id, unsigned short type)
{
struct mds_obd *mds = &obd->u.mds;
- struct lustre_quota_info *qinfo= &mds->mds_quota_info;
+ struct lustre_quota_ctxt *qctxt = &mds->mds_obt.obt_qctxt;
+ struct lustre_quota_info *qinfo = &mds->mds_quota_info;
+ struct lustre_qunit_size *lqs;
struct lustre_dquot *dquot;
struct obd_quotactl *qctl;
__u64 total_limits = 0;
- int rc;
+ int rc = 0;
ENTRY;
OBD_ALLOC_PTR(qctl);
if (qctl == NULL)
RETURN(-ENOMEM);
- dquot = lustre_dqget(obd, qinfo, id, type);
+ dquot = lustre_dqget(obd, qinfo, id, type, 0);
if (IS_ERR(dquot)) {
CERROR("Get dquot failed. (rc:%ld)\n", PTR_ERR(dquot));
OBD_FREE_PTR(qctl);
RETURN(PTR_ERR(dquot));
}
- cfs_down(&dquot->dq_sem);
+ lqs = quota_search_lqs(LQS_KEY(type, id), qctxt, 1);
+ if (lqs == NULL)
+ rc = -ENOENT;
+ if (IS_ERR(lqs))
+ rc = PTR_ERR(lqs);
+ if (rc)
+ GOTO(skip, rc);
+
+ cfs_mutex_lock(&dquot->dq_mutex);
- /* don't recovery the dquot without limits or under setting */
+ /* don't recover the dquot without limits or quota is setting or
+ * another recovery is already going on */
if (!(dquot->dq_dqb.dqb_bhardlimit || dquot->dq_dqb.dqb_bsoftlimit) ||
- dquot->dq_status)
- GOTO(skip, rc = 0);
- dquot->dq_status |= DQ_STATUS_RECOVERY;
+ LQS_IS_SETQUOTA(lqs) || LQS_IS_RECOVERY(lqs)) {
+ cfs_mutex_unlock(&dquot->dq_mutex);
+ GOTO(skip1, rc = 0);
+ }
- cfs_up(&dquot->dq_sem);
+ cfs_spin_lock(&lqs->lqs_lock);
+ LQS_SET_RECOVERY(lqs);
+ cfs_spin_unlock(&lqs->lqs_lock);
+ cfs_mutex_unlock(&dquot->dq_mutex);
/* release mds_qonoff_sem during obd_quotactl ops here */
cfs_up_write(&mds->mds_qonoff_sem);
total_limits += qctl->qc_dqblk.dqb_bhardlimit;
/* amend the usage of the administrative quotafile */
- cfs_down(&dquot->dq_sem);
+ cfs_mutex_lock(&dquot->dq_mutex);
dquot->dq_dqb.dqb_curspace = total_limits << QUOTABLOCK_BITS;
if (rc)
CERROR("write dquot failed! (rc:%d)\n", rc);
- cfs_up(&dquot->dq_sem);
+ cfs_mutex_unlock(&dquot->dq_mutex);
EXIT;
out:
- cfs_down(&dquot->dq_sem);
- dquot->dq_status &= ~DQ_STATUS_RECOVERY;
+ cfs_spin_lock(&lqs->lqs_lock);
+ LQS_CLEAR_RECOVERY(lqs);
+ cfs_spin_unlock(&lqs->lqs_lock);
+skip1:
+ lqs_putref(lqs);
skip:
- cfs_up(&dquot->dq_sem);
-
lustre_dqput(dquot);
OBD_FREE_PTR(qctl);
return rc;
int rc = 0;
ENTRY;
+ if (!ll_sb_any_quota_active(obd->u.obt.obt_qctxt.lqc_sb))
+ RETURN(0);
+
if (unlikely(!mds->mds_quota || obd->obd_stopping))
RETURN(rc);
- cfs_mutex_down(&obd->obd_dev_sem);
+ cfs_mutex_lock(&obd->obd_dev_mutex);
if (mds->mds_lov_desc.ld_active_tgt_count != mds->mds_lov_objid_count) {
CWARN("Only %u/%u OSTs are active, abort quota recovery\n",
mds->mds_lov_desc.ld_active_tgt_count,
mds->mds_lov_objid_count);
- cfs_mutex_up(&obd->obd_dev_sem);
+ cfs_mutex_unlock(&obd->obd_dev_mutex);
RETURN(rc);
}
- cfs_mutex_up(&obd->obd_dev_sem);
+ cfs_mutex_unlock(&obd->obd_dev_mutex);
data.obd = obd;
cfs_init_completion(&data.comp);
- rc = cfs_kernel_thread(qmaster_recovery_main, &data,
- CLONE_VM|CLONE_FILES);
+ rc = cfs_create_thread(qmaster_recovery_main, &data,
+ CFS_DAEMON_FLAGS);
if (rc < 0)
CERROR("%s: cannot start quota recovery thread: rc %d\n",
obd->obd_name, rc);
cfs_wait_for_completion(&data.comp);
RETURN(rc);
}
-
-#endif /* HAVE_QUOTA_SUPPORT */