Skip to content

Commit

Permalink
nfsv3: merge NameUtils and HimeraNfsUtils into single class
Browse files Browse the repository at this point in the history
Motivation:
There are no reasons to have to utility classes in a single package
(plus Himera vs Chimera)

Modification:
merge NameUtils and HimeraNfsUtils into single class Utils class,
including corresponding tests.

Result:
same code, less classes

Acked-by: Marina Sahakyan
Target: master
  • Loading branch information
kofemann committed Feb 26, 2021
1 parent 235e266 commit 1ec32c5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 115 deletions.
50 changes: 0 additions & 50 deletions core/src/main/java/org/dcache/nfs/v3/NameUtils.java

This file was deleted.

66 changes: 33 additions & 33 deletions core/src/main/java/org/dcache/nfs/v3/NfsServerV3.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.dcache.nfs.v3.HimeraNfsUtils.defaultPostOpAttr;
import static org.dcache.nfs.v3.HimeraNfsUtils.defaultWccData;
import static org.dcache.nfs.v3.NameUtils.checkFilename;
import static org.dcache.nfs.v3.Utils.defaultPostOpAttr;
import static org.dcache.nfs.v3.Utils.defaultWccData;
import static org.dcache.nfs.v3.Utils.checkFilename;

import org.dcache.nfs.vfs.FsStat;
import org.dcache.nfs.vfs.Inode;
Expand Down Expand Up @@ -208,7 +208,7 @@ public ACCESS3res NFSPROC3_ACCESS_3(RpcCall call$, ACCESS3args arg1) {
Inode inode = new Inode(arg1.object.data);
Stat objStat = fs.getattr(inode);

HimeraNfsUtils.fill_attributes(objStat, res.resok.obj_attributes.attributes);
Utils.fill_attributes(objStat, res.resok.obj_attributes.attributes);

int realAccess = fs.access(inode, arg1.access.value);

Expand Down Expand Up @@ -248,7 +248,7 @@ public COMMIT3res NFSPROC3_COMMIT_3(RpcCall call$, COMMIT3args arg1) {
res.resok.file_wcc.after.attributes_follow = true;
res.resok.file_wcc.after.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.file_wcc.after.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.file_wcc.after.attributes);
res.resok.file_wcc.before = new pre_op_attr();
res.resok.file_wcc.before.attributes_follow = false;
res.resok.verf = writeVerifier;
Expand Down Expand Up @@ -324,7 +324,7 @@ public CREATE3res NFSPROC3_CREATE_3(RpcCall call$, CREATE3args arg1) {
res.resok.obj_attributes.attributes_follow = true;
res.resok.obj_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(inodeStat, res.resok.obj_attributes.attributes);
Utils.fill_attributes(inodeStat, res.resok.obj_attributes.attributes);
res.resok.obj = new post_op_fh3();
res.resok.obj.handle_follows = true;
res.resok.obj.handle = new nfs_fh3();
Expand All @@ -339,7 +339,7 @@ public CREATE3res NFSPROC3_CREATE_3(RpcCall call$, CREATE3args arg1) {
parentStat.setNlink(parentStat.getNlink() + 1);
parentStat.setMTime(now);

HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);

res.resok.dir_wcc.before = new pre_op_attr();
res.resok.dir_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -400,7 +400,7 @@ public FSINFO3res NFSPROC3_FSINFO_3(RpcCall call$, FSINFO3args arg1) {
res.resok.obj_attributes.attributes_follow = true;
res.resok.obj_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);

res.resok.properties = new uint32(nfs3_prot.FSF3_CANSETTIME |
nfs3_prot.FSF3_HOMOGENEOUS |
Expand Down Expand Up @@ -445,7 +445,7 @@ public FSSTAT3res NFSPROC3_FSSTAT_3(RpcCall call$, FSSTAT3args arg1) {

Inode inode = new Inode(arg1.fsroot.data);

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);

} catch (Exception e) {
_log.error("FSSTAT", e);
Expand Down Expand Up @@ -474,7 +474,7 @@ public GETATTR3res NFSPROC3_GETATTR_3(RpcCall call$, GETATTR3args arg1) {
res.resok = new GETATTR3resok();

res.resok.obj_attributes = new fattr3();
HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes);

} catch (ChimeraNFSException e) {
res.status = e.getStatus();
Expand Down Expand Up @@ -509,7 +509,7 @@ public LINK3res NFSPROC3_LINK_3(RpcCall call$, LINK3args arg1) {
res.resok.file_attributes.attributes_follow = true;
res.resok.file_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(hlink), res.resok.file_attributes.attributes);
Utils.fill_attributes(fs.getattr(hlink), res.resok.file_attributes.attributes);

res.resok.linkdir_wcc = new wcc_data();
res.resok.linkdir_wcc.after = new post_op_attr();
Expand All @@ -519,7 +519,7 @@ public LINK3res NFSPROC3_LINK_3(RpcCall call$, LINK3args arg1) {
// fake answer
parentStat.setNlink(parentStat.getNlink() + 1);
parentStat.setMTime(System.currentTimeMillis());
HimeraNfsUtils.fill_attributes(parentStat, res.resok.linkdir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.linkdir_wcc.after.attributes);

res.resok.linkdir_wcc.before = new pre_op_attr();
res.resok.linkdir_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -566,13 +566,13 @@ public LOOKUP3res NFSPROC3_LOOKUP_3(RpcCall call$, LOOKUP3args arg1) {
res.resok.obj_attributes.attributes_follow = true;
res.resok.obj_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);

res.resok.dir_attributes = new post_op_attr();
res.resok.dir_attributes.attributes_follow = true;
res.resok.dir_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(parent), res.resok.dir_attributes.attributes);
Utils.fill_attributes(fs.getattr(parent), res.resok.dir_attributes.attributes);

} catch (ChimeraNFSException hne) {
_log.debug("lookup {}", hne.toString());
Expand Down Expand Up @@ -627,7 +627,7 @@ public MKDIR3res NFSPROC3_MKDIR_3(RpcCall call$, MKDIR3args arg1) {
res.resok.obj_attributes.attributes_follow = true;
res.resok.obj_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);

res.resok.dir_wcc = new wcc_data();
res.resok.dir_wcc.after = new post_op_attr();
Expand All @@ -637,7 +637,7 @@ public MKDIR3res NFSPROC3_MKDIR_3(RpcCall call$, MKDIR3args arg1) {
// fake answer
parentStat.setNlink(parentStat.getNlink() + 1);
parentStat.setMTime(System.currentTimeMillis());
HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);

res.resok.dir_wcc.before = new pre_op_attr();
res.resok.dir_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -736,7 +736,7 @@ public READDIRPLUS3res NFSPROC3_READDIRPLUS_3(RpcCall call$, READDIRPLUS3args ar
res.resok.dir_attributes.attributes = new fattr3();
res.resok.cookieverf = new cookieverf3(directoryStream.getVerifier());

HimeraNfsUtils.fill_attributes(dirStat, res.resok.dir_attributes.attributes);
Utils.fill_attributes(dirStat, res.resok.dir_attributes.attributes);


int currcount = READDIRPLUS3RESOK_SIZE;
Expand All @@ -761,7 +761,7 @@ public READDIRPLUS3res NFSPROC3_READDIRPLUS_3(RpcCall call$, READDIRPLUS3args ar
currentEntry.name_attributes = new post_op_attr();
currentEntry.name_attributes.attributes_follow = true;
currentEntry.name_attributes.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(le.getStat(), currentEntry.name_attributes.attributes);
Utils.fill_attributes(le.getStat(), currentEntry.name_attributes.attributes);

// check if writing this entry exceeds the count limit
int newSize = ENTRYPLUS3_SIZE + name.length() + currentEntry.name_handle.handle.data.length;
Expand Down Expand Up @@ -842,7 +842,7 @@ public READDIR3res NFSPROC3_READDIR_3(RpcCall call$, READDIR3args arg1) {
res.resok.dir_attributes = new post_op_attr();
res.resok.dir_attributes.attributes_follow = true;
res.resok.dir_attributes.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(dirStat, res.resok.dir_attributes.attributes);
Utils.fill_attributes(dirStat, res.resok.dir_attributes.attributes);

res.resok.cookieverf = new cookieverf3(directoryStream.getVerifier());

Expand Down Expand Up @@ -919,7 +919,7 @@ public READLINK3res NFSPROC3_READLINK_3(RpcCall call$, READLINK3args arg1) {

res.resok.symlink_attributes.attributes_follow = true;
res.resok.symlink_attributes.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.symlink_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.symlink_attributes.attributes);

res.status = nfsstat.NFS_OK;

Expand Down Expand Up @@ -977,7 +977,7 @@ public READ3res NFSPROC3_READ_3(RpcCall call$, READ3args arg1) {
res.resok.file_attributes = new post_op_attr();
res.resok.file_attributes.attributes_follow = true;
res.resok.file_attributes.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(inodeStat, res.resok.file_attributes.attributes);
Utils.fill_attributes(inodeStat, res.resok.file_attributes.attributes);
} catch (ChimeraNFSException hne) {
res.status = hne.getStatus();
res.resfail = new READ3resfail();
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public REMOVE3res NFSPROC3_REMOVE_3(RpcCall call$, REMOVE3args arg1) {
res.resok.dir_wcc.before = new pre_op_attr();
res.resok.dir_wcc.before.attributes_follow = true;
res.resok.dir_wcc.before.attributes = new wcc_attr();
HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.before.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.before.attributes);


// correct parent modification time and nlink counter
Expand All @@ -1029,7 +1029,7 @@ public REMOVE3res NFSPROC3_REMOVE_3(RpcCall call$, REMOVE3args arg1) {
res.resok.dir_wcc.after = new post_op_attr();
res.resok.dir_wcc.after.attributes_follow = true;
res.resok.dir_wcc.after.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);


} catch (ChimeraNFSException hne) {
Expand Down Expand Up @@ -1072,7 +1072,7 @@ public RENAME3res NFSPROC3_RENAME_3(RpcCall call$, RENAME3args arg1) {
res.resok.fromdir_wcc.after = new post_op_attr();
res.resok.fromdir_wcc.after.attributes_follow = true;
res.resok.fromdir_wcc.after.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(fs.getattr(from), res.resok.fromdir_wcc.after.attributes);
Utils.fill_attributes(fs.getattr(from), res.resok.fromdir_wcc.after.attributes);

res.resok.fromdir_wcc.before = new pre_op_attr();
res.resok.fromdir_wcc.before.attributes_follow = false;
Expand All @@ -1081,7 +1081,7 @@ public RENAME3res NFSPROC3_RENAME_3(RpcCall call$, RENAME3args arg1) {
res.resok.todir_wcc.after = new post_op_attr();
res.resok.todir_wcc.after.attributes_follow = true;
res.resok.todir_wcc.after.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(fs.getattr(to), res.resok.todir_wcc.after.attributes);
Utils.fill_attributes(fs.getattr(to), res.resok.todir_wcc.after.attributes);

res.resok.todir_wcc.before = new pre_op_attr();
res.resok.todir_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -1131,15 +1131,15 @@ public RMDIR3res NFSPROC3_RMDIR_3(RpcCall call$, RMDIR3args arg1) {
res.resok.dir_wcc.before = new pre_op_attr();
res.resok.dir_wcc.before.attributes_follow = true;
res.resok.dir_wcc.before.attributes = new wcc_attr();
HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.before.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.before.attributes);

res.resok.dir_wcc.after.attributes_follow = true;
res.resok.dir_wcc.after.attributes = new fattr3();

parentStat.setMTime(System.currentTimeMillis());
parentStat.setNlink(parentStat.getNlink() - 1);

HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);

} catch (ChimeraNFSException hne) {
res.resfail = new RMDIR3resfail();
Expand Down Expand Up @@ -1167,13 +1167,13 @@ public SETATTR3res NFSPROC3_SETATTR_3(RpcCall call$, SETATTR3args arg1) {
Inode inode = new Inode(arg1.object.data);
sattr3 newAttr = arg1.new_attributes;

HimeraNfsUtils.set_sattr(inode, fs, newAttr);
Utils.set_sattr(inode, fs, newAttr);
res.resok = new SETATTR3resok();
res.resok.obj_wcc = new wcc_data();
res.resok.obj_wcc.after = new post_op_attr();
res.resok.obj_wcc.after.attributes_follow = true;
res.resok.obj_wcc.after.attributes = new fattr3();
HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_wcc.after.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_wcc.after.attributes);

res.resok.obj_wcc.before = new pre_op_attr();
res.resok.obj_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -1214,15 +1214,15 @@ public SYMLINK3res NFSPROC3_SYMLINK_3(RpcCall call$, SYMLINK3args arg1) {
Stat parentStat = fs.getattr(parent);
Inode inode = fs.symlink(parent, file, link, call$.getCredential().getSubject(), 777);

HimeraNfsUtils.set_sattr(inode, fs, linkAttr);
Utils.set_sattr(inode, fs, linkAttr);

res.resok = new SYMLINK3resok();

res.resok.obj_attributes = new post_op_attr();
res.resok.obj_attributes.attributes_follow = true;
res.resok.obj_attributes.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.obj_attributes.attributes);
res.resok.obj = new post_op_fh3();
res.resok.obj.handle_follows = true;
res.resok.obj.handle = new nfs_fh3();
Expand All @@ -1237,7 +1237,7 @@ public SYMLINK3res NFSPROC3_SYMLINK_3(RpcCall call$, SYMLINK3args arg1) {
parentStat.setNlink(parentStat.getNlink() + 1);
parentStat.setMTime(System.currentTimeMillis());

HimeraNfsUtils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);
Utils.fill_attributes(parentStat, res.resok.dir_wcc.after.attributes);

res.resok.dir_wcc.before = new pre_op_attr();
res.resok.dir_wcc.before.attributes_follow = false;
Expand Down Expand Up @@ -1285,7 +1285,7 @@ public WRITE3res NFSPROC3_WRITE_3(RpcCall call$, WRITE3args arg1) {
res.resok.file_wcc.after.attributes_follow = true;
res.resok.file_wcc.after.attributes = new fattr3();

HimeraNfsUtils.fill_attributes(fs.getattr(inode), res.resok.file_wcc.after.attributes);
Utils.fill_attributes(fs.getattr(inode), res.resok.file_wcc.after.attributes);
res.resok.file_wcc.before = new pre_op_attr();
res.resok.file_wcc.before.attributes_follow = false;
res.resok.committed = ret.getStabilityLevel().toStableHow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package org.dcache.nfs.v3;

import org.dcache.nfs.status.AccessException;
import org.dcache.nfs.status.NameTooLongException;
import org.dcache.nfs.v3.xdr.fattr3;
import org.dcache.nfs.v3.xdr.fileid3;
import org.dcache.nfs.v3.xdr.ftype3;
Expand Down Expand Up @@ -46,14 +48,14 @@
import java.util.concurrent.TimeUnit;


public class HimeraNfsUtils {
public class Utils {


private static final int MODE_MASK = 0770000;

private static final Logger _log = LoggerFactory.getLogger(HimeraNfsUtils.class);
private static final Logger _log = LoggerFactory.getLogger(Utils.class);

private HimeraNfsUtils() {
private Utils() {
// no instance allowed
}

Expand Down Expand Up @@ -233,4 +235,23 @@ public static wcc_data defaultWccData() {
wccData.before = defaultPreOpAttr();
return wccData;
}

/**
* Validate ${code filename} requirements.
* @param filename
* @throws AccessException if filename does not meet expected constrains
* @throws NameTooLongException if filename is longer than negotiated with PATHCONF operation.
*/
public static void checkFilename(String filename) throws AccessException, NameTooLongException {

// FIXME: merge with NFSv4 defaults
if (filename.length() > 256) {
throw new NameTooLongException();
}

if (filename.length() == 0 || filename.indexOf('/') != -1 || filename.indexOf('\0') != -1 ) {
throw new AccessException();
}

}
}
Loading

0 comments on commit 1ec32c5

Please sign in to comment.