[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

RE: [dm-devel] Using dmsetup to create a snapshot...



Thanks for the detailed mail...
I tried the following steps to create the snapshot using EVMS

Steps to create a snap shot and rollback:
1. Attach a new hard disk to system
2. Delete all the partitions and volumes from the new hard disk
3. Created a new partition and installed ext2 in it. Called it /dev/hdb1.
4. Started EVMS and executed the following commands:
 a) Create:Segment,hdb_freespace1,size=100MB
 b) Create:Container,LvmRegMgr={name="My Container",pe_size=16MB},hdb2
 c) Create:region,LvmRegMgr={name="My Region", size=100MB},"lvm/My
Container/Freespace"
 d) create:object,Snapshot={original=/dev/evms/hdb1, snapshot=snap},"lvm/My
Container/My Region"
 e) c:v , snap, n="My Volume"
5. Mounted /dev/evms/hdb1 and created a few files and directories in the
same.
6. Mounted /dev/evms/My\ Volume and did not see the created files and dirs.
7. Unmounted both the volumes.
8. Started EVMS and executed the following command:
 task:rollback,snap
9. Mounted /dev/evms/hdb1 and saw the rolled back state. 

This all worked very fine. Now when I saw the tables created using dmsetup I
got the following output related to /dev/hdb:

snap: 0 977066 snapshot 254:007 254:008 P 128
hdb1#origin#: 0 977066 snapshot-origin 254:007
hda1: 0 64197 linear 003:000 63
hdb2: 0 204120 linear 003:064 977130
lvm|My Container|My Region: 0 163840 linear 254:005 33152
hdb1: 0 977067 linear 003:064 63
snap#sibling#: 0 163837 linear 254:006 0

When I want to create a similar stuff using "dmsetup" then the ultimate
outcome should be similar set of tables.
With dmsetup I tried the following steps:
1. Cleaned the second hard disk and created two partitions named /dev/hdb1
and /dev/hdb2 both of size 1000MB. Installed ext2 in both of them.
2. Ran the following script to create the snapshot (as you suggested):

#############################################################################
##############################
#!/bin/sh

function clean
{
	echo "removing all mappings..."
	/sbin/dmsetup remove my_data;
	/sbin/dmsetup remove my_data_snap;
	/sbin/dmsetup remove my_data_org;
	/sbin/dmsetup remove hdb1;
	/sbin/dmsetup remove hdb2;

	echo "Cleaning up mapper nodes..."
	/sbin/dmsetup mknodes
	return;
}

if [ "$1" = "clean" ]; then
	echo "cleaning ..."
	clean
	exit 0
fi

echo "Loading the device mapper modules..."
/sbin/insmod /lib/modules/2.4.26/kernel/drivers/md/dm-mod.o

echo "Creating the mapper nodes"
/usr/src/device-mapper.1.00.18/scripts/devmap_mknod.sh

echo "Creating my_data..."
echo " 0 1953100 linear /dev/hdb1 63" | /sbin/dmsetup create my_data
if [ $? -ne 0 ]; then
	echo "Unable to create my_data...Exiting..."
	exit 1
fi

echo "Suspending my_data..."
/sbin/dmsetup suspend my_data
if [ $? -ne 0 ]; then
	echo "Unable to suspend my_data...Exiting..."
	exit 2
fi

echo "Creating my_data_org..."
/sbin/dmsetup create my_data_org --notable
if [ $? -ne 0 ]; then
	echo "Unable to create my_data_org...Exiting..."
	exit 3
fi

echo "Loading my_data_org..."
/sbin/dmsetup table my_data | /sbin/dmsetup load my_data_org
if [ $? -ne 0 ]; then
	echo "Unable to load my_data_org...Exiting..."
	exit 4
fi

echo "Resuming my_data_org..."
/sbin/dmsetup resume my_data_org
if [ $? -ne 0 ]; then
	echo "Unable to resume my_data_org...Exiting..."
	exit 5
fi

echo "Creating my_data_snap..."
/sbin/dmsetup create my_data_snap --notable
if [ $? -ne 0 ]; then
	echo "Unable to create my_data_snap...Exiting..."
	exit 6
fi

echo "Loading my_data_snap..."
echo "0 `/sbin/blockdev --getsize /dev/mapper/my_data` snapshot
/dev/mapper/my_data_org /dev/hdb2 p 64" | /sbin/dmsetup load my_data_snap
if [ $? -ne 0 ]; then
	echo "Unable to load my_data_snap...Exiting..."
	exit 7
fi

echo "Loading my_data..."
echo "0 `/sbin/blockdev --getsize /dev/mapper/my_data` snapshot-origin
/dev/mapper/my_data_org" | /sbin/dmsetup load my_data
if [ $? -ne 0 ]; then
	echo "Unable to load my_data...Exiting..."
	exit 8
fi

echo "Resuming my_data_snap..."
/sbin/dmsetup resume my_data_snap
if [ $? -ne 0 ]; then
	echo "Unable to resume my_data_snap...Exiting..."
	exit 9
fi

echo "Resuming my_data..."
/sbin/dmsetup resume my_data
if [ $? -ne 0 ]; then
	echo "Unable to resume my_data...Exiting..."
	exit 10
fi
#############################################################################
##############################


The output I get after running the script is as follows:

-------------------------------------------------------
Loading the device mapper modules...
insmod: a module named dm-mod already exists
Creating the mapper nodes
Creating /dev/mapper/control character device with major:10 minor:63.
Creating my_data...
Suspending my_data...
Creating my_data_org...
Loading my_data_org...
Resuming my_data_org...
Creating my_data_snap...
Loading my_data_snap...
Loading my_data...
Resuming my_data_snap...
device-mapper: Invalid/corrupt snapshot
Resuming my_data...
---------------------------------------------------------

Thus device mapper is saying that the SNAPSHOT IS INVALID/CORRUPT

On running "dmsetup table" I get the following output:
---------------------------------------------------
my_data_org: 0 1953100 linear 003:065 63
my_data: 0 1953100 snapshot-origin 254:001
my_data_snap: 0 1953100 snapshot 254:001 003:066 P 64
-----------------------------------------------------

Surely I am close to creating a snapshot using dmsetup, but am missing
something. What ????


Thanks,
Manu.

-----Original Message-----
From: Kevin Corry [mailto:kevcorry us ibm com]
Sent: Thursday, July 22, 2004 9:01 PM
To: dm-devel redhat com
Cc: Manu Tayal
Subject: Re: [dm-devel] Using dmsetup to create a snapshot...


On Wednesday 21 July 2004 7:57 am, Manu Tayal wrote:
> Hi,
> I have installed device-mapper.1.00.18 on kernel 2.4.26. Now I want to
> create a snapshot using "dmsetup". I could not get hold of enough
> documentation to do the same. Can somebody tell me the steps which are
> required to do the same.
>
> My Setup: I have two hard disks on my system and I am using the second hard
> disk to experiment with device mapper. What I was trying to do was create a
> volume and install etx3 on the same. Then create a snapshot of it, mount
> the snapshot and view the same. I was able to achieve this via EVMS but not
> with dmsetup.
>
> Any pointers to good documentation would also help.

At this point, there isn't any written documentation about DM's snapshot 
implementation. I had hoped to write some to go into the 
Documentation/device-mapper/ directory in the kernel tree, but I got 
distracted with other work. I'm sure I'll get around to it eventually. For 
now I'd recommend looking through drivers/md/dm-snap.[ch] and 
drivers/md/dm-exception-store.c in the kernel source.

As for using dmsetup to create snapshots, I can't say I'd recommend that 
approach. The activation sequence is very tricky. To simply create a DM 
snapshot device, you'd do something like:

echo "0 <device_size_in_sectors> snapshot <origin_device> <cow_device> <p|n>
\ 
<chunk_size_in_sectors> | dmsetup create <new_snapshot_name>

But, that's only part of the story. You also need a snapshot-origin device to

actually monitor the I/Os to the origin volume and perform the 
copy-on-writes, which you create with:

echo "0 <device_size_in_sectors> snapshot-origin <origin_device>" \
| dmsetup create <new_origin_name>

Where <origin_device> is the same for both the snapshot and the origin. But, 
this isn't *really* what you want, either. Because for this to work, you 
would have you unmount the <origin_device> device and mount the 
<new_origin_name> device, so that I/O will actually go through the 
snapshot-origin device and be subject to the COW monitoring. But unmounting 
your origin volume and remounting through a different device is, of course, 
undesireable. You'd rather just allow the origin volume to remain mounted 
while you create the snapshot, since the whole point of snapshotting is to 
make backups of a live volume.

In order to do this properly, your origin volume must also be a DM device.
For 
example, a simple dm-linear or dm-stripe device, like the ones created by 
EVMS or LVM2. You can obviously also create such a device with dmsetup. For 
this example let's say you have a dm-linear device named "my_data", which was

created with dmsetup and is mounted using the device /dev/mapper/my_data, and

let's also say that this device has the mapping "0 12345 linear /dev/hdc1 0",

which means the device is 12345 sectors long and maps to /dev/hdc1 with no 
offset.

To create a proper snapshot of my_data while the device is mounted and in
use, 
you need to do the following:

1. Suspend my_data to temporarily stop any I/O while the snapshot is being 
activated.
   dmsetup suspend my_data

2. Create the snapshot-origin device with no table.
   dmsetup create my_data_org

3. Read the table from my_data and load it into my_data_org.
   dmsetup table my_data | dmsetup load my_data_org

4. Resume this new table.
   dmsetup resume my_data_org

5. Create the snapshot device with no table.
   dmsetup create my_data_snap

6. Load the table into my_data_snap. This uses /dev/hdd1 as the COW device
and 
uses a 32kB chunk-size.
   echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot \
    /dev/mapper/my_data_org /dev/hdd1 p 64" | dmsetup load my_data_snap

7. Reload my_data as a snapshot-origin device that points to my_data_org.
   echo "0 `blockdev --getsize /dev/mapper/my_data` snapshot-origin \
    /dev/mapper/my_data_org" | dmsetup load my_data

8. Resume the snapshot and origin devices.
   dmsetup resume my_data_snap
   dmsetup resume my_data

With this setup, a filesystem mounted on /dev/mapper/my_data will not need to

be remounted on a different device, but will now go through the 
snapshot-origin device and be subject to the COW monitoring. You can then 
mount /dev/mapper/my_data_snap to view the snapshot device and make your 
backup. I'll leave it as an exercise to the reader to figure out how to 
properly tear all this down. And if I've made any slight errors in this 
sequence, hopefully Alasdair will correct me. :)

If you're simply interested in using snapshots to do data backups, just stick

with EVMS or LVM2 and save yourself a lot of headache. :)

-- 
Kevin Corry
kevcorry us ibm com
http://evms.sourceforge.net/


DISCLAIMER:
This message (including attachment if any) is confidential and may be privileged. Before opening attachments please check them for viruses and defects. MindTree Consulting Private Limited (MindTree) will not be responsible for any viruses or defects or any forwarded attachments emanating either from within MindTree or outside. If you have received this message by mistake please notify the sender by return  e-mail and delete this message from your system. Any unauthorized use or dissemination of this message in whole or in part is strictly prohibited.  Please note that e-mails are susceptible to change and MindTree shall not be liable for any improper, untimely or incomplete transmission.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]