12 #include <linux/slab.h>
40 list_del_init(&wb->
link);
75 afs_unlink_writeback(wb);
80 afs_free_writeback(wb);
93 _enter(
",,%llu", (
unsigned long long)pos);
104 _debug(
"got NOENT from server"
105 " - marking file deleted and stale");
119 loff_t pos,
unsigned len,
unsigned flags,
120 struct page **pagep,
void **fsdata)
123 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
127 unsigned to = from + len;
131 _enter(
"{%x:%u},{%lx},%u,%u",
132 vnode->
fid.vid, vnode->
fid.vnode, index, from, to);
134 candidate = kzalloc(
sizeof(*candidate),
GFP_KERNEL);
137 candidate->
vnode = vnode;
141 INIT_LIST_HEAD(&candidate->
link);
142 candidate->
usage = 1;
155 ret = afs_fill_page(vnode, key, index << PAGE_CACHE_SHIFT, page);
158 _leave(
" = %d [prep]", ret);
161 SetPageUptodate(page);
172 goto subsume_in_current_wb;
173 goto flush_conflicting_wb;
180 if (wb->
last == index - 1 && wb->
key == key &&
182 goto append_to_previous_wb;
187 candidate->
key = key_get(key);
189 SetPagePrivate(page);
190 set_page_private(page, (
unsigned long) candidate);
194 subsume_in_current_wb:
206 append_to_previous_wb:
212 SetPagePrivate(page);
213 set_page_private(page, (
unsigned long) wb);
220 flush_conflicting_wb:
225 if (PageDirty(page)) {
226 ret = afs_write_back_from_locked_page(wb, page);
236 set_page_private(page, 0);
237 ClearPagePrivate(page);
245 loff_t pos,
unsigned len,
unsigned copied,
246 struct page *page,
void *fsdata)
248 struct afs_vnode *vnode = AFS_FS_I(file->f_dentry->d_inode);
249 loff_t i_size, maybe_i_size;
254 maybe_i_size = pos + copied;
257 if (maybe_i_size > i_size) {
260 if (maybe_i_size > i_size)
261 i_size_write(&vnode->
vfs_inode, maybe_i_size);
281 unsigned count, loop;
284 vnode->
fid.vid, vnode->
fid.vnode, first, last);
286 pagevec_init(&
pv, 0);
289 _debug(
"kill %lx-%lx", first, last);
291 count = last - first + 1;
295 first, count,
pv.pages);
298 for (loop = 0; loop <
count; loop++) {
299 ClearPageUptodate(
pv.pages[loop]);
301 SetPageError(
pv.pages[loop]);
306 }
while (first < last);
315 static int afs_write_back_from_locked_page(
struct afs_writeback *wb,
316 struct page *primary_page)
335 start = primary_page->
index;
336 if (start >= wb->
last)
340 _debug(
"more %lx [%lx]", start, count);
341 n = wb->
last - start + 1;
349 if (pages[0]->
index != start) {
356 for (loop = 0; loop <
n; loop++) {
360 if (!trylock_page(page))
362 if (!PageDirty(page) ||
363 page_private(page) != (
unsigned long) wb) {
376 for (; loop <
n; loop++)
382 }
while (start <= wb->last && count < 65536);
388 first = primary_page->
index;
389 last = first + count - 1;
391 offset = (first == wb->first) ? wb->offset_first : 0;
392 to = (last == wb->last) ? wb->to_last :
PAGE_SIZE;
394 _debug(
"write back %lx[%u..] to %lx[..%u]", first, offset, last, to);
402 &wb->vnode->vfs_inode.i_mapping->flags);
411 afs_kill_pages(wb->vnode,
true, first, last);
420 afs_kill_pages(wb->vnode,
false, first, last);
447 ret = afs_write_back_from_locked_page(wb, page);
471 _enter(
",,%lx,%lx,", index, end);
481 if (page->
index > end) {
484 _leave(
" = 0 [%lx]", *_next);
495 if (page->
mapping != mapping) {
502 wait_on_page_writeback(page);
504 if (PageWriteback(page) || !PageDirty(page)) {
512 spin_lock(&wb->
vnode->writeback_lock);
514 spin_unlock(&wb->
vnode->writeback_lock);
516 ret = afs_write_back_from_locked_page(wb, page);
527 }
while (index < end && wbc->nr_to_write > 0);
530 _leave(
" = 0 [%lx]", *_next);
548 ret = afs_writepages_region(mapping, wbc, start, end, &next);
550 ret = afs_writepages_region(mapping, wbc, 0, start,
555 ret = afs_writepages_region(mapping, wbc, 0, end, &next);
561 ret = afs_writepages_region(mapping, wbc, start, end, &next);
575 unsigned count, loop;
579 _enter(
"{%x:%u},{%lx-%lx}",
580 vnode->
fid.vid, vnode->
fid.vnode, first, last);
584 pagevec_init(&pv, 0);
587 _debug(
"done %lx-%lx", first, last);
589 count = last - first + 1;
597 for (loop = 0; loop <
count; loop++) {
598 struct page *page = pv.
pages[loop];
600 if (page_private(page) == (
unsigned long) wb) {
601 set_page_private(page, 0);
602 ClearPagePrivate(page);
607 if (wb->
usage == 0) {
608 afs_unlink_writeback(wb);
614 afs_free_writeback(wb);
619 }
while (first <= last);
628 unsigned long nr_segs, loff_t pos)
633 size_t count = iov_length(iov, nr_segs);
635 _enter(
"{%x.%u},{%zu},%lu,",
636 vnode->
fid.vid, vnode->
fid.vnode, count, nr_segs);
640 "AFS: Attempt to write to active swap file!\n");
672 ret = mapping->
a_ops->writepages(mapping, &wbc);
692 _enter(
"{%x:%u},{n=%s},%d",
730 _leave(
" = %d [wb]", ret);
758 #ifdef CONFIG_AFS_FSCACHE
759 fscache_wait_on_page_write(vnode->cache, page);