FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Device-mapper Development

 
 
LinkBack Thread Tools
 
Old 11-01-2011, 05:08 AM
Sanjana Shari
 
Default creating two device mapper files for an underline blockdevice

Hello,I am trying to create two device mapper files for an underline blockdevice. One file( half1) will be mapped to the first half of the block-device. and the second half (half2) will be mapped to the rest of the space in the same block device.
1.Using dd command I have created a 100 MB file.
# dd if=/dev/zero of=dm_test bs=512 count=2048002. associated it with loop device:
# losetup /dev/loop0 /tmp/dm_test# blockdev --getsize /dev/loop0
204800using dmsetup to create dm file.
# dmsetup create half --table "0 102400 linear /dev/loop0 0"
[root@bladelinux01 root]# dmsetup table half0 102400 linear 7:0 0
[root@bladelinux01 root]# dmsetup info halfName:************* half
State:************ ACTIVERead Ahead:******* 256
Tables present:*** LIVEOpen count:******* 0
Event number:***** 0Major, minor:***** 253, 6
Number of targets: 1
[root@bladelinux01 root]# ls -l /dev/mapper/halflrwxrwxrwx. 1 root root 7 Nov* 1 01:44 /dev/mapper/half -> ../dm-6
But if I use the other part of the disk to map. The command is not successful
[root@bladelinux01 root]#* dmsetup create half1 --table "102401 102399 linear /dev/loop0 102400"
device-mapper: reload ioctl failed: Invalid argumentCommand failed
[root@bladelinux01 root]#* dmsetup create half1 --table "102401 102399 linear /dev/loop0 0"
device-mapper: reload ioctl failed: Invalid argumentCommand failed
The format used seems to be correct according to the man page of dmsetup. Please guide me. I am not sure what am I missing.


-- sanjana


--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 11-01-2011, 05:10 AM
Sanjana Shari
 
Default creating two device mapper files for an underline blockdevice

Please do put me in cc list while replying.

On Tue, Nov 1, 2011 at 11:38 AM, Sanjana Shari <sanjana.linux@gmail.com> wrote:

Hello,
I am trying to create two device mapper files for an underline blockdevice. One file( half1) will be mapped to the first half of the block-device. and the second half (half2) will be mapped to the rest of the space in the same block device.

1.Using dd command I have created a 100 MB file.

# dd if=/dev/zero of=dm_test bs=512 count=2048002. associated it with loop device:

# losetup /dev/loop0 /tmp/dm_test# blockdev --getsize /dev/loop0

204800using dmsetup to create dm file.

# dmsetup create half --table "0 102400 linear /dev/loop0 0"
[root@bladelinux01 root]# dmsetup table half0 102400 linear 7:0 0

[root@bladelinux01 root]# dmsetup info halfName:************* half

State:************ ACTIVERead Ahead:******* 256

Tables present:*** LIVEOpen count:******* 0

Event number:***** 0Major, minor:***** 253, 6

Number of targets: 1
[root@bladelinux01 root]# ls -l /dev/mapper/halflrwxrwxrwx. 1 root root 7 Nov* 1 01:44 /dev/mapper/half -> ../dm-6

But if I use the other part of the disk to map. The command is not successful

[root@bladelinux01 root]#* dmsetup create half1 --table "102401 102399 linear /dev/loop0 102400"

device-mapper: reload ioctl failed: Invalid argumentCommand failed

[root@bladelinux01 root]#* dmsetup create half1 --table "102401 102399 linear /dev/loop0 0"

device-mapper: reload ioctl failed: Invalid argumentCommand failed

The format used seems to be correct according to the man page of dmsetup. Please guide me. I am not sure what am I missing.



-- sanjana




--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 11-01-2011, 03:52 PM
Sanjana Shari
 
Default creating two device mapper files for an underline blockdevice

Hi Milan,

Thanks for the documentation links... it was useful.. one of the link I had gone through it earlier.

Couple of questions more which I would post here...

Mapping the second half of the first device + the another device to create a new map. here I ma not mapping the whole of first disk. Or I ma not mapping the whole table, but still device creation is sucessfull.

[root@bladelinux01 ~]# losetup -a
/dev/loop0: [fd03]:2359319 (/root/dm/dm_test)
/dev/loop1: [fd03]:2359321 (/root/dm/dm_test1)
[root@bladelinux01 ~]# blockdev --getsize /dev/loop0
204800* < ------ 100 M

[root@bladelinux01 ~]# blockdev --getsize /dev/loop1
204800* < ------ 100 M

Using first half of the block device /dev/loop0. Here I have mapped the table from 0 to 102400 sectors.

[root@bladelinux01 ~]# fdisk -lus /dev/loop0


Disk /dev/loop0: 104 MB, 104857600 bytes
255 heads, 63 sectors/track, 12 cylinders, total 204800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Command is successful.... as expected.

[root@bladelinux01 ~]# dmsetup create firsthalf --table "0 102400 linear /dev/loop0 0"
[root@bladelinux01 ~]# dmsetup table firsthalf

0 102400 linear 7:0 0
[root@bladelinux01 ~]# dmsetup info firsthalf
Name:************* firsthalf
State:************ ACTIVE
Read Ahead:******* 256
Tables present:*** LIVE
Open count:******* 0
Event number:***** 0

Major, minor:***** 253, 6
Number of targets: 1

Now here I am creating a new device named "anotherhalf_plus_otherdisk" by mapping the remaining first half of the first disk and then the whole of a second block device /dev/loop1.


Creating table to use with dmsetup.
[root@bladelinux01 ~]# echo 0 102400 linear /dev/loop0 102400 > table
[root@bladelinux01 ~]# cat table
0 102400 linear /dev/loop0 102400
[root@bladelinux01 ~]# echo 102400 204800 linear /dev/loop1 0 >>table

[root@bladelinux01 ~]# cat table
0 102400 linear /dev/loop0 102400
102400 204800 linear /dev/loop1 0
[root@bladelinux01 ~]# dmsetup create anotherhalf_plus_otherdisk table
[root@bladelinux01 ~]# dmsetup table anotherhalf_plus_otherdisk

0 102400 linear 7:0 102400
102400 204800 linear 7:1 0
[root@bladelinux01 ~]# dmsetup info anotherhalf_plus_otherdisk
Name:************* anotherhalf_plus_otherdisk
State:************ ACTIVE
Read Ahead:******* 256

Tables present:*** LIVE
Open count:******* 0
Event number:***** 0
Major, minor:***** 253, 7
Number of targets: 2

device created with size as expected. Agian here I haven't used the start sector as "0" for the second block device,

I have used "102400"th sector to start from, which I believe should be continuation of the previous logical sector. < --- Please this part.
[root@bladelinux01 ~]# blockdev --getsize /dev/mapper/anotherhalf_plus_otherdisk

307200

[root@bladelinux01 ~]# fdisk -lus /dev/mapper/anotherhalf_plus_otherdisk

Disk /dev/mapper/anotherhalf_plus_otherdisk: 157 MB, 157286400 bytes
255 heads, 63 sectors/track, 19 cylinders, total 307200 sectors

Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Here I have some doubts which needs to be cleared to get a thorough understanding.

My questions:

The table format to be used is as follows from man page of dmsetup.
Each line of the table specifies a single target and is of the form:
logical_start_sector*** num_sectors*** target_type target_args


Here:
"logical_start_sector" start sector should be "0" for the start of any block device, rather I would say for the start of any new map would e more appropriate. What do you say...?
"num_sectors" as name suggestes would be the number of sectors, which would contribute to the size of the end mapped device.


For target type "linear" we use arguments as the following:
destination_device** start_sector** < -------- here which is the start sector..?
Is it the logical start scetor of the blockdevice or the physical sector of the blockdevice...? Or how do we define it...? This part is not yet clear to me.




On Tue, Nov 1, 2011 at 2:01 PM, Milan Broz <mbroz@redhat.com> wrote:

On 11/01/2011 07:08 AM, Sanjana Shari wrote:



> But if I use the other part of the disk to map. The command is not successful

>

> [root@bladelinux01 root]# *dmsetup create half1 --table "102401 102399 linear /dev/loop0 102400"

> device-mapper: reload ioctl failed: Invalid argument

> Command failed



You have to always map the whole table (starting at sector 0).

If you see syslog, you can see why

*device-mapper: table: 254:2: linear: Gap in table

*device-mapper: ioctl: error adding target to table



Anyway, for the info how it works, example how to switch active table:



1. create linear device mapped to /dev/sdb



*# dmsetup create x --table "0 10000 linear /dev/sdb 0"

*# dmsetup table x

*0 10000 linear 8:16 0



2. Remap the first half of device to another target, here "error"



*- load new (yet inactive) table

*# echo -e "0 5000 error
5000 10000 linear /dev/sdb 5000" | dmsetup load x



*- so now you have one active table and one inactive (prepared for switch)

*# dmsetup table x

*0 10000 linear 8:16 0



*# dmsetup table x --inactive

*0 5000 error

*5000 10000 linear 8:16 5000



3. switch to new (inactive) table (note that "dmsetup suspend" here is implicit)

*# dmsetup resume x



*# dmsetup table x

*0 5000 error

*5000 10000 linear 8:16 5000





If you want more info about this low level DM operation, read

http://people.redhat.com/agk/talks/FOSDEM_2005/

http://mbroz.fedorapeople.org/talks/DeviceMapperBasics/

(old, but still useful, I hope :-)



Milan



--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 11-01-2011, 04:10 PM
Sanjana Shari
 
Default creating two device mapper files for an underline blockdevice

Hi,

In an another example:

[root@bladelinux01 ~]# dmsetup table firsthalf
0 102400 linear 7:0 0

Using the remaining of first half of the same blockdevice /dev/loop0. This seems to work. So I ma confused here how the mapping works..

[root@bladelinux01 ~]# dmsetup create x --table "0 102400 linear /dev/loop0 102400"
[root@bladelinux01 ~]# dmsetup table x
0 102400 linear 7:0 102400
[root@bladelinux01 ~]# dmsetup table firsthalf
0 102400 linear 7:0 0

[root@bladelinux01 ~]# dmsetup table x
0 102400 linear 7:0 102400
[root@bladelinux01 ~]# dmsetup deps x
1 dependencies* : (7, 0)
[root@bladelinux01 ~]# dmsetup deps firsthalf
1 dependencies* : (7, 0)
[root@bladelinux01 ~]# dmsetup info x

Name:************* x
State:************ ACTIVE
Read Ahead:******* 256
Tables present:*** LIVE
Open count:******* 0
Event number:***** 0
Major, minor:***** 253, 7
Number of targets: 1

[root@bladelinux01 ~]# dmsetup info firsthalf

Name:************* firsthalf
State:************ ACTIVE
Read Ahead:******* 256
Tables present:*** LIVE
Open count:******* 0
Event number:***** 0
Major, minor:***** 253, 6
Number of targets: 1

--sanjana


On Tue, Nov 1, 2011 at 10:22 PM, Sanjana Shari <sanjana.linux@gmail.com> wrote:

Hi Milan,

Thanks for the documentation links... it was useful.. one of the link I had gone through it earlier.

Couple of questions more which I would post here...

Mapping the second half of the first device + the another device to create a new map. here I ma not mapping the whole of first disk. Or I ma not mapping the whole table, but still device creation is sucessfull.


[root@bladelinux01 ~]# losetup -a
/dev/loop0: [fd03]:2359319 (/root/dm/dm_test)
/dev/loop1: [fd03]:2359321 (/root/dm/dm_test1)
[root@bladelinux01 ~]# blockdev --getsize /dev/loop0
204800* < ------ 100 M


[root@bladelinux01 ~]# blockdev --getsize /dev/loop1
204800* < ------ 100 M

Using first half of the block device /dev/loop0. Here I have mapped the table from 0 to 102400 sectors.

[root@bladelinux01 ~]# fdisk -lus /dev/loop0



Disk /dev/loop0: 104 MB, 104857600 bytes
255 heads, 63 sectors/track, 12 cylinders, total 204800 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes


Disk identifier: 0x00000000

Command is successful.... as expected.

[root@bladelinux01 ~]# dmsetup create firsthalf --table "0 102400 linear /dev/loop0 0"
[root@bladelinux01 ~]# dmsetup table firsthalf


0 102400 linear 7:0 0
[root@bladelinux01 ~]# dmsetup info firsthalf
Name:************* firsthalf
State:************ ACTIVE
Read Ahead:******* 256
Tables present:*** LIVE
Open count:******* 0

Event number:***** 0

Major, minor:***** 253, 6
Number of targets: 1

Now here I am creating a new device named "anotherhalf_plus_otherdisk" by mapping the remaining first half of the first disk and then the whole of a second block device /dev/loop1.



Creating table to use with dmsetup.
[root@bladelinux01 ~]# echo 0 102400 linear /dev/loop0 102400 > table
[root@bladelinux01 ~]# cat table
0 102400 linear /dev/loop0 102400
[root@bladelinux01 ~]# echo 102400 204800 linear /dev/loop1 0 >>table


[root@bladelinux01 ~]# cat table
0 102400 linear /dev/loop0 102400
102400 204800 linear /dev/loop1 0
[root@bladelinux01 ~]# dmsetup create anotherhalf_plus_otherdisk table
[root@bladelinux01 ~]# dmsetup table anotherhalf_plus_otherdisk


0 102400 linear 7:0 102400
102400 204800 linear 7:1 0
[root@bladelinux01 ~]# dmsetup info anotherhalf_plus_otherdisk
Name:************* anotherhalf_plus_otherdisk
State:************ ACTIVE

Read Ahead:******* 256

Tables present:*** LIVE
Open count:******* 0
Event number:***** 0
Major, minor:***** 253, 7
Number of targets: 2

device created with size as expected. Agian here I haven't used the start sector as "0" for the second block device,


I have used "102400"th sector to start from, which I believe should be continuation of the previous logical sector. < --- Please this part.
[root@bladelinux01 ~]# blockdev --getsize /dev/mapper/anotherhalf_plus_otherdisk


307200

[root@bladelinux01 ~]# fdisk -lus /dev/mapper/anotherhalf_plus_otherdisk

Disk /dev/mapper/anotherhalf_plus_otherdisk: 157 MB, 157286400 bytes
255 heads, 63 sectors/track, 19 cylinders, total 307200 sectors


Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Here I have some doubts which needs to be cleared to get a thorough understanding.


My questions:

The table format to be used is as follows from man page of dmsetup.
Each line of the table specifies a single target and is of the form:
logical_start_sector*** num_sectors*** target_type target_args



Here:
"logical_start_sector" start sector should be "0" for the start of any block device, rather I would say for the start of any new map would e more appropriate. What do you say...?
"num_sectors" as name suggestes would be the number of sectors, which would contribute to the size of the end mapped device.



For target type "linear" we use arguments as the following:
destination_device** start_sector** < -------- here which is the start sector..?
Is it the logical start scetor of the blockdevice or the physical sector of the blockdevice...? Or how do we define it...? This part is not yet clear to me.





On Tue, Nov 1, 2011 at 2:01 PM, Milan Broz <mbroz@redhat.com> wrote:


On 11/01/2011 07:08 AM, Sanjana Shari wrote:



> But if I use the other part of the disk to map. The command is not successful

>

> [root@bladelinux01 root]# *dmsetup create half1 --table "102401 102399 linear /dev/loop0 102400"

> device-mapper: reload ioctl failed: Invalid argument

> Command failed



You have to always map the whole table (starting at sector 0).

If you see syslog, you can see why

*device-mapper: table: 254:2: linear: Gap in table

*device-mapper: ioctl: error adding target to table



Anyway, for the info how it works, example how to switch active table:



1. create linear device mapped to /dev/sdb



*# dmsetup create x --table "0 10000 linear /dev/sdb 0"

*# dmsetup table x

*0 10000 linear 8:16 0



2. Remap the first half of device to another target, here "error"



*- load new (yet inactive) table

*# echo -e "0 5000 error
5000 10000 linear /dev/sdb 5000" | dmsetup load x



*- so now you have one active table and one inactive (prepared for switch)

*# dmsetup table x

*0 10000 linear 8:16 0



*# dmsetup table x --inactive

*0 5000 error

*5000 10000 linear 8:16 5000



3. switch to new (inactive) table (note that "dmsetup suspend" here is implicit)

*# dmsetup resume x



*# dmsetup table x

*0 5000 error

*5000 10000 linear 8:16 5000





If you want more info about this low level DM operation, read

http://people.redhat.com/agk/talks/FOSDEM_2005/

http://mbroz.fedorapeople.org/talks/DeviceMapperBasics/

(old, but still useful, I hope :-)



Milan





--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 
Old 11-02-2011, 11:32 AM
Sanjana
 
Default creating two device mapper files for an underline blockdevice

Thanks Milan,

That clears my confusion.. need to read more doc...

--sanjana

On Wed, Nov 2, 2011 at 1:27 PM, Milan Broz <mbroz@redhat.com> wrote:

On 11/01/2011 06:10 PM, Sanjana Shari wrote:

> Using the remaining of first half of the same blockdevice /dev/loop0.

> This seems to work. So I ma confused here how the mapping works..



There is no magic for linear mapping.

Imagine you have this mapping table



0 8 linear /dev/sdb 1000

8 8 linear /dev/sdc 500



It means you created 16 sectors device consisting of two segments.



First half (sectors 0-7) is mapped to /dev/sdb starting at sector 10000.

(IOW sectors 0-7 of newly mapped device is mapped to sectors 10000-10007 of /dev/sdb)



Second half (sectors 8-15) is mapped to /dev/sdc starting at sector 500.



See dmsetup man page, where linear mapping is described.

Just do not confuse source and destination device offset.



Milan






--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
 

Thread Tools




All times are GMT. The time now is 05:56 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org