1) replace "cfs_semaphore_t" with "cfs_rw_semaphore_t" for "mds_qonoff_sem" to enhance the parallel processing of quota related operations
2) hold "mds_qonoff_sem" when call "lustre_read_quota()", and check parameter properly in such function
i=robert.read
i=landen
struct lustre_quota_info mds_quota_info;
struct lustre_quota_info mds_quota_info;
- cfs_semaphore_t mds_qonoff_sem;
+ cfs_rw_semaphore_t mds_qonoff_sem;
cfs_semaphore_t mds_health_sem;
unsigned long mds_fl_user_xattr:1,
mds_fl_acl:1,
cfs_semaphore_t mds_health_sem;
unsigned long mds_fl_user_xattr:1,
mds_fl_acl:1,
+ if (!f && !inode) {
+ CERROR("lustre_read_quota failed for no quota file!\n");
+ libcfs_debug_dumpstack(NULL);
+ return -EINVAL;
+ }
+
/* Support for both adm and op quota files must be provided */
if (f) {
rc = fsfilt_ext3_read_record(f, buf, count, &p);
/* Support for both adm and op quota files must be provided */
if (f) {
rc = fsfilt_ext3_read_record(f, buf, count, &p);
static const uint quota_magics[] = LUSTRE_INITQMAGICS;
const uint *quota_versions = lustre_initqversions[version];
static const uint quota_magics[] = LUSTRE_INITQMAGICS;
const uint *quota_versions = lustre_initqversions[version];
- if (!f && !inode) {
- CERROR("check_quota_file failed!\n");
- libcfs_debug_dumpstack(NULL);
- return -EINVAL;
- }
-
size = lustre_read_quota(f, inode, type, (char *)&dqhead,
sizeof(struct lustre_disk_dqheader), 0);
size = lustre_read_quota(f, inode, type, (char *)&dqhead,
sizeof(struct lustre_disk_dqheader), 0);
if (size != sizeof(struct lustre_disk_dqheader))
return -EINVAL;
if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
if (size != sizeof(struct lustre_disk_dqheader))
return -EINVAL;
if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
int id, is_master, rc = 0, local; /* means we need a local quotaon */
cfs_down(&obt->obt_quotachecking);
int id, is_master, rc = 0, local; /* means we need a local quotaon */
cfs_down(&obt->obt_quotachecking);
+ push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
id = UGQUOTA2LQC(oqctl->qc_type);
local = (obt->obt_qctxt.lqc_flags & id) != id;
id = UGQUOTA2LQC(oqctl->qc_type);
local = (obt->obt_qctxt.lqc_flags & id) != id;
is_master = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
if (is_master) {
is_master = !strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME);
if (is_master) {
- cfs_down(&obd->u.mds.mds_qonoff_sem);
+ cfs_down_write(&obd->u.mds.mds_qonoff_sem);
- push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
/* turn on cluster wide quota */
rc = mds_admin_quota_on(obd, oqctl);
/* 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",
if (rc && rc != -ENOENT)
CERROR("%s: %s admin quotaon failed. rc=%d\n",
obd->obd_name, global ? "global":"local",
if (rc == 0) {
if (local) {
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)
rc = fsfilt_quotactl(obd, obt->obt_sb, oqctl);
if (rc) {
if (rc != -ENOENT)
obt->obt_qctxt.lqc_flags |= UGQUOTA2LQC(oqctl->qc_type);
build_lqs(obd);
}
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)
}
if (rc == 0 && global && is_master)
- cfs_up(&obd->u.mds.mds_qonoff_sem);
+ cfs_up_write(&obd->u.mds.mds_qonoff_sem);
+ pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
cfs_up(&obt->obt_quotachecking);
return rc;
cfs_up(&obt->obt_quotachecking);
return rc;
rc = cfs_kernel_thread(target_quotacheck_thread, qta,
CLONE_VM|CLONE_FILES);
if (rc >= 0) {
rc = cfs_kernel_thread(target_quotacheck_thread, qta,
CLONE_VM|CLONE_FILES);
if (rc >= 0) {
+ /* target_quotacheck_thread will drop the ref on exp and release
+ * obt_quotachecking */
CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
obd->obd_name, rc);
RETURN(0);
CDEBUG(D_INFO, "%s: target_quotacheck_thread: %d\n",
obd->obd_name, rc);
RETURN(0);
mds->mds_quota_info.qi_version = LUSTRE_QUOTA_V2;
cfs_sema_init(&obt->obt_quotachecking, 1);
/* initialize quota master and quota context */
mds->mds_quota_info.qi_version = LUSTRE_QUOTA_V2;
cfs_sema_init(&obt->obt_quotachecking, 1);
/* initialize quota master and quota context */
- cfs_sema_init(&mds->mds_qonoff_sem, 1);
+ cfs_init_rwsem(&mds->mds_qonoff_sem);
rc = qctxt_init(obd, dqacq_handler);
if (rc) {
CERROR("%s: initialize quota context failed! (rc:%d)\n",
rc = qctxt_init(obd, dqacq_handler);
if (rc) {
CERROR("%s: initialize quota context failed! (rc:%d)\n",
memset(&oqctl, 0, sizeof(oqctl));
oqctl.qc_type = UGQUOTA;
memset(&oqctl, 0, sizeof(oqctl));
oqctl.qc_type = UGQUOTA;
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
mds_admin_quota_off(obd, &oqctl);
mds_admin_quota_off(obd, &oqctl);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
+ cfs_down_read(&mds->mds_qonoff_sem);
dquot = lustre_dqget(obd, info, id, type);
if (IS_ERR(dquot))
RETURN(PTR_ERR(dquot));
dquot = lustre_dqget(obd, info, id, type);
if (IS_ERR(dquot))
RETURN(PTR_ERR(dquot));
+ cfs_up_read(&mds->mds_qonoff_sem);
OBD_ALLOC_PTR(oqaq);
if (!oqaq)
GOTO(out, rc = -ENOMEM);
OBD_ALLOC_PTR(oqaq);
if (!oqaq)
GOTO(out, rc = -ENOMEM);
if (OBD_FAIL_CHECK(OBD_FAIL_OBD_DQACQ))
RETURN(-EIO);
if (OBD_FAIL_CHECK(OBD_FAIL_OBD_DQACQ))
RETURN(-EIO);
+ 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));
+ if (IS_ERR(dquot)) {
+ cfs_up_write(&mds->mds_qonoff_sem);
DQUOT_DEBUG(dquot, "get dquot in dqacq_handler\n");
QINFO_DEBUG(dquot->dq_info, "get dquot in dqadq_handler\n");
DQUOT_DEBUG(dquot, "get dquot in dqacq_handler\n");
QINFO_DEBUG(dquot->dq_info, "get dquot in dqadq_handler\n");
- cfs_down(&mds->mds_qonoff_sem);
cfs_down(&dquot->dq_sem);
if (dquot->dq_status & DQ_STATUS_RECOVERY) {
cfs_down(&dquot->dq_sem);
if (dquot->dq_status & DQ_STATUS_RECOVERY) {
EXIT;
out:
cfs_up(&dquot->dq_sem);
EXIT;
out:
cfs_up(&dquot->dq_sem);
- cfs_up(&mds->mds_qonoff_sem);
+ 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));
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)) {
lqs = quota_search_lqs(LQS_KEY(QDATA_IS_GRP(qdata), qdata->qd_id),
qctxt, 0);
if (lqs == NULL || IS_ERR(lqs)) {
cfs_down(&obt->obt_quotachecking);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
cfs_down(&obt->obt_quotachecking);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
for (i = 0; i < MAXQUOTAS; i++) {
struct file *fp;
for (i = 0; i < MAXQUOTAS; i++) {
struct file *fp;
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
cfs_up(&obt->obt_quotachecking);
RETURN(rc ? : rc1);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
cfs_up(&obt->obt_quotachecking);
RETURN(rc ? : rc1);
if (obt->obt_qctxt.lqc_flags & UGQUOTA2LQC(oqctl->qc_type))
GOTO(out, rc = -EBUSY);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
if (obt->obt_qctxt.lqc_flags & UGQUOTA2LQC(oqctl->qc_type))
GOTO(out, rc = -EBUSY);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
oqctl->qc_cmd = Q_FINVALIDATE;
rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
if (!rc)
rc = obd_quotactl(mds->mds_osc_exp, oqctl);
oqctl->qc_cmd = Q_FINVALIDATE;
rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);
if (!rc)
rc = obd_quotactl(mds->mds_osc_exp, oqctl);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
out:
cfs_up(&obt->obt_quotachecking);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
out:
cfs_up(&obt->obt_quotachecking);
LASSERT(qinfo->qi_version == LUSTRE_QUOTA_V2);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
LASSERT(qinfo->qi_version == LUSTRE_QUOTA_V2);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
-
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
for (i = 0; i < MAXQUOTAS && !rc; i++) {
struct file *fp;
for (i = 0; i < MAXQUOTAS && !rc; i++) {
struct file *fp;
}
qinfo->qi_files[i] = fp;
rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CHK);
}
qinfo->qi_files[i] = fp;
rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CHK);
- qinfo->qi_files[i] = 0;
+ qinfo->qi_files[i] = NULL;
filp_close(fp, 0);
}
else
filp_close(fp, 0);
}
else
filp_close(fp, 0);
qinfo->qi_files[i] = NULL;
}
filp_close(fp, 0);
qinfo->qi_files[i] = NULL;
}
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
RETURN(rc);
}
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
RETURN(rc);
}
RETURN(-EINVAL);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
RETURN(-EINVAL);
push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
/* close admin quota files */
rc2 = mds_admin_quota_off(obd, oqctl);
if (rc2 && rc2 != -EALREADY) {
/* close admin quota files */
rc2 = mds_admin_quota_off(obd, oqctl);
if (rc2 && rc2 != -EALREADY) {
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
return rc ? : (rc1 ? : rc2);
}
pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
return rc ? : (rc1 ? : rc2);
}
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
GOTO(out, rc = -ESRCH);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
GOTO(out, rc = -ESRCH);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_read(&mds->mds_qonoff_sem);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
GOTO(out, rc = -ESRCH);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
GOTO(out, rc = -ESRCH);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_read(&mds->mds_qonoff_sem);
OBD_ALLOC_PTR(oqaq);
if (!oqaq)
RETURN(-ENOMEM);
OBD_ALLOC_PTR(oqaq);
if (!oqaq)
RETURN(-ENOMEM);
- cfs_down(&mds->mds_qonoff_sem);
+
+ cfs_down_write(&mds->mds_qonoff_sem);
init_oqaq(oqaq, qctxt, oqctl->qc_id, oqctl->qc_type);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
init_oqaq(oqaq, qctxt, oqctl->qc_id, oqctl->qc_type);
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
- cfs_up(&mds->mds_qonoff_sem);
-
+ cfs_up_write(&mds->mds_qonoff_sem);
adjust_lqs(obd, oqaq);
orig_set = ihardlimit || isoftlimit;
adjust_lqs(obd, oqaq);
orig_set = ihardlimit || isoftlimit;
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_write(&mds->mds_qonoff_sem);
cfs_down(&dquot->dq_sem);
if (rc) {
/* cancel previous setting */
cfs_down(&dquot->dq_sem);
if (rc) {
/* cancel previous setting */
lustre_dqput(dquot);
EXIT;
out_sem:
lustre_dqput(dquot);
EXIT;
out_sem:
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_write(&mds->mds_qonoff_sem);
if (oqaq)
OBD_FREE_PTR(oqaq);
if (oqaq)
OBD_FREE_PTR(oqaq);
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
oqctl->qc_type != GRPQUOTA)
RETURN(-EINVAL);
- cfs_down(&mds->mds_qonoff_sem);
+ cfs_down_read(&mds->mds_qonoff_sem);
dqblk->dqb_valid = 0;
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
dqblk->dqb_valid = 0;
if (qinfo->qi_files[oqctl->qc_type] == NULL) {
CWARN("quota[%u] is off\n", oqctl->qc_type);
cfs_up(&dquot->dq_sem);
lustre_dqput(dquot);
cfs_up(&dquot->dq_sem);
lustre_dqput(dquot);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_read(&mds->mds_qonoff_sem);
/* the usages in admin quota file is inaccurate */
dqblk->dqb_curinodes = 0;
dqblk->dqb_curspace = 0;
rc = mds_get_space(obd, oqctl);
/* the usages in admin quota file is inaccurate */
dqblk->dqb_curinodes = 0;
dqblk->dqb_curspace = 0;
rc = mds_get_space(obd, oqctl);
- cfs_up(&mds->mds_qonoff_sem);
+ cfs_up_read(&mds->mds_qonoff_sem);
+ /* release mds_qonoff_sem during obd_quotactl ops here */
+ cfs_up_write(&mds->mds_qonoff_sem);
+
/* get real bhardlimit from all slaves. */
qctl->qc_cmd = Q_GETOQUOTA;
qctl->qc_type = type;
qctl->qc_id = id;
qctl->qc_stat = QUOTA_RECOVERING;
rc = obd_quotactl(mds->mds_osc_exp, qctl);
/* get real bhardlimit from all slaves. */
qctl->qc_cmd = Q_GETOQUOTA;
qctl->qc_type = type;
qctl->qc_id = id;
qctl->qc_stat = QUOTA_RECOVERING;
rc = obd_quotactl(mds->mds_osc_exp, qctl);
+ cfs_down_write(&mds->mds_qonoff_sem);
if (rc)
GOTO(out, rc);
total_limits = qctl->qc_dqblk.dqb_bhardlimit;
if (rc)
GOTO(out, rc);
total_limits = qctl->qc_dqblk.dqb_bhardlimit;
total_limits += qctl->qc_dqblk.dqb_bhardlimit;
/* amend the usage of the administrative quotafile */
total_limits += qctl->qc_dqblk.dqb_bhardlimit;
/* amend the usage of the administrative quotafile */
- cfs_down(&mds->mds_qonoff_sem);
cfs_down(&dquot->dq_sem);
dquot->dq_dqb.dqb_curspace = total_limits << QUOTABLOCK_BITS;
cfs_down(&dquot->dq_sem);
dquot->dq_dqb.dqb_curspace = total_limits << QUOTABLOCK_BITS;
CERROR("write dquot failed! (rc:%d)\n", rc);
cfs_up(&dquot->dq_sem);
CERROR("write dquot failed! (rc:%d)\n", rc);
cfs_up(&dquot->dq_sem);
- cfs_up(&mds->mds_qonoff_sem);
EXIT;
out:
cfs_down(&dquot->dq_sem);
EXIT;
out:
cfs_down(&dquot->dq_sem);
cfs_complete(&data->comp);
cfs_complete(&data->comp);
+ cfs_down_write(&mds->mds_qonoff_sem);
for (type = USRQUOTA; type < MAXQUOTAS; type++) {
cfs_list_t id_list;
struct dquot_id *dqid, *tmp;
for (type = USRQUOTA; type < MAXQUOTAS; type++) {
cfs_list_t id_list;
struct dquot_id *dqid, *tmp;
- cfs_down(&mds->mds_qonoff_sem);
- if (qinfo->qi_files[type] == NULL) {
- cfs_up(&mds->mds_qonoff_sem);
+ if (qinfo->qi_files[type] == NULL)
CFS_INIT_LIST_HEAD(&id_list);
rc = fsfilt_qids(obd, qinfo->qi_files[type], NULL, type,
&id_list);
CFS_INIT_LIST_HEAD(&id_list);
rc = fsfilt_qids(obd, qinfo->qi_files[type], NULL, type,
&id_list);
- cfs_up(&mds->mds_qonoff_sem);
-
if (rc)
CERROR("error get ids from admin quotafile.(%d)\n", rc);
if (rc)
CERROR("error get ids from admin quotafile.(%d)\n", rc);
+ cfs_up_write(&mds->mds_qonoff_sem);
class_decref(mds->mds_osc_obd, "qmaster_recovd_lov", mds->mds_osc_obd);
class_decref(obd, "qmaster_recovd_mds", obd);
RETURN(rc);
class_decref(mds->mds_osc_obd, "qmaster_recovd_lov", mds->mds_osc_obd);
class_decref(obd, "qmaster_recovd_mds", obd);
RETURN(rc);