Re: [patch] fake pv drivers installation on xen

2017-07-17 Thread Maxim Khitrov
On Mon, Jul 17, 2017 at 3:40 PM, Mike Belopuhov  wrote:
> On Mon, Jul 17, 2017 at 14:32 -0400, Maxim Khitrov wrote:
>> On Wed, Jan 18, 2017 at 2:16 PM, Dinar Talypov  wrote:
>> > I use Xenserver 7.0 with xencenter management console.
>> > without it doesn't allow shutdown or reboot.
>> > Anyway I'll try with hostctl.
>> >
>> > Thanks.
>>
>> Were you able to get this working with hostctl? I'm running OpenBSD
>> 6.1 amd64 on XenServer 7.0. When I run any hostctl command, such as
>> `hostctl device/vif/0/mac`, I get the following error:
>>
>> hostctl: ioctl: Device not configured
>>
>> During boot, I see these messages:
>>
>> pvbus0 at mainbus0: Hyper-V 0.0, Xen 4.6
>> xen0 at pvbus0: features 0x2705, 32 grant table frames, event channel 3
>> xbf0 at xen0 backend 0 channel 8: disk
>>
>
> You need to disable viridian compatibility in your Xenserver.
>
>> Running `hostctl -t` returns "/dev/pvbus0: Hyper-V"
>>
>
> That's because Xenserver announces Hyper-V compatibility layer
> (called viridian) before Xen for whatever reason.  You need to
> do "cd /dev; ./MAKEDEV pvbus1" and then use "hostctl -f /dev/pvbus1"
> with your commands (I assume -- never tried a Xenserver myself).
>
>> Any tips on getting hostctl to work?
>
> See above.  The easiest is probably just to disable viridian :)

Disabling viridian worked, thanks! For anyone else interested in doing
this, run the following command on your XenServer host:

xe vm-param-set uuid= platform:viridian=false

After that, you can add these commands to /etc/rc.local:

ostype=$(sysctl -n kern.ostype)
osrelease=$(sysctl -n kern.osrelease)

# PV driver version
hostctl attr/PVAddons/MajorVersion 6
hostctl attr/PVAddons/MinorVersion 2
hostctl attr/PVAddons/MicroVersion 0
hostctl attr/PVAddons/BuildVersion 76888
hostctl attr/PVAddons/Installed 1

# OS version
hostctl data/os_name "$ostype $osrelease"
hostctl data/os_uname $osrelease
hostctl data/os_distro $ostype

# Update XenStore
hostctl data/updated 1

-Max



Re: [patch] fake pv drivers installation on xen

2017-07-17 Thread Mike Belopuhov
On Mon, Jul 17, 2017 at 14:32 -0400, Maxim Khitrov wrote:
> On Wed, Jan 18, 2017 at 2:16 PM, Dinar Talypov  wrote:
> > I use Xenserver 7.0 with xencenter management console.
> > without it doesn't allow shutdown or reboot.
> > Anyway I'll try with hostctl.
> >
> > Thanks.
> 
> Were you able to get this working with hostctl? I'm running OpenBSD
> 6.1 amd64 on XenServer 7.0. When I run any hostctl command, such as
> `hostctl device/vif/0/mac`, I get the following error:
> 
> hostctl: ioctl: Device not configured
> 
> During boot, I see these messages:
> 
> pvbus0 at mainbus0: Hyper-V 0.0, Xen 4.6
> xen0 at pvbus0: features 0x2705, 32 grant table frames, event channel 3
> xbf0 at xen0 backend 0 channel 8: disk
>

You need to disable viridian compatibility in your Xenserver.

> Running `hostctl -t` returns "/dev/pvbus0: Hyper-V"
>

That's because Xenserver announces Hyper-V compatibility layer
(called viridian) before Xen for whatever reason.  You need to
do "cd /dev; ./MAKEDEV pvbus1" and then use "hostctl -f /dev/pvbus1"
with your commands (I assume -- never tried a Xenserver myself).

> Any tips on getting hostctl to work?

See above.  The easiest is probably just to disable viridian :)

> Also, do the values persist
> across reboots or do they need to be set via rc.d?
> 

No, they're not.



Re: [patch] fake pv drivers installation on xen

2017-07-17 Thread Maxim Khitrov
On Wed, Jan 18, 2017 at 2:16 PM, Dinar Talypov  wrote:
> I use Xenserver 7.0 with xencenter management console.
> without it doesn't allow shutdown or reboot.
> Anyway I'll try with hostctl.
>
> Thanks.

Were you able to get this working with hostctl? I'm running OpenBSD
6.1 amd64 on XenServer 7.0. When I run any hostctl command, such as
`hostctl device/vif/0/mac`, I get the following error:

hostctl: ioctl: Device not configured

During boot, I see these messages:

pvbus0 at mainbus0: Hyper-V 0.0, Xen 4.6
xen0 at pvbus0: features 0x2705, 32 grant table frames, event channel 3
xbf0 at xen0 backend 0 channel 8: disk

Running `hostctl -t` returns "/dev/pvbus0: Hyper-V"

Any tips on getting hostctl to work? Also, do the values persist
across reboots or do they need to be set via rc.d?

-Max



Re: [patch] fake pv drivers installation on xen

2017-01-18 Thread Dinar Talypov
I use Xenserver 7.0 with xencenter management console.
without it doesn't allow shutdown or reboot.
Anyway I'll try with hostctl.

Thanks.

2017-01-18 21:53 GMT+03:00 Mike Belopuhov :

> On Wed, Jan 18, 2017 at 21:23 +0300, Dinar Talypov wrote:
> > +void
> > +xen_inform_host(struct xen_softc *sc)
> > +{
> > + char *os_name;
> > +
> > + /* Fake PV drivers version */
> > + xs_setnum(sc, "attr/PVAddons", "MajorVersion", 6);
> > + xs_setnum(sc, "attr/PVAddons", "MinorVersion", 2);
> > + xs_setnum(sc, "attr/PVAddons", "MicroVersion", 0);
> > + xs_setnum(sc, "attr/PVAddons", "BuildVersion", 76888);
> > + xs_setnum(sc, "attr/PVAddons", "Installed", 1);
> > +
> > + /* Set OS version */
> > + snprintf(os_name, sizeof((char *)ostype) + sizeof((char
> *)osrelease),
> > + "%s %s", ostype, osrelease);
>
> and btw, here you're corrupting kernel memory since os_name is
> an uninitialized pointer :-)
>


Re: [patch] fake pv drivers installation on xen

2017-01-18 Thread Mike Belopuhov
On Wed, Jan 18, 2017 at 21:23 +0300, Dinar Talypov wrote:
> +void
> +xen_inform_host(struct xen_softc *sc)
> +{
> + char *os_name;
> + 
> + /* Fake PV drivers version */
> + xs_setnum(sc, "attr/PVAddons", "MajorVersion", 6);
> + xs_setnum(sc, "attr/PVAddons", "MinorVersion", 2);
> + xs_setnum(sc, "attr/PVAddons", "MicroVersion", 0);
> + xs_setnum(sc, "attr/PVAddons", "BuildVersion", 76888);
> + xs_setnum(sc, "attr/PVAddons", "Installed", 1);
> +
> + /* Set OS version */
> + snprintf(os_name, sizeof((char *)ostype) + sizeof((char *)osrelease),
> + "%s %s", ostype, osrelease);

and btw, here you're corrupting kernel memory since os_name is
an uninitialized pointer :-)



Re: [patch] fake pv drivers installation on xen

2017-01-18 Thread Mike Belopuhov
On Wed, Jan 18, 2017 at 21:23 +0300, Dinar Talypov wrote:
> 
> Hi,
>

Privet, Dinar!

> The patch below fakes pv drivers installation.
> Version numbers are taken from FreeBSD sysutils/xe-guest-utilities.
> With this xen allows reboot or shutdown OpenBSD guest.
>

Which Xen version or what environment requires such properties?
Neither plain Xen 4.5+ on Ubuntu nor EC2 version have the "attr"
subtree and you can reboot and/or shutdown OpenBSD guests there
without any issues (for instance via xl on Ubuntu).

> Index: sys/dev/pv/xen.c
> ===
> RCS file: /cvs/src/sys/dev/pv/xen.c,v
> retrieving revision 1.71
> diff -u -p -u -r1.71 xen.c
> --- sys/dev/pv/xen.c  10 Jan 2017 17:16:39 -  1.71
> +++ sys/dev/pv/xen.c  18 Jan 2017 18:05:27 -
> @@ -35,6 +35,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -75,6 +76,7 @@ voidxen_disable_emulated_devices(struct
>  int  xen_match(struct device *, void *, void *);
>  void xen_attach(struct device *, struct device *, void *);
>  void xen_deferred(struct device *);
> +void xen_inform_host(struct xen_softc *);
>  void xen_control(void *);
>  void xen_hotplug(void *);
>  void xen_resume(struct device *);
> @@ -194,6 +196,29 @@ xen_deferred(struct device *self)
>   xen_control, sc))
>   printf("%s: failed to setup shutdown control watch\n",
>   sc->sc_dev.dv_xname);
> + xen_inform_host(sc);
> +}
> +void
> +xen_inform_host(struct xen_softc *sc)
> +{
> + char *os_name;
> + 
> + /* Fake PV drivers version */
> + xs_setnum(sc, "attr/PVAddons", "MajorVersion", 6);
> + xs_setnum(sc, "attr/PVAddons", "MinorVersion", 2);
> + xs_setnum(sc, "attr/PVAddons", "MicroVersion", 0);
> + xs_setnum(sc, "attr/PVAddons", "BuildVersion", 76888);

Where did you get this build version number from?
It looks rather arbitrary.

> + xs_setnum(sc, "attr/PVAddons", "Installed", 1);
> +
> + /* Set OS version */
> + snprintf(os_name, sizeof((char *)ostype) + sizeof((char *)osrelease),
> + "%s %s", ostype, osrelease);
> + xs_setprop(sc, "data", "os_name", (char *)os_name, strlen(os_name));
> + xs_setprop(sc, "data", "os_uname", (char *)osrelease, 
> strlen(osrelease));
> + xs_setprop(sc, "data", "os_distro", (char *)ostype, strlen(ostype));
> +
> + /* Update xenstore */
> + xs_setnum(sc, "data", "updated", 1);
>  }
>  
>  void
> 

In any case you can set these values yourself with hostctl(8),
i.e. 'hostctl attr/PVAddons/BuildVersion 123456'.  There should
be no need to do that from the kernel.