axmap: fix deadlock
authorMing Lei <ming.lei@canonical.com>
Sat, 3 Jan 2015 14:21:09 +0000 (22:21 +0800)
committerJens Axboe <axboe@fb.com>
Sat, 3 Jan 2015 18:11:08 +0000 (11:11 -0700)
axmap_first_free() is always called with axmap->lock held,
so needn't to acquire the lock inside the function.

The deadlock is introduced in commit 12bde3697fc230d7a(axmap:
ensure we lock down the maps for shared access).

Given axmap_first_free() is only called inside lib/axmap.c,
this patch declares the function as static. In the future,
if external users need the function, axmap lock can be
considered at that time.

Reported-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Ming Lei <ming.lei@canonical.com>
Tested-by: Sedat Dilek <sedat.dilek@gmail.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/axmap.c
lib/axmap.h

index e847a387bc6b8ab984ca4ca4162183ef37b6dd0f..8247fc1ae5d75f8aa452f2018bf248a6cc3a36a7 100644 (file)
@@ -387,17 +387,15 @@ static uint64_t axmap_find_first_free(struct axmap *axmap, unsigned int level,
        return (uint64_t) -1ULL;
 }
 
        return (uint64_t) -1ULL;
 }
 
-uint64_t axmap_first_free(struct axmap *axmap)
+static uint64_t axmap_first_free(struct axmap *axmap)
 {
        uint64_t ret;
 
        if (firstfree_valid(axmap))
                return axmap->first_free;
 
 {
        uint64_t ret;
 
        if (firstfree_valid(axmap))
                return axmap->first_free;
 
-       fio_mutex_down(&axmap->lock);
        ret = axmap_find_first_free(axmap, axmap->nr_levels - 1, 0);
        axmap->first_free = ret;
        ret = axmap_find_first_free(axmap, axmap->nr_levels - 1, 0);
        axmap->first_free = ret;
-       fio_mutex_up(&axmap->lock);
 
        return ret;
 }
 
        return ret;
 }
index edfeba80d854463eb0ada915d22bf493d7df4cb9..3705a1db754514c516511714783435cb54e3f86b 100644 (file)
@@ -11,7 +11,6 @@ void axmap_clear(struct axmap *axmap, uint64_t bit_nr);
 void axmap_set(struct axmap *axmap, uint64_t bit_nr);
 unsigned int axmap_set_nr(struct axmap *axmap, uint64_t bit_nr, unsigned int nr_bits);
 int axmap_isset(struct axmap *axmap, uint64_t bit_nr);
 void axmap_set(struct axmap *axmap, uint64_t bit_nr);
 unsigned int axmap_set_nr(struct axmap *axmap, uint64_t bit_nr, unsigned int nr_bits);
 int axmap_isset(struct axmap *axmap, uint64_t bit_nr);
-uint64_t axmap_first_free(struct axmap *axmap);
 uint64_t axmap_next_free(struct axmap *axmap, uint64_t bit_nr);
 void axmap_reset(struct axmap *axmap);
 
 uint64_t axmap_next_free(struct axmap *axmap, uint64_t bit_nr);
 void axmap_reset(struct axmap *axmap);