Skip to content

Commit ed22e1d

Browse files
committed
netfs, afs: Implement helpers for new write code
Implement the helpers for the new write code in afs. There's now an optional ->prepare_write() that allows the filesystem to set the parameters for the next write, such as maximum size and maximum segment count, and an ->issue_write() that is called to initiate an (asynchronous) write operation. Signed-off-by: David Howells <[email protected]> Reviewed-by: Jeff Layton <[email protected]> cc: Marc Dionne <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected]
1 parent 4824e59 commit ed22e1d

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

fs/afs/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ const struct netfs_request_ops afs_req_ops = {
400400
.update_i_size = afs_update_i_size,
401401
.invalidate_cache = afs_netfs_invalidate_cache,
402402
.create_write_requests = afs_create_write_requests,
403+
.begin_writeback = afs_begin_writeback,
404+
.prepare_write = afs_prepare_write,
405+
.issue_write = afs_issue_write,
403406
};
404407

405408
static void afs_add_open_mmap(struct afs_vnode *vnode)

fs/afs/internal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,9 @@ extern int afs_check_volume_status(struct afs_volume *, struct afs_operation *);
15981598
/*
15991599
* write.c
16001600
*/
1601+
void afs_prepare_write(struct netfs_io_subrequest *subreq);
1602+
void afs_issue_write(struct netfs_io_subrequest *subreq);
1603+
void afs_begin_writeback(struct netfs_io_request *wreq);
16011604
extern int afs_writepages(struct address_space *, struct writeback_control *);
16021605
extern int afs_fsync(struct file *, loff_t, loff_t, int);
16031606
extern vm_fault_t afs_page_mkwrite(struct vm_fault *vmf);

fs/afs/write.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,60 @@ void afs_create_write_requests(struct netfs_io_request *wreq, loff_t start, size
194194
netfs_queue_write_request(subreq);
195195
}
196196

197+
/*
198+
* Writeback calls this when it finds a folio that needs uploading. This isn't
199+
* called if writeback only has copy-to-cache to deal with.
200+
*/
201+
void afs_begin_writeback(struct netfs_io_request *wreq)
202+
{
203+
wreq->io_streams[0].avail = true;
204+
}
205+
206+
/*
207+
* Prepare a subrequest to write to the server. This sets the max_len
208+
* parameter.
209+
*/
210+
void afs_prepare_write(struct netfs_io_subrequest *subreq)
211+
{
212+
//if (test_bit(NETFS_SREQ_RETRYING, &subreq->flags))
213+
// subreq->max_len = 512 * 1024;
214+
//else
215+
subreq->max_len = 256 * 1024 * 1024;
216+
}
217+
218+
/*
219+
* Issue a subrequest to write to the server.
220+
*/
221+
static void afs_issue_write_worker(struct work_struct *work)
222+
{
223+
struct netfs_io_subrequest *subreq = container_of(work, struct netfs_io_subrequest, work);
224+
struct afs_vnode *vnode = AFS_FS_I(subreq->rreq->inode);
225+
ssize_t ret;
226+
227+
_enter("%x[%x],%zx",
228+
subreq->rreq->debug_id, subreq->debug_index, subreq->io_iter.count);
229+
230+
#if 0 // Error injection
231+
if (subreq->debug_index == 3)
232+
return netfs_write_subrequest_terminated(subreq, -ENOANO, false);
233+
234+
if (!test_bit(NETFS_SREQ_RETRYING, &subreq->flags)) {
235+
set_bit(NETFS_SREQ_NEED_RETRY, &subreq->flags);
236+
return netfs_write_subrequest_terminated(subreq, -EAGAIN, false);
237+
}
238+
#endif
239+
240+
ret = afs_store_data(vnode, &subreq->io_iter, subreq->start);
241+
netfs_write_subrequest_terminated(subreq, ret < 0 ? ret : subreq->len, false);
242+
}
243+
244+
void afs_issue_write(struct netfs_io_subrequest *subreq)
245+
{
246+
subreq->work.func = afs_issue_write_worker;
247+
if (!queue_work(system_unbound_wq, &subreq->work))
248+
WARN_ON_ONCE(1);
249+
}
250+
197251
/*
198252
* write some of the pending data back to the server
199253
*/

0 commit comments

Comments
 (0)