Skip to contentSkip to conversation

Rearrange code to make the code more readable

RFC PATCH In review Chandra Seetharaman 4 participants 10 messages Oct 27, 2011 – Nov 11, 2011 XFS filesystem

lore
Share & tools
lore
#0 lore raw

cover Rearrange code to make the code more readable

Hello All,

These are the split up patches from patch 1/5 that I posted today, as suggested by Christoph.

These define some new inline functions and macros, rearrange the code for easier reading, simplification of code paths and prepare for the changes to support pquota and gquota simultaneously.

Regards,

chandra

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw

RFC PATCH 1/4 Define a new function xfs_this_quota_on()

Create a new function xfs_this_quota_on() that takes a xfs_mount data srtucture and a disk quota type and returns true if the specified type of quota is ON in the xfs_mount data structure.

---
 fs/xfs/xfs_dquot.c |    4 ++--
 fs/xfs/xfs_dquot.h |   17 +++++++++++++----
 2 files changed, 15 insertions(+), 6 deletions(-)
fs/xfs/xfs_dquot.c +2 -2
index 25d7280..815e231 100644
@@ -372,7 +372,7 @@ xfs_qm_dqalloc(
 	 * Return if this type of quotas is turned off while we didn't
 	 * have an inode lock
 	 */
-	if (XFS_IS_THIS_QUOTA_OFF(dqp)) {
+	if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
 		xfs_iunlock(quotip, XFS_ILOCK_EXCL);
 		return (ESRCH);
 	}
@@ -474,7 +474,7 @@ xfs_qm_dqtobp(
 	dqp->q_fileoffset = (xfs_fileoff_t)id / mp->m_quotainfo->qi_dqperchunk;
 
 	xfs_ilock(quotip, XFS_ILOCK_SHARED);
-	if (XFS_IS_THIS_QUOTA_OFF(dqp)) {
+	if (!xfs_this_quota_on(dqp->q_mount, dqp->dq_flags)) {
 		/*
 		 * Return if this type of quotas is turned off while we
 		 * didn't have the quota inode lock.
fs/xfs/xfs_dquot.h +13 -4
index 34b7e94..ef7a312 100644
@@ -102,6 +102,19 @@ static inline void xfs_dqfunlock(xfs_dquot_t *dqp)
 	complete(&dqp->q_flush);
 }
 
+static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
+{
+	type &= XFS_DQ_ALLTYPES;
+	switch(type) {
+	case XFS_DQ_USER:
+		return XFS_IS_UQUOTA_ON(mp);
+	case XFS_DQ_GROUP:
+	case XFS_DQ_PROJ:
+	default:
+		return XFS_IS_OQUOTA_ON(mp);
+	}
+}
+
 #define XFS_DQ_IS_LOCKED(dqp)	(mutex_is_locked(&((dqp)->q_qlock)))
 #define XFS_DQ_IS_DIRTY(dqp)	((dqp)->dq_flags & XFS_DQ_DIRTY)
 #define XFS_QM_ISUDQ(dqp)	((dqp)->dq_flags & XFS_DQ_USER)
@@ -112,10 +125,6 @@ static inline void xfs_dqfunlock(xfs_dquot_t *dqp)
 				 XFS_DQ_TO_QINF(dqp)->qi_uquotaip : \
 				 XFS_DQ_TO_QINF(dqp)->qi_gquotaip)
 
-#define XFS_IS_THIS_QUOTA_OFF(d) (! (XFS_QM_ISUDQ(d) ? \
-				     (XFS_IS_UQUOTA_ON((d)->q_mount)) : \
-				     (XFS_IS_OQUOTA_ON((d)->q_mount))))
-
 extern void		xfs_qm_dqdestroy(xfs_dquot_t *);
 extern int		xfs_qm_dqflush(xfs_dquot_t *, uint);
 extern int		xfs_qm_dqpurge(xfs_dquot_t *);
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 1/4
#2 lore raw

Re: [RFC PATCH 1/4] Define a new function xfs_this_quota_on()

Quoted 5 lines · Chandra Seetharaman

Create a new function xfs_this_quota_on() that takes a xfs_mount data srtucture and a disk quota type and returns true if the specified type of quota is ON in the xfs_mount data structure.

Looks good,

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v1 1/4
#3 lore raw

Re: [RFC PATCH 1/4] Define a new function xfs_this_quota_on()

In reply to Chandra Seetharaman
Quoted 5 lines · Chandra Seetharaman

Create a new function xfs_this_quota_on() that takes a xfs_mount data srtucture and a disk quota type and returns true if the specified type of quota is ON in the xfs_mount data structure.

Looks good.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw

RFC PATCH 2/4 Define a new function xfs_inode_dquot()

In reply to Chandra Seetharaman

Define a new function xfs_inode_dquot() that takes a inode pointer and a disk quota type and returns the quota pointer for the specified quota type.

This simplifies the xfs_qm_dqget() error path significantly.

---
 fs/xfs/xfs_dquot.c |   33 +++++++++------------------------
 fs/xfs/xfs_dquot.h |   14 ++++++++++++++
 2 files changed, 23 insertions(+), 24 deletions(-)
fs/xfs/xfs_dquot.c +9 -24
index 815e231..3c983a7 100644
@@ -808,7 +808,7 @@ xfs_qm_dqget(
 	uint		flags,	  /* DQALLOC, DQSUSER, DQREPAIR, DOWARN */
 	xfs_dquot_t	**O_dqpp) /* OUT : locked incore dquot */
 {
-	xfs_dquot_t	*dqp;
+	xfs_dquot_t	*dqp, *dqp1;
 	xfs_dqhash_t	*h;
 	uint		version;
 	int		error;
@@ -839,10 +839,7 @@ xfs_qm_dqget(
 	       type == XFS_DQ_GROUP);
 	if (ip) {
 		ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
-		if (type == XFS_DQ_USER)
-			ASSERT(ip->i_udquot == NULL);
-		else
-			ASSERT(ip->i_gdquot == NULL);
+		ASSERT(xfs_inode_dquot(ip, type) == NULL);
 	}
 #endif
 	mutex_lock(&h->qh_lock);
@@ -921,30 +918,18 @@ xfs_qm_dqget(
 		 * A dquot could be attached to this inode by now, since
 		 * we had dropped the ilock.
 		 */
-		if (type == XFS_DQ_USER) {
-			if (!XFS_IS_UQUOTA_ON(mp)) {
-				/* inode stays locked on return */
-				xfs_qm_dqdestroy(dqp);
-				return XFS_ERROR(ESRCH);
-			}
-			if (ip->i_udquot) {
+		if (xfs_this_quota_on(mp, type)) {
+			dqp1 = xfs_inode_dquot(ip, type);
+			if (dqp1) {
 				xfs_qm_dqdestroy(dqp);
-				dqp = ip->i_udquot;
+				dqp = dqp1;
 				xfs_dqlock(dqp);
 				goto dqret;
 			}
 		} else {
-			if (!XFS_IS_OQUOTA_ON(mp)) {
-				/* inode stays locked on return */
-				xfs_qm_dqdestroy(dqp);
-				return XFS_ERROR(ESRCH);
-			}
-			if (ip->i_gdquot) {
-				xfs_qm_dqdestroy(dqp);
-				dqp = ip->i_gdquot;
-				xfs_dqlock(dqp);
-				goto dqret;
-			}
+			/* inode stays locked on return */
+			xfs_qm_dqdestroy(dqp);
+			return XFS_ERROR(ESRCH);
 		}
 	}
 
fs/xfs/xfs_dquot.h +14 -0
index ef7a312..c09510a 100644
@@ -115,6 +115,20 @@ static inline int xfs_this_quota_on(struct xfs_mount *mp, int type)
 	}
 }
 
+static inline xfs_dquot_t *xfs_inode_dquot(struct xfs_inode *ip, int type)
+{
+	type &= XFS_DQ_ALLTYPES;
+	switch(type) {
+	case XFS_DQ_USER:
+		return ip->i_udquot;
+	case XFS_DQ_PROJ:
+	case XFS_DQ_GROUP:
+		return ip->i_gdquot;
+	default:
+		return NULL;
+	}
+}
+
 #define XFS_DQ_IS_LOCKED(dqp)	(mutex_is_locked(&((dqp)->q_qlock)))
 #define XFS_DQ_IS_DIRTY(dqp)	((dqp)->dq_flags & XFS_DQ_DIRTY)
 #define XFS_QM_ISUDQ(dqp)	((dqp)->dq_flags & XFS_DQ_USER)
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 2/4
#5 lore raw

Re: [RFC PATCH 2/4] Define a new function xfs_inode_dquot()

Quoted 7 lines · Chandra Seetharaman

Define a new function xfs_inode_dquot() that takes a inode pointer and a disk quota type and returns the quota pointer for the specified quota type.

This simplifies the xfs_qm_dqget() error path significantly.

Looks good.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#6 lore raw

RFC PATCH 3/4 Change xfs_sb_from_disk() interface to take a mount pointer

In reply to Chandra Seetharaman

Change xfs_sb_from_disk() interface to take a mount pointer instead of a superblock pointer.

This is to print mount point specific error messages in future fixes.

---
 fs/xfs/xfs_log_recover.c |    2 +-
 fs/xfs/xfs_mount.c       |    6 ++++--
 fs/xfs/xfs_mount.h       |    2 +-
 3 files changed, 6 insertions(+), 4 deletions(-)
fs/xfs/xfs_log_recover.c +1 -1
index 541a508..b38eb84 100644
@@ -3695,7 +3695,7 @@ xlog_do_recover(
 
 	/* Convert superblock from on-disk format */
 	sbp = &log->l_mp->m_sb;
-	xfs_sb_from_disk(sbp, XFS_BUF_TO_SBP(bp));
+	xfs_sb_from_disk(log->l_mp, XFS_BUF_TO_SBP(bp));
 	ASSERT(sbp->sb_magicnum == XFS_SB_MAGIC);
 	ASSERT(xfs_sb_good_version(sbp));
 	xfs_buf_relse(bp);
fs/xfs/xfs_mount.c +4 -2
index d06afbc..25e9908 100644
@@ -553,9 +553,11 @@ out_unwind:
 
 void
 xfs_sb_from_disk(
-	xfs_sb_t	*to,
+	struct xfs_mount	*mp,
 	xfs_dsb_t	*from)
 {
+	struct xfs_sb *to = &mp->m_sb;
+
 	to->sb_magicnum = be32_to_cpu(from->sb_magicnum);
 	to->sb_blocksize = be32_to_cpu(from->sb_blocksize);
 	to->sb_dblocks = be64_to_cpu(from->sb_dblocks);
@@ -693,7 +695,7 @@ reread:
 	 * Initialize the mount structure from the superblock.
 	 * But first do some basic consistency checking.
 	 */
-	xfs_sb_from_disk(&mp->m_sb, XFS_BUF_TO_SBP(bp));
+	xfs_sb_from_disk(mp, XFS_BUF_TO_SBP(bp));
 	error = xfs_mount_validate_sb(mp, &(mp->m_sb), flags);
 	if (error) {
 		if (loud)
fs/xfs/xfs_mount.h +1 -1
index bb24dac..376a618 100644
@@ -396,7 +396,7 @@ extern void	xfs_set_low_space_thresholds(struct xfs_mount *);
 extern void	xfs_mod_sb(struct xfs_trans *, __int64_t);
 extern int	xfs_initialize_perag(struct xfs_mount *, xfs_agnumber_t,
 					xfs_agnumber_t *);
-extern void	xfs_sb_from_disk(struct xfs_sb *, struct xfs_dsb *);
+extern void	xfs_sb_from_disk(struct xfs_mount *, struct xfs_dsb *);
 extern void	xfs_sb_to_disk(struct xfs_dsb *, struct xfs_sb *, __int64_t);
 
 #endif	/* __XFS_MOUNT_H__ */
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v1 3/4
#7 lore raw

Re: [RFC PATCH 3/4] Change xfs_sb_from_disk() interface to take a mount pointer

Quoted 7 lines · Chandra Seetharaman

Change xfs_sb_from_disk() interface to take a mount pointer instead of a superblock pointer.

This is to print mount point specific error messages in future fixes.

Looks good.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#8 lore raw

RFC PATCH 4/4 Define new macro XFS_ALL_QUOTA_ACTIVE and simply some usage

In reply to Chandra Seetharaman

Define new macro XFS_ALL_QUOTA_ACTIVE and simply some usage of quota macros.

---
 fs/xfs/xfs_qm.c    |    2 +-
 fs/xfs/xfs_quota.h |    2 ++
 fs/xfs/xfs_super.c |    7 +++----
 3 files changed, 6 insertions(+), 5 deletions(-)
fs/xfs/xfs_qm.c +1 -1
index 5cff443..508cee7 100644
@@ -1688,7 +1688,7 @@ xfs_qm_quotacheck(
 	 * quotachecked status, since we won't be doing accounting for
 	 * that type anymore.
 	 */
-	mp->m_qflags &= ~(XFS_OQUOTA_CHKD | XFS_UQUOTA_CHKD);
+	mp->m_qflags &= ~XFS_ALL_QUOTA_CHKD;
 	mp->m_qflags |= flags;
 
  error_return:
fs/xfs/xfs_quota.h +2 -0
index a595f29..1e52504 100644
@@ -176,6 +176,8 @@ typedef struct xfs_qoff_logformat {
 #define XFS_UQUOTA_ACTIVE	0x0100  /* uquotas are being turned off */
 #define XFS_PQUOTA_ACTIVE	0x0200  /* pquotas are being turned off */
 #define XFS_GQUOTA_ACTIVE	0x0400  /* gquotas are being turned off */
+#define XFS_ALL_QUOTA_ACTIVE	\
+	(XFS_UQUOTA_ACTIVE | XFS_PQUOTA_ACTIVE | XFS_GQUOTA_ACTIVE)
 
 /*
  * Checking XFS_IS_*QUOTA_ON() while holding any inode lock guarantees
fs/xfs/xfs_super.c +3 -4
index 3eca58f..5e4364a 100644
@@ -325,10 +325,9 @@ xfs_parseargs(
 		} else if (!strcmp(this_char, MNTOPT_FILESTREAM)) {
 			mp->m_flags |= XFS_MOUNT_FILESTREAMS;
 		} else if (!strcmp(this_char, MNTOPT_NOQUOTA)) {
-			mp->m_qflags &= ~(XFS_UQUOTA_ACCT | XFS_UQUOTA_ACTIVE |
-					  XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE |
-					  XFS_PQUOTA_ACCT | XFS_PQUOTA_ACTIVE |
-					  XFS_UQUOTA_ENFD | XFS_OQUOTA_ENFD);
+			mp->m_qflags &= ~XFS_ALL_QUOTA_ACCT;
+			mp->m_qflags &= ~XFS_ALL_QUOTA_ENFD;
+			mp->m_qflags &= ~XFS_ALL_QUOTA_ACTIVE;
 		} else if (!strcmp(this_char, MNTOPT_QUOTA) ||
 			   !strcmp(this_char, MNTOPT_UQUOTA) ||
 			   !strcmp(this_char, MNTOPT_USRQUOTA)) {
Signature · 6 lines
1.7.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on the v1 series
#9 lore raw
In reply to Chandra Seetharaman

Hey Chandra,

Quoted 7 lines · Chandra Seetharaman

These are the split up patches from patch 1/5 that I posted today, as suggested by Christoph.

These define some new inline functions and macros, rearrange the code for easier reading, simplification of code paths and prepare for the changes to support pquota and gquota simultaneously.

All four of these patches look good to me.

Regards,
Ben

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs