Whamcloud - gitweb
LU-13048 mdd: allow release after a non-blocking migrate
[fs/lustre-release.git] / lustre / utils / liblustreapi_util.c
index 9818851..ceab7a4 100644 (file)
@@ -297,7 +297,7 @@ int llapi_search_ost(const char *fsname, const char *poolname,
  * \retval                     0 on success
  * \retval                     -ve on failure
  */
-int llapi_root_path_open(char *device, int *rootfd)
+int llapi_root_path_open(const char *device, int *rootfd)
 {
        int tmp_fd, rc;
 
@@ -333,7 +333,7 @@ int llapi_rmfid(const char *path, struct fid_array *fa)
 {
        int rootfd, rc;
 
-       rc = llapi_root_path_open((char *)path, &rootfd);
+       rc = llapi_root_path_open(path, &rootfd);
        if (rc < 0) {
                fprintf(stderr,
                        "lfs rmfid: error opening device/fsname '%s': %s\n",
@@ -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));
@@ -362,10 +363,15 @@ int llapi_direntry_remove(char *dname)
        int rc = 0;
 
        dirpath = strdup(dname);
-       namepath = strdup(dname);
-       if (!dirpath || !namepath)
+       if (!dirpath)
                return -ENOMEM;
 
+       namepath = strdup(dname);
+       if (!namepath) {
+               rc = -ENOMEM;
+               goto out_dirpath;
+       }
+
        filename = basename(namepath);
 
        dir = dirname(dirpath);
@@ -383,10 +389,10 @@ int llapi_direntry_remove(char *dname)
                            "error on ioctl %#lx for '%s' (%d)",
                            (long)LL_IOC_LMV_SETSTRIPE, filename, fd);
 out:
-       free(dirpath);
+       close(fd);
        free(namepath);
-       if (fd != -1)
-               close(fd);
+out_dirpath:
+       free(dirpath);
        return rc;
 #else
        return -EOPNOTSUPP;