/
NFSv41Door.java
731 lines (601 loc) · 24.9 KB
/
NFSv41Door.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
* $Id:NFSv41Door.java 140 2007-06-07 13:44:55Z tigran $
*/
package org.dcache.chimera.nfsv41.door;
import com.google.common.base.Joiner;
import com.google.common.collect.Sets;
import org.glassfish.grizzly.Buffer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.security.auth.Subject;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import diskCacheV111.util.CacheException;
import diskCacheV111.util.FileInCacheException;
import diskCacheV111.util.FsPath;
import diskCacheV111.util.PnfsHandler;
import diskCacheV111.util.PnfsId;
import diskCacheV111.vehicles.DoorTransferFinishedMessage;
import diskCacheV111.vehicles.IoDoorEntry;
import diskCacheV111.vehicles.IoDoorInfo;
import diskCacheV111.vehicles.PoolMoverKillMessage;
import diskCacheV111.vehicles.PoolPassiveIoFileMessage;
import dmg.cells.nucleus.CDC;
import dmg.cells.nucleus.CellMessage;
import dmg.cells.nucleus.CellPath;
import dmg.cells.nucleus.CellInfoProvider;
import dmg.cells.services.login.LoginManagerChildrenInfo;
import dmg.util.Args;
import java.util.Set;
import org.dcache.auth.Subjects;
import org.dcache.cells.AbstractCellComponent;
import org.dcache.cells.CellCommandListener;
import org.dcache.cells.CellMessageReceiver;
import org.dcache.cells.CellStub;
import org.dcache.chimera.FsInode;
import org.dcache.chimera.FsInodeType;
import org.dcache.chimera.JdbcFs;
import org.dcache.nfs.ChimeraNFSException;
import org.dcache.nfs.ExportFile;
import org.dcache.nfs.nfsstat;
import org.dcache.nfs.v3.MountServer;
import org.dcache.nfs.v3.NfsServerV3;
import org.dcache.nfs.v3.xdr.mount_prot;
import org.dcache.nfs.v3.xdr.nfs3_prot;
import org.dcache.nfs.v4.CompoundContext;
import org.dcache.nfs.v4.Layout;
import org.dcache.nfs.v4.MDSOperationFactory;
import org.dcache.nfs.v4.NFS4Client;
import org.dcache.nfs.v4.NFSServerV41;
import org.dcache.nfs.v4.NFSv41DeviceManager;
import org.dcache.nfs.v4.NFSv41Session;
import org.dcache.nfs.v4.RoundRobinStripingPattern;
import org.dcache.nfs.v4.StripingPattern;
import org.dcache.nfs.v4.xdr.device_addr4;
import org.dcache.nfs.v4.xdr.deviceid4;
import org.dcache.nfs.v4.xdr.layout4;
import org.dcache.nfs.v4.xdr.layoutiomode4;
import org.dcache.nfs.v4.xdr.layouttype4;
import org.dcache.nfs.v4.xdr.multipath_list4;
import org.dcache.nfs.v4.xdr.netaddr4;
import org.dcache.nfs.v4.xdr.nfs4_prot;
import org.dcache.nfs.v4.xdr.nfs_fh4;
import org.dcache.nfs.v4.xdr.nfsv4_1_file_layout_ds_addr4;
import org.dcache.nfs.v4.xdr.stateid4;
import org.dcache.nfs.vfs.ChimeraVfs;
import org.dcache.nfs.vfs.Inode;
import org.dcache.nfs.vfs.VirtualFileSystem;
import org.dcache.chimera.nfsv41.mover.NFS4ProtocolInfo;
import org.dcache.commons.stats.RequestExecutionTimeGauges;
import org.dcache.commons.util.NDC;
import org.dcache.util.LoginBrokerHandler;
import org.dcache.util.RedirectedTransfer;
import org.dcache.util.Transfer;
import org.dcache.util.TransferRetryPolicy;
import org.dcache.utils.Bytes;
import org.dcache.xdr.OncRpcException;
import org.dcache.xdr.OncRpcProgram;
import org.dcache.xdr.OncRpcSvc;
import org.dcache.xdr.OncRpcSvcBuilder;
import org.dcache.xdr.XdrBuffer;
import org.dcache.xdr.gss.GssSessionManager;
import org.springframework.beans.factory.annotation.Required;
public class NFSv41Door extends AbstractCellComponent implements
NFSv41DeviceManager, CellCommandListener,
CellMessageReceiver, CellInfoProvider {
private static final Logger _log = LoggerFactory.getLogger(NFSv41Door.class);
/** dCache-friendly NFS device id to pool name mapping */
private final Map<String, PoolDS> _poolNameToIpMap = new HashMap<>();
/** All known devices */
private final Map<deviceid4, PoolDS> _deviceMap = new HashMap<>();
/** next device id, 0 reserved for MDS */
private final AtomicInteger _nextDeviceID = new AtomicInteger(1);
/*
* reserved device for IO through MDS (for pnfs dot files)
*/
private static final deviceid4 MDS_ID = deviceidOf(0);
private final Map<stateid4, NfsTransfer> _ioMessages = new ConcurrentHashMap<>();
/**
* The usual timeout for NFS ops. is 30s.
* We will use a bit shorter (27s) one to avoid retries.
*/
private final static long NFS_REPLY_TIMEOUT = TimeUnit.SECONDS.toMillis(27);
/**
* Given that the timeout is pretty short, the retry period has to
* be rather small too.
*/
private final static long NFS_RETRY_PERIOD = TimeUnit.SECONDS.toMillis(1);
/**
* Cell communication helper.
*/
private CellStub _poolManagerStub;
private CellStub _billingStub;
private String _cellName;
private String _domainName;
private PnfsHandler _pnfsHandler;
private String _ioQueue;
/**
* TCP port number to bind.
*/
private int _port;
/**
* nfs versions to run.
*/
private Set<String> _versions;
private final static String V3 = "3";
private final static String V41 = "4.1";
/**
* embedded nfs server
*/
private NFSServerV41 _nfs4;
/**
* RPC service
*/
private OncRpcSvc _rpcService;
private StrategyIdMapper _idMapper;
private boolean _enableRpcsecGss;
private VirtualFileSystem _vfs;
private LoginBrokerHandler _loginBrokerHandler;
private final static TransferRetryPolicy RETRY_POLICY =
new TransferRetryPolicy(Integer.MAX_VALUE, NFS_RETRY_PERIOD,
NFS_REPLY_TIMEOUT, NFS_REPLY_TIMEOUT);
public void setEnableRpcsecGss(boolean enable) {
_enableRpcsecGss = enable;
}
public void setIdMapper(StrategyIdMapper idMapper) {
_idMapper = idMapper;
}
public void setPoolManagerStub(CellStub stub)
{
_poolManagerStub = stub;
}
public void setPnfsHandler(PnfsHandler pnfs) {
_pnfsHandler = pnfs;
}
private JdbcFs _fileFileSystemProvider;
public void setFileSystemProvider(JdbcFs fs) {
_fileFileSystemProvider = fs;
}
private ExportFile _exportFile;
public void setExportFile(ExportFile export) {
_exportFile = export;
}
public void setIoQueue(String ioQueue) {
_ioQueue = ioQueue;
}
public void setPortNumber(int port) {
_port = port;
}
public void setVersions(String[] versions) {
_versions = Sets.newHashSet(versions);
}
@Required
public void setLoginBrokerHandler(LoginBrokerHandler loginBrokerHandler) {
_loginBrokerHandler = loginBrokerHandler;
}
public void init() throws Exception {
_cellName = getCellName();
_domainName = getCellDomainName();
_rpcService = new OncRpcSvcBuilder()
.withPort(_port)
.withTCP()
.withAutoPublish()
.build();
if (_enableRpcsecGss) {
_rpcService.setGssSessionManager(new GssSessionManager(_idMapper));
}
_vfs = new ChimeraVfs(_fileFileSystemProvider, _idMapper);
MountServer ms = new MountServer(_exportFile, _vfs);
_rpcService.register(new OncRpcProgram(mount_prot.MOUNT_PROGRAM, mount_prot.MOUNT_V3), ms);
_rpcService.register(new OncRpcProgram(mount_prot.MOUNT_PROGRAM, mount_prot.MOUNT_V3), ms);
for (String version : _versions) {
switch (version) {
case V3:
NfsServerV3 nfs3 = new NfsServerV3(_exportFile, _vfs);
_rpcService.register(new OncRpcProgram(nfs3_prot.NFS_PROGRAM, nfs3_prot.NFS_V3), nfs3);
break;
case V41:
final NFSv41DeviceManager _dm = this;
_nfs4 = new NFSServerV41(new MDSOperationFactory(),
_dm, _vfs, _idMapper, _exportFile);
_rpcService.register(new OncRpcProgram(nfs4_prot.NFS4_PROGRAM, nfs4_prot.NFS_V4), _nfs4);
_loginBrokerHandler.start();
break;
default:
throw new IllegalArgumentException("Unsupported NFS version: " + version);
}
}
_rpcService.start();
}
public void destroy() throws IOException {
_loginBrokerHandler.stop();
_rpcService.stop();
}
/*
* Handle reply from the pool that mover actually started.
*
* If the pools is not know yet, create a mapping between pool name
* and NFSv4.1 device id. Finally, notify waiting request that we have got
* the reply for LAYOUTGET
*/
public void messageArrived(PoolPassiveIoFileMessage<stateid4> message) {
String poolName = message.getPoolName();
_log.debug("NFS mover ready: {}", poolName);
InetSocketAddress[] poolAddress = message.socketAddresses();
PoolDS device = _poolNameToIpMap.get(poolName);
if (device == null || !Arrays.equals(device.getInetSocketAddress(), poolAddress)) {
/* pool is unknown yet or has been restarted so create new device and device-id */
int id = this.nextDeviceID();
if (device != null) {
/*
* clean stale entry
*/
deviceid4 oldId = device.getDeviceId();
_deviceMap.remove(oldId);
}
/*
* TODO: the PoolPassiveIoFileMessage have to be adopted to send
* list of all interfaces
*/
deviceid4 deviceid = deviceidOf(id);
device = new PoolDS(deviceid, poolAddress);
_poolNameToIpMap.put(poolName, device);
_deviceMap.put(deviceid, device);
_log.debug("new mapping: {}", device);
}
stateid4 stateid = message.challange();
NfsTransfer transfer = _ioMessages.get(stateid);
transfer.redirect(device);
}
public void messageArrived(DoorTransferFinishedMessage transferFinishedMessage) {
NFS4ProtocolInfo protocolInfo = (NFS4ProtocolInfo)transferFinishedMessage.getProtocolInfo();
_log.debug("Mover {} done.", protocolInfo.stateId());
Transfer transfer = _ioMessages.remove(protocolInfo.stateId());
if(transfer != null) {
transfer.finished(transferFinishedMessage);
transfer.notifyBilling(transferFinishedMessage.getReturnCode(), "");
}
}
private int nextDeviceID() {
return _nextDeviceID.incrementAndGet();
}
// NFSv41DeviceManager interface
/*
The most important calls is LAYOUTGET, OPEN, CLOSE, LAYOUTRETURN
The READ, WRITE and COMMIT goes to storage device.
We assume the following mapping between nfs and dcache:
NFS | dCache
_____________|________________________________________
LAYOUTGET : get pool, bind the answer to the client
OPEN : send IO request to the pool
CLOSE : sent end-of-IO to the pool, LAYOUTRECALL
LAYOUTRETURN : unbind pool from client
*/
@Override
public device_addr4 getDeviceInfo(CompoundContext context, deviceid4 deviceId) {
/* in case of MDS access we return the same interface which client already connected to */
if (deviceId.equals(MDS_ID)) {
return deviceAddrOf( new RoundRobinStripingPattern<InetSocketAddress[]>(),
new InetSocketAddress[] { context.getRpcCall().getTransport().getLocalSocketAddress() } );
}
PoolDS ds = _deviceMap.get(deviceId);
if( ds == null) {
return null;
}
return ds.getDeviceAddr();
}
/**
* ask pool manager for a file
*
* On successful reply from pool manager corresponding O request will be sent
* to the pool to start a NFS mover.
*
* @throws ChimeraNFSException in case of NFS friendly errors ( like ACCESS )
* @throws IOException in case of any other errors
*/
@Override
public Layout layoutGet(CompoundContext context, Inode nfsInode, int ioMode, stateid4 stateid)
throws IOException {
FsInode inode = _fileFileSystemProvider.inodeFromBytes(nfsInode.getFileId());
try(CDC cdc = CDC.reset(_cellName, _domainName)) {
NDC.push("pnfsid=" + inode);
NDC.push("client=" + context.getRpcCall().getTransport().getRemoteSocketAddress());
deviceid4 deviceid;
if (inode.type() != FsInodeType.INODE || inode.getLevel() != 0) {
/*
* all non regular files ( AKA pnfs dot files ) provided by door itself.
*/
deviceid = MDS_ID;
} else {
InetSocketAddress remote = context.getRpcCall().getTransport().getRemoteSocketAddress();
PnfsId pnfsId = new PnfsId(inode.toString());
Transfer.initSession();
NfsTransfer transfer = new NfsTransfer(_pnfsHandler, Subjects.ROOT,
context.getRpcCall().getCredential().getSubject(),
remote, stateid);
NFS4ProtocolInfo protocolInfo = transfer.getProtocolInfoForPool();
protocolInfo.door(new CellPath(getCellAddress()));
transfer.setCellName(this.getCellName());
transfer.setDomainName(this.getCellDomainName());
transfer.setBillingStub(_billingStub);
transfer.setPoolStub(_poolManagerStub);
transfer.setPoolManagerStub(_poolManagerStub);
transfer.setPnfsId(pnfsId);
transfer.setClientAddress(remote);
transfer.readNameSpaceEntry();
_ioMessages.put(protocolInfo.stateId(), transfer);
PoolDS ds = getPool(transfer, protocolInfo, ioMode);
deviceid = ds.getDeviceId();
}
nfs_fh4 fh = new nfs_fh4(nfsInode.toNfsHandle());
// -1 is special value, which means entire file
layout4 layout = Layout.getLayoutSegment(deviceid, fh, ioMode,
0, nfs4_prot.NFS4_UINT64_MAX);
return new Layout(true, stateid, new layout4[]{layout});
} catch (FileInCacheException e) {
throw new ChimeraNFSException(nfsstat.NFSERR_IO, e.getMessage());
} catch (InterruptedException | CacheException e) {
throw new ChimeraNFSException(nfsstat.NFSERR_LAYOUTTRYLATER,
e.getMessage());
}
}
private PoolDS getPool(NfsTransfer transfer, NFS4ProtocolInfo protocolInfo, int iomode)
throws InterruptedException, CacheException
{
if ((iomode == layoutiomode4.LAYOUTIOMODE4_READ) || !transfer.getStorageInfo().isCreatedOnly()) {
_log.debug("looking for read pool for {}", transfer.getPnfsId());
transfer.setWrite(false);
} else {
_log.debug("looking for write pool for {}", transfer.getPnfsId());
transfer.setWrite(true);
}
transfer.selectPoolAndStartMover(_ioQueue, RETRY_POLICY);
_log.debug("mover ready: pool={} moverid={}", transfer.getPool(),
transfer.getMoverId());
/*
* FIXME;
*
* usually RPC request will timeout in 30s.
* We have to handle this cases and return LAYOUTTRYLATER
* or GRACE.
*
*/
return transfer.waitForRedirect(NFS_REPLY_TIMEOUT);
}
@Override
public List<deviceid4> getDeviceList(CompoundContext context) {
List<deviceid4> knownDevices = new ArrayList<>();
knownDevices.addAll(_deviceMap.keySet());
return knownDevices;
}
/*
* (non-Javadoc)
*
* @see org.dcache.chimera.nfsv4.NFSv41DeviceManager#releaseDevice(stateid4 stateid)
*/
@Override
public void layoutReturn(CompoundContext context, stateid4 stateid) throws IOException {
_log.debug("Releasing device by stateid: {}", stateid);
NfsTransfer transfer = _ioMessages.get(stateid);
if (transfer == null) {
return;
}
_log.debug("Sending KILL to {}@{}", transfer.getMoverId(), transfer.getPool());
transfer.killMover(0);
try {
if(!transfer.waitForMover(500)) {
throw new ChimeraNFSException(nfsstat.NFSERR_DELAY, "Mover not stopped");
}
} catch (CacheException | InterruptedException e) {
_log.info("Failed to kill mover: {}@{} : {}",
transfer.getMoverId(), transfer.getPool(), e.getMessage());
throw new ChimeraNFSException(nfsstat.NFSERR_IO, e.getMessage());
}
}
public void setBillingStub(CellStub stub) {
_billingStub = stub;
}
/*
* Cell specific
*/
@Override
public void getInfo(PrintWriter pw) {
pw.println("NFS (" + _versions + ") door (MDS):");
if (_nfs4 != null) {
pw.printf(" IO queue: %s\n", _ioQueue);
pw.println(" Known pools (DS):\n");
for (Map.Entry<String, PoolDS> ioDevice : _poolNameToIpMap.entrySet()) {
pw.println(String.format(" %s : [%s]", ioDevice.getKey(), ioDevice.getValue()));
}
pw.println();
pw.println(" Known movers (layouts):");
for (NfsTransfer io : _ioMessages.values()) {
pw.println(String.format(" %s : %s@%s, OS=%s,cl=[%s]",
io.getPnfsId(),
io.getMoverId(),
io.getPool(),
io.getProtocolInfoForPool().stateId(),
io.getProtocolInfoForPool().getSocketAddress().getAddress().getHostAddress()));
}
pw.println();
pw.println(" Known clients:");
for (NFS4Client client : _nfs4.getClients()) {
pw.println(String.format(" %s", client));
for (NFSv41Session session : client.sessions()) {
pw.println(String.format(" %s, max slot: %d/%d",
session, session.getHighestSlot(), session.getHighestUsedSlot()));
}
}
}
}
public static final String hh_kill_mover = " <pool> <moverid> # kill mover on the pool";
public String ac_kill_mover_$_2(Args args) throws Exception {
int mover = Integer.parseInt(args.argv(1));
String pool = args.argv(0);
PoolMoverKillMessage message = new PoolMoverKillMessage(pool, mover);
message.setReplyRequired(false);
sendMessage(new CellMessage(new CellPath(pool), message));
return "";
}
public static final String fh_exports_reload = " # re-scan export file";
public String ac_exports_reload(Args args) throws IOException {
_exportFile.rescan();
return "Done";
}
public static final String fh_exports_ls = " [host] # dump nfs exports";
public String ac_exports_ls_$_0_1(Args args) throws UnknownHostException {
InetAddress address = InetAddress.getByName(args.argv(0));
if (args.argc() > 0 ) {
return Joiner.on('\n').join(_exportFile.exportsFor(address));
} else {
return Joiner.on('\n').join(_exportFile.getExports());
}
}
private static deviceid4 deviceidOf(int id) {
byte[] deviceidBytes = new byte[nfs4_prot.NFS4_DEVICEID4_SIZE];
Bytes.putInt(deviceidBytes, 0, id);
return new deviceid4(deviceidBytes);
}
private static class PoolDS {
private final deviceid4 _deviceId;
private final InetSocketAddress[] _socketAddress;
private final device_addr4 _deviceAddr;
public PoolDS(deviceid4 deviceId, InetSocketAddress[] ip) {
_deviceId = deviceId;
_socketAddress = ip;
_deviceAddr = deviceAddrOf(new RoundRobinStripingPattern<InetSocketAddress[]>(), ip);
}
public deviceid4 getDeviceId() {
return _deviceId;
}
public InetSocketAddress[] getInetSocketAddress() {
return _socketAddress;
}
public device_addr4 getDeviceAddr() {
return _deviceAddr;
}
@Override
public String toString() {
return String.format("DS: %s, InetAddress: %s",
_deviceId, Arrays.toString(_socketAddress));
}
}
private static class NfsTransfer extends RedirectedTransfer<PoolDS> {
private final stateid4 _stateid;
private final NFS4ProtocolInfo _protocolInfo;
NfsTransfer(PnfsHandler pnfs, Subject namespaceSubject, Subject ioSubject, InetSocketAddress client,
stateid4 stateid) {
super(pnfs, namespaceSubject, ioSubject, new FsPath("/"));
_stateid = stateid;
_protocolInfo = new NFS4ProtocolInfo(client, _stateid);
}
@Override
protected NFS4ProtocolInfo getProtocolInfoForPoolManager() {
return _protocolInfo;
}
@Override
protected NFS4ProtocolInfo getProtocolInfoForPool() {
return _protocolInfo;
}
}
/**
* To allow the transfer monitoring in the httpd cell to recognize us
* as a door, we have to emulate LoginManager. To emulate
* LoginManager we list ourselves as our child.
*/
public final static String hh_get_children = "[-binary]";
public Object ac_get_children(Args args) {
boolean binary = args.hasOption("binary");
if (binary) {
String[] childrens = new String[]{this.getCellName()};
return new LoginManagerChildrenInfo(this.getCellName(), this.getCellDomainName(), childrens);
} else {
return this.getCellName();
}
}
public final static String hh_get_door_info = "[-binary]";
public final static String fh_get_door_info =
"Provides information about the door and current transfers";
public Object ac_get_door_info(Args args) {
List<IoDoorEntry> entries = new ArrayList<>();
for (Transfer transfer : _ioMessages.values()) {
entries.add(transfer.getIoDoorEntry());
}
IoDoorInfo doorInfo = new IoDoorInfo(this.getCellName(), this.getCellDomainName());
doorInfo.setProtocol("NFSV4.1", "0");
doorInfo.setOwner("");
doorInfo.setProcess("");
doorInfo.setIoDoorEntries(entries
.toArray(new IoDoorEntry[entries.size()]));
return args.hasOption("binary") ? doorInfo : doorInfo.toString();
}
/**
* Create a multipath based NFSv4.1 file layout address.
*
* @param stripingPattern of the device
* @param deviceAddress
* @return device address
*/
public static device_addr4 deviceAddrOf(StripingPattern<InetSocketAddress[]> stripingPattern,
InetSocketAddress[]... deviceAddress) {
nfsv4_1_file_layout_ds_addr4 file_type = new nfsv4_1_file_layout_ds_addr4();
file_type.nflda_multipath_ds_list = new multipath_list4[deviceAddress.length];
for (int i = 0; i < deviceAddress.length; i++) {
file_type.nflda_multipath_ds_list[i] = toMultipath(deviceAddress[i]);
}
file_type.nflda_stripe_indices = stripingPattern.getPattern(deviceAddress);
XdrBuffer xdr = new XdrBuffer(128);
try {
xdr.beginEncoding();
file_type.xdrEncode(xdr);
xdr.endEncoding();
} catch (OncRpcException e) {
/* forced by interface, should never happen. */
throw new RuntimeException("Unexpected OncRpcException:", e);
} catch (IOException e) {
/* forced by interface, should never happen. */
throw new RuntimeException("Unexpected IOException:", e);
}
Buffer body = xdr.asBuffer();
byte[] retBytes = new byte[body.remaining()];
body.get(retBytes);
device_addr4 addr = new device_addr4();
addr.da_layout_type = layouttype4.LAYOUT4_NFSV4_1_FILES;
addr.da_addr_body = retBytes;
return addr;
}
private static multipath_list4 toMultipath(InetSocketAddress[] addresses)
{
multipath_list4 multipath = new multipath_list4();
multipath.value = new netaddr4[addresses.length];
for(int i = 0; i < addresses.length; i++) {
multipath.value[i] = new netaddr4(addresses[i]);
}
return multipath;
}
public final static String fh_stats =
"stats [-c] # show nfs requests statstics\n\n" +
" Print nfs operation statistics.\n" +
" -c clear current statistics values";
public final static String hh_stats = " [-c] # show nfs requests statstics";
public String ac_stats(Args args) {
RequestExecutionTimeGauges<String> gauges = _nfs4.getStatistics();
StringBuilder sb = new StringBuilder();
sb.append("Stats:").append("\n").append(gauges);
if (args.hasOption("c")) {
gauges.reset();
}
return sb.toString();
}
}