lkml.org 
[lkml]   [2008]   [Apr]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 1/2] loop : change lo_refcnt from int to atomic_t
It's not necessary to use lo_ctl_mutex to lock lo_refcnt. 

So here use atomic_t instead of int for lo_refcnt and leave lo_ctl_mutex just
for ioctl use.

Signed-off-by: Dave Young <hidave.darkstar@gmail.com>

---
drivers/block/loop.c | 12 +++++-------
include/linux/loop.h | 2 +-
2 files changed, 6 insertions(+), 8 deletions(-)

diff -upr linux/drivers/block/loop.c linux.new/drivers/block/loop.c
--- linux/drivers/block/loop.c 2008-04-25 10:10:25.000000000 +0800
+++ linux.new/drivers/block/loop.c 2008-04-25 10:30:54.000000000 +0800
@@ -891,7 +891,7 @@ static int loop_clr_fd(struct loop_devic
if (lo->lo_state != Lo_bound)
return -ENXIO;

- if (lo->lo_refcnt > 1) /* we needed one fd for the ioctl */
+ if (atomic_read(&lo->lo_refcnt) > 1)/* we needed one fd for the ioctl */
return -EBUSY;

if (filp == NULL)
@@ -1331,9 +1331,7 @@ static int lo_open(struct inode *inode,
{
struct loop_device *lo = inode->i_bdev->bd_disk->private_data;

- mutex_lock(&lo->lo_ctl_mutex);
- lo->lo_refcnt++;
- mutex_unlock(&lo->lo_ctl_mutex);
+ atomic_inc(&lo->lo_refcnt);

return 0;
}
@@ -1342,10 +1340,10 @@ static int lo_release(struct inode *inod
{
struct loop_device *lo = inode->i_bdev->bd_disk->private_data;

- mutex_lock(&lo->lo_ctl_mutex);
- --lo->lo_refcnt;
+ atomic_dec(&lo->lo_refcnt);

- if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !lo->lo_refcnt)
+ mutex_lock(&lo->lo_ctl_mutex);
+ if ((lo->lo_flags & LO_FLAGS_AUTOCLEAR) && !atomic_read(&lo->lo_refcnt))
loop_clr_fd(lo, inode->i_bdev);

mutex_unlock(&lo->lo_ctl_mutex);
diff -upr linux/include/linux/loop.h linux.new/include/linux/loop.h
--- linux/include/linux/loop.h 2008-04-25 10:31:23.000000000 +0800
+++ linux.new/include/linux/loop.h 2008-04-25 10:31:34.000000000 +0800
@@ -30,7 +30,7 @@ struct loop_func_table;

struct loop_device {
int lo_number;
- int lo_refcnt;
+ atomic_t lo_refcnt;
loff_t lo_offset;
loff_t lo_sizelimit;
int lo_flags;

\
 
 \ /
  Last update: 2008-04-28 04:11    [W:1.810 / U:1.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site