Skip to content

Commit

Permalink
smb3: reenable swapfiles over SMB3 mounts
Browse files Browse the repository at this point in the history
With the changes to folios/netfs it is now easier to reenable
swapfile support over SMB3 which fixes various xfstests

Reviewed-by: David Howells <dhowells@redhat.com>
Suggested-by: David Howells <dhowells@redhat.com>
Fixes: e1209d3 ("mm: introduce ->swap_rw and use it for reads from SWP_FS_OPS swap-space")
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Steve French committed May 21, 2024
1 parent 0450d20 commit 16e0068
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/netfs/direct_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static void netfs_cleanup_dio_write(struct netfs_io_request *wreq)
* Perform an unbuffered write where we may have to do an RMW operation on an
* encrypted file. This can also be used for direct I/O writes.
*/
static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
struct netfs_group *netfs_group)
{
struct netfs_io_request *wreq;
Expand Down Expand Up @@ -117,6 +117,7 @@ static ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov
netfs_put_request(wreq, false, netfs_rreq_trace_put_return);
return ret;
}
EXPORT_SYMBOL(netfs_unbuffered_write_iter_locked);

/**
* netfs_unbuffered_write_iter - Unbuffered write to a file
Expand Down
23 changes: 23 additions & 0 deletions fs/smb/client/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -3189,6 +3189,28 @@ static void cifs_swap_deactivate(struct file *file)
/* do we need to unpin (or unlock) the file */
}

/**
* cifs_swap_rw - SMB3 address space operation for swap I/O
* @iocb: target I/O control block
* @iter: I/O buffer
*
* Perform IO to the swap-file. This is much like direct IO.
*/
static int cifs_swap_rw(struct kiocb *iocb, struct iov_iter *iter)
{
ssize_t ret;

WARN_ON_ONCE(iov_iter_count(iter) != PAGE_SIZE);

if (iov_iter_rw(iter) == READ)
ret = netfs_unbuffered_read_iter_locked(iocb, iter);
else
ret = netfs_unbuffered_write_iter_locked(iocb, iter, NULL);
if (ret < 0)
return ret;
return 0;
}

const struct address_space_operations cifs_addr_ops = {
.read_folio = netfs_read_folio,
.readahead = netfs_readahead,
Expand All @@ -3204,6 +3226,7 @@ const struct address_space_operations cifs_addr_ops = {
*/
.swap_activate = cifs_swap_activate,
.swap_deactivate = cifs_swap_deactivate,
.swap_rw = cifs_swap_rw,
};

/*
Expand Down
2 changes: 2 additions & 0 deletions include/linux/netfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,8 @@ ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,
ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *from,
struct netfs_group *netfs_group);
ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from);
ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
struct netfs_group *netfs_group);
ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from);

/* Address operations API */
Expand Down

0 comments on commit 16e0068

Please sign in to comment.