src/core/builtin/Catalog.h

Go to the documentation of this file.
00001 /// @file    core/builtin/Catalog.h
00002 /// @brief   Implementation of a Catalog using other plugins, as INode.
00003 /// @details Intended to ease the development of database backends.
00004 /// @author  Alejandro Álvarez Ayllon <aalvarez@cern.ch>
00005 #ifndef BUILTIN_CATALOG_H
00006 #define BUILTIN_CATALOG_H
00007 
00008 #include <dmlite/cpp/catalog.h>
00009 #include <dmlite/cpp/inode.h>
00010 #include <dmlite/cpp/poolmanager.h>
00011 #include <dmlite/cpp/pooldriver.h>
00012 
00013 namespace dmlite {
00014   
00015   struct BuiltInDir: public Directory {
00016     virtual ~BuiltInDir() {};
00017     IDirectory*  idir;
00018     ExtendedStat dir;
00019   };
00020 
00021   class BuiltInCatalog: public Catalog {
00022    public:
00023     BuiltInCatalog(bool updateATime, unsigned symLinkLimit) throw (DmException);
00024     ~BuiltInCatalog();
00025 
00026     std::string getImplId(void) const throw();
00027 
00028     void setStackInstance(StackInstance* si) throw (DmException);
00029 
00030     void setSecurityContext(const SecurityContext*) throw (DmException);  
00031 
00032     void        changeDir     (const std::string&) throw (DmException);
00033     std::string getWorkingDir (void) throw (DmException);
00034 
00035     ExtendedStat extendedStat(const std::string& path,
00036                               bool followSym = true) throw (DmException);
00037     ExtendedStat extendedStatByRFN(const std::string& rfn) throw (DmException);
00038 
00039     bool access(const std::string& path, int mode) throw (DmException);
00040     bool accessReplica(const std::string& replica, int mode) throw (DmException);
00041 
00042     void addReplica   (const Replica& replica) throw (DmException);
00043     void deleteReplica(const Replica& replica) throw (DmException);
00044 
00045     std::vector<Replica> getReplicas(const std::string& path) throw (DmException);
00046     Location get(const std::string& path) throw (DmException);
00047 
00048     Location put(const std::string& path) throw (DmException);
00049     void     putDone(const std::string& host, const std::string& rfn,
00050                     const std::map<std::string, std::string>& params) throw (DmException);
00051 
00052     void symlink(const std::string& oldpath,
00053                  const std::string& newpath) throw (DmException);
00054     std::string readLink(const std::string& path) throw (DmException);
00055 
00056     void unlink(const std::string& path) throw (DmException);
00057 
00058     void create(const std::string& path, mode_t mode) throw (DmException);
00059 
00060     void makeDir  (const std::string& path, mode_t mode) throw (DmException);
00061     void removeDir(const std::string& path) throw (DmException);
00062 
00063     void rename(const std::string& oldPath,
00064                 const std::string& newPath) throw (DmException);
00065 
00066     mode_t umask(mode_t mask) throw ();
00067 
00068     void setMode     (const std::string& path, mode_t mode) throw (DmException);
00069     void setOwner    (const std::string& path, uid_t newUid, gid_t newGid,
00070                       bool followSymLink = true) throw (DmException);
00071 
00072     void setSize    (const std::string& path, size_t newSize) throw (DmException);
00073 
00074     void setAcl(const std::string& path, const Acl& acls) throw (DmException);
00075 
00076     void utime(const std::string& path, const struct utimbuf* buf) throw (DmException);
00077 
00078     std::string getComment(const std::string& path) throw (DmException);
00079     void        setComment(const std::string& path,
00080                            const std::string& comment) throw (DmException);
00081 
00082     void setGuid(const std::string& path,
00083                  const std::string &guid) throw (DmException);
00084 
00085     void updateExtendedAttributes(const std::string& path,
00086                                   const Extensible& attr) throw (DmException);
00087 
00088     Directory*     openDir (const std::string& path) throw (DmException);
00089     void           closeDir(Directory* dir) throw (DmException);
00090     struct dirent* readDir (Directory* dir) throw (DmException);
00091     ExtendedStat*  readDirx(Directory* dir) throw (DmException);
00092 
00093     Replica getReplicaByRFN(const std::string& rfn) throw (DmException);
00094     void    updateReplica(const Replica& replica)   throw (DmException);
00095 
00096    protected:
00097     /// Get the parent of a directory.
00098     /// @param path       The path to split.
00099     /// @param parentPath Where to put the parent path.
00100     /// @param name       Where to put the file name (stripping last /).
00101     /// @return           The parent metadata.
00102     ExtendedStat getParent(const std::string& path, std::string* parentPath,
00103                           std::string* name) throw (DmException);
00104 
00105     /// Update access time (if updateATime is true)
00106     void updateAccessTime(const ExtendedStat& meta) throw (DmException);
00107 
00108     /// Traverse backwards to check permissions.
00109     /// @param meta The file at the end
00110     /// @note       Throws an exception if it is not possible.
00111     void traverseBackwards(const ExtendedStat& meta) throw (DmException);
00112     
00113     /// addFileSizeToParents
00114     /// Add (or subtract) the size of the given file from
00115     /// all its parent directories
00116     /// @param fname The logical file name (SFN) of the file in question
00117     /// @param subtract If true then subtract instead of adding
00118     void addFileSizeToParents(const std::string &fname, bool subtract) throw (DmException);
00119     
00120     /// addFileSizeToParents
00121     /// Add (or subtract) the size of the given file from
00122     /// all its parent directories
00123     /// @param st The stat information about the file in question
00124     /// @param subtract If true then subtract instead of adding
00125     void addFileSizeToParents(const ExtendedStat &statinfo, bool subtract) throw (DmException);
00126     
00127    private:
00128     StackInstance*   si_;
00129 
00130     const SecurityContext* secCtx_;
00131 
00132     std::string cwdPath_;
00133     ino_t       cwd_;
00134 
00135     mode_t   umask_;
00136     bool     updateATime_;
00137     unsigned symLinkLimit_;
00138   };
00139 
00140   /// Plug-ins must implement a concrete factory to be instantiated.
00141   class BuiltInCatalogFactory: public CatalogFactory {
00142    public:
00143     BuiltInCatalogFactory();
00144     ~BuiltInCatalogFactory();
00145 
00146     void configure(const std::string&, const std::string&) throw (DmException);
00147 
00148     Catalog* createCatalog(PluginManager*) throw (DmException);
00149 
00150    private:
00151     bool     updateATime_;
00152     unsigned symLinkLimit_;
00153   };
00154   
00155 };
00156 
00157 #endif  // BUILTIN_CATALOG_H

Generated on 4 May 2016 for dmlite by  doxygen 1.4.7