Search in sources :

Example 1 with Stat

use of org.dcache.chimera.posix.Stat in project dcache by dCache.

the class StorageUriTest method setUp.

@Before
public void setUp() throws Exception {
    fs = mock(JdbcFs.class);
    root = new RootInode(fs, 0L);
    file = new FsInode(fs, 1L);
    locations = new ArrayList<>();
    stat = new Stat();
    stat.setSize(0);
    stat.setMode(0);
    stat.setGeneration(0);
    newFsInodeSURI();
    mockFileSystem();
}
Also used : Stat(org.dcache.chimera.posix.Stat) FsInode(org.dcache.chimera.FsInode) JdbcFs(org.dcache.chimera.JdbcFs) Before(org.junit.Before)

Example 2 with Stat

use of org.dcache.chimera.posix.Stat in project dcache by dCache.

the class StorageUriTest method write.

private void write(String location, boolean append) throws Exception {
    int len = location.length();
    byte[] buffer = location.getBytes();
    Stat stat = inode_suri.stat();
    /*
         * Emulate OPEN TRUNCATE for write.
         */
    if (!append) {
        if (ChimeraVfs.shouldRejectAttributeUpdates(inode_suri, fs)) {
            throw new PermissionDeniedChimeraFsException("setStat not allowed.");
        }
        stat.setSize(0);
        inode_suri.setStat(stat);
    }
    if (ChimeraVfs.shouldRejectUpdates(inode_suri, fs)) {
        throw new PermissionDeniedChimeraFsException("write not allowed.");
    }
    inode_suri.write(stat.getSize(), buffer, 0, len);
    addStorageLocation(location);
}
Also used : Stat(org.dcache.chimera.posix.Stat) PermissionDeniedChimeraFsException(org.dcache.chimera.PermissionDeniedChimeraFsException)

Example 3 with Stat

use of org.dcache.chimera.posix.Stat in project dcache by dCache.

the class FsSqlDriver method statTag.

Stat statTag(FsInode dir, String name) throws ChimeraFsException {
    Long tagId = getTagId(dir, name);
    if (tagId == null) {
        throw FileNotFoundChimeraFsException.ofTag(dir, name);
    }
    try {
        return _jdbc.queryForObject("SELECT isize,inlink,imode,iuid,igid,iatime,ictime,imtime " + "FROM t_tags_inodes WHERE itagid=?", (rs, rowNum) -> {
            Stat ret = new Stat();
            ret.setSize(rs.getLong("isize"));
            ret.setATime(rs.getTimestamp("iatime").getTime());
            ret.setCTime(rs.getTimestamp("ictime").getTime());
            ret.setMTime(rs.getTimestamp("imtime").getTime());
            ret.setUid(rs.getInt("iuid"));
            ret.setGid(rs.getInt("igid"));
            ret.setMode(rs.getInt("imode"));
            ret.setNlink(rs.getInt("inlink"));
            ret.setIno(tagId);
            ret.setGeneration(rs.getTimestamp("imtime").getTime());
            ret.setDev(17);
            ret.setRdev(13);
            return ret;
        }, tagId);
    } catch (IncorrectResultSizeDataAccessException e) {
        throw FileNotFoundChimeraFsException.ofTag(dir, name);
    }
}
Also used : Stat(org.dcache.chimera.posix.Stat) IncorrectResultSizeDataAccessException(org.springframework.dao.IncorrectResultSizeDataAccessException)

Example 4 with Stat

use of org.dcache.chimera.posix.Stat in project dcache by dCache.

the class FsSqlDriver method newDirectoryStream.

/**
 * Returns {@link DirectoryStreamB} of ChimeraDirectoryEntry in the directory.
 *
 * @param dir
 * @return stream of directory entries
 */
DirectoryStreamB<ChimeraDirectoryEntry> newDirectoryStream(FsInode dir) {
    return new DirectoryStreamB<ChimeraDirectoryEntry>() {

        final DirectoryStreamImpl stream = new DirectoryStreamImpl(dir, _jdbc);

        @Override
        public Iterator<ChimeraDirectoryEntry> iterator() {
            return new Iterator<ChimeraDirectoryEntry>() {

                private ChimeraDirectoryEntry current = innerNext();

                @Override
                public boolean hasNext() {
                    return current != null;
                }

                @Override
                public ChimeraDirectoryEntry next() {
                    if (current == null) {
                        throw new NoSuchElementException("No more entries");
                    }
                    ChimeraDirectoryEntry entry = current;
                    current = innerNext();
                    return entry;
                }

                protected ChimeraDirectoryEntry innerNext() {
                    try {
                        ResultSet rs = stream.next();
                        if (rs == null) {
                            return null;
                        }
                        Stat stat = toStat(rs);
                        FsInode inode = new FsInode(dir.getFs(), rs.getLong("inumber"), FsInodeType.INODE, 0, stat);
                        inode.setParent(dir);
                        return new ChimeraDirectoryEntry(rs.getString("iname"), inode, stat);
                    } catch (SQLException e) {
                        LOGGER.error("failed to fetch next entry: {}", e.getMessage());
                        return null;
                    }
                }
            };
        }

        @Override
        public void close() throws IOException {
            stream.close();
        }
    };
}
Also used : Stat(org.dcache.chimera.posix.Stat) SQLException(java.sql.SQLException) Iterator(java.util.Iterator) ResultSet(java.sql.ResultSet) NoSuchElementException(java.util.NoSuchElementException)

Example 5 with Stat

use of org.dcache.chimera.posix.Stat in project dcache by dCache.

the class FsSqlDriver method createLevel.

/**
 * creates an entry in t_level_x table
 *
 * @param inode
 * @param uid
 * @param gid
 * @param mode
 * @param level
 * @return
 */
FsInode createLevel(FsInode inode, int uid, int gid, int mode, int level) {
    Timestamp now = new Timestamp(System.currentTimeMillis());
    _jdbc.update("INSERT INTO t_level_" + level + "(inumber,imode,inlink,iuid,igid,isize,ictime,iatime,imtime,ifiledata) VALUES(?,?,1,?,?,0,?,?,?, NULL)", ps -> {
        ps.setLong(1, inode.ino());
        ps.setInt(2, mode);
        ps.setInt(3, uid);
        ps.setInt(4, gid);
        ps.setTimestamp(5, now);
        ps.setTimestamp(6, now);
        ps.setTimestamp(7, now);
    });
    Stat stat = new Stat();
    stat.setCrTime(now.getTime());
    stat.setGeneration(0);
    stat.setSize(0);
    stat.setATime(now.getTime());
    stat.setCTime(now.getTime());
    stat.setMTime(now.getTime());
    stat.setUid(uid);
    stat.setGid(gid);
    stat.setMode(mode | UnixPermission.S_IFREG);
    stat.setNlink(1);
    stat.setIno(inode.ino());
    stat.setDev(17);
    stat.setRdev(13);
    return new FsInode(inode.getFs(), inode.ino(), FsInodeType.INODE, level, stat);
}
Also used : Stat(org.dcache.chimera.posix.Stat) Timestamp(java.sql.Timestamp)

Aggregations

Stat (org.dcache.chimera.posix.Stat)85 Test (org.junit.Test)39 FsInode (org.dcache.chimera.FsInode)6 PnfsId (diskCacheV111.util.PnfsId)5 Timestamp (java.sql.Timestamp)5 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)5 RetentionPolicy (diskCacheV111.util.RetentionPolicy)4 File (java.io.File)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Lists (com.google.common.collect.Lists)2 AccessLatency (diskCacheV111.util.AccessLatency)2 CacheException (diskCacheV111.util.CacheException)2 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)2 StorageInfo (diskCacheV111.vehicles.StorageInfo)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2