1

I am trying to do some testing of several thousand NFSv3 fileserver exports across hundreds of servers. Lots of things can go wrong, from configurations on the server to network connectivity. The most complete test I can do is to actually try to mount it on a client.

I can do that, but actually mounting everything is more than I need, takes state and resources beyond the program's execution, and tends to stress client a bit. I've more than once seen problems that seem to indicate something on the client was unhappy and preventing a mount from happening. (With no changes other than a client reboot, mounts worked again).

I was hoping to instead code something lighter weight that would simply act as a NFS client and see if the NFS MOUNT call successfully returned a filehandle. If it did, my server is running and my client is authorized. But I've not found any simple code to do so.

When I look at the Linux Source, it looks like at least some of the code is involved with it being a linux module, which is confusing.

Is there some user-space code that just requests a NFS filehandle via a mount call that I might be able to strip down? (Or is there any reason that my idea wouldn't work)? This is all AUTH_SYS, so I don't have to get kerberos tickets or anything.

BowlOfRed
  • 339
  • 2
  • 11

2 Answers2

0

Without knowing more, I will speculate a little based on my knowledge of NFS/Linux file systems.

I assume your client is linux (but the same logic could apply with windows if it had an nfs client present).

It sounds like when you do the mounts you are reaching a point where resources are being consumed to the point that the client cannot mount any more nfs mounts. Makes sense as when you reboot it starts working again, and a reboot will drop the nfs mounts (assuming that you are explicitly/programmatically mounting) thus allowing mounts to occur again. I bet you are just mounting the nfs mounts and are never unmounting them. So I would suggest the following:

  1. mount
  2. access a file or directory in the just mounted nfs filesystem
  3. unmount the nfs file system
Jimd
  • 1
  • 1
  • No, for this purpose I do attempt to unmount every time, but it's not always sufficient to prevent problems. That's why I'm looking to write a lightweight NFS client. – BowlOfRed Feb 21 '17 at 16:25
  • Even if you do write a client, the nfs file system will have to be mounted to execute it. Of course you are probably are aware of this. – Jimd Feb 22 '17 at 10:04
  • If all you need to do is acquire a file handle (I assume you mean a file descriptor), I am not sure about windows, with Linux or any other unix variant, you simply use the open() system call, there is this object in the filesystem called a vnode that points to either a real or a virtual file system (nfs is a virtual file system). There is really no need to dig in the kernel or use the NFS RPC Client to do this. Now your mileage may vary as you are on windoz and ms tends to do things "their way" and often are not done according to standards/specifications and I speak from experience on this. – Jimd Feb 22 '17 at 13:45
  • I don't understand why an NFS client that requests a filehandle would have to do anything with it (such as hand it off to a filesystem driver). I plan to simply discard it after receiving it. All my current work is Linux. – BowlOfRed Feb 22 '17 at 19:00
  • Wow, that was a bad error in my comment. I have no idea why I typed "windows" in the earlier comment. I deleted it. It's all Linux. – BowlOfRed Feb 22 '17 at 19:01
  • well then all you have to do is an open system call, doesn't matter if the file is a local mount or a remote nfs mount, if it can access the file it will return a file descriptor otherwise will return an error with error code in errno variable – Jimd Feb 22 '17 at 19:10
  • Certainly that is a possible way to do it. I'm looking to avoid any file descriptor/open or any relationship with the kernel. I just want a user-space NFS call. No open files, no mounts. – BowlOfRed Feb 22 '17 at 19:13
0

well, then just get the rpc protocol definition files for the version of nfs you are running, probably version 3 or 4, run them through the rpcget xdr protocol compiler you will get client functions in c that you can compile that you can make calls to the server with. But they will execute several system system calls, no way to do network communication linux without that happening and it will go throuth the tcp/ip stack (you will probably use udp) in the linux kernel. U can probably find the nfs protocol definition files on the SUN/Oracle website, or you can get find them in the source for a linux distribution -- you will be making application layer calls but the client calls rpc library functions which in turn will call linux system calls which go to the kernel

Jimd
  • 1
  • 1