[libvirt] [PATCH v3 0/2] Fabric name must not be required for fc_host capability

fabric_name is one of many fc_host attributes in Linux that is optional and left to the low-level driver to decide if it is implemented. --- Changes sinve v2: - removed virReadFCHostOption method - changed additional file check to be used permanently Changes since v1: - split of minor correction in documenting comment - added news entry... - added new virReadFCHostOption method - added check for file existence when optional is set - rearranged fchost tests to fit the numbering --- Boris Fiuczynski (2): util: add file exists check in virReadFCHost nodedev: Fabric name must not be required for fc_host capability docs/formatnode.html.in | 2 +- docs/news.xml | 12 ++++++++++ docs/schemas/nodedev.rng | 8 ++++--- src/node_device/node_device_linux_sysfs.c | 9 +++---- src/util/virutil.c | 5 +++- tests/fchostdata/fc_host/host6/node_name | 1 + tests/fchostdata/fc_host/host6/port_name | 1 + tests/fchostdata/fc_host/host6/port_state | 1 + tests/fchosttest.c | 40 ++++++++++++++++++++++++++++++- 9 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/fchostdata/fc_host/host6/node_name create mode 100644 tests/fchostdata/fc_host/host6/port_name create mode 100644 tests/fchostdata/fc_host/host6/port_state -- 2.5.5

File open errors are prevented by a file exists check before virFileReadAll is called since all callers of the virReadFCHost method handle errors themselves based on the NULL return anyway. Also included is a minor spelling correction in a comment. Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> --- src/util/virutil.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index aeaa7f9..91178d1 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2011,7 +2011,7 @@ virGetSCSIHostNameByParentaddr(unsigned int domain, * * Read the value of sysfs "fc_host" entry. * - * Returns result as a stringon success, caller must free @result after + * Returns result as a string on success, caller must free @result after * Otherwise returns NULL. */ char * @@ -2029,6 +2029,9 @@ virReadFCHost(const char *sysfs_prefix, host, entry) < 0) goto cleanup; + if (!virFileExists(sysfs_path)) + goto cleanup; + if (virFileReadAll(sysfs_path, 1024, &buf) < 0) goto cleanup; -- 2.5.5

fabric_name is one of many fc_host attributes in Linux that is optional and left to the low-level driver to decide if it is implemented. The zfcp device driver does not provide a fabric name for an fcp host. This patch removes the requirement for a fabric name by making it optional. Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> --- docs/formatnode.html.in | 2 +- docs/news.xml | 12 ++++++++++ docs/schemas/nodedev.rng | 8 ++++--- src/node_device/node_device_linux_sysfs.c | 9 +++---- tests/fchostdata/fc_host/host6/node_name | 1 + tests/fchostdata/fc_host/host6/port_name | 1 + tests/fchostdata/fc_host/host6/port_state | 1 + tests/fchosttest.c | 40 ++++++++++++++++++++++++++++++- 8 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 tests/fchostdata/fc_host/host6/node_name create mode 100644 tests/fchostdata/fc_host/host6/port_name create mode 100644 tests/fchostdata/fc_host/host6/port_state diff --git a/docs/formatnode.html.in b/docs/formatnode.html.in index e7b1140..f8d0e12 100644 --- a/docs/formatnode.html.in +++ b/docs/formatnode.html.in @@ -254,7 +254,7 @@ number of vport in use. <code>max_vports</code> shows the maximum vports the HBA supports. "fc_host" implies following sub-elements: <code>wwnn</code>, <code>wwpn</code>, and - <code>fabric_wwn</code>. + optionally <code>fabric_wwn</code>. </dd> </dl> </dd> diff --git a/docs/news.xml b/docs/news.xml index baafcff..002227f 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -158,6 +158,18 @@ <section title="Bug fixes"> <change> <summary> + nodedev: Fabric name must not be required for fc_host capability + </summary> + <description> + fabric_name is one of many fc_host attributes in Linux that is + optional and left to the low-level driver to decide if it is + implemented. For example the zfcp device driver does not provide a + fabric name for an fcp host. The requirement for the existence of + a fabric name has been removed by making it optional. + </description> + </change> + <change> + <summary> qemu: Correct GetBlockInfo values </summary> <description> diff --git a/docs/schemas/nodedev.rng b/docs/schemas/nodedev.rng index 9c98402..b100a6e 100644 --- a/docs/schemas/nodedev.rng +++ b/docs/schemas/nodedev.rng @@ -367,9 +367,11 @@ <ref name='wwn'/> </element> - <element name='fabric_wwn'> - <ref name='wwn'/> - </element> + <optional> + <element name='fabric_wwn'> + <ref name='wwn'/> + </element> + </optional> </define> <define name='capsvports'> diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/node_device_linux_sysfs.c index be99c41..13520cd 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -72,13 +72,10 @@ nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapDataPtr d) VIR_FREE(d->scsi_host.wwnn); VIR_STEAL_PTR(d->scsi_host.wwnn, tmp); - if (!(tmp = virReadFCHost(NULL, d->scsi_host.host, "fabric_name"))) { - VIR_WARN("Failed to read fabric WWN for host%d", - d->scsi_host.host); - goto cleanup; + if ((tmp = virReadFCHost(NULL, d->scsi_host.host, "fabric_name"))) { + VIR_FREE(d->scsi_host.fabric_wwn); + VIR_STEAL_PTR(d->scsi_host.fabric_wwn, tmp); } - VIR_FREE(d->scsi_host.fabric_wwn); - VIR_STEAL_PTR(d->scsi_host.fabric_wwn, tmp); } if (virIsCapableVport(NULL, d->scsi_host.host)) { diff --git a/tests/fchostdata/fc_host/host6/node_name b/tests/fchostdata/fc_host/host6/node_name new file mode 100644 index 0000000..73a91bd --- /dev/null +++ b/tests/fchostdata/fc_host/host6/node_name @@ -0,0 +1 @@ +0x2002001b32a9da4e diff --git a/tests/fchostdata/fc_host/host6/port_name b/tests/fchostdata/fc_host/host6/port_name new file mode 100644 index 0000000..f25abeb --- /dev/null +++ b/tests/fchostdata/fc_host/host6/port_name @@ -0,0 +1 @@ +0x2102001b32a9da4e diff --git a/tests/fchostdata/fc_host/host6/port_state b/tests/fchostdata/fc_host/host6/port_state new file mode 100644 index 0000000..b73dd46 --- /dev/null +++ b/tests/fchostdata/fc_host/host6/port_state @@ -0,0 +1 @@ +Online diff --git a/tests/fchosttest.c b/tests/fchosttest.c index a08a2e8..bb35b88 100644 --- a/tests/fchosttest.c +++ b/tests/fchosttest.c @@ -29,13 +29,16 @@ static char *fchost_prefix; #define TEST_FC_HOST_PREFIX fchost_prefix #define TEST_FC_HOST_NUM 5 +#define TEST_FC_HOST_NUM_NO_FAB 6 /* Test virIsCapableFCHost */ static int test1(const void *data ATTRIBUTE_UNUSED) { if (virIsCapableFCHost(TEST_FC_HOST_PREFIX, - TEST_FC_HOST_NUM)) + TEST_FC_HOST_NUM) && + virIsCapableFCHost(TEST_FC_HOST_PREFIX, + TEST_FC_HOST_NUM_NO_FAB)) return 0; return -1; @@ -148,6 +151,39 @@ test5(const void *data ATTRIBUTE_UNUSED) return ret; } +/* Test virReadFCHost fabric name optional */ +static int +test6(const void *data ATTRIBUTE_UNUSED) +{ + const char *expect_wwnn = "2002001b32a9da4e"; + const char *expect_wwpn = "2102001b32a9da4e"; + char *wwnn = NULL; + char *wwpn = NULL; + int ret = -1; + + if (!(wwnn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, + "node_name"))) + return -1; + + if (!(wwpn = virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, + "port_name"))) + goto cleanup; + + if (virReadFCHost(TEST_FC_HOST_PREFIX, TEST_FC_HOST_NUM_NO_FAB, + "fabric_name")) + goto cleanup; + + if (STRNEQ(expect_wwnn, wwnn) || + STRNEQ(expect_wwpn, wwpn)) + goto cleanup; + + ret = 0; + cleanup: + VIR_FREE(wwnn); + VIR_FREE(wwpn); + return ret; +} + static int mymain(void) { @@ -169,6 +205,8 @@ mymain(void) ret = -1; if (virTestRun("test5", test5, NULL) < 0) ret = -1; + if (virTestRun("test6", test6, NULL) < 0) + ret = -1; cleanup: VIR_FREE(fchost_prefix); -- 2.5.5

On 01/16/2017 08:27 AM, Boris Fiuczynski wrote:
fabric_name is one of many fc_host attributes in Linux that is optional and left to the low-level driver to decide if it is implemented.
--- Changes sinve v2: - removed virReadFCHostOption method - changed additional file check to be used permanently
Changes since v1: - split of minor correction in documenting comment - added news entry... - added new virReadFCHostOption method - added check for file existence when optional is set - rearranged fchost tests to fit the numbering
--- Boris Fiuczynski (2): util: add file exists check in virReadFCHost nodedev: Fabric name must not be required for fc_host capability
docs/formatnode.html.in | 2 +- docs/news.xml | 12 ++++++++++ docs/schemas/nodedev.rng | 8 ++++--- src/node_device/node_device_linux_sysfs.c | 9 +++---- src/util/virutil.c | 5 +++- tests/fchostdata/fc_host/host6/node_name | 1 + tests/fchostdata/fc_host/host6/port_name | 1 + tests/fchostdata/fc_host/host6/port_state | 1 + tests/fchosttest.c | 40 ++++++++++++++++++++++++++++++- 9 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/fchostdata/fc_host/host6/node_name create mode 100644 tests/fchostdata/fc_host/host6/port_name create mode 100644 tests/fchostdata/fc_host/host6/port_state
ACK series, but I'll only push after 3.0.0 is out (and move the release note). John

On 01/17/2017 04:22 PM, John Ferlan wrote:
On 01/16/2017 08:27 AM, Boris Fiuczynski wrote:
fabric_name is one of many fc_host attributes in Linux that is optional and left to the low-level driver to decide if it is implemented.
--- Changes sinve v2: - removed virReadFCHostOption method - changed additional file check to be used permanently
Changes since v1: - split of minor correction in documenting comment - added news entry... - added new virReadFCHostOption method - added check for file existence when optional is set - rearranged fchost tests to fit the numbering
--- Boris Fiuczynski (2): util: add file exists check in virReadFCHost nodedev: Fabric name must not be required for fc_host capability
docs/formatnode.html.in | 2 +- docs/news.xml | 12 ++++++++++ docs/schemas/nodedev.rng | 8 ++++--- src/node_device/node_device_linux_sysfs.c | 9 +++---- src/util/virutil.c | 5 +++- tests/fchostdata/fc_host/host6/node_name | 1 + tests/fchostdata/fc_host/host6/port_name | 1 + tests/fchostdata/fc_host/host6/port_state | 1 + tests/fchosttest.c | 40 ++++++++++++++++++++++++++++++- 9 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 tests/fchostdata/fc_host/host6/node_name create mode 100644 tests/fchostdata/fc_host/host6/port_name create mode 100644 tests/fchostdata/fc_host/host6/port_state
ACK series, but I'll only push after 3.0.0 is out (and move the release note).
John
Thanks, John! -- Mit freundlichen Grüßen/Kind regards Boris Fiuczynski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
participants (2)
-
Boris Fiuczynski
-
John Ferlan