aboutsummaryrefslogtreecommitdiffstats
path: root/fs/quota
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-09-16 04:11:45 -0400
committerEric W. Biederman <ebiederm@xmission.com>2012-09-18 04:01:38 -0400
commite8a3e4719b7ec19288c56f22623f537cb78885c1 (patch)
treeee5ae227f2aa9db13358e66511f5b42d0ed783cb /fs/quota
parentf76d207a66c3a53defea67e7d36c3eb1b7d6d61d (diff)
userns: Implement struct kqid
Add the data type struct kqid which holds the kernel internal form of the owning identifier of a quota. struct kqid is a replacement for the implicit union of uid, gid and project id stored in an unsigned int and the quota type field that is was used in the quota data structures. Making the data type explicit allows the kuid_t and kgid_t type safety to propogate more thoroughly through the code, revealing more places where uid/gid conversions need be made. Along with the data type struct kqid comes the helper functions qid_eq, qid_lt, from_kqid, from_kqid_munged, qid_valid, make_kqid, make_kqid_invalid, make_kqid_uid, make_kqid_gid. Cc: Jan Kara <jack@suse.cz> Cc: Dave Chinner <david@fromorbit.com> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'fs/quota')
-rw-r--r--fs/quota/Makefile2
-rw-r--r--fs/quota/kqid.c132
2 files changed, 133 insertions, 1 deletions
diff --git a/fs/quota/Makefile b/fs/quota/Makefile
index 5f9e9e276af0..c66c37cdaa39 100644
--- a/fs/quota/Makefile
+++ b/fs/quota/Makefile
@@ -2,6 +2,6 @@ obj-$(CONFIG_QUOTA) += dquot.o
2obj-$(CONFIG_QFMT_V1) += quota_v1.o 2obj-$(CONFIG_QFMT_V1) += quota_v1.o
3obj-$(CONFIG_QFMT_V2) += quota_v2.o 3obj-$(CONFIG_QFMT_V2) += quota_v2.o
4obj-$(CONFIG_QUOTA_TREE) += quota_tree.o 4obj-$(CONFIG_QUOTA_TREE) += quota_tree.o
5obj-$(CONFIG_QUOTACTL) += quota.o 5obj-$(CONFIG_QUOTACTL) += quota.o kqid.o
6obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o 6obj-$(CONFIG_QUOTACTL_COMPAT) += compat.o
7obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o 7obj-$(CONFIG_QUOTA_NETLINK_INTERFACE) += netlink.o
diff --git a/fs/quota/kqid.c b/fs/quota/kqid.c
new file mode 100644
index 000000000000..2f97b0e2c501
--- /dev/null
+++ b/fs/quota/kqid.c
@@ -0,0 +1,132 @@
1#include <linux/fs.h>
2#include <linux/quota.h>
3#include <linux/export.h>
4
5/**
6 * qid_eq - Test to see if to kquid values are the same
7 * @left: A qid value
8 * @right: Another quid value
9 *
10 * Return true if the two qid values are equal and false otherwise.
11 */
12bool qid_eq(struct kqid left, struct kqid right)
13{
14 if (left.type != right.type)
15 return false;
16 switch(left.type) {
17 case USRQUOTA:
18 return uid_eq(left.uid, right.uid);
19 case GRPQUOTA:
20 return gid_eq(left.gid, right.gid);
21 case PRJQUOTA:
22 return projid_eq(left.projid, right.projid);
23 default:
24 BUG();
25 }
26}
27EXPORT_SYMBOL(qid_eq);
28
29/**
30 * qid_lt - Test to see if one qid value is less than another
31 * @left: The possibly lesser qid value
32 * @right: The possibly greater qid value
33 *
34 * Return true if left is less than right and false otherwise.
35 */
36bool qid_lt(struct kqid left, struct kqid right)
37{
38 if (left.type < right.type)
39 return true;
40 if (left.type > right.type)
41 return false;
42 switch (left.type) {
43 case USRQUOTA:
44 return uid_lt(left.uid, right.uid);
45 case GRPQUOTA:
46 return gid_lt(left.gid, right.gid);
47 case PRJQUOTA:
48 return projid_lt(left.projid, right.projid);
49 default:
50 BUG();
51 }
52}
53EXPORT_SYMBOL(qid_lt);
54
55/**
56 * from_kqid - Create a qid from a kqid user-namespace pair.
57 * @targ: The user namespace we want a qid in.
58 * @kuid: The kernel internal quota identifier to start with.
59 *
60 * Map @kqid into the user-namespace specified by @targ and
61 * return the resulting qid.
62 *
63 * There is always a mapping into the initial user_namespace.
64 *
65 * If @kqid has no mapping in @targ (qid_t)-1 is returned.
66 */
67qid_t from_kqid(struct user_namespace *targ, struct kqid kqid)
68{
69 switch (kqid.type) {
70 case USRQUOTA:
71 return from_kuid(targ, kqid.uid);
72 case GRPQUOTA:
73 return from_kgid(targ, kqid.gid);
74 case PRJQUOTA:
75 return from_kprojid(targ, kqid.projid);
76 default:
77 BUG();
78 }
79}
80EXPORT_SYMBOL(from_kqid);
81
82/**
83 * from_kqid_munged - Create a qid from a kqid user-namespace pair.
84 * @targ: The user namespace we want a qid in.
85 * @kqid: The kernel internal quota identifier to start with.
86 *
87 * Map @kqid into the user-namespace specified by @targ and
88 * return the resulting qid.
89 *
90 * There is always a mapping into the initial user_namespace.
91 *
92 * Unlike from_kqid from_kqid_munged never fails and always
93 * returns a valid projid. This makes from_kqid_munged
94 * appropriate for use in places where failing to provide
95 * a qid_t is not a good option.
96 *
97 * If @kqid has no mapping in @targ the kqid.type specific
98 * overflow identifier is returned.
99 */
100qid_t from_kqid_munged(struct user_namespace *targ, struct kqid kqid)
101{
102 switch (kqid.type) {
103 case USRQUOTA:
104 return from_kuid_munged(targ, kqid.uid);
105 case GRPQUOTA:
106 return from_kgid_munged(targ, kqid.gid);
107 case PRJQUOTA:
108 return from_kprojid_munged(targ, kqid.projid);
109 default:
110 BUG();
111 }
112}
113EXPORT_SYMBOL(from_kqid_munged);
114
115/**
116 * qid_valid - Report if a valid value is stored in a kqid.
117 * @qid: The kernel internal quota identifier to test.
118 */
119bool qid_valid(struct kqid qid)
120{
121 switch (qid.type) {
122 case USRQUOTA:
123 return uid_valid(qid.uid);
124 case GRPQUOTA:
125 return gid_valid(qid.gid);
126 case PRJQUOTA:
127 return projid_valid(qid.projid);
128 default:
129 BUG();
130 }
131}
132EXPORT_SYMBOL(qid_valid);