porting.rst 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. ====================
  2. Changes since 2.5.0:
  3. ====================
  4. ---
  5. **recommended**
  6. New helpers: sb_bread(), sb_getblk(), sb_find_get_block(), set_bh(),
  7. sb_set_blocksize() and sb_min_blocksize().
  8. Use them.
  9. (sb_find_get_block() replaces 2.4's get_hash_table())
  10. ---
  11. **recommended**
  12. New methods: ->alloc_inode() and ->destroy_inode().
  13. Remove inode->u.foo_inode_i
  14. Declare::
  15. struct foo_inode_info {
  16. /* fs-private stuff */
  17. struct inode vfs_inode;
  18. };
  19. static inline struct foo_inode_info *FOO_I(struct inode *inode)
  20. {
  21. return list_entry(inode, struct foo_inode_info, vfs_inode);
  22. }
  23. Use FOO_I(inode) instead of &inode->u.foo_inode_i;
  24. Add foo_alloc_inode() and foo_destroy_inode() - the former should allocate
  25. foo_inode_info and return the address of ->vfs_inode, the latter should free
  26. FOO_I(inode) (see in-tree filesystems for examples).
  27. Make them ->alloc_inode and ->destroy_inode in your super_operations.
  28. Keep in mind that now you need explicit initialization of private data
  29. typically between calling iget_locked() and unlocking the inode.
  30. At some point that will become mandatory.
  31. **mandatory**
  32. The foo_inode_info should always be allocated through alloc_inode_sb() rather
  33. than kmem_cache_alloc() or kmalloc() related to set up the inode reclaim context
  34. correctly.
  35. ---
  36. **mandatory**
  37. Change of file_system_type method (->read_super to ->get_sb)
  38. ->read_super() is no more. Ditto for DECLARE_FSTYPE and DECLARE_FSTYPE_DEV.
  39. Turn your foo_read_super() into a function that would return 0 in case of
  40. success and negative number in case of error (-EINVAL unless you have more
  41. informative error value to report). Call it foo_fill_super(). Now declare::
  42. int foo_get_sb(struct file_system_type *fs_type,
  43. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  44. {
  45. return get_sb_bdev(fs_type, flags, dev_name, data, foo_fill_super,
  46. mnt);
  47. }
  48. (or similar with s/bdev/nodev/ or s/bdev/single/, depending on the kind of
  49. filesystem).
  50. Replace DECLARE_FSTYPE... with explicit initializer and have ->get_sb set as
  51. foo_get_sb.
  52. ---
  53. **mandatory**
  54. Locking change: ->s_vfs_rename_sem is taken only by cross-directory renames.
  55. Most likely there is no need to change anything, but if you relied on
  56. global exclusion between renames for some internal purpose - you need to
  57. change your internal locking. Otherwise exclusion warranties remain the
  58. same (i.e. parents and victim are locked, etc.).
  59. ---
  60. **informational**
  61. Now we have the exclusion between ->lookup() and directory removal (by
  62. ->rmdir() and ->rename()). If you used to need that exclusion and do
  63. it by internal locking (most of filesystems couldn't care less) - you
  64. can relax your locking.
  65. ---
  66. **mandatory**
  67. ->lookup(), ->truncate(), ->create(), ->unlink(), ->mknod(), ->mkdir(),
  68. ->rmdir(), ->link(), ->lseek(), ->symlink(), ->rename()
  69. and ->readdir() are called without BKL now. Grab it on entry, drop upon return
  70. - that will guarantee the same locking you used to have. If your method or its
  71. parts do not need BKL - better yet, now you can shift lock_kernel() and
  72. unlock_kernel() so that they would protect exactly what needs to be
  73. protected.
  74. ---
  75. **mandatory**
  76. BKL is also moved from around sb operations. BKL should have been shifted into
  77. individual fs sb_op functions. If you don't need it, remove it.
  78. ---
  79. **informational**
  80. check for ->link() target not being a directory is done by callers. Feel
  81. free to drop it...
  82. ---
  83. **informational**
  84. ->link() callers hold ->i_mutex on the object we are linking to. Some of your
  85. problems might be over...
  86. ---
  87. **mandatory**
  88. new file_system_type method - kill_sb(superblock). If you are converting
  89. an existing filesystem, set it according to ->fs_flags::
  90. FS_REQUIRES_DEV - kill_block_super
  91. FS_LITTER - kill_litter_super
  92. neither - kill_anon_super
  93. FS_LITTER is gone - just remove it from fs_flags.
  94. ---
  95. **mandatory**
  96. FS_SINGLE is gone (actually, that had happened back when ->get_sb()
  97. went in - and hadn't been documented ;-/). Just remove it from fs_flags
  98. (and see ->get_sb() entry for other actions).
  99. ---
  100. **mandatory**
  101. ->setattr() is called without BKL now. Caller _always_ holds ->i_mutex, so
  102. watch for ->i_mutex-grabbing code that might be used by your ->setattr().
  103. Callers of notify_change() need ->i_mutex now.
  104. ---
  105. **recommended**
  106. New super_block field ``struct export_operations *s_export_op`` for
  107. explicit support for exporting, e.g. via NFS. The structure is fully
  108. documented at its declaration in include/linux/fs.h, and in
  109. Documentation/filesystems/nfs/exporting.rst.
  110. Briefly it allows for the definition of decode_fh and encode_fh operations
  111. to encode and decode filehandles, and allows the filesystem to use
  112. a standard helper function for decode_fh, and provide file-system specific
  113. support for this helper, particularly get_parent.
  114. It is planned that this will be required for exporting once the code
  115. settles down a bit.
  116. **mandatory**
  117. s_export_op is now required for exporting a filesystem.
  118. isofs, ext2, ext3, reiserfs, fat
  119. can be used as examples of very different filesystems.
  120. ---
  121. **mandatory**
  122. iget4() and the read_inode2 callback have been superseded by iget5_locked()
  123. which has the following prototype::
  124. struct inode *iget5_locked(struct super_block *sb, unsigned long ino,
  125. int (*test)(struct inode *, void *),
  126. int (*set)(struct inode *, void *),
  127. void *data);
  128. 'test' is an additional function that can be used when the inode
  129. number is not sufficient to identify the actual file object. 'set'
  130. should be a non-blocking function that initializes those parts of a
  131. newly created inode to allow the test function to succeed. 'data' is
  132. passed as an opaque value to both test and set functions.
  133. When the inode has been created by iget5_locked(), it will be returned with the
  134. I_NEW flag set and will still be locked. The filesystem then needs to finalize
  135. the initialization. Once the inode is initialized it must be unlocked by
  136. calling unlock_new_inode().
  137. The filesystem is responsible for setting (and possibly testing) i_ino
  138. when appropriate. There is also a simpler iget_locked function that
  139. just takes the superblock and inode number as arguments and does the
  140. test and set for you.
  141. e.g.::
  142. inode = iget_locked(sb, ino);
  143. if (inode->i_state & I_NEW) {
  144. err = read_inode_from_disk(inode);
  145. if (err < 0) {
  146. iget_failed(inode);
  147. return err;
  148. }
  149. unlock_new_inode(inode);
  150. }
  151. Note that if the process of setting up a new inode fails, then iget_failed()
  152. should be called on the inode to render it dead, and an appropriate error
  153. should be passed back to the caller.
  154. ---
  155. **recommended**
  156. ->getattr() finally getting used. See instances in nfs, minix, etc.
  157. ---
  158. **mandatory**
  159. ->revalidate() is gone. If your filesystem had it - provide ->getattr()
  160. and let it call whatever you had as ->revlidate() + (for symlinks that
  161. had ->revalidate()) add calls in ->follow_link()/->readlink().
  162. ---
  163. **mandatory**
  164. ->d_parent changes are not protected by BKL anymore. Read access is safe
  165. if at least one of the following is true:
  166. * filesystem has no cross-directory rename()
  167. * we know that parent had been locked (e.g. we are looking at
  168. ->d_parent of ->lookup() argument).
  169. * we are called from ->rename().
  170. * the child's ->d_lock is held
  171. Audit your code and add locking if needed. Notice that any place that is
  172. not protected by the conditions above is risky even in the old tree - you
  173. had been relying on BKL and that's prone to screwups. Old tree had quite
  174. a few holes of that kind - unprotected access to ->d_parent leading to
  175. anything from oops to silent memory corruption.
  176. ---
  177. **mandatory**
  178. FS_NOMOUNT is gone. If you use it - just set SB_NOUSER in flags
  179. (see rootfs for one kind of solution and bdev/socket/pipe for another).
  180. ---
  181. **recommended**
  182. Use bdev_read_only(bdev) instead of is_read_only(kdev). The latter
  183. is still alive, but only because of the mess in drivers/s390/block/dasd.c.
  184. As soon as it gets fixed is_read_only() will die.
  185. ---
  186. **mandatory**
  187. ->permission() is called without BKL now. Grab it on entry, drop upon
  188. return - that will guarantee the same locking you used to have. If
  189. your method or its parts do not need BKL - better yet, now you can
  190. shift lock_kernel() and unlock_kernel() so that they would protect
  191. exactly what needs to be protected.
  192. ---
  193. **mandatory**
  194. ->statfs() is now called without BKL held. BKL should have been
  195. shifted into individual fs sb_op functions where it's not clear that
  196. it's safe to remove it. If you don't need it, remove it.
  197. ---
  198. **mandatory**
  199. is_read_only() is gone; use bdev_read_only() instead.
  200. ---
  201. **mandatory**
  202. destroy_buffers() is gone; use invalidate_bdev().
  203. ---
  204. **mandatory**
  205. fsync_dev() is gone; use fsync_bdev(). NOTE: lvm breakage is
  206. deliberate; as soon as struct block_device * is propagated in a reasonable
  207. way by that code fixing will become trivial; until then nothing can be
  208. done.
  209. **mandatory**
  210. block truncatation on error exit from ->write_begin, and ->direct_IO
  211. moved from generic methods (block_write_begin, cont_write_begin,
  212. nobh_write_begin, blockdev_direct_IO*) to callers. Take a look at
  213. ext2_write_failed and callers for an example.
  214. **mandatory**
  215. ->truncate is gone. The whole truncate sequence needs to be
  216. implemented in ->setattr, which is now mandatory for filesystems
  217. implementing on-disk size changes. Start with a copy of the old inode_setattr
  218. and vmtruncate, and the reorder the vmtruncate + foofs_vmtruncate sequence to
  219. be in order of zeroing blocks using block_truncate_page or similar helpers,
  220. size update and on finally on-disk truncation which should not fail.
  221. setattr_prepare (which used to be inode_change_ok) now includes the size checks
  222. for ATTR_SIZE and must be called in the beginning of ->setattr unconditionally.
  223. **mandatory**
  224. ->clear_inode() and ->delete_inode() are gone; ->evict_inode() should
  225. be used instead. It gets called whenever the inode is evicted, whether it has
  226. remaining links or not. Caller does *not* evict the pagecache or inode-associated
  227. metadata buffers; the method has to use truncate_inode_pages_final() to get rid
  228. of those. Caller makes sure async writeback cannot be running for the inode while
  229. (or after) ->evict_inode() is called.
  230. ->drop_inode() returns int now; it's called on final iput() with
  231. inode->i_lock held and it returns true if filesystems wants the inode to be
  232. dropped. As before, generic_drop_inode() is still the default and it's been
  233. updated appropriately. generic_delete_inode() is also alive and it consists
  234. simply of return 1. Note that all actual eviction work is done by caller after
  235. ->drop_inode() returns.
  236. As before, clear_inode() must be called exactly once on each call of
  237. ->evict_inode() (as it used to be for each call of ->delete_inode()). Unlike
  238. before, if you are using inode-associated metadata buffers (i.e.
  239. mark_buffer_dirty_inode()), it's your responsibility to call
  240. invalidate_inode_buffers() before clear_inode().
  241. NOTE: checking i_nlink in the beginning of ->write_inode() and bailing out
  242. if it's zero is not *and* *never* *had* *been* enough. Final unlink() and iput()
  243. may happen while the inode is in the middle of ->write_inode(); e.g. if you blindly
  244. free the on-disk inode, you may end up doing that while ->write_inode() is writing
  245. to it.
  246. ---
  247. **mandatory**
  248. .d_delete() now only advises the dcache as to whether or not to cache
  249. unreferenced dentries, and is now only called when the dentry refcount goes to
  250. 0. Even on 0 refcount transition, it must be able to tolerate being called 0,
  251. 1, or more times (eg. constant, idempotent).
  252. ---
  253. **mandatory**
  254. .d_compare() calling convention and locking rules are significantly
  255. changed. Read updated documentation in Documentation/filesystems/vfs.rst (and
  256. look at examples of other filesystems) for guidance.
  257. ---
  258. **mandatory**
  259. .d_hash() calling convention and locking rules are significantly
  260. changed. Read updated documentation in Documentation/filesystems/vfs.rst (and
  261. look at examples of other filesystems) for guidance.
  262. ---
  263. **mandatory**
  264. dcache_lock is gone, replaced by fine grained locks. See fs/dcache.c
  265. for details of what locks to replace dcache_lock with in order to protect
  266. particular things. Most of the time, a filesystem only needs ->d_lock, which
  267. protects *all* the dcache state of a given dentry.
  268. ---
  269. **mandatory**
  270. Filesystems must RCU-free their inodes, if they can have been accessed
  271. via rcu-walk path walk (basically, if the file can have had a path name in the
  272. vfs namespace).
  273. Even though i_dentry and i_rcu share storage in a union, we will
  274. initialize the former in inode_init_always(), so just leave it alone in
  275. the callback. It used to be necessary to clean it there, but not anymore
  276. (starting at 3.2).
  277. ---
  278. **recommended**
  279. vfs now tries to do path walking in "rcu-walk mode", which avoids
  280. atomic operations and scalability hazards on dentries and inodes (see
  281. Documentation/filesystems/path-lookup.txt). d_hash and d_compare changes
  282. (above) are examples of the changes required to support this. For more complex
  283. filesystem callbacks, the vfs drops out of rcu-walk mode before the fs call, so
  284. no changes are required to the filesystem. However, this is costly and loses
  285. the benefits of rcu-walk mode. We will begin to add filesystem callbacks that
  286. are rcu-walk aware, shown below. Filesystems should take advantage of this
  287. where possible.
  288. ---
  289. **mandatory**
  290. d_revalidate is a callback that is made on every path element (if
  291. the filesystem provides it), which requires dropping out of rcu-walk mode. This
  292. may now be called in rcu-walk mode (nd->flags & LOOKUP_RCU). -ECHILD should be
  293. returned if the filesystem cannot handle rcu-walk. See
  294. Documentation/filesystems/vfs.rst for more details.
  295. permission is an inode permission check that is called on many or all
  296. directory inodes on the way down a path walk (to check for exec permission). It
  297. must now be rcu-walk aware (mask & MAY_NOT_BLOCK). See
  298. Documentation/filesystems/vfs.rst for more details.
  299. ---
  300. **mandatory**
  301. In ->fallocate() you must check the mode option passed in. If your
  302. filesystem does not support hole punching (deallocating space in the middle of a
  303. file) you must return -EOPNOTSUPP if FALLOC_FL_PUNCH_HOLE is set in mode.
  304. Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
  305. so the i_size should not change when hole punching, even when puching the end of
  306. a file off.
  307. ---
  308. **mandatory**
  309. ->get_sb() is gone. Switch to use of ->mount(). Typically it's just
  310. a matter of switching from calling ``get_sb_``... to ``mount_``... and changing
  311. the function type. If you were doing it manually, just switch from setting
  312. ->mnt_root to some pointer to returning that pointer. On errors return
  313. ERR_PTR(...).
  314. ---
  315. **mandatory**
  316. ->permission() and generic_permission()have lost flags
  317. argument; instead of passing IPERM_FLAG_RCU we add MAY_NOT_BLOCK into mask.
  318. generic_permission() has also lost the check_acl argument; ACL checking
  319. has been taken to VFS and filesystems need to provide a non-NULL
  320. ->i_op->get_inode_acl to read an ACL from disk.
  321. ---
  322. **mandatory**
  323. If you implement your own ->llseek() you must handle SEEK_HOLE and
  324. SEEK_DATA. You can handle this by returning -EINVAL, but it would be nicer to
  325. support it in some way. The generic handler assumes that the entire file is
  326. data and there is a virtual hole at the end of the file. So if the provided
  327. offset is less than i_size and SEEK_DATA is specified, return the same offset.
  328. If the above is true for the offset and you are given SEEK_HOLE, return the end
  329. of the file. If the offset is i_size or greater return -ENXIO in either case.
  330. **mandatory**
  331. If you have your own ->fsync() you must make sure to call
  332. filemap_write_and_wait_range() so that all dirty pages are synced out properly.
  333. You must also keep in mind that ->fsync() is not called with i_mutex held
  334. anymore, so if you require i_mutex locking you must make sure to take it and
  335. release it yourself.
  336. ---
  337. **mandatory**
  338. d_alloc_root() is gone, along with a lot of bugs caused by code
  339. misusing it. Replacement: d_make_root(inode). On success d_make_root(inode)
  340. allocates and returns a new dentry instantiated with the passed in inode.
  341. On failure NULL is returned and the passed in inode is dropped so the reference
  342. to inode is consumed in all cases and failure handling need not do any cleanup
  343. for the inode. If d_make_root(inode) is passed a NULL inode it returns NULL
  344. and also requires no further error handling. Typical usage is::
  345. inode = foofs_new_inode(....);
  346. s->s_root = d_make_root(inode);
  347. if (!s->s_root)
  348. /* Nothing needed for the inode cleanup */
  349. return -ENOMEM;
  350. ...
  351. ---
  352. **mandatory**
  353. The witch is dead! Well, 2/3 of it, anyway. ->d_revalidate() and
  354. ->lookup() do *not* take struct nameidata anymore; just the flags.
  355. ---
  356. **mandatory**
  357. ->create() doesn't take ``struct nameidata *``; unlike the previous
  358. two, it gets "is it an O_EXCL or equivalent?" boolean argument. Note that
  359. local filesystems can ignore this argument - they are guaranteed that the
  360. object doesn't exist. It's remote/distributed ones that might care...
  361. ---
  362. **mandatory**
  363. FS_REVAL_DOT is gone; if you used to have it, add ->d_weak_revalidate()
  364. in your dentry operations instead.
  365. ---
  366. **mandatory**
  367. vfs_readdir() is gone; switch to iterate_dir() instead
  368. ---
  369. **mandatory**
  370. ->readdir() is gone now; switch to ->iterate_shared()
  371. **mandatory**
  372. vfs_follow_link has been removed. Filesystems must use nd_set_link
  373. from ->follow_link for normal symlinks, or nd_jump_link for magic
  374. /proc/<pid> style links.
  375. ---
  376. **mandatory**
  377. iget5_locked()/ilookup5()/ilookup5_nowait() test() callback used to be
  378. called with both ->i_lock and inode_hash_lock held; the former is *not*
  379. taken anymore, so verify that your callbacks do not rely on it (none
  380. of the in-tree instances did). inode_hash_lock is still held,
  381. of course, so they are still serialized wrt removal from inode hash,
  382. as well as wrt set() callback of iget5_locked().
  383. ---
  384. **mandatory**
  385. d_materialise_unique() is gone; d_splice_alias() does everything you
  386. need now. Remember that they have opposite orders of arguments ;-/
  387. ---
  388. **mandatory**
  389. f_dentry is gone; use f_path.dentry, or, better yet, see if you can avoid
  390. it entirely.
  391. ---
  392. **mandatory**
  393. never call ->read() and ->write() directly; use __vfs_{read,write} or
  394. wrappers; instead of checking for ->write or ->read being NULL, look for
  395. FMODE_CAN_{WRITE,READ} in file->f_mode.
  396. ---
  397. **mandatory**
  398. do _not_ use new_sync_{read,write} for ->read/->write; leave it NULL
  399. instead.
  400. ---
  401. **mandatory**
  402. ->aio_read/->aio_write are gone. Use ->read_iter/->write_iter.
  403. ---
  404. **recommended**
  405. for embedded ("fast") symlinks just set inode->i_link to wherever the
  406. symlink body is and use simple_follow_link() as ->follow_link().
  407. ---
  408. **mandatory**
  409. calling conventions for ->follow_link() have changed. Instead of returning
  410. cookie and using nd_set_link() to store the body to traverse, we return
  411. the body to traverse and store the cookie using explicit void ** argument.
  412. nameidata isn't passed at all - nd_jump_link() doesn't need it and
  413. nd_[gs]et_link() is gone.
  414. ---
  415. **mandatory**
  416. calling conventions for ->put_link() have changed. It gets inode instead of
  417. dentry, it does not get nameidata at all and it gets called only when cookie
  418. is non-NULL. Note that link body isn't available anymore, so if you need it,
  419. store it as cookie.
  420. ---
  421. **mandatory**
  422. any symlink that might use page_follow_link_light/page_put_link() must
  423. have inode_nohighmem(inode) called before anything might start playing with
  424. its pagecache. No highmem pages should end up in the pagecache of such
  425. symlinks. That includes any preseeding that might be done during symlink
  426. creation. page_symlink() will honour the mapping gfp flags, so once
  427. you've done inode_nohighmem() it's safe to use, but if you allocate and
  428. insert the page manually, make sure to use the right gfp flags.
  429. ---
  430. **mandatory**
  431. ->follow_link() is replaced with ->get_link(); same API, except that
  432. * ->get_link() gets inode as a separate argument
  433. * ->get_link() may be called in RCU mode - in that case NULL
  434. dentry is passed
  435. ---
  436. **mandatory**
  437. ->get_link() gets struct delayed_call ``*done`` now, and should do
  438. set_delayed_call() where it used to set ``*cookie``.
  439. ->put_link() is gone - just give the destructor to set_delayed_call()
  440. in ->get_link().
  441. ---
  442. **mandatory**
  443. ->getxattr() and xattr_handler.get() get dentry and inode passed separately.
  444. dentry might be yet to be attached to inode, so do _not_ use its ->d_inode
  445. in the instances. Rationale: !@#!@# security_d_instantiate() needs to be
  446. called before we attach dentry to inode.
  447. ---
  448. **mandatory**
  449. symlinks are no longer the only inodes that do *not* have i_bdev/i_cdev/
  450. i_pipe/i_link union zeroed out at inode eviction. As the result, you can't
  451. assume that non-NULL value in ->i_nlink at ->destroy_inode() implies that
  452. it's a symlink. Checking ->i_mode is really needed now. In-tree we had
  453. to fix shmem_destroy_callback() that used to take that kind of shortcut;
  454. watch out, since that shortcut is no longer valid.
  455. ---
  456. **mandatory**
  457. ->i_mutex is replaced with ->i_rwsem now. inode_lock() et.al. work as
  458. they used to - they just take it exclusive. However, ->lookup() may be
  459. called with parent locked shared. Its instances must not
  460. * use d_instantiate) and d_rehash() separately - use d_add() or
  461. d_splice_alias() instead.
  462. * use d_rehash() alone - call d_add(new_dentry, NULL) instead.
  463. * in the unlikely case when (read-only) access to filesystem
  464. data structures needs exclusion for some reason, arrange it
  465. yourself. None of the in-tree filesystems needed that.
  466. * rely on ->d_parent and ->d_name not changing after dentry has
  467. been fed to d_add() or d_splice_alias(). Again, none of the
  468. in-tree instances relied upon that.
  469. We are guaranteed that lookups of the same name in the same directory
  470. will not happen in parallel ("same" in the sense of your ->d_compare()).
  471. Lookups on different names in the same directory can and do happen in
  472. parallel now.
  473. ---
  474. **mandatory**
  475. ->iterate_shared() is added.
  476. Exclusion on struct file level is still provided (as well as that
  477. between it and lseek on the same struct file), but if your directory
  478. has been opened several times, you can get these called in parallel.
  479. Exclusion between that method and all directory-modifying ones is
  480. still provided, of course.
  481. If you have any per-inode or per-dentry in-core data structures modified
  482. by ->iterate_shared(), you might need something to serialize the access
  483. to them. If you do dcache pre-seeding, you'll need to switch to
  484. d_alloc_parallel() for that; look for in-tree examples.
  485. ---
  486. **mandatory**
  487. ->atomic_open() calls without O_CREAT may happen in parallel.
  488. ---
  489. **mandatory**
  490. ->setxattr() and xattr_handler.set() get dentry and inode passed separately.
  491. The xattr_handler.set() gets passed the user namespace of the mount the inode
  492. is seen from so filesystems can idmap the i_uid and i_gid accordingly.
  493. dentry might be yet to be attached to inode, so do _not_ use its ->d_inode
  494. in the instances. Rationale: !@#!@# security_d_instantiate() needs to be
  495. called before we attach dentry to inode and !@#!@##!@$!$#!@#$!@$!@$ smack
  496. ->d_instantiate() uses not just ->getxattr() but ->setxattr() as well.
  497. ---
  498. **mandatory**
  499. ->d_compare() doesn't get parent as a separate argument anymore. If you
  500. used it for finding the struct super_block involved, dentry->d_sb will
  501. work just as well; if it's something more complicated, use dentry->d_parent.
  502. Just be careful not to assume that fetching it more than once will yield
  503. the same value - in RCU mode it could change under you.
  504. ---
  505. **mandatory**
  506. ->rename() has an added flags argument. Any flags not handled by the
  507. filesystem should result in EINVAL being returned.
  508. ---
  509. **recommended**
  510. ->readlink is optional for symlinks. Don't set, unless filesystem needs
  511. to fake something for readlink(2).
  512. ---
  513. **mandatory**
  514. ->getattr() is now passed a struct path rather than a vfsmount and
  515. dentry separately, and it now has request_mask and query_flags arguments
  516. to specify the fields and sync type requested by statx. Filesystems not
  517. supporting any statx-specific features may ignore the new arguments.
  518. ---
  519. **mandatory**
  520. ->atomic_open() calling conventions have changed. Gone is ``int *opened``,
  521. along with FILE_OPENED/FILE_CREATED. In place of those we have
  522. FMODE_OPENED/FMODE_CREATED, set in file->f_mode. Additionally, return
  523. value for 'called finish_no_open(), open it yourself' case has become
  524. 0, not 1. Since finish_no_open() itself is returning 0 now, that part
  525. does not need any changes in ->atomic_open() instances.
  526. ---
  527. **mandatory**
  528. alloc_file() has become static now; two wrappers are to be used instead.
  529. alloc_file_pseudo(inode, vfsmount, name, flags, ops) is for the cases
  530. when dentry needs to be created; that's the majority of old alloc_file()
  531. users. Calling conventions: on success a reference to new struct file
  532. is returned and callers reference to inode is subsumed by that. On
  533. failure, ERR_PTR() is returned and no caller's references are affected,
  534. so the caller needs to drop the inode reference it held.
  535. alloc_file_clone(file, flags, ops) does not affect any caller's references.
  536. On success you get a new struct file sharing the mount/dentry with the
  537. original, on failure - ERR_PTR().
  538. ---
  539. **mandatory**
  540. ->clone_file_range() and ->dedupe_file_range have been replaced with
  541. ->remap_file_range(). See Documentation/filesystems/vfs.rst for more
  542. information.
  543. ---
  544. **recommended**
  545. ->lookup() instances doing an equivalent of::
  546. if (IS_ERR(inode))
  547. return ERR_CAST(inode);
  548. return d_splice_alias(inode, dentry);
  549. don't need to bother with the check - d_splice_alias() will do the
  550. right thing when given ERR_PTR(...) as inode. Moreover, passing NULL
  551. inode to d_splice_alias() will also do the right thing (equivalent of
  552. d_add(dentry, NULL); return NULL;), so that kind of special cases
  553. also doesn't need a separate treatment.
  554. ---
  555. **strongly recommended**
  556. take the RCU-delayed parts of ->destroy_inode() into a new method -
  557. ->free_inode(). If ->destroy_inode() becomes empty - all the better,
  558. just get rid of it. Synchronous work (e.g. the stuff that can't
  559. be done from an RCU callback, or any WARN_ON() where we want the
  560. stack trace) *might* be movable to ->evict_inode(); however,
  561. that goes only for the things that are not needed to balance something
  562. done by ->alloc_inode(). IOW, if it's cleaning up the stuff that
  563. might have accumulated over the life of in-core inode, ->evict_inode()
  564. might be a fit.
  565. Rules for inode destruction:
  566. * if ->destroy_inode() is non-NULL, it gets called
  567. * if ->free_inode() is non-NULL, it gets scheduled by call_rcu()
  568. * combination of NULL ->destroy_inode and NULL ->free_inode is
  569. treated as NULL/free_inode_nonrcu, to preserve the compatibility.
  570. Note that the callback (be it via ->free_inode() or explicit call_rcu()
  571. in ->destroy_inode()) is *NOT* ordered wrt superblock destruction;
  572. as the matter of fact, the superblock and all associated structures
  573. might be already gone. The filesystem driver is guaranteed to be still
  574. there, but that's it. Freeing memory in the callback is fine; doing
  575. more than that is possible, but requires a lot of care and is best
  576. avoided.
  577. ---
  578. **mandatory**
  579. DCACHE_RCUACCESS is gone; having an RCU delay on dentry freeing is the
  580. default. DCACHE_NORCU opts out, and only d_alloc_pseudo() has any
  581. business doing so.
  582. ---
  583. **mandatory**
  584. d_alloc_pseudo() is internal-only; uses outside of alloc_file_pseudo() are
  585. very suspect (and won't work in modules). Such uses are very likely to
  586. be misspelled d_alloc_anon().
  587. ---
  588. **mandatory**
  589. [should've been added in 2016] stale comment in finish_open() notwithstanding,
  590. failure exits in ->atomic_open() instances should *NOT* fput() the file,
  591. no matter what. Everything is handled by the caller.
  592. ---
  593. **mandatory**
  594. clone_private_mount() returns a longterm mount now, so the proper destructor of
  595. its result is kern_unmount() or kern_unmount_array().
  596. ---
  597. **mandatory**
  598. zero-length bvec segments are disallowed, they must be filtered out before
  599. passed on to an iterator.
  600. ---
  601. **mandatory**
  602. For bvec based itererators bio_iov_iter_get_pages() now doesn't copy bvecs but
  603. uses the one provided. Anyone issuing kiocb-I/O should ensure that the bvec and
  604. page references stay until I/O has completed, i.e. until ->ki_complete() has
  605. been called or returned with non -EIOCBQUEUED code.
  606. ---
  607. **mandatory**
  608. mnt_want_write_file() can now only be paired with mnt_drop_write_file(),
  609. whereas previously it could be paired with mnt_drop_write() as well.
  610. ---
  611. **mandatory**
  612. iov_iter_copy_from_user_atomic() is gone; use copy_page_from_iter_atomic().
  613. The difference is copy_page_from_iter_atomic() advances the iterator and
  614. you don't need iov_iter_advance() after it. However, if you decide to use
  615. only a part of obtained data, you should do iov_iter_revert().
  616. ---
  617. **mandatory**
  618. Calling conventions for file_open_root() changed; now it takes struct path *
  619. instead of passing mount and dentry separately. For callers that used to
  620. pass <mnt, mnt->mnt_root> pair (i.e. the root of given mount), a new helper
  621. is provided - file_open_root_mnt(). In-tree users adjusted.
  622. ---
  623. **mandatory**
  624. no_llseek is gone; don't set .llseek to that - just leave it NULL instead.
  625. Checks for "does that file have llseek(2), or should it fail with ESPIPE"
  626. should be done by looking at FMODE_LSEEK in file->f_mode.
  627. ---
  628. *mandatory*
  629. filldir_t (readdir callbacks) calling conventions have changed. Instead of
  630. returning 0 or -E... it returns bool now. false means "no more" (as -E... used
  631. to) and true - "keep going" (as 0 in old calling conventions). Rationale:
  632. callers never looked at specific -E... values anyway. -> iterate_shared()
  633. instances require no changes at all, all filldir_t ones in the tree
  634. converted.
  635. ---
  636. **mandatory**
  637. Calling conventions for ->tmpfile() have changed. It now takes a struct
  638. file pointer instead of struct dentry pointer. d_tmpfile() is similarly
  639. changed to simplify callers. The passed file is in a non-open state and on
  640. success must be opened before returning (e.g. by calling
  641. finish_open_simple()).
  642. ---
  643. **mandatory**
  644. Calling convention for ->huge_fault has changed. It now takes a page
  645. order instead of an enum page_entry_size, and it may be called without the
  646. mmap_lock held. All in-tree users have been audited and do not seem to
  647. depend on the mmap_lock being held, but out of tree users should verify
  648. for themselves. If they do need it, they can return VM_FAULT_RETRY to
  649. be called with the mmap_lock held.
  650. ---
  651. **mandatory**
  652. The order of opening block devices and matching or creating superblocks has
  653. changed.
  654. The old logic opened block devices first and then tried to find a
  655. suitable superblock to reuse based on the block device pointer.
  656. The new logic tries to find a suitable superblock first based on the device
  657. number, and opening the block device afterwards.
  658. Since opening block devices cannot happen under s_umount because of lock
  659. ordering requirements s_umount is now dropped while opening block devices and
  660. reacquired before calling fill_super().
  661. In the old logic concurrent mounters would find the superblock on the list of
  662. superblocks for the filesystem type. Since the first opener of the block device
  663. would hold s_umount they would wait until the superblock became either born or
  664. was discarded due to initialization failure.
  665. Since the new logic drops s_umount concurrent mounters could grab s_umount and
  666. would spin. Instead they are now made to wait using an explicit wait-wake
  667. mechanism without having to hold s_umount.
  668. ---
  669. **mandatory**
  670. The holder of a block device is now the superblock.
  671. The holder of a block device used to be the file_system_type which wasn't
  672. particularly useful. It wasn't possible to go from block device to owning
  673. superblock without matching on the device pointer stored in the superblock.
  674. This mechanism would only work for a single device so the block layer couldn't
  675. find the owning superblock of any additional devices.
  676. In the old mechanism reusing or creating a superblock for a racing mount(2) and
  677. umount(2) relied on the file_system_type as the holder. This was severely
  678. underdocumented however:
  679. (1) Any concurrent mounter that managed to grab an active reference on an
  680. existing superblock was made to wait until the superblock either became
  681. ready or until the superblock was removed from the list of superblocks of
  682. the filesystem type. If the superblock is ready the caller would simple
  683. reuse it.
  684. (2) If the mounter came after deactivate_locked_super() but before
  685. the superblock had been removed from the list of superblocks of the
  686. filesystem type the mounter would wait until the superblock was shutdown,
  687. reuse the block device and allocate a new superblock.
  688. (3) If the mounter came after deactivate_locked_super() and after
  689. the superblock had been removed from the list of superblocks of the
  690. filesystem type the mounter would reuse the block device and allocate a new
  691. superblock (the bd_holder point may still be set to the filesystem type).
  692. Because the holder of the block device was the file_system_type any concurrent
  693. mounter could open the block devices of any superblock of the same
  694. file_system_type without risking seeing EBUSY because the block device was
  695. still in use by another superblock.
  696. Making the superblock the owner of the block device changes this as the holder
  697. is now a unique superblock and thus block devices associated with it cannot be
  698. reused by concurrent mounters. So a concurrent mounter in (2) could suddenly
  699. see EBUSY when trying to open a block device whose holder was a different
  700. superblock.
  701. The new logic thus waits until the superblock and the devices are shutdown in
  702. ->kill_sb(). Removal of the superblock from the list of superblocks of the
  703. filesystem type is now moved to a later point when the devices are closed:
  704. (1) Any concurrent mounter managing to grab an active reference on an existing
  705. superblock is made to wait until the superblock is either ready or until
  706. the superblock and all devices are shutdown in ->kill_sb(). If the
  707. superblock is ready the caller will simply reuse it.
  708. (2) If the mounter comes after deactivate_locked_super() but before
  709. the superblock has been removed from the list of superblocks of the
  710. filesystem type the mounter is made to wait until the superblock and the
  711. devices are shut down in ->kill_sb() and the superblock is removed from the
  712. list of superblocks of the filesystem type. The mounter will allocate a new
  713. superblock and grab ownership of the block device (the bd_holder pointer of
  714. the block device will be set to the newly allocated superblock).
  715. (3) This case is now collapsed into (2) as the superblock is left on the list
  716. of superblocks of the filesystem type until all devices are shutdown in
  717. ->kill_sb(). In other words, if the superblock isn't on the list of
  718. superblock of the filesystem type anymore then it has given up ownership of
  719. all associated block devices (the bd_holder pointer is NULL).
  720. As this is a VFS level change it has no practical consequences for filesystems
  721. other than that all of them must use one of the provided kill_litter_super(),
  722. kill_anon_super(), or kill_block_super() helpers.
  723. ---
  724. **mandatory**
  725. Lock ordering has been changed so that s_umount ranks above open_mutex again.
  726. All places where s_umount was taken under open_mutex have been fixed up.
  727. ---
  728. **mandatory**
  729. export_operations ->encode_fh() no longer has a default implementation to
  730. encode FILEID_INO32_GEN* file handles.
  731. Filesystems that used the default implementation may use the generic helper
  732. generic_encode_ino32_fh() explicitly.
  733. ---
  734. **mandatory**
  735. If ->rename() update of .. on cross-directory move needs an exclusion with
  736. directory modifications, do *not* lock the subdirectory in question in your
  737. ->rename() - it's done by the caller now [that item should've been added in
  738. 28eceeda130f "fs: Lock moved directories"].
  739. ---
  740. **mandatory**
  741. On same-directory ->rename() the (tautological) update of .. is not protected
  742. by any locks; just don't do it if the old parent is the same as the new one.
  743. We really can't lock two subdirectories in same-directory rename - not without
  744. deadlocks.
  745. ---
  746. **mandatory**
  747. lock_rename() and lock_rename_child() may fail in cross-directory case, if
  748. their arguments do not have a common ancestor. In that case ERR_PTR(-EXDEV)
  749. is returned, with no locks taken. In-tree users updated; out-of-tree ones
  750. would need to do so.
  751. ---
  752. **mandatory**
  753. The list of children anchored in parent dentry got turned into hlist now.
  754. Field names got changed (->d_children/->d_sib instead of ->d_subdirs/->d_child
  755. for anchor/entries resp.), so any affected places will be immediately caught
  756. by compiler.
  757. ---
  758. **mandatory**
  759. ->d_delete() instances are now called for dentries with ->d_lock held
  760. and refcount equal to 0. They are not permitted to drop/regain ->d_lock.
  761. None of in-tree instances did anything of that sort. Make sure yours do not...
  762. ---
  763. **mandatory**
  764. ->d_prune() instances are now called without ->d_lock held on the parent.
  765. ->d_lock on dentry itself is still held; if you need per-parent exclusions (none
  766. of the in-tree instances did), use your own spinlock.
  767. ->d_iput() and ->d_release() are called with victim dentry still in the
  768. list of parent's children. It is still unhashed, marked killed, etc., just not
  769. removed from parent's ->d_children yet.
  770. Anyone iterating through the list of children needs to be aware of the
  771. half-killed dentries that might be seen there; taking ->d_lock on those will
  772. see them negative, unhashed and with negative refcount, which means that most
  773. of the in-kernel users would've done the right thing anyway without any adjustment.
  774. ---
  775. **recommended**
  776. Block device freezing and thawing have been moved to holder operations.
  777. Before this change, get_active_super() would only be able to find the
  778. superblock of the main block device, i.e., the one stored in sb->s_bdev. Block
  779. device freezing now works for any block device owned by a given superblock, not
  780. just the main block device. The get_active_super() helper and bd_fsfreeze_sb
  781. pointer are gone.
  782. ---
  783. **mandatory**
  784. set_blocksize() takes opened struct file instead of struct block_device now
  785. and it *must* be opened exclusive.