Skip to contentSkip to conversation

Snapshots

DISCUSSION Phillip Susi 2 participants 6 messages Dec 18, 2007 – Dec 22, 2007 Device mapper

lore
Share & tools
lore
#0 lore raw

I have been playing around with the snapshot target with dmsetup, and I can set up a snapshot that diverts writes to a backing file, so that modifications to the snapshot device are discarded when I remove the snapshot device and go back to using the origin device. What I can't figure out is how to keep the origin device mounted and have the snapshot device appear to contain the origin's data at the time it was created, even though the origin continues to be modified.

I thought one of the main ideas of the snapshot was to be able to backup a consistent filesystem image even though the filesystem continues to be written to, but it seems that having the origin device mounted gets an exclusive lock on it so that the snapshot device can not be targeted at it, so how do you do this?

#1 lore raw
Quoted 8 lines · Phillip Susi

I have been playing around with the snapshot target with dmsetup, and I can set up a snapshot that diverts writes to a backing file, so that modifications to the snapshot device are discarded when I remove the snapshot device and go back to using the origin device. What I can't figure out is how to keep the origin device mounted and have the snapshot device appear to contain the origin's data at the time it was created, even though the origin continues to be modified.

Quoted 5 lines

I thought one of the main ideas of the snapshot was to be able to backup a consistent filesystem image even though the filesystem continues to be written to, but it seems that having the origin device mounted gets an exclusive lock on it so that the snapshot device can not be targeted at it, so how do you do this?

LVM2 does it by putting a linear mapping on top of the origin device.

I'm not sure if this meets your requirement, but something like this:

1. Put a linear mapping on the origin
(/dev/sdb2 is origin in this example)

# echo "0 $(blockdev --getsz /dev/sdb2) linear /dev/sdb2 0" | dmsetup create sdb2

2. Use the device as you like..

# mkfs.ext3 /dev/mapper/sdb2
# mount /dev/mapper/sdb2 /mnt/1
..

3. Insert a snapshot-origin map *below* the dm-linear

# dmsetup suspend sdb2
# echo $(dmsetup table sdb2) | dmsetup create sdb2-origin
# echo "0 $(blockdev --getsz /dev/mapper/sdb2-origin) snapshot-origin /dev/mapper/sdb2-origin" | dmsetup load sdb2
# dmsetup resume sdb2

4. Create any number of snapshots for the origin map

# echo "0 $(blockdev --getsz /dev/mapper/sdb2) snapshot /dev/mapper/sdb2-origin /dev/sdc2 P 8 " | dmsetup create
sdb2-snapshot
# dmsetup ls --tree
sdb2 (253:19)
 `-sdb2-origin (253:21)
    `- (8:18)
sdb2-snapshot1 (253:20)
 |- (8:34)
 `-sdb2-origin (253:21)
    `- (8:18)
# dmsetup table | grep sdb
sdb2: 0 15615180 linear 253:21 0
sdb2-snapshot1: 0 15615180 snapshot 253:21 8:34 P 8
sdb2-origin: 0 15615180 linear 8:18 0

If dm can insert a mapping *below* the device, you can do without the dm-linear layer. But there's no such feature yet.

Thanks,

Signature · 1 line
Jun'ichi Nomura, NEC Corporation of America
#2 lore raw
Quoted 1 line · Jun'ichi Nomura

LVM2 does it by putting a linear mapping on top of the origin device.

How does this work? I'm trying to figure out the whole locking business and it seems that mounting the device, or using it as a target in a dm table place an exclusive lock on the device, so how can you add a linear mapping to the origin device, if it is already used as a target in the snapshot device, and thus locked?

#3 lore raw
Quoted 8 lines · Phillip Susi
Quoted 1 line · Jun'ichi Nomura

LVM2 does it by putting a linear mapping on top of the origin device.

How does this work? I'm trying to figure out the whole locking business and it seems that mounting the device, or using it as a target in a dm table place an exclusive lock on the device, so how can you add a linear mapping to the origin device, if it is already used as a target in the snapshot device, and thus locked?

So, you have to put the linear mapping *before* that. Then, the top-level block device will be locked but you can still change the underlying mappings.

Thanks,

Signature · 1 line
Jun'ichi Nomura, NEC Corporation of America
#4 lore raw
Quoted 3 lines · Jun'ichi Nomura

So, you have to put the linear mapping *before* that. Then, the top-level block device will be locked but you can still change the underlying mappings.

So using a disk device as a dm target locks it. DM won't use a disk device as a target if it is locked. Are you saying that dm can use another dm device as a target, even if it is already locked by being used as another dm target?

#5 lore raw
Quoted 7 lines · Phillip Susi
Quoted 3 lines · Jun'ichi Nomura

So, you have to put the linear mapping *before* that. Then, the top-level block device will be locked but you can still change the underlying mappings.

So using a disk device as a dm target locks it. DM won't use a disk device as a target if it is locked.

If a device is locked by a DM device on top of it, other DM device can still use the device as a target.

Also, even if a DM device is locked by mount, you can still change the table of the DM device.

Quoted 3 lines

Are you saying that dm can use
another dm device as a target, even if it is already locked by being used as another dm target?

I'm not sure if I understand your last sentence correctly. Does the above comment answer to your question?

Thanks,

Signature · 1 line
Jun'ichi Nomura, NEC Corporation of America