Quantcast

highlevel read / write return values

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

highlevel read / write return values

Antonio SJ Musumeci
fuse.h states

/** Read data from an open file
 *
 * Read should return exactly the number of bytes requested except
 * on EOF or error, otherwise the rest of the data will be
 * substituted with zeroes.      An exception to this is when the
 * 'direct_io' mount option is specified, in which case the return
 * value of the read system call will reflect the return value of
 * this operation.

Does this mean that the passthrough[0] example is wrong/incomplete? If you always return the size asked for how does the system know how much of the last read is appropriate to send through?

It should be in effect:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;
else if(res > 0)
  res = size;

return res;

and with direct_io it'd be:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;

return res;


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: highlevel read / write return values

Michael Theall-2
For non-direct-io, the kernel replies to the user depending on the filesize your fuse server gives with lookup/getattr/readdirplus. If you return a short count, the kernel might send uninitialized data. If the user does a read past end-of-file, you'll get a getattr first to verify whether there is more data. If you return zero, I believe that will be followed by a getattr to verify the file size.

Regards,
Michael Theall

On Mon, Dec 19, 2016, 18:44 Antonio SJ Musumeci <[hidden email]> wrote:
fuse.h states

/** Read data from an open file
 *
 * Read should return exactly the number of bytes requested except
 * on EOF or error, otherwise the rest of the data will be
 * substituted with zeroes.      An exception to this is when the
 * 'direct_io' mount option is specified, in which case the return
 * value of the read system call will reflect the return value of
 * this operation.

Does this mean that the passthrough[0] example is wrong/incomplete? If you always return the size asked for how does the system know how much of the last read is appropriate to send through?

It should be in effect:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;
else if(res > 0)
  res = size;

return res;

and with direct_io it'd be:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;

return res;

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: highlevel read / write return values

Antonio SJ Musumeci
Thanks. I figured it was something like that.

The examples should probably be changed or noted that it should only be used with direct_io.

On Mon, Dec 19, 2016 at 9:18 PM, Michael Theall <[hidden email]> wrote:
For non-direct-io, the kernel replies to the user depending on the filesize your fuse server gives with lookup/getattr/readdirplus. If you return a short count, the kernel might send uninitialized data. If the user does a read past end-of-file, you'll get a getattr first to verify whether there is more data. If you return zero, I believe that will be followed by a getattr to verify the file size.

Regards,
Michael Theall

On Mon, Dec 19, 2016, 18:44 Antonio SJ Musumeci <[hidden email]> wrote:
fuse.h states

/** Read data from an open file
 *
 * Read should return exactly the number of bytes requested except
 * on EOF or error, otherwise the rest of the data will be
 * substituted with zeroes.      An exception to this is when the
 * 'direct_io' mount option is specified, in which case the return
 * value of the read system call will reflect the return value of
 * this operation.

Does this mean that the passthrough[0] example is wrong/incomplete? If you always return the size asked for how does the system know how much of the last read is appropriate to send through?

It should be in effect:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;
else if(res > 0)
  res = size;

return res;

and with direct_io it'd be:

res = pread(fd,buf,size,offset);
if(res == -1)
  res = -errno;

return res;

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: highlevel read / write return values

Miklos Szeredi
In reply to this post by Antonio SJ Musumeci
On Tue, Dec 20, 2016 at 12:54 AM, Antonio SJ Musumeci
<[hidden email]> wrote:

> fuse.h states
>
> /** Read data from an open file
>  *
>  * Read should return exactly the number of bytes requested except
>  * on EOF or error, otherwise the rest of the data will be
>  * substituted with zeroes.      An exception to this is when the
>  * 'direct_io' mount option is specified, in which case the return
>  * value of the read system call will reflect the return value of
>  * this operation.
>
> Does this mean that the passthrough[0] example is wrong/incomplete? If you
> always return the size asked for how does the system know how much of the
> last read is appropriate to send through?
>
> It should be in effect:
>
> res = pread(fd,buf,size,offset);
> if(res == -1)
>   res = -errno;
> else if(res > 0)
>   res = size;
>
> return res;

Definitely not.  That would possibly send uninitialized bytes.

The example should be fine, because normally reads do confirm to the
above specification (they return size except in case of error or eof).

Thanks,
Miklos

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: highlevel read / write return values

Antonio SJ Musumeci
In which setting? The snippet quoted below returns 'size requested' unless error or eof (0). The example (and my other snippet) returns 'size read' unless error or eof(0).

On Dec 20, 2016 4:34 AM, "Miklos Szeredi" <[hidden email]> wrote:
On Tue, Dec 20, 2016 at 12:54 AM, Antonio SJ Musumeci
<[hidden email]> wrote:
> fuse.h states
>
> /** Read data from an open file
>  *
>  * Read should return exactly the number of bytes requested except
>  * on EOF or error, otherwise the rest of the data will be
>  * substituted with zeroes.      An exception to this is when the
>  * 'direct_io' mount option is specified, in which case the return
>  * value of the read system call will reflect the return value of
>  * this operation.
>
> Does this mean that the passthrough[0] example is wrong/incomplete? If you
> always return the size asked for how does the system know how much of the
> last read is appropriate to send through?
>
> It should be in effect:
>
> res = pread(fd,buf,size,offset);
> if(res == -1)
>   res = -errno;
> else if(res > 0)
>   res = size;
>
> return res;

Definitely not.  That would possibly send uninitialized bytes.

The example should be fine, because normally reads do confirm to the
above specification (they return size except in case of error or eof).

Thanks,
Miklos


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/intel
--
fuse-devel mailing list
To unsubscribe or subscribe, visit https://lists.sourceforge.net/lists/listinfo/fuse-devel
Loading...