Re: [libvirt RFCv4 04/20] runio: add arguments to extend use beyond just stdin and stdout

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

 



On Thu, Apr 28, 2022 at 06:24:11PM +0200, Claudio Fontana wrote:
> On 4/28/22 2:54 PM, Daniel P. Berrangé wrote:
> > On Wed, Apr 27, 2022 at 11:13:23PM +0200, Claudio Fontana wrote:
> >> add arguments to runio to allow read/write from/to arbitrary
> >> file descriptors, as opposed to just stdin and stdout.
> >>
> >> Signed-off-by: Claudio Fontana <cfontana@xxxxxxx>
> >> ---
> >>  src/util/iohelper.c |  2 +-
> >>  src/util/runio.c    | 10 +++++-----
> >>  src/util/runio.h    | 17 ++++++++++++++++-
> >>  3 files changed, 22 insertions(+), 7 deletions(-)
> >>
> >> diff --git a/src/util/iohelper.c b/src/util/iohelper.c
> >> index 5a0098542e..93674c1e2f 100644
> >> --- a/src/util/iohelper.c
> >> +++ b/src/util/iohelper.c
> >> @@ -96,7 +96,7 @@ main(int argc, char **argv)
> >>          usage(EXIT_FAILURE);
> >>      }
> >>  
> >> -    if (fd < 0 || runIO(path, fd, oflags) < 0)
> >> +    if (fd < 0 || runIO(path, fd, oflags, STDIN_FILENO, STDOUT_FILENO) < 0)
> >>          goto error;
> >>  
> >>      return 0;
> >> diff --git a/src/util/runio.c b/src/util/runio.c
> >> index a7b902af7e..f42acddae9 100644
> >> --- a/src/util/runio.c
> >> +++ b/src/util/runio.c
> >> @@ -134,7 +134,7 @@ runIOCopy(const struct runIOParams p)
> >>  
> >>  
> >>  off_t
> >> -runIO(const char *path, int fd, int oflags)
> >> +runIO(const char *path, int fd, int oflags, int in_fd, int out_fd)
> > 
> > This is getting rather wierd as a signature.
> > 
> > If O_RDONLY, then in_fd is ignored, 'fd' is input.
> > 
> > If O_WRONLY, then out_fd is ignored, 'fd' is output
> > 
> > What about instead simply :
> > 
> >    runIO(const char *srcpath, int srcfd,
> >          const char *dstpath, int dstfd)
> > 
> > so there's no read vs write distinction at all.
> 
> maybe I am a bit confused/tired, but I don't see how this would work,
> which side one of those is the disk, where we want to check for S_ISBLK and O_DIRECT, and buffer accordingly?

We call fstat on the FD, we'll know which FD is a pipe/socket vs
which FD is a file/blockdev.  If we call fcntl(GET_FL) we can also
discover if O_DIRECT is turned on or not.

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 :|




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux