Whamcloud - gitweb
LU-14093 utils: trivial changes to support gcc10
[fs/lustre-release.git] / lustre / utils / liblustreapi_ladvise.c
index b606dfe..6fd0209 100644 (file)
@@ -38,7 +38,6 @@
 #include <errno.h>
 
 #include <lustre/lustreapi.h>
-#include <lustre/lustre_idl.h>
 #include "lustreapi_internal.h"
 
 /*
@@ -53,8 +52,9 @@
 int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
                  struct llapi_lu_ladvise *ladvise)
 {
-       int rc;
        struct llapi_ladvise_hdr *ladvise_hdr;
+       int rc;
+       int i;
 
        if (num_advise < 1 || num_advise >= LAH_COUNT_MAX) {
                errno = EINVAL;
@@ -78,8 +78,24 @@ int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
        rc = ioctl(fd, LL_IOC_LADVISE, ladvise_hdr);
        if (rc < 0) {
                llapi_error(LLAPI_MSG_ERROR, -errno, "cannot give advice");
-               return -1;
+               goto out;
+       } else {
+               rc = 0;
+       }
+
+       /* Copy results back in to caller provided structs */
+       for (i = 0; i < num_advise; i++) {
+               struct llapi_lu_ladvise *ladvise_iter;
+
+               ladvise_iter = &ladvise_hdr->lah_advise[i];
+
+               if (ladvise_iter->lla_advice == LU_LADVISE_LOCKAHEAD)
+                       ladvise[i].lla_lockahead_result =
+                                       ladvise_iter->lla_lockahead_result;
        }
-       return 0;
+
+out:
+       free(ladvise_hdr);
+       return rc;
 }