On Sat, Mar 09, 2019 at 08:24:43PM -0400, Jason Gunthorpe wrote: > On Fri, Mar 08, 2019 at 10:13:48PM +0200, Leon Romanovsky wrote: > > > > > +static int by_pci(struct data *d) > > > > +{ > > > > + char *path, *token, *pci; > > > > + char buf[256]; > > > > + long p, s, f; > > > > + ssize_t len; > > > > + int ret; > > > > + > > > > + ret = asprintf(&path, "/sys/class/infiniband/%s", d->curr); > > > > + if (ret == -1) { > > > > + path = NULL; > > > > + ret = -ENOMEM; > > > > + goto out; > > > > + } > > > > + > > > > + len = readlink(path, buf, sizeof(buf)-1); > > > > + if (len == -1) { > > > > + ret = -EINVAL; > > > > + goto out; > > > > + } > > > > + pci = buf + strlen("../../devices/pci0000:00/"); > > > > > > This is really sketchy. > > > > > > Do > > > dev_path = realpath(/sys/class/infiniband/%s/device/) > > > > > > Check that > > > > > > stat(dev_path + /subsystem).st_inode == stat("/sys/bus/pci").st_inode > > > > > > To confirm PCI > > > > > > Strip the last path off to get the domain:B:D.f: > > > > > > basename(dev_path) > > > > The current implementation is needed for RXE devices connected in VM > > over virtio devices, in such case your "basename" will return > > virtio_net. > > Which is right, RXE isn't a PCI device and shouldn't use PCI naming at > all. > > The check on the subsystem should exclude it entirely. But why should we exclude it? At the end, RXE is connected to some device and this device will have some sort of PCI. Why don't you want to use this knowledge to ensure that every time "rxe add" will be called we will see same name? Thanks > > Jason
Attachment:
signature.asc
Description: PGP signature