-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#57] Added support for hard links. #113
Draft
korydraughn
wants to merge
2
commits into
irods:main
Choose a base branch
from
korydraughn:57
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,9 @@ | |
import java.nio.file.Paths; | ||
import java.security.AccessController; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
@@ -75,6 +77,8 @@ | |
import org.irods.jargon.core.pub.DataObjectAO; | ||
import org.irods.jargon.core.pub.IRODSAccessObjectFactory; | ||
import org.irods.jargon.core.pub.IRODSFileSystemAO; | ||
import org.irods.jargon.core.pub.IRODSGenQueryExecutor; | ||
import org.irods.jargon.core.pub.RuleProcessingAO; | ||
import org.irods.jargon.core.pub.UserAO; | ||
import org.irods.jargon.core.pub.UserGroupAO; | ||
import org.irods.jargon.core.pub.domain.ObjStat; | ||
|
@@ -85,11 +89,20 @@ | |
import org.irods.jargon.core.pub.io.IRODSFile; | ||
import org.irods.jargon.core.pub.io.IRODSFileFactory; | ||
import org.irods.jargon.core.pub.io.IRODSRandomAccessFile; | ||
import org.irods.jargon.core.query.AbstractIRODSGenQuery.RowCountOptions; | ||
import org.irods.jargon.core.query.CollectionAndDataObjectListingEntry; | ||
import org.irods.jargon.core.query.CollectionAndDataObjectListingEntry.ObjectType; | ||
import org.irods.jargon.core.query.IRODSGenQuery; | ||
import org.irods.jargon.core.query.IRODSQueryResultRow; | ||
import org.irods.jargon.core.query.IRODSQueryResultSet; | ||
import org.irods.jargon.core.query.JargonQueryException; | ||
import org.irods.jargon.core.rule.IRODSRuleExecResult; | ||
import org.irods.jargon.core.rule.IrodsRuleInvocationTypeEnum; | ||
import org.irods.jargon.core.rule.RuleInvocationConfiguration; | ||
import org.irods.nfsrods.config.IRODSClientConfig; | ||
import org.irods.nfsrods.config.IRODSProxyAdminAccountConfig; | ||
import org.irods.nfsrods.config.ServerConfig; | ||
import org.irods.nfsrods.utils.JSONUtils; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
|
@@ -103,6 +116,7 @@ public class IRODSVirtualFileSystem implements VirtualFileSystem, AclCheckable | |
private static final long FIXED_TIMESTAMP = System.currentTimeMillis(); | ||
private static final FsStat FILE_SYSTEM_STAT_INFO = new FsStat(0, 0, 0, 0); | ||
|
||
private final IRODSClientConfig irodsSvrConfig_; | ||
private final IRODSAccessObjectFactory factory_; | ||
private final IRODSIdMapper idMapper_; | ||
private final InodeToPathMapper inodeToPathMapper_; | ||
|
@@ -132,28 +146,27 @@ public IRODSVirtualFileSystem(ServerConfig _config, | |
CacheManager _cacheManager) | ||
throws DataNotFoundException, JargonException | ||
{ | ||
irodsSvrConfig_ = _config.getIRODSClientConfig(); | ||
factory_ = _factory; | ||
idMapper_ = _idMapper; | ||
inodeToPathMapper_ = new InodeToPathMapper(_config, _factory); | ||
|
||
IRODSClientConfig rodsSvrConfig = _config.getIRODSClientConfig(); | ||
|
||
ROOT_COLLECTION = Paths.get("/"); | ||
ZONE_COLLECTION = ROOT_COLLECTION.resolve(rodsSvrConfig.getZone()); | ||
ZONE_COLLECTION = ROOT_COLLECTION.resolve(irodsSvrConfig_.getZone()); | ||
HOME_COLLECTION = ZONE_COLLECTION.resolve("home"); | ||
PUBLIC_COLLECTION = ZONE_COLLECTION.resolve("public"); | ||
TRASH_COLLECTION = ZONE_COLLECTION.resolve("trash"); | ||
|
||
IRODSProxyAdminAccountConfig proxyConfig = rodsSvrConfig.getIRODSProxyAdminAcctConfig(); | ||
Path proxyUserHomeCollection = Paths.get("/", rodsSvrConfig.getZone(), "home", proxyConfig.getUsername()); | ||
IRODSProxyAdminAccountConfig proxyConfig = irodsSvrConfig_.getIRODSProxyAdminAcctConfig(); | ||
Path proxyUserHomeCollection = Paths.get("/", irodsSvrConfig_.getZone(), "home", proxyConfig.getUsername()); | ||
// @formatter:off | ||
adminAcct_ = IRODSAccount.instance(rodsSvrConfig.getHost(), | ||
rodsSvrConfig.getPort(), | ||
adminAcct_ = IRODSAccount.instance(irodsSvrConfig_.getHost(), | ||
irodsSvrConfig_.getPort(), | ||
proxyConfig.getUsername(), | ||
proxyConfig.getPassword(), | ||
proxyUserHomeCollection.toString(), | ||
rodsSvrConfig.getZone(), | ||
rodsSvrConfig.getDefaultResource()); | ||
irodsSvrConfig_.getZone(), | ||
irodsSvrConfig_.getDefaultResource()); | ||
// @formatter:on | ||
|
||
readWriteAclWhitelist_ = new ReadWriteAclWhitelist(factory_, adminAcct_); | ||
|
@@ -644,7 +657,7 @@ public Access checkAcl(Subject _subject, Inode _inode, int _accessMask) throws C | |
} | ||
|
||
String path = getPath(toInodeNumber(_inode)).toString(); | ||
|
||
// Key (String) => <user_id>#<access_mask>#<path> | ||
// Value (Access) => ALLOW/DENY | ||
// Cached stat information must be scoped to the user due to the permissions | ||
|
@@ -832,7 +845,64 @@ public boolean hasIOLayout(Inode _inode) throws IOException | |
@Override | ||
public Inode link(Inode _parent, Inode _existing, String _target, Subject _subject) throws IOException | ||
{ | ||
throw new UnsupportedOperationException("Not supported"); | ||
log_.debug("vfs::link"); | ||
|
||
Path linkParentPath = getPath(toInodeNumber(_parent)); | ||
Path linkTargetPath = getPath(toInodeNumber(_existing)); | ||
Path linkNamePath = linkParentPath.resolve(_target); | ||
|
||
log_.debug("list - _parent = {}", linkParentPath); // The parent directory of _target. | ||
log_.debug("list - _existing = {}", linkTargetPath); // The file or directory to link to. | ||
log_.debug("list - _target = {}", _target); // The filename or absolute path of the link. | ||
log_.debug("list - _subject = {}", Subjects.getUid(_subject)); // The UID of the user who executed this command. | ||
|
||
// _parent + _target => the absolute path of the hard link. | ||
|
||
try | ||
{ | ||
IRODSAccount acct = getCurrentIRODSUser().getAccount(); | ||
Optional<String> replicaNumber = getReplicaNumberOfLatestGoodReplica(acct, linkTargetPath); | ||
|
||
if (!replicaNumber.isPresent()) | ||
{ | ||
throw new NoEntException(String.format("No good replica to link for [%s]", linkTargetPath)); | ||
} | ||
|
||
Map<String, String> jsonInput = new HashMap<>(); | ||
jsonInput.put("operation", "hard_link_create"); | ||
jsonInput.put("logical_path", linkTargetPath.toString()); | ||
jsonInput.put("replica_number", replicaNumber.get()); | ||
jsonInput.put("link_name", linkNamePath.toString()); | ||
|
||
RuleProcessingAO rpao = factory_.getRuleProcessingAO(acct); | ||
RuleInvocationConfiguration ctx = new RuleInvocationConfiguration(); | ||
ctx.setIrodsRuleInvocationTypeEnum(IrodsRuleInvocationTypeEnum.OTHER); | ||
ctx.setRuleEngineSpecifier(irodsSvrConfig_.getHardLinksRuleEnginePluginInstanceName()); | ||
|
||
StringBuilder sb = new StringBuilder(JSONUtils.toJSON(jsonInput)); | ||
sb.append("\nINPUT null\nOUTPUT ruleExecOut\n"); | ||
|
||
IRODSRuleExecResult result = rpao.executeRule(sb.toString(), null, ctx); | ||
|
||
if (!result.getRuleExecOut().isEmpty() || !result.getRuleExecErr().isEmpty()) | ||
{ | ||
throw new IOException("Unexpected output on creation of hard link"); | ||
} | ||
|
||
long newInodeNumber = inodeToPathMapper_.getAndIncrementFileID(); | ||
inodeToPathMapper_.map(newInodeNumber, linkNamePath); | ||
|
||
return toFh(newInodeNumber); | ||
} | ||
catch (JargonException | JargonQueryException e) | ||
{ | ||
log_.error(e.getMessage()); | ||
throw new IOException(e); | ||
} | ||
finally | ||
{ | ||
closeCurrentConnection(); | ||
} | ||
} | ||
|
||
@Override | ||
|
@@ -1126,6 +1196,7 @@ public int read(Inode _inode, byte[] _data, long _offset, int _count) throws IOE | |
@Override | ||
public String readlink(Inode _inode) throws IOException | ||
{ | ||
log_.debug("vfs::readlink"); | ||
throw new UnsupportedOperationException("Not supported"); | ||
} | ||
|
||
|
@@ -1299,7 +1370,7 @@ private Stat statPath(Path _path, long _inodeNumber) throws IOException | |
|
||
stat.setUid(userId); | ||
stat.setGid(groupId); | ||
stat.setNlink(1); | ||
stat.setNlink(1); // TODO: Should hard links affect this number? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we'd increase it and then... decrease it somewhere else? |
||
stat.setDev(17); | ||
stat.setIno((int) _inodeNumber); | ||
stat.setRdev(0); | ||
|
@@ -1553,6 +1624,33 @@ private boolean isAdministrator(String _userName) throws JargonException | |
|
||
return user.getUserType() == UserTypeEnum.RODS_ADMIN; | ||
} | ||
|
||
private Optional<String> getReplicaNumberOfLatestGoodReplica(IRODSAccount _acct, Path _logicalPath) | ||
throws JargonException, JargonQueryException | ||
{ | ||
// @formatter:off | ||
String gql = String.format("select max(DATA_MODIFY_TIME) " + | ||
"where " + | ||
" COLL_NAME = '%s' and" + | ||
" DATA_NAME = '%s' and" + | ||
" DATA_REPL_STATUS = '1'", | ||
_logicalPath.getParent(), | ||
_logicalPath.getFileName()); | ||
// @formatter:on | ||
final int rowsDesired = 1; | ||
IRODSGenQuery genQuery = IRODSGenQuery.instance(gql, rowsDesired, RowCountOptions.ROW_COUNT_FOR_THIS_RESULT); | ||
IRODSGenQueryExecutor executor = factory_.getIRODSGenQueryExecutor(_acct); | ||
|
||
final int partialStartIndex = 0; | ||
IRODSQueryResultSet resultSet = executor.executeIRODSQueryAndCloseResult(genQuery, partialStartIndex); | ||
|
||
for (IRODSQueryResultRow row : resultSet.getResults()) | ||
{ | ||
return Optional.of(row.getColumn(0)); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
|
||
private void closeCurrentConnection() throws IOException | ||
{ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list -> link