Whamcloud - gitweb
LU-17444 utils: fix fd leak after conversion to llapi_root_path_open 36/53736/3
authorDominique Martinet <asmadeus@codewreck.org>
Thu, 18 Jan 2024 20:46:10 +0000 (05:46 +0900)
committerOleg Drokin <green@whamcloud.com>
Tue, 23 Jan 2024 05:43:10 +0000 (05:43 +0000)
Conversions to llapi_root_path_open missed a few close() calls, leading
to fd leaks.

These should be obvious enough to regroup in a single commit.

Fixes: 7154244354e3 ("LU-16786 utils: Replace open call to WANT_FD")
Change-Id: I3af25ef2981367bfaea7f5280972f84bee09a5c2
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/53736
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Stephane Thiell <sthiell@stanford.edu>
Reviewed-by: Etienne AUJAMES <eaujames@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/lfs.c
lustre/utils/liblustreapi_fid.c
lustre/utils/liblustreapi_util.c

index 4566994..20e42c0 100644 (file)
@@ -10102,10 +10102,11 @@ static int lfs_rmfid(int argc, char **argv)
 
        fa = malloc(offsetof(struct fid_array, fa_fids[nr + 1]));
        if (!fa) {
+               rc = -errno ?: -ENOMEM;
                fprintf(stderr, "%s rmfid: error allocating %zd bytes: %s\n",
                        progname, offsetof(struct fid_array, fa_fids[nr + 1]),
-                       strerror(errno));
-               return -ENOMEM;
+                       strerror(-rc));
+               goto out_close;
        }
 
        fa->fa_nr = 0;
@@ -10149,6 +10150,7 @@ static int lfs_rmfid(int argc, char **argv)
                fa = NULL;
        }
 
+out_close:
        close(rootfd);
        return rc;
 }
index b3bf411..bf326bc 100644 (file)
@@ -472,15 +472,12 @@ int llapi_open_by_fid(const char *lustre_dir, const struct lu_fid *fid,
 {
        int mnt_fd, rc;
 
-       /* this will return a cached FD if available, so only one open needed.
-        * WANT_FD doesn't modify lustre_dir so casting away "const" is OK */
-
        rc = llapi_root_path_open(lustre_dir, &mnt_fd);
        if (rc)
                goto out;
 
-       /* "mnt_fd" is cached internally for reuse, no need to close it */
        rc = llapi_open_by_fid_at(mnt_fd, fid, flags);
+       close(mnt_fd);
 out:
        return rc;
 }
index 9309aac..ceab7a4 100644 (file)
@@ -342,6 +342,7 @@ int llapi_rmfid(const char *path, struct fid_array *fa)
        }
 
        rc = llapi_rmfid_at(rootfd, fa);
+       close(rootfd);
        if (rc < 0) {
                fprintf(stderr, "lfs rmfid: cannot remove FIDs: %s\n",
                        strerror(-rc));