]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blobdiff - fs/open.c
hwmon: (occ) Remove sequence numbering and checksum calculation
[mirror_ubuntu-jammy-kernel.git] / fs / open.c
index daa324606a41f8141567cf4395d26458db76a924..a262586974ed8acc4caa27f84c8c7689df74ced5 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -32,6 +32,7 @@
 #include <linux/ima.h>
 #include <linux/dnotify.h>
 #include <linux/compat.h>
+#include <linux/mnt_idmapping.h>
 
 #include "internal.h"
 
@@ -65,6 +66,7 @@ int do_truncate(struct user_namespace *mnt_userns, struct dentry *dentry,
        inode_unlock(dentry->d_inode);
        return ret;
 }
+EXPORT_SYMBOL_GPL(do_truncate);
 
 long vfs_truncate(const struct path *path, loff_t length)
 {
@@ -640,7 +642,7 @@ SYSCALL_DEFINE2(chmod, const char __user *, filename, umode_t, mode)
 
 int chown_common(const struct path *path, uid_t user, gid_t group)
 {
-       struct user_namespace *mnt_userns;
+       struct user_namespace *mnt_userns, *fs_userns;
        struct inode *inode = path->dentry->d_inode;
        struct inode *delegated_inode = NULL;
        int error;
@@ -652,8 +654,9 @@ int chown_common(const struct path *path, uid_t user, gid_t group)
        gid = make_kgid(current_user_ns(), group);
 
        mnt_userns = mnt_user_ns(path->mnt);
-       uid = kuid_from_mnt(mnt_userns, uid);
-       gid = kgid_from_mnt(mnt_userns, gid);
+       fs_userns = i_user_ns(inode);
+       uid = mapped_kuid_user(mnt_userns, fs_userns, uid);
+       gid = mapped_kgid_user(mnt_userns, fs_userns, gid);
 
 retry_deleg:
        newattrs.ia_valid =  ATTR_CTIME;
@@ -856,8 +859,20 @@ static int do_dentry_open(struct file *f,
                 * of THPs into the page cache will fail.
                 */
                smp_mb();
-               if (filemap_nr_thps(inode->i_mapping))
-                       truncate_pagecache(inode, 0);
+               if (filemap_nr_thps(inode->i_mapping)) {
+                       struct address_space *mapping = inode->i_mapping;
+
+                       filemap_invalidate_lock(inode->i_mapping);
+                       /*
+                        * unmap_mapping_range just need to be called once
+                        * here, because the private pages is not need to be
+                        * unmapped mapping (e.g. data segment of dynamic
+                        * shared libraries here).
+                        */
+                       unmap_mapping_range(mapping, 0, 0, 0);
+                       truncate_inode_pages(mapping, 0);
+                       filemap_invalidate_unlock(inode->i_mapping);
+               }
        }
 
        return 0;