Whamcloud - gitweb
LU-8998 clio: getstripe support comp layout
[fs/lustre-release.git] / lustre / llite / dir.c
index b171f3e..c78767e 100644 (file)
@@ -570,6 +570,15 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
                         lum_size = sizeof(struct lov_user_md_v3);
                         break;
                 }
+               case LOV_USER_MAGIC_COMP_V1: {
+                       if (lump->lmm_magic !=
+                           cpu_to_le32(LOV_USER_MAGIC_COMP_V1))
+                               lustre_swab_lov_comp_md_v1(
+                                       (struct lov_comp_md_v1 *)lump);
+                       lum_size = le32_to_cpu(
+                               ((struct lov_comp_md_v1 *)lump)->lcm_size);
+                       break;
+               }
                case LMV_USER_MAGIC: {
                        if (lump->lmm_magic != cpu_to_le32(LMV_USER_MAGIC))
                                lustre_swab_lmv_user_md(
@@ -610,7 +619,10 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
         * LOV_USER_MAGIC_V3 have the same initial fields so we do not
         * need the make the distiction between the 2 versions
         */
-       if (set_default && mgc->u.cli.cl_mgc_mgsexp) {
+       if (set_default && mgc->u.cli.cl_mgc_mgsexp &&
+           (lump == NULL ||
+            le32_to_cpu(lump->lmm_magic) == LOV_USER_MAGIC_V1 ||
+            le32_to_cpu(lump->lmm_magic) == LOV_USER_MAGIC_V3)) {
                char *param = NULL;
                char *buf;
 
@@ -625,23 +637,23 @@ int ll_dir_setstripe(struct inode *inode, struct lov_user_md *lump,
                buf += strlen(buf);
 
                /* Set root stripesize */
-               sprintf(buf, ".stripesize=%u",
-                       lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
+               snprintf(buf, MGS_PARAM_MAXLEN, ".stripesize=%u",
+                        lump ? le32_to_cpu(lump->lmm_stripe_size) : 0);
                rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
                if (rc)
                        GOTO(end, rc);
 
                /* Set root stripecount */
-               sprintf(buf, ".stripecount=%hd",
-                       lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
+               snprintf(buf, MGS_PARAM_MAXLEN, ".stripecount=%hd",
+                        lump ? le16_to_cpu(lump->lmm_stripe_count) : 0);
                rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
                if (rc)
                        GOTO(end, rc);
 
                /* Set root stripeoffset */
-               sprintf(buf, ".stripeoffset=%hd",
-                       lump ? le16_to_cpu(lump->lmm_stripe_offset) :
-                       (typeof(lump->lmm_stripe_offset))(-1));
+               snprintf(buf, MGS_PARAM_MAXLEN, ".stripeoffset=%hd",
+                        lump ? le16_to_cpu(lump->lmm_stripe_offset) :
+                               (typeof(lump->lmm_stripe_offset))(-1));
                rc = ll_send_mgc_param(mgc->u.cli.cl_mgc_mgsexp, param);
 
 end:
@@ -719,6 +731,11 @@ int ll_dir_getstripe(struct inode *inode, void **plmm, int *plmm_size,
                if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
                        lustre_swab_lov_user_md_v3((struct lov_user_md_v3 *)lmm);
                break;
+       case LOV_MAGIC_COMP_V1:
+               if (LOV_MAGIC != cpu_to_le32(LOV_MAGIC))
+                       lustre_swab_lov_comp_md_v1(
+                                       (struct lov_comp_md_v1 *)lmm);
+               break;
        case LMV_MAGIC_V1:
                if (LMV_MAGIC != cpu_to_le32(LMV_MAGIC))
                        lustre_swab_lmv_mds_md((union lmv_mds_md *)lmm);
@@ -1254,36 +1271,37 @@ lmv_out_free:
 
                RETURN(rc);
        }
-        case LL_IOC_LOV_SETSTRIPE: {
-                struct lov_user_md_v3 lumv3;
-                struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
+       case LL_IOC_LOV_SETSTRIPE: {
+               struct lov_user_md_v3 lumv3;
+               struct lov_user_md_v1 *lumv1 = (struct lov_user_md_v1 *)&lumv3;
                struct lov_user_md_v1 __user *lumv1p =
                        (struct lov_user_md_v1 __user *)arg;
                struct lov_user_md_v3 __user *lumv3p =
                        (struct lov_user_md_v3 __user *)arg;
 
-                int set_default = 0;
+               int set_default = 0;
 
-                LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
-                LASSERT(sizeof(lumv3.lmm_objects[0]) ==
-                        sizeof(lumv3p->lmm_objects[0]));
-                /* first try with v1 which is smaller than v3 */
+               CLASSERT(sizeof(struct lov_user_md_v3) >
+                        sizeof(struct lov_comp_md_v1));
+               LASSERT(sizeof(lumv3) == sizeof(*lumv3p));
+               LASSERT(sizeof(lumv3.lmm_objects[0]) ==
+                               sizeof(lumv3p->lmm_objects[0]));
+               /* first try with v1 which is smaller than v3 */
                if (copy_from_user(lumv1, lumv1p, sizeof(*lumv1)))
                         RETURN(-EFAULT);
 
-                if ((lumv1->lmm_magic == LOV_USER_MAGIC_V3) ) {
+               if (lumv1->lmm_magic == LOV_USER_MAGIC_V3)
                        if (copy_from_user(&lumv3, lumv3p, sizeof(lumv3)))
-                                RETURN(-EFAULT);
-                }
+                               RETURN(-EFAULT);
 
                if (inode->i_sb->s_root == file_dentry(file))
-                        set_default = 1;
+                       set_default = 1;
 
-                /* in v1 and v3 cases lumv1 points to data */
-                rc = ll_dir_setstripe(inode, lumv1, set_default);
+               /* in v1 and v3 cases lumv1 points to data */
+               rc = ll_dir_setstripe(inode, lumv1, set_default);
 
-                RETURN(rc);
-        }
+               RETURN(rc);
+       }
        case LL_IOC_LMV_GETSTRIPE: {
                struct lmv_user_md __user *ulmv =
                                        (struct lmv_user_md __user *)arg;