+/* Is this a lustre fs? */
+int llapi_is_lustre_mnttype(const char *type)
+{
+ return (strcmp(type, "lustre") == 0 || strcmp(type,"lustre_lite") == 0);
+}
+
+/* Is this a lustre client fs? */
+int llapi_is_lustre_mnt(struct mntent *mnt)
+{
+ return (llapi_is_lustre_mnttype(mnt->mnt_type) &&
+ strstr(mnt->mnt_fsname, ":/") != NULL);
+}
+
+int llapi_quotacheck(char *mnt, int check_type)
+{
+ DIR *root;
+ int rc;
+
+ root = opendir(mnt);
+ if (!root) {
+ err_msg("open %s failed", mnt);
+ return -1;
+ }
+
+ rc = ioctl(dirfd(root), LL_IOC_QUOTACHECK, check_type);
+
+ closedir(root);
+ return rc;
+}
+
+int llapi_poll_quotacheck(char *mnt, struct if_quotacheck *qchk)
+{
+ DIR *root;
+ int poll_intvl = 2;
+ int rc;
+
+ root = opendir(mnt);
+ if (!root) {
+ err_msg("open %s failed", mnt);
+ return -1;
+ }
+
+ while (1) {
+ rc = ioctl(dirfd(root), LL_IOC_POLL_QUOTACHECK, qchk);
+ if (!rc)
+ break;
+ sleep(poll_intvl);
+ if (poll_intvl < 30)
+ poll_intvl *= 2;
+ }
+
+ closedir(root);
+ return rc;
+}
+
+int llapi_quotactl(char *mnt, struct if_quotactl *qctl)
+{
+ DIR *root;
+ int rc;
+
+ root = opendir(mnt);
+ if (!root) {
+ err_msg("open %s failed", mnt);
+ return -1;
+ }
+
+ rc = ioctl(dirfd(root), LL_IOC_QUOTACTL, qctl);
+
+ closedir(root);
+ return rc;
+}
+
+static int cb_quotachown(char *path, DIR *parent, DIR *d, void *data)
+{
+ struct find_param *param = (struct find_param *)data;
+ lstat_t *st;
+ int rc;
+
+ LASSERT(parent != NULL || d != NULL);
+
+ if (d) {
+ rc = ioctl(dirfd(d), LL_IOC_MDC_GETINFO,
+ (void *)param->lmd);
+ } else if (parent) {
+ char *fname = strrchr(path, '/');
+ fname = (fname == NULL ? path : fname + 1);
+
+ strncpy((char *)param->lmd, fname, param->lumlen);
+ rc = ioctl(dirfd(parent), IOC_MDC_GETFILEINFO,
+ (void *)param->lmd);
+ } else {
+ return 0;
+ }
+
+ if (rc) {
+ if (errno == ENODATA) {
+ if (!param->obduuid && !param->quiet)
+ fprintf(stderr, "%s has no stripe info\n",
+ path);
+ rc = 0;
+ } else if (errno != EISDIR) {
+ rc = errno;
+ err_msg("%s ioctl failed for %s.",
+ d ? "LL_IOC_MDC_GETINFO" :
+ "IOC_MDC_GETFILEINFO", path);
+ }
+ return rc;
+ }
+
+ st = ¶m->lmd->lmd_st;
+
+ /* libc chown() will do extra check, and if the real owner is
+ * the same as the ones to set, it won't fall into kernel, so
+ * invoke syscall directly. */
+ rc = syscall(SYS_chown, path, -1, -1);
+ if (rc)
+ err_msg("error: chown %s (%u,%u)", path);
+
+ rc = chmod(path, st->st_mode);
+ if (rc)
+ err_msg("error: chmod %s (%hu)", path, st->st_mode);
+
+ return rc;
+}
+
+int llapi_quotachown(char *path, int flag)