From: John L. Hammond Date: Thu, 20 Oct 2016 16:52:44 +0000 (-0500) Subject: LU-8731 utils: propagate errors in lfs df X-Git-Tag: 2.8.60~4 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=bfd4600f31691fdad676a8489f591bccc24f2100 LU-8731 utils: propagate errors in lfs df Add llapi_obd_fstatfs() which does the same thing as llapi_obd_statfs() but takes an open file descriptor instead of a path. Refector the handler for 'lfs df' to use llapi_obd_fstatfs(), thereby avoiding opening the mount point for each target and making the error conditions easier to understand. Propagate errors from llapi_obd_fstatfs() as the exit status of 'lfs df'. In conf-sanity.sh test_64() allow 'lfs df' to fail when a target is offline. Signed-off-by: John L. Hammond Change-Id: Iabfc92a65571b1a277de7fd42431f5b7e45ad440 Reviewed-on: http://review.whamcloud.com/23286 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: Hongchao Zhang --- diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index fa04465..52b141c 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -247,6 +247,9 @@ extern int llapi_dir_create_pool(const char *name, int flags, int stripe_offset, int stripe_count, int stripe_pattern, const char *poolname); int llapi_direntry_remove(char *dname); + +int llapi_obd_fstatfs(int fd, __u32 type, __u32 index, + struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf); extern int llapi_obd_statfs(char *path, __u32 type, __u32 index, struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf); diff --git a/lustre/tests/conf-sanity.sh b/lustre/tests/conf-sanity.sh index a27994b..880c918 100755 --- a/lustre/tests/conf-sanity.sh +++ b/lustre/tests/conf-sanity.sh @@ -4467,7 +4467,7 @@ test_64() { mount_client $MOUNT || error "Unable to mount client" stop_ost2 || error "Unable to stop second ost" echo "$LFS df" - $LFS df --lazy || error "lfs df failed" + $LFS df --lazy umount_client $MOUNT -f || error “unmount $MOUNT failed” cleanup_nocli || error "cleanup_nocli failed with $?" #writeconf to remove all ost2 traces for subsequent tests diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 9ba07579..109fd8d 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -2356,7 +2356,9 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, __u64 ost_ffree = 0; __u32 index; __u32 type; - int rc; + int fd; + int rc = 0; + int rc2; if (pool) { poolname = strchr(pool, '.'); @@ -2370,6 +2372,14 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, poolname = pool; } + fd = open(mntdir, O_RDONLY); + if (fd < 0) { + rc = -errno; + fprintf(stderr, "%s: cannot open '%s': %s\n", progname, mntdir, + strerror(errno)); + return rc; + } + if (ishow) printf(UUF" "CSF" "CSF" "CSF" "RSF" %-s\n", "UUID", "Inodes", "IUsed", "IFree", @@ -2384,13 +2394,16 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, memset(&stat_buf, 0, sizeof(struct obd_statfs)); memset(&uuid_buf, 0, sizeof(struct obd_uuid)); type = lazy ? tp->st_op | LL_STATFS_NODELAY : tp->st_op; - rc = llapi_obd_statfs(mntdir, type, index, - &stat_buf, &uuid_buf); - if (rc == -ENODEV) - break; - - if (rc == -EAGAIN) + rc2 = llapi_obd_fstatfs(fd, type, index, + &stat_buf, &uuid_buf); + if (rc2 == -ENODEV) + break; + else if (rc2 == -EAGAIN) continue; + else if (rc2 == -ENODATA) + ; /* Inactive device, OK. */ + else if (rc2 < 0 && rc == 0) + rc = rc2; if (poolname && tp->st_op == LL_STATFS_LOV && llapi_search_ost(fsname, poolname, @@ -2405,10 +2418,10 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, if (uuid_buf.uuid[0] == '\0') sprintf(uuid_buf.uuid, "%s%04x", tp->st_name, index); - showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf), - ishow, cooked, tp->st_name, index, rc); + showdf(mntdir, &stat_buf, obd_uuid2str(&uuid_buf), + ishow, cooked, tp->st_name, index, rc2); - if (rc == 0) { + if (rc2 == 0) { if (tp->st_op == LL_STATFS_LMV) { sum.os_ffree += stat_buf.os_ffree; sum.os_files += stat_buf.os_files; @@ -2421,12 +2434,12 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, stat_buf.os_bsize; ost_ffree += stat_buf.os_ffree; } - } else if (rc == -EINVAL || rc == -EFAULT) { - break; } } } + close(fd); + /* If we don't have as many objects free on the OST as inodes * on the MDS, we reduce the total number of inodes to * compensate, so that the "inodes in use" number is correct. @@ -2438,7 +2451,8 @@ static int mntdf(char *mntdir, char *fsname, char *pool, int ishow, printf("\n"); showdf(mntdir, &sum, "filesystem summary:", ishow, cooked, NULL, 0, 0); printf("\n"); - return 0; + + return rc; } static int lfs_df(int argc, char **argv) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 07c24ba..ef34c1b 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3356,11 +3356,9 @@ int llapi_getstripe(char *path, struct find_param *param) cb_common_fini, param); } -int llapi_obd_statfs(char *path, __u32 type, __u32 index, - struct obd_statfs *stat_buf, - struct obd_uuid *uuid_buf) +int llapi_obd_fstatfs(int fd, __u32 type, __u32 index, + struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf) { - int fd; char raw[OBD_MAX_IOCTL_BUFFER] = {'\0'}; char *rawbuf = raw; struct obd_ioctl_data data = { 0 }; @@ -3382,6 +3380,17 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, return rc; } + rc = ioctl(fd, IOC_OBD_STATFS, (void *)rawbuf); + + return rc < 0 ? -errno : 0; +} + +int llapi_obd_statfs(char *path, __u32 type, __u32 index, + struct obd_statfs *stat_buf, struct obd_uuid *uuid_buf) +{ + int fd; + int rc; + fd = open(path, O_RDONLY); if (fd < 0) { rc = -errno; @@ -3391,11 +3400,11 @@ int llapi_obd_statfs(char *path, __u32 type, __u32 index, * -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; + + rc = llapi_obd_fstatfs(fd, type, index, stat_buf, uuid_buf); close(fd); + return rc; }