aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2014-10-09 10:03:13 -0400
committerJan Kara <jack@suse.cz>2015-01-28 03:01:40 -0500
commit14bf61ffe6ac54afcd1e888a4407fe16054483db (patch)
treeb5af94fc8771e82735064a82a7df4ec4de66744e
parentb07ef35244424cbeda9844198607c7077099c82c (diff)
quota: Switch ->get_dqblk() and ->set_dqblk() to use bytes as space units
Currently ->get_dqblk() and ->set_dqblk() use struct fs_disk_quota which tracks space limits and usage in 512-byte blocks. However VFS quotas track usage in bytes (as some filesystems require that) and we need to somehow pass this information. Upto now it wasn't a problem because we didn't do any unit conversion (thus VFS quota routines happily stuck number of bytes into d_bcount field of struct fd_disk_quota). Only if you tried to use Q_XGETQUOTA or Q_XSETQLIM for VFS quotas (or Q_GETQUOTA / Q_SETQUOTA for XFS quotas), you got bogus results. Hardly anyone tried this but reportedly some Samba users hit the problem in practice. So when we want interfaces compatible we need to fix this. We bite the bullet and define another quota structure used for passing information from/to ->get_dqblk()/->set_dqblk. It's somewhat sad we have to have more conversion routines in fs/quota/quota.c and another copying of quota structure slows down getting of quota information by about 2% but it seems cleaner than overloading e.g. units of d_bcount to bytes. CC: stable@vger.kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r--fs/gfs2/quota.c49
-rw-r--r--fs/quota/dquot.c83
-rw-r--r--fs/quota/quota.c162
-rw-r--r--fs/xfs/xfs_qm.h4
-rw-r--r--fs/xfs/xfs_qm_syscalls.c156
-rw-r--r--fs/xfs/xfs_quotaops.c8
-rw-r--r--include/linux/quota.h47
-rw-r--r--include/linux/quotaops.h4
8 files changed, 318 insertions, 195 deletions
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index c8b148bbdc8b..3e193cb36996 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -667,7 +667,7 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
667 667
668static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc, 668static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
669 s64 change, struct gfs2_quota_data *qd, 669 s64 change, struct gfs2_quota_data *qd,
670 struct fs_disk_quota *fdq) 670 struct qc_dqblk *fdq)
671{ 671{
672 struct inode *inode = &ip->i_inode; 672 struct inode *inode = &ip->i_inode;
673 struct gfs2_sbd *sdp = GFS2_SB(inode); 673 struct gfs2_sbd *sdp = GFS2_SB(inode);
@@ -697,16 +697,16 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
697 be64_add_cpu(&q.qu_value, change); 697 be64_add_cpu(&q.qu_value, change);
698 qd->qd_qb.qb_value = q.qu_value; 698 qd->qd_qb.qb_value = q.qu_value;
699 if (fdq) { 699 if (fdq) {
700 if (fdq->d_fieldmask & FS_DQ_BSOFT) { 700 if (fdq->d_fieldmask & QC_SPC_SOFT) {
701 q.qu_warn = cpu_to_be64(fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift); 701 q.qu_warn = cpu_to_be64(fdq->d_spc_softlimit >> sdp->sd_sb.sb_bsize_shift);
702 qd->qd_qb.qb_warn = q.qu_warn; 702 qd->qd_qb.qb_warn = q.qu_warn;
703 } 703 }
704 if (fdq->d_fieldmask & FS_DQ_BHARD) { 704 if (fdq->d_fieldmask & QC_SPC_HARD) {
705 q.qu_limit = cpu_to_be64(fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift); 705 q.qu_limit = cpu_to_be64(fdq->d_spc_hardlimit >> sdp->sd_sb.sb_bsize_shift);
706 qd->qd_qb.qb_limit = q.qu_limit; 706 qd->qd_qb.qb_limit = q.qu_limit;
707 } 707 }
708 if (fdq->d_fieldmask & FS_DQ_BCOUNT) { 708 if (fdq->d_fieldmask & QC_SPACE) {
709 q.qu_value = cpu_to_be64(fdq->d_bcount >> sdp->sd_fsb2bb_shift); 709 q.qu_value = cpu_to_be64(fdq->d_space >> sdp->sd_sb.sb_bsize_shift);
710 qd->qd_qb.qb_value = q.qu_value; 710 qd->qd_qb.qb_value = q.qu_value;
711 } 711 }
712 } 712 }
@@ -1497,7 +1497,7 @@ static int gfs2_quota_get_xstate(struct super_block *sb,
1497} 1497}
1498 1498
1499static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid, 1499static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid,
1500 struct fs_disk_quota *fdq) 1500 struct qc_dqblk *fdq)
1501{ 1501{
1502 struct gfs2_sbd *sdp = sb->s_fs_info; 1502 struct gfs2_sbd *sdp = sb->s_fs_info;
1503 struct gfs2_quota_lvb *qlvb; 1503 struct gfs2_quota_lvb *qlvb;
@@ -1505,7 +1505,7 @@ static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid,
1505 struct gfs2_holder q_gh; 1505 struct gfs2_holder q_gh;
1506 int error; 1506 int error;
1507 1507
1508 memset(fdq, 0, sizeof(struct fs_disk_quota)); 1508 memset(fdq, 0, sizeof(*fdq));
1509 1509
1510 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF) 1510 if (sdp->sd_args.ar_quota == GFS2_QUOTA_OFF)
1511 return -ESRCH; /* Crazy XFS error code */ 1511 return -ESRCH; /* Crazy XFS error code */
@@ -1522,12 +1522,9 @@ static int gfs2_get_dqblk(struct super_block *sb, struct kqid qid,
1522 goto out; 1522 goto out;
1523 1523
1524 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr; 1524 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lksb.sb_lvbptr;
1525 fdq->d_version = FS_DQUOT_VERSION; 1525 fdq->d_spc_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_sb.sb_bsize_shift;
1526 fdq->d_flags = (qid.type == USRQUOTA) ? FS_USER_QUOTA : FS_GROUP_QUOTA; 1526 fdq->d_spc_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_sb.sb_bsize_shift;
1527 fdq->d_id = from_kqid_munged(current_user_ns(), qid); 1527 fdq->d_space = be64_to_cpu(qlvb->qb_value) << sdp->sd_sb.sb_bsize_shift;
1528 fdq->d_blk_hardlimit = be64_to_cpu(qlvb->qb_limit) << sdp->sd_fsb2bb_shift;
1529 fdq->d_blk_softlimit = be64_to_cpu(qlvb->qb_warn) << sdp->sd_fsb2bb_shift;
1530 fdq->d_bcount = be64_to_cpu(qlvb->qb_value) << sdp->sd_fsb2bb_shift;
1531 1528
1532 gfs2_glock_dq_uninit(&q_gh); 1529 gfs2_glock_dq_uninit(&q_gh);
1533out: 1530out:
@@ -1536,10 +1533,10 @@ out:
1536} 1533}
1537 1534
1538/* GFS2 only supports a subset of the XFS fields */ 1535/* GFS2 only supports a subset of the XFS fields */
1539#define GFS2_FIELDMASK (FS_DQ_BSOFT|FS_DQ_BHARD|FS_DQ_BCOUNT) 1536#define GFS2_FIELDMASK (QC_SPC_SOFT|QC_SPC_HARD|QC_SPACE)
1540 1537
1541static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid, 1538static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid,
1542 struct fs_disk_quota *fdq) 1539 struct qc_dqblk *fdq)
1543{ 1540{
1544 struct gfs2_sbd *sdp = sb->s_fs_info; 1541 struct gfs2_sbd *sdp = sb->s_fs_info;
1545 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode); 1542 struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
@@ -1583,17 +1580,17 @@ static int gfs2_set_dqblk(struct super_block *sb, struct kqid qid,
1583 goto out_i; 1580 goto out_i;
1584 1581
1585 /* If nothing has changed, this is a no-op */ 1582 /* If nothing has changed, this is a no-op */
1586 if ((fdq->d_fieldmask & FS_DQ_BSOFT) && 1583 if ((fdq->d_fieldmask & QC_SPC_SOFT) &&
1587 ((fdq->d_blk_softlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_warn))) 1584 ((fdq->d_spc_softlimit >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_warn)))
1588 fdq->d_fieldmask ^= FS_DQ_BSOFT; 1585 fdq->d_fieldmask ^= QC_SPC_SOFT;
1589 1586
1590 if ((fdq->d_fieldmask & FS_DQ_BHARD) && 1587 if ((fdq->d_fieldmask & QC_SPC_HARD) &&
1591 ((fdq->d_blk_hardlimit >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_limit))) 1588 ((fdq->d_spc_hardlimit >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_limit)))
1592 fdq->d_fieldmask ^= FS_DQ_BHARD; 1589 fdq->d_fieldmask ^= QC_SPC_HARD;
1593 1590
1594 if ((fdq->d_fieldmask & FS_DQ_BCOUNT) && 1591 if ((fdq->d_fieldmask & QC_SPACE) &&
1595 ((fdq->d_bcount >> sdp->sd_fsb2bb_shift) == be64_to_cpu(qd->qd_qb.qb_value))) 1592 ((fdq->d_space >> sdp->sd_sb.sb_bsize_shift) == be64_to_cpu(qd->qd_qb.qb_value)))
1596 fdq->d_fieldmask ^= FS_DQ_BCOUNT; 1593 fdq->d_fieldmask ^= QC_SPACE;
1597 1594
1598 if (fdq->d_fieldmask == 0) 1595 if (fdq->d_fieldmask == 0)
1599 goto out_i; 1596 goto out_i;
diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
index 8f0acef3d184..69df5b239844 100644
--- a/fs/quota/dquot.c
+++ b/fs/quota/dquot.c
@@ -2396,30 +2396,25 @@ static inline qsize_t stoqb(qsize_t space)
2396} 2396}
2397 2397
2398/* Generic routine for getting common part of quota structure */ 2398/* Generic routine for getting common part of quota structure */
2399static void do_get_dqblk(struct dquot *dquot, struct fs_disk_quota *di) 2399static void do_get_dqblk(struct dquot *dquot, struct qc_dqblk *di)
2400{ 2400{
2401 struct mem_dqblk *dm = &dquot->dq_dqb; 2401 struct mem_dqblk *dm = &dquot->dq_dqb;
2402 2402
2403 memset(di, 0, sizeof(*di)); 2403 memset(di, 0, sizeof(*di));
2404 di->d_version = FS_DQUOT_VERSION;
2405 di->d_flags = dquot->dq_id.type == USRQUOTA ?
2406 FS_USER_QUOTA : FS_GROUP_QUOTA;
2407 di->d_id = from_kqid_munged(current_user_ns(), dquot->dq_id);
2408
2409 spin_lock(&dq_data_lock); 2404 spin_lock(&dq_data_lock);
2410 di->d_blk_hardlimit = stoqb(dm->dqb_bhardlimit); 2405 di->d_spc_hardlimit = dm->dqb_bhardlimit;
2411 di->d_blk_softlimit = stoqb(dm->dqb_bsoftlimit); 2406 di->d_spc_softlimit = dm->dqb_bsoftlimit;
2412 di->d_ino_hardlimit = dm->dqb_ihardlimit; 2407 di->d_ino_hardlimit = dm->dqb_ihardlimit;
2413 di->d_ino_softlimit = dm->dqb_isoftlimit; 2408 di->d_ino_softlimit = dm->dqb_isoftlimit;
2414 di->d_bcount = dm->dqb_curspace + dm->dqb_rsvspace; 2409 di->d_space = dm->dqb_curspace + dm->dqb_rsvspace;
2415 di->d_icount = dm->dqb_curinodes; 2410 di->d_ino_count = dm->dqb_curinodes;
2416 di->d_btimer = dm->dqb_btime; 2411 di->d_spc_timer = dm->dqb_btime;
2417 di->d_itimer = dm->dqb_itime; 2412 di->d_ino_timer = dm->dqb_itime;
2418 spin_unlock(&dq_data_lock); 2413 spin_unlock(&dq_data_lock);
2419} 2414}
2420 2415
2421int dquot_get_dqblk(struct super_block *sb, struct kqid qid, 2416int dquot_get_dqblk(struct super_block *sb, struct kqid qid,
2422 struct fs_disk_quota *di) 2417 struct qc_dqblk *di)
2423{ 2418{
2424 struct dquot *dquot; 2419 struct dquot *dquot;
2425 2420
@@ -2433,70 +2428,70 @@ int dquot_get_dqblk(struct super_block *sb, struct kqid qid,
2433} 2428}
2434EXPORT_SYMBOL(dquot_get_dqblk); 2429EXPORT_SYMBOL(dquot_get_dqblk);
2435 2430
2436#define VFS_FS_DQ_MASK \ 2431#define VFS_QC_MASK \
2437 (FS_DQ_BCOUNT | FS_DQ_BSOFT | FS_DQ_BHARD | \ 2432 (QC_SPACE | QC_SPC_SOFT | QC_SPC_HARD | \
2438 FS_DQ_ICOUNT | FS_DQ_ISOFT | FS_DQ_IHARD | \ 2433 QC_INO_COUNT | QC_INO_SOFT | QC_INO_HARD | \
2439 FS_DQ_BTIMER | FS_DQ_ITIMER) 2434 QC_SPC_TIMER | QC_INO_TIMER)
2440 2435
2441/* Generic routine for setting common part of quota structure */ 2436/* Generic routine for setting common part of quota structure */
2442static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di) 2437static int do_set_dqblk(struct dquot *dquot, struct qc_dqblk *di)
2443{ 2438{
2444 struct mem_dqblk *dm = &dquot->dq_dqb; 2439 struct mem_dqblk *dm = &dquot->dq_dqb;
2445 int check_blim = 0, check_ilim = 0; 2440 int check_blim = 0, check_ilim = 0;
2446 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type]; 2441 struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_id.type];
2447 2442
2448 if (di->d_fieldmask & ~VFS_FS_DQ_MASK) 2443 if (di->d_fieldmask & ~VFS_QC_MASK)
2449 return -EINVAL; 2444 return -EINVAL;
2450 2445
2451 if (((di->d_fieldmask & FS_DQ_BSOFT) && 2446 if (((di->d_fieldmask & QC_SPC_SOFT) &&
2452 (di->d_blk_softlimit > dqi->dqi_maxblimit)) || 2447 stoqb(di->d_spc_softlimit) > dqi->dqi_maxblimit) ||
2453 ((di->d_fieldmask & FS_DQ_BHARD) && 2448 ((di->d_fieldmask & QC_SPC_HARD) &&
2454 (di->d_blk_hardlimit > dqi->dqi_maxblimit)) || 2449 stoqb(di->d_spc_hardlimit) > dqi->dqi_maxblimit) ||
2455 ((di->d_fieldmask & FS_DQ_ISOFT) && 2450 ((di->d_fieldmask & QC_INO_SOFT) &&
2456 (di->d_ino_softlimit > dqi->dqi_maxilimit)) || 2451 (di->d_ino_softlimit > dqi->dqi_maxilimit)) ||
2457 ((di->d_fieldmask & FS_DQ_IHARD) && 2452 ((di->d_fieldmask & QC_INO_HARD) &&
2458 (di->d_ino_hardlimit > dqi->dqi_maxilimit))) 2453 (di->d_ino_hardlimit > dqi->dqi_maxilimit)))
2459 return -ERANGE; 2454 return -ERANGE;
2460 2455
2461 spin_lock(&dq_data_lock); 2456 spin_lock(&dq_data_lock);
2462 if (di->d_fieldmask & FS_DQ_BCOUNT) { 2457 if (di->d_fieldmask & QC_SPACE) {
2463 dm->dqb_curspace = di->d_bcount - dm->dqb_rsvspace; 2458 dm->dqb_curspace = di->d_space - dm->dqb_rsvspace;
2464 check_blim = 1; 2459 check_blim = 1;
2465 set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags); 2460 set_bit(DQ_LASTSET_B + QIF_SPACE_B, &dquot->dq_flags);
2466 } 2461 }
2467 2462
2468 if (di->d_fieldmask & FS_DQ_BSOFT) 2463 if (di->d_fieldmask & QC_SPC_SOFT)
2469 dm->dqb_bsoftlimit = qbtos(di->d_blk_softlimit); 2464 dm->dqb_bsoftlimit = di->d_spc_softlimit;
2470 if (di->d_fieldmask & FS_DQ_BHARD) 2465 if (di->d_fieldmask & QC_SPC_HARD)
2471 dm->dqb_bhardlimit = qbtos(di->d_blk_hardlimit); 2466 dm->dqb_bhardlimit = di->d_spc_hardlimit;
2472 if (di->d_fieldmask & (FS_DQ_BSOFT | FS_DQ_BHARD)) { 2467 if (di->d_fieldmask & (QC_SPC_SOFT | QC_SPC_HARD)) {
2473 check_blim = 1; 2468 check_blim = 1;
2474 set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags); 2469 set_bit(DQ_LASTSET_B + QIF_BLIMITS_B, &dquot->dq_flags);
2475 } 2470 }
2476 2471
2477 if (di->d_fieldmask & FS_DQ_ICOUNT) { 2472 if (di->d_fieldmask & QC_INO_COUNT) {
2478 dm->dqb_curinodes = di->d_icount; 2473 dm->dqb_curinodes = di->d_ino_count;
2479 check_ilim = 1; 2474 check_ilim = 1;
2480 set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags); 2475 set_bit(DQ_LASTSET_B + QIF_INODES_B, &dquot->dq_flags);
2481 } 2476 }
2482 2477
2483 if (di->d_fieldmask & FS_DQ_ISOFT) 2478 if (di->d_fieldmask & QC_INO_SOFT)
2484 dm->dqb_isoftlimit = di->d_ino_softlimit; 2479 dm->dqb_isoftlimit = di->d_ino_softlimit;
2485 if (di->d_fieldmask & FS_DQ_IHARD) 2480 if (di->d_fieldmask & QC_INO_HARD)
2486 dm->dqb_ihardlimit = di->d_ino_hardlimit; 2481 dm->dqb_ihardlimit = di->d_ino_hardlimit;
2487 if (di->d_fieldmask & (FS_DQ_ISOFT | FS_DQ_IHARD)) { 2482 if (di->d_fieldmask & (QC_INO_SOFT | QC_INO_HARD)) {
2488 check_ilim = 1; 2483 check_ilim = 1;
2489 set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags); 2484 set_bit(DQ_LASTSET_B + QIF_ILIMITS_B, &dquot->dq_flags);
2490 } 2485 }
2491 2486
2492 if (di->d_fieldmask & FS_DQ_BTIMER) { 2487 if (di->d_fieldmask & QC_SPC_TIMER) {
2493 dm->dqb_btime = di->d_btimer; 2488 dm->dqb_btime = di->d_spc_timer;
2494 check_blim = 1; 2489 check_blim = 1;
2495 set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags); 2490 set_bit(DQ_LASTSET_B + QIF_BTIME_B, &dquot->dq_flags);
2496 } 2491 }
2497 2492
2498 if (di->d_fieldmask & FS_DQ_ITIMER) { 2493 if (di->d_fieldmask & QC_INO_TIMER) {
2499 dm->dqb_itime = di->d_itimer; 2494 dm->dqb_itime = di->d_ino_timer;
2500 check_ilim = 1; 2495 check_ilim = 1;
2501 set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags); 2496 set_bit(DQ_LASTSET_B + QIF_ITIME_B, &dquot->dq_flags);
2502 } 2497 }
@@ -2506,7 +2501,7 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2506 dm->dqb_curspace < dm->dqb_bsoftlimit) { 2501 dm->dqb_curspace < dm->dqb_bsoftlimit) {
2507 dm->dqb_btime = 0; 2502 dm->dqb_btime = 0;
2508 clear_bit(DQ_BLKS_B, &dquot->dq_flags); 2503 clear_bit(DQ_BLKS_B, &dquot->dq_flags);
2509 } else if (!(di->d_fieldmask & FS_DQ_BTIMER)) 2504 } else if (!(di->d_fieldmask & QC_SPC_TIMER))
2510 /* Set grace only if user hasn't provided his own... */ 2505 /* Set grace only if user hasn't provided his own... */
2511 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace; 2506 dm->dqb_btime = get_seconds() + dqi->dqi_bgrace;
2512 } 2507 }
@@ -2515,7 +2510,7 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2515 dm->dqb_curinodes < dm->dqb_isoftlimit) { 2510 dm->dqb_curinodes < dm->dqb_isoftlimit) {
2516 dm->dqb_itime = 0; 2511 dm->dqb_itime = 0;
2517 clear_bit(DQ_INODES_B, &dquot->dq_flags); 2512 clear_bit(DQ_INODES_B, &dquot->dq_flags);
2518 } else if (!(di->d_fieldmask & FS_DQ_ITIMER)) 2513 } else if (!(di->d_fieldmask & QC_INO_TIMER))
2519 /* Set grace only if user hasn't provided his own... */ 2514 /* Set grace only if user hasn't provided his own... */
2520 dm->dqb_itime = get_seconds() + dqi->dqi_igrace; 2515 dm->dqb_itime = get_seconds() + dqi->dqi_igrace;
2521 } 2516 }
@@ -2531,7 +2526,7 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
2531} 2526}
2532 2527
2533int dquot_set_dqblk(struct super_block *sb, struct kqid qid, 2528int dquot_set_dqblk(struct super_block *sb, struct kqid qid,
2534 struct fs_disk_quota *di) 2529 struct qc_dqblk *di)
2535{ 2530{
2536 struct dquot *dquot; 2531 struct dquot *dquot;
2537 int rc; 2532 int rc;
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 2aa4151f99d2..6f3856328eea 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -118,17 +118,27 @@ static int quota_setinfo(struct super_block *sb, int type, void __user *addr)
118 return sb->s_qcop->set_info(sb, type, &info); 118 return sb->s_qcop->set_info(sb, type, &info);
119} 119}
120 120
121static void copy_to_if_dqblk(struct if_dqblk *dst, struct fs_disk_quota *src) 121static inline qsize_t qbtos(qsize_t blocks)
122{
123 return blocks << QIF_DQBLKSIZE_BITS;
124}
125
126static inline qsize_t stoqb(qsize_t space)
127{
128 return (space + QIF_DQBLKSIZE - 1) >> QIF_DQBLKSIZE_BITS;
129}
130
131static void copy_to_if_dqblk(struct if_dqblk *dst, struct qc_dqblk *src)
122{ 132{
123 memset(dst, 0, sizeof(*dst)); 133 memset(dst, 0, sizeof(*dst));
124 dst->dqb_bhardlimit = src->d_blk_hardlimit; 134 dst->dqb_bhardlimit = stoqb(src->d_spc_hardlimit);
125 dst->dqb_bsoftlimit = src->d_blk_softlimit; 135 dst->dqb_bsoftlimit = stoqb(src->d_spc_softlimit);
126 dst->dqb_curspace = src->d_bcount; 136 dst->dqb_curspace = src->d_space;
127 dst->dqb_ihardlimit = src->d_ino_hardlimit; 137 dst->dqb_ihardlimit = src->d_ino_hardlimit;
128 dst->dqb_isoftlimit = src->d_ino_softlimit; 138 dst->dqb_isoftlimit = src->d_ino_softlimit;
129 dst->dqb_curinodes = src->d_icount; 139 dst->dqb_curinodes = src->d_ino_count;
130 dst->dqb_btime = src->d_btimer; 140 dst->dqb_btime = src->d_spc_timer;
131 dst->dqb_itime = src->d_itimer; 141 dst->dqb_itime = src->d_ino_timer;
132 dst->dqb_valid = QIF_ALL; 142 dst->dqb_valid = QIF_ALL;
133} 143}
134 144
@@ -136,7 +146,7 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id,
136 void __user *addr) 146 void __user *addr)
137{ 147{
138 struct kqid qid; 148 struct kqid qid;
139 struct fs_disk_quota fdq; 149 struct qc_dqblk fdq;
140 struct if_dqblk idq; 150 struct if_dqblk idq;
141 int ret; 151 int ret;
142 152
@@ -154,36 +164,36 @@ static int quota_getquota(struct super_block *sb, int type, qid_t id,
154 return 0; 164 return 0;
155} 165}
156 166
157static void copy_from_if_dqblk(struct fs_disk_quota *dst, struct if_dqblk *src) 167static void copy_from_if_dqblk(struct qc_dqblk *dst, struct if_dqblk *src)
158{ 168{
159 dst->d_blk_hardlimit = src->dqb_bhardlimit; 169 dst->d_spc_hardlimit = qbtos(src->dqb_bhardlimit);
160 dst->d_blk_softlimit = src->dqb_bsoftlimit; 170 dst->d_spc_softlimit = qbtos(src->dqb_bsoftlimit);
161 dst->d_bcount = src->dqb_curspace; 171 dst->d_space = src->dqb_curspace;
162 dst->d_ino_hardlimit = src->dqb_ihardlimit; 172 dst->d_ino_hardlimit = src->dqb_ihardlimit;
163 dst->d_ino_softlimit = src->dqb_isoftlimit; 173 dst->d_ino_softlimit = src->dqb_isoftlimit;
164 dst->d_icount = src->dqb_curinodes; 174 dst->d_ino_count = src->dqb_curinodes;
165 dst->d_btimer = src->dqb_btime; 175 dst->d_spc_timer = src->dqb_btime;
166 dst->d_itimer = src->dqb_itime; 176 dst->d_ino_timer = src->dqb_itime;
167 177
168 dst->d_fieldmask = 0; 178 dst->d_fieldmask = 0;
169 if (src->dqb_valid & QIF_BLIMITS) 179 if (src->dqb_valid & QIF_BLIMITS)
170 dst->d_fieldmask |= FS_DQ_BSOFT | FS_DQ_BHARD; 180 dst->d_fieldmask |= QC_SPC_SOFT | QC_SPC_HARD;
171 if (src->dqb_valid & QIF_SPACE) 181 if (src->dqb_valid & QIF_SPACE)
172 dst->d_fieldmask |= FS_DQ_BCOUNT; 182 dst->d_fieldmask |= QC_SPACE;
173 if (src->dqb_valid & QIF_ILIMITS) 183 if (src->dqb_valid & QIF_ILIMITS)
174 dst->d_fieldmask |= FS_DQ_ISOFT | FS_DQ_IHARD; 184 dst->d_fieldmask |= QC_INO_SOFT | QC_INO_HARD;
175 if (src->dqb_valid & QIF_INODES) 185 if (src->dqb_valid & QIF_INODES)
176 dst->d_fieldmask |= FS_DQ_ICOUNT; 186 dst->d_fieldmask |= QC_INO_COUNT;
177 if (src->dqb_valid & QIF_BTIME) 187 if (src->dqb_valid & QIF_BTIME)
178 dst->d_fieldmask |= FS_DQ_BTIMER; 188 dst->d_fieldmask |= QC_SPC_TIMER;
179 if (src->dqb_valid & QIF_ITIME) 189 if (src->dqb_valid & QIF_ITIME)
180 dst->d_fieldmask |= FS_DQ_ITIMER; 190 dst->d_fieldmask |= QC_INO_TIMER;
181} 191}
182 192
183static int quota_setquota(struct super_block *sb, int type, qid_t id, 193static int quota_setquota(struct super_block *sb, int type, qid_t id,
184 void __user *addr) 194 void __user *addr)
185{ 195{
186 struct fs_disk_quota fdq; 196 struct qc_dqblk fdq;
187 struct if_dqblk idq; 197 struct if_dqblk idq;
188 struct kqid qid; 198 struct kqid qid;
189 199
@@ -247,10 +257,78 @@ static int quota_getxstatev(struct super_block *sb, void __user *addr)
247 return ret; 257 return ret;
248} 258}
249 259
260/*
261 * XFS defines BBTOB and BTOBB macros inside fs/xfs/ and we cannot move them
262 * out of there as xfsprogs rely on definitions being in that header file. So
263 * just define same functions here for quota purposes.
264 */
265#define XFS_BB_SHIFT 9
266
267static inline u64 quota_bbtob(u64 blocks)
268{
269 return blocks << XFS_BB_SHIFT;
270}
271
272static inline u64 quota_btobb(u64 bytes)
273{
274 return (bytes + (1 << XFS_BB_SHIFT) - 1) >> XFS_BB_SHIFT;
275}
276
277static void copy_from_xfs_dqblk(struct qc_dqblk *dst, struct fs_disk_quota *src)
278{
279 dst->d_spc_hardlimit = quota_bbtob(src->d_blk_hardlimit);
280 dst->d_spc_softlimit = quota_bbtob(src->d_blk_softlimit);
281 dst->d_ino_hardlimit = src->d_ino_hardlimit;
282 dst->d_ino_softlimit = src->d_ino_softlimit;
283 dst->d_space = quota_bbtob(src->d_bcount);
284 dst->d_ino_count = src->d_icount;
285 dst->d_ino_timer = src->d_itimer;
286 dst->d_spc_timer = src->d_btimer;
287 dst->d_ino_warns = src->d_iwarns;
288 dst->d_spc_warns = src->d_bwarns;
289 dst->d_rt_spc_hardlimit = quota_bbtob(src->d_rtb_hardlimit);
290 dst->d_rt_spc_softlimit = quota_bbtob(src->d_rtb_softlimit);
291 dst->d_rt_space = quota_bbtob(src->d_rtbcount);
292 dst->d_rt_spc_timer = src->d_rtbtimer;
293 dst->d_rt_spc_warns = src->d_rtbwarns;
294 dst->d_fieldmask = 0;
295 if (src->d_fieldmask & FS_DQ_ISOFT)
296 dst->d_fieldmask |= QC_INO_SOFT;
297 if (src->d_fieldmask & FS_DQ_IHARD)
298 dst->d_fieldmask |= QC_INO_HARD;
299 if (src->d_fieldmask & FS_DQ_BSOFT)
300 dst->d_fieldmask |= QC_SPC_SOFT;
301 if (src->d_fieldmask & FS_DQ_BHARD)
302 dst->d_fieldmask |= QC_SPC_HARD;
303 if (src->d_fieldmask & FS_DQ_RTBSOFT)
304 dst->d_fieldmask |= QC_RT_SPC_SOFT;
305 if (src->d_fieldmask & FS_DQ_RTBHARD)
306 dst->d_fieldmask |= QC_RT_SPC_HARD;
307 if (src->d_fieldmask & FS_DQ_BTIMER)
308 dst->d_fieldmask |= QC_SPC_TIMER;
309 if (src->d_fieldmask & FS_DQ_ITIMER)
310 dst->d_fieldmask |= QC_INO_TIMER;
311 if (src->d_fieldmask & FS_DQ_RTBTIMER)
312 dst->d_fieldmask |= QC_RT_SPC_TIMER;
313 if (src->d_fieldmask & FS_DQ_BWARNS)
314 dst->d_fieldmask |= QC_SPC_WARNS;
315 if (src->d_fieldmask & FS_DQ_IWARNS)
316 dst->d_fieldmask |= QC_INO_WARNS;
317 if (src->d_fieldmask & FS_DQ_RTBWARNS)
318 dst->d_fieldmask |= QC_RT_SPC_WARNS;
319 if (src->d_fieldmask & FS_DQ_BCOUNT)
320 dst->d_fieldmask |= QC_SPACE;
321 if (src->d_fieldmask & FS_DQ_ICOUNT)
322 dst->d_fieldmask |= QC_INO_COUNT;
323 if (src->d_fieldmask & FS_DQ_RTBCOUNT)
324 dst->d_fieldmask |= QC_RT_SPACE;
325}
326
250static int quota_setxquota(struct super_block *sb, int type, qid_t id, 327static int quota_setxquota(struct super_block *sb, int type, qid_t id,
251 void __user *addr) 328 void __user *addr)
252{ 329{
253 struct fs_disk_quota fdq; 330 struct fs_disk_quota fdq;
331 struct qc_dqblk qdq;
254 struct kqid qid; 332 struct kqid qid;
255 333
256 if (copy_from_user(&fdq, addr, sizeof(fdq))) 334 if (copy_from_user(&fdq, addr, sizeof(fdq)))
@@ -260,13 +338,44 @@ static int quota_setxquota(struct super_block *sb, int type, qid_t id,
260 qid = make_kqid(current_user_ns(), type, id); 338 qid = make_kqid(current_user_ns(), type, id);
261 if (!qid_valid(qid)) 339 if (!qid_valid(qid))
262 return -EINVAL; 340 return -EINVAL;
263 return sb->s_qcop->set_dqblk(sb, qid, &fdq); 341 copy_from_xfs_dqblk(&qdq, &fdq);
342 return sb->s_qcop->set_dqblk(sb, qid, &qdq);
343}
344
345static void copy_to_xfs_dqblk(struct fs_disk_quota *dst, struct qc_dqblk *src,
346 int type, qid_t id)
347{
348 memset(dst, 0, sizeof(*dst));
349 dst->d_version = FS_DQUOT_VERSION;
350 dst->d_id = id;
351 if (type == USRQUOTA)
352 dst->d_flags = FS_USER_QUOTA;
353 else if (type == PRJQUOTA)
354 dst->d_flags = FS_PROJ_QUOTA;
355 else
356 dst->d_flags = FS_GROUP_QUOTA;
357 dst->d_blk_hardlimit = quota_btobb(src->d_spc_hardlimit);
358 dst->d_blk_softlimit = quota_btobb(src->d_spc_softlimit);
359 dst->d_ino_hardlimit = src->d_ino_hardlimit;
360 dst->d_ino_softlimit = src->d_ino_softlimit;
361 dst->d_bcount = quota_btobb(src->d_space);
362 dst->d_icount = src->d_ino_count;
363 dst->d_itimer = src->d_ino_timer;
364 dst->d_btimer = src->d_spc_timer;
365 dst->d_iwarns = src->d_ino_warns;
366 dst->d_bwarns = src->d_spc_warns;
367 dst->d_rtb_hardlimit = quota_btobb(src->d_rt_spc_hardlimit);
368 dst->d_rtb_softlimit = quota_btobb(src->d_rt_spc_softlimit);
369 dst->d_rtbcount = quota_btobb(src->d_rt_space);
370 dst->d_rtbtimer = src->d_rt_spc_timer;
371 dst->d_rtbwarns = src->d_rt_spc_warns;
264} 372}
265 373
266static int quota_getxquota(struct super_block *sb, int type, qid_t id, 374static int quota_getxquota(struct super_block *sb, int type, qid_t id,
267 void __user *addr) 375 void __user *addr)
268{ 376{
269 struct fs_disk_quota fdq; 377 struct fs_disk_quota fdq;
378 struct qc_dqblk qdq;
270 struct kqid qid; 379 struct kqid qid;
271 int ret; 380 int ret;
272 381
@@ -275,8 +384,11 @@ static int quota_getxquota(struct super_block *sb, int type, qid_t id,
275 qid = make_kqid(current_user_ns(), type, id); 384 qid = make_kqid(current_user_ns(), type, id);
276 if (!qid_valid(qid)) 385 if (!qid_valid(qid))
277 return -EINVAL; 386 return -EINVAL;
278 ret = sb->s_qcop->get_dqblk(sb, qid, &fdq); 387 ret = sb->s_qcop->get_dqblk(sb, qid, &qdq);
279 if (!ret && copy_to_user(addr, &fdq, sizeof(fdq))) 388 if (ret)
389 return ret;
390 copy_to_xfs_dqblk(&fdq, &qdq, type, id);
391 if (copy_to_user(addr, &fdq, sizeof(fdq)))
280 return -EFAULT; 392 return -EFAULT;
281 return ret; 393 return ret;
282} 394}
diff --git a/fs/xfs/xfs_qm.h b/fs/xfs/xfs_qm.h
index 3a07a937e232..41f6c0b9d51c 100644
--- a/fs/xfs/xfs_qm.h
+++ b/fs/xfs/xfs_qm.h
@@ -166,9 +166,9 @@ extern void xfs_qm_dqrele_all_inodes(struct xfs_mount *, uint);
166/* quota ops */ 166/* quota ops */
167extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint); 167extern int xfs_qm_scall_trunc_qfiles(struct xfs_mount *, uint);
168extern int xfs_qm_scall_getquota(struct xfs_mount *, xfs_dqid_t, 168extern int xfs_qm_scall_getquota(struct xfs_mount *, xfs_dqid_t,
169 uint, struct fs_disk_quota *); 169 uint, struct qc_dqblk *);
170extern int xfs_qm_scall_setqlim(struct xfs_mount *, xfs_dqid_t, uint, 170extern int xfs_qm_scall_setqlim(struct xfs_mount *, xfs_dqid_t, uint,
171 struct fs_disk_quota *); 171 struct qc_dqblk *);
172extern int xfs_qm_scall_getqstat(struct xfs_mount *, 172extern int xfs_qm_scall_getqstat(struct xfs_mount *,
173 struct fs_quota_stat *); 173 struct fs_quota_stat *);
174extern int xfs_qm_scall_getqstatv(struct xfs_mount *, 174extern int xfs_qm_scall_getqstatv(struct xfs_mount *,
diff --git a/fs/xfs/xfs_qm_syscalls.c b/fs/xfs/xfs_qm_syscalls.c
index 74fca68e43b6..cb6168ec92c9 100644
--- a/fs/xfs/xfs_qm_syscalls.c
+++ b/fs/xfs/xfs_qm_syscalls.c
@@ -39,7 +39,6 @@ STATIC int xfs_qm_log_quotaoff(xfs_mount_t *, xfs_qoff_logitem_t **, uint);
39STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *, 39STATIC int xfs_qm_log_quotaoff_end(xfs_mount_t *, xfs_qoff_logitem_t *,
40 uint); 40 uint);
41STATIC uint xfs_qm_export_flags(uint); 41STATIC uint xfs_qm_export_flags(uint);
42STATIC uint xfs_qm_export_qtype_flags(uint);
43 42
44/* 43/*
45 * Turn off quota accounting and/or enforcement for all udquots and/or 44 * Turn off quota accounting and/or enforcement for all udquots and/or
@@ -573,8 +572,8 @@ xfs_qm_scall_getqstatv(
573 return 0; 572 return 0;
574} 573}
575 574
576#define XFS_DQ_MASK \ 575#define XFS_QC_MASK \
577 (FS_DQ_LIMIT_MASK | FS_DQ_TIMER_MASK | FS_DQ_WARNS_MASK) 576 (QC_LIMIT_MASK | QC_TIMER_MASK | QC_WARNS_MASK)
578 577
579/* 578/*
580 * Adjust quota limits, and start/stop timers accordingly. 579 * Adjust quota limits, and start/stop timers accordingly.
@@ -584,7 +583,7 @@ xfs_qm_scall_setqlim(
584 struct xfs_mount *mp, 583 struct xfs_mount *mp,
585 xfs_dqid_t id, 584 xfs_dqid_t id,
586 uint type, 585 uint type,
587 fs_disk_quota_t *newlim) 586 struct qc_dqblk *newlim)
588{ 587{
589 struct xfs_quotainfo *q = mp->m_quotainfo; 588 struct xfs_quotainfo *q = mp->m_quotainfo;
590 struct xfs_disk_dquot *ddq; 589 struct xfs_disk_dquot *ddq;
@@ -593,9 +592,9 @@ xfs_qm_scall_setqlim(
593 int error; 592 int error;
594 xfs_qcnt_t hard, soft; 593 xfs_qcnt_t hard, soft;
595 594
596 if (newlim->d_fieldmask & ~XFS_DQ_MASK) 595 if (newlim->d_fieldmask & ~XFS_QC_MASK)
597 return -EINVAL; 596 return -EINVAL;
598 if ((newlim->d_fieldmask & XFS_DQ_MASK) == 0) 597 if ((newlim->d_fieldmask & XFS_QC_MASK) == 0)
599 return 0; 598 return 0;
600 599
601 /* 600 /*
@@ -633,11 +632,11 @@ xfs_qm_scall_setqlim(
633 /* 632 /*
634 * Make sure that hardlimits are >= soft limits before changing. 633 * Make sure that hardlimits are >= soft limits before changing.
635 */ 634 */
636 hard = (newlim->d_fieldmask & FS_DQ_BHARD) ? 635 hard = (newlim->d_fieldmask & QC_SPC_HARD) ?
637 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_hardlimit) : 636 (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_hardlimit) :
638 be64_to_cpu(ddq->d_blk_hardlimit); 637 be64_to_cpu(ddq->d_blk_hardlimit);
639 soft = (newlim->d_fieldmask & FS_DQ_BSOFT) ? 638 soft = (newlim->d_fieldmask & QC_SPC_SOFT) ?
640 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_blk_softlimit) : 639 (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_spc_softlimit) :
641 be64_to_cpu(ddq->d_blk_softlimit); 640 be64_to_cpu(ddq->d_blk_softlimit);
642 if (hard == 0 || hard >= soft) { 641 if (hard == 0 || hard >= soft) {
643 ddq->d_blk_hardlimit = cpu_to_be64(hard); 642 ddq->d_blk_hardlimit = cpu_to_be64(hard);
@@ -650,11 +649,11 @@ xfs_qm_scall_setqlim(
650 } else { 649 } else {
651 xfs_debug(mp, "blkhard %Ld < blksoft %Ld", hard, soft); 650 xfs_debug(mp, "blkhard %Ld < blksoft %Ld", hard, soft);
652 } 651 }
653 hard = (newlim->d_fieldmask & FS_DQ_RTBHARD) ? 652 hard = (newlim->d_fieldmask & QC_RT_SPC_HARD) ?
654 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_hardlimit) : 653 (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_hardlimit) :
655 be64_to_cpu(ddq->d_rtb_hardlimit); 654 be64_to_cpu(ddq->d_rtb_hardlimit);
656 soft = (newlim->d_fieldmask & FS_DQ_RTBSOFT) ? 655 soft = (newlim->d_fieldmask & QC_RT_SPC_SOFT) ?
657 (xfs_qcnt_t) XFS_BB_TO_FSB(mp, newlim->d_rtb_softlimit) : 656 (xfs_qcnt_t) XFS_B_TO_FSB(mp, newlim->d_rt_spc_softlimit) :
658 be64_to_cpu(ddq->d_rtb_softlimit); 657 be64_to_cpu(ddq->d_rtb_softlimit);
659 if (hard == 0 || hard >= soft) { 658 if (hard == 0 || hard >= soft) {
660 ddq->d_rtb_hardlimit = cpu_to_be64(hard); 659 ddq->d_rtb_hardlimit = cpu_to_be64(hard);
@@ -667,10 +666,10 @@ xfs_qm_scall_setqlim(
667 xfs_debug(mp, "rtbhard %Ld < rtbsoft %Ld", hard, soft); 666 xfs_debug(mp, "rtbhard %Ld < rtbsoft %Ld", hard, soft);
668 } 667 }
669 668
670 hard = (newlim->d_fieldmask & FS_DQ_IHARD) ? 669 hard = (newlim->d_fieldmask & QC_INO_HARD) ?
671 (xfs_qcnt_t) newlim->d_ino_hardlimit : 670 (xfs_qcnt_t) newlim->d_ino_hardlimit :
672 be64_to_cpu(ddq->d_ino_hardlimit); 671 be64_to_cpu(ddq->d_ino_hardlimit);
673 soft = (newlim->d_fieldmask & FS_DQ_ISOFT) ? 672 soft = (newlim->d_fieldmask & QC_INO_SOFT) ?
674 (xfs_qcnt_t) newlim->d_ino_softlimit : 673 (xfs_qcnt_t) newlim->d_ino_softlimit :
675 be64_to_cpu(ddq->d_ino_softlimit); 674 be64_to_cpu(ddq->d_ino_softlimit);
676 if (hard == 0 || hard >= soft) { 675 if (hard == 0 || hard >= soft) {
@@ -687,12 +686,12 @@ xfs_qm_scall_setqlim(
687 /* 686 /*
688 * Update warnings counter(s) if requested 687 * Update warnings counter(s) if requested
689 */ 688 */
690 if (newlim->d_fieldmask & FS_DQ_BWARNS) 689 if (newlim->d_fieldmask & QC_SPC_WARNS)
691 ddq->d_bwarns = cpu_to_be16(newlim->d_bwarns); 690 ddq->d_bwarns = cpu_to_be16(newlim->d_spc_warns);
692 if (newlim->d_fieldmask & FS_DQ_IWARNS) 691 if (newlim->d_fieldmask & QC_INO_WARNS)
693 ddq->d_iwarns = cpu_to_be16(newlim->d_iwarns); 692 ddq->d_iwarns = cpu_to_be16(newlim->d_ino_warns);
694 if (newlim->d_fieldmask & FS_DQ_RTBWARNS) 693 if (newlim->d_fieldmask & QC_RT_SPC_WARNS)
695 ddq->d_rtbwarns = cpu_to_be16(newlim->d_rtbwarns); 694 ddq->d_rtbwarns = cpu_to_be16(newlim->d_rt_spc_warns);
696 695
697 if (id == 0) { 696 if (id == 0) {
698 /* 697 /*
@@ -702,24 +701,24 @@ xfs_qm_scall_setqlim(
702 * soft and hard limit values (already done, above), and 701 * soft and hard limit values (already done, above), and
703 * for warnings. 702 * for warnings.
704 */ 703 */
705 if (newlim->d_fieldmask & FS_DQ_BTIMER) { 704 if (newlim->d_fieldmask & QC_SPC_TIMER) {
706 q->qi_btimelimit = newlim->d_btimer; 705 q->qi_btimelimit = newlim->d_spc_timer;
707 ddq->d_btimer = cpu_to_be32(newlim->d_btimer); 706 ddq->d_btimer = cpu_to_be32(newlim->d_spc_timer);
708 } 707 }
709 if (newlim->d_fieldmask & FS_DQ_ITIMER) { 708 if (newlim->d_fieldmask & QC_INO_TIMER) {
710 q->qi_itimelimit = newlim->d_itimer; 709 q->qi_itimelimit = newlim->d_ino_timer;
711 ddq->d_itimer = cpu_to_be32(newlim->d_itimer); 710 ddq->d_itimer = cpu_to_be32(newlim->d_ino_timer);
712 } 711 }
713 if (newlim->d_fieldmask & FS_DQ_RTBTIMER) { 712 if (newlim->d_fieldmask & QC_RT_SPC_TIMER) {
714 q->qi_rtbtimelimit = newlim->d_rtbtimer; 713 q->qi_rtbtimelimit = newlim->d_rt_spc_timer;
715 ddq->d_rtbtimer = cpu_to_be32(newlim->d_rtbtimer); 714 ddq->d_rtbtimer = cpu_to_be32(newlim->d_rt_spc_timer);
716 } 715 }
717 if (newlim->d_fieldmask & FS_DQ_BWARNS) 716 if (newlim->d_fieldmask & QC_SPC_WARNS)
718 q->qi_bwarnlimit = newlim->d_bwarns; 717 q->qi_bwarnlimit = newlim->d_spc_warns;
719 if (newlim->d_fieldmask & FS_DQ_IWARNS) 718 if (newlim->d_fieldmask & QC_INO_WARNS)
720 q->qi_iwarnlimit = newlim->d_iwarns; 719 q->qi_iwarnlimit = newlim->d_ino_warns;
721 if (newlim->d_fieldmask & FS_DQ_RTBWARNS) 720 if (newlim->d_fieldmask & QC_RT_SPC_WARNS)
722 q->qi_rtbwarnlimit = newlim->d_rtbwarns; 721 q->qi_rtbwarnlimit = newlim->d_rt_spc_warns;
723 } else { 722 } else {
724 /* 723 /*
725 * If the user is now over quota, start the timelimit. 724 * If the user is now over quota, start the timelimit.
@@ -824,7 +823,7 @@ xfs_qm_scall_getquota(
824 struct xfs_mount *mp, 823 struct xfs_mount *mp,
825 xfs_dqid_t id, 824 xfs_dqid_t id,
826 uint type, 825 uint type,
827 struct fs_disk_quota *dst) 826 struct qc_dqblk *dst)
828{ 827{
829 struct xfs_dquot *dqp; 828 struct xfs_dquot *dqp;
830 int error; 829 int error;
@@ -848,28 +847,25 @@ xfs_qm_scall_getquota(
848 } 847 }
849 848
850 memset(dst, 0, sizeof(*dst)); 849 memset(dst, 0, sizeof(*dst));
851 dst->d_version = FS_DQUOT_VERSION; 850 dst->d_spc_hardlimit =
852 dst->d_flags = xfs_qm_export_qtype_flags(dqp->q_core.d_flags); 851 XFS_FSB_TO_B(mp, be64_to_cpu(dqp->q_core.d_blk_hardlimit));
853 dst->d_id = be32_to_cpu(dqp->q_core.d_id); 852 dst->d_spc_softlimit =
854 dst->d_blk_hardlimit = 853 XFS_FSB_TO_B(mp, be64_to_cpu(dqp->q_core.d_blk_softlimit));
855 XFS_FSB_TO_BB(mp, be64_to_cpu(dqp->q_core.d_blk_hardlimit));
856 dst->d_blk_softlimit =
857 XFS_FSB_TO_BB(mp, be64_to_cpu(dqp->q_core.d_blk_softlimit));
858 dst->d_ino_hardlimit = be64_to_cpu(dqp->q_core.d_ino_hardlimit); 854 dst->d_ino_hardlimit = be64_to_cpu(dqp->q_core.d_ino_hardlimit);
859 dst->d_ino_softlimit = be64_to_cpu(dqp->q_core.d_ino_softlimit); 855 dst->d_ino_softlimit = be64_to_cpu(dqp->q_core.d_ino_softlimit);
860 dst->d_bcount = XFS_FSB_TO_BB(mp, dqp->q_res_bcount); 856 dst->d_space = XFS_FSB_TO_B(mp, dqp->q_res_bcount);
861 dst->d_icount = dqp->q_res_icount; 857 dst->d_ino_count = dqp->q_res_icount;
862 dst->d_btimer = be32_to_cpu(dqp->q_core.d_btimer); 858 dst->d_spc_timer = be32_to_cpu(dqp->q_core.d_btimer);
863 dst->d_itimer = be32_to_cpu(dqp->q_core.d_itimer); 859 dst->d_ino_timer = be32_to_cpu(dqp->q_core.d_itimer);
864 dst->d_iwarns = be16_to_cpu(dqp->q_core.d_iwarns); 860 dst->d_ino_warns = be16_to_cpu(dqp->q_core.d_iwarns);
865 dst->d_bwarns = be16_to_cpu(dqp->q_core.d_bwarns); 861 dst->d_spc_warns = be16_to_cpu(dqp->q_core.d_bwarns);
866 dst->d_rtb_hardlimit = 862 dst->d_rt_spc_hardlimit =
867 XFS_FSB_TO_BB(mp, be64_to_cpu(dqp->q_core.d_rtb_hardlimit)); 863 XFS_FSB_TO_B(mp, be64_to_cpu(dqp->q_core.d_rtb_hardlimit));
868 dst->d_rtb_softlimit = 864 dst->d_rt_spc_softlimit =
869 XFS_FSB_TO_BB(mp, be64_to_cpu(dqp->q_core.d_rtb_softlimit)); 865 XFS_FSB_TO_B(mp, be64_to_cpu(dqp->q_core.d_rtb_softlimit));
870 dst->d_rtbcount = XFS_FSB_TO_BB(mp, dqp->q_res_rtbcount); 866 dst->d_rt_space = XFS_FSB_TO_B(mp, dqp->q_res_rtbcount);
871 dst->d_rtbtimer = be32_to_cpu(dqp->q_core.d_rtbtimer); 867 dst->d_rt_spc_timer = be32_to_cpu(dqp->q_core.d_rtbtimer);
872 dst->d_rtbwarns = be16_to_cpu(dqp->q_core.d_rtbwarns); 868 dst->d_rt_spc_warns = be16_to_cpu(dqp->q_core.d_rtbwarns);
873 869
874 /* 870 /*
875 * Internally, we don't reset all the timers when quota enforcement 871 * Internally, we don't reset all the timers when quota enforcement
@@ -882,23 +878,23 @@ xfs_qm_scall_getquota(
882 dqp->q_core.d_flags == XFS_DQ_GROUP) || 878 dqp->q_core.d_flags == XFS_DQ_GROUP) ||
883 (!XFS_IS_PQUOTA_ENFORCED(mp) && 879 (!XFS_IS_PQUOTA_ENFORCED(mp) &&
884 dqp->q_core.d_flags == XFS_DQ_PROJ)) { 880 dqp->q_core.d_flags == XFS_DQ_PROJ)) {
885 dst->d_btimer = 0; 881 dst->d_spc_timer = 0;
886 dst->d_itimer = 0; 882 dst->d_ino_timer = 0;
887 dst->d_rtbtimer = 0; 883 dst->d_rt_spc_timer = 0;
888 } 884 }
889 885
890#ifdef DEBUG 886#ifdef DEBUG
891 if (((XFS_IS_UQUOTA_ENFORCED(mp) && dst->d_flags == FS_USER_QUOTA) || 887 if (((XFS_IS_UQUOTA_ENFORCED(mp) && type == XFS_DQ_USER) ||
892 (XFS_IS_GQUOTA_ENFORCED(mp) && dst->d_flags == FS_GROUP_QUOTA) || 888 (XFS_IS_GQUOTA_ENFORCED(mp) && type == XFS_DQ_GROUP) ||
893 (XFS_IS_PQUOTA_ENFORCED(mp) && dst->d_flags == FS_PROJ_QUOTA)) && 889 (XFS_IS_PQUOTA_ENFORCED(mp) && type == XFS_DQ_PROJ)) &&
894 dst->d_id != 0) { 890 id != 0) {
895 if ((dst->d_bcount > dst->d_blk_softlimit) && 891 if ((dst->d_space > dst->d_spc_softlimit) &&
896 (dst->d_blk_softlimit > 0)) { 892 (dst->d_spc_softlimit > 0)) {
897 ASSERT(dst->d_btimer != 0); 893 ASSERT(dst->d_spc_timer != 0);
898 } 894 }
899 if ((dst->d_icount > dst->d_ino_softlimit) && 895 if ((dst->d_ino_count > dst->d_ino_softlimit) &&
900 (dst->d_ino_softlimit > 0)) { 896 (dst->d_ino_softlimit > 0)) {
901 ASSERT(dst->d_itimer != 0); 897 ASSERT(dst->d_ino_timer != 0);
902 } 898 }
903 } 899 }
904#endif 900#endif
@@ -908,26 +904,6 @@ out_put:
908} 904}
909 905
910STATIC uint 906STATIC uint
911xfs_qm_export_qtype_flags(
912 uint flags)
913{
914 /*
915 * Can't be more than one, or none.
916 */
917 ASSERT((flags & (FS_PROJ_QUOTA | FS_USER_QUOTA)) !=
918 (FS_PROJ_QUOTA | FS_USER_QUOTA));
919 ASSERT((flags & (FS_PROJ_QUOTA | FS_GROUP_QUOTA)) !=
920 (FS_PROJ_QUOTA | FS_GROUP_QUOTA));
921 ASSERT((flags & (FS_USER_QUOTA | FS_GROUP_QUOTA)) !=
922 (FS_USER_QUOTA | FS_GROUP_QUOTA));
923 ASSERT((flags & (FS_PROJ_QUOTA|FS_USER_QUOTA|FS_GROUP_QUOTA)) != 0);
924
925 return (flags & XFS_DQ_USER) ?
926 FS_USER_QUOTA : (flags & XFS_DQ_PROJ) ?
927 FS_PROJ_QUOTA : FS_GROUP_QUOTA;
928}
929
930STATIC uint
931xfs_qm_export_flags( 907xfs_qm_export_flags(
932 uint flags) 908 uint flags)
933{ 909{
diff --git a/fs/xfs/xfs_quotaops.c b/fs/xfs/xfs_quotaops.c
index 7542bbeca6a1..801a84c1cdc3 100644
--- a/fs/xfs/xfs_quotaops.c
+++ b/fs/xfs/xfs_quotaops.c
@@ -131,7 +131,7 @@ STATIC int
131xfs_fs_get_dqblk( 131xfs_fs_get_dqblk(
132 struct super_block *sb, 132 struct super_block *sb,
133 struct kqid qid, 133 struct kqid qid,
134 struct fs_disk_quota *fdq) 134 struct qc_dqblk *qdq)
135{ 135{
136 struct xfs_mount *mp = XFS_M(sb); 136 struct xfs_mount *mp = XFS_M(sb);
137 137
@@ -141,14 +141,14 @@ xfs_fs_get_dqblk(
141 return -ESRCH; 141 return -ESRCH;
142 142
143 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid), 143 return xfs_qm_scall_getquota(mp, from_kqid(&init_user_ns, qid),
144 xfs_quota_type(qid.type), fdq); 144 xfs_quota_type(qid.type), qdq);
145} 145}
146 146
147STATIC int 147STATIC int
148xfs_fs_set_dqblk( 148xfs_fs_set_dqblk(
149 struct super_block *sb, 149 struct super_block *sb,
150 struct kqid qid, 150 struct kqid qid,
151 struct fs_disk_quota *fdq) 151 struct qc_dqblk *qdq)
152{ 152{
153 struct xfs_mount *mp = XFS_M(sb); 153 struct xfs_mount *mp = XFS_M(sb);
154 154
@@ -160,7 +160,7 @@ xfs_fs_set_dqblk(
160 return -ESRCH; 160 return -ESRCH;
161 161
162 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid), 162 return xfs_qm_scall_setqlim(mp, from_kqid(&init_user_ns, qid),
163 xfs_quota_type(qid.type), fdq); 163 xfs_quota_type(qid.type), qdq);
164} 164}
165 165
166const struct quotactl_ops xfs_quotactl_operations = { 166const struct quotactl_ops xfs_quotactl_operations = {
diff --git a/include/linux/quota.h b/include/linux/quota.h
index 50978b781a19..097d7eb2441e 100644
--- a/include/linux/quota.h
+++ b/include/linux/quota.h
@@ -321,6 +321,49 @@ struct dquot_operations {
321 321
322struct path; 322struct path;
323 323
324/* Structure for communicating via ->get_dqblk() & ->set_dqblk() */
325struct qc_dqblk {
326 int d_fieldmask; /* mask of fields to change in ->set_dqblk() */
327 u64 d_spc_hardlimit; /* absolute limit on used space */
328 u64 d_spc_softlimit; /* preferred limit on used space */
329 u64 d_ino_hardlimit; /* maximum # allocated inodes */
330 u64 d_ino_softlimit; /* preferred inode limit */
331 u64 d_space; /* Space owned by the user */
332 u64 d_ino_count; /* # inodes owned by the user */
333 s64 d_ino_timer; /* zero if within inode limits */
334 /* if not, we refuse service */
335 s64 d_spc_timer; /* similar to above; for space */
336 int d_ino_warns; /* # warnings issued wrt num inodes */
337 int d_spc_warns; /* # warnings issued wrt used space */
338 u64 d_rt_spc_hardlimit; /* absolute limit on realtime space */
339 u64 d_rt_spc_softlimit; /* preferred limit on RT space */
340 u64 d_rt_space; /* realtime space owned */
341 s64 d_rt_spc_timer; /* similar to above; for RT space */
342 int d_rt_spc_warns; /* # warnings issued wrt RT space */
343};
344
345/* Field specifiers for ->set_dqblk() in struct qc_dqblk */
346#define QC_INO_SOFT (1<<0)
347#define QC_INO_HARD (1<<1)
348#define QC_SPC_SOFT (1<<2)
349#define QC_SPC_HARD (1<<3)
350#define QC_RT_SPC_SOFT (1<<4)
351#define QC_RT_SPC_HARD (1<<5)
352#define QC_LIMIT_MASK (QC_INO_SOFT | QC_INO_HARD | QC_SPC_SOFT | QC_SPC_HARD | \
353 QC_RT_SPC_SOFT | QC_RT_SPC_HARD)
354#define QC_SPC_TIMER (1<<6)
355#define QC_INO_TIMER (1<<7)
356#define QC_RT_SPC_TIMER (1<<8)
357#define QC_TIMER_MASK (QC_SPC_TIMER | QC_INO_TIMER | QC_RT_SPC_TIMER)
358#define QC_SPC_WARNS (1<<9)
359#define QC_INO_WARNS (1<<10)
360#define QC_RT_SPC_WARNS (1<<11)
361#define QC_WARNS_MASK (QC_SPC_WARNS | QC_INO_WARNS | QC_RT_SPC_WARNS)
362#define QC_SPACE (1<<12)
363#define QC_INO_COUNT (1<<13)
364#define QC_RT_SPACE (1<<14)
365#define QC_ACCT_MASK (QC_SPACE | QC_INO_COUNT | QC_RT_SPACE)
366
324/* Operations handling requests from userspace */ 367/* Operations handling requests from userspace */
325struct quotactl_ops { 368struct quotactl_ops {
326 int (*quota_on)(struct super_block *, int, int, struct path *); 369 int (*quota_on)(struct super_block *, int, int, struct path *);
@@ -329,8 +372,8 @@ struct quotactl_ops {
329 int (*quota_sync)(struct super_block *, int); 372 int (*quota_sync)(struct super_block *, int);
330 int (*get_info)(struct super_block *, int, struct if_dqinfo *); 373 int (*get_info)(struct super_block *, int, struct if_dqinfo *);
331 int (*set_info)(struct super_block *, int, struct if_dqinfo *); 374 int (*set_info)(struct super_block *, int, struct if_dqinfo *);
332 int (*get_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *); 375 int (*get_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
333 int (*set_dqblk)(struct super_block *, struct kqid, struct fs_disk_quota *); 376 int (*set_dqblk)(struct super_block *, struct kqid, struct qc_dqblk *);
334 int (*get_xstate)(struct super_block *, struct fs_quota_stat *); 377 int (*get_xstate)(struct super_block *, struct fs_quota_stat *);
335 int (*set_xstate)(struct super_block *, unsigned int, int); 378 int (*set_xstate)(struct super_block *, unsigned int, int);
336 int (*get_xstatev)(struct super_block *, struct fs_quota_statv *); 379 int (*get_xstatev)(struct super_block *, struct fs_quota_statv *);
diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
index f23538a6e411..29e3455f7d41 100644
--- a/include/linux/quotaops.h
+++ b/include/linux/quotaops.h
@@ -98,9 +98,9 @@ int dquot_quota_sync(struct super_block *sb, int type);
98int dquot_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); 98int dquot_get_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
99int dquot_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii); 99int dquot_set_dqinfo(struct super_block *sb, int type, struct if_dqinfo *ii);
100int dquot_get_dqblk(struct super_block *sb, struct kqid id, 100int dquot_get_dqblk(struct super_block *sb, struct kqid id,
101 struct fs_disk_quota *di); 101 struct qc_dqblk *di);
102int dquot_set_dqblk(struct super_block *sb, struct kqid id, 102int dquot_set_dqblk(struct super_block *sb, struct kqid id,
103 struct fs_disk_quota *di); 103 struct qc_dqblk *di);
104 104
105int __dquot_transfer(struct inode *inode, struct dquot **transfer_to); 105int __dquot_transfer(struct inode *inode, struct dquot **transfer_to);
106int dquot_transfer(struct inode *inode, struct iattr *iattr); 106int dquot_transfer(struct inode *inode, struct iattr *iattr);