History

Merge tag 'dm-3.15-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm

Pull device mapper fixes from Mike Snitzer: "A few dm-thinp fixes for changes merged in 3.15-rc1. A dm-verity fix for an immutable biovec regression that affects 3.14+. A dm-cache fix to properly quiesce when using writethrough mode (3.14+)" * tag 'dm-3.15-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: dm cache: fix writethrough mode quiescing in cache_map dm thin: use INIT_WORK_ONSTACK in noflush_work to avoid ODEBUG warning dm verity: fix biovecs hash calculation regression dm thin: fix rcu_read_lock being held in code that can sleep dm thin: irqsave must always be used with the pool->lock spinlock

Linus Torvalds committed 12 years ago

Commit 54366a72 parents 0845e11 131cd133 files · +81 −12Browse files

Unified · Split

3 files
  1. drivers/md/dm-cache-target.c +1 −0
  2. drivers/md/dm-thin.c +71 −6
  3. drivers/md/dm-verity.c +9 −6
drivers/md/dm-cache-target.c+1−0
@@ -2488,6 +2488,7 @@ static int cache_map(struct dm_target *ti, struct bio *bio) · 2487 unmodified lines
24882488
24892489 } else {
24902490 inc_hit_counter(cache, bio);
2491+ pb->all_io_entry = dm_deferred_entry_inc(cache->all_io_ds);
24912492
24922493 if (bio_data_dir(bio) == WRITE && writethrough_mode(&cache->features) &&
24932494 !is_dirty(cache, lookup_result.cblock))
drivers/md/dm-thin.c+71−6
@@ -232,6 +232,13 @@ struct thin_c { · 231 unmodified lines
232232 struct bio_list deferred_bio_list;
233233 struct bio_list retry_on_resume_list;
234234 struct rb_root sort_bio_list; /* sorted list of deferred bios */
235+
236+ /*
237+ * Ensures the thin is not destroyed until the worker has finished
238+ * iterating the active_thins list.
239+ */
240+ atomic_t refcount;
241+ struct completion can_destroy;
235242 };
236243
237244 /*----------------------------------------------------------------*/
@@ -1486,6 +1493,45 @@ static void process_thin_deferred_bios(struct thin_c *tc) · 1248 unmodified lines
14861493 blk_finish_plug(&plug);
14871494 }
14881495
1496+static void thin_get(struct thin_c *tc);
1497+static void thin_put(struct thin_c *tc);
1498+
1499+/*
1500+ * We can't hold rcu_read_lock() around code that can block. So we
1501+ * find a thin with the rcu lock held; bump a refcount; then drop
1502+ * the lock.
1503+ */
1504+static struct thin_c *get_first_thin(struct pool *pool)
1505+{
1506+ struct thin_c *tc = NULL;
1507+
1508+ rcu_read_lock();
1509+ if (!list_empty(&pool->active_thins)) {
1510+ tc = list_entry_rcu(pool->active_thins.next, struct thin_c, list);
1511+ thin_get(tc);
1512+ }
1513+ rcu_read_unlock();
1514+
1515+ return tc;
1516+}
1517+
1518+static struct thin_c *get_next_thin(struct pool *pool, struct thin_c *tc)
1519+{
1520+ struct thin_c *old_tc = tc;
1521+
1522+ rcu_read_lock();
1523+ list_for_each_entry_continue_rcu(tc, &pool->active_thins, list) {
1524+ thin_get(tc);
1525+ thin_put(old_tc);
1526+ rcu_read_unlock();
1527+ return tc;
1528+ }
1529+ thin_put(old_tc);
1530+ rcu_read_unlock();
1531+
1532+ return NULL;
1533+}
1534+
14891535 static void process_deferred_bios(struct pool *pool)
14901536 {
14911537 unsigned long flags;
@@ -1493,10 +1539,11 @@ static void process_deferred_bios(struct pool *pool) · 1 unmodified line
14931539 struct bio_list bios;
14941540 struct thin_c *tc;
14951541
1496− rcu_read_lock();
1497− list_for_each_entry_rcu(tc, &pool->active_thins, list)
1542+ tc = get_first_thin(pool);
1543+ while (tc) {
14981544 process_thin_deferred_bios(tc);
1499− rcu_read_unlock();
1545+ tc = get_next_thin(pool, tc);
1546+ }
15001547
15011548 /*
15021549 * If there are any deferred flush bios, we must commit
@@ -1578,7 +1625,7 @@ static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *)) · 75 unmodified lines
15781625 {
15791626 struct noflush_work w;
15801627
1581− INIT_WORK(&w.worker, fn);
1628+ INIT_WORK_ONSTACK(&w.worker, fn);
15821629 w.tc = tc;
15831630 atomic_set(&w.complete, 0);
15841631 init_waitqueue_head(&w.wait);
@@ -3061,11 +3108,25 @@ static struct target_type pool_target = { · 1476 unmodified lines
30613108 /*----------------------------------------------------------------
30623109 * Thin target methods
30633110 *--------------------------------------------------------------*/
3111+static void thin_get(struct thin_c *tc)
3112+{
3113+ atomic_inc(&tc->refcount);
3114+}
3115+
3116+static void thin_put(struct thin_c *tc)
3117+{
3118+ if (atomic_dec_and_test(&tc->refcount))
3119+ complete(&tc->can_destroy);
3120+}
3121+
30643122 static void thin_dtr(struct dm_target *ti)
30653123 {
30663124 struct thin_c *tc = ti->private;
30673125 unsigned long flags;
30683126
3127+ thin_put(tc);
3128+ wait_for_completion(&tc->can_destroy);
3129+
30693130 spin_lock_irqsave(&tc->pool->lock, flags);
30703131 list_del_rcu(&tc->list);
30713132 spin_unlock_irqrestore(&tc->pool->lock, flags);
@@ -3101,6 +3162,7 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 29 unmodified lines
31013162 struct thin_c *tc;
31023163 struct dm_dev *pool_dev, *origin_dev;
31033164 struct mapped_device *pool_md;
3165+ unsigned long flags;
31043166
31053167 mutex_lock(&dm_thin_pool_table.mutex);
31063168
@@ -3191,9 +3253,12 @@ static int thin_ctr(struct dm_target *ti, unsigned argc, char **argv) · 84 unmodified lines
31913253
31923254 mutex_unlock(&dm_thin_pool_table.mutex);
31933255
3194− spin_lock(&tc->pool->lock);
3256+ atomic_set(&tc->refcount, 1);
3257+ init_completion(&tc->can_destroy);
3258+
3259+ spin_lock_irqsave(&tc->pool->lock, flags);
31953260 list_add_tail_rcu(&tc->list, &tc->pool->active_thins);
3196− spin_unlock(&tc->pool->lock);
3261+ spin_unlock_irqrestore(&tc->pool->lock, flags);
31973262 /*
31983263 * This synchronize_rcu() call is needed here otherwise we risk a
31993264 * wake_worker() call finding no bios to process (because the newly
drivers/md/dm-verity.c+9−6
@@ -330,15 +330,17 @@ test_block_hash: · 329 unmodified lines
330330 return r;
331331 }
332332 }
333−
334333 todo = 1 << v->data_dev_block_bits;
335− while (io->iter.bi_size) {
334+ do {
336335 u8 *page;
336+ unsigned len;
337337 struct bio_vec bv = bio_iter_iovec(bio, io->iter);
338338
339339 page = kmap_atomic(bv.bv_page);
340− r = crypto_shash_update(desc, page + bv.bv_offset,
341− bv.bv_len);
340+ len = bv.bv_len;
341+ if (likely(len >= todo))
342+ len = todo;
343+ r = crypto_shash_update(desc, page + bv.bv_offset, len);
342344 kunmap_atomic(page);
343345
344346 if (r < 0) {
@@ -346,8 +348,9 @@ test_block_hash: · 1 unmodified line
346348 return r;
347349 }
348350
349− bio_advance_iter(bio, &io->iter, bv.bv_len);
350− }
351+ bio_advance_iter(bio, &io->iter, len);
352+ todo -= len;
353+ } while (todo);
351354
352355 if (!v->version) {
353356 r = crypto_shash_update(desc, v->salt, v->salt_size);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t