From 4f965b8cff863334d536ec8a9806dba5eb10c62f Mon Sep 17 00:00:00 2001 From: Andreas Dilger Date: Tue, 21 Jan 2014 14:25:56 -0700 Subject: [PATCH] LU-4397 utils: fix lfs_df loop for disconnected client If the client is disconnected from the MDT on which "lfs df" is run (typically MDT0 for the mountpoint), then the file open can fail with -ESHUTDOWN, causing mntdf() to loop forever trying to find other MDTs or OSTs to get statfs data from. The caller of llapi_obd_statfs() cannot tell the difference between an error from open() and ioctl(IOC_OBD_STATFS), so llapi_obd_statfs() should return a fatal error if the open failed since all of the later opens will fail as well. Signed-off-by: Andreas Dilger Change-Id: I05d48d5b6680c382c9e05c02fd82a9a200500c1e Reviewed-on: http://review.whamcloud.com/8949 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Emoly Liu Reviewed-by: Faccini Bruno Reviewed-by: Oleg Drokin --- lustre/utils/liblustreapi.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 402c44e..ff20c9a 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3429,18 +3429,20 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, if (errno == EISDIR) fd = open(path, O_DIRECTORY | O_RDONLY); - if (fd < 0) { - rc = errno ? -errno : -EBADF; - llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'", - __func__, path); - return rc; - } - rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf); - if (rc) - rc = errno ? -errno : -EINVAL; + if (fd < 0) { + rc = errno ? -errno : -EBADF; + llapi_error(LLAPI_MSG_ERROR, rc, "error: %s: opening '%s'", + __func__, path); + /* If we can't even open a file on the filesystem (e.g. with + * -ESHUTDOWN), force caller to exit or it will loop forever. */ + return -ENODEV; + } + rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf); + if (rc) + rc = errno ? -errno : -EINVAL; - close(fd); - return rc; + close(fd); + return rc; } #define MAX_STRING_SIZE 128 -- 1.8.3.1