Skip to content

Commit 4c376dc

Browse files
committed
userns: Convert struct dquot dq_id to be a struct kqid
Change struct dquot dq_id to a struct kqid and remove the now unecessary dq_type. Make minimal changes to dquot, quota_tree, quota_v1, quota_v2, ext3, ext4, and ocfs2 to deal with the change in quota structures and signatures. The ocfs2 changes are larger than most because of the extensive tracing throughout the ocfs2 quota code that prints out dq_id. quota_tree.c:get_index is modified to take a struct kqid instead of a qid_t because all of it's callers pass in dquot->dq_id and it allows me to introduce only a single conversion. The rest of the changes are either just replacing dq_type with dq_id.type, adding conversions to deal with the change in type and occassionally adding qid_eq to allow quota id comparisons in a user namespace safe way. Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Jan Kara <jack@suse.cz> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Andreas Dilger <adilger.kernel@dilger.ca> Cc: Theodore Tso <tytso@mit.edu> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent aca645a commit 4c376dc

9 files changed

Lines changed: 102 additions & 82 deletions

File tree

‎fs/ext3/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2814,7 +2814,7 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
28142814

28152815
static inline struct inode *dquot_to_inode(struct dquot *dquot)
28162816
{
2817-
return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
2817+
return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type];
28182818
}
28192819

28202820
static int ext3_write_dquot(struct dquot *dquot)

‎fs/ext4/super.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4796,7 +4796,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
47964796

47974797
static inline struct inode *dquot_to_inode(struct dquot *dquot)
47984798
{
4799-
return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
4799+
return sb_dqopt(dquot->dq_sb)->files[dquot->dq_id.type];
48004800
}
48014801

48024802
static int ext4_write_dquot(struct dquot *dquot)

‎fs/ocfs2/quota_global.c‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void ocfs2_global_mem2diskdqb(void *dp, struct dquot *dquot)
9595
struct ocfs2_global_disk_dqblk *d = dp;
9696
struct mem_dqblk *m = &dquot->dq_dqb;
9797

98-
d->dqb_id = cpu_to_le32(dquot->dq_id);
98+
d->dqb_id = cpu_to_le32(from_kqid(&init_user_ns, dquot->dq_id));
9999
d->dqb_use_count = cpu_to_le32(OCFS2_DQUOT(dquot)->dq_use_count);
100100
d->dqb_ihardlimit = cpu_to_le64(m->dqb_ihardlimit);
101101
d->dqb_isoftlimit = cpu_to_le64(m->dqb_isoftlimit);
@@ -112,11 +112,14 @@ static int ocfs2_global_is_id(void *dp, struct dquot *dquot)
112112
{
113113
struct ocfs2_global_disk_dqblk *d = dp;
114114
struct ocfs2_mem_dqinfo *oinfo =
115-
sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv;
115+
sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
116116

117117
if (qtree_entry_unused(&oinfo->dqi_gi, dp))
118118
return 0;
119-
return le32_to_cpu(d->dqb_id) == dquot->dq_id;
119+
120+
return qid_eq(make_kqid(&init_user_ns, dquot->dq_id.type,
121+
le32_to_cpu(d->dqb_id)),
122+
dquot->dq_id);
120123
}
121124

122125
struct qtree_fmt_operations ocfs2_global_ops = {
@@ -475,7 +478,7 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing)
475478
{
476479
int err, err2;
477480
struct super_block *sb = dquot->dq_sb;
478-
int type = dquot->dq_type;
481+
int type = dquot->dq_id.type;
479482
struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv;
480483
struct ocfs2_global_disk_dqblk dqblk;
481484
s64 spacechange, inodechange;
@@ -504,7 +507,8 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing)
504507
olditime = dquot->dq_dqb.dqb_itime;
505508
oldbtime = dquot->dq_dqb.dqb_btime;
506509
ocfs2_global_disk2memdqb(dquot, &dqblk);
507-
trace_ocfs2_sync_dquot(dquot->dq_id, dquot->dq_dqb.dqb_curspace,
510+
trace_ocfs2_sync_dquot(from_kqid(&init_user_ns, dquot->dq_id),
511+
dquot->dq_dqb.dqb_curspace,
508512
(long long)spacechange,
509513
dquot->dq_dqb.dqb_curinodes,
510514
(long long)inodechange);
@@ -555,8 +559,8 @@ int __ocfs2_sync_dquot(struct dquot *dquot, int freeing)
555559
err = ocfs2_qinfo_lock(info, freeing);
556560
if (err < 0) {
557561
mlog(ML_ERROR, "Failed to lock quota info, losing quota write"
558-
" (type=%d, id=%u)\n", dquot->dq_type,
559-
(unsigned)dquot->dq_id);
562+
" (type=%d, id=%u)\n", dquot->dq_id.type,
563+
(unsigned)from_kqid(&init_user_ns, dquot->dq_id));
560564
goto out;
561565
}
562566
if (freeing)
@@ -591,9 +595,10 @@ static int ocfs2_sync_dquot_helper(struct dquot *dquot, unsigned long type)
591595
struct ocfs2_super *osb = OCFS2_SB(sb);
592596
int status = 0;
593597

594-
trace_ocfs2_sync_dquot_helper(dquot->dq_id, dquot->dq_type,
598+
trace_ocfs2_sync_dquot_helper(from_kqid(&init_user_ns, dquot->dq_id),
599+
dquot->dq_id.type,
595600
type, sb->s_id);
596-
if (type != dquot->dq_type)
601+
if (type != dquot->dq_id.type)
597602
goto out;
598603
status = ocfs2_lock_global_qf(oinfo, 1);
599604
if (status < 0)
@@ -643,7 +648,8 @@ static int ocfs2_write_dquot(struct dquot *dquot)
643648
struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb);
644649
int status = 0;
645650

646-
trace_ocfs2_write_dquot(dquot->dq_id, dquot->dq_type);
651+
trace_ocfs2_write_dquot(from_kqid(&init_user_ns, dquot->dq_id),
652+
dquot->dq_id.type);
647653

648654
handle = ocfs2_start_trans(osb, OCFS2_QWRITE_CREDITS);
649655
if (IS_ERR(handle)) {
@@ -677,11 +683,12 @@ static int ocfs2_release_dquot(struct dquot *dquot)
677683
{
678684
handle_t *handle;
679685
struct ocfs2_mem_dqinfo *oinfo =
680-
sb_dqinfo(dquot->dq_sb, dquot->dq_type)->dqi_priv;
686+
sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv;
681687
struct ocfs2_super *osb = OCFS2_SB(dquot->dq_sb);
682688
int status = 0;
683689

684-
trace_ocfs2_release_dquot(dquot->dq_id, dquot->dq_type);
690+
trace_ocfs2_release_dquot(from_kqid(&init_user_ns, dquot->dq_id),
691+
dquot->dq_id.type);
685692

686693
mutex_lock(&dquot->dq_lock);
687694
/* Check whether we are not racing with some other dqget() */
@@ -691,7 +698,7 @@ static int ocfs2_release_dquot(struct dquot *dquot)
691698
if (status < 0)
692699
goto out;
693700
handle = ocfs2_start_trans(osb,
694-
ocfs2_calc_qdel_credits(dquot->dq_sb, dquot->dq_type));
701+
ocfs2_calc_qdel_credits(dquot->dq_sb, dquot->dq_id.type));
695702
if (IS_ERR(handle)) {
696703
status = PTR_ERR(handle);
697704
mlog_errno(status);
@@ -733,13 +740,14 @@ static int ocfs2_acquire_dquot(struct dquot *dquot)
733740
int ex = 0;
734741
struct super_block *sb = dquot->dq_sb;
735742
struct ocfs2_super *osb = OCFS2_SB(sb);
736-
int type = dquot->dq_type;
743+
int type = dquot->dq_id.type;
737744
struct ocfs2_mem_dqinfo *info = sb_dqinfo(sb, type)->dqi_priv;
738745
struct inode *gqinode = info->dqi_gqinode;
739746
int need_alloc = ocfs2_global_qinit_alloc(sb, type);
740747
handle_t *handle;
741748

742-
trace_ocfs2_acquire_dquot(dquot->dq_id, type);
749+
trace_ocfs2_acquire_dquot(from_kqid(&init_user_ns, dquot->dq_id),
750+
type);
743751
mutex_lock(&dquot->dq_lock);
744752
/*
745753
* We need an exclusive lock, because we're going to update use count
@@ -821,12 +829,13 @@ static int ocfs2_mark_dquot_dirty(struct dquot *dquot)
821829
int sync = 0;
822830
int status;
823831
struct super_block *sb = dquot->dq_sb;
824-
int type = dquot->dq_type;
832+
int type = dquot->dq_id.type;
825833
struct ocfs2_mem_dqinfo *oinfo = sb_dqinfo(sb, type)->dqi_priv;
826834
handle_t *handle;
827835
struct ocfs2_super *osb = OCFS2_SB(sb);
828836

829-
trace_ocfs2_mark_dquot_dirty(dquot->dq_id, type);
837+
trace_ocfs2_mark_dquot_dirty(from_kqid(&init_user_ns, dquot->dq_id),
838+
type);
830839

831840
/* In case user set some limits, sync dquot immediately to global
832841
* quota file so that information propagates quicker */

‎fs/ocfs2/quota_local.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,8 @@ static void olq_set_dquot(struct buffer_head *bh, void *private)
883883
dqblk = (struct ocfs2_local_disk_dqblk *)(bh->b_data
884884
+ ol_dqblk_block_offset(sb, od->dq_local_off));
885885

886-
dqblk->dqb_id = cpu_to_le64(od->dq_dquot.dq_id);
886+
dqblk->dqb_id = cpu_to_le64(from_kqid(&init_user_ns,
887+
od->dq_dquot.dq_id));
887888
spin_lock(&dq_data_lock);
888889
dqblk->dqb_spacemod = cpu_to_le64(od->dq_dquot.dq_dqb.dqb_curspace -
889890
od->dq_origspace);
@@ -893,7 +894,7 @@ static void olq_set_dquot(struct buffer_head *bh, void *private)
893894
trace_olq_set_dquot(
894895
(unsigned long long)le64_to_cpu(dqblk->dqb_spacemod),
895896
(unsigned long long)le64_to_cpu(dqblk->dqb_inodemod),
896-
od->dq_dquot.dq_id);
897+
from_kqid(&init_user_ns, od->dq_dquot.dq_id));
897898
}
898899

899900
/* Write dquot to local quota file */
@@ -902,7 +903,7 @@ int ocfs2_local_write_dquot(struct dquot *dquot)
902903
struct super_block *sb = dquot->dq_sb;
903904
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
904905
struct buffer_head *bh;
905-
struct inode *lqinode = sb_dqopt(sb)->files[dquot->dq_type];
906+
struct inode *lqinode = sb_dqopt(sb)->files[dquot->dq_id.type];
906907
int status;
907908

908909
status = ocfs2_read_quota_phys_block(lqinode, od->dq_local_phys_blk,
@@ -1223,7 +1224,7 @@ static void olq_alloc_dquot(struct buffer_head *bh, void *private)
12231224
int ocfs2_create_local_dquot(struct dquot *dquot)
12241225
{
12251226
struct super_block *sb = dquot->dq_sb;
1226-
int type = dquot->dq_type;
1227+
int type = dquot->dq_id.type;
12271228
struct inode *lqinode = sb_dqopt(sb)->files[type];
12281229
struct ocfs2_quota_chunk *chunk;
12291230
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
@@ -1277,7 +1278,7 @@ int ocfs2_create_local_dquot(struct dquot *dquot)
12771278
int ocfs2_local_release_dquot(handle_t *handle, struct dquot *dquot)
12781279
{
12791280
int status;
1280-
int type = dquot->dq_type;
1281+
int type = dquot->dq_id.type;
12811282
struct ocfs2_dquot *od = OCFS2_DQUOT(dquot);
12821283
struct super_block *sb = dquot->dq_sb;
12831284
struct ocfs2_local_disk_chunk *dchunk;

0 commit comments

Comments
 (0)