/*
* Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
* Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
*
* This copyrighted material is made available to anyone wishing to use,
* modify, copy, or redistribute it subject to the terms and conditions
* of the GNU General Public License version 2.
*/
/*
* Quota change tags are associated with each transaction that allocates or
* deallocates space. Those changes are accumulated locally to each node (in a
* per-node file) and then are periodically synced to the quota file. This
* avoids the bottleneck of constantly touching the quota file, but introduces
* fuzziness in the current usage value of IDs that are being used on different
* nodes in the cluster simultaneously. So, it is possible for a user on
* multiple nodes to overrun their quota, but that overrun is controlable.
* Since quota tags are part of transactions, there is no need to a quota check
* program to be run on node crashes or anything like that.
*
* There are couple of knobs that let the administrator manage the quota
* fuzziness. "quota_quantum" sets the maximum time a quota change can be
* sitting on one node before being synced to the quota file. (The default is
* 60 seconds.) Another knob, "quota_scale" controls how quickly the frequency
* of quota file syncs increases as the user moves closer to their limit. The
* more frequent the syncs, the more accurate the quota enforcement, but that
* means that there is more contention between the nodes for the quota file.
* The default value is one. This sets the maximum theoretical quota overrun
* (with infinite node with infinite bandwidth) to twice the user's limit. (In
* practice, the maximum overrun you see should be much less.) A "quota_scale"
* number greater than one makes quota syncs more frequent and reduces the
* maximum overrun. Numbers less than one (but greater than zero) make quota
* syncs less frequent.
*
* GFS quotas also use per-ID Lock Value Blocks (LVBs) to cache the contents of
* the quota file, so it is not being constantly read.
*/
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/completion.h>
#include <linux/buffer_head.h>
#include <linux/sort.h>
#include <linux/fs.h>
#include <linux/bio.h>
#include <linux/gfs2_ondisk.h>
#include <linux/kthread.h>
#include <linux/freezer.h>
#include "gfs2.h"
#include "incore.h"
#include "bmap.h"
#include "glock.h"
#include "glops.h"
#include "log.h"
#include "meta_io.h"
#include "quota.h"
#include "rgrp.h"
#include "super.h"
#include "trans.h"
#include "inode.h"
#include "ops_address.h"
#include "util.h"
#define QUOTA_USER 1
#define QUOTA_GROUP 0
struct gfs2_quota_host {
u64 qu_limit;
u64 qu_warn;
s64 qu_value;
u32 qu_ll_next;
};
struct gfs2_quota_change_host {
u64 qc_change;
u32 qc_flags; /* GFS2_QCF_... */
u32 qc_id;
};
static LIST_HEAD(qd_lru_list);
static atomic_t qd_lru_count = ATOMIC_INIT(0);
static DEFINE_SPINLOCK(qd_lru_lock);
int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask)
{
struct gfs2_quota_data *qd;
struct gfs2_sbd *sdp;
if (nr == 0)
goto out;
if (!(gfp_mask & __GFP