dm-snap-transient.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (C) 2001-2002 Sistina Software (UK) Limited.
  3. * Copyright (C) 2006-2008 Red Hat GmbH
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #include "dm-exception-store.h"
  8. #include "dm-snap.h"
  9. #include <linux/mm.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/vmalloc.h>
  12. #include <linux/slab.h>
  13. #include <linux/dm-io.h>
  14. #define DM_MSG_PREFIX "transient snapshot"
  15. /*-----------------------------------------------------------------
  16. * Implementation of the store for non-persistent snapshots.
  17. *---------------------------------------------------------------*/
  18. struct transient_c {
  19. sector_t next_free;
  20. };
  21. static void transient_destroy(struct dm_exception_store *store)
  22. {
  23. kfree(store->context);
  24. }
  25. static int transient_read_metadata(struct dm_exception_store *store,
  26. int (*callback)(void *callback_context,
  27. chunk_t old, chunk_t new),
  28. void *callback_context)
  29. {
  30. return 0;
  31. }
  32. static int transient_prepare_exception(struct dm_exception_store *store,
  33. struct dm_snap_exception *e)
  34. {
  35. struct transient_c *tc = (struct transient_c *) store->context;
  36. sector_t size = get_dev_size(store->snap->cow->bdev);
  37. if (size < (tc->next_free + store->snap->chunk_size))
  38. return -1;
  39. e->new_chunk = sector_to_chunk(store->snap, tc->next_free);
  40. tc->next_free += store->snap->chunk_size;
  41. return 0;
  42. }
  43. static void transient_commit_exception(struct dm_exception_store *store,
  44. struct dm_snap_exception *e,
  45. void (*callback) (void *, int success),
  46. void *callback_context)
  47. {
  48. /* Just succeed */
  49. callback(callback_context, 1);
  50. }
  51. static void transient_fraction_full(struct dm_exception_store *store,
  52. sector_t *numerator, sector_t *denominator)
  53. {
  54. *numerator = ((struct transient_c *) store->context)->next_free;
  55. *denominator = get_dev_size(store->snap->cow->bdev);
  56. }
  57. int dm_create_transient(struct dm_exception_store *store)
  58. {
  59. struct transient_c *tc;
  60. store->destroy = transient_destroy;
  61. store->read_metadata = transient_read_metadata;
  62. store->prepare_exception = transient_prepare_exception;
  63. store->commit_exception = transient_commit_exception;
  64. store->drop_snapshot = NULL;
  65. store->fraction_full = transient_fraction_full;
  66. tc = kmalloc(sizeof(struct transient_c), GFP_KERNEL);
  67. if (!tc)
  68. return -ENOMEM;
  69. tc->next_free = 0;
  70. store->context = tc;
  71. return 0;
  72. }
  73. int dm_transient_snapshot_init(void)
  74. {
  75. return 0;
  76. }
  77. void dm_transient_snapshot_exit(void)
  78. {
  79. }