[libvirt PATCH v3 5/5] qemu: implement support for Fibre Channel VMID

Pavel Hrdina posted 5 patches 4 years, 5 months ago
There is a newer version of this series
[libvirt PATCH v3 5/5] qemu: implement support for Fibre Channel VMID
Posted by Pavel Hrdina 4 years, 5 months ago
Based on kernel commit messages the interface is

    /sys/class/fc/fc_udev_device/appid_store

where we need to write the following string "$INODE:$APPID".

$INODE is the VM root cgroup inode in hexadecimal and $APPID is user
provided string that will be attached to each FC frame for the VM
within the cgroup identified by inode and has limit 128 bytes.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
 src/qemu/qemu_cgroup.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index f2d99abcfa..cb83cc8e3e 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -904,6 +904,30 @@ qemuSetupCpuCgroup(virDomainObj *vm)
 }
 
 
+static int
+qemuSetupCgroupAppid(virDomainObj *vm)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+    int inode = virCgroupGetInode(priv->cgroup);
+    const char *path = "/sys/class/fc/fc_udev_device/appid_store";
+    g_autofree char *appid = NULL;
+    virDomainResourceDef *resource = vm->def->resource;
+
+    if (!resource || !resource->appid)
+        return 0;
+
+    appid = g_strdup_printf("%X:%s", inode, resource->appid);
+
+    if (virFileWriteStr(path, appid, 0) < 0) {
+        virReportSystemError(errno,
+                             _("Unable to write '%s' to '%s'"), appid, path);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 qemuInitCgroup(virDomainObj *vm,
                size_t nnicindexes,
@@ -1096,6 +1120,9 @@ qemuSetupCgroup(virDomainObj *vm,
     if (qemuSetupCpusetCgroup(vm) < 0)
         return -1;
 
+    if (qemuSetupCgroupAppid(vm) < 0)
+        return -1;
+
     return 0;
 }
 
-- 
2.31.1

Re: [libvirt PATCH v3 5/5] qemu: implement support for Fibre Channel VMID
Posted by Martin Kletzander 4 years, 5 months ago
On Tue, Aug 17, 2021 at 11:26:42AM +0200, Pavel Hrdina wrote:
>Based on kernel commit messages the interface is
>
>    /sys/class/fc/fc_udev_device/appid_store
>
>where we need to write the following string "$INODE:$APPID".
>
>$INODE is the VM root cgroup inode in hexadecimal and $APPID is user
>provided string that will be attached to each FC frame for the VM
>within the cgroup identified by inode and has limit 128 bytes.
>
>Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
>---
> src/qemu/qemu_cgroup.c | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
>
>diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
>index f2d99abcfa..cb83cc8e3e 100644
>--- a/src/qemu/qemu_cgroup.c
>+++ b/src/qemu/qemu_cgroup.c
>@@ -904,6 +904,30 @@ qemuSetupCpuCgroup(virDomainObj *vm)
> }
>
>
>+static int
>+qemuSetupCgroupAppid(virDomainObj *vm)
>+{
>+    qemuDomainObjPrivate *priv = vm->privateData;
>+    int inode = virCgroupGetInode(priv->cgroup);

You are not checking if this resulted in an error.
Re: [libvirt PATCH v3 5/5] qemu: implement support for Fibre Channel VMID
Posted by Pavel Hrdina 4 years, 5 months ago
On Tue, Aug 17, 2021 at 12:06:11PM +0200, Martin Kletzander wrote:
> On Tue, Aug 17, 2021 at 11:26:42AM +0200, Pavel Hrdina wrote:
> > Based on kernel commit messages the interface is
> > 
> >    /sys/class/fc/fc_udev_device/appid_store
> > 
> > where we need to write the following string "$INODE:$APPID".
> > 
> > $INODE is the VM root cgroup inode in hexadecimal and $APPID is user
> > provided string that will be attached to each FC frame for the VM
> > within the cgroup identified by inode and has limit 128 bytes.
> > 
> > Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
> > ---
> > src/qemu/qemu_cgroup.c | 27 +++++++++++++++++++++++++++
> > 1 file changed, 27 insertions(+)
> > 
> > diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
> > index f2d99abcfa..cb83cc8e3e 100644
> > --- a/src/qemu/qemu_cgroup.c
> > +++ b/src/qemu/qemu_cgroup.c
> > @@ -904,6 +904,30 @@ qemuSetupCpuCgroup(virDomainObj *vm)
> > }
> > 
> > 
> > +static int
> > +qemuSetupCgroupAppid(virDomainObj *vm)
> > +{
> > +    qemuDomainObjPrivate *priv = vm->privateData;
> > +    int inode = virCgroupGetInode(priv->cgroup);
> 
> You are not checking if this resulted in an error.

Nice catch, somehow missed that! Will fix, thanks.