#include <errno.h>
#include <lustre/lustreapi.h>
-#include <lustre/lustre_idl.h>
#include "lustreapi_internal.h"
/*
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;
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;
}