Re: Search for advice on testing whether a local CIFS fd closed remotely

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jul 26, 2019 at 3:22 AM Gefei Li <gefeili.2013@xxxxxxxxx> wrote:
>
> Hi,
>
> From some stack overflow result I know that on a local ext4/fat32
> system, we can test whether a file descriptor is valid through
> "fcntl(fd, F_GETFD)". But in cifs cases, a fd typically bind a local
> fd to remote handle, do we have some c function/syscall that can test
> whether the fd is remotely closed?
>
> I've tried some windows way like "ioctl", which works well, and in
> linux local file system "fcntl" works. Tried to use "fcntl" on kernel
> 5.1.15, found no server request is received.. Could you please give me
> some advice on testing whether a fd is remoted closed in CIFS client?

both F_GETFD and F_GETFL look like they check in the local VFS only
(aren't passed down to the file system, whether ext4 or cifs or even nfs)
for the value of these flags (see do_fcntl function in fs/fcntl.c)

In general an open of a file (over an SMB3 mount) will result in a open
over a file on the server.   You can see the detailed information on
the network file handle ("PersistentFileID") open on the server by (on
the Linux client) doing:

       cat /proc/fs/cifs/open_files

If you were worried about a network crash temporarily closing remote handles
(in which case you might temporarily have a local handle which is not
open on the
server) you could (in theory) do:

      /proc/fs/cifs/Stats | grep "Open files"

but I did notice a bug (in the processing of one of those counters for
that /proc file)
in which we are leaking one of those two counters (the counter is
informational only
so presumably not a serious bug) and it can go negative so looking at the count
of open files on the server may not be as useful.

-- 
Thanks,

Steve



[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux