Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 40498
b: refs/heads/master
c: 528ba4e
h: refs/heads/master
v: v3
  • Loading branch information
Linus Torvalds committed Oct 31, 2006
1 parent 58ce5a9 commit 44588ea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 21e9ac7b2dd96dfca997313bae6d9a8f642635c7
refs/heads/master: 528ba4ef855bd184b7d68e3fa596b420fb4fa86a
54 changes: 37 additions & 17 deletions trunk/fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -641,17 +641,39 @@ static void free_bd_holder(struct bd_holder *bo)
kfree(bo);
}

/**
* find_bd_holder - find matching struct bd_holder from the block device
*
* @bdev: struct block device to be searched
* @bo: target struct bd_holder
*
* Returns matching entry with @bo in @bdev->bd_holder_list.
* If found, increment the reference count and return the pointer.
* If not found, returns NULL.
*/
static int find_bd_holder(struct block_device *bdev, struct bd_holder *bo)
{
struct bd_holder *tmp;

list_for_each_entry(tmp, &bdev->bd_holder_list, list)
if (tmp->sdir == bo->sdir) {
tmp->count++;
return tmp;
}

return NULL;
}

/**
* add_bd_holder - create sysfs symlinks for bd_claim() relationship
*
* @bdev: block device to be bd_claimed
* @bo: preallocated and initialized by alloc_bd_holder()
*
* If there is no matching entry with @bo in @bdev->bd_holder_list,
* add @bo to the list, create symlinks.
* Add @bo to @bdev->bd_holder_list, create symlinks.
*
* Returns 0 if symlinks are created or already there.
* Returns -ve if something fails and @bo can be freed.
* Returns 0 if symlinks are created.
* Returns -ve if something fails.
*/
static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
{
Expand All @@ -661,15 +683,6 @@ static int add_bd_holder(struct block_device *bdev, struct bd_holder *bo)
if (!bo)
return -EINVAL;

list_for_each_entry(tmp, &bdev->bd_holder_list, list) {
if (tmp->sdir == bo->sdir) {
tmp->count++;
/* We've already done what we need to do here. */
free_bd_holder(bo);
return 0;
}
}

if (!bd_holder_grab_dirs(bdev, bo))
return -EBUSY;

Expand Down Expand Up @@ -740,7 +753,7 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,
struct kobject *kobj)
{
int res;
struct bd_holder *bo;
struct bd_holder *bo, *found;

if (!kobj)
return -EINVAL;
Expand All @@ -751,9 +764,16 @@ static int bd_claim_by_kobject(struct block_device *bdev, void *holder,

mutex_lock_nested(&bdev->bd_mutex, BD_MUTEX_PARTITION);
res = bd_claim(bdev, holder);
if (res == 0)
res = add_bd_holder(bdev, bo);
if (res)
if (res == 0) {
found = find_bd_holder(bdev, bo);
if (found == NULL) {
res = add_bd_holder(bdev, bo);
if (res)
bd_release(bdev);
}
}

if (res || found)
free_bd_holder(bo);
mutex_unlock(&bdev->bd_mutex);

Expand Down

0 comments on commit 44588ea

Please sign in to comment.