- rc = qctxt_adjust_qunit(obd, qctxt, uid, gid, isblk, 1, oti);
- RETURN(rc);
-}
-
-#endif /* HAVE_QUOTA_SUPPORT */
-#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;
- ENTRY;
-
- 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;
- }
- }
-