Whamcloud - gitweb
LU-12090 utils: lfs rmfid
[fs/lustre-release.git] / lustre / utils / liblustreapi_util.c
index d206b02..59f7e98 100644 (file)
@@ -34,6 +34,7 @@
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <sys/ioctl.h>
 #include <string.h>
 #include <unistd.h>
 #include <sys/time.h>
@@ -286,3 +287,27 @@ int llapi_search_ost(const char *fsname, const char *poolname,
        return llapi_search_tgt(fsname, poolname, ostname, false);
 }
 
+int llapi_rmfid(const char *path, struct fid_array *fa)
+{
+       char rootpath[PATH_MAX];
+       int fd, rc;
+
+retry_open:
+       fd = open(path, O_RDONLY | O_NONBLOCK | O_NOFOLLOW);
+       if (fd < 0) {
+               if (errno == ENOENT && path != rootpath) {
+                       rc = llapi_search_rootpath(rootpath, path);
+                       if (!rc) {
+                               path = rootpath;
+                               goto retry_open;
+                       }
+               } else {
+                       return -errno;
+               }
+       }
+
+       rc = ioctl(fd, LL_IOC_RMFID, fa);
+       close(fd);
+
+       return rc ? -errno : 0;
+}