NPIV provides a way of assigning a fibre channel LUN directly to a XEN guest, without having it assigned to the host that the VM is running on. NPIV effectively bridges through the HBA, using a vport. The SAN should then see the WWN of the VM and allow you to assign LUNs directly to that VM. Of course, you’ll need both SAN and Fiber Channel switch support for NPIV.
Setting up an NPIV block device
To use NPIV, you need to create an identifier for the device that XEN understands. The identifier is formatted as follows:
To obtain these values you’ll need to do a little detective work.
This will be shown in the file /sys/class/fc_host/hostX/fabric_name. You will need to identify the host number that corresponds to your HBA. If you have more than one HBA, pick one and use it for all the steps that follow. You must remove the 0x from the start of the value you read from the file.
wwpn and wwnn (worldwide port/node name)
These are the identifiers that will be presented as the virtual HBA to your SAN. You will use these values to assign storage using your usual method. The values for these are entirely up to you, you can create them form scratch or base them on existing WWN values. There are only two restrictions; they mush be unique, and they must be 16 hex digits long. An example is: wwpn – 9990000000000001 and wwnn – 9990100000000001.
This is possibly the trickiest of all. You will find it buried in the fc_host information. For example:
As with the above, you may have more than one host and more than one remote port according to your SAN layout, especially if you have multipathing enabled.
This is the simplest of all. It is the LUN number as assigned on the SAN when you created the LUN in the storage group. It will usually be 0 if there is only one LUN assigned to the vport.
So, once you have all of the above details, your npiv statement should look something like:
You may need to attempt to add the storage to the VM before you can actually zone it in your SAN as the new WWN will not show up there. If you can add it manually, you may want to do that now.
Adding the storage to a VM
To add the storage to a running VM (the easiest way to test) try the following, substituting xvdb for the disk name that you want the VM to see:
xm block-attach sles11 npiv:100000051e8ccaf2-9990000000000001-9990100000000001-50060e8010458780-0 xvdb w
If this works, then you should see the new disk inside your VM. Check that by using
cat /proc/partitions inside the VM.
If you didn’t set up the SAN zoning manually, the above will fail, but you should now see the new WWN. Set up the zoning and the try the command again.
Once you are happy that the above is working, you can add the LUN to the configuration file for the VM in the same way as you would add any other disk.
Unfortunately there is a bug in the npiv code as shipped with SLES11 (versions 3.3.1_18546_12 to 3.3.1_18546_16). This has been reported to engineering and updated code is currently being tested. It should be fixed in versions greater than the above.