Whamcloud - gitweb
LU-15220 utils: fix gcc-11 -Werror=format-truncation= error
[fs/lustre-release.git] / lustre / utils / liblustreapi.c
index 1371a12..ca5debe 100644 (file)
@@ -776,6 +776,18 @@ retry_open:
        return fd;
 }
 
+int llapi_file_is_encrypted(int fd)
+{
+       unsigned long flags;
+       int rc;
+
+       rc = ioctl(fd, FS_IOC_GETFLAGS, &flags);
+       if (rc == -1)
+               return -errno;
+
+       return !!(flags & LUSTRE_ENCRYPT_FL);
+}
+
 int llapi_file_open_pool(const char *name, int flags, int mode,
                         unsigned long long stripe_size, int stripe_offset,
                         int stripe_count, int stripe_pattern, char *pool_name)
@@ -3658,7 +3670,7 @@ static inline void
 lov_v1v3_pool_name(struct lov_user_md *v1, char *pool_name)
 {
        if (v1->lmm_magic == LOV_USER_MAGIC_V3)
-               snprintf(pool_name, LOV_MAXPOOLNAME, "%s",
+               snprintf(pool_name, LOV_MAXPOOLNAME + 1, "%s",
                         ((struct lov_user_md_v3 *)v1)->lmm_pool_name);
        else
                pool_name[0] = '\0';
@@ -4880,20 +4892,21 @@ static int fget_projid(int fd, int *projid)
  * Check that the file's permissions in *st matches the one in find_param
  */
 static int check_file_permissions(const struct find_param *param,
-                       const lstat_t *st)
+                       mode_t mode)
 {
-       const mode_t st_mode = st->st_mode & 07777;
        int decision = 0;
 
+       mode &= 07777;
+
        switch (param->fp_perm_sign) {
        case LFS_FIND_PERM_EXACT:
-               decision = (st_mode == param->fp_perm);
+               decision = (mode == param->fp_perm);
                break;
        case LFS_FIND_PERM_ALL:
-               decision = ((st_mode & param->fp_perm) == param->fp_perm);
+               decision = ((mode & param->fp_perm) == param->fp_perm);
                break;
        case LFS_FIND_PERM_ANY:
-               decision = ((st_mode & param->fp_perm) != 0);
+               decision = ((mode & param->fp_perm) != 0);
                break;
        }
 
@@ -5094,6 +5107,13 @@ static int cb_find_init(char *path, int p, int *dp,
                }
        }
 
+       /* Check the file permissions from the stat info */
+       if (param->fp_perm_sign) {
+               decision = check_file_permissions(param, lmd->lmd_stx.stx_mode);
+               if (decision == -1)
+                       goto decided;
+       }
+
        if (param->fp_type && !checked_type) {
                if ((param->fp_check_mdt_count || param->fp_check_hash_flag ||
                     param->fp_hash_type) && !S_ISDIR(lmd->lmd_stx.stx_mode))
@@ -5316,9 +5336,6 @@ obd_matches:
              (param->fp_lazy && flags & OBD_MD_FLLAZYBLOCKS)))
                decision = 0;
 
-       if (param->fp_perm_sign)
-               decision = 0;
-
        /*
         * If file still fits the request, ask ost for updated info.
         * The regular stat is almost of the same speed as some new
@@ -5375,13 +5392,6 @@ obd_matches:
                                goto out;
                        }
                }
-
-               /* Check the file permissions from the stat info */
-               if (param->fp_perm_sign) {
-                       decision = check_file_permissions(param, &st);
-                       if (decision == -1)
-                               goto decided;
-               }
        }
 
        if (param->fp_check_size) {
@@ -5464,6 +5474,9 @@ static int cb_migrate_mdt_init(char *path, int p, int *dp,
        data.ioc_inlbuf2 = (char *)lmu;
        data.ioc_inllen2 = lmv_user_md_size(lmu->lum_stripe_count,
                                            lmu->lum_magic);
+       /* reach bottom? */
+       if (param->fp_depth == param->fp_max_depth)
+               data.ioc_type = MDS_MIGRATE_NSONLY;
        ret = llapi_ioctl_pack(&data, &rawbuf, sizeof(raw));
        if (ret != 0) {
                llapi_error(LLAPI_MSG_ERROR, ret,
@@ -5505,6 +5518,11 @@ migrate:
        }
 
 out:
+       /* Do not get down anymore? */
+       if (param->fp_depth == param->fp_max_depth)
+               ret = 1;
+       param->fp_depth++;
+
        if (dp != NULL) {
                /*
                 * If the directory is being migration, we need