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

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