statfs on NFS partition always returns "0"
Issue
Symptom/Problem
- Even if an error occurs, statfs on NFS always returns 0
- When an error like the server down occurs on NFS, if a program calls statfs() system call, it will return 0. However it should return a negative value.
Environment
- Red Hat Enterprise Linux 5.3
- Red Hat Enterprise Linux 4.8
Resolution
- Apply the following errata which addresses this issue. http://access.redhat.com/errata/RHSA-2011:0263
Root Cause
- nfs_statfs() function shouldn't return 0.
- The original patch upstream.
Diagnostic Steps
-
Start NFS service:
# echo "/test *(rw,no_root_squash)" >> /etc/exports # service nfs start
-
Setup client:
# mount -t nfs -o soft,timeo=5 server:/test /mnt/nfs
-
Stop NFS service:
# service nfs stop
-
From the client, run program such as:
#include <stdio.h> #include <stdlib.h> #include <sys/statvfs.h> int main() { struct statvfs sv; int rc; rc = statvfs("/mnt/nfs", &sv); if (rc < 0) { perror("statvfs"); exit(1); } return 0; }
-
Waiting for awhile, it would return with 0 even NFS server is already offline. The above program returns with 0, which actually should return negative number according to statfs(2).
-
The call trace is as below:
sys_statfs() => return 0 vfs_statfs() => return 0 nfs_statfs() => return 0 nfs3_proc_statfs() => return -5
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.