summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMikulas Patocka <mpatocka@redhat.com>2014-01-13 19:12:36 -0500
committerMike Snitzer <snitzer@redhat.com>2014-01-14 23:23:02 -0500
commit55494bf2947dccdf2d98b62374fea7365dfead84 (patch)
tree08958b0812f1c59732f6a56e2b567ad3a8da7230
parent2cadabd512acca99e6553d303eaedc97a3178a4d (diff)
dm snapshot: use dm-bufio
Use dm-bufio for initial loading of the exceptions. Introduce a new function dm_bufio_forget that frees the given buffer. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
-rw-r--r--drivers/md/Kconfig1
-rw-r--r--drivers/md/dm-bufio.c22
-rw-r--r--drivers/md/dm-bufio.h7
-rw-r--r--drivers/md/dm-snap-persistent.c39
4 files changed, 62 insertions, 7 deletions
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 7441344bd214..39b540a13369 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -238,6 +238,7 @@ config DM_CRYPT
238config DM_SNAPSHOT 238config DM_SNAPSHOT
239 tristate "Snapshot target" 239 tristate "Snapshot target"
240 depends on BLK_DEV_DM 240 depends on BLK_DEV_DM
241 select DM_BUFIO
241 ---help--- 242 ---help---
242 Allow volume managers to take writable snapshots of a device. 243 Allow volume managers to take writable snapshots of a device.
243 244
diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
index 54bdd923316f..d86593721915 100644
--- a/drivers/md/dm-bufio.c
+++ b/drivers/md/dm-bufio.c
@@ -1350,6 +1350,28 @@ retry:
1350} 1350}
1351EXPORT_SYMBOL_GPL(dm_bufio_release_move); 1351EXPORT_SYMBOL_GPL(dm_bufio_release_move);
1352 1352
1353/*
1354 * Free the given buffer.
1355 *
1356 * This is just a hint, if the buffer is in use or dirty, this function
1357 * does nothing.
1358 */
1359void dm_bufio_forget(struct dm_bufio_client *c, sector_t block)
1360{
1361 struct dm_buffer *b;
1362
1363 dm_bufio_lock(c);
1364
1365 b = __find(c, block);
1366 if (b && likely(!b->hold_count) && likely(!b->state)) {
1367 __unlink_buffer(b);
1368 __free_buffer_wake(b);
1369 }
1370
1371 dm_bufio_unlock(c);
1372}
1373EXPORT_SYMBOL(dm_bufio_forget);
1374
1353unsigned dm_bufio_get_block_size(struct dm_bufio_client *c) 1375unsigned dm_bufio_get_block_size(struct dm_bufio_client *c)
1354{ 1376{
1355 return c->block_size; 1377 return c->block_size;
diff --git a/drivers/md/dm-bufio.h b/drivers/md/dm-bufio.h
index b142946a9e32..3dac37627ba4 100644
--- a/drivers/md/dm-bufio.h
+++ b/drivers/md/dm-bufio.h
@@ -108,6 +108,13 @@ int dm_bufio_issue_flush(struct dm_bufio_client *c);
108 */ 108 */
109void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block); 109void dm_bufio_release_move(struct dm_buffer *b, sector_t new_block);
110 110
111/*
112 * Free the given buffer.
113 * This is just a hint, if the buffer is in use or dirty, this function
114 * does nothing.
115 */
116void dm_bufio_forget(struct dm_bufio_client *c, sector_t block);
117
111unsigned dm_bufio_get_block_size(struct dm_bufio_client *c); 118unsigned dm_bufio_get_block_size(struct dm_bufio_client *c);
112sector_t dm_bufio_get_device_size(struct dm_bufio_client *c); 119sector_t dm_bufio_get_device_size(struct dm_bufio_client *c);
113sector_t dm_bufio_get_block_number(struct dm_buffer *b); 120sector_t dm_bufio_get_block_number(struct dm_buffer *b);
diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index ba792ae068b7..169275050c0b 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -13,6 +13,7 @@
13#include <linux/export.h> 13#include <linux/export.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/dm-io.h> 15#include <linux/dm-io.h>
16#include "dm-bufio.h"
16 17
17#define DM_MSG_PREFIX "persistent snapshot" 18#define DM_MSG_PREFIX "persistent snapshot"
18#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */ 19#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */
@@ -495,27 +496,51 @@ static int read_exceptions(struct pstore *ps,
495 void *callback_context) 496 void *callback_context)
496{ 497{
497 int r, full = 1; 498 int r, full = 1;
499 struct dm_bufio_client *client;
500
501 client = dm_bufio_client_create(dm_snap_cow(ps->store->snap)->bdev,
502 ps->store->chunk_size << SECTOR_SHIFT,
503 1, 0, NULL, NULL);
504
505 if (IS_ERR(client))
506 return PTR_ERR(client);
498 507
499 /* 508 /*
500 * Keeping reading chunks and inserting exceptions until 509 * Keeping reading chunks and inserting exceptions until
501 * we find a partially full area. 510 * we find a partially full area.
502 */ 511 */
503 for (ps->current_area = 0; full; ps->current_area++) { 512 for (ps->current_area = 0; full; ps->current_area++) {
504 r = area_io(ps, READ); 513 struct dm_buffer *bp;
505 if (r) 514 void *area;
506 return r; 515 chunk_t chunk = area_location(ps, ps->current_area);
516
517 area = dm_bufio_read(client, chunk, &bp);
518 if (unlikely(IS_ERR(area))) {
519 r = PTR_ERR(area);
520 goto ret_destroy_bufio;
521 }
507 522
508 r = insert_exceptions(ps, ps->area, callback, callback_context, 523 r = insert_exceptions(ps, area, callback, callback_context,
509 &full); 524 &full);
510 if (r) 525
511 return r; 526 dm_bufio_release(bp);
527
528 dm_bufio_forget(client, chunk);
529
530 if (unlikely(r))
531 goto ret_destroy_bufio;
512 } 532 }
513 533
514 ps->current_area--; 534 ps->current_area--;
515 535
516 skip_metadata(ps); 536 skip_metadata(ps);
517 537
518 return 0; 538 r = 0;
539
540ret_destroy_bufio:
541 dm_bufio_client_destroy(client);
542
543 return r;
519} 544}
520 545
521static struct pstore *get_info(struct dm_exception_store *store) 546static struct pstore *get_info(struct dm_exception_store *store)