Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 347610
b: refs/heads/master
c: 42382b7
h: refs/heads/master
v: v3
  • Loading branch information
Alex Elder committed Dec 17, 2012
1 parent 71bf44f commit 74f9cb3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8884d53dd63b1d9315b343564fcbe1ede004a99e
refs/heads/master: 42382b709bd1d143b9f0fa93e0a3a1f2f4210707
13 changes: 13 additions & 0 deletions trunk/drivers/block/rbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ struct rbd_device {

/* sysfs related */
struct device dev;
unsigned long open_count;
};

static DEFINE_MUTEX(ctl_mutex); /* Serialize open/close/setup/teardown */
Expand Down Expand Up @@ -309,8 +310,11 @@ static int rbd_open(struct block_device *bdev, fmode_t mode)
if ((mode & FMODE_WRITE) && rbd_dev->mapping.read_only)
return -EROFS;

mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
rbd_get_dev(rbd_dev);
set_device_ro(bdev, rbd_dev->mapping.read_only);
rbd_dev->open_count++;
mutex_unlock(&ctl_mutex);

return 0;
}
Expand All @@ -319,7 +323,11 @@ static int rbd_release(struct gendisk *disk, fmode_t mode)
{
struct rbd_device *rbd_dev = disk->private_data;

mutex_lock_nested(&ctl_mutex, SINGLE_DEPTH_NESTING);
rbd_assert(rbd_dev->open_count > 0);
rbd_dev->open_count--;
rbd_put_dev(rbd_dev);
mutex_unlock(&ctl_mutex);

return 0;
}
Expand Down Expand Up @@ -3745,6 +3753,11 @@ static ssize_t rbd_remove(struct bus_type *bus,
goto done;
}

if (rbd_dev->open_count) {
ret = -EBUSY;
goto done;
}

rbd_remove_all_snaps(rbd_dev);
rbd_bus_del_dev(rbd_dev);

Expand Down

0 comments on commit 74f9cb3

Please sign in to comment.