xref: /spdk/doc/lvol.md (revision 34edd9f1bf5fda4c987f4500ddc3c9f50be32e7d)
185377087SDaniel Verkamp# Logical Volumes {#logical_volumes}
25226e908SPiotr Pelplinski
312fcbc9bSwawrykThe Logical Volumes library is a flexible storage space management system. It provides creating and managing virtual
412fcbc9bSwawrykblock devices with variable size. The SPDK Logical Volume library is built on top of @ref blob.
55226e908SPiotr Pelplinski
61e1fd9acSwawryk## Terminology {#lvol_terminology}
75226e908SPiotr Pelplinski
81e1fd9acSwawryk### Logical volume store {#lvs}
95226e908SPiotr Pelplinski
10d1734518SPiotr Pelplinski* Shorthand:  lvolstore, lvs
11d1734518SPiotr Pelplinski* Type name:  struct spdk_lvol_store
125226e908SPiotr Pelplinski
1312fcbc9bSwawrykA logical volume store uses the super blob feature of blobstore to hold uuid (and in future other metadata).
1412fcbc9bSwawrykBlobstore types are implemented in blobstore itself, and saved on disk. An lvolstore will generate a UUID on
1512fcbc9bSwawrykcreation, so that it can be uniquely identified from other lvolstores.
1612fcbc9bSwawrykBy default when creating lvol store data region is unmapped. Optional --clear-method parameter can be passed
1712fcbc9bSwawrykon creation to change that behavior to writing zeroes or performing no operation.
185226e908SPiotr Pelplinski
191e1fd9acSwawryk### Logical volume {#lvol}
205226e908SPiotr Pelplinski
21d1734518SPiotr Pelplinski* Shorthand: lvol
22d1734518SPiotr Pelplinski* Type name: struct spdk_lvol
235226e908SPiotr Pelplinski
2412fcbc9bSwawrykA logical volume is implemented as an SPDK blob created from an lvolstore. An lvol is uniquely identified by
2512fcbc9bSwawrykits UUID. Lvol additional can have alias name.
265226e908SPiotr Pelplinski
271e1fd9acSwawryk### Logical volume block device {#lvol_bdev}
28d1734518SPiotr Pelplinski
29d1734518SPiotr Pelplinski* Shorthand: lvol_bdev
30d1734518SPiotr Pelplinski* Type name: struct spdk_lvol_bdev
31d1734518SPiotr Pelplinski
32d1734518SPiotr PelplinskiRepresentation of an SPDK block device (spdk_bdev) with an lvol implementation.
3312fcbc9bSwawrykA logical volume block device translates generic SPDK block device I/O (spdk_bdev_io) operations into the
3412fcbc9bSwawrykequivalent SPDK blob operations. Combination of lvol name and lvolstore name gives lvol_bdev alias name in
3512fcbc9bSwawryka form "lvs_name/lvol_name". block_size of the created bdev is always 4096, due to blobstore page size.
3612fcbc9bSwawrykCluster_size is configurable by parameter. Size of the new bdev will be rounded up to nearest multiple of
3712fcbc9bSwawrykcluster_size. By default lvol bdevs claim part of lvol store equal to their set size. When thin provision
3812fcbc9bSwawrykoption is enabled, no space is taken from lvol store until data is written to lvol bdev.
3912fcbc9bSwawrykBy default when deleting lvol bdev or resizing down, allocated clusters are unmapped. Optional --clear-method
4012fcbc9bSwawrykparameter can be passed on creation to change that behavior to writing zeroes or performing no operation.
41d1734518SPiotr Pelplinski
421e1fd9acSwawryk### Thin provisioning {#lvol_thin_provisioning}
43ac34a2dfSTomasz Kulasek
4412fcbc9bSwawrykThin provisioned lvols rely on dynamic cluster allocation (e.g. when the first write operation on a cluster is performed), only space
4512fcbc9bSwawrykrequired to store data is used and unallocated clusters are obtained from underlying device (e.g. zeroes_dev).
46ac34a2dfSTomasz Kulasek
47ac34a2dfSTomasz KulasekSample write operations of thin provisioned blob are shown on the diagram below:
48ac34a2dfSTomasz Kulasek
49ac34a2dfSTomasz Kulasek![Writing clusters to the thin provisioned blob](lvol_thin_provisioning_write.svg)
50ac34a2dfSTomasz Kulasek
51ac34a2dfSTomasz KulasekSample read operations and the structure of thin provisioned blob are shown on the diagram below:
52ac34a2dfSTomasz Kulasek
53ac34a2dfSTomasz Kulasek![Reading clusters from thin provisioned blob](lvol_thin_provisioning.svg)
54ac34a2dfSTomasz Kulasek
551e1fd9acSwawryk### Snapshots and clone {#lvol_snapshots}
56897bb3acSMaciej Szwed
5712fcbc9bSwawrykLogical volumes support snapshots and clones functionality. User may at any given time create snapshot of existing
5812fcbc9bSwawryklogical volume to save a backup of current volume state. When creating snapshot original volume becomes thin provisioned
5912fcbc9bSwawrykand saves only incremental differences from its underlying snapshot. This means that every read from unallocated cluster
6012fcbc9bSwawrykis actually a read from the snapshot and every write to unallocated cluster triggers new cluster allocation and data copy
6112fcbc9bSwawrykfrom corresponding cluster in snapshot to the new cluster in logical volume before the actual write occurs.
62c9476f1bSTomasz Kulasek
63c9476f1bSTomasz KulasekThe read operation is performed as shown in the diagram below:
64c9476f1bSTomasz Kulasek![Reading cluster from clone](lvol_clone_snapshot_read.svg)
65c9476f1bSTomasz Kulasek
66c9476f1bSTomasz KulasekThe write operation is performed as shown in the diagram below:
67c9476f1bSTomasz Kulasek![Writing cluster to the clone](lvol_clone_snapshot_write.svg)
68c9476f1bSTomasz Kulasek
6912fcbc9bSwawrykUser may also create clone of existing snapshot that will be thin provisioned and it will behave in the same way as logical volume
7012fcbc9bSwawrykfrom which snapshot is created. There is no limit of clones and snapshots that may be created as long as there is enough space on
7112fcbc9bSwawryklogical volume store. Snapshots are read only. Clones may be created only from snapshots or read only logical volumes.
72897bb3acSMaciej Szwed
7312fcbc9bSwawrykA snapshot can be removed only if there is a single clone on top of it. The relation chain will be updated accordingly.
7412fcbc9bSwawrykThe cluster map of clone and snapshot will be merged and entries for unallocated clusters in the clone will be updated with
7512fcbc9bSwawrykaddresses from the snapshot cluster map. The entire operation modifies metadata only - no data is copied during this process.
769622c1cbSMaciej Szwed
77a67e0eb3SMike Gerdts### External Snapshots
78a67e0eb3SMike Gerdts
79a67e0eb3SMike GerdtsWith the external snapshots feature, clones can be made of any bdev. These clones are commonly called *esnap clones*.
80a67e0eb3SMike GerdtsEsnap clones work very similarly to thin provisioning. Rather than the back device being an zeroes device, the external snapshot
81a67e0eb3SMike Gerdtsbdev is used as the back device.
82a67e0eb3SMike Gerdts
83a67e0eb3SMike Gerdts![Clone of External Snapshot](lvol_esnap_clone.svg)
84a67e0eb3SMike Gerdts
85a67e0eb3SMike GerdtsA bdev that is used as an external snapshot cannot be opened for writing by anything else so long as an esnap clone exists.
86a67e0eb3SMike Gerdts
87a67e0eb3SMike GerdtsA bdev may have multiple esnap clones and esnap clones can themselves be snapshotted and cloned.
88a67e0eb3SMike Gerdts
891e1fd9acSwawryk### Inflation {#lvol_inflation}
908ee51221STomasz Kulasek
9112fcbc9bSwawrykBlobs can be inflated to copy data from backing devices (e.g. snapshots) and allocate all remaining clusters. As a result of this
9212fcbc9bSwawrykoperation all dependencies for the blob are removed.
938ee51221STomasz Kulasek
948ee51221STomasz Kulasek![Removing backing blob and bdevs relations using inflate call](lvol_inflate_clone_snapshot.svg)
958ee51221STomasz Kulasek
961e1fd9acSwawryk### Decoupling {#lvol_decoupling}
97c053afc0STomasz Zawadzki
9812fcbc9bSwawrykBlobs can be decoupled from their parent blob by copying data from backing devices (e.g. snapshots) for all allocated clusters.
9912fcbc9bSwawrykRemaining unallocated clusters are kept thin provisioned.
10012fcbc9bSwawrykNote: When decouple is performed, only single dependency is removed. To remove all dependencies in a chain of blobs depending
10112fcbc9bSwawrykon each other, multiple calls need to be issued.
102c053afc0STomasz Zawadzki
1031e1fd9acSwawryk## Configuring Logical Volumes
104d1734518SPiotr Pelplinski
105*34edd9f1SKamil GodzwonThere is no static configuration available for logical volumes. All configuration is done through RPC. Information about
10612fcbc9bSwawryklogical volumes is kept on block devices.
107d1734518SPiotr Pelplinski
1081e1fd9acSwawryk## RPC overview {#lvol_rpc}
109d1734518SPiotr Pelplinski
110d1734518SPiotr PelplinskiRPC regarding lvolstore:
111d1734518SPiotr Pelplinski
11263ee471bSMaciej Wawryk```bash
113de756853SMaciej Wawrykbdev_lvol_create_lvstore [-h] [-c CLUSTER_SZ] bdev_name lvs_name
114897bb3acSMaciej Szwed    Constructs lvolstore on specified bdev with specified name. During
115897bb3acSMaciej Szwed    construction bdev is unmapped at initialization and all data is
116897bb3acSMaciej Szwed    erased. Then original bdev is claimed by
117d1734518SPiotr Pelplinski    SPDK, but no additional spdk bdevs are created.
118d1734518SPiotr Pelplinski    Returns uuid of created lvolstore.
1191f813ec3SChen Wang    Optional parameters:
120d1734518SPiotr Pelplinski    -h  show help
121cb5178eaSMaciej Szwed    -c  CLUSTER_SZ Specifies the size of cluster. By default its 4MiB.
122ca87060dSTomasz Zawadzki    --clear-method specify data region clear method "none", "unmap" (default), "write_zeroes"
1234c049618SMaciej Wawrykbdev_lvol_delete_lvstore [-h] [-u UUID] [-l LVS_NAME]
124d1734518SPiotr Pelplinski    Destroy lvolstore on specified bdev. Removes lvolstore along with lvols on
125897bb3acSMaciej Szwed    it. User can identify lvol store by UUID or its name. Note that destroying
126897bb3acSMaciej Szwed    lvolstore requires using this call, while deleting single lvol requires
127b5fdf4ecSMaciej Wawryk    using bdev_lvol_delete rpc call.
128d1734518SPiotr Pelplinski    optional arguments:
129d1734518SPiotr Pelplinski    -h, --help  show help
1300b3f378fSMaciej Wawrykbdev_lvol_get_lvstores [-h] [-u UUID] [-l LVS_NAME]
131d1734518SPiotr Pelplinski    Display current logical volume store list
132d1734518SPiotr Pelplinski    optional arguments:
133d1734518SPiotr Pelplinski    -h, --help  show help
134897bb3acSMaciej Szwed    -u UUID, --uuid UUID  show details of specified lvol store
135897bb3acSMaciej Szwed    -l LVS_NAME, --lvs_name LVS_NAME  show details of specified lvol store
13690e4ae5dSMaciej Wawrykbdev_lvol_rename_lvstore [-h] old_name new_name
137897bb3acSMaciej Szwed    Change logical volume store name
138897bb3acSMaciej Szwed    optional arguments:
139897bb3acSMaciej Szwed    -h, --help  show this help message and exit
140d1734518SPiotr Pelplinski```
141d1734518SPiotr Pelplinski
142d1734518SPiotr PelplinskiRPC regarding lvol and spdk bdev:
143d1734518SPiotr Pelplinski
14463ee471bSMaciej Wawryk```bash
145c57cd922SMaciej Wawrykbdev_lvol_create [-h] [-u UUID] [-l LVS_NAME] [-t] [-c CLEAR_METHOD] lvol_name size
146897bb3acSMaciej Szwed    Creates lvol with specified size and name on lvolstore specified by its uuid
147897bb3acSMaciej Szwed    or name. Then constructs spdk bdev on top of that lvol and presents it as spdk bdev.
148897bb3acSMaciej Szwed    User may use -t switch to create thin provisioned lvol.
149d1734518SPiotr Pelplinski    Returns the name of new spdk bdev
150897bb3acSMaciej Szwed    optional arguments:
151897bb3acSMaciej Szwed    -h, --help  show help
1520c0d9d4eSTomasz Zawadzki    -c, --clear-method specify data clusters clear method "none", "unmap" (default), "write_zeroes"
153f3c14b8dSMike Gerdtsbdev_lvol_get_lvols [-h] [-u LVS_UUID] [-l LVS_NAME]
154f3c14b8dSMike Gerdts    Display logical volume list, including those that do not have associated bdevs.
155f3c14b8dSMike Gerdts    optional arguments:
156f3c14b8dSMike Gerdts    -h, --help  show help
157f3c14b8dSMike Gerdts    -u LVS_UUID, --lvs_uuid UUID  show volumes only in the specified lvol store
158f3c14b8dSMike Gerdts    -l LVS_NAME, --lvs_name LVS_NAME  show volumes only in the specified lvol store
1592c49e910SMaciej Wawrykbdev_get_bdevs [-h] [-b NAME]
160d1734518SPiotr Pelplinski    User can view created bdevs using this call including those created on top of lvols.
161d1734518SPiotr Pelplinski    optional arguments:
162d1734518SPiotr Pelplinski    -h, --help  show help
163d1734518SPiotr Pelplinski    -b NAME, --name NAME  Name of the block device. Example: Nvme0n1
164b5fdf4ecSMaciej Wawrykbdev_lvol_delete [-h] bdev_name
165c57cd922SMaciej Wawryk    Deletes a logical volume previously created by bdev_lvol_create.
166d1734518SPiotr Pelplinski    optional arguments:
167d1734518SPiotr Pelplinski    -h, --help  show help
168f5cf8ea1SMaciej Wawrykbdev_lvol_snapshot [-h] lvol_name snapshot_name
169897bb3acSMaciej Szwed    Create a snapshot with snapshot_name of a given lvol bdev.
170897bb3acSMaciej Szwed    optional arguments:
171897bb3acSMaciej Szwed    -h, --help  show help
172827b2667SMaciej Wawrykbdev_lvol_clone [-h] snapshot_name clone_name
173897bb3acSMaciej Szwed    Create a clone with clone_name of a given lvol snapshot.
174897bb3acSMaciej Szwed    optional arguments:
175897bb3acSMaciej Szwed    -h, --help  show help
176a67e0eb3SMike Gerdtsbdev_lvol_clone_bdev [-h] bdev_name_or_uuid lvs_name clone_name
177a67e0eb3SMike Gerdts    Create a clone with clone_name of a bdev. The bdev must not be an lvol in the lvs_name lvstore.
178a67e0eb3SMike Gerdts    optional arguments:
179a67e0eb3SMike Gerdts    -h, --help  show help
1800ce883ceSMaciej Wawrykbdev_lvol_rename [-h] old_name new_name
181897bb3acSMaciej Szwed    Change lvol bdev name
182897bb3acSMaciej Szwed    optional arguments:
183897bb3acSMaciej Szwed    -h, --help  show help
184c2d85bb2SMaciej Wawrykbdev_lvol_resize [-h] name size
185897bb3acSMaciej Szwed    Resize existing lvol bdev
186897bb3acSMaciej Szwed    optional arguments:
187897bb3acSMaciej Szwed    -h, --help  show help
188b7ad0bd0SMaciej Wawrykbdev_lvol_set_read_only [-h] name
1893bb815aeSTomasz Zawadzki    Mark lvol bdev as read only
1903bb815aeSTomasz Zawadzki    optional arguments:
1913bb815aeSTomasz Zawadzki    -h, --help  show help
1927a294f4cSMaciej Wawrykbdev_lvol_inflate [-h] name
1938ee51221STomasz Kulasek    Inflate lvol bdev
1948ee51221STomasz Kulasek    optional arguments:
1958ee51221STomasz Kulasek    -h, --help  show help
196975efa2aSMaciej Wawrykbdev_lvol_decouple_parent [-h] name
197c053afc0STomasz Zawadzki    Decouple parent of a logical volume
198c053afc0STomasz Zawadzki    optional arguments:
199c053afc0STomasz Zawadzki    -h, --help  show help
200b269b0edSDamiano Ciprianibdev_lvol_start_shallow_copy [-h] src_lvol_name dst_bdev_name
201b269b0edSDamiano Cipriani    Make a shallow copy of lvol over a given bdev
202b269b0edSDamiano Cipriani    This RPC starts the operation and returns an identifier that can be used to query the status
203b269b0edSDamiano Cipriani    of the operation with the RPC bdev_lvol_check_shallow_copy.
204b269b0edSDamiano Cipriani    optional arguments:
205b269b0edSDamiano Cipriani    -h, --help  show help
206b269b0edSDamiano Ciprianibdev_lvol_check_shallow_copy [-h] operation_id
207b269b0edSDamiano Cipriani    Get shallow copy status
208b269b0edSDamiano Cipriani    optional arguments:
209b269b0edSDamiano Cipriani    -h, --help  show help
2102acfb846SDamiano Ciprianibdev_lvol_set_parent [-h] lvol_name snapshot_name
2112acfb846SDamiano Cipriani    Set the parent snapshot of a lvol
2122acfb846SDamiano Cipriani    optional arguments:
2132acfb846SDamiano Cipriani    -h, --help  show help
2142acfb846SDamiano Ciprianibdev_lvol_set_parent_bdev lvol_name esnap_name
2152acfb846SDamiano Cipriani    Set the parent external snapshot of a lvol
2162acfb846SDamiano Cipriani    optional arguments:
2172acfb846SDamiano Cipriani    -h, --help  show help
218d1734518SPiotr Pelplinski```
219