int notify_change(struct mnt_idmap *idmap, struct dentry *dentry,
                  struct iattr *attr, struct inode **delegated_inode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct inode *inode = dentry->d_inode;
        umode_t mode = inode->i_mode;
        int error;
         * namespace of the superblock.
         */
        if (ia_valid & ATTR_UID &&
-           !vfsuid_has_fsmapping(mnt_userns, inode->i_sb->s_user_ns,
+           !vfsuid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
                                  attr->ia_vfsuid))
                return -EOVERFLOW;
        if (ia_valid & ATTR_GID &&
-           !vfsgid_has_fsmapping(mnt_userns, inode->i_sb->s_user_ns,
+           !vfsgid_has_fsmapping(idmap, inode->i_sb->s_user_ns,
                                  attr->ia_vfsgid))
                return -EOVERFLOW;
 
 
 int fat_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
                struct iattr *attr)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct msdos_sb_info *sbi = MSDOS_SB(dentry->d_sb);
        struct inode *inode = d_inode(dentry);
        unsigned int ia_valid;
        }
 
        if (((attr->ia_valid & ATTR_UID) &&
-            (!uid_eq(from_vfsuid(mnt_userns, i_user_ns(inode), attr->ia_vfsuid),
+            (!uid_eq(from_vfsuid(idmap, i_user_ns(inode), attr->ia_vfsuid),
                      sbi->options.fs_uid))) ||
            ((attr->ia_valid & ATTR_GID) &&
-            (!gid_eq(from_vfsgid(mnt_userns, i_user_ns(inode), attr->ia_vfsgid),
+            (!gid_eq(from_vfsgid(idmap, i_user_ns(inode), attr->ia_vfsgid),
                      sbi->options.fs_gid))) ||
            ((attr->ia_valid & ATTR_MODE) &&
             (attr->ia_mode & ~FAT_VALID_MODE)))
 
        struct ksmbd_file *fp = NULL;
        struct file *filp = NULL;
        struct mnt_idmap *idmap = NULL;
-       struct user_namespace *user_ns = NULL;
        struct kstat stat;
        struct create_context *context;
        struct lease_ctx_info *lc = NULL;
        } else {
                file_present = true;
                idmap = mnt_idmap(path.mnt);
-               user_ns = mnt_idmap_owner(idmap);
        }
        if (stream_name) {
                if (req->CreateOptions & FILE_DIRECTORY_FILE_LE) {
 
                created = true;
                idmap = mnt_idmap(path.mnt);
-               user_ns = mnt_idmap_owner(idmap);
                if (ea_buf) {
                        if (le32_to_cpu(ea_buf->ccontext.DataLength) <
                            sizeof(struct smb2_ea_info)) {
                                        if (!pntsd)
                                                goto err_out;
 
-                                       rc = build_sec_desc(user_ns,
+                                       rc = build_sec_desc(idmap,
                                                            pntsd, NULL, 0,
                                                            OWNER_SECINFO |
                                                            GROUP_SECINFO |
 {
        struct ksmbd_file *fp;
        struct mnt_idmap *idmap;
-       struct user_namespace *user_ns;
        struct smb_ntsd *pntsd = (struct smb_ntsd *)rsp->Buffer, *ppntsd = NULL;
        struct smb_fattr fattr = {{0}};
        struct inode *inode;
                return -ENOENT;
 
        idmap = file_mnt_idmap(fp->filp);
-       user_ns = mnt_idmap_owner(idmap);
        inode = file_inode(fp->filp);
        ksmbd_acls_fattr(&fattr, idmap, inode);
 
 
        /* Check if sd buffer size exceeds response buffer size */
        if (smb2_resp_buf_len(work, 8) > ppntsd_size)
-               rc = build_sec_desc(user_ns, pntsd, ppntsd, ppntsd_size,
+               rc = build_sec_desc(idmap, pntsd, ppntsd, ppntsd_size,
                                    addition_info, &secdesclen, &fattr);
        posix_acl_release(fattr.cf_acls);
        posix_acl_release(fattr.cf_dacls);
 
        ssid->num_subauth++;
 }
 
-static int sid_to_id(struct user_namespace *user_ns,
+static int sid_to_id(struct mnt_idmap *idmap,
                     struct smb_sid *psid, uint sidtype,
                     struct smb_fattr *fattr)
 {
 
                id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
                uid = KUIDT_INIT(id);
-               uid = from_vfsuid(user_ns, &init_user_ns, VFSUIDT_INIT(uid));
+               uid = from_vfsuid(idmap, &init_user_ns, VFSUIDT_INIT(uid));
                if (uid_valid(uid)) {
                        fattr->cf_uid = uid;
                        rc = 0;
 
                id = le32_to_cpu(psid->sub_auth[psid->num_subauth - 1]);
                gid = KGIDT_INIT(id);
-               gid = from_vfsgid(user_ns, &init_user_ns, VFSGIDT_INIT(gid));
+               gid = from_vfsgid(idmap, &init_user_ns, VFSGIDT_INIT(gid));
                if (gid_valid(gid)) {
                        fattr->cf_gid = gid;
                        rc = 0;
        kfree(state->groups);
 }
 
-static void parse_dacl(struct user_namespace *user_ns,
+static void parse_dacl(struct mnt_idmap *idmap,
                       struct smb_acl *pdacl, char *end_of_acl,
                       struct smb_sid *pownersid, struct smb_sid *pgrpsid,
                       struct smb_fattr *fattr)
                        acl_mode = access_flags_to_mode(fattr, ppace[i]->access_req,
                                                        ppace[i]->type);
                        temp_fattr.cf_uid = INVALID_UID;
-                       ret = sid_to_id(user_ns, &ppace[i]->sid, SIDOWNER, &temp_fattr);
+                       ret = sid_to_id(idmap, &ppace[i]->sid, SIDOWNER, &temp_fattr);
                        if (ret || uid_eq(temp_fattr.cf_uid, INVALID_UID)) {
                                pr_err("%s: Error %d mapping Owner SID to uid\n",
                                       __func__, ret);
        free_acl_state(&default_acl_state);
 }
 
-static void set_posix_acl_entries_dacl(struct user_namespace *user_ns,
+static void set_posix_acl_entries_dacl(struct mnt_idmap *idmap,
                                       struct smb_ace *pndace,
                                       struct smb_fattr *fattr, u32 *num_aces,
                                       u16 *size, u32 nt_aces_num)
                        uid_t uid;
                        unsigned int sid_type = SIDOWNER;
 
-                       uid = posix_acl_uid_translate(user_ns, pace);
+                       uid = posix_acl_uid_translate(idmap, pace);
                        if (!uid)
                                sid_type = SIDUNIX_USER;
                        id_to_sid(uid, sid_type, sid);
                } else if (pace->e_tag == ACL_GROUP) {
                        gid_t gid;
 
-                       gid = posix_acl_gid_translate(user_ns, pace);
+                       gid = posix_acl_gid_translate(idmap, pace);
                        id_to_sid(gid, SIDUNIX_GROUP, sid);
                } else if (pace->e_tag == ACL_OTHER && !nt_aces_num) {
                        smb_copy_sid(sid, &sid_everyone);
                if (pace->e_tag == ACL_USER) {
                        uid_t uid;
 
-                       uid = posix_acl_uid_translate(user_ns, pace);
+                       uid = posix_acl_uid_translate(idmap, pace);
                        id_to_sid(uid, SIDCREATOR_OWNER, sid);
                } else if (pace->e_tag == ACL_GROUP) {
                        gid_t gid;
 
-                       gid = posix_acl_gid_translate(user_ns, pace);
+                       gid = posix_acl_gid_translate(idmap, pace);
                        id_to_sid(gid, SIDCREATOR_GROUP, sid);
                } else {
                        kfree(sid);
        }
 }
 
-static void set_ntacl_dacl(struct user_namespace *user_ns,
+static void set_ntacl_dacl(struct mnt_idmap *idmap,
                           struct smb_acl *pndacl,
                           struct smb_acl *nt_dacl,
                           unsigned int aces_size,
                }
        }
 
-       set_posix_acl_entries_dacl(user_ns, pndace, fattr,
+       set_posix_acl_entries_dacl(idmap, pndace, fattr,
                                   &num_aces, &size, nt_num_aces);
        pndacl->num_aces = cpu_to_le32(num_aces);
        pndacl->size = cpu_to_le16(le16_to_cpu(pndacl->size) + size);
 }
 
-static void set_mode_dacl(struct user_namespace *user_ns,
+static void set_mode_dacl(struct mnt_idmap *idmap,
                          struct smb_acl *pndacl, struct smb_fattr *fattr)
 {
        struct smb_ace *pace, *pndace;
        pace = pndace = (struct smb_ace *)((char *)pndacl + sizeof(struct smb_acl));
 
        if (fattr->cf_acls) {
-               set_posix_acl_entries_dacl(user_ns, pndace, fattr,
+               set_posix_acl_entries_dacl(idmap, pndace, fattr,
                                           &num_aces, &size, num_aces);
                goto out;
        }
 }
 
 /* Convert CIFS ACL to POSIX form */
-int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
+int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
                   int acl_len, struct smb_fattr *fattr)
 {
        int rc = 0;
                        return rc;
                }
 
-               rc = sid_to_id(user_ns, owner_sid_ptr, SIDOWNER, fattr);
+               rc = sid_to_id(idmap, owner_sid_ptr, SIDOWNER, fattr);
                if (rc) {
                        pr_err("%s: Error %d mapping Owner SID to uid\n",
                               __func__, rc);
                               __func__, rc);
                        return rc;
                }
-               rc = sid_to_id(user_ns, group_sid_ptr, SIDUNIX_GROUP, fattr);
+               rc = sid_to_id(idmap, group_sid_ptr, SIDUNIX_GROUP, fattr);
                if (rc) {
                        pr_err("%s: Error %d mapping Group SID to gid\n",
                               __func__, rc);
                pntsd->type |= cpu_to_le16(DACL_PROTECTED);
 
        if (dacloffset) {
-               parse_dacl(user_ns, dacl_ptr, end_of_acl,
+               parse_dacl(idmap, dacl_ptr, end_of_acl,
                           owner_sid_ptr, group_sid_ptr, fattr);
        }
 
 }
 
 /* Convert permission bits from mode to equivalent CIFS ACL */
-int build_sec_desc(struct user_namespace *user_ns,
+int build_sec_desc(struct mnt_idmap *idmap,
                   struct smb_ntsd *pntsd, struct smb_ntsd *ppntsd,
                   int ppntsd_size, int addition_info, __u32 *secdesclen,
                   struct smb_fattr *fattr)
                dacl_ptr->num_aces = 0;
 
                if (!ppntsd) {
-                       set_mode_dacl(user_ns, dacl_ptr, fattr);
+                       set_mode_dacl(idmap, dacl_ptr, fattr);
                } else {
                        struct smb_acl *ppdacl_ptr;
                        unsigned int dacl_offset = le32_to_cpu(ppntsd->dacloffset);
                            ppdacl_size < sizeof(struct smb_acl))
                                goto out;
 
-                       set_ntacl_dacl(user_ns, dacl_ptr, ppdacl_ptr,
+                       set_ntacl_dacl(idmap, dacl_ptr, ppdacl_ptr,
                                       ntacl_size - sizeof(struct smb_acl),
                                       nowner_sid_ptr, ngroup_sid_ptr,
                                       fattr);
                        __le32 *pdaccess, int uid)
 {
        struct mnt_idmap *idmap = mnt_idmap(path->mnt);
-       struct user_namespace *user_ns = mnt_idmap_owner(idmap);
        struct smb_ntsd *pntsd = NULL;
        struct smb_acl *pdacl;
        struct posix_acl *posix_acls;
                        pa_entry = posix_acls->a_entries;
                        for (i = 0; i < posix_acls->a_count; i++, pa_entry++) {
                                if (pa_entry->e_tag == ACL_USER)
-                                       id = posix_acl_uid_translate(user_ns, pa_entry);
+                                       id = posix_acl_uid_translate(idmap, pa_entry);
                                else if (pa_entry->e_tag == ACL_GROUP)
-                                       id = posix_acl_gid_translate(user_ns, pa_entry);
+                                       id = posix_acl_gid_translate(idmap, pa_entry);
                                else
                                        continue;
 
        struct smb_fattr fattr = {{0}};
        struct inode *inode = d_inode(path->dentry);
        struct mnt_idmap *idmap = mnt_idmap(path->mnt);
-       struct user_namespace *user_ns = mnt_idmap_owner(idmap);
        struct iattr newattrs;
 
        fattr.cf_uid = INVALID_UID;
        fattr.cf_gid = INVALID_GID;
        fattr.cf_mode = inode->i_mode;
 
-       rc = parse_sec_desc(user_ns, pntsd, ntsd_len, &fattr);
+       rc = parse_sec_desc(idmap, pntsd, ntsd_len, &fattr);
        if (rc)
                goto out;
 
 
        struct posix_ace_state_array *groups;
 };
 
-int parse_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
+int parse_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
                   int acl_len, struct smb_fattr *fattr);
-int build_sec_desc(struct user_namespace *user_ns, struct smb_ntsd *pntsd,
+int build_sec_desc(struct mnt_idmap *idmap, struct smb_ntsd *pntsd,
                   struct smb_ntsd *ppntsd, int ppntsd_size, int addition_info,
                   __u32 *secdesclen, struct smb_fattr *fattr);
 int init_acl_state(struct posix_acl_state *state, int cnt);
 void id_to_sid(unsigned int cid, uint sidtype, struct smb_sid *ssid);
 void ksmbd_init_domain(u32 *sub_auth);
 
-static inline uid_t posix_acl_uid_translate(struct user_namespace *mnt_userns,
+static inline uid_t posix_acl_uid_translate(struct mnt_idmap *idmap,
                                            struct posix_acl_entry *pace)
 {
        vfsuid_t vfsuid;
 
        /* If this is an idmapped mount, apply the idmapping. */
-       vfsuid = make_vfsuid(mnt_userns, &init_user_ns, pace->e_uid);
+       vfsuid = make_vfsuid(idmap, &init_user_ns, pace->e_uid);
 
        /* Translate the kuid into a userspace id ksmbd would see. */
        return from_kuid(&init_user_ns, vfsuid_into_kuid(vfsuid));
 }
 
-static inline gid_t posix_acl_gid_translate(struct user_namespace *mnt_userns,
+static inline gid_t posix_acl_gid_translate(struct mnt_idmap *idmap,
                                            struct posix_acl_entry *pace)
 {
        vfsgid_t vfsgid;
 
        /* If this is an idmapped mount, apply the idmapping. */
-       vfsgid = make_vfsgid(mnt_userns, &init_user_ns, pace->e_gid);
+       vfsgid = make_vfsgid(idmap, &init_user_ns, pace->e_gid);
 
        /* Translate the kgid into a userspace id ksmbd would see. */
        return from_kgid(&init_user_ns, vfsgid_into_kgid(vfsgid));
 
        return err;
 }
 
-static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(struct user_namespace *user_ns,
+static struct xattr_smb_acl *ksmbd_vfs_make_xattr_posix_acl(struct mnt_idmap *idmap,
                                                            struct inode *inode,
                                                            int acl_type)
 {
                switch (pa_entry->e_tag) {
                case ACL_USER:
                        xa_entry->type = SMB_ACL_USER;
-                       xa_entry->uid = posix_acl_uid_translate(user_ns, pa_entry);
+                       xa_entry->uid = posix_acl_uid_translate(idmap, pa_entry);
                        break;
                case ACL_USER_OBJ:
                        xa_entry->type = SMB_ACL_USER_OBJ;
                        break;
                case ACL_GROUP:
                        xa_entry->type = SMB_ACL_GROUP;
-                       xa_entry->gid = posix_acl_gid_translate(user_ns, pa_entry);
+                       xa_entry->gid = posix_acl_gid_translate(idmap, pa_entry);
                        break;
                case ACL_GROUP_OBJ:
                        xa_entry->type = SMB_ACL_GROUP_OBJ;
                           struct smb_ntsd *pntsd, int len)
 {
        int rc;
-       struct user_namespace *user_ns = mnt_idmap_owner(idmap);
        struct ndr sd_ndr = {0}, acl_ndr = {0};
        struct xattr_ntacl acl = {0};
        struct xattr_smb_acl *smb_acl, *def_smb_acl = NULL;
                return rc;
        }
 
-       smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
+       smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
                                                 ACL_TYPE_ACCESS);
        if (S_ISDIR(inode->i_mode))
-               def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
+               def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
                                                             ACL_TYPE_DEFAULT);
 
        rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode,
                           struct smb_ntsd **pntsd)
 {
        int rc;
-       struct user_namespace *user_ns = mnt_idmap_owner(idmap);
        struct ndr n;
        struct inode *inode = d_inode(dentry);
        struct ndr acl_ndr = {0};
        if (rc)
                goto free_n_data;
 
-       smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
+       smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
                                                 ACL_TYPE_ACCESS);
        if (S_ISDIR(inode->i_mode))
-               def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(user_ns, inode,
+               def_smb_acl = ksmbd_vfs_make_xattr_posix_acl(idmap, inode,
                                                             ACL_TYPE_DEFAULT);
 
        rc = ndr_encode_posix_acl(&acl_ndr, idmap, inode, smb_acl,
 
 int chown_common(const struct path *path, uid_t user, gid_t group)
 {
        struct mnt_idmap *idmap;
-       struct user_namespace *mnt_userns, *fs_userns;
+       struct user_namespace *fs_userns;
        struct inode *inode = path->dentry->d_inode;
        struct inode *delegated_inode = NULL;
        int error;
        gid = make_kgid(current_user_ns(), group);
 
        idmap = mnt_idmap(path->mnt);
-       mnt_userns = mnt_idmap_owner(idmap);
        fs_userns = i_user_ns(inode);
 
 retry_deleg:
        /* Continue to send actual fs values, not the mount values. */
        error = security_path_chown(
                path,
-               from_vfsuid(mnt_userns, fs_userns, newattrs.ia_vfsuid),
-               from_vfsgid(mnt_userns, fs_userns, newattrs.ia_vfsgid));
+               from_vfsuid(idmap, fs_userns, newattrs.ia_vfsuid),
+               from_vfsgid(idmap, fs_userns, newattrs.ia_vfsgid));
        if (!error)
                error = notify_change(idmap, path->dentry, &newattrs,
                                      &delegated_inode);
 
  * alter the POSIX ACLs for the underlying filesystem.
  */
 static void ovl_idmap_posix_acl(const struct inode *realinode,
-                               struct user_namespace *mnt_userns,
+                               struct mnt_idmap *idmap,
                                struct posix_acl *acl)
 {
        struct user_namespace *fs_userns = i_user_ns(realinode);
                struct posix_acl_entry *e = &acl->a_entries[i];
                switch (e->e_tag) {
                case ACL_USER:
-                       vfsuid = make_vfsuid(mnt_userns, fs_userns, e->e_uid);
+                       vfsuid = make_vfsuid(idmap, fs_userns, e->e_uid);
                        e->e_uid = vfsuid_into_kuid(vfsuid);
                        break;
                case ACL_GROUP:
-                       vfsgid = make_vfsgid(mnt_userns, fs_userns, e->e_gid);
+                       vfsgid = make_vfsgid(idmap, fs_userns, e->e_gid);
                        e->e_gid = vfsgid_into_kgid(vfsgid);
                        break;
                }
                                   const char *acl_name, bool noperm)
 {
        struct posix_acl *real_acl, *clone;
-       struct user_namespace *mnt_userns;
        struct mnt_idmap *idmap;
        struct inode *realinode = d_inode(path->dentry);
 
        idmap = mnt_idmap(path->mnt);
-       mnt_userns = mnt_idmap_owner(idmap);
 
        if (noperm)
                real_acl = get_inode_acl(realinode, posix_acl_type(acl_name));
        if (!clone)
                return ERR_PTR(-ENOMEM);
 
-       ovl_idmap_posix_acl(realinode, mnt_userns, clone);
+       ovl_idmap_posix_acl(realinode, idmap, clone);
        return clone;
 }
 
 
 {
        const struct posix_acl_entry *pa, *pe, *mask_obj;
        struct user_namespace *fs_userns = i_user_ns(inode);
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        int found = 0;
        vfsuid_t vfsuid;
        vfsgid_t vfsgid;
                                         goto check_perm;
                                 break;
                         case ACL_USER:
-                               vfsuid = make_vfsuid(mnt_userns, fs_userns,
+                               vfsuid = make_vfsuid(idmap, fs_userns,
                                                     pa->e_uid);
                                if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
                                         goto mask;
                                 }
                                break;
                         case ACL_GROUP:
-                               vfsgid = make_vfsgid(mnt_userns, fs_userns,
+                               vfsgid = make_vfsgid(idmap, fs_userns,
                                                     pa->e_gid);
                                if (vfsgid_in_group_p(vfsgid)) {
                                        found = 1;
        struct posix_acl_xattr_header *ext_acl = buffer;
        struct posix_acl_xattr_entry *ext_entry;
        struct user_namespace *fs_userns, *caller_userns;
-       struct user_namespace *mnt_userns;
        ssize_t real_size, n;
        vfsuid_t vfsuid;
        vfsgid_t vfsgid;
 
        fs_userns = i_user_ns(inode);
        caller_userns = current_user_ns();
-       mnt_userns = mnt_idmap_owner(idmap);
        for (n=0; n < acl->a_count; n++, ext_entry++) {
                const struct posix_acl_entry *acl_e = &acl->a_entries[n];
                ext_entry->e_tag  = cpu_to_le16(acl_e->e_tag);
                ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
                switch(acl_e->e_tag) {
                case ACL_USER:
-                       vfsuid = make_vfsuid(mnt_userns, fs_userns, acl_e->e_uid);
+                       vfsuid = make_vfsuid(idmap, fs_userns, acl_e->e_uid);
                        ext_entry->e_id = cpu_to_le32(from_kuid(
                                caller_userns, vfsuid_into_kuid(vfsuid)));
                        break;
                case ACL_GROUP:
-                       vfsgid = make_vfsgid(mnt_userns, fs_userns, acl_e->e_gid);
+                       vfsgid = make_vfsgid(idmap, fs_userns, acl_e->e_gid);
                        ext_entry->e_id = cpu_to_le32(from_kgid(
                                caller_userns, vfsgid_into_kgid(vfsgid)));
                        break;
                                    struct user_namespace *fs_userns,
                                    struct posix_acl *acl)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-
        for (int n = 0; n < acl->a_count; n++) {
                struct posix_acl_entry *acl_e = &acl->a_entries[n];
 
                switch (acl_e->e_tag) {
                case ACL_USER:
-                       acl_e->e_uid = from_vfsuid(mnt_userns, fs_userns,
+                       acl_e->e_uid = from_vfsuid(idmap, fs_userns,
                                                   VFSUIDT_INIT(acl_e->e_uid));
                        break;
                case ACL_GROUP:
-                       acl_e->e_gid = from_vfsgid(mnt_userns, fs_userns,
+                       acl_e->e_gid = from_vfsgid(idmap, fs_userns,
                                                   VFSGIDT_INIT(acl_e->e_gid));
                        break;
                }
 
 int dquot_transfer(struct mnt_idmap *idmap, struct inode *inode,
                   struct iattr *iattr)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        struct dquot *transfer_to[MAXQUOTAS] = {};
        struct dquot *dquot;
        struct super_block *sb = inode->i_sb;
                return 0;
 
        if (i_uid_needs_update(idmap, iattr, inode)) {
-               kuid_t kuid = from_vfsuid(mnt_userns, i_user_ns(inode),
+               kuid_t kuid = from_vfsuid(idmap, i_user_ns(inode),
                                          iattr->ia_vfsuid);
 
                dquot = dqget(sb, make_kqid_uid(kuid));
                transfer_to[USRQUOTA] = dquot;
        }
        if (i_gid_needs_update(idmap, iattr, inode)) {
-               kgid_t kgid = from_vfsgid(mnt_userns, i_user_ns(inode),
+               kgid_t kgid = from_vfsgid(idmap, i_user_ns(inode),
                                          iattr->ia_vfsgid);
 
                dquot = dqget(sb, make_kqid_gid(kgid));
 
        kgid_t                  gid = GLOBAL_ROOT_GID;
        struct xfs_dquot        *udqp = NULL, *gdqp = NULL;
        struct xfs_dquot        *old_udqp = NULL, *old_gdqp = NULL;
-       struct user_namespace   *mnt_userns = mnt_idmap_owner(idmap);
 
        ASSERT((mask & ATTR_SIZE) == 0);
 
                uint    qflags = 0;
 
                if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
-                       uid = from_vfsuid(mnt_userns, i_user_ns(inode),
+                       uid = from_vfsuid(idmap, i_user_ns(inode),
                                          iattr->ia_vfsuid);
                        qflags |= XFS_QMOPT_UQUOTA;
                } else {
                        uid = inode->i_uid;
                }
                if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
-                       gid = from_vfsgid(mnt_userns, i_user_ns(inode),
+                       gid = from_vfsgid(idmap, i_user_ns(inode),
                                          iattr->ia_vfsgid);
                        qflags |= XFS_QMOPT_GQUOTA;
                }  else {
 
 static inline vfsuid_t i_uid_into_vfsuid(struct mnt_idmap *idmap,
                                         const struct inode *inode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-       return make_vfsuid(mnt_userns, i_user_ns(inode), inode->i_uid);
+       return make_vfsuid(idmap, i_user_ns(inode), inode->i_uid);
 }
 
 /**
                                const struct iattr *attr,
                                struct inode *inode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-
        if (attr->ia_valid & ATTR_UID)
-               inode->i_uid = from_vfsuid(mnt_userns, i_user_ns(inode),
+               inode->i_uid = from_vfsuid(idmap, i_user_ns(inode),
                                           attr->ia_vfsuid);
 }
 
 static inline vfsgid_t i_gid_into_vfsgid(struct mnt_idmap *idmap,
                                         const struct inode *inode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-       return make_vfsgid(mnt_userns, i_user_ns(inode), inode->i_gid);
+       return make_vfsgid(idmap, i_user_ns(inode), inode->i_gid);
 }
 
 /**
                                const struct iattr *attr,
                                struct inode *inode)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-
        if (attr->ia_valid & ATTR_GID)
-               inode->i_gid = from_vfsgid(mnt_userns, i_user_ns(inode),
+               inode->i_gid = from_vfsgid(idmap, i_user_ns(inode),
                                           attr->ia_vfsgid);
 }
 
 
 
 /**
  * make_vfsuid - map a filesystem kuid into a mnt_userns
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @kuid : kuid to be mapped
  *
  * returned.
  */
 
-static inline vfsuid_t make_vfsuid(struct user_namespace *mnt_userns,
+static inline vfsuid_t make_vfsuid(struct mnt_idmap *idmap,
                                   struct user_namespace *fs_userns,
                                   kuid_t kuid)
 {
        uid_t uid;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (no_idmapping(mnt_userns, fs_userns))
                return VFSUIDT_INIT(kuid);
 
 /**
  * make_vfsgid - map a filesystem kgid into a mnt_userns
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @kgid : kgid to be mapped
  *
  * returned.
  */
 
-static inline vfsgid_t make_vfsgid(struct user_namespace *mnt_userns,
+static inline vfsgid_t make_vfsgid(struct mnt_idmap *idmap,
                                   struct user_namespace *fs_userns,
                                   kgid_t kgid)
 {
        gid_t gid;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (no_idmapping(mnt_userns, fs_userns))
                return VFSGIDT_INIT(kgid);
 
 /**
  * from_vfsuid - map a vfsuid into the filesystem idmapping
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @vfsuid : vfsuid to be mapped
  *
  *
  * Return: @vfsuid mapped into the filesystem idmapping
  */
-static inline kuid_t from_vfsuid(struct user_namespace *mnt_userns,
+static inline kuid_t from_vfsuid(struct mnt_idmap *idmap,
                                 struct user_namespace *fs_userns,
                                 vfsuid_t vfsuid)
 {
        uid_t uid;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (no_idmapping(mnt_userns, fs_userns))
                return AS_KUIDT(vfsuid);
 
 /**
  * vfsuid_has_fsmapping - check whether a vfsuid maps into the filesystem
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @vfsuid: vfsuid to be mapped
  *
  *
  * Return: true if @vfsuid has a mapping in the filesystem, false if not.
  */
-static inline bool vfsuid_has_fsmapping(struct user_namespace *mnt_userns,
+static inline bool vfsuid_has_fsmapping(struct mnt_idmap *idmap,
                                        struct user_namespace *fs_userns,
                                        vfsuid_t vfsuid)
 {
-       return uid_valid(from_vfsuid(mnt_userns, fs_userns, vfsuid));
+       return uid_valid(from_vfsuid(idmap, fs_userns, vfsuid));
 }
 
 static inline bool vfsuid_has_mapping(struct user_namespace *userns,
 
 /**
  * from_vfsgid - map a vfsgid into the filesystem idmapping
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @vfsgid : vfsgid to be mapped
  *
  *
  * Return: @vfsgid mapped into the filesystem idmapping
  */
-static inline kgid_t from_vfsgid(struct user_namespace *mnt_userns,
+static inline kgid_t from_vfsgid(struct mnt_idmap *idmap,
                                 struct user_namespace *fs_userns,
                                 vfsgid_t vfsgid)
 {
        gid_t gid;
+       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (no_idmapping(mnt_userns, fs_userns))
                return AS_KGIDT(vfsgid);
 
 /**
  * vfsgid_has_fsmapping - check whether a vfsgid maps into the filesystem
- * @mnt_userns: the mount's idmapping
+ * @idmap: the mount's idmapping
  * @fs_userns: the filesystem's idmapping
  * @vfsgid: vfsgid to be mapped
  *
  *
  * Return: true if @vfsgid has a mapping in the filesystem, false if not.
  */
-static inline bool vfsgid_has_fsmapping(struct user_namespace *mnt_userns,
+static inline bool vfsgid_has_fsmapping(struct mnt_idmap *idmap,
                                        struct user_namespace *fs_userns,
                                        vfsgid_t vfsgid)
 {
-       return gid_valid(from_vfsgid(mnt_userns, fs_userns, vfsgid));
+       return gid_valid(from_vfsgid(idmap, fs_userns, vfsgid));
 }
 
 static inline bool vfsgid_has_mapping(struct user_namespace *userns,
 static inline kuid_t mapped_fsuid(struct mnt_idmap *idmap,
                                  struct user_namespace *fs_userns)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-       return from_vfsuid(mnt_userns, fs_userns,
-                          VFSUIDT_INIT(current_fsuid()));
+       return from_vfsuid(idmap, fs_userns, VFSUIDT_INIT(current_fsuid()));
 }
 
 /**
 static inline kgid_t mapped_fsgid(struct mnt_idmap *idmap,
                                  struct user_namespace *fs_userns)
 {
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
-       return from_vfsgid(mnt_userns, fs_userns,
-                          VFSGIDT_INIT(current_fsgid()));
+       return from_vfsgid(idmap, fs_userns, VFSGIDT_INIT(current_fsgid()));
 }
 
 #endif /* _LINUX_MNT_IDMAPPING_H */
 
        struct vfs_ns_cap_data *nscap = NULL;
        struct dentry *dentry;
        struct user_namespace *fs_ns;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        if (strcmp(name, "capability") != 0)
                return -EOPNOTSUPP;
        kroot = make_kuid(fs_ns, root);
 
        /* If this is an idmapped mount shift the kuid. */
-       vfsroot = make_vfsuid(mnt_userns, fs_ns, kroot);
+       vfsroot = make_vfsuid(idmap, fs_ns, kroot);
 
        /* If the root kuid maps to a valid uid in current ns, then return
         * this as a nscap. */
        struct inode *inode = d_backing_inode(dentry);
        struct user_namespace *task_ns = current_user_ns(),
                *fs_ns = inode->i_sb->s_user_ns;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
        kuid_t rootid;
        vfsuid_t vfsrootid;
        size_t newsize;
        if (!vfsuid_valid(vfsrootid))
                return -EINVAL;
 
-       rootid = from_vfsuid(mnt_userns, fs_ns, vfsrootid);
+       rootid = from_vfsuid(idmap, fs_ns, vfsrootid);
        if (!uid_valid(rootid))
                return -EINVAL;
 
        kuid_t rootkuid;
        vfsuid_t rootvfsuid;
        struct user_namespace *fs_ns;
-       struct user_namespace *mnt_userns = mnt_idmap_owner(idmap);
 
        memset(cpu_caps, 0, sizeof(struct cpu_vfs_cap_data));
 
                return -EINVAL;
        }
 
-       rootvfsuid = make_vfsuid(mnt_userns, fs_ns, rootkuid);
+       rootvfsuid = make_vfsuid(idmap, fs_ns, rootkuid);
        if (!vfsuid_valid(rootvfsuid))
                return -ENODATA;