On Mon, Oct 10, 2022 at 04:34:01PM +0300, Nikolay Borisov wrote: > The upcoming 'fixed-ram' feature would require qemu to write data at > specific offsets of the file. This is currently missing so this patch > adds it. I've chosen to implement it as a type-specific function rather > than plumb it through the generic channel interface as it relies on > being able to do seeks.
Well the base QIOChannel does have an 'io_seek' callback, so it already has some support for seeking. In addition to this QIOChannelFile class, the QIOChannelBuffer and QIOChannelNull classes could also allow seekable IO ops. So I think it is OK to add this to the QIOChannel base class, especially since your next patch adds a "SEEKABLE" feature flag. We have io_writev/io_readv callbacks. If we add io_pwritev/io_preadv callbacks too, we should validate that they exist when the SEEKABLE feature is marked present. > > Signed-off-by: Nikolay Borisov <nbori...@suse.com> > --- > include/io/channel-file.h | 5 +++++ > io/channel-file.c | 24 ++++++++++++++++++++++++ > 2 files changed, 29 insertions(+) > > diff --git a/include/io/channel-file.h b/include/io/channel-file.h > index 50e8eb113868..0a5d54f5e58e 100644 > --- a/include/io/channel-file.h > +++ b/include/io/channel-file.h > @@ -89,4 +89,9 @@ qio_channel_file_new_path(const char *path, > mode_t mode, > Error **errp); > > +ssize_t qio_channel_file_pwritev(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + off_t offset, > + Error **errp); > #endif /* QIO_CHANNEL_FILE_H */ > diff --git a/io/channel-file.c b/io/channel-file.c > index b67687c2aa64..da17d0a11ba7 100644 > --- a/io/channel-file.c > +++ b/io/channel-file.c > @@ -136,6 +136,30 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc, > return ret; > } > > +ssize_t qio_channel_file_pwritev(QIOChannel *ioc, > + const struct iovec *iov, > + size_t niov, > + off_t offset, > + Error **errp) > +{ > + QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc); > + ssize_t ret; > + > + retry: > + ret = pwritev(fioc->fd, iov, niov, offset); > + if (ret <= 0) { > + if (errno == EAGAIN) { > + return QIO_CHANNEL_ERR_BLOCK; > + } > + if (errno == EINTR) { > + goto retry; > + } > + error_setg_errno(errp, errno, "Unable to write to file"); > + return -1; > + } > + return ret; > +} > + > static int qio_channel_file_set_blocking(QIOChannel *ioc, > bool enabled, > Error **errp) > -- > 2.34.1 > With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|