Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 16 Jul 2011 20:03:23 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r224113 - in stable/8/sys: sys ufs/ffs
Message-ID:  <201107162003.p6GK3N0O042269@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Jul 16 20:03:23 2011
New Revision: 224113
URL: http://svn.freebsd.org/changeset/base/224113

Log:
  MFC r223886:
  Implement a helper functions to locally set thread-private flag, and
  restore it to the previous state. Note that only setting a flag locally
  is supported.
  
  MFC r223887:
  Use helper functions instead of manually managing TDP_INBDFLUSH.
  
  MFC r223888:
  Use 'curthread_pflags' instead of 'thread_pflags' to signify that only
  curthread can be operated upon.
  
  Sponsored by: The FreeBSD Foundation

Modified:
  stable/8/sys/sys/proc.h
  stable/8/sys/ufs/ffs/ffs_balloc.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)

Modified: stable/8/sys/sys/proc.h
==============================================================================
--- stable/8/sys/sys/proc.h	Sat Jul 16 19:56:07 2011	(r224112)
+++ stable/8/sys/sys/proc.h	Sat Jul 16 20:03:23 2011	(r224113)
@@ -897,6 +897,25 @@ void	thread_unthread(struct thread *td);
 void	thread_wait(struct proc *p);
 struct thread	*thread_find(struct proc *p, lwpid_t tid);
 
+static __inline int
+curthread_pflags_set(int flags)
+{
+	struct thread *td;
+	int save;
+
+	td = curthread;
+	save = ~flags | (td->td_pflags & flags);
+	td->td_pflags |= flags;
+	return (save);
+}
+
+static __inline void
+curthread_pflags_restore(int save)
+{
+
+	curthread->td_pflags &= save;
+}
+
 #endif	/* _KERNEL */
 
 #endif	/* !_SYS_PROC_H_ */

Modified: stable/8/sys/ufs/ffs/ffs_balloc.c
==============================================================================
--- stable/8/sys/ufs/ffs/ffs_balloc.c	Sat Jul 16 19:56:07 2011	(r224112)
+++ stable/8/sys/ufs/ffs/ffs_balloc.c	Sat Jul 16 20:03:23 2011	(r224113)
@@ -228,9 +228,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t 
 	if (num < 1)
 		panic ("ffs_balloc_ufs1: ufs_getlbns returned indirect block");
 #endif
-	saved_inbdflush = ~TDP_INBDFLUSH | (curthread->td_pflags &
-	    TDP_INBDFLUSH);
-	curthread->td_pflags |= TDP_INBDFLUSH;
+	saved_inbdflush = curthread_pflags_set(TDP_INBDFLUSH);
 	/*
 	 * Fetch the first indirect block allocating if necessary.
 	 */
@@ -244,7 +242,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t 
 		pref = ffs_blkpref_ufs1(ip, lbn, 0, (ufs1_daddr_t *)0);
 	        if ((error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize,
 		    flags, cred, &newb)) != 0) {
-			curthread->td_pflags &= saved_inbdflush;
+			curthread_pflags_restore(saved_inbdflush);
 			return (error);
 		}
 		nb = newb;
@@ -337,7 +335,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t 
 	 * If asked only for the indirect block, then return it.
 	 */
 	if (flags & BA_METAONLY) {
-		curthread->td_pflags &= saved_inbdflush;
+		curthread_pflags_restore(saved_inbdflush);
 		*bpp = bp;
 		return (0);
 	}
@@ -375,7 +373,7 @@ ffs_balloc_ufs1(struct vnode *vp, off_t 
 				bp->b_flags |= B_CLUSTEROK;
 			bdwrite(bp);
 		}
-		curthread->td_pflags &= saved_inbdflush;
+		curthread_pflags_restore(saved_inbdflush);
 		*bpp = nbp;
 		return (0);
 	}
@@ -397,11 +395,11 @@ ffs_balloc_ufs1(struct vnode *vp, off_t 
 		nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0, 0);
 		nbp->b_blkno = fsbtodb(fs, nb);
 	}
-	curthread->td_pflags &= saved_inbdflush;
+	curthread_pflags_restore(saved_inbdflush);
 	*bpp = nbp;
 	return (0);
 fail:
-	curthread->td_pflags &= saved_inbdflush;
+	curthread_pflags_restore(saved_inbdflush);
 	/*
 	 * If we have failed to allocate any blocks, simply return the error.
 	 * This is the usual case and avoids the need to fsync the file.
@@ -734,9 +732,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 	if (num < 1)
 		panic ("ffs_balloc_ufs2: ufs_getlbns returned indirect block");
 #endif
-	saved_inbdflush = ~TDP_INBDFLUSH | (curthread->td_pflags &
-	    TDP_INBDFLUSH);
-	curthread->td_pflags |= TDP_INBDFLUSH;
+	saved_inbdflush = curthread_pflags_set(TDP_INBDFLUSH);
 	/*
 	 * Fetch the first indirect block allocating if necessary.
 	 */
@@ -750,7 +746,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 		pref = ffs_blkpref_ufs2(ip, lbn, 0, (ufs2_daddr_t *)0);
 	        if ((error = ffs_alloc(ip, lbn, pref, (int)fs->fs_bsize,
 		    flags, cred, &newb)) != 0) {
-			curthread->td_pflags &= saved_inbdflush;
+			curthread_pflags_restore(saved_inbdflush);
 			return (error);
 		}
 		nb = newb;
@@ -843,7 +839,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 	 * If asked only for the indirect block, then return it.
 	 */
 	if (flags & BA_METAONLY) {
-		curthread->td_pflags &= saved_inbdflush;
+		curthread_pflags_restore(saved_inbdflush);
 		*bpp = bp;
 		return (0);
 	}
@@ -881,7 +877,7 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 				bp->b_flags |= B_CLUSTEROK;
 			bdwrite(bp);
 		}
-		curthread->td_pflags &= saved_inbdflush;
+		curthread_pflags_restore(saved_inbdflush);
 		*bpp = nbp;
 		return (0);
 	}
@@ -909,11 +905,11 @@ ffs_balloc_ufs2(struct vnode *vp, off_t 
 		nbp = getblk(vp, lbn, fs->fs_bsize, 0, 0, 0);
 		nbp->b_blkno = fsbtodb(fs, nb);
 	}
-	curthread->td_pflags &= saved_inbdflush;
+	curthread_pflags_restore(saved_inbdflush);
 	*bpp = nbp;
 	return (0);
 fail:
-	curthread->td_pflags &= saved_inbdflush;
+	curthread_pflags_restore(saved_inbdflush);
 	/*
 	 * If we have failed to allocate any blocks, simply return the error.
 	 * This is the usual case and avoids the need to fsync the file.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201107162003.p6GK3N0O042269>