[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [win-pv-devel] [PATCH 3/6] Add XenIfaceDevice



> -----Original Message-----
> From: win-pv-devel [mailto:win-pv-devel-bounces@xxxxxxxxxxxxxxxxxxxx] On
> Behalf Of Owen Smith
> Sent: 05 July 2016 11:38
> To: win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> Cc: Owen Smith
> Subject: [win-pv-devel] [PATCH 3/6] Add XenIfaceDevice
> 
> XenIfaceDevice is a CDevice subclass that abstracts the IOCTL
> interface by managing the conversion to/from IOCTL inputs/outputs.
> 
> Signed-off-by: Owen Smith <owen.smith@xxxxxxxxxx>

Acked-by: Paul Durrant <paul.durrant@xxxxxxxxxx>

> ---
>  src/xenagent/service.cpp         |   2 +-
>  src/xenagent/service.h           |   1 +
>  src/xenagent/xenifacedevice.cpp  | 153
> +++++++++++++++++++++++++++++++++++++++
>  src/xenagent/xenifacedevice.h    |  64 ++++++++++++++++
>  vs2012/xenagent/xenagent.vcxproj |   2 +
>  vs2013/xenagent/xenagent.vcxproj |   2 +
>  6 files changed, 223 insertions(+), 1 deletion(-)
>  create mode 100644 src/xenagent/xenifacedevice.cpp
>  create mode 100644 src/xenagent/xenifacedevice.h
> 
> diff --git a/src/xenagent/service.cpp b/src/xenagent/service.cpp
> index fec8e95..bd085f6 100644
> --- a/src/xenagent/service.cpp
> +++ b/src/xenagent/service.cpp
> @@ -171,7 +171,7 @@ CXenAgent::~CXenAgent()
> 
>  /*virtual*/ CDevice* CXenAgent::Create(const wchar_t* path)
>  {
> -    return new CDevice(path);
> +    return new CXenIfaceDevice(path);
>  }
> 
>  /*virtual*/ void CXenAgent::OnDeviceAdded(CDevice* dev)
> diff --git a/src/xenagent/service.h b/src/xenagent/service.h
> index ba3f430..e31dcfd 100644
> --- a/src/xenagent/service.h
> +++ b/src/xenagent/service.h
> @@ -39,6 +39,7 @@
>  #define SVC_DESC "Monitors and provides various metrics to XenStore"
> 
>  #include "devicelist.h"
> +#include "xenifacedevice.h"
> 
>  class CXenAgent : public IDeviceCreator
>  {
> diff --git a/src/xenagent/xenifacedevice.cpp
> b/src/xenagent/xenifacedevice.cpp
> new file mode 100644
> index 0000000..16189d2
> --- /dev/null
> +++ b/src/xenagent/xenifacedevice.cpp
> @@ -0,0 +1,153 @@
> +/* Copyright (c) Citrix Systems Inc.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms,
> + * with or without modification, are permitted provided
> + * that the following conditions are met:
> + *
> + * *   Redistributions of source code must retain the above
> + *     copyright notice, this list of conditions and the
> + *     following disclaimer.
> + * *   Redistributions in binary form must reproduce the above
> + *     copyright notice, this list of conditions and the
> + *     following disclaimer in the documentation and/or other
> + *     materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
> + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#include <windows.h>
> +#include "xenifacedevice.h"
> +#include "devicelist.h"
> +#include "xeniface_ioctls.h"
> +
> +CXenIfaceDevice::CXenIfaceDevice(const wchar_t* path) : CDevice(path)
> +{}
> +
> +/*virtual*/ CXenIfaceDevice::~CXenIfaceDevice()
> +{}
> +
> +// store interface
> +bool CXenIfaceDevice::StoreRead(const std::string& path, std::string&
> value)
> +{
> +    DWORD   bytes(0);
> +    char*   buffer;
> +    bool    result;
> +
> +    Ioctl(IOCTL_XENIFACE_STORE_READ,
> +          (void*)path.c_str(), (DWORD)path.length() + 1,
> +          NULL, 0,
> +          &bytes);
> +
> +    buffer = new char[bytes + 1];
> +    if (buffer == NULL)
> +        return false;
> +
> +    result = Ioctl(IOCTL_XENIFACE_STORE_READ,
> +                   (void*)path.c_str(), (DWORD)path.length() + 1,
> +                   buffer, bytes);
> +
> +    buffer[bytes] = 0;
> +    if (result)
> +        value = buffer;
> +
> +    delete [] buffer;
> +    return result;
> +}
> +
> +bool CXenIfaceDevice::StoreWrite(const std::string& path, const
> std::string& value)
> +{
> +    bool   result;
> +    size_t length = path.length() + 1 + value.length() + 1 + 1;
> +    char*  buffer = new char[length];
> +    if (buffer == NULL)
> +        return false;
> +
> +    memcpy(buffer, path.c_str(), path.length());
> +    buffer[path.length()] = 0;
> +
> +    memcpy(buffer + path.length() + 1, value.c_str(), value.length());
> +    buffer[path.length() + 1 + value.length()] = 0;
> +    buffer[length - 1] = 0;
> +
> +    result = Ioctl(IOCTL_XENIFACE_STORE_WRITE, buffer, (DWORD)length,
> NULL, 0);
> +    delete [] buffer;
> +    return result;
> +}
> +
> +bool CXenIfaceDevice::StoreRemove(const std::string& path)
> +{
> +    return Ioctl(IOCTL_XENIFACE_STORE_REMOVE,
> +                 (void*)path.c_str(), (DWORD)path.length() + 1,
> +                 NULL, 0);
> +}
> +
> +bool CXenIfaceDevice::StoreAddWatch(const std::string& path, HANDLE
> evt, void** ctxt)
> +{
> +    XENIFACE_STORE_ADD_WATCH_IN  in  = { (PCHAR)path.c_str(),
> (DWORD)path.length() + 1, evt };
> +    XENIFACE_STORE_ADD_WATCH_OUT out = { NULL };
> +    if (!Ioctl(IOCTL_XENIFACE_STORE_ADD_WATCH,
> +               &in, (DWORD)sizeof(in),
> +               &out, (DWORD)sizeof(out)))
> +        return false;
> +    *ctxt = out.Context;
> +    return true;
> +}
> +
> +bool CXenIfaceDevice::StoreRemoveWatch(void* ctxt)
> +{
> +    XENIFACE_STORE_REMOVE_WATCH_IN in = { ctxt };
> +    return Ioctl(IOCTL_XENIFACE_STORE_REMOVE_WATCH,
> +                 &in, (DWORD)sizeof(in),
> +                 NULL, 0);
> +}
> +
> +// suspend interface
> +bool CXenIfaceDevice::SuspendRegister(HANDLE evt, void** ctxt)
> +{
> +    XENIFACE_SUSPEND_REGISTER_IN  in  = { evt };
> +    XENIFACE_SUSPEND_REGISTER_OUT out = { NULL };
> +    if (!Ioctl(IOCTL_XENIFACE_SUSPEND_REGISTER,
> +               &in, (DWORD)sizeof(in),
> +               &out, (DWORD)sizeof(out)))
> +        return false;
> +    *ctxt = out.Context;
> +    return true;
> +}
> +
> +bool CXenIfaceDevice::SuspendDeregister(void* ctxt)
> +{
> +    XENIFACE_SUSPEND_REGISTER_OUT in = { ctxt };
> +    return Ioctl(IOCTL_XENIFACE_SUSPEND_DEREGISTER,
> +                 &in, (DWORD)sizeof(in),
> +                 NULL, 0);
> +}
> +
> +// sharedinfo interface
> +bool CXenIfaceDevice::SharedInfoGetTime(FILETIME* time)
> +{
> +    return Ioctl(IOCTL_XENIFACE_SHAREDINFO_GET_TIME,
> +                 NULL, 0,
> +                 time, sizeof(FILETIME));
> +}
> +
> +// logging
> +bool CXenIfaceDevice::Log(const std::string& msg)
> +{
> +    return Ioctl(IOCTL_XENIFACE_LOG,
> +                 (void*)msg.c_str(), (DWORD)msg.length() + 1,
> +                 NULL, 0);
> +}
> diff --git a/src/xenagent/xenifacedevice.h b/src/xenagent/xenifacedevice.h
> new file mode 100644
> index 0000000..ee0104c
> --- /dev/null
> +++ b/src/xenagent/xenifacedevice.h
> @@ -0,0 +1,64 @@
> +/* Copyright (c) Citrix Systems Inc.
> + * All rights reserved.
> + *
> + * Redistribution and use in source and binary forms,
> + * with or without modification, are permitted provided
> + * that the following conditions are met:
> + *
> + * *   Redistributions of source code must retain the above
> + *     copyright notice, this list of conditions and the
> + *     following disclaimer.
> + * *   Redistributions in binary form must reproduce the above
> + *     copyright notice, this list of conditions and the
> + *     following disclaimer in the documentation and/or other
> + *     materials provided with the distribution.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
> + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
> + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
> + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
> + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
> + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
> + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
> + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
> + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
> + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
> + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
> + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
> + * SUCH DAMAGE.
> + */
> +
> +#ifndef __XENAGENT_XENIFACEDEVICE_H__
> +#define __XENAGENT_XENIFACEDEVICE_H__
> +
> +#include <windows.h>
> +#include <string>
> +#include "devicelist.h"
> +
> +class CXenIfaceDevice : public CDevice
> +{
> +public:
> +    CXenIfaceDevice(const wchar_t* path);
> +    virtual ~CXenIfaceDevice();
> +
> +public: // store interface
> +    bool StoreRead(const std::string& path, std::string& value);
> +    bool StoreWrite(const std::string& path, const std::string& value);
> +    bool StoreRemove(const std::string& path);
> +    bool StoreAddWatch(const std::string& path, HANDLE evt, void** ctxt);
> +    bool StoreRemoveWatch(void* ctxt);
> +
> +public: // suspend interface
> +    bool SuspendRegister(HANDLE evt, void** ctxt);
> +    bool SuspendDeregister(void* ctxt);
> +
> +public: // sharedinfo interface
> +    bool SharedInfoGetTime(FILETIME* time);
> +
> +public: // logging
> +    bool Log(const std::string& msg);
> +};
> +
> +#endif
> +
> diff --git a/vs2012/xenagent/xenagent.vcxproj
> b/vs2012/xenagent/xenagent.vcxproj
> index 6c9c91c..37db3fd 100644
> --- a/vs2012/xenagent/xenagent.vcxproj
> +++ b/vs2012/xenagent/xenagent.vcxproj
> @@ -195,10 +195,12 @@
>    <ItemGroup>
>      <ClCompile Include="..\..\src\xenagent\service.cpp"/>
>      <ClCompile Include="..\..\src\xenagent\devicelist.cpp"/>
> +    <ClCompile Include="..\..\src\xenagent\xenifacedevice.cpp"/>
>    </ItemGroup>
>    <ItemGroup>
>      <ClInclude Include="..\..\src\xenagent\service.h" />
>      <ClInclude Include="..\..\src\xenagent\devicelist.h" />
> +    <ClInclude Include="..\..\src\xenagent\xenifacedevice.h" />
>    </ItemGroup>
>    <ItemGroup>
>      <CustomBuild Include="..\..\src\xenagent\messages.mc">
> diff --git a/vs2013/xenagent/xenagent.vcxproj
> b/vs2013/xenagent/xenagent.vcxproj
> index d312626..f5c1730 100644
> --- a/vs2013/xenagent/xenagent.vcxproj
> +++ b/vs2013/xenagent/xenagent.vcxproj
> @@ -199,10 +199,12 @@
>    <ItemGroup>
>      <ClCompile Include="..\..\src\xenagent\service.cpp"/>
>      <ClCompile Include="..\..\src\xenagent\devicelist.cpp"/>
> +    <ClCompile Include="..\..\src\xenagent\xenifacedevice.cpp"/>
>    </ItemGroup>
>    <ItemGroup>
>      <ClInclude Include="..\..\src\xenagent\service.h" />
>      <ClInclude Include="..\..\src\xenagent\devicelist.h" />
> +    <ClInclude Include="..\..\src\xenagent\xenifacedevice.h" />
>    </ItemGroup>
>    <ItemGroup>
>      <CustomBuild Include="..\..\src\xenagent\xenagent.mc">
> --
> 1.9.4.msysgit.1
> 
> 
> _______________________________________________
> win-pv-devel mailing list
> win-pv-devel@xxxxxxxxxxxxxxxxxxxx
> http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
_______________________________________________
win-pv-devel mailing list
win-pv-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.