Skip to content

Commit

Permalink
nfs: do not use CDC as try-with-resource
Browse files Browse the repository at this point in the history
in a cunstruction like:

  try (CDC ignored = new CDC()) {
     ....
  } catch (Exception e) {
    log.error(e);
  }

the catch block will not have a correct context.
Use try-catch-finally instead.

Acked-by: Gerd Behrmann
Target: master, 2.9, 2.8, 2.7
Require-book: no
Require-notes: no
(cherry picked from commit c34be64)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
(cherry picked from commit c4fef0c)
Signed-off-by: Tigran Mkrtchyan <tigran.mkrtchyan@desy.de>
  • Loading branch information
kofemann committed Apr 23, 2014
1 parent f1b91b1 commit 969e14f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Expand Up @@ -389,9 +389,10 @@ public Layout layoutGet(CompoundContext context, Inode nfsInode, int ioMode, sta
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());
CDC cdc = CDC.reset(_cellName, _domainName);
try {
NDC.push(inode.toString());
NDC.push(context.getRpcCall().getTransport().getRemoteSocketAddress().toString());
deviceid4 deviceid;
if (inode.type() != FsInodeType.INODE || inode.getLevel() != 0) {
/*
Expand Down Expand Up @@ -447,6 +448,8 @@ public Layout layoutGet(CompoundContext context, Inode nfsInode, int ioMode, sta
_ioMessages.remove(stateid);
throw new ChimeraNFSException(nfsstat.NFSERR_LAYOUTTRYLATER,
e.getMessage());
} finally {
cdc.close();
}

}
Expand Down
Expand Up @@ -50,7 +50,8 @@ public ProxyIoREAD(nfs_argop4 args, DcapProxyIoFactory proxyIoFactory) {
public void process(CompoundContext context, nfs_resop4 result) {
final READ4res res = result.opread;

try (CDC ignored = new CDC()) {
CDC cdc = CDC.reset(proxyIoFactory.getCellName(), proxyIoFactory.getCellDomainName());
try {
NDC.push(context.getRpcCall().getTransport().getRemoteSocketAddress().toString());
Inode inode = context.currentInode();
if (!context.getFs().hasIOLayout(inode)) {
Expand Down Expand Up @@ -109,6 +110,8 @@ public void process(CompoundContext context, nfs_resop4 result) {
}catch(Exception e) {
_log.error("DSREAD: ", e);
res.status = nfsstat.NFSERR_SERVERFAULT;
} finally {
cdc.close();
}
}

Expand Down

0 comments on commit 969e14f

Please sign in to comment.