Re: [systemd-devel] [PATCH] v3 Read NIC partitions on Dell Servers

2015-11-25 Thread Harald Hoyer
On 10.11.2015 21:57, jhar...@gmail.com wrote:
> +char path[256];

Is that on the safe side?
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] v3 Read NIC partitions on Dell Servers

2015-11-12 Thread Lennart Poettering
On Tue, 10.11.15 14:57, jhar...@gmail.com (jhar...@gmail.com) wrote:

> From: Jordan Hargrave 
> 
> I removed the SMBIOS-specific code, this code is for partition detection only.
> 
> This patch will read NIC partition info from VPD on Dell Servers
> 
> It creates a new environment variable 'ID_NET_NAME_PARTITION'
> with the format '_'
> 
> Signed-off-by: Jordan Hargrave 

I am not sure if Kay/Tom want this patch at all or not, but if they
do:

please have a look at CODING_STYLE, and try to follow the rules. I see
quite a few places where coding style isn't followed: we don't use
S-o-b on systemd, we place opening brackets on the same line as the
functions/structs. We don't use types such as "unsigned char", we
don't invent error codes such as "-1", we don't use {} on single-line
if blocks, and so on.

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] v3 Read NIC partitions on Dell Servers

2015-11-10 Thread systemd github import bot
Patchset imported to github.
To create a pull request, one of the main developers has to initiate one via:


--
Generated by https://github.com/haraldh/mail2git
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] v3 Read NIC partitions on Dell Servers

2015-11-10 Thread jharg93
From: Jordan Hargrave 

I removed the SMBIOS-specific code, this code is for partition detection only.

This patch will read NIC partition info from VPD on Dell Servers

It creates a new environment variable 'ID_NET_NAME_PARTITION'
with the format '_'

Signed-off-by: Jordan Hargrave 
---
 src/udev/udev-builtin-net_id.c | 127 +
 1 file changed, 127 insertions(+)

diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index ef9c398..69dd9fd 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -119,16 +119,131 @@ struct netnames {
 bool mac_valid;
 
 struct udev_device *pcidev;
+struct udev_device *physdev;
 char pci_slot[IFNAMSIZ];
 char pci_path[IFNAMSIZ];
 char pci_onboard[IFNAMSIZ];
 const char *pci_onboard_label;
+int  npar_port;
+int  npar_pfi;
 
 char usb_ports[IFNAMSIZ];
 char bcma_core[IFNAMSIZ];
 char ccw_group[IFNAMSIZ];
 };
 
+#define FLAG_IOV 0x80
+#define FLAG_NPAR 0x1000
+
+#define VPDI_TAG 0x82
+#define VPDR_TAG 0x90
+
+struct vpd_tag
+{
+char  cc[2];
+unsigned char len;
+char  data[1];
+};
+
+/* Read VPD tag ID */
+static int vpd_readtag(int fd, int *len)
+{
+unsigned char tag, tlen[2];
+
+if (read(fd, &tag, 1) != 1)
+return -1;
+if (tag == 0x00 || tag == 0xFF || tag == 0x7F)
+return -1;
+if (tag & 0x80) {
+if (read(fd, tlen, 2) != 2)
+return -1;
+*len = tlen[0] + (tlen[1] << 8);
+return tag;
+}
+*len = (tag & 0x7);
+return (tag & ~0x7);
+}
+
+static void *vpd_findtag(void *buf, int len, const char *sig)
+{
+int off, siglen;
+struct vpd_tag *t;
+
+off = 0;
+siglen = strlen(sig);
+while (off < len) {
+t = (struct vpd_tag *)((unsigned char *)buf + off);
+if (!memcmp(t->data, sig, siglen))
+return t;
+off += (t->len + 3);
+}
+return NULL;
+}
+
+static void dev_pci_npar_dcm(struct udev_device *dev, struct netnames *names,
+ int len, const char *dcm,
+ const char *fmt, int step)
+{
+int domain, bus, slot, func, off, mydf;
+int port, df, pfi, flag;
+
+if (sscanf(udev_device_get_sysname(names->physdev), "%x:%x:%x.%u",
+   &domain, &bus, &slot, &func) != 4)
+return;
+mydf = (slot << 3) + func;
+for (off=3; offnpar_port = port;
+names->npar_pfi = pfi;
+}
+}
+}
+
+static void dev_pci_npar(struct udev_device *dev, struct netnames *names) {
+const char *filename;
+int len, fd;
+struct vpd_tag *dcm;
+void *buf;
+
+/* Search for VPD or IOV VPD */
+filename = strjoina(udev_device_get_syspath(names->physdev), "/vpd");
+if ((fd = open(filename, O_RDONLY)) < 0) {
+return;
+}
+if (vpd_readtag(fd, &len) != VPDI_TAG) {
+goto done;
+}
+lseek(fd, len, SEEK_CUR);
+
+/* Check VPD-R */
+if (vpd_readtag(fd, &len) != VPDR_TAG) {
+goto done;
+}
+buf = alloca(len);
+if (read(fd, buf, len) != len) {
+goto done;
+}
+
+/* Check for DELL VPD tag */
+if (!vpd_findtag(buf, len, "DSV1028VPDR.VER")) {
+goto done;
+}
+
+/* Find DCM/DC2 tag */
+if ((dcm = vpd_findtag(buf, len, "DCM")) != NULL) {
+dev_pci_npar_dcm(dev, names, dcm->len, dcm->data,
+ "%1x%1x%2x%6x", 10);
+}
+else if ((dcm = vpd_findtag(buf, len, "DC2")) != NULL) {
+dev_pci_npar_dcm(dev, names, dcm->len, dcm->data,
+ "%1x%2x%2x%6x", 11);
+}
+ done:
+close(fd);
+return;
+}
+
 /* retrieve on-board index number and label from firmware */
 static int dev_pci_onboard(struct udev_device *dev, struct netnames *names) {
 unsigned dev_port = 0;
@@ -277,6 +392,7 @@ out:
 
 static int names_pci(struct udev_device *dev, struct netnames *names) {
 struct udev_device *parent;
+char path[256];
 
 assert(dev);
 assert(names);
@@ -301,8 +417,14 @@ static int names_pci(struct udev_device *dev, struct 
netnames *names) {
 if (!names->pcidev)
 return -ENOENT;
 }
+/* find SR-IOV parent device */
+snprintf(path, sizeof(path), "%s/physfn", 
udev_device_get_syspath(names->pcidev));
+names->physdev = udev_device_new_from_syspath(names->pcidev, path);
+if (!names->physdev)
+names->physdev = names-