Skip to contentSkip to conversation

snapshot reset

linux-lvm Bastian Blank 3 participants 4 messages Mar 16, 2005 – Mar 24, 2005

lore
Share & tools
lore
#0 lore raw

Hi folks

Is it possible to reset a snapshot without a delete, create cycle?

Bastian

Signature · 1 line
Spock: We suffered 23 casualties in that attack, Captain.
#1 lore raw
Quoted 1 line · Bastian Blank

Is it possible to reset a snapshot without a delete, create cycle?

Not sure if I'm answering the right question, but with LVM2/device-mapper:

You have to suspend & resume it in the kernel [with existing device-mapper implementation; this may change].

With LVM2, between those commands, you can just zero out the start of the cow device (say first 64k). And then it'll treat it as if it were a new snapshot (based on current state of filesystem.)

Alasdair

Signature · 1 line
[email protected]
#2 lore raw
Quoted 4 lines · Alasdair G Kergon
Quoted 1 line · Bastian Blank

Is it possible to reset a snapshot without a delete, create cycle?

Not sure if I'm answering the right question, but with LVM2/device-mapper:

Yes, you were answering the right questions.

Quoted 6 lines

You have to suspend & resume it in the kernel [with existing device-mapper implementation; this may change].

With LVM2, between those commands, you can just zero out the start of the cow device (say first 64k). And then it'll treat it as if it were a new snapshot (based on current state of filesystem.)

Something like this?

| name=${vg}-${lv}
| dmsetup suspend $name
| dd if=/dev/zero of=/dev/mapper/${name}-cow bs=64k count=1
| dmsetup resume $name

Is it possible to implement that somewhere in the lvm commands?

Bastian

Signature · 2 lines
Power is danger.
		-- The Centurion, "Balance of Terror", stardate 1709.2
#3 lore raw
Quoted 10 lines · Bastian Blank
Quoted 3 lines

With LVM2, between those commands, you can just zero out the start of the cow device (say first 64k). And then it'll treat it as if it were a new snapshot (based on current state of filesystem.)

Something like this?

| name=${vg}-${lv}
| dmsetup suspend $name
| dd if=/dev/zero of=/dev/mapper/${name}-cow bs=64k count=1
| dmsetup resume $name

I tried something very much like this a couple of weeks ago (with Linux 2.6.10) and found that it's not reliable. Digging further, I learned that the snapshot device doesn't actually read the cow device when it resumes. (BTW, you only need to blank the first 4 bytes, which contain the magic number.) However, if you use "vgchange -a n; vgchange -a y" after this script, it should work.

My goal was to use snapshot devices to implement filesystem-level transactions. I wanted to write a set of changes to the filesystem only if all of the changes could be committed. I decided that vgchange was too invasive for my purposes, so I wrote a patch for device-mapper that lets you reliably and quickly clear a snapshot device using this command:

  dmsetup message ${vg}-${lv} 0 resync

Then I wrote a script that commits the changes from a snapshot device back to the original volume, then clears the snapshot device so it can be reused for more transactions. I was happy with how it turned out; you don't even have to unmount the filesystem to commit a transaction. (Aborting a transaction does require a remount.)

Once I finished, I changed my mind and decided I wanted to gain transactional integrity in a different way. However, if anyone's interested in my work, email me and I'll send you everything.

Shane