Commit 84038b27 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: client support

parent bb5c5d67
...@@ -173,6 +173,11 @@ ...@@ -173,6 +173,11 @@
<artifactId>c3p0</artifactId> <artifactId>c3p0</artifactId>
<version>0.9.1.2</version> <version>0.9.1.2</version>
</dependency> </dependency>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.94</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.CLOSE4args;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.seqid4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
public class CloseStub {
public static nfs_argop4 generateRequest(stateid4 stateid) {
CLOSE4args args = new CLOSE4args();
args.seqid = new seqid4(new uint32_t (0));
args.open_stateid = stateid;
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_CLOSE;
op.opclose = args;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.CREATE_SESSION4args;
import org.dcache.chimera.nfs.v4.xdr.callback_sec_parms4;
import org.dcache.chimera.nfs.v4.xdr.channel_attrs4;
import org.dcache.chimera.nfs.v4.xdr.clientid4;
import org.dcache.chimera.nfs.v4.xdr.count4;
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;
import org.dcache.chimera.nfs.v4.xdr.sequenceid4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
public class CreateSessionStub {
public static nfs_argop4 standard(clientid4 eir_clientid,
sequenceid4 eir_sequenceid) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_CREATE_SESSION;
op.opcreate_session = new CREATE_SESSION4args();
channel_attrs4 chan_attrs = new channel_attrs4();
chan_attrs.ca_headerpadsize = new count4(new uint32_t(0));
chan_attrs.ca_maxoperations = new count4(new uint32_t(8192));
chan_attrs.ca_maxrequests = new count4(new uint32_t(8192));
chan_attrs.ca_maxrequestsize = new count4(new uint32_t(8192));
chan_attrs.ca_maxresponsesize = new count4(new uint32_t(8192));
chan_attrs.ca_maxresponsesize_cached = new count4(new uint32_t(8));
chan_attrs.ca_rdma_ird = new uint32_t[0];
op.opcreate_session.csa_clientid = eir_clientid;
op.opcreate_session.csa_sequence = eir_sequenceid;
op.opcreate_session.csa_flags = new uint32_t(0);
op.opcreate_session.csa_fore_chan_attrs = chan_attrs;
op.opcreate_session.csa_back_chan_attrs = chan_attrs;
op.opcreate_session.csa_cb_program = new uint32_t(123);
callback_sec_parms4[] cb = new callback_sec_parms4[1];
callback_sec_parms4 callb = new callback_sec_parms4();
callb.cb_secflavor = nfs4_prot.AUTH_NONE;
cb[0] = callb;
op.opcreate_session.csa_sec_parms = new callback_sec_parms4[1];
op.opcreate_session.csa_sec_parms = cb;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.DESTROY_SESSION4args;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.sessionid4;
public class DestroySessionStub {
public static nfs_argop4 standard( sessionid4 sessionid) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_DESTROY_SESSION;
op.opdestroy_session = new DESTROY_SESSION4args();
op.opdestroy_session.dsa_sessionid = sessionid;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.EXCHANGE_ID4args;
import org.dcache.chimera.nfs.v4.xdr.client_owner4;
import org.dcache.chimera.nfs.v4.xdr.int64_t;
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_impl_id4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.nfstime4;
import org.dcache.chimera.nfs.v4.xdr.state_protect4_a;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.verifier4;
import static org.dcache.chimera.nfs.v4.HimeraNFS4Utils.string2utf8str_cis;
import static org.dcache.chimera.nfs.v4.HimeraNFS4Utils.string2utf8str_cs;
public class ExchengeIDStub {
public static nfs_argop4 normal(String nii_domain, String nii_name,
String co_ownerid, int flags, int how) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_EXCHANGE_ID;
op.opexchange_id = new EXCHANGE_ID4args();
op.opexchange_id.eia_client_impl_id = new nfs_impl_id4[1];
nfs_impl_id4 n4 = new nfs_impl_id4();
n4.nii_domain = string2utf8str_cis(nii_domain);
n4.nii_name = string2utf8str_cs(nii_name);
op.opexchange_id.eia_client_impl_id[0] = n4;
nfstime4 releaseDate = new nfstime4();
releaseDate.nseconds = new uint32_t(0);
releaseDate.seconds = new int64_t(System.currentTimeMillis() / 1000);
op.opexchange_id.eia_client_impl_id[0].nii_date = releaseDate;
op.opexchange_id.eia_clientowner = new client_owner4();
op.opexchange_id.eia_clientowner.co_ownerid = co_ownerid.getBytes();
op.opexchange_id.eia_clientowner.co_verifier = new verifier4();
op.opexchange_id.eia_clientowner.co_verifier.value = new byte[nfs4_prot.NFS4_VERIFIER_SIZE];
byte[] locVerifier = Long.toHexString(releaseDate.seconds.value).getBytes();
int len = locVerifier.length > nfs4_prot.NFS4_VERIFIER_SIZE ? nfs4_prot.NFS4_VERIFIER_SIZE : locVerifier.length;
System.arraycopy(locVerifier, 0, op.opexchange_id.eia_clientowner.co_verifier.value, 0,len );
op.opexchange_id.eia_flags = new uint32_t(flags);
op.opexchange_id.eia_state_protect = new state_protect4_a();
op.opexchange_id.eia_state_protect.spa_how = how;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.dcache.chimera.nfs.v4.xdr.GETDEVICELIST4args;
import org.dcache.chimera.nfs.v4.xdr.count4;
import org.dcache.chimera.nfs.v4.xdr.layouttype4;
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_cookie4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.nfsv4_1_file_layout_ds_addr4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
import org.dcache.chimera.nfs.v4.xdr.verifier4;
import org.dcache.xdr.OncRpcException;
import org.dcache.xdr.Xdr;
import org.dcache.xdr.XdrDecodingStream;
public class GetDeviceListStub {
public static nfs_argop4 normal() {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_GETDEVICELIST;
op.opgetdevicelist = new GETDEVICELIST4args();
op.opgetdevicelist.gdla_cookie = new nfs_cookie4();
op.opgetdevicelist.gdla_cookie.value = new uint64_t(0);
op.opgetdevicelist.gdla_cookieverf = new verifier4();
op.opgetdevicelist.gdla_cookieverf.value = new byte[nfs4_prot.NFS4_VERIFIER_SIZE];
op.opgetdevicelist.gdla_layout_type = layouttype4.LAYOUT4_NFSV4_1_FILES;
op.opgetdevicelist.gdla_maxdevices = new count4();
op.opgetdevicelist.gdla_maxdevices.value = new uint32_t(256);
return op;
}
public static nfsv4_1_file_layout_ds_addr4 decodeFileDevice(byte[] data)
throws OncRpcException, IOException {
XdrDecodingStream xdr = new Xdr(ByteBuffer.wrap(data));
nfsv4_1_file_layout_ds_addr4 device = new nfsv4_1_file_layout_ds_addr4();
xdr.beginDecoding();
device.xdrDecode(xdr);
xdr.endDecoding();
return device;
}
}
package org.dcache.chimera.nfs.v4.client;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.dcache.chimera.nfs.v4.xdr.GETATTR4args;
import org.dcache.chimera.nfs.v4.xdr.bitmap4;
import org.dcache.chimera.nfs.v4.xdr.fattr4;
import org.dcache.chimera.nfs.v4.xdr.fattr4_type;
import org.dcache.chimera.nfs.v4.xdr.mode4;
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;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
import org.dcache.chimera.nfs.v4.xdr.utf8str_cs;
import org.dcache.xdr.OncRpcException;
import org.dcache.xdr.Xdr;
import org.dcache.xdr.XdrDecodingStream;
public class GetattrStub {
public static nfs_argop4 generateRequest(List<Integer> attrs) {
nfs_argop4 op = new nfs_argop4();
GETATTR4args args = new GETATTR4args();
args.attr_request = new bitmap4();
args.attr_request.value = new uint32_t[2];
args.attr_request.value[0] = new uint32_t();
args.attr_request.value[1] = new uint32_t();
for( Integer mask : attrs) {
int bit = mask -(32*(mask/32));
args.attr_request.value[mask/32].value |= 1 << bit;
}
op.argop = nfs_opnum4.OP_GETATTR;
op.opgetattr = args;
return op;
}
public static List<Integer> supportedAttrs(bitmap4 bitmap) {
List<Integer> supported = new ArrayList<Integer>();
// TODO:
return supported;
}
public static Map<Integer, Object> decodeType(fattr4 attributes) throws OncRpcException, IOException {
Map<Integer,Object> attr = new HashMap<Integer, Object>();
int[] mask = new int[attributes.attrmask.value.length];
for( int i = 0; i < mask.length; i++) {
mask[i] = attributes.attrmask.value[i].value;
}
XdrDecodingStream xdr = new Xdr(ByteBuffer.wrap(attributes.attr_vals.value));
xdr.beginDecoding();
if( mask.length != 0 ) {
int maxAttr = 32*mask.length;
for( int i = 0; i < maxAttr; i++) {
int newmask = (mask[i/32] >> (i-(32*(i/32))) );
if( (newmask & 1L) != 0 ) {
xdr2fattr(attr, i, xdr);
}
}
}
xdr.endDecoding();
return attr;
}
static void xdr2fattr( Map<Integer,Object> attr, int fattr , XdrDecodingStream xdr) throws OncRpcException, IOException {
System.out.println("decoding mask " + fattr);
switch(fattr) {
case nfs4_prot.FATTR4_SIZE :
uint64_t size = new uint64_t();
size.xdrDecode(xdr);
attr.put(fattr, size);
break;
case nfs4_prot.FATTR4_MODE :
mode4 mode = new mode4();
mode.xdrDecode(xdr);
attr.put(fattr, mode);
break;
case nfs4_prot.FATTR4_OWNER :
// TODO: use princilat
utf8str_cs owner = new utf8str_cs ();
owner.xdrDecode(xdr);
String new_owner = new String(owner.value.value);
attr.put(fattr,new_owner );
break;
case nfs4_prot.FATTR4_OWNER_GROUP :
// TODO: use princilat
utf8str_cs owner_group = new utf8str_cs ();
owner_group.xdrDecode(xdr);
String new_group = new String(owner_group.value.value);
attr.put(fattr,new_group );
break;
case nfs4_prot.FATTR4_TYPE :
fattr4_type type = new fattr4_type();
type.xdrDecode(xdr);
attr.put(fattr,type );
}
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.GETDEVICEINFO4args;
import org.dcache.chimera.nfs.v4.xdr.bitmap4;
import org.dcache.chimera.nfs.v4.xdr.count4;
import org.dcache.chimera.nfs.v4.xdr.deviceid4;
import org.dcache.chimera.nfs.v4.xdr.layouttype4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
public class GetdeviceinfoStub {
public static nfs_argop4 generateRequest(deviceid4 devId) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_GETDEVICEINFO;
op.opgetdeviceinfo = new GETDEVICEINFO4args();
op.opgetdeviceinfo.gdia_device_id = devId;
op.opgetdeviceinfo.gdia_layout_type = layouttype4.LAYOUT4_NFSV4_1_FILES;
count4 cn = new count4();
cn.value = new uint32_t(0xffffff);
op.opgetdeviceinfo.gdia_maxcount = cn;
op.opgetdeviceinfo.gdia_notify_types = new bitmap4();
op.opgetdeviceinfo.gdia_notify_types.value = new uint32_t[1];
op.opgetdeviceinfo.gdia_notify_types.value[0] = new uint32_t(0);
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
public class GetfhStub {
public static nfs_argop4 generateRequest() {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_GETFH;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import java.io.IOException;
import java.nio.ByteBuffer;
import org.dcache.chimera.nfs.v4.xdr.LAYOUTGET4args;
import org.dcache.chimera.nfs.v4.xdr.count4;
import org.dcache.chimera.nfs.v4.xdr.length4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.nfsv4_1_file_layout4;
import org.dcache.chimera.nfs.v4.xdr.offset4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.uint32_t;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
import org.dcache.xdr.OncRpcException;
import org.dcache.xdr.Xdr;
import org.dcache.xdr.XdrDecodingStream;
public class LayoutgetStub {
public static nfs_argop4 generateRequest(boolean signal_layout_avail,
int layout_type, int iomode, int offset, int length, int minlength,
int maxcount, stateid4 stateid) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_LAYOUTGET;
op.oplayoutget = new LAYOUTGET4args();
op.oplayoutget.loga_signal_layout_avail = signal_layout_avail;
op.oplayoutget.loga_layout_type = layout_type;
op.oplayoutget.loga_iomode = iomode;
offset4 off = new offset4();
uint64_t u64 = new uint64_t(offset);
off.value = u64;
length4 cnLong = new length4();
cnLong.value = new uint64_t(length);
length4 cnZero = new length4();
cnZero.value = new uint64_t(minlength);
count4 cnShort = new count4();
cnShort.value = new uint32_t(maxcount);
op.oplayoutget.loga_offset = off;
op.oplayoutget.loga_length = cnLong;
op.oplayoutget.loga_minlength = cnZero;
op.oplayoutget.loga_maxcount = cnShort;
op.oplayoutget.loga_stateid = stateid;
return op;
}
static public nfsv4_1_file_layout4 decodeLayoutId(byte[] data) throws OncRpcException, IOException {
XdrDecodingStream xdr = new Xdr(ByteBuffer.wrap(data));
nfsv4_1_file_layout4 device = new nfsv4_1_file_layout4();
xdr.beginDecoding();
device.xdrDecode(xdr);
xdr.endDecoding();
return device;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.LAYOUTRETURN4args;
import org.dcache.chimera.nfs.v4.xdr.layoutiomode4;
import org.dcache.chimera.nfs.v4.xdr.layoutreturn4;
import org.dcache.chimera.nfs.v4.xdr.layoutreturn_file4;
import org.dcache.chimera.nfs.v4.xdr.layoutreturn_type4;
import org.dcache.chimera.nfs.v4.xdr.layouttype4;
import org.dcache.chimera.nfs.v4.xdr.length4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.offset4;
import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
public class LayoutreturnStub {
private LayoutreturnStub() {
}
public static nfs_argop4 generateRequest(long offset, long len, byte[] body, stateid4 stateid) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_LAYOUTRETURN;
op.oplayoutreturn = new LAYOUTRETURN4args();
op.oplayoutreturn.lora_reclaim = true;
op.oplayoutreturn.lora_iomode = layoutiomode4.LAYOUTIOMODE4_ANY;
op.oplayoutreturn.lora_layout_type = layouttype4.LAYOUT4_NFSV4_1_FILES;
op.oplayoutreturn.lora_layoutreturn = new layoutreturn4();
op.oplayoutreturn.lora_layoutreturn.lr_returntype = layoutreturn_type4.LAYOUTRETURN4_FILE;
op.oplayoutreturn.lora_layoutreturn.lr_layout = new layoutreturn_file4();
op.oplayoutreturn.lora_layoutreturn.lr_layout.lrf_offset = new offset4(new uint64_t(offset));
op.oplayoutreturn.lora_layoutreturn.lr_layout.lrf_length = new length4(new uint64_t(len));
op.oplayoutreturn.lora_layoutreturn.lr_layout.lrf_body = body;
op.oplayoutreturn.lora_layoutreturn.lr_layout.lrf_stateid = stateid;
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.LOOKUP4args;
import org.dcache.chimera.nfs.v4.xdr.component4;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.utf8str_cs;
import org.dcache.chimera.nfs.v4.xdr.utf8string;
public class LookupStub {
public static nfs_argop4 generateRequest(String path) {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_LOOKUP;
op.oplookup = new LOOKUP4args();
op.oplookup.objname = new component4(new utf8str_cs(new utf8string(path
.getBytes())));
return op;
}
}
package org.dcache.chimera.nfs.v4.client;
import org.dcache.chimera.nfs.v4.xdr.nfs_argop4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
public class LookuppStub {
public static nfs_argop4 generateRequest() {
nfs_argop4 op = new nfs_argop4();
op.argop = nfs_opnum4.OP_LOOKUPP;
return op;
}
}
This diff is collapsed.
package org.dcache.chimera.nfs.v4.client;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import org.dcache.chimera.nfs.v4.xdr.CREATE4args;
import org.dcache.chimera.nfs.v4.xdr.attrlist4;
import org.dcache.chimera.nfs.v4.xdr.bitmap4;
import org.dcache.chimera.nfs.v4.xdr.component4;
import org.dcache.chimera.nfs.v4.xdr.createtype4;
import org.dcache.chimera.nfs.v4.xdr.fattr4;
import org.dcache.chimera.nfs.v4.xdr.fattr4_mode;