quota_master.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,592 行 · 第 1/4 页
C
1,592 行
LBUG(); } rc = fsfilt_dquot(obd, dquot, QFILE_WR_DQUOT); EXIT;out: up(&dquot->dq_sem); up(&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)); quota_search_lqs(qdata, NULL, qctxt, &lqs); if (QDATA_IS_BLK(qdata)) { if (!lqs) { CDEBUG(D_INFO, "Can't find the lustre qunit size!\n"); qdata->qd_qunit = qctxt->lqc_bunit_sz; } else { spin_lock(&lqs->lqs_lock); qdata->qd_qunit = lqs->lqs_bunit_sz; spin_unlock(&lqs->lqs_lock); } QDATA_SET_ADJBLK(qdata); } else { if (!lqs) { CDEBUG(D_INFO, "Can't find the lustre qunit size!\n"); qdata->qd_qunit = qctxt->lqc_iunit_sz; } else { spin_lock(&lqs->lqs_lock); qdata->qd_qunit = lqs->lqs_iunit_sz; spin_unlock(&lqs->lqs_lock); } QDATA_SET_ADJINO(qdata); } QDATA_DEBUG(qdata, "alloc/release qunit in dqacq_handler\n"); if (lqs) lqs_putref(lqs); return rc;}int mds_quota_adjust(struct obd_device *obd, unsigned int qcids[], unsigned int qpids[], int rc, int opc){ struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt; int rc2 = 0; ENTRY; if (rc && rc != -EDQUOT && rc != ENOLCK) RETURN(0); switch (opc) { case FSFILT_OP_RENAME: /* acquire/release block quota on owner of original parent */ rc2 = qctxt_adjust_qunit(obd, qctxt, qpids[2], qpids[3], 1, 0); /* fall-through */ case FSFILT_OP_SETATTR: /* acquire/release file quota on original owner */ rc2 |= qctxt_adjust_qunit(obd, qctxt, qpids[0], qpids[1], 0, 0); /* fall-through */ case FSFILT_OP_CREATE: case FSFILT_OP_UNLINK: /* acquire/release file/block quota on owner of child * (or current owner) */ rc2 |= qctxt_adjust_qunit(obd, qctxt, qcids[0], qcids[1], 0, 0); rc2 |= qctxt_adjust_qunit(obd, qctxt, qcids[0], qcids[1], 1, 0); /* acquire/release block quota on owner of parent * (or original owner) */ rc2 |= qctxt_adjust_qunit(obd, qctxt, qpids[0], qpids[1], 1, 0); break; default: LBUG(); break; } if (rc2) CDEBUG(rc2 == -EAGAIN ? D_QUOTA: D_ERROR, "mds adjust qunit failed! (opc:%d rc:%d)\n", opc, rc2); RETURN(0);}int filter_quota_adjust(struct obd_device *obd, unsigned int qcids[], unsigned int qpids[], int rc, int opc){ struct lustre_quota_ctxt *qctxt = &obd->u.obt.obt_qctxt; int rc2 = 0; ENTRY; if (rc && rc != -EDQUOT) RETURN(0); switch (opc) { case FSFILT_OP_SETATTR: /* acquire/release block quota on original & current owner */ rc = qctxt_adjust_qunit(obd, qctxt, qcids[0], qcids[1], 1, 0); rc2 = qctxt_adjust_qunit(obd, qctxt, qpids[0], qpids[1], 1, 0); break; case FSFILT_OP_UNLINK: /* release block quota on this owner */ case FSFILT_OP_CREATE: /* XXX for write operation on obdfilter */ /* acquire block quota on this owner */ rc = qctxt_adjust_qunit(obd, qctxt, qcids[0], qcids[1], 1, 0); break; default: LBUG(); break; } if (rc || rc2) { if (!rc) rc = rc2; CDEBUG(rc == -EAGAIN ? D_QUOTA: D_ERROR, "filter adjust qunit failed! (opc:%d rc%d)\n", opc, rc); } RETURN(0);}static const char prefix[] = "OBJECTS/";int mds_quota_get_version(struct obd_device *obd, lustre_quota_version_t *version){ struct mds_obd *mds = &obd->u.mds; struct lustre_quota_info *qinfo = &mds->mds_quota_info; *version = qinfo->qi_version; return 0;}int mds_quota_set_version(struct obd_device *obd, lustre_quota_version_t version){ struct mds_obd *mds = &obd->u.mds; struct lustre_quota_info *qinfo = &mds->mds_quota_info; int rc = 0, i; if (version != LUSTRE_QUOTA_V1 && version != LUSTRE_QUOTA_V2) return -EINVAL; down(&mds->mds_qonoff_sem); /* no need to change version? nothing to do then */ if (qinfo->qi_version == version) goto out; for (i = 0; i < MAXQUOTAS; i++) { /* quota file has been opened ? */ if (qinfo->qi_files[i]) { rc = -EBUSY; goto out; } } CDEBUG(D_INFO, "changing quota version %d -> %d\n", qinfo->qi_version, version); qinfo->qi_version = version;out: up(&mds->mds_qonoff_sem); return rc;}int mds_quota_invalidate(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 = 0, i; char *quotafiles_v1[] = LUSTRE_ADMIN_QUOTAFILES_V1; char *quotafiles_v2[] = LUSTRE_ADMIN_QUOTAFILES_V2; char name[64]; struct lvfs_run_ctxt saved; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); for (i = 0; i < MAXQUOTAS; i++) { struct file *fp; char* quotafile = (qinfo->qi_version == LUSTRE_QUOTA_V1)? quotafiles_v1[i]:quotafiles_v2[i]; if (!Q_TYPESET(oqctl, i)) continue; /* quota file has been opened ? */ if (qinfo->qi_files[i]) { rc = -EBUSY; goto out; } LASSERT(strlen(quotafile) + sizeof(prefix) <= sizeof(name)); sprintf(name, "%s%s", prefix, quotafile); fp = filp_open(name, O_CREAT | O_TRUNC, 0644); if (IS_ERR(fp)) { rc = PTR_ERR(fp); CERROR("error invalidating admin quotafile %s (rc:%d)\n", name, rc); } else filp_close(fp, 0); }out: up(&mds->mds_qonoff_sem); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); return rc;}int init_admin_quotafiles(struct obd_device *obd, struct obd_quotactl *oqctl){ struct mds_obd *mds = &obd->u.mds; struct lustre_quota_info *qinfo = &mds->mds_quota_info; char *quotafiles_v1[] = LUSTRE_ADMIN_QUOTAFILES_V1; char *quotafiles_v2[] = LUSTRE_ADMIN_QUOTAFILES_V2; struct lvfs_run_ctxt saved; char name[64]; int i, rc = 0; ENTRY; push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); down(&mds->mds_qonoff_sem); for (i = 0; i < MAXQUOTAS && !rc; i++) { struct file *fp; char* quotafile = (qinfo->qi_version == LUSTRE_QUOTA_V1)? quotafiles_v1[i]:quotafiles_v2[i]; if (!Q_TYPESET(oqctl, i)) continue; /* quota file has been opened ? */ if (qinfo->qi_files[i]) { CWARN("init %s admin quotafile while quota on.\n", i == USRQUOTA ? "user" : "group"); continue; } LASSERT(strlen(quotafile) + sizeof(prefix) <= sizeof(name)); sprintf(name, "%s%s", prefix, quotafile); /* check if quota file exists and is correct */ fp = filp_open(name, O_RDONLY, 0); if (!IS_ERR(fp)) { /* irregular file is not the right place for quota */ if (!S_ISREG(fp->f_dentry->d_inode->i_mode)) { CERROR("admin quota file %s is not " "regular!", quotafile); filp_close(fp, 0); rc = -EINVAL; break; } qinfo->qi_files[i] = fp; rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CHK); qinfo->qi_files[i] = 0; filp_close(fp, 0); } else rc = PTR_ERR(fp); if (!rc) continue; /* -EINVAL may be returned by quotainfo for bad quota file */ if (rc != -ENOENT && rc != -EINVAL) { CERROR("error opening old quota file %s (%d)\n", name, rc); break; } CDEBUG(D_INFO, "%s new quota file %s\n", name, rc == -ENOENT ? "creating" : "overwriting"); /* create quota file overwriting old if needed */ fp = filp_open(name, O_CREAT | O_TRUNC, 0644); if (IS_ERR(fp)) { rc = PTR_ERR(fp); CERROR("error creating admin quotafile %s (rc:%d)\n", name, rc); break; } qinfo->qi_files[i] = fp; switch (qinfo->qi_version) { case LUSTRE_QUOTA_V1: rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_INIT_INFO); if (rc) CERROR("error init %s admin quotafile! (rc:%d)\n", i == USRQUOTA ? "user" : "group", rc); break; case LUSTRE_QUOTA_V2: rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CONVERT); if (rc) CERROR("error convert %s admin quotafile! (rc:%d)\n", i == USRQUOTA ? "user" : "group", rc); break; default: LBUG(); } filp_close(fp, 0); qinfo->qi_files[i] = NULL; } up(&mds->mds_qonoff_sem); pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); RETURN(rc);}static int close_quota_files(struct obd_quotactl *oqctl, struct lustre_quota_info *qinfo){ int i, rc = 0; ENTRY; for (i = 0; i < MAXQUOTAS; i++) { if (!Q_TYPESET(oqctl, i)) continue; if (qinfo->qi_files[i] == NULL) { rc = -ESRCH; continue; } filp_close(qinfo->qi_files[i], 0); qinfo->qi_files[i] = NULL; } RETURN(rc);}int mds_admin_quota_on(struct obd_device *obd, struct obd_quotactl *oqctl){ struct mds_obd *mds = &obd->u.mds; struct lustre_quota_info *qinfo = &mds->mds_quota_info; const char *quotafiles_v1[] = LUSTRE_ADMIN_QUOTAFILES_V1; const char *quotafiles_v2[] = LUSTRE_ADMIN_QUOTAFILES_V2; char name[64]; int i, rc = 0; ENTRY; /* open admin quota files and read quotafile info */ for (i = 0; i < MAXQUOTAS; i++) { struct file *fp; const char* quotafile = qinfo->qi_version == LUSTRE_QUOTA_V1? quotafiles_v1[i] : quotafiles_v2[i]; if (!Q_TYPESET(oqctl, i)) continue; LASSERT(strlen(quotafile) + sizeof(prefix) <= sizeof(name)); sprintf(name, "%s%s", prefix, quotafile); if (qinfo->qi_files[i] != NULL) { rc = -EBUSY; break; } fp = filp_open(name, O_RDWR, 0); /* handle transparent migration to 64 bit quota file */ if (IS_ERR(fp) && PTR_ERR(fp) == -ENOENT && qinfo->qi_version == LUSTRE_QUOTA_V2) { CDEBUG(D_INFO, "attempting to convert V1 quota file to" " V2 format\n"); fp = filp_open(name, O_CREAT | O_TRUNC, 0644); if (!IS_ERR(fp)) { qinfo->qi_files[i] = fp; rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CONVERT); if (rc) { CERROR("error convert %s admin " "quotafile! (rc:%d)\n", i == USRQUOTA ? "user" : "group", rc); break; } } } if (IS_ERR(fp) || !S_ISREG(fp->f_dentry->d_inode->i_mode)) { rc = IS_ERR(fp) ? PTR_ERR(fp) : -EINVAL; CERROR("error open/create %s! (rc:%d)\n", name, rc); break; } qinfo->qi_files[i] = fp; rc = fsfilt_quotainfo(obd, qinfo, i, QFILE_CHK); if (rc) { CERROR("invalid quota file %s! (rc:%d)\n", name, rc); break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?