Merge tag 'v5.7-rc7' into perf/core, to pick up fixes
[linux-2.6-microblaze.git] / fs / cifs / file.c
index 5920820..75ddce8 100644 (file)
@@ -4060,7 +4060,7 @@ cifs_read(struct file *file, char *read_data, size_t read_size, loff_t *offset)
                         * than it negotiated since it will refuse the read
                         * then.
                         */
-                       if ((tcon->ses) && !(tcon->ses->capabilities &
+                       if (!(tcon->ses->capabilities &
                                tcon->ses->server->vals->cap_large_files)) {
                                current_read_size = min_t(uint,
                                        current_read_size, CIFSMaxBufSize);
@@ -4808,6 +4808,60 @@ cifs_direct_io(struct kiocb *iocb, struct iov_iter *iter)
         return -EINVAL;
 }
 
+static int cifs_swap_activate(struct swap_info_struct *sis,
+                             struct file *swap_file, sector_t *span)
+{
+       struct cifsFileInfo *cfile = swap_file->private_data;
+       struct inode *inode = swap_file->f_mapping->host;
+       unsigned long blocks;
+       long long isize;
+
+       cifs_dbg(FYI, "swap activate\n");
+
+       spin_lock(&inode->i_lock);
+       blocks = inode->i_blocks;
+       isize = inode->i_size;
+       spin_unlock(&inode->i_lock);
+       if (blocks*512 < isize) {
+               pr_warn("swap activate: swapfile has holes\n");
+               return -EINVAL;
+       }
+       *span = sis->pages;
+
+       printk_once(KERN_WARNING "Swap support over SMB3 is experimental\n");
+
+       /*
+        * TODO: consider adding ACL (or documenting how) to prevent other
+        * users (on this or other systems) from reading it
+        */
+
+
+       /* TODO: add sk_set_memalloc(inet) or similar */
+
+       if (cfile)
+               cfile->swapfile = true;
+       /*
+        * TODO: Since file already open, we can't open with DENY_ALL here
+        * but we could add call to grab a byte range lock to prevent others
+        * from reading or writing the file
+        */
+
+       return 0;
+}
+
+static void cifs_swap_deactivate(struct file *file)
+{
+       struct cifsFileInfo *cfile = file->private_data;
+
+       cifs_dbg(FYI, "swap deactivate\n");
+
+       /* TODO: undo sk_set_memalloc(inet) will eventually be needed */
+
+       if (cfile)
+               cfile->swapfile = false;
+
+       /* do we need to unpin (or unlock) the file */
+}
 
 const struct address_space_operations cifs_addr_ops = {
        .readpage = cifs_readpage,
@@ -4821,6 +4875,13 @@ const struct address_space_operations cifs_addr_ops = {
        .direct_IO = cifs_direct_io,
        .invalidatepage = cifs_invalidate_page,
        .launder_page = cifs_launder_page,
+       /*
+        * TODO: investigate and if useful we could add an cifs_migratePage
+        * helper (under an CONFIG_MIGRATION) in the future, and also
+        * investigate and add an is_dirty_writeback helper if needed
+        */
+       .swap_activate = cifs_swap_activate,
+       .swap_deactivate = cifs_swap_deactivate,
 };
 
 /*