/
NfsTransferService.java
185 lines (158 loc) · 6.54 KB
/
NfsTransferService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package org.dcache.chimera.nfsv41.mover;
import org.ietf.jgss.GSSException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.CompletionHandler;
import java.util.List;
import diskCacheV111.util.CacheException;
import diskCacheV111.util.DiskErrorCacheException;
import diskCacheV111.vehicles.PoolIoFileMessage;
import diskCacheV111.vehicles.PoolPassiveIoFileMessage;
import dmg.cells.nucleus.CellPath;
import dmg.cells.nucleus.NoRouteToCellException;
import dmg.util.Args;
import org.dcache.cells.AbstractCellComponent;
import org.dcache.cells.CellCommandListener;
import org.dcache.cells.CellStub;
import org.dcache.chimera.ChimeraFsException;
import org.dcache.nfs.v4.NFS4Client;
import org.dcache.nfs.v4.NFSv41Session;
import org.dcache.nfs.v4.xdr.stateid4;
import org.dcache.commons.stats.RequestExecutionTimeGauges;
import org.dcache.pool.FaultAction;
import org.dcache.pool.FaultEvent;
import org.dcache.pool.FaultListener;
import org.dcache.pool.classic.Cancellable;
import org.dcache.pool.classic.PostTransferService;
import org.dcache.pool.classic.TransferService;
import org.dcache.pool.movers.Mover;
import org.dcache.pool.movers.MoverFactory;
import org.dcache.pool.repository.ReplicaDescriptor;
import org.dcache.pool.repository.RepositoryChannel;
import org.dcache.util.NetworkUtils;
import org.dcache.util.PortRange;
import org.dcache.xdr.OncRpcException;
/**
* Factory and transfer service for NFS movers.
*
* @since 1.9.11
*/
public class NfsTransferService extends AbstractCellComponent
implements MoverFactory, TransferService<NfsMover>, CellCommandListener
{
private static final Logger _log = LoggerFactory.getLogger(NfsTransferService.class);
private NFSv4MoverHandler _nfsIO;
private boolean _withGss;
private InetSocketAddress[] _localSocketAddresses;
private CellStub _door;
private PostTransferService _postTransferService;
private FaultListener _faultListener;
public void init() throws ChimeraFsException, IOException, GSSException, OncRpcException {
String dcachePorts = System.getProperty("org.dcache.net.tcp.portrange");
PortRange portRange;
if (dcachePorts != null) {
portRange = PortRange.valueOf(dcachePorts);
} else {
portRange = new PortRange(0);
}
_nfsIO = new NFSv4MoverHandler(portRange, _withGss, getCellName());
_localSocketAddresses =
localSocketAddresses(NetworkUtils.getLocalAddresses(), _nfsIO.getLocalAddress().getPort());
_door = new CellStub(getCellEndpoint());
}
@Required
public void setFaultListener(FaultListener faultListener) {
_faultListener = faultListener;
}
@Required
public void setPostTransferService(PostTransferService postTransferService) {
_postTransferService = postTransferService;
}
public void shutdown() throws IOException {
_nfsIO.shutdown();
}
@Override
public Mover<?> createMover(ReplicaDescriptor handle, PoolIoFileMessage message, CellPath pathToDoor) throws CacheException
{
return new NfsMover(handle, message, pathToDoor, this, _postTransferService);
}
@Override
public Cancellable execute(final NfsMover mover, final CompletionHandler<Void,Void> completionHandler) {
try {
final stateid4 stateid = mover.getStateId();
final RepositoryChannel repositoryChannel = mover.open();
_nfsIO.add(mover);
CellPath directDoorPath = new CellPath(mover.getPathToDoor().getDestinationAddress());
_door.send(directDoorPath, new PoolPassiveIoFileMessage<>(getCellName(), _localSocketAddresses, stateid));
/* An NFS mover doesn't complete until it is cancelled (the door sends a mover kill
* message when the file is closed).
*/
return new Cancellable() {
@Override
public void cancel() {
_nfsIO.remove(mover);
try {
repositoryChannel.close();
} catch (IOException e) {
_log.error("failed to close RAF", e);
}
completionHandler.completed(null, null);
}
};
} catch (DiskErrorCacheException e) {
_faultListener.faultOccurred(new FaultEvent("repository", FaultAction.DISABLED,
e.getMessage(), e));
completionHandler.failed(e, null);
} catch (NoRouteToCellException e) {
completionHandler.failed(e, null);
}
return null;
}
public void setEnableGss(boolean withGss) {
_withGss = withGss;
}
private InetSocketAddress[] localSocketAddresses(List<InetAddress> addresses, int port) {
InetSocketAddress[] socketAddresses = new InetSocketAddress[addresses.size()];
int i = 0;
for(InetAddress address: addresses) {
socketAddresses[i] = new InetSocketAddress(address, port);
i++;
}
return socketAddresses;
}
public final static String fh_nfs_stats =
"nfs stats [-c] # show nfs requests statstics\n\n" +
" Print nfs operation statistics.\n" +
" -c clear current statistics values";
public final static String hh_nfs_stats = " [-c] # show nfs mover statstics";
public String ac_nfs_stats(Args args) {
RequestExecutionTimeGauges<String> gauges = _nfsIO.getNFSServer().getStatistics();
StringBuilder sb = new StringBuilder();
sb.append("Stats:").append("\n").append(gauges);
if (args.hasOption("c")) {
gauges.reset();
}
return sb.toString();
}
public final static String hh_nfs_sessions = " # show nfs sessions";
public String ac_nfs_sessions(Args args) {
StringBuilder sb = new StringBuilder();
for (NFS4Client client : _nfsIO.getNFSServer().getClients()) {
sb.append(client).append('\n');
for (NFSv41Session session : client.sessions()) {
sb.append(" ")
.append(session)
.append(" slots (max/used): ")
.append(session.getHighestSlot())
.append('/')
.append(session.getHighestUsedSlot())
.append('\n');
}
}
return sb.toString();
}
}