Blame SOURCES/xfsprogs-4.7.0-quota-fixes.patch

4a5a34
commit 52e81d72272a00c692cb6fdaa49df8b59a539c50
4a5a34
Author: Zorro Lang <zlang@redhat.com>
4a5a34
Date:   Thu Aug 4 11:29:49 2016 +1000
4a5a34
4a5a34
    xfs_quota: fall back silently if XFS_GETNEXTQUOTA fails
4a5a34
    
4a5a34
    After XFS_GETNEXTQUOTA feature has been merged into linux kernel and
4a5a34
    xfsprogs, xfs_quota use Q_XGETNEXTQUOTA for report and dump, and
4a5a34
    fall back to old XFS_GETQUOTA ioctl if XFS_GETNEXTQUOTA fails.
4a5a34
    
4a5a34
    But when XFS_GETNEXTQUOTA fails, xfs_quota print a warning as
4a5a34
    "XFS_GETQUOTA: Invalid argument". That's due to kernel can't
4a5a34
    recognize XFS_GETNEXTQUOTA ioctl and return EINVAL. At this time,
4a5a34
    the warning is helpless, xfs_quota just need to fall back.
4a5a34
    
4a5a34
    Signed-off-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Reviewed-by: Dave Chinner <dchinner@redhat.com>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
4a5a34
commit f61be1b4401e7653b2bdcd3aac2130a4da10faa5
4a5a34
Author: Eric Sandeen <sandeen@redhat.com>
4a5a34
Date:   Fri Jun 3 11:04:15 2016 +1000
4a5a34
4a5a34
    xfs_quota: only round up timer reporting > 1 day
4a5a34
    
4a5a34
    I was too hasty with:
4a5a34
    
4a5a34
    d1fe6ff xfs_quota: remove extra 30 seconds from time limit reporting
4a5a34
    
4a5a34
    The point of that extra 30s, turns out, was to allow the user
4a5a34
    to set a limit, query it, and get back what they just set, if
4a5a34
    it is set to more than a day.
4a5a34
    
4a5a34
    Without it, if we set a grace period to i.e. 3 days, and query it
4a5a34
    1 second later, the rounding in the time_to_string function returns
4a5a34
    "2 days" not "3 days" as it did before, because we are at
4a5a34
    2 days 23:59:59 and it essentially applies a floor() for
4a5a34
    brevity.  I guess this was confusing.
4a5a34
    
4a5a34
    (I've run into this same conundrum on my stove digital timer;
4a5a34
    if you set it to 10m, it blinks "10" at you twice so that you
4a5a34
    know what you set, then quickly flips to 9 as it counts down).
4a5a34
    
4a5a34
    In some cases, however (and this is the case that prompted the
4a5a34
    prior patch), we display a full "XYZ days hh:mm:ss" - we do this
4a5a34
    if the verbose flag is set, or if the timer is less than one day.
4a5a34
    In these cases, we should not add the 30s, because we are showing
4a5a34
    full time resolution to the user.
4a5a34
    
4a5a34
    Reported-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
4a5a34
    Reviewed-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Reviewed-by: Christoph Hellwig <hch@lst.de>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
4a5a34
commit a8b6f5274724ea2413d40f452f58874a36b78499
4a5a34
Author: Eric Sandeen <sandeen@sandeen.net>
4a5a34
Date:   Mon May 30 12:21:31 2016 +1000
4a5a34
4a5a34
    xfs_quota: check report_mount return value
4a5a34
    
4a5a34
    The new call to report_mount doesn't check the return value
4a5a34
    like every other caller does...
4a5a34
    
4a5a34
    Returning 1 means it printed something; if the terse flag
4a5a34
    is used and there is no usage, nothing gets printed.
4a5a34
    If we set the NO_HEADER_FLAG anyway, then we won't see
4a5a34
    the header for subsequent entries as we expect.
4a5a34
    
4a5a34
    For example, project ID 0 has no usage in this case:
4a5a34
    
4a5a34
    # xfs_quota -x -c "report -a" /mnt/test
4a5a34
    Project quota on /mnt/test (/dev/sdb1)
4a5a34
                                   Blocks
4a5a34
    Project ID       Used       Soft       Hard    Warn/Grace
4a5a34
    ---------- --------------------------------------------------
4a5a34
    #0                  0          0          0     00 [--------]
4a5a34
    project          2048          4          4     00 [--none--]
4a5a34
    
4a5a34
    So using the terse flag results in no header when it prints
4a5a34
    projects with usage:
4a5a34
    
4a5a34
    # xfs_quota -x -c "report -t -a" /mnt/test
4a5a34
    project          2048          4          4     00 [--none--]
4a5a34
    
4a5a34
    With this fix it prints the header as expected:
4a5a34
    
4a5a34
    # xfs_quota -x -c "report -t -a" /mnt/test
4a5a34
    Project quota on /mnt/test (/dev/sdb1)
4a5a34
                                   Blocks
4a5a34
    Project ID       Used       Soft       Hard    Warn/Grace
4a5a34
    ---------- --------------------------------------------------
4a5a34
    project          2048          4          4     00 [--none--]
4a5a34
    
4a5a34
    Addresses-Coverity-Id: 1361552
4a5a34
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
4a5a34
    Reviewed-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Reviewed-by: Christoph Hellwig <hch@lst.de>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
4a5a34
commit 3d607a1134c55849952412d64e7658fb00312705
4a5a34
Author: Zorro Lang <zlang@redhat.com>
4a5a34
Date:   Tue May 10 17:16:06 2016 +1000
4a5a34
4a5a34
    xfs_quota: print quota id number if the name can't be found
4a5a34
    
4a5a34
    When use GETNEXTQUOTA ioctl to report project quota, it always
4a5a34
    report an unexpected quota:
4a5a34
    
4a5a34
      (null) 0 0 0 00 [--------]
4a5a34
    
4a5a34
    The ID 0 store the default quota, even if no one set default quota,
4a5a34
    it still have quota accounting, but not enforced. So GETNEXTQUOTA
4a5a34
    can find and report this undefined quota.
4a5a34
    
4a5a34
    From this problem, I thought if others' quota name miss, (null) will
4a5a34
    be printed too. e.g.
4a5a34
    
4a5a34
      # xfs_quota -xc "limit -u bsoft=300m bhard=400m test" $mnt
4a5a34
      # xfs_quota -xc "report -u" $mnt
4a5a34
      User ID          Used       Soft       Hard    Warn/Grace
4a5a34
      ---------- --------------------------------------------------
4a5a34
      root                0          0          0     00 [--------]
4a5a34
      test                0     307200     409600     00 [--------]
4a5a34
      # userdel -r test
4a5a34
      # xfs_quota -xc "report -u" $mnt
4a5a34
      User ID          Used       Soft       Hard    Warn/Grace
4a5a34
      ---------- --------------------------------------------------
4a5a34
      root                0          0          0     00 [--------]
4a5a34
      (null)              0     307200     409600     00 [--------]
4a5a34
    
4a5a34
    So this problem same with above id 0's problem. To deal with this,
4a5a34
    this patch will print id number if the name can't be found.
4a5a34
    
4a5a34
    However, if we use the old GETQUOTA ioctl, it won't print project id
4a5a34
    0 quota information if it's not defined. That's different with
4a5a34
    GETNEXTQUOTA. For keep consistent, this patch also print project id
4a5a34
    0 when use old GETQUOTA.
4a5a34
    
4a5a34
    Signed-off-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Reviewed-by: Eric Sandeen <sandeen@redhat.com>
4a5a34
    Reviewed-by: Christoph Hellwig <hch@lst.de>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
4a5a34
commit cef37d5a0ef68351ea97518249b0c91746e700e3
4a5a34
Author: Zorro Lang <zlang@redhat.com>
4a5a34
Date:   Tue May 10 17:16:06 2016 +1000
4a5a34
4a5a34
    xfs_quota: fully support users and groups beginning with digits
4a5a34
    
4a5a34
    A normal user or group name allow beginning with digits, but xfs_quota
4a5a34
    can't create a limit for that user or group. The reason is 'strtoul'
4a5a34
    function only translate digits at the beginning, it will ignore
4a5a34
    letters after digits.
4a5a34
    
4a5a34
    There's a commit fd537fc50eeade63bbd2a66105f39d04a011a7f5, it try to
4a5a34
    fix "xfsprogs: xfs_quota allow user or group names beginning with
4a5a34
    digits". But it doesn't effect 'limit' command, so a command likes:
4a5a34
    
4a5a34
      xfs_quota 'limit .... 12345678-user' xxxx
4a5a34
    
4a5a34
    will try to create limit for username="12345678", not "12345678-user".
4a5a34
    
4a5a34
    This patch will fix this problem, and a test case xfs/138 in xfstests
4a5a34
    is used to reproduce this bug.
4a5a34
    
4a5a34
    Signed-off-by: Zorro Lang <zlang@redhat.com>
4a5a34
    Reviewed-by: Eric Sandeen <sandeen@redhat.com>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
4a5a34
commit 43633a39ef424e9e867b34a5dd3ea6c44508a45c
4a5a34
Author: Eric Sandeen <sandeen@sandeen.net>
4a5a34
Date:   Wed Feb 17 17:03:02 2016 +1100
4a5a34
4a5a34
    xfs: wire up Q_XGETNEXTQUOTA / get_nextdqblk
4a5a34
    
4a5a34
    Source kernel commit 296c24e26ee3af2dbfecb482e6bc9560bd34c455
4a5a34
    
4a5a34
    Add code to allow the Q_XGETNEXTQUOTA quotactl to quickly find
4a5a34
    all active quotas by examining the quota inode, and skipping
4a5a34
    over unallocated or uninitialized regions.
4a5a34
    
4a5a34
    Userspace can then use this interface rather than i.e. a
4a5a34
    getpwent() loop when asked to report all active quotas.
4a5a34
    
4a5a34
    Signed-off-by: Eric Sandeen <sandeen@redhat.com>
4a5a34
    Reviewed-by: Dave Chinner <dchinner@redhat.com>
4a5a34
    Signed-off-by: Dave Chinner <david@fromorbit.com>
4a5a34
Index: xfsprogs-4.5.0/quota/report.c
4a5a34
===================================================================
4a5a34
--- xfsprogs-4.5.0.orig/quota/report.c
4a5a34
+++ xfsprogs-4.5.0/quota/report.c
4a5a34
@@ -90,8 +90,10 @@ dump_file(
4a5a34
 	else
4a5a34
 		cmd = XFS_GETQUOTA;
4a5a34
 
4a5a34
+	/* Fall back silently if XFS_GETNEXTQUOTA fails, warn on XFS_GETQUOTA */
4a5a34
 	if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
4a5a34
-		if (errno != ENOENT && errno != ENOSYS && errno != ESRCH)
4a5a34
+		if (errno != ENOENT && errno != ENOSYS && errno != ESRCH &&
4a5a34
+		    cmd == XFS_GETQUOTA)
4a5a34
 			perror("XFS_GETQUOTA");
4a5a34
 		return 0;
4a5a34
 	}
4a5a34
@@ -347,8 +349,10 @@ report_mount(
4a5a34
 	else
4a5a34
 		cmd = XFS_GETQUOTA;
4a5a34
 
4a5a34
+	/* Fall back silently if XFS_GETNEXTQUOTA fails, warn on XFS_GETQUOTA*/
4a5a34
 	if (xfsquotactl(cmd, dev, type, id, (void *)&d) < 0) {
4a5a34
-		if (errno != ENOENT && errno != ENOSYS && errno != ESRCH)
4a5a34
+		if (errno != ENOENT && errno != ENOSYS && errno != ESRCH &&
4a5a34
+		    cmd == XFS_GETQUOTA)
4a5a34
 			perror("XFS_GETQUOTA");
4a5a34
 		return 0;
4a5a34
 	}
4a5a34
@@ -389,7 +393,11 @@ report_mount(
4a5a34
 					name = p->pr_name;
4a5a34
 			}
4a5a34
 		}
4a5a34
-		fprintf(fp, "%-10s", name);
4a5a34
+		/* If no name is found, print the id #num instead of (null) */
4a5a34
+		if (name != NULL)
4a5a34
+			fprintf(fp, "%-10s", name);
4a5a34
+		else
4a5a34
+			fprintf(fp, "#%-9u", d.d_id);
4a5a34
 	}
4a5a34
 
4a5a34
 	if (form & XFS_BLOCK_QUOTA) {
4a5a34
@@ -571,6 +579,16 @@ report_project_mount(
4a5a34
 			id = oid + 1;
4a5a34
 		}
4a5a34
 	} else {
4a5a34
+		if (!getprprid(0)) {
4a5a34
+			/*
4a5a34
+			 * Print default project quota, even if projid 0
4a5a34
+			 * isn't defined
4a5a34
+			 */
4a5a34
+			if (report_mount(fp, 0, NULL, NULL,
4a5a34
+					form, XFS_PROJ_QUOTA, mount, flags))
4a5a34
+				flags |= NO_HEADER_FLAG;
4a5a34
+		}
4a5a34
+
4a5a34
 		setprent();
4a5a34
 		while ((p = getprent()) != NULL) {
4a5a34
 			if (report_mount(fp, p->pr_prid, p->pr_name, NULL,
4a5a34
Index: xfsprogs-4.5.0/quota/util.c
4a5a34
===================================================================
4a5a34
--- xfsprogs-4.5.0.orig/quota/util.c
4a5a34
+++ xfsprogs-4.5.0/quota/util.c
4a5a34
@@ -43,6 +43,18 @@ time_to_string(
4a5a34
 		timer = MAX(origin - now, 0);
4a5a34
 	}
4a5a34
 
4a5a34
+	/*
4a5a34
+	 * If we are in verbose mode, or if less than a day remains, we
4a5a34
+	 * will show "X days hh:mm:ss" so the user knows the exact timer status.
4a5a34
+	 *
4a5a34
+	 * Otherwise, we round down to the nearest day - so we add 30s here
4a5a34
+	 * such that setting and reporting a limit in rapid succession will
4a5a34
+	 * show the limit which was just set, rather than immediately reporting
4a5a34
+	 * one day less.
4a5a34
+	 */
4a5a34
+	if ((timer > SECONDS_IN_A_DAY) && !(flags & VERBOSE_FLAG))
4a5a34
+		timer += 30;	/* seconds */
4a5a34
+
4a5a34
 	days = timer / SECONDS_IN_A_DAY;
4a5a34
 	if (days)
4a5a34
 		timer %= SECONDS_IN_A_DAY;
4a5a34
Index: xfsprogs-4.5.0/man/man8/xfs_quota.8
4a5a34
===================================================================
4a5a34
--- xfsprogs-4.5.0.orig/man/man8/xfs_quota.8
4a5a34
+++ xfsprogs-4.5.0/man/man8/xfs_quota.8
4a5a34
@@ -357,7 +357,9 @@ option outputs the report to
4a5a34
 .I file
4a5a34
 instead of stdout. The
4a5a34
 .B \-a
4a5a34
-option reports on all filesystems. The
4a5a34
+option reports on all filesystems. By default, outputs the name of
4a5a34
+the user/group/project. If no name is defined for a given ID, outputs
4a5a34
+the numeric ID instead. The
4a5a34
 .B \-n
4a5a34
 option outputs the numeric ID instead of the name. The
4a5a34
 .B \-L
4a5a34
Index: xfsprogs-4.5.0/libxcmd/input.c
4a5a34
===================================================================
4a5a34
--- xfsprogs-4.5.0.orig/libxcmd/input.c
4a5a34
+++ xfsprogs-4.5.0/libxcmd/input.c
4a5a34
@@ -366,7 +366,7 @@ uid_from_string(
4a5a34
 	char		*sp;
4a5a34
 
4a5a34
 	uid_long = strtoul(user, &sp, 10);
4a5a34
-	if (sp != user) {
4a5a34
+	if (sp != user && *sp == '\0') {
4a5a34
 		if ((uid_long == ULONG_MAX && errno == ERANGE)
4a5a34
 				|| (uid_long > (uid_t)-1))
4a5a34
 			return -1;
4a5a34
@@ -387,7 +387,7 @@ gid_from_string(
4a5a34
 	char		*sp;
4a5a34
 
4a5a34
 	gid_long = strtoul(group, &sp, 10);
4a5a34
-	if (sp != group) {
4a5a34
+	if (sp != group && *sp == '\0') {
4a5a34
 		if ((gid_long == ULONG_MAX && errno == ERANGE)
4a5a34
 				|| (gid_long > (gid_t)-1))
4a5a34
 			return -1;
4a5a34
Index: xfsprogs-4.5.0/libxfs/xfs_quota_defs.h
4a5a34
===================================================================
4a5a34
--- xfsprogs-4.5.0.orig/libxfs/xfs_quota_defs.h
4a5a34
+++ xfsprogs-4.5.0/libxfs/xfs_quota_defs.h
4a5a34
@@ -37,7 +37,7 @@ typedef __uint16_t	xfs_qwarncnt_t;
4a5a34
 #define XFS_DQ_PROJ		0x0002		/* project quota */
4a5a34
 #define XFS_DQ_GROUP		0x0004		/* a group quota */
4a5a34
 #define XFS_DQ_DIRTY		0x0008		/* dquot is dirty */
4a5a34
-#define XFS_DQ_FREEING		0x0010		/* dquot is beeing torn down */
4a5a34
+#define XFS_DQ_FREEING		0x0010		/* dquot is being torn down */
4a5a34
 
4a5a34
 #define XFS_DQ_ALLTYPES		(XFS_DQ_USER|XFS_DQ_PROJ|XFS_DQ_GROUP)
4a5a34
 
4a5a34
@@ -116,6 +116,7 @@ typedef __uint16_t	xfs_qwarncnt_t;
4a5a34
 #define XFS_QMOPT_DQREPAIR	0x0001000 /* repair dquot if damaged */
4a5a34
 #define XFS_QMOPT_GQUOTA	0x0002000 /* group dquot requested */
4a5a34
 #define XFS_QMOPT_ENOSPC	0x0004000 /* enospc instead of edquot (prj) */
4a5a34
+#define XFS_QMOPT_DQNEXT	0x0008000 /* return next dquot >= this ID */
4a5a34
 
4a5a34
 /*
4a5a34
  * flags to xfs_trans_mod_dquot to indicate which field needs to be