Commit 09c3098d authored by Juergen Hannappel's avatar Juergen Hannappel
Browse files

gpfs fputatrs does *NOT* handle xattrs

parent 49c8330c
......@@ -42,25 +42,32 @@ void gpfsIoCommon::handleParallelUsedBlocks(size_t aBlockSize, off_t offset) {
}
void gpfsIoCommon::attrDataType::set(ioHandle* handle) {
auto castHandle = dynamic_cast<outputHandler::posixFile::writerPosixFile*>(handle);
throwcall::good0(gpfs_fputattrs(castHandle->fd, GPFS_ATTRFLAG_NO_PLACEMENT, buffer),
"can't set gpfs attributes for", castHandle->path);
if (size != 0) {
throwcall::good0(gpfs_fputattrs(castHandle->fd, GPFS_ATTRFLAG_NO_PLACEMENT, buffer),
"can't set gpfs attributes for", castHandle->path);
}
posixFileIoCommon::attrDataType::set(handle);
}
std::unique_ptr<ioHandle::attrDataType> gpfsIoCommon::getAttrData(const outputHandler::base* aOutputHandler) {
std::unique_ptr<ioHandle::attrDataType> gpfsIoCommon::getAttrData(const outputHandler::base* aOutputHandler,
ioHandle::attrDataType* oldPtr) {
if (oldPtr != nullptr) {
throw std::logic_error("gpfsIoCommon::getAttrData should not be caled with non-NULL oldPtr");
}
auto data=new gpfsIoCommon::attrDataType();
std::unique_ptr<ioHandle::attrDataType> oldSmartPtr=posixFileIoCommon::getAttrData(aOutputHandler, data);
auto attrData = dynamic_cast<gpfsIoCommon::attrDataType*>(oldSmartPtr.release());
if (dynamic_cast<const outputHandler::Gpfs*>(aOutputHandler)) { // we work all in gpfs
auto attrData = std::unique_ptr<gpfsIoCommon::attrDataType>(new gpfsIoCommon::attrDataType());
throwcall::good0(gpfs_fgetattrs(fd, GPFS_ATTRFLAG_NO_PLACEMENT,
attrData->buffer,
sizeof(attrData->buffer),
&(attrData->size)),
"can't get gpfs attributes for ", path);
if (attrData->size > 0) {
return std::unique_ptr<ioHandle::attrDataType>(attrData.release());
} else { // no xattr data found
return nullptr;
}
} else { // no gpfs on output side, fall back to posix or worse
return posixFileIoCommon::getAttrData(aOutputHandler);
}
if (attrData->size > 0 && !attrData->xattrs.empty()) {
return std::unique_ptr<ioHandle::attrDataType>(attrData);
} else { // no xattr data found
return nullptr;
}
}
......
......@@ -15,7 +15,7 @@ class gpfsIoCommon: virtual public posixFileIoCommon {
void releaseUsedBlocks(size_t aBlockSize);
void handleParallelUsedBlocks(size_t aBlockSize, off_t offset);
public:
class attrDataType: public ioHandle::attrDataType {
class attrDataType: public posixFileIoCommon::attrDataType {
public:
char buffer[0x10000];
int size;
......@@ -24,7 +24,8 @@ class gpfsIoCommon: virtual public posixFileIoCommon {
};
gpfsIoCommon(const std::string& aPath);
~gpfsIoCommon() override = default;
std::unique_ptr<ioHandle::attrDataType> getAttrData(const outputHandler::base* aOutputHandler) override;
std::unique_ptr<ioHandle::attrDataType> getAttrData(const outputHandler::base* aOutputHandler,
ioHandle::attrDataType* oldPtr=nullptr) override;
std::unique_ptr<acl::list> getAclData() override;
static std::unique_ptr<acl::list> aclFromGpfs(const gpfs_acl_handler& acl, const std::string& aPath);
};
......
......@@ -63,9 +63,10 @@ class ioHandle {
/// get attributes in the optimal way for setting with aOutputHandler
/// \return std::unique_ptr to the attribute data or nullptr if none available
/// \throw std::system_error when reading of attributes fails
virtual std::unique_ptr<attrDataType> getAttrData(const outputHandler::base* /*aOutputHandler*/ ///< [in] output handler as a hint to it's capabilities
virtual std::unique_ptr<attrDataType> getAttrData(const outputHandler::base* /*aOutputHandler*/, ///< [in] output handler as a hint to it's capabilities
attrDataType* oldPtr=nullptr
) {
return nullptr;
return std::unique_ptr<attrDataType>(oldPtr);
};
/// get acls
......
......@@ -166,19 +166,23 @@ void posixFileIoCommon::attrDataType::set(ioHandle* handle) {
}
#if defined(WithXattr) || defined(WithXattrUgly)
std::unique_ptr<ioHandle::attrDataType> posixFileIoCommon::getAttrData(const outputHandler::base* /*aOutputHandler*/) {
std::unique_ptr<ioHandle::attrDataType> posixFileIoCommon::getAttrData(const outputHandler::base* /*aOutputHandler*/,
ioHandle::attrDataType* oldPtr) {
char buf[0x10000];
auto bufSize = throwcall::badval(flistxattr(fd, buf, sizeof(buf)), -1,
"can't get xattrs for ", path);
if (bufSize > 0) {
auto retval = new posixFileIoCommon::attrDataType();
posixFileIoCommon::attrDataType *retval = oldPtr ? dynamic_cast<posixFileIoCommon::attrDataType*>(oldPtr) : new posixFileIoCommon::attrDataType();
if (retval == nullptr) {
throw std::logic_error("can't cast oldPtr tp posixFileIoCommon::attrDataType*");
}
for (auto readPtr = &buf[0]; readPtr < &buf[bufSize];) {
retval->add(readPtr, getXattr(readPtr));
while (*readPtr++);
}
return std::unique_ptr<ioHandle::attrDataType>(retval);
} else {
return nullptr;
return std::unique_ptr<ioHandle::attrDataType>(oldPtr);
}
}
#else
......
......@@ -21,6 +21,7 @@ class posixFileIoCommon: virtual public ioHandle {
int fd = -1;
public:
class attrDataType: public ioHandle::attrDataType {
friend class gpfsIoCommon;
protected:
std::forward_list<std::pair<std::string, std::string>> xattrs;
public:
......@@ -33,7 +34,8 @@ class posixFileIoCommon: virtual public ioHandle {
std::string getXattr(const std::string& name) override;
void removeXattr(const std::string& name) override;
std::unique_ptr<const genericStat> getStat() override;
std::unique_ptr<ioHandle::attrDataType> getAttrData(const outputHandler::base* aOutputHandler) override;
std::unique_ptr<ioHandle::attrDataType> getAttrData(const outputHandler::base* aOutputHandler,
ioHandle::attrDataType* oldPtr=nullptr) override;
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment