[dm-devel] [PATCH v2] multipathd: Added support to handle FPIN-Li events for FC-NVMe

2023-09-21 Thread Muneendra Kumar
From: Muneendra 

This patch adds the support to handle FPIN-Li for FC-NVMe.
On receiving the FPIN-Li events this patch moves the devices paths
which are affected due to link integrity to marginal path groups.
The paths which are set to marginal path group will be unset
on receiving the RSCN events

Signed-off-by: Muneendra 
Signed-off-by: Benjamin Marzinski 

---
Notes:
v2:
Addressed the review comments from Martin

Made changes to make sure that fpin_path_setmarginal()
now always set the path to marginal.
---
 multipathd/fpin_handlers.c | 204 +++--
 1 file changed, 149 insertions(+), 55 deletions(-)

diff --git a/multipathd/fpin_handlers.c b/multipathd/fpin_handlers.c
index aa0f63c9..f495f6ee 100644
--- a/multipathd/fpin_handlers.c
+++ b/multipathd/fpin_handlers.c
@@ -60,18 +60,15 @@ static void _udev_device_unref(void *p)
 
 
 /*set/unset the path state to marginal*/
-static int fpin_set_pathstate(struct path *pp, bool set)
+static void fpin_set_pathstate(struct path *pp, bool set)
 {
const char *action = set ? "set" : "unset";
 
-   if (!pp || !pp->mpp || !pp->mpp->alias)
-   return -1;
-
-   condlog(3, "\n%s: %s  marginal path %s (fpin)",
-   action, pp->mpp->alias, pp->dev_t);
+   condlog(3, "%s: %s marginal path %s (fpin)",
+   pp->mpp ? pp->mpp->alias : "orphan", action, pp->dev_t);
pp->marginal = set;
-   pp->mpp->fpin_must_reload = true;
-   return 0;
+   if (pp->mpp)
+   pp->mpp->fpin_must_reload = true;
 }
 
 /* This will unset marginal state of a device*/
@@ -82,14 +79,14 @@ static void fpin_path_unsetmarginal(char *devname, struct 
vectors *vecs)
pp = find_path_by_dev(vecs->pathvec, devname);
if (!pp)
pp = find_path_by_devt(vecs->pathvec, devname);
-
-   fpin_set_pathstate(pp, false);
+   if (pp)
+   fpin_set_pathstate(pp, false);
 }
 
 /*This will set the marginal state of a device*/
-static int fpin_path_setmarginal(struct path *pp)
+static void  fpin_path_setmarginal(struct path *pp)
 {
-   return fpin_set_pathstate(pp, true);
+   fpin_set_pathstate(pp, true);
 }
 
 /* Unsets all the devices in the list from marginal state */
@@ -183,8 +180,8 @@ static void fpin_set_rport_marginal(struct udev_device 
*rport_dev)
 udev_device_get_syspath(rport_dev));
 }
 
-/*Add the marginal devices info into the list*/
-static void
+/*Add the marginal devices info into the list and return 0 on success*/
+static int
 fpin_add_marginal_dev_info(uint32_t host_num, char *devname)
 {
struct marginal_dev_list *newdev = NULL;
@@ -199,65 +196,159 @@ fpin_add_marginal_dev_info(uint32_t host_num, char 
*devname)
list_add_tail(&(newdev->node),
_li_marginal_dev_list_head);
pthread_mutex_unlock(_li_marginal_dev_mutex);
-   }
+   } else
+   return -ENOMEM;
+   return 0;
 }
 
 /*
- * This function goes through the vecs->pathvec, and for
- * each path, check that the host  number,
- * the target WWPN associated with the path matches
- * with the els wwpn and sets the path and port state to
+ * This function compares Transport Address Controller Port pn,
+ * Host Transport Address Controller Port pn with the els wwpn ,attached_wwpn
+ * and return 1 (match) or 0 (no match) or a negative error code
+ */
+static int  extract_nvme_addresses_chk_path_pwwn(const char *address,
+   uint64_t els_wwpn, uint64_t els_attached_wwpn)
+
+{
+   uint64_t traddr;
+   uint64_t host_traddr;
+
+   /*
+*  Find the position of "traddr=" and "host_traddr="
+*  and the address will be in the below format
+*  "traddr=nn-0x200400110dff9400:pn-0x200400110dff9400,
+*  host_traddr=nn-0x200400110dff9400:pn-0x200400110dff9400"
+*/
+   const char *traddr_start = strstr(address, "traddr=");
+   const char *host_traddr_start = strstr(address, "host_traddr=");
+
+   if (!traddr_start || !host_traddr_start)
+   return -EINVAL;
+
+   /* Extract traddr pn */
+   if (sscanf(traddr_start, "traddr=nn-%*[^:]:pn-%" SCNx64, ) != 1)
+   return -EINVAL;
+
+   /* Extract host_traddr pn*/
+   if (sscanf(host_traddr_start, "host_traddr=nn-%*[^:]:pn-%" SCNx64,
+   _traddr) != 1)
+   return -EINVAL;
+   condlog(4, "traddr 0x%lx hosttraddr 0x%lx els_wwpn 0x%lx 
els_host_traddr 0x%lx",
+   traddr, host_traddr,
+   els_wwpn, els_attached_wwpn);
+   if ((host_traddr == els_attached_wwpn) && (traddr == els_wwpn))
+   return 1;
+   return 0;
+}
+
+/*
+ * This function check that the Transport Address Controller Port pn,
+ * Host Transport Address Controller Port pn associated with the path matches
+ * with the els wwpn 

Re: [dm-devel] [PATCH v2] multipathd: Added support to handle FPIN-Li events for FC-NVMe

2023-09-21 Thread Martin Wilck
On Thu, 2023-09-21 at 16:09 +0200, Martin Wilck wrote:
> On Wed, 2023-09-20 at 20:41 -0700, Muneendra Kumar wrote:
> > From: Muneendra 
> > 
> >     This patch adds the support to handle FPIN-Li for FC-NVMe.
> >     On receiving the FPIN-Li events this patch moves the devices
> > paths
> >     which are affected due to link integrity to marginal path
> > groups.
> >     The paths which are set to marginal path group will be unset
> >     on receiving the RSCN events
> > 
> > Signed-off-by: Muneendra 
> > Signed-off-by: Benjamin Marzinski 
> 
> 
> Reviewed-by: Martin Wilck 

There was a minor compilation error for 32 bit architectures (%lx vs
%llx format specifier), which I've fixed on my queue branch:

https://github.com/openSUSE/multipath-tools/tree/queue

Regards,
Martin

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



Re: [dm-devel] [PATCH v2] multipathd: Added support to handle FPIN-Li events for FC-NVMe

2023-09-21 Thread Martin Wilck
On Wed, 2023-09-20 at 20:41 -0700, Muneendra Kumar wrote:
> From: Muneendra 
> 
>     This patch adds the support to handle FPIN-Li for FC-NVMe.
>     On receiving the FPIN-Li events this patch moves the devices
> paths
>     which are affected due to link integrity to marginal path groups.
>     The paths which are set to marginal path group will be unset
>     on receiving the RSCN events
> 
> Signed-off-by: Muneendra 
> Signed-off-by: Benjamin Marzinski 


Reviewed-by: Martin Wilck 


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