From a8c9ddfbaa412699c8b8139afd98bc7cf240a12e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alejandro=20=C3=81lvarez=20Ayll=C3=B3n?= Date: Tue, 28 Aug 2012 14:59:56 +0000 Subject: [PATCH] LCGDM-669: Error codes propagated to plugins and dav git-svn-id: https://svn.cern.ch/reps/lcgdm/dmlite-plugins-vfs/trunk@7044 4525493e-7705-40b1-a816-d608a930855b --- src/Throw.cpp | 35 +---------------------------------- src/Vfs.cpp | 3 ++- src/VfsDriver.cpp | 6 +++--- src/VfsIO.cpp | 12 ++++++------ src/VfsNs.cpp | 50 ++++++++++++++++++++++++++++---------------------- src/VfsPool.cpp | 12 ++++++------ 6 files changed, 46 insertions(+), 72 deletions(-) diff --git a/src/Throw.cpp b/src/Throw.cpp index d7a4e5e..15a2e9b 100644 --- a/src/Throw.cpp +++ b/src/Throw.cpp @@ -6,45 +6,12 @@ #include "Vfs.h" -static int Errno2Code(int err) -{ - switch (err) - { - case EBADF: - return DM_BAD_DESCRIPTOR; - case EINVAL: - return DM_INVALID_VALUE; - case ENOMEM: - return DM_OUT_OF_MEMORY; - case EPERM: - return DM_BAD_OPERATION; - case ENOENT: - return DM_NO_SUCH_FILE; - case EACCES: - return DM_FORBIDDEN; - case EFAULT: - return DM_NULL_POINTER; - case EEXIST: - return DM_EXISTS; - case EISDIR: - return DM_IS_DIRECTORY; - case ENOTDIR: - return DM_NOT_DIRECTORY; - case ENOSPC: - return DM_NO_SPACE_LEFT; - case ENAMETOOLONG: - return DM_NAME_TOO_LONG; - default: - return DM_UNKNOWN_ERROR; - } -} - void dmlite::ThrowExceptionFromErrno(int err, const char* extra) throw(DmException) { if (extra == 0) extra = ""; - throw DmException(Errno2Code(err), "%s: %s", strerror(err), extra); + throw DmException(err, "%s: %s", strerror(err), extra); } diff --git a/src/Vfs.cpp b/src/Vfs.cpp index 56da6d5..c55c27b 100644 --- a/src/Vfs.cpp +++ b/src/Vfs.cpp @@ -55,7 +55,8 @@ void VfsFactory::configure(const std::string& key, const std::string& value) thr this->tokenLife_ = (unsigned)atoi(value.c_str()); } else - throw DmException(DM_UNKNOWN_OPTION, "Unrecognised option " + key); + throw DmException(DMLITE_CFGERR(DMLITE_UNKNOWN_KEY), + "Unrecognised option " + key); } diff --git a/src/VfsDriver.cpp b/src/VfsDriver.cpp index bb28f0d..f9c87d2 100644 --- a/src/VfsDriver.cpp +++ b/src/VfsDriver.cpp @@ -186,14 +186,14 @@ Location VfsPoolHandler::whereToRead(const Replica& replica) throw (DmException) void VfsPoolHandler::removeReplica(const Replica& replica) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } Location VfsPoolHandler::whereToWrite(const std::string& sfn) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -201,5 +201,5 @@ Location VfsPoolHandler::whereToWrite(const std::string& sfn) throw (DmException void VfsPoolHandler::doneWriting(const Replica& replica, const Extensible& extras) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } diff --git a/src/VfsIO.cpp b/src/VfsIO.cpp index 9682a4f..094225c 100644 --- a/src/VfsIO.cpp +++ b/src/VfsIO.cpp @@ -51,7 +51,7 @@ IOHandler* VfsIODriver::createIOHandler(const std::string& pfn, const Extensible& extras) throw (DmException) { if (!extras.hasField("token")) - throw DmException(DM_FORBIDDEN, "Missing token"); + throw DmException(EACCES, "Missing token"); std::string userId; if (this->useIp_) @@ -63,7 +63,7 @@ IOHandler* VfsIODriver::createIOHandler(const std::string& pfn, userId, pfn, this->passwd_, openmode != O_RDONLY) != kTokenOK) - throw DmException(DM_FORBIDDEN, "Token does not validate (using %s)", + throw DmException(EACCES, "Token does not validate (using %s)", this->useIp_?"IP":"DN"); // Create @@ -75,7 +75,7 @@ IOHandler* VfsIODriver::createIOHandler(const std::string& pfn, void VfsIODriver::doneWriting(const std::string& pfn, const Extensible& params) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -87,13 +87,13 @@ VfsIOHandler::VfsIOHandler(const std::string& path, std::string real; if (path.compare(0, 5, "/vfs/") != 0) - throw DmException(DM_NO_SUCH_FILE, "File not on the /vfs/ namespace"); + throw DmException(EINVAL, "File not on the /vfs/ namespace"); real = path.substr(4); this->fd_ = ::open(real.c_str(), openmode, 0644); if (this->fd_ == -1) - throw DmException(DM_NO_SUCH_FILE, "Could not open %s (%d)", path.c_str(), errno); + throw DmException(errno, "Could not open %s", path.c_str()); } @@ -135,7 +135,7 @@ size_t VfsIOHandler::write(const char* buffer, size_t count) throw (DmException) void VfsIOHandler::seek(off_t offset, Whence whence) throw (DmException) { if ((pos_ = ::lseek(this->fd_, offset, whence)) == ((off_t) - 1)) - throw DmException(DM_INTERNAL_ERROR, "Could not seek (%d)", errno); + throw DmException(errno, "Could not seek (%d)", errno); } diff --git a/src/VfsNs.cpp b/src/VfsNs.cpp index 06b8269..ba2c1ad 100644 --- a/src/VfsNs.cpp +++ b/src/VfsNs.cpp @@ -92,14 +92,14 @@ ExtendedStat VfsCatalog::extendedStat(const std::string& path, bool follow) thro void VfsCatalog::addReplica(const Replica& replica) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::deleteReplica(const Replica& replica) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -133,7 +133,7 @@ std::vector VfsCatalog::getReplicas(const std::string& path) throw (DmE void VfsCatalog::symlink(const std::string& oldpath, const std::string& newpath) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -149,14 +149,14 @@ std::string VfsCatalog::readLink(const std::string& path) throw (DmException) void VfsCatalog::unlink(const std::string& path) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::create(const std::string& path, mode_t mode) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -170,21 +170,21 @@ mode_t VfsCatalog::umask(mode_t mask) throw () void VfsCatalog::setMode(const std::string& path, mode_t mode) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::setOwner(const std::string& path, uid_t newUid, gid_t newGid, bool followSymLink) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::setSize(const std::string& path, size_t newSize) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -193,42 +193,45 @@ void VfsCatalog::setChecksum(const std::string& path, const std::string& csumtype, const std::string& csumvalue) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported");; + throw DmException(EACCES, "Write mode not supported");; } void VfsCatalog::setAcl(const std::string& path, const Acl& acl) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::utime(const std::string& path, const struct utimbuf* buf) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } std::string VfsCatalog::getComment(const std::string& path) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, "VfsCatalog does not implement comments"); + throw DmException(DMLITE_SYSERR(ENOSYS), + "VfsCatalog does not implement comments"); } void VfsCatalog::setComment(const std::string& path, const std::string& comment) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, "VfsCatalog does not implement comments"); + throw DmException(DMLITE_SYSERR(ENOSYS), + "VfsCatalog does not implement comments"); } void VfsCatalog::setGuid(const std::string&, const std::string&) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, "VfsCatalog does not support setting the GUID"); + throw DmException(DMLITE_SYSERR(ENOSYS), + "VfsCatalog does not support setting the GUID"); } @@ -236,7 +239,8 @@ void VfsCatalog::setGuid(const std::string&, const std::string&) throw (DmExcept void VfsCatalog::updateExtendedAttributes(const std::string& path, const Extensible& attr) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, "VfsCatalog does not support extended attributes"); + throw DmException(DMLITE_SYSERR(ENOSYS), + "VfsCatalog does not support extended attributes"); } @@ -265,7 +269,8 @@ void VfsCatalog::closeDir(Directory* dir) throw (DmException) PrivateDir *privateDir = dynamic_cast(dir); if (privateDir == NULL) - throw DmException(DM_NULL_POINTER, "Tried to close a null directory"); + throw DmException(DMLITE_SYSERR(EFAULT), + "Tried to close a null directory"); r = closedir(privateDir->dir); delete privateDir; @@ -280,7 +285,8 @@ struct dirent* VfsCatalog::readDir(Directory* dir) throw (DmException) PrivateDir *privateDir = dynamic_cast(dir); if (privateDir == NULL) - throw DmException(DM_NULL_POINTER, "Tried to read a null directory"); + throw DmException(DMLITE_SYSERR(EFAULT), + "Tried to read a null directory"); return static_cast(wrapCall(readdir(privateDir->dir))); } @@ -289,7 +295,7 @@ struct dirent* VfsCatalog::readDir(Directory* dir) throw (DmException) ExtendedStat* VfsCatalog::readDirx(Directory* dir) throw (DmException) { - PrivateDir *privateDir = static_cast(dir); + PrivateDir *privateDir = static_cast(dir); struct dirent *ent = this->readDir(dir); if (ent == NULL) return NULL; @@ -311,21 +317,21 @@ ExtendedStat* VfsCatalog::readDirx(Directory* dir) throw (DmException) void VfsCatalog::makeDir(const std::string& path, mode_t mode) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::rename(const std::string& oldPath, const std::string& newPath) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } void VfsCatalog::removeDir(const std::string& path) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } @@ -355,5 +361,5 @@ Replica VfsCatalog::getReplica(const std::string& rfn) throw (DmException) void VfsCatalog::updateReplica(const Replica& replica) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } diff --git a/src/VfsPool.cpp b/src/VfsPool.cpp index 5062f28..e14ac3b 100644 --- a/src/VfsPool.cpp +++ b/src/VfsPool.cpp @@ -84,7 +84,7 @@ std::vector VfsPoolManager::getPools(PoolAvailability availability) throw Pool VfsPoolManager::getPool(const std::string& poolname) throw (DmException) { if (poolname != "vfs") - throw DmException(DM_NO_SUCH_POOL, "Pool " + poolname + " not found"); + throw DmException(DMLITE_NO_SUCH_POOL, "Pool " + poolname + " not found"); Pool pool; @@ -98,7 +98,7 @@ Pool VfsPoolManager::getPool(const std::string& poolname) throw (DmException) void VfsPoolManager::newPool(const Pool&) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, + throw DmException(DMLITE_SYSERR(ENOSYS), "VfsPoolManager::newPool not implemented"); } @@ -106,7 +106,7 @@ void VfsPoolManager::newPool(const Pool&) throw (DmException) void VfsPoolManager::updatePool(const Pool&) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, + throw DmException(DMLITE_SYSERR(ENOSYS), "VfsPoolManager::updatePool not implemented"); } @@ -114,7 +114,7 @@ void VfsPoolManager::updatePool(const Pool&) throw (DmException) void VfsPoolManager::deletePool(const Pool&) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, + throw DmException(DMLITE_SYSERR(ENOSYS), "VfsPoolManager::deletePool not implemented"); } @@ -146,12 +146,12 @@ Location VfsPoolManager::whereToRead(const std::string& path) throw (DmException Location VfsPoolManager::whereToRead(ino_t) throw (DmException) { - throw DmException(DM_NOT_IMPLEMENTED, "VfsPoolManager: Access by inode not supported"); + throw DmException(DMLITE_SYSERR(ENOSYS), "VfsPoolManager: Access by inode not supported"); } Location VfsPoolManager::whereToWrite(const std::string& path) throw (DmException) { - throw DmException(DM_FORBIDDEN, "Write mode not supported"); + throw DmException(EACCES, "Write mode not supported"); } -- 1.8.2.3