linux/drivers/md/dm-thin-metadata.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2010-2011 Red Hat, Inc.
   3 *
   4 * This file is released under the GPL.
   5 */
   6
   7#ifndef DM_THIN_METADATA_H
   8#define DM_THIN_METADATA_H
   9
  10#include "persistent-data/dm-block-manager.h"
  11
  12#define THIN_METADATA_BLOCK_SIZE 4096
  13
  14/*----------------------------------------------------------------*/
  15
  16struct dm_pool_metadata;
  17struct dm_thin_device;
  18
  19/*
  20 * Device identifier
  21 */
  22typedef uint64_t dm_thin_id;
  23
  24/*
  25 * Reopens or creates a new, empty metadata volume.
  26 */
  27struct dm_pool_metadata *dm_pool_metadata_open(struct block_device *bdev,
  28                                               sector_t data_block_size);
  29
  30int dm_pool_metadata_close(struct dm_pool_metadata *pmd);
  31
  32/*
  33 * Compat feature flags.  Any incompat flags beyond the ones
  34 * specified below will prevent use of the thin metadata.
  35 */
  36#define THIN_FEATURE_COMPAT_SUPP          0UL
  37#define THIN_FEATURE_COMPAT_RO_SUPP       0UL
  38#define THIN_FEATURE_INCOMPAT_SUPP        0UL
  39
  40/*
  41 * Device creation/deletion.
  42 */
  43int dm_pool_create_thin(struct dm_pool_metadata *pmd, dm_thin_id dev);
  44
  45/*
  46 * An internal snapshot.
  47 *
  48 * You can only snapshot a quiesced origin i.e. one that is either
  49 * suspended or not instanced at all.
  50 */
  51int dm_pool_create_snap(struct dm_pool_metadata *pmd, dm_thin_id dev,
  52                        dm_thin_id origin);
  53
  54/*
  55 * Deletes a virtual device from the metadata.  It _is_ safe to call this
  56 * when that device is open.  Operations on that device will just start
  57 * failing.  You still need to call close() on the device.
  58 */
  59int dm_pool_delete_thin_device(struct dm_pool_metadata *pmd,
  60                               dm_thin_id dev);
  61
  62/*
  63 * Commits _all_ metadata changes: device creation, deletion, mapping
  64 * updates.
  65 */
  66int dm_pool_commit_metadata(struct dm_pool_metadata *pmd);
  67
  68/*
  69 * Set/get userspace transaction id.
  70 */
  71int dm_pool_set_metadata_transaction_id(struct dm_pool_metadata *pmd,
  72                                        uint64_t current_id,
  73                                        uint64_t new_id);
  74
  75int dm_pool_get_metadata_transaction_id(struct dm_pool_metadata *pmd,
  76                                        uint64_t *result);
  77
  78/*
  79 * Hold/get root for userspace transaction.
  80 */
  81int dm_pool_hold_metadata_root(struct dm_pool_metadata *pmd);
  82
  83int dm_pool_get_held_metadata_root(struct dm_pool_metadata *pmd,
  84                                   dm_block_t *result);
  85
  86/*
  87 * Actions on a single virtual device.
  88 */
  89
  90/*
  91 * Opening the same device more than once will fail with -EBUSY.
  92 */
  93int dm_pool_open_thin_device(struct dm_pool_metadata *pmd, dm_thin_id dev,
  94                             struct dm_thin_device **td);
  95
  96int dm_pool_close_thin_device(struct dm_thin_device *td);
  97
  98dm_thin_id dm_thin_dev_id(struct dm_thin_device *td);
  99
 100struct dm_thin_lookup_result {
 101        dm_block_t block;
 102        int shared;
 103};
 104
 105/*
 106 * Returns:
 107 *   -EWOULDBLOCK iff @can_block is set and would block.
 108 *   -ENODATA iff that mapping is not present.
 109 *   0 success
 110 */
 111int dm_thin_find_block(struct dm_thin_device *td, dm_block_t block,
 112                       int can_block, struct dm_thin_lookup_result *result);
 113
 114/*
 115 * Obtain an unused block.
 116 */
 117int dm_pool_alloc_data_block(struct dm_pool_metadata *pmd, dm_block_t *result);
 118
 119/*
 120 * Insert or remove block.
 121 */
 122int dm_thin_insert_block(struct dm_thin_device *td, dm_block_t block,
 123                         dm_block_t data_block);
 124
 125int dm_thin_remove_block(struct dm_thin_device *td, dm_block_t block);
 126
 127/*
 128 * Queries.
 129 */
 130int dm_thin_get_highest_mapped_block(struct dm_thin_device *td,
 131                                     dm_block_t *highest_mapped);
 132
 133int dm_thin_get_mapped_count(struct dm_thin_device *td, dm_block_t *result);
 134
 135int dm_pool_get_free_block_count(struct dm_pool_metadata *pmd,
 136                                 dm_block_t *result);
 137
 138int dm_pool_get_free_metadata_block_count(struct dm_pool_metadata *pmd,
 139                                          dm_block_t *result);
 140
 141int dm_pool_get_metadata_dev_size(struct dm_pool_metadata *pmd,
 142                                  dm_block_t *result);
 143
 144int dm_pool_get_data_block_size(struct dm_pool_metadata *pmd, sector_t *result);
 145
 146int dm_pool_get_data_dev_size(struct dm_pool_metadata *pmd, dm_block_t *result);
 147
 148/*
 149 * Returns -ENOSPC if the new size is too small and already allocated
 150 * blocks would be lost.
 151 */
 152int dm_pool_resize_data_dev(struct dm_pool_metadata *pmd, dm_block_t new_size);
 153
 154/*----------------------------------------------------------------*/
 155
 156#endif
 157