[libvirt] virDomainInfo marshalling prolem

arnaud.champion at devatom.fr arnaud.champion at devatom.fr
Fri Oct 29 14:33:58 UTC 2010


Okay,

I have corrected to this structure :

public class DomainInfo
    {
        /// <summary>
        /// The running state, one of virDomainState.
        /// </summary>
        private byte state;
        /// <summary>
        /// The maximum memory in KBytes allowed.
        /// </summary>
        public ulong maxMem;
        /// <summary>
        /// The memory in KBytes used by the domain.
        /// </summary>
        public ulong memory;
        /// <summary>
        /// The number of virtual CPUs for the domain.
        /// </summary>
        public ushort nrVirtCpu;
        /// <summary>
        /// The CPU time used in nanoseconds.
        /// </summary>
        public ulong cpuTime;
        /// <summary>
        /// The running state, one of virDomainState.
        /// </summary>
        public DomainState State { get { return (DomainState)state; } }
    }

And now it works in 64bits but not in 32bits :S

Arnaud

--------------------------------------------------
From: "Matthias Bolte" <matthias.bolte at googlemail.com>
Sent: Friday, October 29, 2010 4:19 PM
To: <arnaud.champion at devatom.fr>
Cc: <libvir-list at redhat.com>
Subject: Re: [libvirt] virDomainInfo marshalling prolem

> 2010/10/29  <arnaud.champion at devatom.fr>:
>> Hi,
>>
>> I am working on the marshaling of the virDomainInfo structure. I have
>> marshalled it in this way :
>>
>>
>> ///
>>
>> <summary>
>>
>> /// Structure to handle domain informations
>>
>> /// </summary>
>>
>> [
>>
>> StructLayout(LayoutKind.Sequential)]
>>
>> public class DomainInfo
>>
>> {
>>
>>     /// <summary>
>>     /// The running state, one of virDomainState.
>>     /// </summary>
>>     private Byte state;
>>     /// <summary>
>>     /// The maximum memory in KBytes allowed.
>>     /// </summary>
>>     public int maxMem;
>>     /// <summary>
>>     /// The memory in KBytes used by the domain.
>>     /// </summary>
>>     public int memory;
>>     /// <summary>
>>     /// The number of virtual CPUs for the domain.
>>     /// </summary>
>>     public short nrVirtCpu;
>>     /// <summary>
>>     /// The CPU time used in nanoseconds.
>>     /// </summary>
>>     public long cpuTime;
>>     /// <summary>
>>     /// The running state, one of virDomainState.
>>     /// </summary>
>>     public DomainState State { get { return (DomainState)state; } }
>>
>> }
>>
>> It work fine in 32 bits, but not in 64 bits, it seems that packing in 64
>> bits is different so infos are not in order. Am I right ?
>>
>
> In the struct looks like this
>
> struct _virDomainInfo {
>    unsigned char state;        /* the running state, one of virDomainState 
> */
>    unsigned long maxMem;       /* the maximum memory in KBytes allowed */
>    unsigned long memory;       /* the memory in KBytes used by the domain 
> */
>    unsigned short nrVirtCpu;   /* the number of virtual CPUs for the 
> domain */
>    unsigned long long cpuTime; /* the CPU time used in nanoseconds */
> };
>
> but you mapped unsigned long to int. First of all you should map this
> to an unsigned type. You also lost the unsigned for some other
> members.
>
> The problem probably is that long in C is 32bit on a 32bit platform an
> 64bit on a 64bit platform. You mapped it to int that is always 32bit
> in C#, when I looked it up correctly.
>
> Matthias 





More information about the libvir-list mailing list