xref: /spdk/doc/lvol.md (revision cc6920a4763d4b9a43aa40583c8397d8f14fa100)
1# Logical Volumes {#logical_volumes}
2
3The Logical Volumes library is a flexible storage space management system. It provides creating and managing virtual
4block devices with variable size. The SPDK Logical Volume library is built on top of @ref blob.
5
6## Terminology {#lvol_terminology}
7
8### Logical volume store {#lvs}
9
10* Shorthand:  lvolstore, lvs
11* Type name:  struct spdk_lvol_store
12
13A logical volume store uses the super blob feature of blobstore to hold uuid (and in future other metadata).
14Blobstore types are implemented in blobstore itself, and saved on disk. An lvolstore will generate a UUID on
15creation, so that it can be uniquely identified from other lvolstores.
16By default when creating lvol store data region is unmapped. Optional --clear-method parameter can be passed
17on creation to change that behavior to writing zeroes or performing no operation.
18
19### Logical volume {#lvol}
20
21* Shorthand: lvol
22* Type name: struct spdk_lvol
23
24A logical volume is implemented as an SPDK blob created from an lvolstore. An lvol is uniquely identified by
25its UUID. Lvol additional can have alias name.
26
27### Logical volume block device {#lvol_bdev}
28
29* Shorthand: lvol_bdev
30* Type name: struct spdk_lvol_bdev
31
32Representation of an SPDK block device (spdk_bdev) with an lvol implementation.
33A logical volume block device translates generic SPDK block device I/O (spdk_bdev_io) operations into the
34equivalent SPDK blob operations. Combination of lvol name and lvolstore name gives lvol_bdev alias name in
35a form "lvs_name/lvol_name". block_size of the created bdev is always 4096, due to blobstore page size.
36Cluster_size is configurable by parameter. Size of the new bdev will be rounded up to nearest multiple of
37cluster_size. By default lvol bdevs claim part of lvol store equal to their set size. When thin provision
38option is enabled, no space is taken from lvol store until data is written to lvol bdev.
39By default when deleting lvol bdev or resizing down, allocated clusters are unmapped. Optional --clear-method
40parameter can be passed on creation to change that behavior to writing zeroes or performing no operation.
41
42### Thin provisioning {#lvol_thin_provisioning}
43
44Thin provisioned lvols rely on dynamic cluster allocation (e.g. when the first write operation on a cluster is performed), only space
45required to store data is used and unallocated clusters are obtained from underlying device (e.g. zeroes_dev).
46
47Sample write operations of thin provisioned blob are shown on the diagram below:
48
49![Writing clusters to the thin provisioned blob](lvol_thin_provisioning_write.svg)
50
51Sample read operations and the structure of thin provisioned blob are shown on the diagram below:
52
53![Reading clusters from thin provisioned blob](lvol_thin_provisioning.svg)
54
55### Snapshots and clone {#lvol_snapshots}
56
57Logical volumes support snapshots and clones functionality. User may at any given time create snapshot of existing
58logical volume to save a backup of current volume state. When creating snapshot original volume becomes thin provisioned
59and saves only incremental differences from its underlying snapshot. This means that every read from unallocated cluster
60is actually a read from the snapshot and every write to unallocated cluster triggers new cluster allocation and data copy
61from corresponding cluster in snapshot to the new cluster in logical volume before the actual write occurs.
62
63The read operation is performed as shown in the diagram below:
64![Reading cluster from clone](lvol_clone_snapshot_read.svg)
65
66The write operation is performed as shown in the diagram below:
67![Writing cluster to the clone](lvol_clone_snapshot_write.svg)
68
69User may also create clone of existing snapshot that will be thin provisioned and it will behave in the same way as logical volume
70from which snapshot is created. There is no limit of clones and snapshots that may be created as long as there is enough space on
71logical volume store. Snapshots are read only. Clones may be created only from snapshots or read only logical volumes.
72
73A snapshot can be removed only if there is a single clone on top of it. The relation chain will be updated accordingly.
74The cluster map of clone and snapshot will be merged and entries for unallocated clusters in the clone will be updated with
75addresses from the snapshot cluster map. The entire operation modifies metadata only - no data is copied during this process.
76
77### Inflation {#lvol_inflation}
78
79Blobs can be inflated to copy data from backing devices (e.g. snapshots) and allocate all remaining clusters. As a result of this
80operation all dependencies for the blob are removed.
81
82![Removing backing blob and bdevs relations using inflate call](lvol_inflate_clone_snapshot.svg)
83
84### Decoupling {#lvol_decoupling}
85
86Blobs can be decoupled from their parent blob by copying data from backing devices (e.g. snapshots) for all allocated clusters.
87Remaining unallocated clusters are kept thin provisioned.
88Note: When decouple is performed, only single dependency is removed. To remove all dependencies in a chain of blobs depending
89on each other, multiple calls need to be issued.
90
91## Configuring Logical Volumes
92
93There is no static configuration available for logical volumes. All configuration is done trough RPC. Information about
94logical volumes is kept on block devices.
95
96## RPC overview {#lvol_rpc}
97
98RPC regarding lvolstore:
99
100```bash
101bdev_lvol_create_lvstore [-h] [-c CLUSTER_SZ] bdev_name lvs_name
102    Constructs lvolstore on specified bdev with specified name. During
103    construction bdev is unmapped at initialization and all data is
104    erased. Then original bdev is claimed by
105    SPDK, but no additional spdk bdevs are created.
106    Returns uuid of created lvolstore.
107    Optional parameters:
108    -h  show help
109    -c  CLUSTER_SZ Specifies the size of cluster. By default its 4MiB.
110    --clear-method specify data region clear method "none", "unmap" (default), "write_zeroes"
111bdev_lvol_delete_lvstore [-h] [-u UUID] [-l LVS_NAME]
112    Destroy lvolstore on specified bdev. Removes lvolstore along with lvols on
113    it. User can identify lvol store by UUID or its name. Note that destroying
114    lvolstore requires using this call, while deleting single lvol requires
115    using bdev_lvol_delete rpc call.
116    optional arguments:
117    -h, --help  show help
118bdev_lvol_get_lvstores [-h] [-u UUID] [-l LVS_NAME]
119    Display current logical volume store list
120    optional arguments:
121    -h, --help  show help
122    -u UUID, --uuid UUID  show details of specified lvol store
123    -l LVS_NAME, --lvs_name LVS_NAME  show details of specified lvol store
124bdev_lvol_rename_lvstore [-h] old_name new_name
125    Change logical volume store name
126    optional arguments:
127    -h, --help  show this help message and exit
128```
129
130RPC regarding lvol and spdk bdev:
131
132```bash
133bdev_lvol_create [-h] [-u UUID] [-l LVS_NAME] [-t] [-c CLEAR_METHOD] lvol_name size
134    Creates lvol with specified size and name on lvolstore specified by its uuid
135    or name. Then constructs spdk bdev on top of that lvol and presents it as spdk bdev.
136    User may use -t switch to create thin provisioned lvol.
137    Returns the name of new spdk bdev
138    optional arguments:
139    -h, --help  show help
140    -c, --clear-method specify data clusters clear method "none", "unmap" (default), "write_zeroes"
141bdev_get_bdevs [-h] [-b NAME]
142    User can view created bdevs using this call including those created on top of lvols.
143    optional arguments:
144    -h, --help  show help
145    -b NAME, --name NAME  Name of the block device. Example: Nvme0n1
146bdev_lvol_delete [-h] bdev_name
147    Deletes a logical volume previously created by bdev_lvol_create.
148    optional arguments:
149    -h, --help  show help
150bdev_lvol_snapshot [-h] lvol_name snapshot_name
151    Create a snapshot with snapshot_name of a given lvol bdev.
152    optional arguments:
153    -h, --help  show help
154bdev_lvol_clone [-h] snapshot_name clone_name
155    Create a clone with clone_name of a given lvol snapshot.
156    optional arguments:
157    -h, --help  show help
158bdev_lvol_rename [-h] old_name new_name
159    Change lvol bdev name
160    optional arguments:
161    -h, --help  show help
162bdev_lvol_resize [-h] name size
163    Resize existing lvol bdev
164    optional arguments:
165    -h, --help  show help
166bdev_lvol_set_read_only [-h] name
167    Mark lvol bdev as read only
168    optional arguments:
169    -h, --help  show help
170bdev_lvol_inflate [-h] name
171    Inflate lvol bdev
172    optional arguments:
173    -h, --help  show help
174bdev_lvol_decouple_parent [-h] name
175    Decouple parent of a logical volume
176    optional arguments:
177    -h, --help  show help
178```
179