Skip to content

Commit

Permalink
nfs: extend host filter of 'show clients' command to accept patterns
Browse files Browse the repository at this point in the history
Motivation:
the host is aims to help admins to filter nfs clients based on provided
mask. However, current implementation support exact ip match only.

Modification:
extend host filter of 'show clients' command to the same kind of
patterns as export files.

Result:
more flexible host filtering.

Acked-by: Paul Millar
Target: master
Require-book: no
Require-notes: yes
  • Loading branch information
kofemann committed Jan 24, 2020
1 parent 4f6ef66 commit d02f314
Showing 1 changed file with 8 additions and 5 deletions.
Expand Up @@ -74,7 +74,9 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.dcache.alarms.AlarmMarkerFactory;
import org.dcache.alarms.PredefinedAlarm;
Expand All @@ -94,6 +96,7 @@
import org.dcache.nfs.ChimeraNFSException;
import org.dcache.nfs.ExportFile;
import org.dcache.nfs.FsExport;
import org.dcache.nfs.InetAddressMatcher;
import org.dcache.nfs.nfsstat;
import org.dcache.nfs.status.DelayException;
import org.dcache.nfs.status.LayoutTryLaterException;
Expand Down Expand Up @@ -169,7 +172,6 @@

import static java.util.stream.Collectors.toList;

import java.util.stream.Stream;

import javax.annotation.concurrent.GuardedBy;

Expand Down Expand Up @@ -972,7 +974,7 @@ public String call() throws IOException {
description = "Show NFSv4 clients and corresponding sessions.")
public class ShowClientsCmd implements Callable<String> {

@Argument(required = false, metaVar = "host")
@Argument(required = false, metaVar = "host", usage = "address/netmask|pattern")
String host;

@Override
Expand All @@ -981,12 +983,13 @@ public String call() throws IOException {
return "NFSv4 server not running.";
}

InetAddress clientAddress = InetAddress.getByName(host);
StringBuilder sb = new StringBuilder();
Predicate<InetAddress> clientMatcher =
host == null ? c -> true: InetAddressMatcher.forPattern(host);

StringBuilder sb = new StringBuilder();
_nfs4.getStateHandler().getClients()
.stream()
.filter(c -> host == null? true : c.getRemoteAddress().getAddress().equals(clientAddress))
.filter(c -> clientMatcher.test(c.getRemoteAddress().getAddress()))
.forEach(c -> {
sb.append(" ").append(c).append("\n");
for (NFSv41Session session : c.sessions()) {
Expand Down

0 comments on commit d02f314

Please sign in to comment.