Commit a61548af authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs: make NFSv4OperationFactory an interface

Make code more flexible and reduses code duplication

Acked-by: Gerd
parent d9e1019f
......@@ -13,20 +13,18 @@ import org.dcache.chimera.posix.UnixPermissionHandler;
*/
public abstract class AbstractNFSv4Operation {
protected final nfs_resop4 _result = new nfs_resop4();
protected final nfs_argop4 _args;
protected AclHandler _permissionHandler = UnixPermissionHandler.getInstance();
public AbstractNFSv4Operation(nfs_argop4 args, int opCode) {
_result.resop = opCode;
_args = args;
}
/**
* Process current opration.
* @return <code>true</code> if next operration may continue.
*/
public abstract boolean process(CompoundContext context);
protected final nfs_resop4 _result = new nfs_resop4();
protected final nfs_argop4 _args;
protected AclHandler _permissionHandler = UnixPermissionHandler.getInstance();
public AbstractNFSv4Operation(nfs_argop4 args, int opCode) {
_result.resop = opCode;
_args = args;
}
/**
* Process current opration.
* @return <code>true</code> if next operration may continue.
*/
public abstract boolean process(CompoundContext context);
}
package org.dcache.chimera.nfs.v4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs4_prot;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
public class MDSOperationFactory implements NFSv4OperationFactory {
@Override
public AbstractNFSv4Operation getOperation(nfs_argop4 op) {
switch (op.argop) {
case nfs_opnum4.OP_ACCESS:
return new OperationACCESS(op);
case nfs_opnum4.OP_CLOSE:
return new OperationCLOSE(op);
case nfs_opnum4.OP_COMMIT:
return new OperationCOMMIT(op);
case nfs_opnum4.OP_CREATE:
return new OperationCREATE(op);
case nfs_opnum4.OP_DELEGPURGE:
return new OperationDELEGPURGE(op);
case nfs_opnum4.OP_DELEGRETURN:
return new OperationDELEGRETURN(op);
case nfs_opnum4.OP_GETATTR:
return new OperationGETATTR(op);
case nfs_opnum4.OP_GETFH:
return new OperationGETFH(op);
case nfs_opnum4.OP_LINK:
return new OperationLINK(op);
case nfs_opnum4.OP_LOCK:
return new OperationLOCK(op);
case nfs_opnum4.OP_LOCKT:
return new OperationLOCKT(op);
case nfs_opnum4.OP_LOCKU:
return new OperationLOCKU(op);
case nfs_opnum4.OP_LOOKUP:
return new OperationLOOKUP(op);
case nfs_opnum4.OP_LOOKUPP:
return new OperationLOOKUPP(op);
case nfs_opnum4.OP_NVERIFY:
return new OperationNVERIFY(op);
case nfs_opnum4.OP_OPEN:
return new OperationOPEN(op);
case nfs_opnum4.OP_OPENATTR:
return new OperationOPENATTR(op);
case nfs_opnum4.OP_OPEN_CONFIRM:
return new OperationOPEN_CONFIRM(op);
case nfs_opnum4.OP_OPEN_DOWNGRADE:
break;
case nfs_opnum4.OP_PUTFH:
return new OperationPUTFH(op);
case nfs_opnum4.OP_PUTPUBFH:
return new OperationPUTPUBFH(op);
case nfs_opnum4.OP_PUTROOTFH:
return new OperationPUTROOTFH(op);
case nfs_opnum4.OP_READ:
return new OperationREAD(op);
case nfs_opnum4.OP_READDIR:
return new OperationREADDIR(op);
case nfs_opnum4.OP_READLINK:
return new OperationREADLINK(op);
case nfs_opnum4.OP_REMOVE:
return new OperationREMOVE(op);
case nfs_opnum4.OP_RENAME:
return new OperationRENAME(op);
case nfs_opnum4.OP_RENEW:
return new OperationRENEW(op);
case nfs_opnum4.OP_RESTOREFH:
return new OperationRESTOREFH(op);
case nfs_opnum4.OP_SAVEFH:
return new OperationSAVEFH(op);
case nfs_opnum4.OP_SECINFO:
return new OperationSECINFO(op);
case nfs_opnum4.OP_SETATTR:
return new OperationSETATTR(op);
case nfs_opnum4.OP_SETCLIENTID:
return new OperationSETCLIENTID(op);
case nfs_opnum4.OP_SETCLIENTID_CONFIRM:
return new OperationSETCLIENTID_CONFIRM(op);
case nfs_opnum4.OP_VERIFY:
return new OperationVERIFY(op);
case nfs_opnum4.OP_WRITE:
return new OperationWRITE(op);
/* case nfs_opnum4.OP_RELEASE_LOCKOWNER:
nRes.oprelease_lockowner = new RELEASE_LOCKOWNER4res();
res = new NFSv4OperationResult(nRes, nfsstat4.NFS4ERR_NOTSUPP);
break; */
/**
* NFSv4.1 (pNFS)
*/
case nfs_opnum4.OP_GETDEVICELIST:
return new OperationGETDEVICELIST(op);
case nfs_opnum4.OP_LAYOUTGET:
return new OperationLAYOUTGET(op);
case nfs_opnum4.OP_LAYOUTCOMMIT:
return new OperationLAYOUTCOMMIT(op);
case nfs_opnum4.OP_LAYOUTRETURN:
return new OperationLAYOUTRETURN(op);
case nfs_opnum4.OP_GETDEVICEINFO:
return new OperationGETDEVICEINFO(op);
case nfs_opnum4.OP_EXCHANGE_ID:
return new OperationEXCHANGE_ID(op, nfs4_prot.EXCHGID4_FLAG_USE_PNFS_MDS);
case nfs_opnum4.OP_CREATE_SESSION:
return new OperationCREATE_SESSION(op);
case nfs_opnum4.OP_DESTROY_SESSION:
return new OperationDESTROY_SESSION(op);
case nfs_opnum4.OP_SEQUENCE:
return new OperationSEQUENCE(op, true);
case nfs_opnum4.OP_ILLEGAL:
}
return new OperationILLEGAL(op);
}
}
......@@ -31,7 +31,7 @@ import org.dcache.chimera.JdbcFs;
import org.dcache.chimera.XMLconfig;
import org.dcache.chimera.nfs.ExportFile;
import org.dcache.chimera.nfs.v3.MountServer;
import org.dcache.chimera.nfs.v4.mover.NFSProtocol_4;
import org.dcache.chimera.nfs.v4.mover.DSOperationFactory;
import org.dcache.xdr.portmap.OncRpcEmbeddedPortmap;
......@@ -86,7 +86,7 @@ public class Main {
ExportFile exports = new ExportFile(new File("/etc/exports"));
MountServer ms = new MountServer(exports, fs);
NFSServerV41 nfs4 = new NFSServerV41(new DeviceManager(),
NFSServerV41 nfs4 = new NFSServerV41(new MDSOperationFactory(), new DeviceManager(),
fs, exports);
service.register(100003, nfs4);
......@@ -96,7 +96,8 @@ public class Main {
port = DEFAULT_PORT_DS;
service = new OncRpcSvc(port);
_log.log(Level.INFO, "starting DS on: {0}", port );
NFSProtocol_4 ds = new NFSProtocol_4(fs, new File("/tmp/pNFS"));
NFSServerV41 ds = new NFSServerV41(new DSOperationFactory(), new DeviceManager(),
fs, null);
service.register(100003, ds);
}
......
......@@ -27,12 +27,16 @@ public class NFSServerV41 extends nfs4_prot_NFS4_PROGRAM_ServerStub {
private final FileSystemProvider _fs;
private final ExportFile _exportFile;
private static final Logger _log = Logger.getLogger(NFSServerV41.class.getName());
private final NFSv4OperationFactory _operationFactory;
public NFSServerV41(NFSv41DeviceManager deviceManager, FileSystemProvider fs, ExportFile exportFile) throws OncRpcException, IOException {
public NFSServerV41(NFSv4OperationFactory operationFactory,
NFSv41DeviceManager deviceManager, FileSystemProvider fs,
ExportFile exportFile) throws OncRpcException, IOException, ChimeraFsException {
NFSv41DeviceManagerFactory.setDeviceManager(deviceManager);
_fs = fs;
_exportFile = exportFile;
_operationFactory = operationFactory;
}
@Override
......@@ -63,7 +67,7 @@ public class NFSServerV41 extends nfs4_prot_NFS4_PROGRAM_ServerStub {
for (nfs_argop4 op: arg1.argarray) {
if( ! NFSv4OperationFactory.getOperation(op).process(context) ) {
if( ! _operationFactory.getOperation(op).process(context) ) {
break;
}
}
......
package org.dcache.chimera.nfs.v4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs4_prot;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
public class NFSv4OperationFactory {
/*
* no instance allowed
*/
private NFSv4OperationFactory() {}
public static AbstractNFSv4Operation getOperation(nfs_argop4 op) {
switch ( op.argop ) {
case nfs_opnum4.OP_ACCESS:
return new OperationACCESS(op);
case nfs_opnum4.OP_CLOSE:
return new OperationCLOSE(op);
case nfs_opnum4.OP_COMMIT:
return new OperationCOMMIT(op);
case nfs_opnum4.OP_CREATE:
return new OperationCREATE(op);
case nfs_opnum4.OP_DELEGPURGE:
return new OperationDELEGPURGE(op);
case nfs_opnum4.OP_DELEGRETURN:
return new OperationDELEGRETURN(op);
case nfs_opnum4.OP_GETATTR:
return new OperationGETATTR(op);
case nfs_opnum4.OP_GETFH:
return new OperationGETFH(op);
case nfs_opnum4.OP_LINK:
return new OperationLINK(op);
case nfs_opnum4.OP_LOCK:
return new OperationLOCK(op);
case nfs_opnum4.OP_LOCKT:
return new OperationLOCKT(op);
case nfs_opnum4.OP_LOCKU:
return new OperationLOCKU(op);
case nfs_opnum4.OP_LOOKUP:
return new OperationLOOKUP(op);
case nfs_opnum4.OP_LOOKUPP:
return new OperationLOOKUPP(op);
case nfs_opnum4.OP_NVERIFY:
return new OperationNVERIFY(op);
case nfs_opnum4.OP_OPEN:
return new OperationOPEN(op);
case nfs_opnum4.OP_OPENATTR:
return new OperationOPENATTR(op);
case nfs_opnum4.OP_OPEN_CONFIRM:
return new OperationOPEN_CONFIRM(op);
case nfs_opnum4.OP_OPEN_DOWNGRADE:break;
case nfs_opnum4.OP_PUTFH:
return new OperationPUTFH(op);
case nfs_opnum4.OP_PUTPUBFH:
return new OperationPUTPUBFH(op);
case nfs_opnum4.OP_PUTROOTFH:
return new OperationPUTROOTFH(op);
case nfs_opnum4.OP_READ:
return new OperationREAD(op);
case nfs_opnum4.OP_READDIR:
return new OperationREADDIR(op);
case nfs_opnum4.OP_READLINK:
return new OperationREADLINK(op);
case nfs_opnum4.OP_REMOVE:
return new OperationREMOVE(op);
case nfs_opnum4.OP_RENAME:
return new OperationRENAME(op);
case nfs_opnum4.OP_RENEW:
return new OperationRENEW(op);
case nfs_opnum4.OP_RESTOREFH:
return new OperationRESTOREFH(op);
case nfs_opnum4.OP_SAVEFH:
return new OperationSAVEFH(op);
case nfs_opnum4.OP_SECINFO:
return new OperationSECINFO(op);
case nfs_opnum4.OP_SETATTR:
return new OperationSETATTR(op);
case nfs_opnum4.OP_SETCLIENTID:
return new OperationSETCLIENTID(op);
case nfs_opnum4.OP_SETCLIENTID_CONFIRM:
return new OperationSETCLIENTID_CONFIRM(op);
case nfs_opnum4.OP_VERIFY:
return new OperationVERIFY(op);
case nfs_opnum4.OP_WRITE:
return new OperationWRITE(op);
/* case nfs_opnum4.OP_RELEASE_LOCKOWNER:
nRes.oprelease_lockowner = new RELEASE_LOCKOWNER4res();
res = new NFSv4OperationResult(nRes, nfsstat4.NFS4ERR_NOTSUPP);
break; */
/**
* NFSv4.1 (pNFS)
*/
case nfs_opnum4.OP_GETDEVICELIST:
return new OperationGETDEVICELIST(op);
case nfs_opnum4.OP_LAYOUTGET:
return new OperationLAYOUTGET(op);
case nfs_opnum4.OP_LAYOUTCOMMIT:
return new OperationLAYOUTCOMMIT(op);
case nfs_opnum4.OP_LAYOUTRETURN:
return new OperationLAYOUTRETURN(op);
case nfs_opnum4.OP_GETDEVICEINFO:
return new OperationGETDEVICEINFO(op);
case nfs_opnum4.OP_EXCHANGE_ID:
return new OperationEXCHANGE_ID(op, nfs4_prot.EXCHGID4_FLAG_USE_PNFS_MDS);
case nfs_opnum4.OP_CREATE_SESSION:
return new OperationCREATE_SESSION(op);
case nfs_opnum4.OP_DESTROY_SESSION:
return new OperationDESTROY_SESSION(op);
case nfs_opnum4.OP_SEQUENCE:
return new OperationSEQUENCE(op, true);
case nfs_opnum4.OP_ILLEGAL:
}
return new OperationILLEGAL(op);
}
public interface NFSv4OperationFactory {
AbstractNFSv4Operation getOperation(nfs_argop4 op);
}
package org.dcache.chimera.nfs.v4.mover;
import org.dcache.chimera.nfs.v4.AbstractNFSv4Operation;
import org.dcache.chimera.nfs.v4.NFSv4OperationFactory;
import org.dcache.chimera.nfs.v4.OperationCOMMIT;
import org.dcache.chimera.nfs.v4.OperationCREATE_SESSION;
import org.dcache.chimera.nfs.v4.OperationDESTROY_SESSION;
......@@ -14,45 +15,34 @@ import org.dcache.chimera.nfs.v4.xdr.nfs4_prot;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
class DSNFSv4OperationFactory {
/*
* no instance allowed
*/
private DSNFSv4OperationFactory() {}
static AbstractNFSv4Operation getOperation(nfs_argop4 op) {
switch ( op.argop ) {
case nfs_opnum4.OP_COMMIT:
return new OperationCOMMIT(op);
case nfs_opnum4.OP_GETATTR:
return new OperationGETATTR(op);
case nfs_opnum4.OP_PUTFH:
return new OperationPUTFH(op);
case nfs_opnum4.OP_PUTROOTFH:
return new OperationPUTROOTFH(op);
case nfs_opnum4.OP_READ:
return new DSOperationREAD(op);
case nfs_opnum4.OP_WRITE:
return new DSOperationWRITE(op);
case nfs_opnum4.OP_EXCHANGE_ID:
return new OperationEXCHANGE_ID(op, nfs4_prot.EXCHGID4_FLAG_USE_PNFS_DS);
case nfs_opnum4.OP_CREATE_SESSION:
return new OperationCREATE_SESSION(op);
case nfs_opnum4.OP_DESTROY_SESSION:
return new OperationDESTROY_SESSION(op);
case nfs_opnum4.OP_SEQUENCE:
return new OperationSEQUENCE(op, false);
case nfs_opnum4.OP_ILLEGAL:
}
return new OperationILLEGAL(op);
}
public class DSOperationFactory implements NFSv4OperationFactory {
@Override
public AbstractNFSv4Operation getOperation(nfs_argop4 op) {
switch (op.argop) {
case nfs_opnum4.OP_COMMIT:
return new OperationCOMMIT(op);
case nfs_opnum4.OP_GETATTR:
return new OperationGETATTR(op);
case nfs_opnum4.OP_PUTFH:
return new OperationPUTFH(op);
case nfs_opnum4.OP_PUTROOTFH:
return new OperationPUTROOTFH(op);
case nfs_opnum4.OP_READ:
return new DSOperationREAD(op);
case nfs_opnum4.OP_WRITE:
return new DSOperationWRITE(op);
case nfs_opnum4.OP_EXCHANGE_ID:
return new OperationEXCHANGE_ID(op, nfs4_prot.EXCHGID4_FLAG_USE_PNFS_DS);
case nfs_opnum4.OP_CREATE_SESSION:
return new OperationCREATE_SESSION(op);
case nfs_opnum4.OP_DESTROY_SESSION:
return new OperationDESTROY_SESSION(op);
case nfs_opnum4.OP_SEQUENCE:
return new OperationSEQUENCE(op, false);
}
return new OperationILLEGAL(op);
}
}
/*
* $Id:NFSProtocol_4.java 140 2007-06-07 13:44:55Z tigran $
*/
package org.dcache.chimera.nfs.v4.mover;
import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dcache.chimera.FileSystemProvider;
import org.dcache.chimera.nfs.v4.xdr.COMPOUND4args;
import org.dcache.chimera.nfs.v4.xdr.COMPOUND4res;
import org.dcache.chimera.nfs.v4.CompoundContext;
import org.dcache.chimera.nfs.ChimeraNFSException;
import org.dcache.chimera.nfs.v4.NFSv4Call;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_resop4;
import org.dcache.chimera.nfs.v4.xdr.nfsstat4;
import org.dcache.xdr.OncRpcException;
import org.dcache.xdr.RpcCall;
import org.dcache.xdr.RpcDispatchable;
import org.dcache.xdr.XdrVoid;
/**
*
* dCache pool simulator
*
*/
public class NFSProtocol_4 implements RpcDispatchable {
private static final Logger _log = Logger.getLogger(NFSProtocol_4.class.getName());
private final FileSystemProvider _fs;
public NFSProtocol_4(FileSystemProvider fs, File poolRoot) {
_fs = fs;
}
public void dispatchOncRpcCall(RpcCall call) throws OncRpcException, IOException {
int version = call.getProgramVersion();
int procedure = call.getProcedure();
if (version == 4) {
switch (procedure) {
case 0: {
call.retrieveCall(XdrVoid.XDR_VOID);
NFSPROC4_NULL_4(call);
call.reply(XdrVoid.XDR_VOID);
break;
}
case 1: {
COMPOUND4args args$ = new COMPOUND4args();
call.retrieveCall(args$);
COMPOUND4res result$ = NFSPROC4_COMPOUND_4(call, args$);
call.reply(result$);
break;
}
default:
call.failProcedureUnavailable();
}
} else {
call.failProgramUnavailable();
}
}
public void NFSPROC4_NULL_4(RpcCall call$) {
_log.log(Level.FINE, "MOVER: PING from client: {0}",
call$.getTransport().getRemoteSocketAddress() );
}
public COMPOUND4res NFSPROC4_COMPOUND_4(RpcCall call$, COMPOUND4args arg1) {
COMPOUND4res res = new COMPOUND4res();
_log.log(Level.FINE, "MOVER: NFS COMPOUND client: {0}, tag: {1}",
new Object[] {
call$.getTransport().getRemoteSocketAddress(),
new String(arg1.tag.value.value)
}
);
try {
_log.log(Level.FINE, "NFS COMPOUND client: {0}, tag: {1}",
new Object[]{call$.getTransport().getRemoteSocketAddress(),
new String(arg1.tag.value.value)}
);
List<nfs_resop4> v = new LinkedList<nfs_resop4>();
if( arg1.minorversion.value > 1 ) {
res.status = nfsstat4.NFS4ERR_MINOR_VERS_MISMATCH;
_log.log(Level.FINE," : NFS4ERR_MINOR_VERS_MISMATCH");
}else{
CompoundContext context = new CompoundContext(v, arg1.minorversion.value,
_fs, call$, null);
for (nfs_argop4 op : arg1.argarray) {
if (!DSNFSv4OperationFactory.getOperation(op).process(context)) {
break;
}
}
try {
_log.log(Level.FINE, "CURFH: {0}", context.currentInode().toFullString());
} catch (ChimeraNFSException he) {
_log.fine("CURFH: NULL");
}
v = context.processedOperations();
}
res.tag = arg1.tag;
res.resarray = v.toArray(new nfs_resop4[v.size()]);
// result status must be equivalent
// to the status of the last operation that
// was executed within the COMPOUND procedure
res.status = res.resarray[res.resarray.length - 1].getStatus();
_log.log(Level.FINE, "OP: {1} status: {1}",
new Object[]{NFSv4Call.toString(res.resarray[res.resarray.length - 1].resop), res.status});
}catch(Exception e) {
_log.log(Level.SEVERE,"Unhandled exception:", e);
}
return res;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment