Skip to content

Commit

Permalink
afs: Use the netfs write helpers
Browse files Browse the repository at this point in the history
Make afs use the netfs write helpers.

Signed-off-by: David Howells <dhowells@redhat.com>
  • Loading branch information
dhowells committed Jun 9, 2022
1 parent 2a9c241 commit 61ba76d
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 854 deletions.
62 changes: 56 additions & 6 deletions fs/afs/file.c
Expand Up @@ -31,7 +31,7 @@ const struct file_operations afs_file_operations = {
.release = afs_release,
.llseek = generic_file_llseek,
.read_iter = afs_file_read_iter,
.write_iter = afs_file_write,
.write_iter = netfs_file_write_iter,
.mmap = afs_file_mmap,
.splice_read = generic_file_splice_read,
.splice_write = iter_file_splice_write,
Expand All @@ -54,9 +54,7 @@ const struct address_space_operations afs_file_aops = {
.launder_folio = afs_launder_folio,
.release_folio = netfs_release_folio,
.invalidate_folio = netfs_invalidate_folio,
.write_begin = afs_write_begin,
.write_end = afs_write_end,
.writepages = afs_writepages,
.writepages = netfs_writepages,
};

const struct address_space_operations afs_symlink_aops = {
Expand All @@ -70,7 +68,7 @@ static const struct vm_operations_struct afs_vm_ops = {
.close = afs_vm_close,
.fault = filemap_fault,
.map_pages = afs_vm_map_pages,
.page_mkwrite = afs_page_mkwrite,
.page_mkwrite = netfs_page_mkwrite,
};

/*
Expand Down Expand Up @@ -351,8 +349,10 @@ static int afs_symlink_read_folio(struct file *file, struct folio *folio)

static int afs_init_request(struct netfs_io_request *rreq, struct file *file)
{
rreq->netfs_priv = key_get(afs_file_key(file));
if (file)
rreq->netfs_priv = key_get(afs_file_key(file));
rreq->rsize = 4 * 1024 * 1024;
rreq->wsize = 16 * 1024 * 1024; // 0x33333;
return 0;
}

Expand All @@ -369,12 +369,62 @@ static void afs_free_request(struct netfs_io_request *rreq)
key_put(rreq->netfs_priv);
}

static void afs_init_dirty_region(struct netfs_dirty_region *region, struct file *file)
{
region->netfs_priv = key_get(afs_file_key(file));
}

static void afs_split_dirty_region(struct netfs_dirty_region *front,
struct netfs_dirty_region *back)
{
front->netfs_priv = key_get(back->netfs_priv);
}

static void afs_free_dirty_region(struct netfs_dirty_region *region)
{
key_put(region->netfs_priv);
}

static void afs_update_i_size(struct inode *inode, loff_t new_i_size)
{
struct afs_vnode *vnode = AFS_FS_I(inode);
loff_t i_size;

write_seqlock(&vnode->cb_lock);
i_size = i_size_read(&vnode->netfs.inode);
if (new_i_size > i_size) {
i_size_write(&vnode->netfs.inode, new_i_size);
inode_set_bytes(&vnode->netfs.inode, new_i_size);
}
write_sequnlock(&vnode->cb_lock);
fscache_update_cookie(afs_vnode_cache(vnode), NULL, &new_i_size);
}

static int afs_validate_for_write(struct inode *inode, struct file *file)
{
return afs_validate(AFS_FS_I(inode), afs_file_key(file));
}

static void afs_netfs_invalidate_cache(struct netfs_io_request *wreq)
{
struct afs_vnode *vnode = AFS_FS_I(wreq->inode);

afs_invalidate_cache(vnode, 0);
}

const struct netfs_request_ops afs_req_ops = {
.init_request = afs_init_request,
.free_request = afs_free_request,
.begin_cache_operation = fscache_begin_cache_operation,
.check_write_begin = afs_check_write_begin,
.issue_read = afs_issue_read,
.init_dirty_region = afs_init_dirty_region,
.split_dirty_region = afs_split_dirty_region,
.free_dirty_region = afs_free_dirty_region,
.update_i_size = afs_update_i_size,
.validate_for_write = afs_validate_for_write,
.invalidate_cache = afs_netfs_invalidate_cache,
.create_write_requests = afs_create_write_requests,
};

int afs_write_inode(struct inode *inode, struct writeback_control *wbc)
Expand Down
2 changes: 2 additions & 0 deletions fs/afs/inode.c
Expand Up @@ -59,6 +59,8 @@ static noinline void dump_vnode(struct afs_vnode *vnode, struct afs_vnode *paren
static void afs_set_netfs_context(struct afs_vnode *vnode)
{
netfs_inode_init(&vnode->netfs.inode, &afs_req_ops);
//ctx->min_bshift = ilog2(0x10000);
//ctx->obj_bshift = ilog2(0x40000);
}

/*
Expand Down
66 changes: 1 addition & 65 deletions fs/afs/internal.h
Expand Up @@ -890,62 +890,6 @@ static inline void afs_invalidate_cache(struct afs_vnode *vnode, unsigned int fl
i_size_read(&vnode->netfs.inode), flags);
}

/*
* We use folio->private to hold the amount of the folio that we've written to,
* splitting the field into two parts. However, we need to represent a range
* 0...FOLIO_SIZE, so we reduce the resolution if the size of the folio
* exceeds what we can encode.
*/
#ifdef CONFIG_64BIT
#define __AFS_FOLIO_PRIV_MASK 0x7fffffffUL
#define __AFS_FOLIO_PRIV_SHIFT 32
#define __AFS_FOLIO_PRIV_MMAPPED 0x80000000UL
#else
#define __AFS_FOLIO_PRIV_MASK 0x7fffUL
#define __AFS_FOLIO_PRIV_SHIFT 16
#define __AFS_FOLIO_PRIV_MMAPPED 0x8000UL
#endif

static inline unsigned int afs_folio_dirty_resolution(struct folio *folio)
{
int shift = folio_shift(folio) - (__AFS_FOLIO_PRIV_SHIFT - 1);
return (shift > 0) ? shift : 0;
}

static inline size_t afs_folio_dirty_from(struct folio *folio, unsigned long priv)
{
unsigned long x = priv & __AFS_FOLIO_PRIV_MASK;

/* The lower bound is inclusive */
return x << afs_folio_dirty_resolution(folio);
}

static inline size_t afs_folio_dirty_to(struct folio *folio, unsigned long priv)
{
unsigned long x = (priv >> __AFS_FOLIO_PRIV_SHIFT) & __AFS_FOLIO_PRIV_MASK;

/* The upper bound is immediately beyond the region */
return (x + 1) << afs_folio_dirty_resolution(folio);
}

static inline unsigned long afs_folio_dirty(struct folio *folio, size_t from, size_t to)
{
unsigned int res = afs_folio_dirty_resolution(folio);
from >>= res;
to = (to - 1) >> res;
return (to << __AFS_FOLIO_PRIV_SHIFT) | from;
}

static inline unsigned long afs_folio_dirty_mmapped(unsigned long priv)
{
return priv | __AFS_FOLIO_PRIV_MMAPPED;
}

static inline bool afs_is_folio_dirty_mmapped(unsigned long priv)
{
return priv & __AFS_FOLIO_PRIV_MMAPPED;
}

#include <trace/events/afs.h>

/*****************************************************************************/
Expand Down Expand Up @@ -1529,18 +1473,10 @@ bool afs_dirty_folio(struct address_space *, struct folio *);
#else
#define afs_dirty_folio filemap_dirty_folio
#endif
extern int afs_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len,
struct page **pagep, void **fsdata);
extern int afs_write_end(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned copied,
struct page *page, void *fsdata);
extern int afs_writepages(struct address_space *, struct writeback_control *);
extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
extern int afs_fsync(struct file *, loff_t, loff_t, int);
extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
extern void afs_prune_wb_keys(struct afs_vnode *);
int afs_launder_folio(struct folio *);
extern void afs_create_write_requests(struct netfs_io_request *);

/*
* xattr.c
Expand Down

0 comments on commit 61ba76d

Please sign in to comment.