quotafmt_test.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 509 行 · 第 1/2 页
C
509 行
GOTO(out, rc); } out: put_rand_dquot(dquot); RETURN(rc);}static int quotfmt_test_3(struct lustre_quota_info *lqi){ struct lustre_dquot *dquot; int i = 0, rc = 0; ENTRY; dquot = get_rand_dquot(lqi); if (dquot == NULL) RETURN(-ENOMEM); repeat: clear_bit(DQ_FAKE_B, &dquot->dq_flags); /* write a new dquot */ rc = lustre_commit_dquot(dquot); if (rc) { CERROR("commit dquot failed! (rc:%d)\n", rc); GOTO(out, rc); } dquot->dq_off = 0; memset(&dquot->dq_dqb, 0, sizeof(dquot->dq_dqb)); /* check if this dquot is on disk now */ rc = lustre_read_dquot(dquot); if (rc) { CERROR("read dquot failed! (rc:%d)\n", rc); GOTO(out, rc); } if (!dquot->dq_off || test_bit(DQ_FAKE_B, &dquot->dq_flags)) { CERROR("the dquot isn't committed\n"); GOTO(out, rc = -EINVAL); } /* remove this dquot */ set_bit(DQ_FAKE_B, &dquot->dq_flags); dquot->dq_dqb.dqb_curspace = 0; dquot->dq_dqb.dqb_curinodes = 0; rc = lustre_commit_dquot(dquot); if (rc) { CERROR("remove dquot failed! (rc:%d)\n", rc); GOTO(out, rc); } /* check if the dquot is really removed */ clear_bit(DQ_FAKE_B, &dquot->dq_flags); dquot->dq_off = 0; rc = lustre_read_dquot(dquot); if (rc) { CERROR("read dquot failed! (rc:%d)\n", rc); GOTO(out, rc); } if (!test_bit(DQ_FAKE_B, &dquot->dq_flags) || dquot->dq_off) { CERROR("the dquot isn't removed!\n"); GOTO(out, rc = -EINVAL); } /* check if this dquot can be write again */ if (++i < 2) goto repeat; print_quota_info(lqi); out: put_rand_dquot(dquot); RETURN(rc);}static int quotfmt_test_4(struct lustre_quota_info *lqi){ int i, rc = 0; ENTRY; for (i = 0; i < 30000; i++) { rc = write_check_dquot(lqi); if (rc) { CERROR("write/check dquot failed at %d! (rc:%d)\n", i, rc); break; } } print_quota_info(lqi); RETURN(rc);}static int quotfmt_test_5(struct lustre_quota_info *lqi){#ifndef KERNEL_SUPPORTS_QUOTA_READ int i, rc = 0; for (i = USRQUOTA; i < MAXQUOTAS && !rc; i++) { struct list_head list; struct dquot_id *dqid, *tmp; INIT_LIST_HEAD(&list); rc = lustre_get_qids(lqi->qi_files[i], NULL, i, &list); if (rc) { CERROR("%s get all %ss (rc:%d):\n", rc ? "error" : "success", i == USRQUOTA ? "uid" : "gid", rc); } list_for_each_entry_safe(dqid, tmp, &list, di_link) { list_del_init(&dqid->di_link); if (rc == 0) printk("%d ", dqid->di_id); kfree(dqid); } printk("\n"); } return rc;#else CWARN("kernel supports quota_read OR kernel version >= 2.6.12, test skipped\n"); return 0;#endif}static int quotfmt_run_tests(struct obd_device *obd, struct obd_device *tgt){ struct lvfs_run_ctxt saved; struct lustre_quota_info *lqi = NULL; int rc = 0; ENTRY; OBD_ALLOC(lqi, sizeof(*lqi)); if (lqi == NULL) { CERROR("not enough memory\n"); RETURN(-ENOMEM); } CWARN("=== Initialize quotafile test\n"); rc = quotfmt_initialize(lqi, tgt, &saved); if (rc) GOTO(out, rc); CWARN("=== test 1: check quota header\n"); rc = quotfmt_test_1(lqi); if (rc) { CERROR("check quota header failed! (rc:%d)\n", rc); GOTO(out, rc); } CWARN("=== test 2: write/read quota info\n"); rc = quotfmt_test_2(lqi); if (rc) { CERROR("write/read quota info failed! (rc:%d)\n", rc); GOTO(out, rc); } CWARN("=== test 3: write/remove dquot\n"); rc = quotfmt_test_3(lqi); if (rc) { CERROR("write/remove dquot failed! (rc:%d)\n", rc); GOTO(out, rc); } CWARN("=== test 4: write/read 30000 dquot\n"); rc = quotfmt_test_4(lqi); if (rc) { CERROR("write/read 30000 dquot failed\n"); GOTO(out, rc); } CWARN("=== test 5: walk through quota file to get all ids\n"); rc = quotfmt_test_5(lqi); if (rc) { CERROR("walk through quota file failed\n"); GOTO(out, rc); } out: CWARN("=== Finalize quotafile test\n"); rc = quotfmt_finalize(lqi, tgt, &saved); OBD_FREE(lqi, sizeof(*lqi)); RETURN(rc);}static int quotfmt_test_cleanup(struct obd_device *obd){ ENTRY; lprocfs_obd_cleanup(obd); RETURN(0);}static int quotfmt_test_setup(struct obd_device *obd, obd_count len, void *buf){ struct lprocfs_static_vars lvars; struct lustre_cfg *lcfg = buf; struct obd_device *tgt; int rc; ENTRY; if (lcfg->lcfg_bufcount < 1) { CERROR("requires a mds OBD name\n"); RETURN(-EINVAL); } tgt = class_name2obd(lustre_cfg_string(lcfg, 1)); if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) { CERROR("target device not attached or not set up (%s)\n", lustre_cfg_string(lcfg, 1)); RETURN(-EINVAL); } rc = quotfmt_run_tests(obd, tgt); if (rc) quotfmt_test_cleanup(obd); lprocfs_quotfmt_test_init_vars(&lvars); lprocfs_obd_setup(obd, lvars.obd_vars); RETURN(rc);}static struct obd_ops quotfmt_obd_ops = { .o_owner = THIS_MODULE, .o_setup = quotfmt_test_setup, .o_cleanup = quotfmt_test_cleanup,};#ifdef LPROCFSstatic struct lprocfs_vars lprocfs_quotfmt_test_obd_vars[] = { {0} };static struct lprocfs_vars lprocfs_quotfmt_test_module_vars[] = { {0} };void lprocfs_quotfmt_test_init_vars(struct lprocfs_static_vars *lvars){ lvars->module_vars = lprocfs_quotfmt_test_module_vars; lvars->obd_vars = lprocfs_quotfmt_test_obd_vars;}#endifstatic int __init quotfmt_test_init(void){ struct lprocfs_static_vars lvars; lprocfs_quotfmt_test_init_vars(&lvars); return class_register_type("fmt_obd_ops, lvars.module_vars, "quotfmt_test");}static void __exit quotfmt_test_exit(void){ class_unregister_type("quotfmt_test");}MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");MODULE_DESCRIPTION("administrative quotafile test module");MODULE_LICENSE("GPL");module_init(quotfmt_test_init);module_exit(quotfmt_test_exit);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?