quota_interface.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 948 行 · 第 1/3 页
C
948 行
ENTRY; rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, 0, 1); RETURN(rc);}static int mds_quota_pending_commit(struct obd_device *obd, unsigned int uid, unsigned int gid, int inodes){ return quota_pending_commit(obd, uid, gid, inodes, 0);}#endif /* __KERNEL__ */struct osc_quota_info { struct list_head oqi_hash; /* hash list */ struct client_obd *oqi_cli; /* osc obd */ unsigned int oqi_id; /* uid/gid of a file */ short oqi_type; /* quota type */};spinlock_t qinfo_list_lock = SPIN_LOCK_UNLOCKED;static struct list_head qinfo_hash[NR_DQHASH];/* SLAB cache for client quota context */cfs_mem_cache_t *qinfo_cachep = NULL;static inline int hashfn(struct client_obd *cli, unsigned long id, int type) __attribute__((__const__));static inline int hashfn(struct client_obd *cli, unsigned long id, int type){ unsigned long tmp = ((unsigned long)cli>>6) ^ id; tmp = (tmp * (MAXQUOTAS - type)) % NR_DQHASH; return tmp;}/* caller must hold qinfo_list_lock */static inline void insert_qinfo_hash(struct osc_quota_info *oqi){ struct list_head *head = qinfo_hash + hashfn(oqi->oqi_cli, oqi->oqi_id, oqi->oqi_type); LASSERT_SPIN_LOCKED(&qinfo_list_lock); list_add(&oqi->oqi_hash, head);}/* caller must hold qinfo_list_lock */static inline void remove_qinfo_hash(struct osc_quota_info *oqi){ LASSERT_SPIN_LOCKED(&qinfo_list_lock); list_del_init(&oqi->oqi_hash);}/* caller must hold qinfo_list_lock */static inline struct osc_quota_info *find_qinfo(struct client_obd *cli, unsigned int id, int type){ unsigned int hashent = hashfn(cli, id, type); struct osc_quota_info *oqi; LASSERT_SPIN_LOCKED(&qinfo_list_lock); list_for_each_entry(oqi, &qinfo_hash[hashent], oqi_hash) { if (oqi->oqi_cli == cli && oqi->oqi_id == id && oqi->oqi_type == type) return oqi; } return NULL;}static struct osc_quota_info *alloc_qinfo(struct client_obd *cli, unsigned int id, int type){ struct osc_quota_info *oqi; ENTRY; OBD_SLAB_ALLOC(oqi, qinfo_cachep, CFS_ALLOC_STD, sizeof(*oqi)); if(!oqi) RETURN(NULL); CFS_INIT_LIST_HEAD(&oqi->oqi_hash); oqi->oqi_cli = cli; oqi->oqi_id = id; oqi->oqi_type = type; RETURN(oqi);}static void free_qinfo(struct osc_quota_info *oqi){ OBD_SLAB_FREE(oqi, qinfo_cachep, sizeof(*oqi));}int osc_quota_chkdq(struct client_obd *cli, unsigned int uid, unsigned int gid){ unsigned int id; int cnt, rc = QUOTA_OK; ENTRY; spin_lock(&qinfo_list_lock); for (cnt = 0; cnt < MAXQUOTAS; cnt++) { struct osc_quota_info *oqi = NULL; id = (cnt == USRQUOTA) ? uid : gid; oqi = find_qinfo(cli, id, cnt); if (oqi) { rc = NO_QUOTA; break; } } spin_unlock(&qinfo_list_lock); RETURN(rc);}int osc_quota_setdq(struct client_obd *cli, unsigned int uid, unsigned int gid, obd_flag valid, obd_flag flags){ unsigned int id; obd_flag noquota; int cnt, rc = 0; ENTRY; for (cnt = 0; cnt < MAXQUOTAS; cnt++) { struct osc_quota_info *oqi, *old; if (!(valid & ((cnt == USRQUOTA) ? OBD_MD_FLUSRQUOTA : OBD_MD_FLGRPQUOTA))) continue; id = (cnt == USRQUOTA) ? uid : gid; noquota = (cnt == USRQUOTA) ? (flags & OBD_FL_NO_USRQUOTA) : (flags & OBD_FL_NO_GRPQUOTA); oqi = alloc_qinfo(cli, id, cnt); if (oqi) { spin_lock(&qinfo_list_lock); old = find_qinfo(cli, id, cnt); if (old && !noquota) remove_qinfo_hash(old); else if (!old && noquota) insert_qinfo_hash(oqi); spin_unlock(&qinfo_list_lock); if (old || !noquota) free_qinfo(oqi); if (old && !noquota) free_qinfo(old); } else { CERROR("not enough mem!\n"); rc = -ENOMEM; break; } } RETURN(rc);}int osc_quota_cleanup(struct obd_device *obd){ struct client_obd *cli = &obd->u.cli; struct osc_quota_info *oqi, *n; int i; ENTRY; spin_lock(&qinfo_list_lock); for (i = 0; i < NR_DQHASH; i++) { list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) { if (oqi->oqi_cli != cli) continue; remove_qinfo_hash(oqi); free_qinfo(oqi); } } spin_unlock(&qinfo_list_lock); RETURN(0);}int osc_quota_init(void){ int i; ENTRY; LASSERT(qinfo_cachep == NULL); qinfo_cachep = cfs_mem_cache_create("osc_quota_info", sizeof(struct osc_quota_info), 0, 0); if (!qinfo_cachep) RETURN(-ENOMEM); for (i = 0; i < NR_DQHASH; i++) CFS_INIT_LIST_HEAD(qinfo_hash + i); RETURN(0);}int osc_quota_exit(void){ struct osc_quota_info *oqi, *n; int i, rc; ENTRY; spin_lock(&qinfo_list_lock); for (i = 0; i < NR_DQHASH; i++) { list_for_each_entry_safe(oqi, n, &qinfo_hash[i], oqi_hash) { remove_qinfo_hash(oqi); free_qinfo(oqi); } } spin_unlock(&qinfo_list_lock); rc = cfs_mem_cache_destroy(qinfo_cachep); LASSERTF(rc == 0, "couldn't destory qinfo_cachep slab\n"); qinfo_cachep = NULL; RETURN(0);}#ifdef __KERNEL__quota_interface_t mds_quota_interface = { .quota_init = mds_quota_init, .quota_exit = mds_quota_exit, .quota_setup = mds_quota_setup, .quota_cleanup = mds_quota_cleanup, .quota_check = target_quota_check, .quota_ctl = mds_quota_ctl, .quota_fs_cleanup =mds_quota_fs_cleanup, .quota_recovery = mds_quota_recovery, .quota_adjust = mds_quota_adjust, .quota_chkquota = mds_quota_check, .quota_acquire = mds_quota_acquire, .quota_pending_commit = mds_quota_pending_commit,};quota_interface_t filter_quota_interface = { .quota_setup = filter_quota_setup, .quota_cleanup = filter_quota_cleanup, .quota_check = target_quota_check, .quota_ctl = filter_quota_ctl, .quota_setinfo = filter_quota_setinfo, .quota_clearinfo = filter_quota_clearinfo, .quota_enforce = filter_quota_enforce, .quota_getflag = filter_quota_getflag, .quota_acquire = filter_quota_acquire, .quota_adjust = filter_quota_adjust, .quota_chkquota = filter_quota_check, .quota_adjust_qunit = filter_quota_adjust_qunit, .quota_pending_commit = filter_quota_pending_commit,};#endif /* __KERNEL__ */quota_interface_t mdc_quota_interface = { .quota_ctl = client_quota_ctl, .quota_check = client_quota_check, .quota_poll_check = client_quota_poll_check,};quota_interface_t osc_quota_interface = { .quota_ctl = client_quota_ctl, .quota_check = client_quota_check, .quota_poll_check = client_quota_poll_check, .quota_init = osc_quota_init, .quota_exit = osc_quota_exit, .quota_chkdq = osc_quota_chkdq, .quota_setdq = osc_quota_setdq, .quota_cleanup = osc_quota_cleanup, .quota_adjust_qunit = client_quota_adjust_qunit,};quota_interface_t lov_quota_interface = { .quota_check = lov_quota_check, .quota_ctl = lov_quota_ctl, .quota_adjust_qunit = lov_quota_adjust_qunit,};#ifdef __KERNEL__static int __init init_lustre_quota(void){ int rc = qunit_cache_init(); if (rc) return rc; PORTAL_SYMBOL_REGISTER(filter_quota_interface); PORTAL_SYMBOL_REGISTER(mds_quota_interface); PORTAL_SYMBOL_REGISTER(mdc_quota_interface); PORTAL_SYMBOL_REGISTER(osc_quota_interface); PORTAL_SYMBOL_REGISTER(lov_quota_interface); return 0;}static void /*__exit*/ exit_lustre_quota(void){ PORTAL_SYMBOL_UNREGISTER(filter_quota_interface); PORTAL_SYMBOL_UNREGISTER(mds_quota_interface); PORTAL_SYMBOL_UNREGISTER(mdc_quota_interface); PORTAL_SYMBOL_UNREGISTER(osc_quota_interface); PORTAL_SYMBOL_UNREGISTER(lov_quota_interface); qunit_cache_cleanup();}MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");MODULE_DESCRIPTION("Lustre Quota");MODULE_LICENSE("GPL");cfs_module(lquota, "1.0.0", init_lustre_quota, exit_lustre_quota);EXPORT_SYMBOL(mds_quota_interface);EXPORT_SYMBOL(filter_quota_interface);EXPORT_SYMBOL(mdc_quota_interface);EXPORT_SYMBOL(osc_quota_interface);EXPORT_SYMBOL(lov_quota_interface);#endif /* __KERNEL */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?