Alberto Miranda
2017-04-04 15:50:26 UTC
Hi,
I've been taking a look to the read_buf interface while developing a
RAM-based caching filesystem and I'm not sure what the correct procedure
is to return multiple buffers through the 'struct fuse_bufvec** bufp'
passed to read_buf.
In our case, the data for a file may be stored in RAM in potentially
separate regions, which might need to be returned by a single read_buf()
invocation. From what I understood from the code and the documentation,
it seems that, first of all, a 'struct fuse_bufvec' should be
malloc()-ed with enough space to contain several 'fuse_bufs', that
should be appropriately initialized to describe these regions.
For instance, if we had two memory regions 'data0' and 'data1', would it
be ok to initialize the fuse_bufs in the following manner? (src in this
case is a struct fuse_bufvec *):
src->buf[0].flags = (fuse_buf_flags) (~FUSE_BUF_IS_FD);
src->buf[0].mem = data0; // pointer to internal in-RAM
cache entry
src->buf[0].size = bytes0;
src->buf[1].flags = (fuse_buf_flags) (~FUSE_BUF_IS_FD);
src->buf[1].mem = data1; // pointer to internal in-RAM
cache entry
src->buf[1].size = bytes1;
My confusion comes from the following description of read_buf (fuse.h):
* The buffer must be allocated dynamically and stored at the
* location pointed to by bufp. If the buffer contains memory
* regions, they too must be allocated using malloc(). The
* allocated memory will be freed by the caller.
This seems to imply that the contents of 'data0' and 'data1' should be
memcopied to two dynamically allocated memory regions, and that the
addresses of these two new regions should be used to initialize
buf[0].mem and buf[1].mem, rather than directly using the data that is
already in RAM. Is this the case? If so, why is this extra copy needed?
Thanks in advance,
alberto
--
Alberto Miranda, PhD
Researcher on HPC I/O
Barcelona Supercomputing Center
www : https://www.bsc.es/research-development/research-areas/big-data/high-performance-io
email : alberto.miranda(at)bsc.es
phone : (+34) 93 405 42 81
http://bsc.es/disclaimer
I've been taking a look to the read_buf interface while developing a
RAM-based caching filesystem and I'm not sure what the correct procedure
is to return multiple buffers through the 'struct fuse_bufvec** bufp'
passed to read_buf.
In our case, the data for a file may be stored in RAM in potentially
separate regions, which might need to be returned by a single read_buf()
invocation. From what I understood from the code and the documentation,
it seems that, first of all, a 'struct fuse_bufvec' should be
malloc()-ed with enough space to contain several 'fuse_bufs', that
should be appropriately initialized to describe these regions.
For instance, if we had two memory regions 'data0' and 'data1', would it
be ok to initialize the fuse_bufs in the following manner? (src in this
case is a struct fuse_bufvec *):
src->buf[0].flags = (fuse_buf_flags) (~FUSE_BUF_IS_FD);
src->buf[0].mem = data0; // pointer to internal in-RAM
cache entry
src->buf[0].size = bytes0;
src->buf[1].flags = (fuse_buf_flags) (~FUSE_BUF_IS_FD);
src->buf[1].mem = data1; // pointer to internal in-RAM
cache entry
src->buf[1].size = bytes1;
My confusion comes from the following description of read_buf (fuse.h):
* The buffer must be allocated dynamically and stored at the
* location pointed to by bufp. If the buffer contains memory
* regions, they too must be allocated using malloc(). The
* allocated memory will be freed by the caller.
This seems to imply that the contents of 'data0' and 'data1' should be
memcopied to two dynamically allocated memory regions, and that the
addresses of these two new regions should be used to initialize
buf[0].mem and buf[1].mem, rather than directly using the data that is
already in RAM. Is this the case? If so, why is this extra copy needed?
Thanks in advance,
alberto
--
Alberto Miranda, PhD
Researcher on HPC I/O
Barcelona Supercomputing Center
www : https://www.bsc.es/research-development/research-areas/big-data/high-performance-io
email : alberto.miranda(at)bsc.es
phone : (+34) 93 405 42 81
http://bsc.es/disclaimer