dCache / nfs4j

Pure Java NFSv3 and NFSv4.2 implementation
Other
240 stars 76 forks source link

Mountd run on same port as NFS #63

Closed aasenov closed 5 years ago

aasenov commented 6 years ago

I'm facing an issue running NFS4j server on Linux environment, while the default OS's NFS server is running. I'm changing port of NFS and Mountd daemons of OS's nfs, but still, there are some problems mounting the server. I construct my server the following way: `

        mNFSService = new OncRpcSvcBuilder().withPort(2049).withTCP().withAutoPublish().withWorkerThreadIoStrategy().withServiceName(serverName).build();
        NFSServerV41 nfs4 = new NFSServerV41.Builder().withVfs(mVFS).withOperationFactory(new MDSOperationFactory()).withExportFile(exportFile).build();
        NfsServerV3 nfs3 = new NfsServerV3(exportFile, mVFS);
        MountServer mountd = new MountServer(exportFile, mVFS);
        mNFSService.register(new OncRpcProgram(mount_prot.MOUNT_PROGRAM, mount_prot.MOUNT_V3), mountd);

        mNFSService.register(new OncRpcProgram(nfs3_prot.NFS_PROGRAM, nfs3_prot.NFS_V3), nfs3);
        mNFSService.register(new OncRpcProgram(nfs4_prot.NFS4_PROGRAM, nfs4_prot.NFS_V4), nfs4);
        mNFSService.start();

` But it seems that both NFS server and Mountd server runs on same port - 2049. If I try to mount using the following command: mount -v -t nfs -o vers=3,nolock,noacl,proto=tcp, :/ / it works fine both with version 3 and 4.1 if the default nfs server is stopped. But if I start the OS's NFS server on port 11200 and mountd on 11300 it seems that portmap detect that mountd on 11300 is the default one and redirect calls to it, instead to NFS4J mountd server. So now if I run the same command, it fails with: mount.nfs: mount(2): Permission denied and message in Linux's mountd log -> refused mount request from for / (/): not exported This works OK for version 4.1 but fails for 3, not sure what's the difference. If I add the following to mount command "port=2049,mountport=2049" I'm able to mount with version 3 too, so I'm suspecting that the problem is that mountd is running on the same port as nfs.

Is it possible to configure different port for mountd daemon, so the mount command to succeed without specifying ports for both version 3 and 4.1?

kofemann commented 6 years ago

This is not related to the same port. Rpcbind is a kind on service registry. If you start two mountd services, then only one of them get published and the last one wins. IOW, you can't have two mountd runningat the same time. With nfs is a bit different, as you run two different nfs versions, e,g it two different services.

To answer your question: yes, it is possible to run mountd and nfs on different ports. You just need to start two OncRpcSvc on two different ports and use one for nfs and other one for mountd.

aasenov commented 6 years ago

Thanks for the clarification - my bad. I've checked the results when executing "rpcinfo -p" on host machine and it seems that native NFS server is always the one listed, no matter when I start NFS4J server - maybe it re-register or something. So no matter of the ports, I'm unable to mount as the client is actually asking for port of program NFS(100003) and Mountd(100005) and it always receive the native NFS ones. It seems that if I specify port/mountport it works cause it didn't ask for ports at all. Native NFS server registry:

# rpcinfo -p
program vers proto   port  service
100000    4   tcp    111  portmapper
100000    3   tcp    111  portmapper
100000    2   tcp    111  portmapper
100000    4   udp    111  portmapper
100000    3   udp    111  portmapper
100000    2   udp    111  portmapper
100024    1   udp  39302  status
100024    1   tcp  47442  status
100005    1   udp  20048  mountd
100005    1   tcp  20048  mountd
100005    2   udp  20048  mountd
100005    2   tcp  20048  mountd
100005    3   udp  20048  mountd
100005    3   tcp  20048  mountd
100003    3   tcp   2049  nfs
100003    4   tcp   2049  nfs
100227    3   tcp   2049  nfs_acl
100003    3   udp   2049  nfs
100003    4   udp   2049  nfs
100227    3   udp   2049  nfs_acl
100021    1   udp  47909  nlockmgr
100021    3   udp  47909  nlockmgr
100021    4   udp  47909  nlockmgr
100021    1   tcp  34293  nlockmgr
100021    3   tcp  34293  nlockmgr
100021    4   tcp  34293  nlockmgr

I wanted to ask - is it OK to use the same Mount server instance to register both V1 and V3:

MountServer mountd = new MountServer(exportFile, mVFS);
mNFSService.register(new OncRpcProgram(mount_prot.MOUNT_PROGRAM, mount_prot.MOUNT_V1), mountd);
mNFSService.register(new OncRpcProgram(mount_prot.MOUNT_PROGRAM, mount_prot.MOUNT_V3), mountd);
kofemann commented 6 years ago

You can run and publish multiple versions of any service, including mountd. However be aware that you can't use mountd from nfs4j with regular nfsd server as export path to file handle mapping will not work.

aasenov commented 6 years ago

OK, thanks for the information.