public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] jbd2,rcu: correctly use RCU
@ 2011-06-16  1:47 Lai Jiangshan
  2011-06-16  1:47 ` [PATCH 2/3] jbd2,tracing,rcu: jbd2_dev_to_name() is not protect by RCU Lai Jiangshan
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Lai Jiangshan @ 2011-06-16  1:47 UTC (permalink / raw)
  To: Paul E. McKenney, Steven Rostedt, Ingo Molnar, Theodore Tso,
	linux-ext4, linux-kernel
  Cc: Lai Jiangshan

In read site, we need to use local_ptr = rcu_dereference(),
and then use this local_ptr to read the content.

In update site, we should assign/publish the new object/pointer after
the content of the new object/pointer is fully initialized,
and we can't not touch the object after the pointer assignment.
rcu_assign_pointer() is need for the assignement.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
 fs/jbd2/journal.c |   25 +++++++++++++------------
 1 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 9267291..1c45b6a 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2439,7 +2439,7 @@ struct devname_cache {
 	char		devname[BDEVNAME_SIZE];
 };
 #define CACHE_SIZE_BITS 6
-static struct devname_cache *devcache[1 << CACHE_SIZE_BITS];
+static struct devname_cache __rcu *devcache[1 << CACHE_SIZE_BITS];
 static DEFINE_SPINLOCK(devname_cache_lock);
 
 const char *jbd2_dev_to_name(dev_t device)
@@ -2447,24 +2447,25 @@ const char *jbd2_dev_to_name(dev_t device)
 	int	i = hash_32(device, CACHE_SIZE_BITS);
 	char	*ret;
 	struct block_device *bd;
-	static struct devname_cache *new_dev;
+	static struct devname_cache *cache;
 
 	rcu_read_lock();
-	if (devcache[i] && devcache[i]->device == device) {
-		ret = devcache[i]->devname;
+	cache = rcu_dereference(devcache[i]);
+	if (cache && cache->device == device) {
+		ret = cache->devname;
 		rcu_read_unlock();
 		return ret;
 	}
 	rcu_read_unlock();
 
-	new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
-	if (!new_dev)
+	cache = kmalloc(sizeof(struct devname_cache), GFP_KERNEL);
+	if (!cache)
 		return "NODEV-ALLOCFAILURE"; /* Something non-NULL */
 	bd = bdget(device);
 	spin_lock(&devname_cache_lock);
 	if (devcache[i]) {
 		if (devcache[i]->device == device) {
-			kfree(new_dev);
+			kfree(cache);
 			bdput(bd);
 			ret = devcache[i]->devname;
 			spin_unlock(&devname_cache_lock);
@@ -2472,14 +2473,14 @@ const char *jbd2_dev_to_name(dev_t device)
 		}
 		kfree_rcu(devcache[i], rcu);
 	}
-	devcache[i] = new_dev;
-	devcache[i]->device = device;
+	cache->device = device;
 	if (bd) {
-		bdevname(bd, devcache[i]->devname);
+		bdevname(bd, cache->devname);
 		bdput(bd);
 	} else
-		__bdevname(device, devcache[i]->devname);
-	ret = devcache[i]->devname;
+		__bdevname(device, cache->devname);
+	rcu_assign_pointer(devcache[i], cache);
+	ret = cache->devname;
 	spin_unlock(&devname_cache_lock);
 	return ret;
 }
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-07-11  1:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-16  1:47 [PATCH 1/3] jbd2,rcu: correctly use RCU Lai Jiangshan
2011-06-16  1:47 ` [PATCH 2/3] jbd2,tracing,rcu: jbd2_dev_to_name() is not protect by RCU Lai Jiangshan
2011-07-08  2:06   ` Steven Rostedt
2011-07-08 16:02     ` Paul E. McKenney
2011-06-16  1:47 ` [PATCH 3/3] jbd2,rcu: simpify jbd2_dev_to_name() Lai Jiangshan
2011-07-11  0:25 ` [PATCH 1/3] jbd2,rcu: correctly use RCU Ted Ts'o
2011-07-11  1:24 ` Ted Ts'o

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox