Commit 2946aa76 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfsv41: pNFS: user DeviceId instead of byte[]

parent 3fc3f452
package org.dcache.chimera.nfs.v4;
import java.util.Arrays;
import org.dcache.chimera.nfs.v4.xdr.deviceid4;
import org.dcache.chimera.nfs.v4.xdr.nfs4_prot;
/**
* Helper ( wrapper ) class for byte[] based deviceid4.
......@@ -28,11 +30,10 @@ public class DeviceID {
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
if( !(obj instanceof DeviceID)) return false;
final DeviceID other = (DeviceID) obj;
if (!Arrays.equals(_id, other._id)) return false;
return true;
return Arrays.equals(_id, other._id);
}
public byte[] getId() {
......@@ -41,6 +42,32 @@ public class DeviceID {
return id;
}
public static DeviceID valueOf(deviceid4 id) {
return new DeviceID(id.value);
}
public static DeviceID valueOf(int id) {
return new DeviceID(id2deviceid(id));
}
private static byte[] id2deviceid(int id) {
byte[] buf = Integer.toString(id).getBytes();
byte[] devData = new byte[nfs4_prot.NFS4_DEVICEID4_SIZE];
int len = Math.min(buf.length, nfs4_prot.NFS4_DEVICEID4_SIZE);
System.arraycopy(buf, 0, devData, 0, len);
return devData;
}
public deviceid4 toDeviceid4() {
return new deviceid4(_id);
}
@Override
public String toString() {
return Arrays.toString(_id);
}
}
......@@ -9,7 +9,6 @@ import org.dcache.chimera.nfs.v4.xdr.stateid4;
import org.dcache.chimera.nfs.v4.xdr.netaddr4;
import org.dcache.chimera.nfs.v4.xdr.nfsv4_1_file_layout_ds_addr4;
import org.dcache.chimera.nfs.v4.xdr.device_addr4;
import org.dcache.chimera.nfs.v4.xdr.nfs4_prot;
import org.dcache.chimera.nfs.v4.xdr.multipath_list4;
import java.io.IOException;
import java.net.InetAddress;
......@@ -17,12 +16,12 @@ import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dcache.xdr.OncRpcException;
......@@ -45,7 +44,8 @@ public class DeviceManager implements NFSv41DeviceManager {
/* hack for multiple pools */
Random _poolManager = new Random();
private final Map<DeviceID, NFS4IoDevice> _deviceMap = new HashMap<DeviceID, NFS4IoDevice>();
private final Map<DeviceID, NFS4IoDevice> _deviceMap =
new ConcurrentHashMap<DeviceID, NFS4IoDevice>();
/*
* (non-Javadoc)
......@@ -57,10 +57,10 @@ public class DeviceManager implements NFSv41DeviceManager {
int id = _poolManager.nextInt(256);
++id; /* 0 is reserved */
byte[] data = id2deviceid(id);
DeviceID deviceId = DeviceID.valueOf(id);
_log.log(Level.FINEST, "generating new device: {0} ({1}) for stateid {2}",
new Object[] {Arrays.toString(data), id, stateid}
new Object[] {deviceId, id, stateid}
);
InetAddress addr = null;
......@@ -76,7 +76,7 @@ public class DeviceManager implements NFSv41DeviceManager {
addresses[0] = new InetSocketAddress(addr, 2052);
device_addr4 deviceAddr = deviceAddrOf( addresses );
NFS4IoDevice newDevice = new NFS4IoDevice(id2deviceid(id) , deviceAddr);
NFS4IoDevice newDevice = new NFS4IoDevice(deviceId , deviceAddr);
addIoDevice(newDevice, ioMode);
......@@ -93,15 +93,8 @@ public class DeviceManager implements NFSv41DeviceManager {
*/
public void addIoDevice(NFS4IoDevice device, int ioMode ) {
_log.log(Level.FINEST, "add device: {0}", Arrays.toString(device.getDeviceId()) );
synchronized (_deviceMap) {
DeviceID deviceId = new DeviceID(device.getDeviceId());
if (!_deviceMap.containsKey(deviceId) ) {
_deviceMap.put(deviceId, device);
}
}
_log.log(Level.FINEST, "add device: {0}", device.getDeviceId());
_deviceMap.put(device.getDeviceId(), device);
}
/*
......@@ -109,15 +102,11 @@ public class DeviceManager implements NFSv41DeviceManager {
*
* @see org.dcache.chimera.nfsv4.NFSv41DeviceManager#getIoDevice(int)
*/
public NFS4IoDevice getIoDevice(byte[] deviceId) {
_log.log(Level.FINEST, "lookup for device: {0}", Arrays.toString(deviceId) );
public NFS4IoDevice getIoDevice(DeviceID deviceId) {
_log.log(Level.FINEST, "lookup for device: {0}", deviceId );
NFS4IoDevice device = null;
synchronized (_deviceMap) {
device = _deviceMap.get(new DeviceID(deviceId));
}
return device;
return _deviceMap.get(deviceId);
}
/*
......@@ -127,11 +116,11 @@ public class DeviceManager implements NFSv41DeviceManager {
*/
public List<NFS4IoDevice> getIoDeviceList() {
List<NFS4IoDevice> deviceList = new ArrayList<NFS4IoDevice>();
synchronized (_deviceMap) {
deviceList.addAll(_deviceMap.values());
}
deviceList.addAll(_deviceMap.values());
for(NFS4IoDevice device : deviceList ) {
_log.log(Level.FINEST, "known device: {0}", Arrays.toString(device.getDeviceId()) );
_log.log(Level.FINEST, "known device: {0}", device.getDeviceId() );
}
return deviceList;
}
......@@ -146,20 +135,6 @@ public class DeviceManager implements NFSv41DeviceManager {
_log.log(Level.FINEST, "release device for stateid {0}", stateid );
}
public static byte[] id2deviceid(int id) {
byte[] puffer = Integer.toString(id).getBytes();
byte[] devData = new byte[nfs4_prot.NFS4_DEVICEID4_SIZE];
int len = puffer.length > nfs4_prot.NFS4_DEVICEID4_SIZE? nfs4_prot.NFS4_DEVICEID4_SIZE : puffer.length;
System.arraycopy(puffer, 0, devData, 0, len);
return devData;
}
/**
* Create a mulipath based NFSv4.1 file layout address.
*
......
......@@ -8,16 +8,16 @@ import org.dcache.chimera.nfs.v4.xdr.device_addr4;
/** Immutable */
public class NFS4IoDevice {
private final byte[] _deviceId;
private final DeviceID _deviceId;
private final device_addr4 _addr;
public NFS4IoDevice(byte[] id, device_addr4 addr) {
public NFS4IoDevice(DeviceID id, device_addr4 addr) {
_deviceId = id;
_addr = addr;
}
public byte[] getDeviceId() {
public DeviceID getDeviceId() {
return _deviceId;
}
......
......@@ -40,7 +40,7 @@ public interface NFSv41DeviceManager {
* @param deviceId
* @return NFS io device address
*/
public NFS4IoDevice getIoDevice(byte[] deviceId);
public NFS4IoDevice getIoDevice(DeviceID deviceId);
/**
* Get list of all registered devices.
......
......@@ -125,12 +125,7 @@ public class NFSv4StateHandler {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "State is not confirmed" );
}
if( state.stateid().seqid.value != stateid.seqid.value ) {
throw new ChimeraNFSException( nfsstat4.NFS4ERR_BAD_STATEID, "Sequence id miss match." );
}
client.updateLeaseTime(NFSv4Defaults.NFS4_LEASE_TIME);
}
public int acquire_state(stateid4 stateid, boolean allow) throws ChimeraNFSException{
......
......@@ -14,12 +14,6 @@ public class OperationCLOSE extends AbstractNFSv4Operation {
private static final Logger _log = Logger.getLogger(OperationCLOSE.class.getName());
/*
* reflects nfsv4.1
*/
private final boolean _isPNFS = false;
OperationCLOSE(nfs_argop4 args) {
super(args, nfs_opnum4.OP_CLOSE);
}
......
......@@ -9,7 +9,6 @@ import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.GETDEVICEINFO4res;
import org.dcache.chimera.nfs.v4.xdr.GETDEVICEINFO4resok;
import org.dcache.chimera.nfs.ChimeraNFSException;
import java.util.Arrays;
import org.apache.log4j.Logger;
......@@ -31,10 +30,10 @@ public class OperationGETDEVICEINFO extends AbstractNFSv4Operation {
*/
GETDEVICEINFO4res res = new GETDEVICEINFO4res();
byte[] deviceId = _args.opgetdeviceinfo.gdia_device_id.value;
DeviceID deviceId = DeviceID.valueOf(_args.opgetdeviceinfo.gdia_device_id);
if (_log.isDebugEnabled()) {
_log.debug(" Info for #" + Arrays.toString(deviceId));
_log.debug(" Info for #" + deviceId);
_log.debug(" type for #"
+ _args.opgetdeviceinfo.gdia_layout_type);
}
......
......@@ -63,7 +63,7 @@ public class OperationGETDEVICELIST extends AbstractNFSv4Operation {
* all non regular inode IO done by MDS
*/
byte[] mdsID = id2deviceid(0);
DeviceID mdsID = DeviceID.valueOf(0);
InetSocketAddress[] addresses = new InetSocketAddress[1];
addresses[0] = context.getRpcCall().getTransport().getLocalSocketAddress();
......@@ -84,11 +84,11 @@ public class OperationGETDEVICELIST extends AbstractNFSv4Operation {
* FIXME: protect against empty list
*/
res.gdlr_resok4.gdlr_deviceid_list = new deviceid4[deviceListSize];
res.gdlr_resok4.gdlr_deviceid_list[0] = new deviceid4( mdsID );
res.gdlr_resok4.gdlr_deviceid_list[0] = mdsID.toDeviceid4();
for (int i = 0; i < deviceListSize; i++) {
NFS4IoDevice device = deviceList.get(i);
res.gdlr_resok4.gdlr_deviceid_list[i] = new deviceid4(device.getDeviceId());
res.gdlr_resok4.gdlr_deviceid_list[i] = device.getDeviceId().toDeviceid4();
}
if (_log.isDebugEnabled()) {
......@@ -116,18 +116,4 @@ public class OperationGETDEVICELIST extends AbstractNFSv4Operation {
return res.gdlr_status == nfsstat4.NFS4_OK;
}
private static byte[] id2deviceid(int id) {
byte[] puffer = Integer.toString(id).getBytes();
byte[] devData = new byte[nfs4_prot.NFS4_DEVICEID4_SIZE];
System.arraycopy(puffer, 0, devData, 0, puffer.length);
return devData;
}
}
......@@ -15,14 +15,12 @@ import org.dcache.chimera.nfs.v4.xdr.layout4;
import org.dcache.chimera.nfs.v4.xdr.layoutiomode4;
import org.dcache.chimera.nfs.v4.xdr.uint64_t;
import org.dcache.chimera.nfs.v4.xdr.length4;
import org.dcache.chimera.nfs.v4.xdr.deviceid4;
import org.dcache.chimera.nfs.v4.xdr.nfs_opnum4;
import org.dcache.chimera.nfs.v4.xdr.LAYOUTGET4res;
import org.dcache.chimera.nfs.v4.xdr.LAYOUTGET4resok;
import org.dcache.chimera.nfs.ChimeraNFSException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -35,7 +33,7 @@ public class OperationLAYOUTGET extends AbstractNFSv4Operation {
private static final Logger _log = Logger.getLogger(OperationLAYOUTGET.class.getName());
static final byte[] MSD_ID = DeviceManager.id2deviceid(0);
static final DeviceID MSD_ID = DeviceID.valueOf(0);
OperationLAYOUTGET(nfs_argop4 args) {
super(args, nfs_opnum4.OP_LAYOUTGET);
......@@ -113,7 +111,7 @@ public class OperationLAYOUTGET extends AbstractNFSv4Operation {
_log.log(Level.FINER, "LAYOUT for {0} sd# {1}",
new Object[] { context.currentInode().toFullString(),
Arrays.toString(ioDevice.getDeviceId())}
ioDevice.getDeviceId()}
);
/*
......@@ -142,7 +140,7 @@ public class OperationLAYOUTGET extends AbstractNFSv4Operation {
nfsv4_1_file_layout4 layout = new nfsv4_1_file_layout4();
layout.nfl_deviceid = new deviceid4(ioDevice.getDeviceId());
layout.nfl_deviceid = ioDevice.getDeviceId().toDeviceid4();
layout.nfl_fh_list = new nfs_fh4[1];
layout.nfl_fh_list[0] = new nfs_fh4();
layout.nfl_fh_list[0].value = context.currentInode().toFullString().getBytes();
......
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