Commit Graph

20 Commits

Author SHA1 Message Date
Avi Kivity
2a622304ed file: make files copyable
Often a single file is used in multiple fibers, and so it is wrapped in a
lw_shared_ptr.  Remove the need for this by making files internally reference
counted.
2015-07-12 18:11:46 +03:00
Avi Kivity
d170efbfcb fstream: optimize file_data_source_impl
file_data_source_impl always calls file::size(), which can be slow.  This
slows down applications that create many short-lived input streams on the
same file (for random-access processing of a subset of the data).

Fix by not calling size(), and letting the file code handle short reads
itself.
2015-07-09 18:40:05 +03:00
Avi Kivity
ea67ca03af file: fix file::size() signature
file::size() uses size_t as an alias for uint64_t, but it isn't.  Use the
right type.
2015-07-09 15:07:58 +03:00
Avi Kivity
7842ac8db6 doc: document file I/O 2015-06-28 22:42:06 +03:00
Avi Kivity
ae38e95bb2 file: uninline posix_file_impl destructor 2015-06-28 20:42:30 +03:00
Avi Kivity
8039544806 file: warn if file::close() was not called in time 2015-06-28 20:39:06 +03:00
Avi Kivity
9c9d943e3a file: add close() method
Closing a file can both expose latent errors that did not have the
opportunity to be reported earlier, and also may block.  While both
are unlikely in the case of O_DIRECT files, better not to risk it.
2015-06-28 20:36:15 +03:00
Avi Kivity
6ac01770df core: avoid fstat() call in reactor thread
When creating a file object, we call fstat() to determine whether it's
a block device or a regular file.  While unlikely, the fstat() call can
block.  Use an ioctl() that we expect to fail on regular files instead.
2015-06-28 17:14:43 +03:00
Avi Kivity
3ab32ae7a1 file: add allocate() method
Allocate disk blocks in advance of writing to them.

Reviewed-by: Pekka Enberg <penberg@cloudius-systems.com>
2015-06-09 08:44:53 +03:00
Vlad Zolotarov
b70c9a2e18 file: read_maybe_eof(): Don't throw file::eof_error().
Make read_maybe_eof() return zero-sized buffer when pos is at or beyond
EOF. This will prevent an internal exception throwing inside "file" class
in cases when dma_read_bulk() is going to succeed and return read data, e.g. when
it was called with "offset" less than file size but "offset" + "range_size"
beyond EOF.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-28 13:25:40 +03:00
Vlad Zolotarov
ae03cfbb5d file: clarify the class interface.
Move read_state helper class, file::dma_read_bulk() and file::read_maybe_eof()
definitions outside the class declaration in order to make reading the class
interface easier.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-28 13:25:40 +03:00
Vlad Zolotarov
7b1f433aed file: Rework read interface
Move the get() logic in fstream.cc into the file::dma_read_bulk()
fixing some issues:
   - Fix the funny "alignment" calculation.
   - Make sure the length is aligned too.
   - Added new functions:
      - dma_read(pos, len): returns a temporary_buffer with read data and
                            doesn't assume/require any alignment from either "pos"
                            or "len". Unlike dma_read_bulk() this function will
                            trim the resulting buffer to the requested size.
      - dma_read_exactly(pos, len): does exactly what dma_read(pos, len) does but it
                                    will also throw and exception if it failed to read
                                    the required number of bytes (e.g. EOF is reached).
   - Changed the names of parameters of dma_read(pos, buf, len) in order to emphasize
     that they have to be aligned.
   - Added a description to dma_read(pos, buf, len) to make it even more clear.

Signed-off-by: Vlad Zolotarov <vladz@cloudius-systems.com>
2015-05-26 15:15:39 +03:00
Raphael S. Carvalho
fe896fa4e4 core: add truncate function to file class 2015-03-10 15:43:39 -03:00
Avi Kivity
7f8d88371a Add LICENSE, NOTICE, and copyright headers to all source files.
The two files imported from the OSv project retain their original licenses.
2015-02-19 16:52:34 +02:00
Avi Kivity
951a93a534 file.hh: add missing include 2015-02-10 18:59:16 +02:00
Avi Kivity
7596819034 file: define move assignment operator 2015-01-13 19:08:48 +02:00
Glauber Costa
66a6a3b50e add a header to file.hh
I am currently unable to use core/file.hh in a fresh include file. Type
conflicts arise, which probably don't happen in other existing files because
of existing includes that end up getting the environment all right beforehand.

FAILED: g++ -MMD -MT build/release/db/db.o -MF build/release/db/db.o.d -std=gnu++1y -g  -Wall -Werror -fvisibility=hidden -pthread -I.   -DHAVE_XEN -DHAVE_HWLOC -DHAVE_NUMA -O2 -I build/release/gen -c -o build/release/db/db.o db/db.cc
In file included from ./sstables.hh:4:0,
                 from ./database.hh:22,
                 from db/composites/composite.hh:27,
                 from db/db.cc:8:
./core/file.hh:35:64: error: ‘iovec’ was not declared in this scope
     virtual future<size_t> write_dma(uint64_t pos, std::vector<iovec> iov) = 0;

Adding <sys/uio.h> to the include list of file.hh makes it includable (apparently) anywhere.

Signed-off-by: Glauber Costa <glommer@cloudius-systems.com>
2015-01-12 18:59:11 +02:00
Avi Kivity
3be04e7009 reactor: implement open_directory(), list_directory()
open_directory() is similar to open_file_dma() with just the O_ flags adjusted.

list_directory() returns a subscription(), so that both the producer and
the consumer can be asynchronous.
2015-01-08 11:09:25 +02:00
Raphael S. Carvalho
6188745a98 core: introduce size method into file_impl
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-11-01 15:36:28 +02:00
Raphael S. Carvalho
932a6e8752 core: move file-specific content from reactor.hh to specialized header
No semantic change; just cleaning things up.

Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
2014-10-18 16:42:08 +03:00