Spin-off syscall-related file operations (#78)
* [file_utils] spin-off syscall-related file operations 1. Eliminate the potential circular dependency between persistent-data/block.h and persistent-data/file_utils.h, if the former one wants to include the latter. 2. Avoid namespace pollution by removing the "using namespace std" declaration in block.tcc. 3. Correct the header hierarchy: base/xml_utils.h now no longer depends on the higher-level persistent-data/file_utils.h * [file_utils] support block files in get_file_length()
This commit is contained in:
committed by
Joe Thornber
parent
8f25e1b234
commit
b7d418131d
@@ -2,25 +2,14 @@
|
||||
#include "thin-provisioning/cache_stream.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
using namespace thin_provisioning;
|
||||
using namespace std;
|
||||
using namespace persistent_data;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
int open_file(string const &path) {
|
||||
int fd = ::open(path.c_str(), O_RDONLY | O_DIRECT | O_EXCL, 0666);
|
||||
if (fd < 0)
|
||||
syscall_failed("open",
|
||||
"Note: you cannot run this tool with these options on live metadata.");
|
||||
|
||||
return fd;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
cache_stream::cache_stream(string const &path,
|
||||
block_address block_size,
|
||||
size_t cache_mem)
|
||||
@@ -29,7 +18,7 @@ cache_stream::cache_stream(string const &path,
|
||||
|
||||
// hack because cache uses LRU rather than MRU
|
||||
cache_blocks_((cache_mem / block_size) / 2u),
|
||||
fd_(open_file(path)),
|
||||
fd_(file_utils::open_file(path, O_RDONLY | O_EXCL)),
|
||||
v_(new bcache::noop_validator()),
|
||||
cache_(new block_cache(fd_, block_size / 512, nr_blocks_, cache_mem)),
|
||||
current_index_(0) {
|
||||
|
@@ -3,8 +3,11 @@
|
||||
#include "thin-provisioning/superblock.h"
|
||||
#include "persistent-data/file_utils.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace thin_provisioning;
|
||||
using namespace superblock_detail;
|
||||
using namespace std;
|
||||
|
||||
//----------------------------------------------------------------
|
||||
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <iostream>
|
||||
#include <getopt.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/fs.h>
|
||||
#include <libgen.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#undef BLOCK_SIZE
|
||||
|
||||
|
Reference in New Issue
Block a user