Commit 1ecb146f authored by David Howells's avatar David Howells

netfs, afs: Use writeback retry to deal with alternate keys

Use a hook in the new writeback code's retry algorithm to rotate the keys
once all the outstanding subreqs have failed rather than doing it
separately on each subreq.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: netfs@lists.linux.dev
cc: linux-fsdevel@vger.kernel.org
parent d41ca44c
...@@ -368,6 +368,7 @@ static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len, ...@@ -368,6 +368,7 @@ static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len,
static void afs_free_request(struct netfs_io_request *rreq) static void afs_free_request(struct netfs_io_request *rreq)
{ {
key_put(rreq->netfs_priv); key_put(rreq->netfs_priv);
afs_put_wb_key(rreq->netfs_priv2);
} }
static void afs_update_i_size(struct inode *inode, loff_t new_i_size) static void afs_update_i_size(struct inode *inode, loff_t new_i_size)
......
...@@ -1601,6 +1601,7 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *); ...@@ -1601,6 +1601,7 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
void afs_prepare_write(struct netfs_io_subrequest *subreq); void afs_prepare_write(struct netfs_io_subrequest *subreq);
void afs_issue_write(struct netfs_io_subrequest *subreq); void afs_issue_write(struct netfs_io_subrequest *subreq);
void afs_begin_writeback(struct netfs_io_request *wreq); void afs_begin_writeback(struct netfs_io_request *wreq);
void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
extern int afs_writepages(struct address_space *, struct writeback_control *); extern int afs_writepages(struct address_space *, struct writeback_control *);
extern int afs_fsync(struct file *, loff_t, loff_t, int); extern int afs_fsync(struct file *, loff_t, loff_t, int);
extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf); extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);
......
...@@ -29,43 +29,39 @@ static void afs_pages_written_back(struct afs_vnode *vnode, loff_t start, unsign ...@@ -29,43 +29,39 @@ static void afs_pages_written_back(struct afs_vnode *vnode, loff_t start, unsign
/* /*
* Find a key to use for the writeback. We cached the keys used to author the * Find a key to use for the writeback. We cached the keys used to author the
* writes on the vnode. *_wbk will contain the last writeback key used or NULL * writes on the vnode. wreq->netfs_priv2 will contain the last writeback key
* and we need to start from there if it's set. * 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.
*/ */
static int afs_get_writeback_key(struct afs_vnode *vnode, static void afs_get_writeback_key(struct netfs_io_request *wreq)
struct afs_wb_key **_wbk)
{ {
struct afs_wb_key *wbk = NULL; struct afs_wb_key *wbk, *old = wreq->netfs_priv2;
struct list_head *p; struct afs_vnode *vnode = AFS_FS_I(wreq->inode);
int ret = -ENOKEY, ret2;
key_put(wreq->netfs_priv);
wreq->netfs_priv = NULL;
wreq->netfs_priv2 = NULL;
spin_lock(&vnode->wb_lock); spin_lock(&vnode->wb_lock);
if (*_wbk) if (old)
p = (*_wbk)->vnode_link.next; wbk = list_next_entry(old, vnode_link);
else else
p = vnode->wb_keys.next; wbk = list_first_entry(&vnode->wb_keys, struct afs_wb_key, vnode_link);
while (p != &vnode->wb_keys) { list_for_each_entry_from(wbk, &vnode->wb_keys, vnode_link) {
wbk = list_entry(p, struct afs_wb_key, vnode_link);
_debug("wbk %u", key_serial(wbk->key)); _debug("wbk %u", key_serial(wbk->key));
ret2 = key_validate(wbk->key); if (key_validate(wbk->key) == 0) {
if (ret2 == 0) {
refcount_inc(&wbk->usage); refcount_inc(&wbk->usage);
wreq->netfs_priv = key_get(wbk->key);
wreq->netfs_priv2 = wbk;
_debug("USE WB KEY %u", key_serial(wbk->key)); _debug("USE WB KEY %u", key_serial(wbk->key));
break; break;
} }
wbk = NULL;
if (ret == -ENOKEY)
ret = ret2;
p = p->next;
} }
spin_unlock(&vnode->wb_lock); spin_unlock(&vnode->wb_lock);
if (*_wbk)
afs_put_wb_key(*_wbk); afs_put_wb_key(old);
*_wbk = wbk;
return 0;
} }
static void afs_store_data_success(struct afs_operation *op) static void afs_store_data_success(struct afs_operation *op)
...@@ -88,72 +84,91 @@ static const struct afs_operation_ops afs_store_data_operation = { ...@@ -88,72 +84,91 @@ static const struct afs_operation_ops afs_store_data_operation = {
}; };
/* /*
* write to a file * Prepare a subrequest to write to the server. This sets the max_len
* parameter.
*/ */
static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_t pos) void afs_prepare_write(struct netfs_io_subrequest *subreq)
{ {
//if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags))
// subreq->max_len = 512 * 1024;
//else
subreq->max_len = 256 * 1024 * 1024;
}
/*
* Issue a subrequest to write to the server.
*/
static void afs_issue_write_worker(struct work_struct *work)
{
struct netfs_io_subrequest *subreq = container_of(work, struct netfs_io_subrequest, work);
struct netfs_io_request *wreq = subreq->rreq;
struct afs_operation *op; struct afs_operation *op;
struct afs_wb_key *wbk = NULL; struct afs_vnode *vnode = AFS_FS_I(wreq->inode);
loff_t size = iov_iter_count(iter); unsigned long long pos = subreq->start + subreq->transferred;
size_t len = subreq->len - subreq->transferred;
int ret = -ENOKEY; int ret = -ENOKEY;
_enter("%s{%llx:%llu.%u},%llx,%llx", _enter("R=%x[%x],%s{%llx:%llu.%u},%llx,%zx",
wreq->debug_id, subreq->debug_index,
vnode->volume->name, vnode->volume->name,
vnode->fid.vid, vnode->fid.vid,
vnode->fid.vnode, vnode->fid.vnode,
vnode->fid.unique, vnode->fid.unique,
size, pos); pos, len);
ret = afs_get_writeback_key(vnode, &wbk); #if 0 // Error injection
if (ret) { if (subreq->debug_index == 3)
_leave(" = %d [no keys]", ret); return netfs_write_subrequest_terminated(subreq, -ENOANO, false);
return ret;
}
op = afs_alloc_operation(wbk->key, vnode->volume); if (!test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) {
if (IS_ERR(op)) { set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
afs_put_wb_key(wbk); return netfs_write_subrequest_terminated(subreq, -EAGAIN, false);
return -ENOMEM;
} }
#endif
op = afs_alloc_operation(wreq->netfs_priv, vnode->volume);
if (IS_ERR(op))
return netfs_write_subrequest_terminated(subreq, -EAGAIN, false);
afs_op_set_vnode(op, 0, vnode); afs_op_set_vnode(op, 0, vnode);
op->file[0].dv_delta = 1; op->file[0].dv_delta = 1;
op->file[0].modification = true; op->file[0].modification = true;
op->store.pos = pos; op->store.pos = pos;
op->store.size = size; op->store.size = len;
op->flags |= AFS_OPERATION_UNINTR; op->flags |= AFS_OPERATION_UNINTR;
op->ops = &afs_store_data_operation; op->ops = &afs_store_data_operation;
try_next_key:
afs_begin_vnode_operation(op); afs_begin_vnode_operation(op);
op->store.write_iter = iter; op->store.write_iter = &subreq->io_iter;
op->store.i_size = max(pos + size, vnode->netfs.remote_i_size); op->store.i_size = umax(pos + len, vnode->netfs.remote_i_size);
op->mtime = inode_get_mtime(&vnode->netfs.inode); op->mtime = inode_get_mtime(&vnode->netfs.inode);
afs_wait_for_operation(op); afs_wait_for_operation(op);
ret = afs_put_operation(op);
switch (afs_op_error(op)) { switch (ret) {
case -EACCES: case -EACCES:
case -EPERM: case -EPERM:
case -ENOKEY: case -ENOKEY:
case -EKEYEXPIRED: case -EKEYEXPIRED:
case -EKEYREJECTED: case -EKEYREJECTED:
case -EKEYREVOKED: case -EKEYREVOKED:
_debug("next"); /* If there are more keys we can try, use the retry algorithm
* to rotate the keys.
ret = afs_get_writeback_key(vnode, &wbk); */
if (ret == 0) { if (wreq->netfs_priv2)
key_put(op->key); set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
op->key = key_get(wbk->key);
goto try_next_key;
}
break; break;
} }
afs_put_wb_key(wbk); netfs_write_subrequest_terminated(subreq, ret < 0 ? ret : subreq->len, false);
_leave(" = %d", afs_op_error(op)); }
return afs_put_operation(op);
void afs_issue_write(struct netfs_io_subrequest *subreq)
{
subreq->work.func = afs_issue_write_worker;
if (!queue_work(system_unbound_wq, &subreq->work))
WARN_ON_ONCE(1);
} }
/* /*
...@@ -162,52 +177,32 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_t ...@@ -162,52 +177,32 @@ static int afs_store_data(struct afs_vnode *vnode, struct iov_iter *iter, loff_t
*/ */
void afs_begin_writeback(struct netfs_io_request *wreq) void afs_begin_writeback(struct netfs_io_request *wreq)
{ {
afs_get_writeback_key(wreq);
wreq->io_streams[0].avail = true; wreq->io_streams[0].avail = true;
} }
/* /*
* Prepare a subrequest to write to the server. This sets the max_len * Prepare to retry the writes in request. Use this to try rotating the
* parameter. * available writeback keys.
*/
void afs_prepare_write(struct netfs_io_subrequest *subreq)
{
//if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags))
// subreq->max_len = 512 * 1024;
//else
subreq->max_len = 256 * 1024 * 1024;
}
/*
* Issue a subrequest to write to the server.
*/ */
static void afs_issue_write_worker(struct work_struct *work) void afs_retry_request(struct netfs_io_request *wreq, struct netfs_io_stream *stream)
{ {
struct netfs_io_subrequest *subreq = container_of(work, struct netfs_io_subrequest, work); struct netfs_io_subrequest *subreq =
struct afs_vnode *vnode = AFS_FS_I(subreq->rreq->inode); list_first_entry(&stream->subrequests,
ssize_t ret; struct netfs_io_subrequest, rreq_link);
_enter("%x[%x],%zx",
subreq->rreq->debug_id, subreq->debug_index, subreq->io_iter.count);
#if 0 // Error injection
if (subreq->debug_index == 3)
return netfs_write_subrequest_terminated(subreq, -ENOANO, false);
if (!test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) { switch (subreq->error) {
set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags); case -EACCES:
return netfs_write_subrequest_terminated(subreq, -EAGAIN, false); case -EPERM:
case -ENOKEY:
case -EKEYEXPIRED:
case -EKEYREJECTED:
case -EKEYREVOKED:
afs_get_writeback_key(wreq);
if (!wreq->netfs_priv)
stream->failed = true;
break;
} }
#endif
ret = afs_store_data(vnode, &subreq->io_iter, subreq->start);
netfs_write_subrequest_terminated(subreq, ret < 0 ? ret : subreq->len, false);
}
void afs_issue_write(struct netfs_io_subrequest *subreq)
{
subreq->work.func = afs_issue_write_worker;
if (!queue_work(system_unbound_wq, &subreq->work))
WARN_ON_ONCE(1);
} }
/* /*
......
...@@ -163,6 +163,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, ...@@ -163,6 +163,13 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
_enter("R=%x[%x:]", wreq->debug_id, stream->stream_nr); _enter("R=%x[%x:]", wreq->debug_id, stream->stream_nr);
if (list_empty(&stream->subrequests))
return;
if (stream->source == NETFS_UPLOAD_TO_SERVER &&
wreq->netfs_ops->retry_request)
wreq->netfs_ops->retry_request(wreq, stream);
if (unlikely(stream->failed)) if (unlikely(stream->failed))
return; return;
...@@ -182,8 +189,6 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq, ...@@ -182,8 +189,6 @@ static void netfs_retry_write_stream(struct netfs_io_request *wreq,
return; return;
} }
if (list_empty(&stream->subrequests))
return;
next = stream->subrequests.next; next = stream->subrequests.next;
do { do {
......
...@@ -235,6 +235,7 @@ struct netfs_io_request { ...@@ -235,6 +235,7 @@ struct netfs_io_request {
struct iov_iter iter; /* Unencrypted-side iterator */ struct iov_iter iter; /* Unencrypted-side iterator */
struct iov_iter io_iter; /* I/O (Encrypted-side) iterator */ struct iov_iter io_iter; /* I/O (Encrypted-side) iterator */
void *netfs_priv; /* Private data for the netfs */ void *netfs_priv; /* Private data for the netfs */
void *netfs_priv2; /* Private data for the netfs */
struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */ struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */
unsigned int direct_bv_count; /* Number of elements in direct_bv[] */ unsigned int direct_bv_count; /* Number of elements in direct_bv[] */
unsigned int debug_id; unsigned int debug_id;
...@@ -306,6 +307,7 @@ struct netfs_request_ops { ...@@ -306,6 +307,7 @@ struct netfs_request_ops {
void (*begin_writeback)(struct netfs_io_request *wreq); void (*begin_writeback)(struct netfs_io_request *wreq);
void (*prepare_write)(struct netfs_io_subrequest *subreq); void (*prepare_write)(struct netfs_io_subrequest *subreq);
void (*issue_write)(struct netfs_io_subrequest *subreq); void (*issue_write)(struct netfs_io_subrequest *subreq);
void (*retry_request)(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
void (*invalidate_cache)(struct netfs_io_request *wreq); void (*invalidate_cache)(struct netfs_io_request *wreq);
}; };
......
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