24 return std::unique_ptr<base::reader>(
new readerDaosFs(aPath,
32 std::vector<char>& target) {
34 auto linklength = readlink(path.c_str(), target.data(), target.size());
35 if (linklength == -1 && errno == ENOENT) {
39 if (linklength >=
static_cast<ssize_t
>(target.size())) {
40 throw std::runtime_error(
"link size increased after stat for " + path);
42 target[linklength] =
'\0';
53 reader(inititalStat) {
58 0, readInitialStat.blksize,
nullptr, &
obj);
62 || (errno == ENOTDIR && !S_ISDIR(readInitialStat.mode))) {
74 if (dfs_release(obj) != 0) {
76 path,
"release during unwind ",
77 std::system_category().default_error_condition(errno).message());
83 throwcall::good0(dfs_release(obj),
"can't release ", path,
" after reading");
95 b.
clear(totalBytesRead);
96 bool lastblock =
false;
100 while (b.
size() + blockSize <= bytesToRead) {
104 iov.iov_buf_len = blockSize;
107 sg_list.sg_iovs = &iov;
109 daos_size_t bytes_read;
110 throwcall::good0(dfs_read(handler.dfs, obj, &sg_list, totalBytesRead, &bytes_read,
nullptr),
111 "read failed on ", path);
113 if (bytes_read == 0) {
115 if (totalBytesRead < readInitialStat.size) {
117 std::to_string(readInitialStat.size) +
119 std::to_string(totalBytesRead) +
124 totalBytesRead += bytes_read;
125 if (totalBytesRead > readInitialStat.size) {
127 std::to_string(readInitialStat.size) +
129 std::to_string(totalBytesRead) +
146 iov.iov_buf_len = blockSize;
149 sg_list.sg_iovs = &iov;
151 daos_size_t bytes_read;
152 throwcall::good0(dfs_read(handler.dfs, obj, &sg_list, offset + b.
size() , &bytes_read,
nullptr),
153 "read failed on ", path);
154 if (bytes_read == 0) {
158 if (b.
size() > bytesToRead) {
162 if (b.
size() < bytesToRead) {
164 + std::to_string(bytesToRead)
166 + std::to_string(b.
size()));
172 struct stat readFinalStatBuf;
175 throwcall::good0(dfs_ostat(handler.dfs, obj, &readFinalStatBuf),
"can't stat path file ", path);
177 genericStat readFinalStat(readFinalStatBuf, std::chrono::nanoseconds(1));
178 if (readFinalStat.
size != readInitialStat.size) {
180 std::to_string(readInitialStat.size) +
182 std::to_string(readFinalStat.
size) +
183 ") during reading on " + path);
188 std::to_string(std::chrono::duration_cast<std::chrono::duration<double>>(readFinalStat.
getMtime() - readInitialStat.getMtime()).count()) +
189 "s different mtime) during reading");
195 "can't open direcory ", path);
199 if (dfs_release(dir) != 0) {
201 "",
"close directory during unwind ",
202 std::system_category().default_error_condition(errno).message());
213 throwcall::good0(dfs_readdir(handler.dfs, dir, &anchor, &n, &entry),
"can't read dir enry");
215 if (entry.d_name[entry.d_name[0] !=
'.' ? 0 : entry.d_name[1] !=
'.' ? 1 : 2] ==
'\0') {
221 auto result = dfs_stat(handler.dfs, dir, entry.d_name, &statbuf);
222 if (result != 0 && errno == ENOENT && ignoreMissing) {
227 auto genStat = std::unique_ptr<const genericStat>(
new genericStat(statbuf, std::chrono::nanoseconds(1)));
228 return std::unique_ptr<Entry>(
new Entry(entry.d_name, genStat));