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

Re: [Xen-devel] [PATCH V5 2/7] libxl_read_file_contents: add new entry to read sysfs file




>>> On 6/29/2015 at 06:52 PM, in message
<21905.9050.452111.208124@xxxxxxxxxxxxxxxxxxxxxxxx>, Ian Jackson
<Ian.Jackson@xxxxxxxxxxxxx> wrote: 
> Chun Yan Liu writes ("Re: [PATCH V5 2/7] libxl_read_file_contents: add new  
> entry to read sysfs file"): 
> > On 6/26/2015 at 09:05 PM, in message 
> > <21901.20009.85407.581628@xxxxxxxxxxxxxxxxxxxxxxxx>, Ian Jackson 
> > <Ian.Jackson@xxxxxxxxxxxxx> wrote:  
> > > But please feel free to explain why I'm wrong.  
> >  
> > You are right. I'm confused about the original logic. The original code 
> > doesn't consider this case (size bigger than requested) at all. 
>  
> Indeed.  The original code assumes that files don't change size, and 
> only detects them shrinking because that causes a short read which it 
> has deal with somehow. 
>  
> But if we are intending to use this with sysfs files, where the 
> reported size is known to be wrong, it seems to me that we should be 
> more proactive.

If only for sysfs files, the bigger size problem should never happens, since 
sysfs
system is not like normal file system, user won't be able to change the size.

Reference from following link:
http://www.makelinux.net/books/lkd2/ch17lev1sec8

[ The sysfs filesystem is an in-memory virtual filesystem that provides a view
of the kobject object hierarchy. It enables users to view the device topology of
their system as a simple filesystem. Using attributes, kobjects can export files
that allow kernel variables to be read from and optionally written to.
......

The show() method is invoked on read. It must copy the value of the attribute
given by attr into the buffer provided by buffer. The buffer is PAGE_SIZE bytes
in length; on x86, PAGE_SIZE is 4096 bytes. The function should return the size
in bytes of data actually written into buffer on success or a negative error
code on failure.

The store() method is invoked on write. It must read the size bytes from buffer
into the variable represented by the attribute attr. The size of the buffer is
always PAGE_SIZE or smaller. The function should return the size in bytes of
data read from buffer on success or a negative error code on failure.]

- Chunyan

>  
> > So, we need to add a check if (rs == datalen && read end of file), 
> > if not, means bigger than requested, report error. 
>  
> To detect a growing file it will be necessary to actually attempt to 
> read at least one byte more than expected.  This is probably done most 
> conveniently by making the buffer one byte bigger, too. 
>  
> Ian. 
>  
>  



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.