quota_master.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,592 行 · 第 1/4 页

C
1,592
字号
                }                rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_RD_INFO);                if (rc) {                        CERROR("error read quotainfo of %s! (rc:%d)\n", name,                               rc);                        break;                }        }        if (rc && rc != -EBUSY)                close_quota_files(oqctl, qinfo);        RETURN(rc);}static int mds_admin_quota_off(struct obd_device *obd,                               struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct lustre_quota_info *qinfo = &mds->mds_quota_info;        int rc;        ENTRY;        /* close admin quota files */        rc = close_quota_files(oqctl, qinfo);        RETURN(rc);}int mds_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct obd_device_target *obt = &obd->u.obt;        struct lvfs_run_ctxt saved;        int rc;        ENTRY;        if (!atomic_dec_and_test(&obt->obt_quotachecking)) {                CDEBUG(D_INFO, "other people are doing quotacheck\n");                atomic_inc(&obt->obt_quotachecking);                RETURN(-EBUSY);        }        down(&mds->mds_qonoff_sem);        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        rc = mds_admin_quota_on(obd, oqctl);        if (rc)                goto out;        rc = obd_quotactl(mds->mds_osc_exp, oqctl);        if (rc)                goto out;        rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);        if (!rc)                obt->obt_qctxt.lqc_status = 1;out:        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        up(&mds->mds_qonoff_sem);        atomic_inc(&obt->obt_quotachecking);        RETURN(rc);}int mds_quota_off(struct obd_device *obd, struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct obd_device_target *obt = &obd->u.obt;        struct lvfs_run_ctxt saved;        int rc, rc2;        ENTRY;        if (!atomic_dec_and_test(&obt->obt_quotachecking)) {                CDEBUG(D_INFO, "other people are doing quotacheck\n");                atomic_inc(&obt->obt_quotachecking);                RETURN(-EBUSY);        }        down(&mds->mds_qonoff_sem);        /* close admin quota files */        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        mds_admin_quota_off(obd, oqctl);        rc = obd_quotactl(mds->mds_osc_exp, oqctl);        rc2 = fsfilt_quotactl(obd, obd->u.obt.obt_sb, oqctl);        if (!rc2)                obt->obt_qctxt.lqc_status = 0;        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        up(&mds->mds_qonoff_sem);        atomic_inc(&obt->obt_quotachecking);        RETURN(rc ?: rc2);}int mds_set_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct lustre_quota_info *qinfo = &mds->mds_quota_info;        struct obd_dqinfo *dqinfo = &oqctl->qc_dqinfo;        int rc;        ENTRY;        down(&mds->mds_qonoff_sem);        if (qinfo->qi_files[oqctl->qc_type] == NULL) {                rc = -ESRCH;                goto out;        }        qinfo->qi_info[oqctl->qc_type].dqi_bgrace = dqinfo->dqi_bgrace;        qinfo->qi_info[oqctl->qc_type].dqi_igrace = dqinfo->dqi_igrace;        qinfo->qi_info[oqctl->qc_type].dqi_flags = dqinfo->dqi_flags;        rc = fsfilt_quotainfo(obd, qinfo, oqctl->qc_type, QFILE_WR_INFO);out:        up(&mds->mds_qonoff_sem);        RETURN(rc);}int mds_get_dqinfo(struct obd_device *obd, struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct lustre_quota_info *qinfo = &mds->mds_quota_info;        struct obd_dqinfo *dqinfo = &oqctl->qc_dqinfo;        int rc = 0;        ENTRY;        down(&mds->mds_qonoff_sem);        if (qinfo->qi_files[oqctl->qc_type] == NULL) {                rc = -ESRCH;                goto out;        }        dqinfo->dqi_bgrace = qinfo->qi_info[oqctl->qc_type].dqi_bgrace;        dqinfo->dqi_igrace = qinfo->qi_info[oqctl->qc_type].dqi_igrace;        dqinfo->dqi_flags = qinfo->qi_info[oqctl->qc_type].dqi_flags;out:        up(&mds->mds_qonoff_sem);        RETURN(rc);}int dquot_create_oqaq(struct lustre_quota_ctxt *qctxt,                      struct lustre_dquot *dquot, __u32 ost_num, __u32 mdt_num,                      int type, struct quota_adjust_qunit *oqaq){        __u64 bunit_curr_o, iunit_curr_o;        unsigned long shrink_qunit_limit = qctxt->lqc_cqs_boundary_factor;        unsigned long cqs_factor = qctxt->lqc_cqs_qs_factor;        __u64 blimit = dquot->dq_dqb.dqb_bhardlimit ?                dquot->dq_dqb.dqb_bhardlimit : dquot->dq_dqb.dqb_bsoftlimit;        __u64 ilimit = dquot->dq_dqb.dqb_ihardlimit ?                dquot->dq_dqb.dqb_ihardlimit : dquot->dq_dqb.dqb_isoftlimit;        int rc = 0;        ENTRY;        if (!dquot || !oqaq)                RETURN(-EINVAL);        LASSERT_SEM_LOCKED(&dquot->dq_sem);        LASSERT(oqaq->qaq_iunit_sz);        LASSERT(oqaq->qaq_bunit_sz);        /* don't change qunit size */        if (!qctxt->lqc_switch_qs)                RETURN(rc);        bunit_curr_o = oqaq->qaq_bunit_sz;        iunit_curr_o = oqaq->qaq_iunit_sz;        if (dquot->dq_type == GRPQUOTA)                QAQ_SET_GRP(oqaq);        if ((type & LQUOTA_FLAGS_ADJBLK) && blimit) {                __u64 b_limitation =                        oqaq->qaq_bunit_sz * ost_num * shrink_qunit_limit;                /* enlarge block qunit size */                while (blimit >                       QUSG(dquot->dq_dqb.dqb_curspace + 2 * b_limitation, 1)) {                        oqaq->qaq_bunit_sz =                                QUSG(oqaq->qaq_bunit_sz * cqs_factor, 1)                                << QUOTABLOCK_BITS;                        b_limitation = oqaq->qaq_bunit_sz * ost_num *                                shrink_qunit_limit;                }                if (oqaq->qaq_bunit_sz > qctxt->lqc_bunit_sz)                        oqaq->qaq_bunit_sz = qctxt->lqc_bunit_sz;                /* shrink block qunit size */                while (blimit <                       QUSG(dquot->dq_dqb.dqb_curspace + b_limitation, 1)) {                        do_div(oqaq->qaq_bunit_sz , cqs_factor);                        oqaq->qaq_bunit_sz = QUSG(oqaq->qaq_bunit_sz, 1) <<                                QUOTABLOCK_BITS;                        b_limitation = oqaq->qaq_bunit_sz * ost_num *                                shrink_qunit_limit;                        if (oqaq->qaq_bunit_sz <  qctxt->lqc_cqs_least_bunit)                                break;                }                if (oqaq->qaq_bunit_sz < qctxt->lqc_cqs_least_bunit)                        oqaq->qaq_bunit_sz = qctxt->lqc_cqs_least_bunit;                if (bunit_curr_o != oqaq->qaq_bunit_sz)                        QAQ_SET_ADJBLK(oqaq);        }        if ((type & LQUOTA_FLAGS_ADJINO) && ilimit) {                __u64 i_limitation =                        oqaq->qaq_iunit_sz * mdt_num * shrink_qunit_limit;                /* enlarge file qunit size */                while (ilimit > dquot->dq_dqb.dqb_curinodes                       + 2 * i_limitation) {                        oqaq->qaq_iunit_sz = oqaq->qaq_iunit_sz * cqs_factor;                        i_limitation = oqaq->qaq_iunit_sz * mdt_num *                                shrink_qunit_limit;                }                if (oqaq->qaq_iunit_sz > qctxt->lqc_iunit_sz)                        oqaq->qaq_iunit_sz = qctxt->lqc_iunit_sz;                /* shrink file qunit size */                while (ilimit < dquot->dq_dqb.dqb_curinodes                       + i_limitation) {                        do_div(oqaq->qaq_iunit_sz, cqs_factor);                        i_limitation = oqaq->qaq_iunit_sz * mdt_num *                                       shrink_qunit_limit;                        if (oqaq->qaq_iunit_sz < qctxt->lqc_cqs_least_iunit)                                break;                }                if (oqaq->qaq_iunit_sz < qctxt->lqc_cqs_least_iunit)                        oqaq->qaq_iunit_sz = qctxt->lqc_cqs_least_iunit;                if (iunit_curr_o != oqaq->qaq_iunit_sz)                        QAQ_SET_ADJINO(oqaq);        }        if (!dquot->dq_dqb.dqb_bhardlimit && !dquot->dq_dqb.dqb_bsoftlimit &&            !dquot->dq_dqb.dqb_ihardlimit && !dquot->dq_dqb.dqb_isoftlimit) {                oqaq->qaq_bunit_sz = 0;                oqaq->qaq_iunit_sz = 0;                QAQ_SET_ADJBLK(oqaq);                QAQ_SET_ADJINO(oqaq);        }        QAQ_DEBUG(oqaq, "the oqaq computed\n");        RETURN(rc);}static int mds_init_slave_ilimits(struct obd_device *obd,                                  struct obd_quotactl *oqctl, int set,                                  struct quota_adjust_qunit *oqaq){        /* XXX: for file limits only adjust local now */        struct obd_device_target *obt = &obd->u.obt;        struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;        unsigned int uid = 0, gid = 0;        struct obd_quotactl *ioqc = NULL;        int flag;        int rc;        ENTRY;        /* if we are going to set zero limit, needn't init slaves */        if (!oqctl->qc_dqblk.dqb_ihardlimit && !oqctl->qc_dqblk.dqb_isoftlimit &&            set)                RETURN(0);        OBD_ALLOC_PTR(ioqc);        if (!ioqc)                RETURN(-ENOMEM);        flag = oqctl->qc_dqblk.dqb_ihardlimit ||               oqctl->qc_dqblk.dqb_isoftlimit || set;        ioqc->qc_cmd = flag ? Q_INITQUOTA : Q_SETQUOTA;        ioqc->qc_id = oqctl->qc_id;        ioqc->qc_type = oqctl->qc_type;        ioqc->qc_dqblk.dqb_valid = QIF_ILIMITS;        ioqc->qc_dqblk.dqb_ihardlimit = flag ? MIN_QLIMIT : 0;        if (QAQ_IS_ADJINO(oqaq)) {                /* adjust the mds slave's inode qunit size */                rc = quota_adjust_slave_lqs(oqaq, qctxt);                if (rc < 0)                        CDEBUG(D_ERROR, "adjust mds slave's inode qunit size \                               failed! (rc:%d)\n", rc);        }        /* set local limit to MIN_QLIMIT */        rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, ioqc);        if (rc)                GOTO(out, rc);        /* trigger local qunit pre-acquire */        if (oqctl->qc_type == USRQUOTA)                uid = oqctl->qc_id;        else                gid = oqctl->qc_id;        rc = qctxt_adjust_qunit(obd, &obd->u.obt.obt_qctxt, uid, gid, 0, 0);        if (rc == -EDQUOT || rc == -EBUSY) {                CDEBUG(D_QUOTA, "rc: %d.\n", rc);                rc = 0;        }        if (rc) {                CDEBUG(D_QUOTA,"error mds adjust local file quota! (rc:%d)\n",                       rc);                GOTO(out, rc);        }        /* FIXME initialize all slaves in CMD */        EXIT;out:        if (ioqc)                OBD_FREE_PTR(ioqc);        return rc;}static int mds_init_slave_blimits(struct obd_device *obd,                                  struct obd_quotactl *oqctl, int set,                                  struct quota_adjust_qunit *oqaq){        struct obd_device_target *obt = &obd->u.obt;        struct lustre_quota_ctxt *qctxt = &obt->obt_qctxt;        struct mds_obd *mds = &obd->u.mds;        struct obd_quotactl *ioqc;        unsigned int uid = 0, gid = 0;        int rc, rc1 = 0;        int flag;        ENTRY;        /* if we are going to set zero limit, needn't init slaves */        if (!oqctl->qc_dqblk.dqb_bhardlimit && !oqctl->qc_dqblk.dqb_bsoftlimit &&            set)                RETURN(0);        OBD_ALLOC_PTR(ioqc);        if (!ioqc)                RETURN(-ENOMEM);        flag = oqctl->qc_dqblk.dqb_bhardlimit ||               oqctl->qc_dqblk.dqb_bsoftlimit || set;        ioqc->qc_cmd = flag ? Q_INITQUOTA : Q_SETQUOTA;        ioqc->qc_id = oqctl->qc_id;        ioqc->qc_type = oqctl->qc_type;        ioqc->qc_dqblk.dqb_valid = QIF_BLIMITS;        ioqc->qc_dqblk.dqb_bhardlimit = flag ? MIN_QLIMIT : 0;        if (QAQ_IS_ADJBLK(oqaq)) {                /* adjust the mds slave's block qunit size */                rc1 = quota_adjust_slave_lqs(oqaq, qctxt);                if (rc1 < 0)                        CERROR("adjust mds slave's block qunit size failed!"                               "(rc:%d)\n", rc1);        }        rc = fsfilt_quotactl(obd, obd->u.obt.obt_sb, ioqc);        if (rc)                GOTO(out, rc);        /* trigger local qunit pre-acquire */        if (oqctl->qc_type == USRQUOTA)                uid = oqctl->qc_id;        else                gid = oqctl->qc_id;        /* initialize all slave's limit */        rc = obd_quotactl(mds->mds_osc_exp, ioqc);        rc = qctxt_adjust_qunit(obd, &obd->u.obt.obt_qctxt, uid, gid, 1, 0);        if (rc == -EDQUOT || rc == -EBUSY) {                CDEBUG(D_QUOTA, "rc: %d.\n", rc);                rc = 0;        }        if (rc) {                CERROR("error mds adjust local block quota! (rc:%d)\n", rc);                GOTO(out, rc);        }        /* adjust all slave's qunit size when setting quota         * this is will create a lqs for every ost, which will present         * certain uid/gid is set quota or not */        QAQ_SET_ADJBLK(oqaq);        rc = obd_quota_adjust_qunit(mds->mds_osc_exp, oqaq);        EXIT;out:        OBD_FREE_PTR(ioqc);        return rc;}int mds_set_dqblk(struct obd_device *obd, struct obd_quotactl *oqctl){        struct mds_obd *mds = &obd->u.mds;        struct lustre_quota_ctxt *qctxt = &mds->mds_obt.obt_qctxt;        struct obd_device *lov_obd = class_exp2obd(mds->mds_osc_exp);        struct lov_obd *lov = &lov_obd->u.lov;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?