Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nilfs: Convert nilfs_set_page_dirty() to nilfs_dirty_folio()

The comment about the page always being locked is wrong, so copy
the locking protection from __set_page_dirty_buffers(). That
means moving the call to nilfs_set_file_dirty() down the
function so as to not acquire a new dependency between the
mapping->private_lock and the ns_inode_lock. That might be a
harmless dependency to add, but it's not necessary.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Tested-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Acked-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
Tested-by: Mike Marshall <hubcap@omnibond.com> # orangefs
Tested-by: David Howells <dhowells@redhat.com> # afs

+19 -21
+19 -21
fs/nilfs2/inode.c
··· 199 199 return 0; 200 200 } 201 201 202 - static int nilfs_set_page_dirty(struct page *page) 202 + static bool nilfs_dirty_folio(struct address_space *mapping, 203 + struct folio *folio) 203 204 { 204 - struct inode *inode = page->mapping->host; 205 - int ret = __set_page_dirty_nobuffers(page); 205 + struct inode *inode = mapping->host; 206 + struct buffer_head *head; 207 + unsigned int nr_dirty = 0; 208 + bool ret = filemap_dirty_folio(mapping, folio); 206 209 207 - if (page_has_buffers(page)) { 208 - unsigned int nr_dirty = 0; 209 - struct buffer_head *bh, *head; 210 + /* 211 + * The page may not be locked, eg if called from try_to_unmap_one() 212 + */ 213 + spin_lock(&mapping->private_lock); 214 + head = folio_buffers(folio); 215 + if (head) { 216 + struct buffer_head *bh = head; 210 217 211 - /* 212 - * This page is locked by callers, and no other thread 213 - * concurrently marks its buffers dirty since they are 214 - * only dirtied through routines in fs/buffer.c in 215 - * which call sites of mark_buffer_dirty are protected 216 - * by page lock. 217 - */ 218 - bh = head = page_buffers(page); 219 218 do { 220 219 /* Do not mark hole blocks dirty */ 221 220 if (buffer_dirty(bh) || !buffer_mapped(bh)) ··· 223 224 set_buffer_dirty(bh); 224 225 nr_dirty++; 225 226 } while (bh = bh->b_this_page, bh != head); 226 - 227 - if (nr_dirty) 228 - nilfs_set_file_dirty(inode, nr_dirty); 229 227 } else if (ret) { 230 - unsigned int nr_dirty = 1 << (PAGE_SHIFT - inode->i_blkbits); 231 - 232 - nilfs_set_file_dirty(inode, nr_dirty); 228 + nr_dirty = 1 << (folio_shift(folio) - inode->i_blkbits); 233 229 } 230 + spin_unlock(&mapping->private_lock); 231 + 232 + if (nr_dirty) 233 + nilfs_set_file_dirty(inode, nr_dirty); 234 234 return ret; 235 235 } 236 236 ··· 297 299 .writepage = nilfs_writepage, 298 300 .readpage = nilfs_readpage, 299 301 .writepages = nilfs_writepages, 300 - .set_page_dirty = nilfs_set_page_dirty, 302 + .dirty_folio = nilfs_dirty_folio, 301 303 .readahead = nilfs_readahead, 302 304 .write_begin = nilfs_write_begin, 303 305 .write_end = nilfs_write_end,