Commit 255ed636 authored by David Howells's avatar David Howells

afs: Use folios in directory handling

Convert the AFS directory handling code to use folios.

With these changes, afs passes -g quick xfstests.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Tested-by: kafs-testing@auristor.com
cc: Matthew Wilcox (Oracle) <willy@infradead.org>
cc: Jeff Layton <jlayton@kernel.org>
cc: Marc Dionne <marc.dionne@auristor.com>
cc: linux-afs@lists.infradead.org
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/162877312172.3085614.992850861791211206.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/162981154845.1901565.2078707403143240098.stgit@warthog.procyon.org.uk/
Link: https://lore.kernel.org/r/163005746215.2472992.8321380998443828308.stgit@warthog.procyon.org.uk/ # v2
Link: https://lore.kernel.org/r/163584190457.4023316.10544419117563104940.stgit@warthog.procyon.org.uk/ # v3
Link: https://lore.kernel.org/r/CAH2r5mtECQA6K_OGgU=_G8qLY3G-6-jo1odVyF9EK+O2-EWLFg@mail.gmail.com/ # v3
Link: https://lore.kernel.org/r/163649330345.309189.11182522282723655658.stgit@warthog.procyon.org.uk/ # v4
Link: https://lore.kernel.org/r/163657854055.834781.5800946340537517009.stgit@warthog.procyon.org.uk/ # v5
parent 78525c74
This diff is collapsed.
...@@ -104,6 +104,25 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block, ...@@ -104,6 +104,25 @@ static void afs_clear_contig_bits(union afs_xdr_dir_block *block,
block->hdr.bitmap[7] &= ~(u8)(mask >> 7 * 8); block->hdr.bitmap[7] &= ~(u8)(mask >> 7 * 8);
} }
/*
* Get a new directory folio.
*/
static struct folio *afs_dir_get_folio(struct afs_vnode *vnode, pgoff_t index)
{
struct address_space *mapping = vnode->vfs_inode.i_mapping;
struct folio *folio;
folio = __filemap_get_folio(mapping, index,
FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
mapping->gfp_mask);
if (!folio)
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
else if (folio && !folio_test_private(folio))
folio_attach_private(folio, (void *)1);
return folio;
}
/* /*
* Scan a directory block looking for a dirent of the right name. * Scan a directory block looking for a dirent of the right name.
*/ */
...@@ -188,13 +207,11 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -188,13 +207,11 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
enum afs_edit_dir_reason why) enum afs_edit_dir_reason why)
{ {
union afs_xdr_dir_block *meta, *block; union afs_xdr_dir_block *meta, *block;
struct afs_xdr_dir_page *meta_page, *dir_page;
union afs_xdr_dirent *de; union afs_xdr_dirent *de;
struct page *page0, *page; struct folio *folio0, *folio;
unsigned int need_slots, nr_blocks, b; unsigned int need_slots, nr_blocks, b;
pgoff_t index; pgoff_t index;
loff_t i_size; loff_t i_size;
gfp_t gfp;
int slot; int slot;
_enter(",,{%d,%s},", name->len, name->name); _enter(",,{%d,%s},", name->len, name->name);
...@@ -206,10 +223,8 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -206,10 +223,8 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
return; return;
} }
gfp = vnode->vfs_inode.i_mapping->gfp_mask; folio0 = afs_dir_get_folio(vnode, 0);
page0 = find_or_create_page(vnode->vfs_inode.i_mapping, 0, gfp); if (!folio0) {
if (!page0) {
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
_leave(" [fgp]"); _leave(" [fgp]");
return; return;
} }
...@@ -217,42 +232,35 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -217,42 +232,35 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
/* Work out how many slots we're going to need. */ /* Work out how many slots we're going to need. */
need_slots = afs_dir_calc_slots(name->len); need_slots = afs_dir_calc_slots(name->len);
meta_page = kmap(page0); meta = kmap_local_folio(folio0, 0);
meta = &meta_page->blocks[0];
if (i_size == 0) if (i_size == 0)
goto new_directory; goto new_directory;
nr_blocks = i_size / AFS_DIR_BLOCK_SIZE; nr_blocks = i_size / AFS_DIR_BLOCK_SIZE;
/* Find a block that has sufficient slots available. Each VM page /* Find a block that has sufficient slots available. Each folio
* contains two or more directory blocks. * contains two or more directory blocks.
*/ */
for (b = 0; b < nr_blocks + 1; b++) { for (b = 0; b < nr_blocks + 1; b++) {
/* If the directory extended into a new page, then we need to /* If the directory extended into a new folio, then we need to
* tack a new page on the end. * tack a new folio on the end.
*/ */
index = b / AFS_DIR_BLOCKS_PER_PAGE; index = b / AFS_DIR_BLOCKS_PER_PAGE;
if (index == 0) { if (nr_blocks >= AFS_DIR_MAX_BLOCKS)
page = page0; goto error;
dir_page = meta_page; if (index >= folio_nr_pages(folio0)) {
} else { folio = afs_dir_get_folio(vnode, index);
if (nr_blocks >= AFS_DIR_MAX_BLOCKS) if (!folio)
goto error;
gfp = vnode->vfs_inode.i_mapping->gfp_mask;
page = find_or_create_page(vnode->vfs_inode.i_mapping,
index, gfp);
if (!page)
goto error; goto error;
if (!PagePrivate(page)) } else {
attach_page_private(page, (void *)1); folio = folio0;
dir_page = kmap(page);
} }
block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_file_pos(folio));
/* Abandon the edit if we got a callback break. */ /* Abandon the edit if we got a callback break. */
if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags)) if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
goto invalidated; goto invalidated;
block = &dir_page->blocks[b % AFS_DIR_BLOCKS_PER_PAGE];
_debug("block %u: %2u %3u %u", _debug("block %u: %2u %3u %u",
b, b,
(b < AFS_DIR_BLOCKS_WITH_CTR) ? meta->meta.alloc_ctrs[b] : 99, (b < AFS_DIR_BLOCKS_WITH_CTR) ? meta->meta.alloc_ctrs[b] : 99,
...@@ -266,7 +274,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -266,7 +274,7 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
afs_set_i_size(vnode, (b + 1) * AFS_DIR_BLOCK_SIZE); afs_set_i_size(vnode, (b + 1) * AFS_DIR_BLOCK_SIZE);
} }
/* Only lower dir pages have a counter in the header. */ /* Only lower dir blocks have a counter in the header. */
if (b >= AFS_DIR_BLOCKS_WITH_CTR || if (b >= AFS_DIR_BLOCKS_WITH_CTR ||
meta->meta.alloc_ctrs[b] >= need_slots) { meta->meta.alloc_ctrs[b] >= need_slots) {
/* We need to try and find one or more consecutive /* We need to try and find one or more consecutive
...@@ -279,10 +287,10 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -279,10 +287,10 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
} }
} }
if (page != page0) { kunmap_local(block);
unlock_page(page); if (folio != folio0) {
kunmap(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
} }
...@@ -298,8 +306,8 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -298,8 +306,8 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
i_size = AFS_DIR_BLOCK_SIZE; i_size = AFS_DIR_BLOCK_SIZE;
afs_set_i_size(vnode, i_size); afs_set_i_size(vnode, i_size);
slot = AFS_DIR_RESV_BLOCKS0; slot = AFS_DIR_RESV_BLOCKS0;
page = page0; folio = folio0;
block = meta; block = kmap_local_folio(folio, 0);
nr_blocks = 1; nr_blocks = 1;
b = 0; b = 0;
...@@ -318,10 +326,10 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -318,10 +326,10 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
/* Adjust the bitmap. */ /* Adjust the bitmap. */
afs_set_contig_bits(block, slot, need_slots); afs_set_contig_bits(block, slot, need_slots);
if (page != page0) { kunmap_local(block);
unlock_page(page); if (folio != folio0) {
kunmap(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
/* Adjust the allocation counter. */ /* Adjust the allocation counter. */
...@@ -333,18 +341,19 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -333,18 +341,19 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
_debug("Insert %s in %u[%u]", name->name, b, slot); _debug("Insert %s in %u[%u]", name->name, b, slot);
out_unmap: out_unmap:
unlock_page(page0); kunmap_local(meta);
kunmap(page0); folio_unlock(folio0);
put_page(page0); folio_put(folio0);
_leave(""); _leave("");
return; return;
invalidated: invalidated:
trace_afs_edit_dir(vnode, why, afs_edit_dir_create_inval, 0, 0, 0, 0, name->name); trace_afs_edit_dir(vnode, why, afs_edit_dir_create_inval, 0, 0, 0, 0, name->name);
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags); clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
if (page != page0) { kunmap_local(block);
kunmap(page); if (folio != folio0) {
put_page(page); folio_unlock(folio);
folio_put(folio);
} }
goto out_unmap; goto out_unmap;
...@@ -364,10 +373,9 @@ void afs_edit_dir_add(struct afs_vnode *vnode, ...@@ -364,10 +373,9 @@ void afs_edit_dir_add(struct afs_vnode *vnode,
void afs_edit_dir_remove(struct afs_vnode *vnode, void afs_edit_dir_remove(struct afs_vnode *vnode,
struct qstr *name, enum afs_edit_dir_reason why) struct qstr *name, enum afs_edit_dir_reason why)
{ {
struct afs_xdr_dir_page *meta_page, *dir_page;
union afs_xdr_dir_block *meta, *block; union afs_xdr_dir_block *meta, *block;
union afs_xdr_dirent *de; union afs_xdr_dirent *de;
struct page *page0, *page; struct folio *folio0, *folio;
unsigned int need_slots, nr_blocks, b; unsigned int need_slots, nr_blocks, b;
pgoff_t index; pgoff_t index;
loff_t i_size; loff_t i_size;
...@@ -384,9 +392,8 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -384,9 +392,8 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
} }
nr_blocks = i_size / AFS_DIR_BLOCK_SIZE; nr_blocks = i_size / AFS_DIR_BLOCK_SIZE;
page0 = find_lock_page(vnode->vfs_inode.i_mapping, 0); folio0 = afs_dir_get_folio(vnode, 0);
if (!page0) { if (!folio0) {
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
_leave(" [fgp]"); _leave(" [fgp]");
return; return;
} }
...@@ -394,30 +401,27 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -394,30 +401,27 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
/* Work out how many slots we're going to discard. */ /* Work out how many slots we're going to discard. */
need_slots = afs_dir_calc_slots(name->len); need_slots = afs_dir_calc_slots(name->len);
meta_page = kmap(page0); meta = kmap_local_folio(folio0, 0);
meta = &meta_page->blocks[0];
/* Find a page that has sufficient slots available. Each VM page /* Find a block that has sufficient slots available. Each folio
* contains two or more directory blocks. * contains two or more directory blocks.
*/ */
for (b = 0; b < nr_blocks; b++) { for (b = 0; b < nr_blocks; b++) {
index = b / AFS_DIR_BLOCKS_PER_PAGE; index = b / AFS_DIR_BLOCKS_PER_PAGE;
if (index != 0) { if (index >= folio_nr_pages(folio0)) {
page = find_lock_page(vnode->vfs_inode.i_mapping, index); folio = afs_dir_get_folio(vnode, index);
if (!page) if (!folio)
goto error; goto error;
dir_page = kmap(page);
} else { } else {
page = page0; folio = folio0;
dir_page = meta_page;
} }
block = kmap_local_folio(folio, b * AFS_DIR_BLOCK_SIZE - folio_file_pos(folio));
/* Abandon the edit if we got a callback break. */ /* Abandon the edit if we got a callback break. */
if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags)) if (!test_bit(AFS_VNODE_DIR_VALID, &vnode->flags))
goto invalidated; goto invalidated;
block = &dir_page->blocks[b % AFS_DIR_BLOCKS_PER_PAGE];
if (b > AFS_DIR_BLOCKS_WITH_CTR || if (b > AFS_DIR_BLOCKS_WITH_CTR ||
meta->meta.alloc_ctrs[b] <= AFS_DIR_SLOTS_PER_BLOCK - 1 - need_slots) { meta->meta.alloc_ctrs[b] <= AFS_DIR_SLOTS_PER_BLOCK - 1 - need_slots) {
slot = afs_dir_scan_block(block, name, b); slot = afs_dir_scan_block(block, name, b);
...@@ -425,10 +429,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -425,10 +429,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
goto found_dirent; goto found_dirent;
} }
if (page != page0) { kunmap_local(block);
unlock_page(page); if (folio != folio0) {
kunmap(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
} }
...@@ -449,10 +453,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -449,10 +453,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
/* Adjust the bitmap. */ /* Adjust the bitmap. */
afs_clear_contig_bits(block, slot, need_slots); afs_clear_contig_bits(block, slot, need_slots);
if (page != page0) { kunmap_local(block);
unlock_page(page); if (folio != folio0) {
kunmap(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
/* Adjust the allocation counter. */ /* Adjust the allocation counter. */
...@@ -464,9 +468,9 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -464,9 +468,9 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
_debug("Remove %s from %u[%u]", name->name, b, slot); _debug("Remove %s from %u[%u]", name->name, b, slot);
out_unmap: out_unmap:
unlock_page(page0); kunmap_local(meta);
kunmap(page0); folio_unlock(folio0);
put_page(page0); folio_put(folio0);
_leave(""); _leave("");
return; return;
...@@ -474,10 +478,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode, ...@@ -474,10 +478,10 @@ void afs_edit_dir_remove(struct afs_vnode *vnode,
trace_afs_edit_dir(vnode, why, afs_edit_dir_delete_inval, trace_afs_edit_dir(vnode, why, afs_edit_dir_delete_inval,
0, 0, 0, 0, name->name); 0, 0, 0, 0, name->name);
clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags); clear_bit(AFS_VNODE_DIR_VALID, &vnode->flags);
if (page != page0) { kunmap_local(block);
unlock_page(page); if (folio != folio0) {
kunmap(page); folio_unlock(folio);
put_page(page); folio_put(folio);
} }
goto out_unmap; goto out_unmap;
......
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