ewmscp  ..
Classes | Public Member Functions | Static Private Attributes | List of all members
outputHandler::daosFs Class Reference

#include <outputHandlerDaosFs.h>

Inheritance diagram for outputHandler::daosFs:
[legend]
Collaboration diagram for outputHandler::daosFs:
[legend]

Classes

class  writerDaosFs
 

Public Member Functions

 daosFs ()=default
 
 ~daosFs () override=default
 
std::unique_ptr< writernewWriter (const std::string &path, bool mightAppend, size_t sourceSize, size_t readBlockSize, copyRequest::stateType &state, bool noWrite, std::unique_ptr< ioHandle::attrDataType > attrData, std::unique_ptr< acl::list > aclData) override
 
std::unique_ptr< writernewTmpWriter (std::string &path, size_t sourceSize, bool noWrite, std::unique_ptr< ioHandle::attrDataType > attrData, std::unique_ptr< acl::list > aclData) override
 
void ensureParentDirs (const std::string &path, const std::string &srcPath, inputHandler::base *InputHandler) override
 
void remove (const std::string &path, copyRequest::stateType &state) override
 
bool renameSimple (const std::string &fromPath, const std::string &toPath) override
 
base::renameRetvalType rename (const std::string &fromPath, const std::unique_ptr< const genericStat > &readInitialStat, const std::string &toPath, copyRequest::stateType &state) override
 
void createSymlink (const std::vector< char > &target, const std::string &path, uid_t uid, gid_t gid) override
 
void doAttributePreservations (const std::string &path, const genericStat &stat) override
 
size_t getMaxNameLength (const std::string &dirPath) override
 
- Public Member Functions inherited from outputHandler::base
 ~base () override=default
 
template<class C >
void shortenNameToMax (const std::string &path, C &pathBuf, const std::string &suffix)
 
- Public Member Functions inherited from pathHandler
virtual ~pathHandler ()=default
 
- Public Member Functions inherited from daosFsCommon
dfs_obj_t * getDirObj (const std::string &path)
 
 daosFsCommon (daosOptions &aOpt, bool isWriter)
 
 ~daosFsCommon () override
 
bool pathExists (const std::string &path) override
 
std::unique_ptr< const genericStatgetStat (const std::string &path, bool followLink) override
 
std::string getXattr (const std::string &path, const std::string &name) override
 

Static Private Attributes

static factoryTemplate< daosFsfactory
 

Additional Inherited Members

- Public Types inherited from outputHandler::base
enum  renameRetvalType { renameRetvalType::ok, renameRetvalType::fileChanged, renameRetvalType::fileVanished, renameRetvalType::cantHappen }
 
- Static Public Member Functions inherited from outputHandler::base
static basenewHandler (const std::string &name)
 
template<class T >
static void addAllowedNamesToOption (T &option)
 
- Public Attributes inherited from daosFsCommon
daos_handle_t poh
 
daos_handle_t coh
 
dfs_t * dfs
 
int flags
 
std::map< std::string, dfs_obj_t * > pathMap
 
- Protected Member Functions inherited from outputHandler::base
 base ()=default
 
- Static Protected Member Functions inherited from outputHandler::base
static std::map< std::string, factoryClass * > & getFactoryMap ()
 
- Protected Attributes inherited from daosFsCommon
daosOptionsopt
 

Detailed Description

Definition at line 10 of file outputHandlerDaosFs.h.

Constructor & Destructor Documentation

◆ daosFs()

outputHandler::daosFs::daosFs ( )
default

◆ ~daosFs()

outputHandler::daosFs::~daosFs ( )
overridedefault

Member Function Documentation

◆ createSymlink()

void outputHandler::daosFs::createSymlink ( const std::vector< char > &  target,
const std::string &  path,
uid_t  uid,
gid_t  gid 
)
overridevirtual

Reimplemented from outputHandler::base.

Definition at line 215 of file outputHandlerDaosFs.cpp.

217  {
218  timerInst(symlink);
219  auto retval = symlink(target.data(), path.c_str());
220  if (retval != 0 && errno != EEXIST) {
221  throwcall::good0(retval, "can't create link at ", path);
222  }
223  if (static_cast<std::make_signed<decltype(gid)>::type>(gid) != -1
224  || static_cast<std::make_signed<decltype(uid)>::type>(uid) != -1) {
225  throwcall::good0(lchown(path.c_str(), uid, gid), "can't set owner/group (", uid, ",", gid, ") on ", path);
226  }
227  }

References gid, throwcall::good0(), timerInst, and uid.

Here is the call graph for this function:

◆ doAttributePreservations()

void outputHandler::daosFs::doAttributePreservations ( const std::string &  path,
const genericStat stat 
)
overridevirtual

Reimplemented from outputHandler::base.

Definition at line 425 of file outputHandlerDaosFs.cpp.

426  {
427  if (preserve.timestamps) {
428  struct timespec times[2];
429  times[0].tv_nsec = UTIME_OMIT; // leave atime unchanged
430  stat.getMtime(times[1]);
431  timerInst(utimensat);
432  throwcall::good0(utimensat(0, path.c_str(), times, 0), "can't set mtime on ", path);
433  }
434  if (preserve.mode) {
435  timerInst(chmod);
436  throwcall::good0(chmod(path.c_str(), stat.mode), "can't set mode of ", path);
437  } else {
438  auto oldmask = umask(0);
439  timerInst(chmod);
440  throwcall::good0(chmod(path.c_str(), modeBits & ~oldmask), "can't set mode of ", path);
441  umask(oldmask);
442  }
443 
444  if (gid != -1 || uid != -1) {
445  timerInst(chown);
446  throwcall::good0(chown(path.c_str(), uid, gid), "can't set owner/group (", uid, ",", gid, ") of ", path);
447  } else if (preserve.ownership) {
448  timerInst(chown);
449  throwcall::good0(chown(path.c_str(), stat.ownerUid, stat.ownerGid),
450  "can't set owner/group (", stat.ownerUid, ",", stat.ownerGid, ") of ",
451  path);
452  }
453  }

References genericStat::getMtime(), gid, throwcall::good0(), genericStat::mode, modeBits, genericStat::ownerGid, genericStat::ownerUid, preserve, timerInst, and uid.

Here is the call graph for this function:

◆ ensureParentDirs()

void outputHandler::daosFs::ensureParentDirs ( const std::string &  path,
const std::string &  srcPath,
inputHandler::base InputHandler 
)
overridevirtual

Implements outputHandler::base.

Definition at line 53 of file outputHandlerDaosFs.cpp.

55  {
56  std::vector<std::remove_reference<decltype(path)>::type::value_type> disposable_buffer(path.c_str(), path.c_str() + path.size() + 1);
57  std::string dir(dirname(disposable_buffer.data()));
58  struct stat statbuf;
59 
60  if (stat(dir.c_str(), &statbuf)) {
61  if (errno == ENOENT || errno == ENOTDIR) {
62  ensureParentDirs(dir, srcPath, InputHandler);
63  static timer::anchor A("mkdir");
65  auto result = mkdir(dir.c_str(), 0777u);
66  I.stop(slownessThreshold, dir);
67 
68  if (result != 0 && errno == EEXIST) {
69  return; // we lost a race with another copy process...
70  }
71 
72  throwcall::good0(result, "can't create directory ", dir);
73 
74  if (gid != -1 || uid != -1) {
75  timerInst(chown);
76  throwcall::good0(chown(dir.c_str(), uid, gid), "can't set owner/group (", uid, ",", gid, ") on ", dir);
77  }
78  }
79  } else if (! S_ISDIR(statbuf.st_mode)) {
81  dir, "ensure parents",
82  "is not a directory (st_mode is ", statbuf.st_mode, ") but should be");
83  }
84  if (requiredFsid != 0) {
85  struct statvfs fsstat;
86  timerInst(statvfs);
87  throwcall::good0(statvfs(dir.c_str(), &fsstat), "can't statvfs ", dir);
88  if ((fsstat.f_fsid & fsidMask) != requiredFsid) {
89  throw fatalException("wrong fs id 0x", std::hex, fsstat.f_fsid, " instead of ", requiredFsid);
90  }
91  }
92  }

References errMsg::emit(), outputHandler::fsidMask, gid, throwcall::good0(), errMsg::info, outputHandler::requiredFsid, outputHandler::slownessThreshold, timer::instanceUnscoped::stop(), timerInst, and uid.

Here is the call graph for this function:

◆ getMaxNameLength()

size_t outputHandler::daosFs::getMaxNameLength ( const std::string &  dirPath)
overridevirtual

Reimplemented from outputHandler::base.

Definition at line 455 of file outputHandlerDaosFs.cpp.

455  {
456  errno = 0;
457  timerInst(pathconf);
458  return throwcall::badval(pathconf(dirPath.c_str(), _PC_NAME_MAX), -1,"can't get max name lenght on", dirPath);
459  }

References throwcall::badval(), and timerInst.

Here is the call graph for this function:

◆ newTmpWriter()

std::unique_ptr< base::writer > outputHandler::daosFs::newTmpWriter ( std::string &  path,
size_t  sourceSize,
bool  noWrite,
std::unique_ptr< ioHandle::attrDataType attrData,
std::unique_ptr< acl::list aclData 
)
overridevirtual

Reimplemented from outputHandler::base.

Definition at line 36 of file outputHandlerDaosFs.cpp.

40  {
41  return std::unique_ptr<base::writer>(new writerDaosFs(path,
42  noWrite,
43  std::move(attrData),
44  std::move(aclData),
45  *this));
46  }

◆ newWriter()

std::unique_ptr< base::writer > outputHandler::daosFs::newWriter ( const std::string &  path,
bool  mightAppend,
size_t  sourceSize,
size_t  readBlockSize,
copyRequest::stateType state,
bool  noWrite,
std::unique_ptr< ioHandle::attrDataType attrData,
std::unique_ptr< acl::list aclData 
)
overridevirtual

Implements outputHandler::base.

Definition at line 20 of file outputHandlerDaosFs.cpp.

27  {
28  return std::unique_ptr<base::writer>(new writerDaosFs(path, mightAppend,
29  sourceSize, readBlockSize,
30  state, noWrite,
31  std::move(attrData),
32  std::move(aclData),
33  *this));
34  }

◆ remove()

void outputHandler::daosFs::remove ( const std::string &  path,
copyRequest::stateType state 
)
overridevirtual

Implements outputHandler::base.

Definition at line 95 of file outputHandlerDaosFs.cpp.

95  {
96  struct stat dsttat;
97  {
98  timerInst(lstat);
99  auto retval = lstat(path.c_str(), &dsttat);
100 
101  if (retval && errno == ENOENT) {
103  return;
104  }
105  }
106  if (S_ISDIR(dsttat.st_mode)) {
107  timerInst(rmdir);
108  auto retval = rmdir(path.c_str());
109  if (retval) {
110  switch (errno) {
111  case ENOENT:
113  return;
114  case ENOTEMPTY:
115  case EEXIST: // POSIX.1 allows this also
117  path, "remove", "directory not empty but should be removed");
119  return;
120  }
121  throwcall::good0(retval, "can't remove directory ", path);
122  } else {
124  return;
125  }
126  } else {
127  timerInst(unlink);
128  auto retval = unlink(path.c_str());
129 
130  if (retval && errno == ENOENT) {
132  } else {
133  throwcall::good0(retval, "can't unlink ", path);
134  }
136  }
137  }

References copyRequest::done, errMsg::emit(), copyRequest::failed, throwcall::good0(), errMsg::info, timerInst, and copyRequest::vanished.

Here is the call graph for this function:

◆ rename()

base::renameRetvalType outputHandler::daosFs::rename ( const std::string &  fromPath,
const std::unique_ptr< const genericStat > &  readInitialStat,
const std::string &  toPath,
copyRequest::stateType state 
)
overridevirtual
Bug:
what if at the end a directory is renamed?

Implements outputHandler::base.

Definition at line 151 of file outputHandlerDaosFs.cpp.

154  {
155  struct stat fromPathStatBuf;
156  static timer::anchor A("stat");
158  auto statRetVal = stat(fromPath.c_str(), &fromPathStatBuf);
159  I.stop();
160  if (statRetVal && (errno == ENOENT || errno == ENOTDIR)) {
161  if (readInitialStat && readInitialStat->isDir()) { // no need to act, dirs are created on the fly
165  }
167  } else if (statRetVal) { // curious error
168  throwcall::good0(statRetVal, "can't stat '", fromPath, "'");
169  return base::renameRetvalType::cantHappen; // never reached
170  }
171  genericStat fromPathStat(fromPathStatBuf, std::chrono::nanoseconds(1));
172  if (!readInitialStat || (! readInitialStat->isDir() &&
173  (fromPathStat.size != readInitialStat->size
174  || !fromPathStat.isSameMtimeAs(*readInitialStat)))) {
175  // the copy on fromPath is not up to date, create a new copy
176  if (readInitialStat) {
177  std::string initialTime;
178  std::string finalTime;
179  readInitialStat->getMtime(initialTime);
180  fromPathStat.getMtime(finalTime);
182  fromPath, "move"
183  "file (", toPath, ") changed unexpectedly ("
184  , initialTime, " -> ", finalTime, ", "
185  , readInitialStat->size, " -> ", fromPathStat.size
186  , ", doing fresh copy");
187  } else {
189  fromPath, "move",
190  "file (", toPath, ") has no initial stat, doing fresh copy");
191  }
193  } else { // try to move the existing copy
194  timerInst(rename);
195  auto retval = std::rename(fromPath.c_str(), toPath.c_str());
196 
197  if (retval && (errno == ENOENT || errno == ENOTDIR)) {
198  if (readInitialStat->isDir()) { // no need to act, dirs are created on the fly
201  }
203  fromPath, "move",
204  "vanished unexpectedly, doing fresh copy");
205  // file was probably not copied yet, try to copy it from the move target
207  } else {
208  throwcall::good0(retval, "can't rename '", fromPath, "' to '", toPath, "'");
211  }
212  }
213  }

References outputHandler::base::cantHappen, copyRequest::done, errMsg::emit(), outputHandler::base::fileChanged, outputHandler::base::fileVanished, genericStat::getMtime(), throwcall::good0(), copyRequest::ignore, errMsg::info, genericStat::isDir(), genericStat::isSameMtimeAs(), outputHandler::base::ok, genericStat::size, timer::instanceUnscoped::stop(), and timerInst.

Referenced by renameSimple().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ renameSimple()

bool outputHandler::daosFs::renameSimple ( const std::string &  fromPath,
const std::string &  toPath 
)
overridevirtual

Implements outputHandler::base.

Definition at line 139 of file outputHandlerDaosFs.cpp.

140  {
142  auto retval = std::rename(fromPath.c_str(), toPath.c_str());
143  if (retval && (errno == ENOENT || errno == ENOTDIR)) {
144  return false;
145  }
146  throwcall::good0(retval, "can't rename '", fromPath, "' to '", toPath, "'");
147  return true;
148  }

References throwcall::good0(), rename(), outputHandler::slownessThreshold, and timerInstTO.

Here is the call graph for this function:

Member Data Documentation

◆ factory

factoryTemplate<daosFs> outputHandler::daosFs::factory
staticprivate

Definition at line 11 of file outputHandlerDaosFs.h.


The documentation for this class was generated from the following files:
genericStat::ownerGid
gid_t ownerGid
Definition: genericStat.h:24
outputHandler::requiredFsid
static options::single< unsigned long > requiredFsid('\0', "requiredFsid", "required fsid of output file system", 0)
genericStat::mode
mode_t mode
Definition: genericStat.h:22
outputHandler::fsidMask
static options::single< unsigned long > fsidMask('\0', "fsidMask", "bit mask for required fsid of output file system", 0)
errMsg::location
class for defining the location of a error message in the source code.
Definition: errMsgQueue.h:14
throwcall::badval
T badval(T call, t badvalue, const Args &... args)
template function to wrap system calls that return a special bad value on failure
Definition: throwcall.h:54
genericStat
generic stat abstraction class Used to abstract the variants of the stat structure.
Definition: genericStat.h:12
fatalException
class for exceptions that should result in program termination
Definition: copyRequestTypes.h:11
copyRequest::stateBitType::ignore
@ ignore
errMsg::level::info
@ info
outputHandler::slownessThreshold
static options::single< timer::clock_type::duration > slownessThreshold('\0',"daosFsSlownessThreshold", "duration after which file operations are considered slow", std::chrono::milliseconds(10))
outputHandler::base::renameRetvalType::cantHappen
@ cantHappen
copyRequest::stateBitType::done
@ done
outputHandler::base::renameRetvalType::fileChanged
@ fileChanged
copyRequest::stateBitType::failed
@ failed
genericStat::getMtime
void getMtime(struct timespec &spec) const
Definition: genericStat.cpp:65
gid
options::single< int > gid
copyRequest::stateBitType::vanished
@ vanished
outputHandler::daosFs::rename
base::renameRetvalType rename(const std::string &fromPath, const std::unique_ptr< const genericStat > &readInitialStat, const std::string &toPath, copyRequest::stateType &state) override
Definition: outputHandlerDaosFs.cpp:151
outputHandler::daosFs::ensureParentDirs
void ensureParentDirs(const std::string &path, const std::string &srcPath, inputHandler::base *InputHandler) override
Definition: outputHandlerDaosFs.cpp:53
genericStat::isDir
bool isDir() const
Definition: genericStat.cpp:92
genericStat::size
size_t size
Definition: genericStat.h:16
outputHandler::base::renameRetvalType::fileVanished
@ fileVanished
outputHandler::base::renameRetvalType::ok
@ ok
timer::instanceUnscoped
Definition: timer.h:95
timer::anchor
Definition: timer.h:22
preserve
decltype(preserve) preserve
set of properties to preserve in the copy
Definition: ewmscp.cpp:111
uid
options::single< int > uid
errMsg::emit
void emit(level aLogLevel, const location &loc, const std::string &aObject, const std::string &aAction, const Args &... args)
function to create and enqueue a message, this is the only way that messages should be created!
Definition: errMsgQueue.h:148
timerInst
#define timerInst(subfunc)
Definition: timer.h:157
timerInstTO
#define timerInstTO(subfunc, timeout, object)
Definition: timer.h:158
throwcall::good0
void good0(T call, const Args &... args)
template function to wrap system calls that return 0 on success
Definition: throwcall.h:40
genericStat::ownerUid
uid_t ownerUid
Definition: genericStat.h:23
modeBits
options::single< modeBitType > modeBits