2020-05-21 02:56:32

by Craig Small

[permalink] [raw]
Subject: How to separate NFS mounts have same device ID

Hi,
I'm the author of the psmisc programs that include things like killall and fuser. I have a problem with finding files open on NFS mounts from the same server. The issue is at https://gitlab.com/psmisc/psmisc/-/issues/10

The way fuser does its job is to find the mounts you specify and collect the device IDs, then scans all /proc/<PID/fd/* for matching devices. However, NFS mounts from the same server have the same device ID so fuser reports every mount has the same file opened.

Putting it another way, if I said "here is file /proc/<PID>/fd/3, dereference the symlink and tell me which of these two NFS mounts from the same server it comes from?" how would you do it?
A simple string match (/mnt/a vs /mnt/b) does not work because you can have symlinks across mounts.

Any help here would be appreciated. I'm not subscribed to the list so hopefully, this makes it through whatever filters there are and please CC me on replies.

- Craig


2020-05-21 05:13:38

by NeilBrown

[permalink] [raw]
Subject: Re: How to separate NFS mounts have same device ID

On Thu, May 21 2020, Craig Small wrote:

> Hi,
> I'm the author of the psmisc programs that include things like killall and fuser. I have a problem with finding files open on NFS mounts from the same server. The issue is at https://gitlab.com/psmisc/psmisc/-/issues/10
>
> The way fuser does its job is to find the mounts you specify and collect the device IDs, then scans all /proc/<PID/fd/* for matching devices. However, NFS mounts from the same server have the same device ID so fuser reports every mount has the same file opened.
>
> Putting it another way, if I said "here is file /proc/<PID>/fd/3, dereference the symlink and tell me which of these two NFS mounts from the same server it comes from?" how would you do it?
> A simple string match (/mnt/a vs /mnt/b) does not work because you can have symlinks across mounts.

I would examine /proc/<PID>/fdinfo/3 and extract the 'mnt_id:' number,
then look for that (as the first field) in /proc/<PID>/mountinfo.

NeilBrown


>
> Any help here would be appreciated. I'm not subscribed to the list so hopefully, this makes it through whatever filters there are and please CC me on replies.
>
> - Craig


Attachments:
signature.asc (847.00 B)

2020-05-21 06:29:40

by Craig Small

[permalink] [raw]
Subject: Re: How to separate NFS mounts have same device ID

On Thu, 21 May 2020 at 15:12, NeilBrown <[email protected]> wrote:
> I would examine /proc/<PID>/fdinfo/3 and extract the 'mnt_id:' number,
> then look for that (as the first field) in /proc/<PID>/mountinfo.

The mountinfo looks very promising and a better way of uniquely
working out where a file is mounted. Thanks!

- Craig