+int mds_convert_mea_ea(struct obd_device *obd, struct inode *inode,
+ struct lov_mds_md *lmm, int lmmsize)
+{
+ int i, rc, err, size;
+ struct mea_old *old;
+ struct mea *mea;
+ struct mea *new;
+ void *handle;
+ ENTRY;
+
+ mea = (struct mea *) lmm;
+ if (mea->mea_magic == MEA_MAGIC_LAST_CHAR ||
+ mea->mea_magic == MEA_MAGIC_ALL_CHARS)
+ RETURN(0);
+
+ old = (struct mea_old *) lmm;
+ rc = sizeof(struct ll_fid) * old->mea_count + sizeof(struct mea_old);
+ if (old->mea_count > 256 || old->mea_master > 256 || lmmsize < rc
+ || old->mea_master > old->mea_count) {
+ CWARN("unknown MEA format, dont convert it\n");
+ CWARN(" count %u, master %u, size %u\n",
+ old->mea_count, old->mea_master, rc);
+ RETURN(0);
+ }
+
+ CWARN("converting MEA EA on %lu/%u from V0 to V1 (%u/%u)\n",
+ inode->i_ino, inode->i_generation, old->mea_count, old->mea_master);
+
+ size = sizeof(struct ll_fid) * old->mea_count + sizeof(struct mea);
+ OBD_ALLOC(new, size);
+ if (new == NULL)
+ RETURN(-ENOMEM);
+
+ new->mea_magic = MEA_MAGIC_LAST_CHAR;
+ new->mea_count = old->mea_count;
+ new->mea_master = old->mea_master;
+ for (i = 0; i < new->mea_count; i++)
+ new->mea_fids[i] = old->mea_fids[i];
+
+ handle = fsfilt_start(obd, inode, FSFILT_OP_SETATTR, NULL);
+ if (IS_ERR(handle)) {
+ rc = PTR_ERR(handle);
+ GOTO(conv_free, rc);
+ }
+
+ rc = fsfilt_set_md(obd, inode, handle, (struct lov_mds_md *) new, size);
+ if (rc > lmmsize)
+ size = lmmsize;
+ memcpy(lmm, new, size);
+
+ err = fsfilt_commit(obd, obd->u.mds.mds_sb, inode, handle, 0);
+ if (!rc)
+ rc = err ? err : size;
+ GOTO(conv_free, rc);
+conv_free:
+ OBD_FREE(new, size);
+ return rc;
+}
+