Commit 966cc171 authored by David Howells's avatar David Howells Committed by Steve French

cifs: Share server EOF pos with netfslib

Use cifsi->netfs_ctx.remote_i_size instead of cifsi->server_eof so that
netfslib can refer to it to.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
cc: Shyam Prasad N <nspmangalore@gmail.com>
cc: Rohith Surabattula <rohiths.msft@gmail.com>
cc: Jeff Layton <jlayton@kernel.org>
cc: linux-cifs@vger.kernel.org
cc: linux-cachefs@redhat.com
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 8deb05c8
...@@ -396,7 +396,7 @@ cifs_alloc_inode(struct super_block *sb) ...@@ -396,7 +396,7 @@ cifs_alloc_inode(struct super_block *sb)
spin_lock_init(&cifs_inode->writers_lock); spin_lock_init(&cifs_inode->writers_lock);
cifs_inode->writers = 0; cifs_inode->writers = 0;
cifs_inode->netfs.inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */ cifs_inode->netfs.inode.i_blkbits = 14; /* 2**14 = CIFS_MAX_MSGSIZE */
cifs_inode->server_eof = 0; cifs_inode->netfs.remote_i_size = 0;
cifs_inode->uniqueid = 0; cifs_inode->uniqueid = 0;
cifs_inode->createtime = 0; cifs_inode->createtime = 0;
cifs_inode->epoch = 0; cifs_inode->epoch = 0;
...@@ -1380,6 +1380,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, ...@@ -1380,6 +1380,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
struct inode *src_inode = file_inode(src_file); struct inode *src_inode = file_inode(src_file);
struct inode *target_inode = file_inode(dst_file); struct inode *target_inode = file_inode(dst_file);
struct cifsInodeInfo *src_cifsi = CIFS_I(src_inode); struct cifsInodeInfo *src_cifsi = CIFS_I(src_inode);
struct cifsInodeInfo *target_cifsi = CIFS_I(target_inode);
struct cifsFileInfo *smb_file_src; struct cifsFileInfo *smb_file_src;
struct cifsFileInfo *smb_file_target; struct cifsFileInfo *smb_file_target;
struct cifs_tcon *src_tcon; struct cifs_tcon *src_tcon;
...@@ -1428,7 +1429,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, ...@@ -1428,7 +1429,7 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
* Advance the EOF marker after the flush above to the end of the range * Advance the EOF marker after the flush above to the end of the range
* if it's short of that. * if it's short of that.
*/ */
if (src_cifsi->server_eof < off + len) { if (src_cifsi->netfs.remote_i_size < off + len) {
rc = cifs_precopy_set_eof(src_inode, src_cifsi, src_tcon, xid, off + len); rc = cifs_precopy_set_eof(src_inode, src_cifsi, src_tcon, xid, off + len);
if (rc < 0) if (rc < 0)
goto unlock; goto unlock;
...@@ -1452,12 +1453,22 @@ ssize_t cifs_file_copychunk_range(unsigned int xid, ...@@ -1452,12 +1453,22 @@ ssize_t cifs_file_copychunk_range(unsigned int xid,
/* Discard all the folios that overlap the destination region. */ /* Discard all the folios that overlap the destination region. */
truncate_inode_pages_range(&target_inode->i_data, fstart, fend); truncate_inode_pages_range(&target_inode->i_data, fstart, fend);
fscache_invalidate(cifs_inode_cookie(target_inode), NULL,
i_size_read(target_inode), 0);
rc = file_modified(dst_file); rc = file_modified(dst_file);
if (!rc) { if (!rc) {
rc = target_tcon->ses->server->ops->copychunk_range(xid, rc = target_tcon->ses->server->ops->copychunk_range(xid,
smb_file_src, smb_file_target, off, len, destoff); smb_file_src, smb_file_target, off, len, destoff);
if (rc > 0 && destoff + rc > i_size_read(target_inode)) if (rc > 0 && destoff + rc > i_size_read(target_inode)) {
truncate_setsize(target_inode, destoff + rc); truncate_setsize(target_inode, destoff + rc);
netfs_resize_file(&target_cifsi->netfs,
i_size_read(target_inode), true);
fscache_resize_cookie(cifs_inode_cookie(target_inode),
i_size_read(target_inode));
}
if (rc > 0 && destoff + rc > target_cifsi->netfs.zero_point)
target_cifsi->netfs.zero_point = destoff + rc;
} }
file_accessed(src_file); file_accessed(src_file);
......
...@@ -1561,7 +1561,6 @@ struct cifsInodeInfo { ...@@ -1561,7 +1561,6 @@ struct cifsInodeInfo {
spinlock_t writers_lock; spinlock_t writers_lock;
unsigned int writers; /* Number of writers on this inode */ unsigned int writers; /* Number of writers on this inode */
unsigned long time; /* jiffies of last update of inode */ unsigned long time; /* jiffies of last update of inode */
u64 server_eof; /* current file size on server -- protected by i_lock */
u64 uniqueid; /* server inode number */ u64 uniqueid; /* server inode number */
u64 createtime; /* creation time on server */ u64 createtime; /* creation time on server */
__u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */ __u8 lease_key[SMB2_LEASE_KEY_SIZE]; /* lease key for this inode */
......
...@@ -2120,8 +2120,8 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset, ...@@ -2120,8 +2120,8 @@ cifs_update_eof(struct cifsInodeInfo *cifsi, loff_t offset,
{ {
loff_t end_of_write = offset + bytes_written; loff_t end_of_write = offset + bytes_written;
if (end_of_write > cifsi->server_eof) if (end_of_write > cifsi->netfs.remote_i_size)
cifsi->server_eof = end_of_write; netfs_resize_file(&cifsi->netfs, end_of_write, true);
} }
static ssize_t static ssize_t
...@@ -3247,8 +3247,8 @@ cifs_uncached_writev_complete(struct work_struct *work) ...@@ -3247,8 +3247,8 @@ cifs_uncached_writev_complete(struct work_struct *work)
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
cifs_update_eof(cifsi, wdata->offset, wdata->bytes); cifs_update_eof(cifsi, wdata->offset, wdata->bytes);
if (cifsi->server_eof > inode->i_size) if (cifsi->netfs.remote_i_size > inode->i_size)
i_size_write(inode, cifsi->server_eof); i_size_write(inode, cifsi->netfs.remote_i_size);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
complete(&wdata->done); complete(&wdata->done);
......
...@@ -104,7 +104,7 @@ cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr) ...@@ -104,7 +104,7 @@ cifs_revalidate_cache(struct inode *inode, struct cifs_fattr *fattr)
fattr->cf_mtime = timestamp_truncate(fattr->cf_mtime, inode); fattr->cf_mtime = timestamp_truncate(fattr->cf_mtime, inode);
mtime = inode_get_mtime(inode); mtime = inode_get_mtime(inode);
if (timespec64_equal(&mtime, &fattr->cf_mtime) && if (timespec64_equal(&mtime, &fattr->cf_mtime) &&
cifs_i->server_eof == fattr->cf_eof) { cifs_i->netfs.remote_i_size == fattr->cf_eof) {
cifs_dbg(FYI, "%s: inode %llu is unchanged\n", cifs_dbg(FYI, "%s: inode %llu is unchanged\n",
__func__, cifs_i->uniqueid); __func__, cifs_i->uniqueid);
return; return;
...@@ -194,7 +194,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr) ...@@ -194,7 +194,7 @@ cifs_fattr_to_inode(struct inode *inode, struct cifs_fattr *fattr)
else else
clear_bit(CIFS_INO_DELETE_PENDING, &cifs_i->flags); clear_bit(CIFS_INO_DELETE_PENDING, &cifs_i->flags);
cifs_i->server_eof = fattr->cf_eof; cifs_i->netfs.remote_i_size = fattr->cf_eof;
/* /*
* Can't safely change the file size here if the client is writing to * Can't safely change the file size here if the client is writing to
* it due to potential races. * it due to potential races.
...@@ -2858,7 +2858,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs, ...@@ -2858,7 +2858,7 @@ cifs_set_file_size(struct inode *inode, struct iattr *attrs,
set_size_out: set_size_out:
if (rc == 0) { if (rc == 0) {
cifsInode->server_eof = attrs->ia_size; netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
cifs_setsize(inode, attrs->ia_size); cifs_setsize(inode, attrs->ia_size);
/* /*
* i_blocks is not related to (i_size / i_blksize), but instead * i_blocks is not related to (i_size / i_blksize), but instead
...@@ -3011,6 +3011,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs) ...@@ -3011,6 +3011,7 @@ cifs_setattr_unix(struct dentry *direntry, struct iattr *attrs)
if ((attrs->ia_valid & ATTR_SIZE) && if ((attrs->ia_valid & ATTR_SIZE) &&
attrs->ia_size != i_size_read(inode)) { attrs->ia_size != i_size_read(inode)) {
truncate_setsize(inode, attrs->ia_size); truncate_setsize(inode, attrs->ia_size);
netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size); fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size);
} }
...@@ -3210,6 +3211,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs) ...@@ -3210,6 +3211,7 @@ cifs_setattr_nounix(struct dentry *direntry, struct iattr *attrs)
if ((attrs->ia_valid & ATTR_SIZE) && if ((attrs->ia_valid & ATTR_SIZE) &&
attrs->ia_size != i_size_read(inode)) { attrs->ia_size != i_size_read(inode)) {
truncate_setsize(inode, attrs->ia_size); truncate_setsize(inode, attrs->ia_size);
netfs_resize_file(&cifsInode->netfs, attrs->ia_size, true);
fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size); fscache_resize_cookie(cifs_inode_cookie(inode), attrs->ia_size);
} }
......
...@@ -141,7 +141,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name, ...@@ -141,7 +141,7 @@ cifs_prime_dcache(struct dentry *parent, struct qstr *name,
if (likely(reparse_inode_match(inode, fattr))) { if (likely(reparse_inode_match(inode, fattr))) {
fattr->cf_mode = inode->i_mode; fattr->cf_mode = inode->i_mode;
fattr->cf_rdev = inode->i_rdev; fattr->cf_rdev = inode->i_rdev;
fattr->cf_eof = CIFS_I(inode)->server_eof; fattr->cf_eof = CIFS_I(inode)->netfs.remote_i_size;
fattr->cf_symlink_target = NULL; fattr->cf_symlink_target = NULL;
} else { } else {
CIFS_I(inode)->time = 0; CIFS_I(inode)->time = 0;
......
...@@ -3213,6 +3213,9 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3213,6 +3213,9 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
cfile->fid.volatile_fid, cfile->pid, new_size); cfile->fid.volatile_fid, cfile->pid, new_size);
if (rc >= 0) { if (rc >= 0) {
truncate_setsize(inode, new_size); truncate_setsize(inode, new_size);
netfs_resize_file(&cifsi->netfs, new_size, true);
if (offset < cifsi->netfs.zero_point)
cifsi->netfs.zero_point = offset;
fscache_resize_cookie(cifs_inode_cookie(inode), new_size); fscache_resize_cookie(cifs_inode_cookie(inode), new_size);
} }
} }
...@@ -3436,7 +3439,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon, ...@@ -3436,7 +3439,7 @@ static long smb3_simple_falloc(struct file *file, struct cifs_tcon *tcon,
rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid,
cfile->fid.volatile_fid, cfile->pid, new_eof); cfile->fid.volatile_fid, cfile->pid, new_eof);
if (rc == 0) { if (rc == 0) {
cifsi->server_eof = new_eof; netfs_resize_file(&cifsi->netfs, new_eof, true);
cifs_setsize(inode, new_eof); cifs_setsize(inode, new_eof);
cifs_truncate_page(inode->i_mapping, inode->i_size); cifs_truncate_page(inode->i_mapping, inode->i_size);
truncate_setsize(inode, new_eof); truncate_setsize(inode, new_eof);
...@@ -3528,8 +3531,9 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3528,8 +3531,9 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
int rc; int rc;
unsigned int xid; unsigned int xid;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct cifsFileInfo *cfile = file->private_data;
struct cifsInodeInfo *cifsi = CIFS_I(inode); struct cifsInodeInfo *cifsi = CIFS_I(inode);
struct cifsFileInfo *cfile = file->private_data;
struct netfs_inode *ictx = &cifsi->netfs;
loff_t old_eof, new_eof; loff_t old_eof, new_eof;
xid = get_xid(); xid = get_xid();
...@@ -3549,6 +3553,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3549,6 +3553,7 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
goto out_2; goto out_2;
truncate_pagecache_range(inode, off, old_eof); truncate_pagecache_range(inode, off, old_eof);
ictx->zero_point = old_eof;
rc = smb2_copychunk_range(xid, cfile, cfile, off + len, rc = smb2_copychunk_range(xid, cfile, cfile, off + len,
old_eof - off - len, off); old_eof - off - len, off);
...@@ -3563,9 +3568,10 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3563,9 +3568,10 @@ static long smb3_collapse_range(struct file *file, struct cifs_tcon *tcon,
rc = 0; rc = 0;
cifsi->server_eof = i_size_read(inode) - len; truncate_setsize(inode, new_eof);
truncate_setsize(inode, cifsi->server_eof); netfs_resize_file(&cifsi->netfs, new_eof, true);
fscache_resize_cookie(cifs_inode_cookie(inode), cifsi->server_eof); ictx->zero_point = new_eof;
fscache_resize_cookie(cifs_inode_cookie(inode), new_eof);
out_2: out_2:
filemap_invalidate_unlock(inode->i_mapping); filemap_invalidate_unlock(inode->i_mapping);
out: out:
...@@ -3581,6 +3587,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3581,6 +3587,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
unsigned int xid; unsigned int xid;
struct cifsFileInfo *cfile = file->private_data; struct cifsFileInfo *cfile = file->private_data;
struct inode *inode = file_inode(file); struct inode *inode = file_inode(file);
struct cifsInodeInfo *cifsi = CIFS_I(inode);
__u64 count, old_eof, new_eof; __u64 count, old_eof, new_eof;
xid = get_xid(); xid = get_xid();
...@@ -3608,6 +3615,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon, ...@@ -3608,6 +3615,7 @@ static long smb3_insert_range(struct file *file, struct cifs_tcon *tcon,
goto out_2; goto out_2;
truncate_setsize(inode, new_eof); truncate_setsize(inode, new_eof);
netfs_resize_file(&cifsi->netfs, i_size_read(inode), true);
fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode)); fscache_resize_cookie(cifs_inode_cookie(inode), i_size_read(inode));
rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len); rc = smb2_copychunk_range(xid, cfile, cfile, off, count, off + len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment