Merge tag 'mm-stable-2022-05-25' of git://git.kernel.org/pub/scm/linux/kernel/git...
[sfrench/cifs-2.6.git] / fs / nfs / file.c
index d764b3ce79050bc9014b164b05d174c2011f5d5c..6f5425e89ca6372aceda877ad390af4904eef1af 100644 (file)
@@ -69,6 +69,8 @@ nfs_file_open(struct inode *inode, struct file *filp)
                return res;
 
        res = nfs_open(inode, filp);
+       if (res == 0)
+               filp->f_mode |= FMODE_CAN_ODIRECT;
        return res;
 }
 
@@ -480,6 +482,7 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
 {
        unsigned long blocks;
        long long isize;
+       int ret;
        struct inode *inode = file_inode(file);
        struct rpc_clnt *clnt = NFS_CLIENT(inode);
        struct nfs_client *cl = NFS_SERVER(inode)->nfs_client;
@@ -493,13 +496,22 @@ static int nfs_swap_activate(struct swap_info_struct *sis, struct file *file,
                return -EINVAL;
        }
 
-       *span = sis->pages;
+       ret = rpc_clnt_swap_activate(clnt);
+       if (ret)
+               return ret;
+       ret = add_swap_extent(sis, 0, sis->max, 0);
+       if (ret < 0) {
+               rpc_clnt_swap_deactivate(clnt);
+               return ret;
+       }
 
+       *span = sis->pages;
 
        if (cl->rpc_ops->enable_swap)
                cl->rpc_ops->enable_swap(inode);
 
-       return rpc_clnt_swap_activate(clnt);
+       sis->flags |= SWP_FS_OPS;
+       return ret;
 }
 
 static void nfs_swap_deactivate(struct file *file)
@@ -523,7 +535,6 @@ const struct address_space_operations nfs_file_aops = {
        .write_end = nfs_write_end,
        .invalidate_folio = nfs_invalidate_folio,
        .release_folio = nfs_release_folio,
-       .direct_IO = nfs_direct_IO,
 #ifdef CONFIG_MIGRATION
        .migratepage = nfs_migrate_page,
 #endif
@@ -532,6 +543,7 @@ const struct address_space_operations nfs_file_aops = {
        .error_remove_page = generic_error_remove_page,
        .swap_activate = nfs_swap_activate,
        .swap_deactivate = nfs_swap_deactivate,
+       .swap_rw = nfs_swap_rw,
 };
 
 /*