Stale file handle ошибка

The error, ESTALE, was originally introduced to handle the situation
where a file handle, which NFS uses to uniquely identify a file on the
server, no longer refers to a valid file on the server. This can
happen when the file is removed on the server, either by an
application on the server, some other client accessing the server, or
sometimes even by another mounted file system from the same client.
The NFS server also returns this error when the file resides upon a
file system which is no longer exported. Additionally, some NFS
servers even change the file handle when a file is renamed, although
this practice is discouraged.

This error occurs even if a file or directory, with the same name, is
recreated on the server without the client being aware of it. The
file handle refers to a specific instance of a file and deleting the
file and then recreating it creates a new instance of the file.

The error, ESTALE, is usually seen when cached directory information
is used to convert a pathname to a dentry/inode pair. The information
is discovered to be out of date or stale when a subsequent operation
is sent to the NFS server. This can easily happen in system calls
such as stat(2) when the pathname is converted a dentry/inode pair
using cached information, but then a subsequent GETATTR call to the
server discovers that the file handle is no longer valid.

This error can also occur when a change is made on the server in
between looking up different components of the pathname to be looked
up or between a successful lookup and a subsequent operation.

Original link about ESTALE: ESTALE LWN .

I suggest to you check files and directories on NFS server or say to admin of NFS server to do this.

Maybe some old pagecache, inode, dentry cache entries are exists on NFS server. Please clean it:

# To free pagecache
echo 1 > /proc/sys/vm/drop_caches

# To free dentries and inodes
echo 2 > /proc/sys/vm/drop_caches

# To free pagecache, dentries and inodes
echo 3 > /proc/sys/vm/drop_caches

Say I have a terminal open, and through that terminal I have cd‘ed to some directory. Through another terminal, I delete that directory and restore it back from an identical backup. When I try to vim a file from the first terminal, in the same directory, why do I get an error about a stale file handle? What does it mean? (On a side note, I have found that it is possible to bypass this issue through cd $(pwd).)

gerrit's user avatar

gerrit

24.1k17 gold badges97 silver badges170 bronze badges

asked Nov 20, 2013 at 19:34

IDDQD's user avatar

1

When the directory is deleted, the inode for that directory (and the inodes for its contents) are recycled. The pointer your shell has to that directory’s inode (and its contents’s inodes) are now no longer valid. When the directory is restored from backup, the old inodes are not (necessarily) reused; the directory and its contents are stored on random inodes. The only thing that stays the same is that the parent directory reuses the same name for the restored directory (because you told it to).

Now if you attempt to access the contents of the directory that your original shell is still pointing to, it communicates that request to the file system as a request for the original inode, which has since been recycled (and may even be in use for something entirely different now). So you get a stale file handle message because you asked for some nonexistent data.

When you perform a cd operation, the shell reevaluates the inode location of whatever destination you give it. Now that your shell knows the new inode for the directory (and the new inodes for its contents), future requests for its contents will be valid.

answered Nov 20, 2013 at 19:56

dg99's user avatar

dg99dg99

5,4863 gold badges37 silver badges49 bronze badges

4

Learn how to resolve mount.nfs: Stale file handle error on the Linux platform. This is a Network File System error that can be resolved from the client or server end.

When you are using the Network File System in your environment, you must have seen mount.nfs: Stale file handle error at times. This error denotes that the NFS share is unable to mount since something has changed since the last good known configuration.

Whenever you reboot the NFS server or some of the NFS processes are not running on the client or server or share is not properly exported at the server; these can be reasons for this error. Moreover, it’s irritating when this error comes to a previously mounted NFS share. Because this means the configuration part is correct since it was previously mounted. In such case once can try the following commands:

Make sure NFS service are running good on client and server.

#  service nfs status
rpc.svcgssd is stopped
rpc.mountd (pid 11993) is running...
nfsd (pid 12009 12008 12007 12006 12005 12004 12003 12002) is running...
rpc.rquotad (pid 11988) is running...

If NFS share currently mounted on the client, then un-mount it forcefully and try to remount it on NFS client. Check if its properly mounted by df command and changing directory inside it.

# umount -f /mydata_nfs
# mount -t nfs server:/nfs_share /mydata_nfs
#df -k
------ output clipped -----
server:/nfs_share 41943040  892928  41050112   3% /mydata_nfs

In above mount command, server can be IP or hostname of NFS server.

If you are getting error while forcefully un-mounting like below :

# umount -f /mydata_nfs
umount2: Device or resource busy
umount: /mydata_nfs: device is busy
umount2: Device or resource busy
umount: /mydata_nfs: device is busy

Then you can check which all processes or users are using that mount point with lsof command like below:

# lsof |grep mydata_nfs
lsof: WARNING: can't stat() nfs file system /mydata_nfs
      Output information may be incomplete.
su         3327      root  cwd   unknown                                                   /mydata_nfs/dir (stat: Stale NFS file handle)
bash       3484      grid  cwd   unknown                                                   /mydata_nfs/MYDB (stat: Stale NFS file handle)
bash      20092  oracle11  cwd   unknown                                                   /mydata_nfs/MPRP (stat: Stale NFS file handle)
bash      25040  oracle11  cwd   unknown                                                   /mydata_nfs/MUYR (stat: Stale NFS file handle)

If you see in above example that 4 PID are using some files on said mount point. Try killing them off to free mount point. Once done you will be able to un-mount it properly.

Sometimes it still gives the same error for mount command. Then try mounting after restarting NFS service at the client using the below command.

#  service nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down RPC idmapd:                                  [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]

Also read : How to restart NFS step by step in HPUX

Even if this didn’t solve your issue, final step is to restart services at the NFS server. Caution! This will disconnect all NFS shares which are exported from the NFS server. All clients will see the mount point disconnect. This step is where 99% of you will get your issue resolved. If not then NFS configurations must be checked, provided you have changed configuration and post that you started seeing this error.

Outputs in above post are from RHEL6.3 server. Drop us your comments related to this post.

Материал из Пингвиньи радостей

Перейти к: навигация, поиск

Статья о пакете Nfs-common

Nfs-common это пакет реализующий NFS-клиента в Linux и предоставляющий общие файлы для NFS-сервера.
Nfs-common используется для подключения к NFS-серверу например Nfs-kernel-server.
В пакет включены программы: lockd, statd, showmount, nfsstat, gssd и idmapd.

Установка

Пакет присутствует в хранилище пакетов debian.
Для установки пакета

  • в командной строке: следует выполнить команду # apt-get install nfs-common
  • в графическом режиме: воспользоваться специализированной программой управления пакетами

После установки пакет готов к использованию.

Некоторые часто используемые программы

  # /etc/init.d/nfs-common restart                - перезапуск nfs-клиента
  # mount.nfs IP-SERVER:/share  /mnt/             - монтирование ресурса /share сервера IP-SERVER в точку /mnt
  # showmount                                     - отображение подключённых клиентов
  # nfsstat -s                                    - отображение статистику nfs-клиента

Для автоматического подключения NFS-ресурсов через файл /etc/fstab

  • в файл /etc/fstab добавляется строка
  # устройство     точка монтирования   тип ФС     параметры                      dump fsckorder
  IP-SERVER:/share     /mnt               nfs     rsize=1024,wsize=1024,hard,intr   0      0
  Замечание:
  Подробное описание параметров монтирования ресурсов по протоколу NFS приведено в статье Mount.

Устранение ошибки Stale NFS file handle

При возникновении ошибки Stale NFS file handle следует установить раздельный fsid=num в файле /etc/exports сервера nfs для ресурсов находящихся на одном UUID, например на одном разделе жёсткого диска.

Литература

  • NFSv4

Справочная информация

  • 03.04.2014: Nfs-common: создание статьи о пакете реализующем NFS-клиента

On the server node, it is possible to access an exported folder. However, after reboots (both server and client), the folder is no longer accessible from the clients.

On server

# ls /data
Folder1
Forlder2

and the /etc/exports file contains

/data 192.168.1.0/24(rw,no_subtree_check,async,no_root_squash)

On client

# ls /data
ls: cannot access /data: Stale NFS file handle

I have to say that there were no problem with the shared folder from client side however after reboots (server and client), I see this message.

Any way to fix that?

asked Aug 3, 2014 at 18:16

mahmood's user avatar

The order of reboots is important. Rebooting the server after the clients can result in this situation. The stale NFS handle indicates that the client has a file open, but the server no longer recognizes the file handle. In some cases, NFS will cleanup its data structures after a timeout. In other cases, you will need to clean the NFS data structures yourself and restart NFS afterwards. Where these structures are located are somewhat O/S dependent.

Try restarting NFS first on the server and then on the clients. This may clear the file handles.

Rebooting NFS servers with files opened from other servers is not recommended. This is especially problematic if the open file has been deleted on the server. The server may keep the file open until it is rebooted, but the reboot will remove the in-memory file handle on the server side. Then the client will no longer be able to open the file.

Determining which mounts have been used from the server is difficult and unreliable. The showmount -a option may show some active mounts, but may not report all of them. Locked files are easier to identify, but require the locking to be enabled and relies on the client software to lock the files.

You can use lsof on the clients to identify the processes which have files open on the mounts.

I use the hard and intr mount options on my NFS mounts. The hard option causes IO to be retried indefinitely. The intr option allows processes to be killed if they are waiting on NFS IO to complete.

answered Aug 3, 2014 at 22:43

BillThor's user avatar

BillThorBillThor

27.8k3 gold badges37 silver badges69 bronze badges

3

Try this script I wrote:

#!/bin/bash
# Purpose:
# Detect Stale File handle and remove it
# Script created: July 29, 2015 by Birgit Ducarroz
# Last modification: --
#

# Detect Stale file handle and write output into a variable and then into a file
mounts=`df 2>&1 | grep 'Stale file handle' |awk '{print ""$2"" }' > NFS_stales.txt`
# Remove : ‘ and ’ characters from the output
sed -r -i 's/://' NFS_stales.txt && sed -r -i 's/‘//' NFS_stales.txt && sed -r -i 's/’//' NFS_stales.txt

# Not used: replace space by a new line
# stales=`cat NFS_stales.txt && sed -r -i ':a;N;$!ba;s/ /\n /g' NFS_stales.txt`

# read NFS_stales.txt output file line by line then unmount stale by stale.
#    IFS='' (or IFS=) prevents leading/trailing whitespace from being trimmed.
#    -r prevents backslash escapes from being interpreted.
#    || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n (since read returns a non-zero exit code when it encounters EOF).

while IFS='' read -r line || [[ -n "$line" ]]; do
    echo "Unmounting due to NFS Stale file handle: $line"
    umount -fl $line
done < "NFS_stales.txt"
#EOF

In meantime, the above script works not with all servers. Here is an update:

#!/bin/bash
# Purpose:
# Detect Stale File handle and remove it
# Script created: July 29, 2015 by Birgit Ducarroz
# Last modification: 23.12.2020  /bdu
#

MYMAIL="my.mail@something.com"
THIS_HOST=`hostname`

# Detect Stale file handle and write output into a variable and then into a file
mounts=`df 2>&1 | grep 'Stale' |awk '{print ""$2"" }' > NFS_stales.txt`
sleep 8

# Remove : special characters from the output

sed -r -i 's/://' NFS_stales.txt && sed -r -i 's/‘//' NFS_stales.txt && sed -r -i 's/’//' NFS_stales.txt && sed -r -i 's/`//' NFS_stales.txt  && sed -r -i "s/'//" NFS_stales.txt 


# Not used: replace space by a new line
# stales=`cat NFS_stales.txt && sed -r -i ':a;N;$!ba;s/ /\n /g' NFS_stales.txt`

# read NFS_stales.txt output file line by line then unmount stale by stale.
#    IFS='' (or IFS=) prevents leading/trailing whitespace from being trimmed.
#    -r prevents backslash escapes from being interpreted.
#    || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n (since read returns a non-zero exit code when it encounters EOF).

while IFS='' read -r line || [[ -n "$line" ]]; do
    message=`echo "Unmounting due to NFS Stale file handle: $line"`
    echo echo | mail -s "$THIS_HOST: NFS Stale Handle unmounted" $MYMAIL <<< $message
    umount -f -l $line
done < "NFS_stales.txt"
mount -a

#EOF

Birgit Ducarroz's user avatar

answered Jul 29, 2015 at 8:00

Birgit Ducarroz's user avatar

On the NFS server UN-export and re-export the file system:

exportfs -u nfs-server:/file_system
exportfs nfs-server:/file_system

On the client mount the file system

mount -t nfs nfs-server:/filesystem /mount_point

answered Mar 16, 2018 at 21:26

Chin's user avatar

check lsof of specific path and kill respective pid .
Then unmount the partition and mount it back.

answered Feb 18, 2019 at 16:53

sridhar gattu's user avatar

1

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Понравилась статья? Поделить с друзьями:
  • Stalcraft ошибка подключения
  • Stalcraft ошибка запуска
  • Stag 200 go fast ошибки
  • St mobile мобильная торговля ошибка 1105
  • Ssps ssangyong rexton ошибка