Hi Milan,<br><br>Thanks for the documentation links... it was useful.. one of the link I had gone through it earlier.<br><br>Couple of questions more which I would post here...<br><br>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.<br>
[root@bladelinux01 ~]# losetup -a<br>/dev/loop0: [fd03]:2359319 (/root/dm/dm_test)<br>/dev/loop1: [fd03]:2359321 (/root/dm/dm_test1)<br>[root@bladelinux01 ~]# blockdev --getsize /dev/loop0<br>204800  < ------ 100 M<br>
[root@bladelinux01 ~]# blockdev --getsize /dev/loop1<br>204800  < ------ 100 M<br><br>Using first half of the block device /dev/loop0. Here I have mapped the table from 0 to 102400 sectors.<br><br>[root@bladelinux01 ~]# fdisk -lus /dev/loop0<br>
<br>Disk /dev/loop0: 104 MB, 104857600 bytes<br>255 heads, 63 sectors/track, 12 cylinders, total 204800 sectors<br>Units = sectors of 1 * 512 = 512 bytes<br>Sector size (logical/physical): 512 bytes / 512 bytes<br>I/O size (minimum/optimal): 512 bytes / 512 bytes<br>
Disk identifier: 0x00000000<br><br>Command is successful.... as expected.<br><br>[root@bladelinux01 ~]# dmsetup create firsthalf --table "0 102400 linear /dev/loop0 0"<br>[root@bladelinux01 ~]# dmsetup table firsthalf<br>
0 102400 linear 7:0 0<br>[root@bladelinux01 ~]# dmsetup info firsthalf<br>Name:              firsthalf<br>State:             ACTIVE<br>Read Ahead:        256<br>Tables present:    LIVE<br>Open count:        0<br>Event number:      0<br>
Major, minor:      253, 6<br>Number of targets: 1<br><br>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.<br>
<br>Creating table to use with dmsetup.<br>[root@bladelinux01 ~]# echo 0 102400 linear /dev/loop0 102400 > table<br>[root@bladelinux01 ~]# cat table<br>0 102400 linear /dev/loop0 102400<br>[root@bladelinux01 ~]# echo 102400 204800 linear /dev/loop1 0 >>table<br>
[root@bladelinux01 ~]# cat table<br>0 102400 linear /dev/loop0 102400<br>102400 204800 linear /dev/loop1 0<br>[root@bladelinux01 ~]# dmsetup create anotherhalf_plus_otherdisk table<br>[root@bladelinux01 ~]# dmsetup table anotherhalf_plus_otherdisk<br>
0 102400 linear 7:0 102400<br>102400 204800 linear 7:1 0<br>[root@bladelinux01 ~]# dmsetup info anotherhalf_plus_otherdisk<br>Name:              anotherhalf_plus_otherdisk<br>State:             ACTIVE<br>Read Ahead:        256<br>
Tables present:    LIVE<br>Open count:        0<br>Event number:      0<br>Major, minor:      253, 7<br>Number of targets: 2<br><br>device created with size as expected. Agian here I haven't used the start sector as "0" for the second block device, <br>
I have used "102400"th sector to start from, which I believe should be continuation of the previous logical sector. < --- Please this part.<br>[root@bladelinux01 ~]# blockdev --getsize /dev/mapper/anotherhalf_plus_otherdisk<br>
307200<br><br>[root@bladelinux01 ~]# fdisk -lus /dev/mapper/anotherhalf_plus_otherdisk<br><br>Disk /dev/mapper/anotherhalf_plus_otherdisk: 157 MB, 157286400 bytes<br>255 heads, 63 sectors/track, 19 cylinders, total 307200 sectors<br>
Units = sectors of 1 * 512 = 512 bytes<br>Sector size (logical/physical): 512 bytes / 512 bytes<br>I/O size (minimum/optimal): 512 bytes / 512 bytes<br>Disk identifier: 0x00000000<br><br>Here I have some doubts which needs to be cleared to get a thorough understanding.<br>
My questions:<br><br>The table format to be used is as follows from man page of dmsetup.<br>Each line of the table specifies a single target and is of the form:<br>logical_start_sector    num_sectors    target_type target_args<br>
<br>Here:<br>"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...?<br>"num_sectors" as name suggestes would be the number of sectors, which would contribute to the size of the end mapped device.<br>
<br>For target type "linear" we use arguments as the following:<br>destination_device   start_sector   < -------- here which is the start sector..? <br>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.<br>
<br><br><br><div class="gmail_quote">On Tue, Nov 1, 2011 at 2:01 PM, Milan Broz <span dir="ltr"><<a href="mailto:mbroz@redhat.com">mbroz@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On 11/01/2011 07:08 AM, Sanjana Shari wrote:<br>
<br>
> But if I use the other part of the disk to map. The command is not successful<br>
><br>
> [root@bladelinux01 root]#  dmsetup create half1 --table "102401 102399 linear /dev/loop0 102400"<br>
> device-mapper: reload ioctl failed: Invalid argument<br>
> Command failed<br>
<br>
</div>You have to always map the whole table (starting at sector 0).<br>
If you see syslog, you can see why<br>
  device-mapper: table: 254:2: linear: Gap in table<br>
  device-mapper: ioctl: error adding target to table<br>
<br>
Anyway, for the info how it works, example how to switch active table:<br>
<br>
1. create linear device mapped to /dev/sdb<br>
<br>
  # dmsetup create x --table "0 10000 linear /dev/sdb 0"<br>
  # dmsetup table x<br>
  0 10000 linear 8:16 0<br>
<br>
2. Remap the first half of device to another target, here "error"<br>
<br>
 - load new (yet inactive) table<br>
 # echo -e "0 5000 error\n5000 10000 linear /dev/sdb 5000" | dmsetup load x<br>
<br>
 - so now you have one active table and one inactive (prepared for switch)<br>
 # dmsetup table x<br>
 0 10000 linear 8:16 0<br>
<br>
 # dmsetup table x --inactive<br>
 0 5000 error<br>
 5000 10000 linear 8:16 5000<br>
<br>
3. switch to new (inactive) table (note that "dmsetup suspend" here is implicit)<br>
  # dmsetup resume x<br>
<br>
  # dmsetup table x<br>
  0 5000 error<br>
  5000 10000 linear 8:16 5000<br>
<br>
<br>
If you want more info about this low level DM operation, read<br>
<a href="http://people.redhat.com/agk/talks/FOSDEM_2005/" target="_blank">http://people.redhat.com/agk/talks/FOSDEM_2005/</a><br>
<a href="http://mbroz.fedorapeople.org/talks/DeviceMapperBasics/" target="_blank">http://mbroz.fedorapeople.org/talks/DeviceMapperBasics/</a><br>
(old, but still useful, I hope :-)<br>
<font color="#888888"><br>
Milan<br>
</font></blockquote></div><br>