qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [Xen-devel] [PATCH V4 05/10] Introduce HostPCIDevice to


From: Anthony PERARD
Subject: Re: [Qemu-devel] [Xen-devel] [PATCH V4 05/10] Introduce HostPCIDevice to access a pci device on the host.
Date: Wed, 23 Nov 2011 18:25:07 +0000

On Fri, Nov 18, 2011 at 15:06, Konrad Rzeszutek Wilk
<address@hidden> wrote:
>> +static int host_pci_config_read(HostPCIDevice *d, int pos, void *buf, int 
>> len)
>> +{
>> +    int fd = host_pci_config_fd(d);
>> +    int res = 0;
>> +
>> +again:
>> +    res = pread(fd, buf, len, pos);
>> +    if (res != len) {
>> +        if (res < 0 && (errno == EINTR || errno == EAGAIN)) {
>> +            goto again;
>> +        }
>> +        fprintf(stderr, "host_pci_config: read failed: %s (fd: %i)\n",
>> +                strerror(errno), fd);
>> +        return -errno;
>> +    }
>> +    return 0;
>> +}
>> +static int host_pci_config_write(HostPCIDevice *d,
>> +                                 int pos, const void *buf, int len)
>> +{
>> +    int fd = host_pci_config_fd(d);
>> +    int res = 0;
>> +
>> +again:
>> +    res = pwrite(fd, buf, len, pos);
>> +    if (res != len) {
>> +        if (res < 0 && (errno == EINTR || errno == EAGAIN)) {
>> +            goto again;
>> +        }
>> +        fprintf(stderr, "host_pci_config: write failed: %s\n",
>> +                strerror(errno));
>> +        return -errno;
>> +    }
>> +    return 0;
>> +}
>> +
>> +int host_pci_get_byte(HostPCIDevice *d, int pos, uint8_t *p)
>> +{
>> +  uint8_t buf;
>> +  if (host_pci_config_read(d, pos, &buf, 1)) {
>> +      return -1;
>
> Would it make sense to use the nice enum you decleraed at the
> top of the file?  Or not?

I should probably return -errno instead, I mean the return value of
host_pci_config_read/write.

I just introduce the enum to have a differente value than -errno for
some internal function (get_ressource/get_hex_value), so I don't think
that the enum can really by used outside of this file, yet.

(I will change the rest of the patch as you sugest in your comment)

Thanks,

-- 
Anthony PERARD



reply via email to

[Prev in Thread] Current Thread [Next in Thread]