Patchwork [04/12] container quota: introduce container disk quota data header file.

login
register
mail settings
Submitter jeff.liu
Date May 30, 2012, 2:58 p.m.
Message ID <1338389946-13711-5-git-send-email-jeff.liu@oracle.com>
Download mbox | patch
Permalink /patch/161994/
State Not Applicable
Headers show

Comments

jeff.liu - May 30, 2012, 2:58 p.m.
Header file for container disk quota.

Signed-off-by: Jie Liu <jeff.liu@oracle.com>
---
 fs/ns_quota.h |   84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 84 insertions(+), 0 deletions(-)
 create mode 100644 fs/ns_quota.h
Glauber Costa - May 31, 2012, 9:10 a.m.
> +
> +/* Operations for quota control */
> +struct ns_quotactl_ops {
> +	int (*quota_on)(struct mnt_namespace *, int);
> +	int (*quota_off)(struct mnt_namespace *, int);
> +	int (*get_info)(struct mnt_namespace *, int, struct if_dqinfo *);
> +	int (*set_info)(struct mnt_namespace *, int, struct if_dqinfo *);
> +	int (*get_dqblk)(struct mnt_namespace *, int, qid_t,
> +			 struct fs_disk_quota *);
> +	int (*set_dqblk)(struct mnt_namespace *, int, qid_t,
> +			 struct fs_disk_quota *);
> +};
> +

That is quite bad. Just have the same signature. Which namespace you 
belong to can *always* be derived from the calling process, you should 
never need to specify that in any interface. It is of course fine to do 
that in functions internal to the kernel, but not this.

You should rethink the whole ns_quota thing. Some of it I believe will 
have to stay, I doubt we'll be able to be completely transparent. But 
the core of your changes have to be making sure a hierarchical walk over 
the valid quotas work well, finding out what are those valid quotas, etc.

The interface should be kept as unchanged as possible, and this can be 
achieved by things like automatic discover of the current namespace, and 
pre-operational container setup for the relevant files.

--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
jeff.liu - May 31, 2012, 12:53 p.m.
On 05/31/2012 05:10 PM, Glauber Costa wrote:

>> +
>> +/* Operations for quota control */
>> +struct ns_quotactl_ops {
>> +    int (*quota_on)(struct mnt_namespace *, int);
>> +    int (*quota_off)(struct mnt_namespace *, int);
>> +    int (*get_info)(struct mnt_namespace *, int, struct if_dqinfo *);
>> +    int (*set_info)(struct mnt_namespace *, int, struct if_dqinfo *);
>> +    int (*get_dqblk)(struct mnt_namespace *, int, qid_t,
>> +             struct fs_disk_quota *);
>> +    int (*set_dqblk)(struct mnt_namespace *, int, qid_t,
>> +             struct fs_disk_quota *);
>> +};
>> +
> 
> That is quite bad. Just have the same signature. Which namespace you
> belong to can *always* be derived from the calling process, you should
> never need to specify that in any interface. It is of course fine to do
> that in functions internal to the kernel, but not this.

Exactly, "struct mnt_namespace" should not be presented at any quota
operation interface, retrieve it through current->nsproxy->mnt_ns should
be fine.

> You should rethink the whole ns_quota thing. Some of it I believe will
> have to stay, I doubt we'll be able to be completely transparent. But
> the core of your changes have to be making sure a hierarchical walk over
> the valid quotas work well, finding out what are those valid quotas, etc.

> The interface should be kept as unchanged as possible, and this can be
> achieved by things like automatic discover of the current namespace, and
> pre-operational container setup for the relevant files.

Thanks for teaching me that,  let me try to refactor ns_quota to make
the change as little as possible.

-Jeff

> 
> -- 
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/fs/ns_quota.h b/fs/ns_quota.h
new file mode 100644
index 0000000..cf90fff
--- /dev/null
+++ b/fs/ns_quota.h
@@ -0,0 +1,84 @@ 
+#ifndef _LINUX_NS_QUOTA_
+#define _LINUX_NS_QUOTA_
+
+#include <linux/types.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/rwsem.h>
+#include <linux/spinlock.h>
+#include <linux/atomic.h>
+#include <linux/quota.h>
+#include <linux/user_namespace.h>
+
+#define NS_MAX_IQ_TIME	604800		/* (7*24*60*60) 1 week */
+#define NS_MAX_DQ_TIME	604800		/* (7*24*60*60) 1 week */
+
+/*
+ * Below most stuff were copied from kernel/user.c, using them
+ * to calculate and define quota hash table and hash routine.
+ */
+#define NS_DQHASH_BITS	(CONFIG_BASE_SMALL ? 3 : 7)
+#define NS_DQHASH_SZ	(1 << NS_DQHASH_BITS)
+
+struct ns_mem_dqinfo {
+	unsigned long dqi_flags;
+	unsigned int dqi_bgrace;
+	unsigned int dqi_igrace;
+	qsize_t dqi_maxblimit;
+	qsize_t dqi_maxilimit;
+};
+
+/* Mount namespace disk quota definitation */
+struct ns_quota_info {
+	/* Flags for disk quotas on this mount namespace */
+	unsigned int dq_flags;
+	/* Serialize mount namespace quotaon & quotaoff */
+	struct mutex dqonoff_mutex;
+	/* Serialize user/group quota list operations */
+	spinlock_t dq_list_lock;
+	/* Serialize quota value incr/decr operations */
+	spinlock_t dq_data_lock;
+	struct kmem_cache *dquot_cachep;
+	/* Hash list of all user disk quotas */
+	struct hlist_head u_dquots[NS_DQHASH_SZ];
+	/* Hash list of all group disk quotas */
+	struct hlist_head g_dquots[NS_DQHASH_SZ];
+	/* Information for each quota type */
+	struct ns_mem_dqinfo dqinfo[MAXQUOTAS];
+};
+
+/* Mount namespace disk quota object */
+struct ns_dquot {
+	struct hlist_node dq_hash_node;	/* Hash list in memory */
+	struct mnt_namespace *dq_ns;	/* Mount namespace this applies to */
+	unsigned int dq_id;		/* ID this applies to (uid, gid) */
+	unsigned long dq_flags;		/* See DQ_* */
+	short dq_type;			/* Type of quota */
+	struct mem_dqblk dq_dqb;	/* Diskquota usage */
+};
+
+/* Operations for quota object allocation/destroy */
+struct ns_dquot_ops {
+	/* Allocate memory for new dqout object */
+	struct ns_dquot *(*alloc_dquot)(struct mnt_namespace *);
+	/* Free memory for dquot */
+	void (*destroy_dquot)(struct ns_dquot *);
+};
+
+/* Operations for quota control */
+struct ns_quotactl_ops {
+	int (*quota_on)(struct mnt_namespace *, int);
+	int (*quota_off)(struct mnt_namespace *, int);
+	int (*get_info)(struct mnt_namespace *, int, struct if_dqinfo *);
+	int (*set_info)(struct mnt_namespace *, int, struct if_dqinfo *);
+	int (*get_dqblk)(struct mnt_namespace *, int, qid_t,
+			 struct fs_disk_quota *);
+	int (*set_dqblk)(struct mnt_namespace *, int, qid_t,
+			 struct fs_disk_quota *);
+};
+
+int ns_dqinfo_init(struct mnt_namespace *ns);
+void ns_dqinfo_destroy(struct mnt_namespace *ns);
+extern unsigned int ns_dquot_getfmt(struct mnt_namespace *ns, int type);
+
+#endif /* _LINUX_NS_QUOTA_ */