Whamcloud - gitweb
LU-15220 utils: use 'fallthrough' pseudo keyword for switch
[fs/lustre-release.git] / lustre / utils / liblustreapi_ladvise.c
index 85083f1..6fd0209 100644 (file)
@@ -38,7 +38,6 @@
 #include <errno.h>
 
 #include <lustre/lustreapi.h>
-#include <lustre/lustre_idl.h>
 #include "lustreapi_internal.h"
 
 /*
  * \param ladvise  Advice to give.
  *
  * \retval 0 on success.
- * \retval -errno on failure.
+ * \retval -1 on failure, errno set
  */
 int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
-                 struct lu_ladvise *ladvise)
+                 struct llapi_lu_ladvise *ladvise)
 {
+       struct llapi_ladvise_hdr *ladvise_hdr;
        int rc;
-       struct ladvise_hdr *ladvise_hdr;
+       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;
 }