Re: [libvirt] [PATCH v2 4/8] virstorageobj: Move virStoragePoolObjSourceFindDuplicate and friends up

2018-08-28 Thread John Ferlan



On 08/20/2018 08:09 AM, Michal Privoznik wrote:
> This function is going to be made static in used in
> virStoragePoolObjAssignDef(). Therefore move it and all the
> static functions it calls a few lines up.
> 
> Signed-off-by: Michal Privoznik 
> ---
>  src/conf/virstorageobj.c | 788 
> +++
>  1 file changed, 394 insertions(+), 394 deletions(-)
> 

Ugh, what a mess git diff makes... need some --patience on the diff

Still consider my patch 3 suggestion about combining this with patch
2... It then just becomes a "reorganize the code" type patch where all
the Add/Del, GetNum, GetName, and Export are lumped together.

Either way,

Reviewed-by: John Ferlan 

John

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


[libvirt] [PATCH v2 4/8] virstorageobj: Move virStoragePoolObjSourceFindDuplicate and friends up

2018-08-20 Thread Michal Privoznik
This function is going to be made static in used in
virStoragePoolObjAssignDef(). Therefore move it and all the
static functions it calls a few lines up.

Signed-off-by: Michal Privoznik 
---
 src/conf/virstorageobj.c | 788 +++
 1 file changed, 394 insertions(+), 394 deletions(-)

diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index ea0ae6fd86..b710ec652d 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1118,6 +1118,400 @@ virStoragePoolObjIsDuplicate(virStoragePoolObjListPtr 
pools,
 }
 
 
+static int
+getSCSIHostNumber(virStorageAdapterSCSIHostPtr scsi_host,
+  unsigned int *hostnum)
+{
+int ret = -1;
+unsigned int num;
+char *name = NULL;
+
+if (scsi_host->has_parent) {
+virPCIDeviceAddressPtr addr = _host->parentaddr;
+unsigned int unique_id = scsi_host->unique_id;
+
+if (!(name = virSCSIHostGetNameByParentaddr(addr->domain,
+addr->bus,
+addr->slot,
+addr->function,
+unique_id)))
+goto cleanup;
+if (virSCSIHostGetNumber(name, ) < 0)
+goto cleanup;
+} else {
+if (virSCSIHostGetNumber(scsi_host->name, ) < 0)
+goto cleanup;
+}
+
+*hostnum = num;
+ret = 0;
+
+ cleanup:
+VIR_FREE(name);
+return ret;
+}
+
+
+static bool
+virStorageIsSameHostnum(const char *name,
+unsigned int scsi_hostnum)
+{
+unsigned int fc_hostnum;
+
+if (virSCSIHostGetNumber(name, _hostnum) == 0 &&
+scsi_hostnum == fc_hostnum)
+return true;
+
+return false;
+}
+
+
+/*
+ * matchFCHostToSCSIHost:
+ *
+ * @conn: Connection pointer
+ * @fchost: fc_host adapter ptr (either def or pool->def)
+ * @scsi_hostnum: Already determined "scsi_pool" hostnum
+ *
+ * Returns true/false whether there is a match between the incoming
+ * fc_adapter host# and the scsi_host host#
+ */
+static bool
+matchFCHostToSCSIHost(virConnectPtr conn,
+  virStorageAdapterFCHostPtr fchost,
+  unsigned int scsi_hostnum)
+{
+bool ret = false;
+char *name = NULL;
+char *scsi_host_name = NULL;
+char *parent_name = NULL;
+
+/* If we have a parent defined, get its hostnum, and compare to the
+ * scsi_hostnum. If they are the same, then we have a match
+ */
+if (fchost->parent &&
+virStorageIsSameHostnum(fchost->parent, scsi_hostnum))
+return true;
+
+/* If we find an fc adapter name, then either libvirt created a vHBA
+ * for this fc_host or a 'virsh nodedev-create' generated a vHBA.
+ */
+if ((name = virVHBAGetHostByWWN(NULL, fchost->wwnn, fchost->wwpn))) {
+
+/* Get the scsi_hostN for the vHBA in order to see if it
+ * matches our scsi_hostnum
+ */
+if (virStorageIsSameHostnum(name, scsi_hostnum)) {
+ret = true;
+goto cleanup;
+}
+
+/* We weren't provided a parent, so we have to query the node
+ * device driver in order to ascertain the parent of the vHBA.
+ * If the parent fc_hostnum is the same as the scsi_hostnum, we
+ * have a match.
+ */
+if (conn && !fchost->parent) {
+if (virAsprintf(_host_name, "scsi_%s", name) < 0)
+goto cleanup;
+if ((parent_name = virNodeDeviceGetParentName(conn,
+  scsi_host_name))) {
+if (virStorageIsSameHostnum(parent_name, scsi_hostnum)) {
+ret = true;
+goto cleanup;
+}
+} else {
+/* Throw away the error and fall through */
+virResetLastError();
+VIR_DEBUG("Could not determine parent vHBA");
+}
+}
+}
+
+/* NB: Lack of a name means that this vHBA hasn't yet been created,
+ * which means our scsi_host cannot be using the vHBA. Furthermore,
+ * lack of a provided parent means libvirt is going to choose the
+ * "best" fc_host capable adapter based on availabilty. That could
+ * conflict with an existing scsi_host definition, but there's no
+ * way to know that now.
+ */
+
+ cleanup:
+VIR_FREE(name);
+VIR_FREE(parent_name);
+VIR_FREE(scsi_host_name);
+return ret;
+}
+
+
+static bool
+matchSCSIAdapterParent(virStorageAdapterSCSIHostPtr pool_scsi_host,
+   virStorageAdapterSCSIHostPtr def_scsi_host)
+{
+virPCIDeviceAddressPtr pooladdr = _scsi_host->parentaddr;
+virPCIDeviceAddressPtr defaddr = _scsi_host->parentaddr;
+
+if (pooladdr->domain == defaddr->domain &&
+pooladdr->bus == defaddr->bus &&
+