Whamcloud - gitweb
LU-17000 utils: Remove check for errno != 0 42/53742/2
authorArshad Hussain <arshad.hussain@aeoncomputing.com>
Fri, 19 Jan 2024 07:44:21 +0000 (13:14 +0530)
committerOleg Drokin <green@whamcloud.com>
Sun, 4 Feb 2024 08:32:48 +0000 (08:32 +0000)
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 <arshad.hussain@aeoncomputing.com>
Change-Id: I7257434e6546f56f30841f49a3bde35e80360bb8
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53742
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/mount_utils.c

index 4313c86..0686159 100644 (file)
@@ -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",