-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdm-snap-mv.txt
253 lines (185 loc) · 7.39 KB
/
dm-snap-mv.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
Device-mapper snapshot multi-version
====================================
what is dm-snap-mv
-------------------
The dm-snap-mv is a target module for device-mapper, which can take
multiple snapshots against an existing block device(origin device).
All snapshots are saved in an independent block device(COW device).
The copy-on-write is used, so only diff-data will be saved in the COW device.
features
--------
1. snapshot of origin
2. snapshot of snapshot
3. instant snapshot creation and deletion
4. origin and snapshots are concurrent readable/writable
5. rollback snapshot to origin
6. multiple origin devices share a COW device
7. multiple COW devices are supported
diagram
-------
+---------------------+ +---------------+ +--------------+
read <--| |----- | | |
| origin dm_dev | | origin_dev | COW | |
write ---| |----> |-----> snapshot-1 |
+---------------------+ +--|------------+ | ... |
| | ... |
+---------------------+ +--|------------------+ ... |
read <--| |-------?- snapshot-N |
| snapshot-X dm_dev | | cow_dev |
write ---| |----> |
+---------------------+ +------------------------------------+
dm_dev: device-mapper device, created by "dmsetup create ..."
COW: copy-on-write
usage with dmsetup
------------------
dmsetup create <dm_dev> --table <logical_start_sector> <num_sectors> dm-snap-mv <target_args>
dmsetup message <dm_dev> <sector> <message-args>
dmsetup status <dm_dev>
<dm_dev>
device-mapper device name
<logical_start_sector>
0 is ok
<num_sectors>
the size of <origin_dev> in sector
<sector>
0 is ok
<target-args>
co <origin_dev> <cow_dev> [-i <origin_id>] [-b [-F|-f [-c <chunk_size>]]]
cs <origin_dev> <cow_dev> <tag> [-i <origin_id>]
<message-args>
so [-m <memo>]
ss <tag> [-m <memo>]
do
ds <tag>
rs <tag> [-b]
For more info about dmsetup, refer to 'man 8 dmsetup'
syntax in <target-args> and <message-args>:
commands:
co Create origin dm_dev
cs Create snapshot dm_dev
so take a snapshot of origin
ss take a snapshot of snapshot
do delete(unbind) origin device from COW device
ds delete snapshot
rs rollback snapshot to origin
positional arguments:
<origin_dev> origin device
<cow_dev> COW(copy-on-write) device
<tag> snapshot tag
options:
-i <origin_id> the unique identity of origin deivce.
COW device uses it to distinguish origin devices.
if not specified, the <origin_dev> is used as default value.
-b bind origin device to COW device.
specify this option when origin device first used with COW device.
-f format COW device.
specify this option when COW device first used.
-F force format COW device.
-c <chunk_size> chunk size of COW device.
the unit is 4KB-page
-m <memo> memo
-b rollback snapshot in background
usage with dms
--------------
dms is a wrap of dmsetup written in python.
dms c|create <dm_dev> <origin_dev> <cow_dev> [-b [-f|-F [-c <chunk_size>]]]
Create dm-device of origin
-b: Bind origin device to COW device
-f: Format COW device
-F: Force format COW device
-c: Specify the chunk size of COW device in 4KB-page
dms c|create <dm_dev> <origin_dev> <cow_dev> <tag>
Create dm-device of snapshot-<tag>
dms r|remove <dm_dev>
Remove dm-device
dms s|snapshot <dm_dev> [-m <memo>]
Take a snapshot of origin
dms s|snapshot <dm_dev> <tag> [-m <memo>]
Take a snapshot of snapshot-<tag>
dms d|delete <dm_dev>
Delete(unbind) origin device from COW device, remove the dm-device
All snapshots should be deleted first
dms d|delete <dm_dev> <tag>
Delete snapshot-<tag>
dms b|rollback <dm_dev> <tag> [-b]
Rollback snapshot to origin
dms l|list [<dm_dev>]
List all snapshots
Usage examples
--------------
origin device: sdb1 COW device: sdc1
# Init COW device, bind origin device to it. Create orig dm_dev
# dms create orig sdb1 sdc1 -bF
# mount /dev/mapper/orig /mnt/orig
# touch /mnt/orig/this-is-orig
# ll /mnt/orig/
-rw-r--r-- 1 root root 0 2010-10-19 21:39 this-is-orig
# Take a snapshot of origin. Create snap1 dm_dev
# dms snapshot orig -m snap1
# dms create snap1 sdb1 sdc1 1
# mount /dev/mapper/snap1 /mnt/snap1/
# touch /mnt/snap1/this-is-snap1
# ll /mnt/snap1/
-rw-r--r-- 1 root root 0 2010-10-19 21:39 this-is-orig
-rw-r--r-- 1 root root 0 2010-10-19 21:42 this-is-snap1
# Take a snapshot of snap1. Create snap2 dm_dev
# dms snapshot orig 1 -m snap2
# dms create snap2 sdb1 sdc1 2
# mount /dev/mapper/snap2 /mnt/snap2/
# touch /mnt/snap2/this-is-snap2
# ll /mnt/snap2/
-rw-r--r-- 1 root root 0 2010-10-19 21:39 this-is-orig
-rw-r--r-- 1 root root 0 2010-10-19 21:42 this-is-snap1
-rw-r--r-- 1 root root 0 2010-10-19 21:43 this-is-snap2
# List all snapshots
# dms list
origin-device : sdb1 (8:17)
cow-device : sdc1 (8:33)
chunk-size : 1 page(s)
used-versions : 0% (3/640)
used-chunks : 0% (946/7865817)
cow-status : valid
cleaning : no
rollbacking : no
YYYY/MM/DD HH:MM:SS Tag R Chunks DM_Dev Memo
2010/10/19 21:38:37 0 . 0 orig "ORIGIN"
2010/10/19 21:41:28 1 . 5 snap1 "snap1"
2010/10/19 21:42:57 2 . 5 snap2 "snap2"
# Rollback snap2 to origin
# umount /mnt/orig
# dms remove orig
# dms rollback snap2 2
# dms create orig sdb1 sdc1
# mount /dev/mapper/orig /mnt/orig
# touch /mnt/orig/this-is-orig-after-rollback
# ll /mnt/orig
-rw-r--r-- 1 root root 0 2010-10-19 21:39 this-is-orig
-rw-r--r-- 1 root root 0 2010-10-19 22:04 this-is-orig-after-rollback
-rw-r--r-- 1 root root 0 2010-10-19 21:42 this-is-snap1
-rw-r--r-- 1 root root 0 2010-10-19 21:43 this-is-snap2
# Stop dm-snap-mv. Take a look at origin device sdb2
# umount /mnt/orig /mnt/snap1 /mnt/snap2
# dmsetup remove_all
# mount /dev/sdb1 /mnt/
# ll /mnt/
-rw-r--r-- 1 root root 0 2010-10-19 21:39 this-is-orig
-rw-r--r-- 1 root root 0 2010-10-19 22:04 this-is-orig-after-rollback
-rw-r--r-- 1 root root 0 2010-10-19 21:42 this-is-snap1
-rw-r--r-- 1 root root 0 2010-10-19 21:43 this-is-snap2
suggestion
----------
1. To get better performance, pick origin_dev and cow_dev from
different physical harddisks and controllers.
thanks
------
Inspired by the article "Versioned pointers: a new method of representing
snapshots" from Daniel Phillips. (http://lwn.net/Articles/288896/)
chage log
---------
2010-10-06
1. First verison 1.0 release
2010-10-20
1. Version 1.1
2. remove the dependence on block-size-kernel.patch by set_blocksize(cow, 4096)
3. backport for Fedora kernel 2.6.33
4. fixed a memory alloc bug