Commit 2e58ea52 authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs4: fix en/decode of REMOVEXATTR4res

Acked-by: Paul Millar
Target: master, 0.20
parent 67f6c898
/*
* Copyright (c) 2019 Deutsches Elektronen-Synchroton,
* Copyright (c) 2019 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
*
* This library is free software; you can redistribute it and/or modify
......@@ -22,10 +22,13 @@ package org.dcache.nfs.v4;
import java.io.IOException;
import org.dcache.nfs.ChimeraNFSException;
import org.dcache.nfs.nfsstat;
import org.dcache.nfs.v4.xdr.change_info4;
import org.dcache.nfs.v4.xdr.changeid4;
import org.dcache.nfs.v4.xdr.nfs_argop4;
import org.dcache.nfs.v4.xdr.nfs_opnum4;
import org.dcache.nfs.v4.xdr.nfs_resop4;
import org.dcache.nfs.vfs.Inode;
import org.dcache.nfs.vfs.Stat;
import org.dcache.oncrpc4j.rpc.OncRpcException;
public class OperationREMOVEXATTR extends AbstractNFSv4Operation {
......@@ -38,8 +41,18 @@ public class OperationREMOVEXATTR extends AbstractNFSv4Operation {
public void process(CompoundContext context, nfs_resop4 result) throws ChimeraNFSException, IOException, OncRpcException {
Inode inode = context.currentInode();
result.opremovexattr.rxr_info = new change_info4();
result.opremovexattr.rxr_info.atomic = true;
Stat stat = context.getFs().getattr(inode);
result.opremovexattr.rxr_info.before = new changeid4(stat.getGeneration());
context.getFs().removeXattr(inode, _args.opremovexattr.rxa_name);
stat = context.getFs().getattr(inode);
result.opremovexattr.rxr_info.after = new changeid4(stat.getGeneration());
result.setStatus(nfsstat.NFS_OK);
}
}
......@@ -7,6 +7,7 @@
* See http://www.dCache.ORG for details
*/
package org.dcache.nfs.v4.xdr;
import org.dcache.nfs.nfsstat;
import org.dcache.oncrpc4j.rpc.*;
import org.dcache.oncrpc4j.rpc.net.*;
import org.dcache.oncrpc4j.xdr.*;
......@@ -27,11 +28,17 @@ public class REMOVEXATTR4res implements XdrAble {
public void xdrEncode(XdrEncodingStream xdr)
throws OncRpcException, IOException {
xdr.xdrEncodeInt(rxr_status);
if (rxr_status == nfsstat.NFS_OK) {
rxr_info.xdrEncode(xdr);
}
}
public void xdrDecode(XdrDecodingStream xdr)
throws OncRpcException, IOException {
rxr_status = xdr.xdrDecodeInt();
if (rxr_status == nfsstat.NFS_OK) {
rxr_info = new change_info4(xdr);
}
}
}
......
......@@ -6,14 +6,17 @@ import org.dcache.nfs.v4.xdr.COMPOUND4args;
import org.dcache.nfs.v4.xdr.COMPOUND4res;
import org.dcache.nfs.v4.xdr.nfs_fh4;
import org.dcache.nfs.vfs.Inode;
import org.dcache.nfs.vfs.Stat;
import org.dcache.nfs.vfs.VirtualFileSystem;
import org.junit.Before;
import org.junit.Test;
import static org.dcache.nfs.v4.NfsTestUtils.execute;
import static org.dcache.nfs.v4.NfsTestUtils.generateRpcCall;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class OperationREMOVEXATTRTest {
......@@ -22,8 +25,23 @@ public class OperationREMOVEXATTRTest {
private final nfs_fh4 fh = new nfs_fh4(inode.toNfsHandle());
@Before
public void setUp() {
public void setUp() throws IOException {
vfs = mock(VirtualFileSystem.class);
Stat fileStat = new Stat();
fileStat.setMode(Stat.S_IFREG | 0755);
fileStat.setMTime(System.currentTimeMillis());
fileStat.setATime(System.currentTimeMillis());
fileStat.setCTime(System.currentTimeMillis());
fileStat.setGeneration(1);
fileStat.setNlink(2);
fileStat.setUid(1);
fileStat.setGid(2);
fileStat.setDev(1);
fileStat.setFileid(1);
fileStat.setSize(512);
when(vfs.getattr(any())).thenReturn(fileStat);
}
@Test
......
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