// SPDX-License-Identifier: GPL-2.0-or-later /* handling of writes to regular files and writing back to the server * * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com)
*/
/* * completion of write to server
*/ staticvoid afs_pages_written_back(struct afs_vnode *vnode, loff_t start, unsignedint len)
{
_enter("{%llx:%llu},{%x @%llx}",
vnode->fid.vid, vnode->fid.vnode, len, start);
afs_prune_wb_keys(vnode);
_leave("");
}
/* * Find a key to use for the writeback. We cached the keys used to author the * writes on the vnode. wreq->netfs_priv2 will contain the last writeback key * record used or NULL and we need to start from there if it's set. * wreq->netfs_priv will be set to the key itself or NULL.
*/ staticvoid afs_get_writeback_key(struct netfs_io_request *wreq)
{ struct afs_wb_key *wbk, *old = wreq->netfs_priv2; struct afs_vnode *vnode = AFS_FS_I(wreq->inode);
/* * Prepare a subrequest to write to the server. This sets the max_len * parameter.
*/ void afs_prepare_write(struct netfs_io_subrequest *subreq)
{ struct netfs_io_stream *stream = &subreq->rreq->io_streams[subreq->stream_nr];
afs_wait_for_operation(op);
ret = afs_put_operation(op); switch (ret) { case 0:
__set_bit(NETFS_SREQ_MADE_PROGRESS, &subreq->flags); break; case -EACCES: case -EPERM: case -ENOKEY: case -EKEYEXPIRED: case -EKEYREJECTED: case -EKEYREVOKED: /* If there are more keys we can try, use the retry algorithm * to rotate the keys.
*/ if (wreq->netfs_priv2)
set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); break;
}
netfs_write_subrequest_terminated(subreq, ret < 0 ? ret : subreq->len);
}
/* * Writeback calls this when it finds a folio that needs uploading. This isn't * called if writeback only has copy-to-cache to deal with.
*/ void afs_begin_writeback(struct netfs_io_request *wreq)
{ if (S_ISREG(wreq->inode->i_mode))
afs_get_writeback_key(wreq);
}
/* * Prepare to retry the writes in request. Use this to try rotating the * available writeback keys.
*/ void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream)
{ struct netfs_io_subrequest *subreq =
list_first_entry(&stream->subrequests, struct netfs_io_subrequest, rreq_link);
switch (wreq->origin) { case NETFS_READAHEAD: case NETFS_READPAGE: case NETFS_READ_GAPS: case NETFS_READ_SINGLE: case NETFS_READ_FOR_WRITE: case NETFS_UNBUFFERED_READ: case NETFS_DIO_READ: return; default: break;
}
switch (subreq->error) { case -EACCES: case -EPERM: case -ENOKEY: case -EKEYEXPIRED: case -EKEYREJECTED: case -EKEYREVOKED:
afs_get_writeback_key(wreq); if (!wreq->netfs_priv)
stream->failed = true; break;
}
}
/* * write some of the pending data back to the server
*/ int afs_writepages(struct address_space *mapping, struct writeback_control *wbc)
{ struct afs_vnode *vnode = AFS_FS_I(mapping->host); int ret;
/* We have to be careful as we can end up racing with setattr() * truncating the pagecache since the caller doesn't take a lock here * to prevent it.
*/ if (wbc->sync_mode == WB_SYNC_ALL)
down_read(&vnode->validate_lock); elseif (!down_read_trylock(&vnode->validate_lock)) return 0;
ret = netfs_writepages(mapping, wbc);
up_read(&vnode->validate_lock); return ret;
}
/* * flush any dirty pages for this process, and check for write errors. * - the return status from this call provides a reliable indication of * whether any write errors occurred for this process.
*/ int afs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
{ struct afs_vnode *vnode = AFS_FS_I(file_inode(file)); struct afs_file *af = file->private_data; int ret;
/* * notification that a previously read-only page is about to become writable * - if it returns an error, the caller will deliver a bus error signal
*/
vm_fault_t afs_page_mkwrite(struct vm_fault *vmf)
{ struct file *file = vmf->vma->vm_file;
/* * Prune the keys cached for writeback. The caller must hold vnode->wb_lock.
*/ void afs_prune_wb_keys(struct afs_vnode *vnode)
{
LIST_HEAD(graveyard); struct afs_wb_key *wbk, *tmp;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.