From 04d95ff28d1ddca79c204ceff7cd5d6ddfe83c34 Mon Sep 17 00:00:00 2001 From: Arshad Hussain Date: Fri, 19 Jan 2024 13:14:21 +0530 Subject: [PATCH] LU-17000 utils: Remove check for errno != 0 In lustre_rename_fsname() after calls to system calls like open/read/write/lseek there is a check if global errno is not equal to zero. This is noop and not required, as these system calls do reset errno to 0 on success. The side effect of this check was that it appeared that the errno could be 0 which would leave 'ret' as negative. This would never happen, but was causing Coverity to complain. This patch fixes this coverity issue by removing the comparison of errno != 0 which is not required. Test-Parameters: trivial testlist=conf-sanity,sanityn Fixes: d0c6e97fa53 ("LU-8900 snapshot: rename filesysetem fsname") CoverityID: 397153 ("Argument cannot be negative") Signed-off-by: Arshad Hussain Change-Id: I7257434e6546f56f30841f49a3bde35e80360bb8 Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53742 Reviewed-by: Andreas Dilger Reviewed-by: Timothy Day Reviewed-by: James Simmons Reviewed-by: Oleg Drokin Tested-by: jenkins Tested-by: Maloo --- lustre/utils/mount_utils.c | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/lustre/utils/mount_utils.c b/lustre/utils/mount_utils.c index 4313c86..0686159 100644 --- a/lustre/utils/mount_utils.c +++ b/lustre/utils/mount_utils.c @@ -1082,10 +1082,7 @@ int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt, if (errno == ENOENT) goto config; - if (errno != 0) - ret = errno; - else - ret = fd; + ret = errno; fprintf(stderr, "Unable to open %s: %s\n", filepnm, strerror(ret)); return ret; @@ -1093,8 +1090,11 @@ int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt, ret = read(fd, &lsd, sizeof(lsd)); if (ret != sizeof(lsd)) { - if (errno != 0) + if (ret < 0) ret = errno; + else + /* short read */ + ret = EINTR; fprintf(stderr, "Unable to read %s: %s\n", filepnm, strerror(ret)); close(fd); @@ -1102,9 +1102,8 @@ int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt, } ret = lseek(fd, 0, SEEK_SET); - if (ret) { - if (errno != 0) - ret = errno; + if (ret < 0) { + ret = errno; fprintf(stderr, "Unable to lseek %s: %s\n", filepnm, strerror(ret)); close(fd); @@ -1123,8 +1122,11 @@ int lustre_rename_fsname(struct mkfs_opts *mop, const char *mntpt, memcpy(lsd.lsd_uuid, ldd->ldd_fsname, new_namelen); ret = write(fd, &lsd, sizeof(lsd)); if (ret != sizeof(lsd)) { - if (errno != 0) + if (ret < 0) ret = errno; + else + /* short writes */ + ret = EINTR; fprintf(stderr, "Unable to write %s: %s\n", filepnm, strerror(ret)); close(fd); @@ -1137,10 +1139,7 @@ config: snprintf(cfg_dir, sizeof(cfg_dir), "%s/%s", mntpt, MOUNT_CONFIGS_DIR); dir = opendir(cfg_dir); if (!dir) { - if (errno != 0) - ret = errno; - else - ret = EINVAL; + ret = errno; fprintf(stderr, "Unable to opendir %s: %s\n", cfg_dir, strerror(ret)); return ret; @@ -1199,9 +1198,8 @@ config: else ret = unlink(filepnm); - if (ret) { - if (errno != 0) - ret = errno; + if (ret < 0) { + ret = errno; fprintf(stderr, "Fail to %s %s: %s\n", IS_MGS(ldd) ? "setxattr" : "unlink", -- 1.8.3.1