Re: [PATCH 1/2 V2] kvm tools: Add scatter-gather variants of IO functions

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

 



Avi Kivity wrote:
On 04/16/2011 09:40 PM, Konstantin Khlebnikov wrote:

It might be better to add an helper function, something like this:

static inline void shift_iovec(const struct iovec **iov, int *iovcnt,
                    size_t nr, ssize_t *total, off_t *offset)
{
     while (nr>= (*iov)->iov_len) {
         nr -= (*iov)->iov_len;
         *total += (*iov)->iov_len;
         *offset += (*iov)->iov_len;
         *iovcnt--;
         *iov++;
     }
	if (nr) {
		(*iov)->iov_base += nr;
	  	(*iov)->iov_len -= nr;
	}
}


What if nr is nonzero when the loop terminates?  You need to update the
first iovec entry so you don't redo that segment.

Oh yes, it is simple (hunk above), so "const" from prototype must be removed,
while original syscalls declare iov argument as const.


ssize_t pwritev_in_full(int fd, const struct iovec *iov, int iovcnt,
off_t offset)
{
     ssize_t nr, total = 0;

     while (iovcnt) {
         nr = xpwritev(fd, iov, iovcnt, offset);
         if (nr<  0)
             return -1;
         if (nr == 0) {
             errno = ENOSPC;
             return -1;
         }
         shift_iovec(&iov,&iovcnt, nr,&total,&offset);
     }

     return total;
}
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux