)]}'
{
  "commit": "b4da738055acf42e00535c52b60d9bef808a7464",
  "tree": "b2ed4fb5079e4b21eba8c7594bf4eacdc35ba622",
  "parents": [
    "9f9623fc9340af731c3f3a09e6e9af0756b38a46"
  ],
  "author": {
    "name": "Eric Biggers",
    "email": "ebiggers@google.com",
    "time": "Mon Jan 25 12:05:09 2021 -0800"
  },
  "committer": {
    "name": "Greg Kroah-Hartman",
    "email": "gregkh@linuxfoundation.org",
    "time": "Sat Jan 30 13:32:13 2021 +0100"
  },
  "message": "fs: fix lazytime expiration handling in __writeback_single_inode()\n\ncommit 1e249cb5b7fc09ff216aa5a12f6c302e434e88f9 upstream.\n\nWhen lazytime is enabled and an inode is being written due to its\nin-memory updated timestamps having expired, either due to a sync() or\nsyncfs() system call or due to dirtytime_expire_interval having elapsed,\nthe VFS needs to inform the filesystem so that the filesystem can copy\nthe inode\u0027s timestamps out to the on-disk data structures.\n\nThis is done by __writeback_single_inode() calling\nmark_inode_dirty_sync(), which then calls -\u003edirty_inode(I_DIRTY_SYNC).\n\nHowever, this occurs after __writeback_single_inode() has already\ncleared the dirty flags from -\u003ei_state.  This causes two bugs:\n\n- mark_inode_dirty_sync() redirties the inode, causing it to remain\n  dirty.  This wastefully causes the inode to be written twice.  But\n  more importantly, it breaks cases where sync_filesystem() is expected\n  to clean dirty inodes.  This includes the FS_IOC_REMOVE_ENCRYPTION_KEY\n  ioctl (as reported at\n  https://lore.kernel.org/r/20200306004555.GB225345@gmail.com), as well\n  as possibly filesystem freezing (freeze_super()).\n\n- Since -\u003ei_state doesn\u0027t contain I_DIRTY_TIME when -\u003edirty_inode() is\n  called from __writeback_single_inode() for lazytime expiration,\n  xfs_fs_dirty_inode() ignores the notification.  (XFS only cares about\n  lazytime expirations, and it assumes that i_state will contain\n  I_DIRTY_TIME during those.)  Therefore, lazy timestamps aren\u0027t\n  persisted by sync(), syncfs(), or dirtytime_expire_interval on XFS.\n\nFix this by moving the call to mark_inode_dirty_sync() to earlier in\n__writeback_single_inode(), before the dirty flags are cleared from\ni_state.  This makes filesystems be properly notified of the timestamp\nexpiration, and it avoids incorrectly redirtying the inode.\n\nThis fixes xfstest generic/580 (which tests\nFS_IOC_REMOVE_ENCRYPTION_KEY) when run on ext4 or f2fs with lazytime\nenabled.  It also fixes the new lazytime xfstest I\u0027ve proposed, which\nreproduces the above-mentioned XFS bug\n(https://lore.kernel.org/r/20210105005818.92978-1-ebiggers@kernel.org).\n\nAlternatively, we could call -\u003edirty_inode(I_DIRTY_SYNC) directly.  But\ndue to the introduction of I_SYNC_QUEUED, mark_inode_dirty_sync() is the\nright thing to do because mark_inode_dirty_sync() now knows not to move\nthe inode to a writeback list if it is currently queued for sync.\n\nFixes: 0ae45f63d4ef (\"vfs: add support for a lazytime mount option\")\nCc: stable@vger.kernel.org\nDepends-on: 5afced3bf281 (\"writeback: Avoid skipping inode writeback\")\nLink: https://lore.kernel.org/r/20210112190253.64307-2-ebiggers@kernel.org\nSuggested-by: Jan Kara \u003cjack@suse.cz\u003e\nReviewed-by: Christoph Hellwig \u003chch@lst.de\u003e\nReviewed-by: Jan Kara \u003cjack@suse.cz\u003e\nSigned-off-by: Eric Biggers \u003cebiggers@google.com\u003e\nSigned-off-by: Jan Kara \u003cjack@suse.cz\u003e\nSigned-off-by: Greg Kroah-Hartman \u003cgregkh@linuxfoundation.org\u003e\n",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "96cdce0144efcbeded755064b00b5b30ee86b2e7",
      "old_mode": 33188,
      "old_path": "fs/fs-writeback.c",
      "new_id": "f2d0c4acb3cbb94958dc70d7115b89d2995f9d61",
      "new_mode": 33188,
      "new_path": "fs/fs-writeback.c"
    }
  ]
}
