porting 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. Changes since 2.5.0:
  2. ---
  3. [recommended]
  4. New helpers: sb_bread(), sb_getblk(), sb_find_get_block(), set_bh(),
  5. sb_set_blocksize() and sb_min_blocksize().
  6. Use them.
  7. (sb_find_get_block() replaces 2.4's get_hash_table())
  8. ---
  9. [recommended]
  10. New methods: ->alloc_inode() and ->destroy_inode().
  11. Remove inode->u.foo_inode_i
  12. Declare
  13. struct foo_inode_info {
  14. /* fs-private stuff */
  15. struct inode vfs_inode;
  16. };
  17. static inline struct foo_inode_info *FOO_I(struct inode *inode)
  18. {
  19. return list_entry(inode, struct foo_inode_info, vfs_inode);
  20. }
  21. Use FOO_I(inode) instead of &inode->u.foo_inode_i;
  22. Add foo_alloc_inode() and foo_destroy_inode() - the former should allocate
  23. foo_inode_info and return the address of ->vfs_inode, the latter should free
  24. FOO_I(inode) (see in-tree filesystems for examples).
  25. Make them ->alloc_inode and ->destroy_inode in your super_operations.
  26. Keep in mind that now you need explicit initialization of private data
  27. typically between calling iget_locked() and unlocking the inode.
  28. At some point that will become mandatory.
  29. ---
  30. [mandatory]
  31. Change of file_system_type method (->read_super to ->get_sb)
  32. ->read_super() is no more. Ditto for DECLARE_FSTYPE and DECLARE_FSTYPE_DEV.
  33. Turn your foo_read_super() into a function that would return 0 in case of
  34. success and negative number in case of error (-EINVAL unless you have more
  35. informative error value to report). Call it foo_fill_super(). Now declare
  36. int foo_get_sb(struct file_system_type *fs_type,
  37. int flags, const char *dev_name, void *data, struct vfsmount *mnt)
  38. {
  39. return get_sb_bdev(fs_type, flags, dev_name, data, foo_fill_super,
  40. mnt);
  41. }
  42. (or similar with s/bdev/nodev/ or s/bdev/single/, depending on the kind of
  43. filesystem).
  44. Replace DECLARE_FSTYPE... with explicit initializer and have ->get_sb set as
  45. foo_get_sb.
  46. ---
  47. [mandatory]
  48. Locking change: ->s_vfs_rename_sem is taken only by cross-directory renames.
  49. Most likely there is no need to change anything, but if you relied on
  50. global exclusion between renames for some internal purpose - you need to
  51. change your internal locking. Otherwise exclusion warranties remain the
  52. same (i.e. parents and victim are locked, etc.).
  53. ---
  54. [informational]
  55. Now we have the exclusion between ->lookup() and directory removal (by
  56. ->rmdir() and ->rename()). If you used to need that exclusion and do
  57. it by internal locking (most of filesystems couldn't care less) - you
  58. can relax your locking.
  59. ---
  60. [mandatory]
  61. ->lookup(), ->truncate(), ->create(), ->unlink(), ->mknod(), ->mkdir(),
  62. ->rmdir(), ->link(), ->lseek(), ->symlink(), ->rename()
  63. and ->readdir() are called without BKL now. Grab it on entry, drop upon return
  64. - that will guarantee the same locking you used to have. If your method or its
  65. parts do not need BKL - better yet, now you can shift lock_kernel() and
  66. unlock_kernel() so that they would protect exactly what needs to be
  67. protected.
  68. ---
  69. [mandatory]
  70. BKL is also moved from around sb operations. BKL should have been shifted into
  71. individual fs sb_op functions. If you don't need it, remove it.
  72. ---
  73. [informational]
  74. check for ->link() target not being a directory is done by callers. Feel
  75. free to drop it...
  76. ---
  77. [informational]
  78. ->link() callers hold ->i_mutex on the object we are linking to. Some of your
  79. problems might be over...
  80. ---
  81. [mandatory]
  82. new file_system_type method - kill_sb(superblock). If you are converting
  83. an existing filesystem, set it according to ->fs_flags:
  84. FS_REQUIRES_DEV - kill_block_super
  85. FS_LITTER - kill_litter_super
  86. neither - kill_anon_super
  87. FS_LITTER is gone - just remove it from fs_flags.
  88. ---
  89. [mandatory]
  90. FS_SINGLE is gone (actually, that had happened back when ->get_sb()
  91. went in - and hadn't been documented ;-/). Just remove it from fs_flags
  92. (and see ->get_sb() entry for other actions).
  93. ---
  94. [mandatory]
  95. ->setattr() is called without BKL now. Caller _always_ holds ->i_mutex, so
  96. watch for ->i_mutex-grabbing code that might be used by your ->setattr().
  97. Callers of notify_change() need ->i_mutex now.
  98. ---
  99. [recommended]
  100. New super_block field "struct export_operations *s_export_op" for
  101. explicit support for exporting, e.g. via NFS. The structure is fully
  102. documented at its declaration in include/linux/fs.h, and in
  103. Documentation/filesystems/nfs/Exporting.
  104. Briefly it allows for the definition of decode_fh and encode_fh operations
  105. to encode and decode filehandles, and allows the filesystem to use
  106. a standard helper function for decode_fh, and provide file-system specific
  107. support for this helper, particularly get_parent.
  108. It is planned that this will be required for exporting once the code
  109. settles down a bit.
  110. [mandatory]
  111. s_export_op is now required for exporting a filesystem.
  112. isofs, ext2, ext3, resierfs, fat
  113. can be used as examples of very different filesystems.
  114. ---
  115. [mandatory]
  116. iget4() and the read_inode2 callback have been superseded by iget5_locked()
  117. which has the following prototype,
  118. struct inode *iget5_locked(struct super_block *sb, unsigned long ino,
  119. int (*test)(struct inode *, void *),
  120. int (*set)(struct inode *, void *),
  121. void *data);
  122. 'test' is an additional function that can be used when the inode
  123. number is not sufficient to identify the actual file object. 'set'
  124. should be a non-blocking function that initializes those parts of a
  125. newly created inode to allow the test function to succeed. 'data' is
  126. passed as an opaque value to both test and set functions.
  127. When the inode has been created by iget5_locked(), it will be returned with the
  128. I_NEW flag set and will still be locked. The filesystem then needs to finalize
  129. the initialization. Once the inode is initialized it must be unlocked by
  130. calling unlock_new_inode().
  131. The filesystem is responsible for setting (and possibly testing) i_ino
  132. when appropriate. There is also a simpler iget_locked function that
  133. just takes the superblock and inode number as arguments and does the
  134. test and set for you.
  135. e.g.
  136. inode = iget_locked(sb, ino);
  137. if (inode->i_state & I_NEW) {
  138. err = read_inode_from_disk(inode);
  139. if (err < 0) {
  140. iget_failed(inode);
  141. return err;
  142. }
  143. unlock_new_inode(inode);
  144. }
  145. Note that if the process of setting up a new inode fails, then iget_failed()
  146. should be called on the inode to render it dead, and an appropriate error
  147. should be passed back to the caller.
  148. ---
  149. [recommended]
  150. ->getattr() finally getting used. See instances in nfs, minix, etc.
  151. ---
  152. [mandatory]
  153. ->revalidate() is gone. If your filesystem had it - provide ->getattr()
  154. and let it call whatever you had as ->revlidate() + (for symlinks that
  155. had ->revalidate()) add calls in ->follow_link()/->readlink().
  156. ---
  157. [mandatory]
  158. ->d_parent changes are not protected by BKL anymore. Read access is safe
  159. if at least one of the following is true:
  160. * filesystem has no cross-directory rename()
  161. * we know that parent had been locked (e.g. we are looking at
  162. ->d_parent of ->lookup() argument).
  163. * we are called from ->rename().
  164. * the child's ->d_lock is held
  165. Audit your code and add locking if needed. Notice that any place that is
  166. not protected by the conditions above is risky even in the old tree - you
  167. had been relying on BKL and that's prone to screwups. Old tree had quite
  168. a few holes of that kind - unprotected access to ->d_parent leading to
  169. anything from oops to silent memory corruption.
  170. ---
  171. [mandatory]
  172. FS_NOMOUNT is gone. If you use it - just set MS_NOUSER in flags
  173. (see rootfs for one kind of solution and bdev/socket/pipe for another).
  174. ---
  175. [recommended]
  176. Use bdev_read_only(bdev) instead of is_read_only(kdev). The latter
  177. is still alive, but only because of the mess in drivers/s390/block/dasd.c.
  178. As soon as it gets fixed is_read_only() will die.
  179. ---
  180. [mandatory]
  181. ->permission() is called without BKL now. Grab it on entry, drop upon
  182. return - that will guarantee the same locking you used to have. If
  183. your method or its parts do not need BKL - better yet, now you can
  184. shift lock_kernel() and unlock_kernel() so that they would protect
  185. exactly what needs to be protected.
  186. ---
  187. [mandatory]
  188. ->statfs() is now called without BKL held. BKL should have been
  189. shifted into individual fs sb_op functions where it's not clear that
  190. it's safe to remove it. If you don't need it, remove it.
  191. ---
  192. [mandatory]
  193. is_read_only() is gone; use bdev_read_only() instead.
  194. ---
  195. [mandatory]
  196. destroy_buffers() is gone; use invalidate_bdev().
  197. ---
  198. [mandatory]
  199. fsync_dev() is gone; use fsync_bdev(). NOTE: lvm breakage is
  200. deliberate; as soon as struct block_device * is propagated in a reasonable
  201. way by that code fixing will become trivial; until then nothing can be
  202. done.
  203. [mandatory]
  204. block truncatation on error exit from ->write_begin, and ->direct_IO
  205. moved from generic methods (block_write_begin, cont_write_begin,
  206. nobh_write_begin, blockdev_direct_IO*) to callers. Take a look at
  207. ext2_write_failed and callers for an example.
  208. [mandatory]
  209. ->truncate is gone. The whole truncate sequence needs to be
  210. implemented in ->setattr, which is now mandatory for filesystems
  211. implementing on-disk size changes. Start with a copy of the old inode_setattr
  212. and vmtruncate, and the reorder the vmtruncate + foofs_vmtruncate sequence to
  213. be in order of zeroing blocks using block_truncate_page or similar helpers,
  214. size update and on finally on-disk truncation which should not fail.
  215. inode_change_ok now includes the size checks for ATTR_SIZE and must be called
  216. in the beginning of ->setattr unconditionally.
  217. [mandatory]
  218. ->clear_inode() and ->delete_inode() are gone; ->evict_inode() should
  219. be used instead. It gets called whenever the inode is evicted, whether it has
  220. remaining links or not. Caller does *not* evict the pagecache or inode-associated
  221. metadata buffers; the method has to use truncate_inode_pages_final() to get rid
  222. of those. Caller makes sure async writeback cannot be running for the inode while
  223. (or after) ->evict_inode() is called.
  224. ->drop_inode() returns int now; it's called on final iput() with
  225. inode->i_lock held and it returns true if filesystems wants the inode to be
  226. dropped. As before, generic_drop_inode() is still the default and it's been
  227. updated appropriately. generic_delete_inode() is also alive and it consists
  228. simply of return 1. Note that all actual eviction work is done by caller after
  229. ->drop_inode() returns.
  230. As before, clear_inode() must be called exactly once on each call of
  231. ->evict_inode() (as it used to be for each call of ->delete_inode()). Unlike
  232. before, if you are using inode-associated metadata buffers (i.e.
  233. mark_buffer_dirty_inode()), it's your responsibility to call
  234. invalidate_inode_buffers() before clear_inode().
  235. NOTE: checking i_nlink in the beginning of ->write_inode() and bailing out
  236. if it's zero is not *and* *never* *had* *been* enough. Final unlink() and iput()
  237. may happen while the inode is in the middle of ->write_inode(); e.g. if you blindly
  238. free the on-disk inode, you may end up doing that while ->write_inode() is writing
  239. to it.
  240. ---
  241. [mandatory]
  242. .d_delete() now only advises the dcache as to whether or not to cache
  243. unreferenced dentries, and is now only called when the dentry refcount goes to
  244. 0. Even on 0 refcount transition, it must be able to tolerate being called 0,
  245. 1, or more times (eg. constant, idempotent).
  246. ---
  247. [mandatory]
  248. .d_compare() calling convention and locking rules are significantly
  249. changed. Read updated documentation in Documentation/filesystems/vfs.txt (and
  250. look at examples of other filesystems) for guidance.
  251. ---
  252. [mandatory]
  253. .d_hash() calling convention and locking rules are significantly
  254. changed. Read updated documentation in Documentation/filesystems/vfs.txt (and
  255. look at examples of other filesystems) for guidance.
  256. ---
  257. [mandatory]
  258. dcache_lock is gone, replaced by fine grained locks. See fs/dcache.c
  259. for details of what locks to replace dcache_lock with in order to protect
  260. particular things. Most of the time, a filesystem only needs ->d_lock, which
  261. protects *all* the dcache state of a given dentry.
  262. --
  263. [mandatory]
  264. Filesystems must RCU-free their inodes, if they can have been accessed
  265. via rcu-walk path walk (basically, if the file can have had a path name in the
  266. vfs namespace).
  267. Even though i_dentry and i_rcu share storage in a union, we will
  268. initialize the former in inode_init_always(), so just leave it alone in
  269. the callback. It used to be necessary to clean it there, but not anymore
  270. (starting at 3.2).
  271. --
  272. [recommended]
  273. vfs now tries to do path walking in "rcu-walk mode", which avoids
  274. atomic operations and scalability hazards on dentries and inodes (see
  275. Documentation/filesystems/path-lookup.txt). d_hash and d_compare changes
  276. (above) are examples of the changes required to support this. For more complex
  277. filesystem callbacks, the vfs drops out of rcu-walk mode before the fs call, so
  278. no changes are required to the filesystem. However, this is costly and loses
  279. the benefits of rcu-walk mode. We will begin to add filesystem callbacks that
  280. are rcu-walk aware, shown below. Filesystems should take advantage of this
  281. where possible.
  282. --
  283. [mandatory]
  284. d_revalidate is a callback that is made on every path element (if
  285. the filesystem provides it), which requires dropping out of rcu-walk mode. This
  286. may now be called in rcu-walk mode (nd->flags & LOOKUP_RCU). -ECHILD should be
  287. returned if the filesystem cannot handle rcu-walk. See
  288. Documentation/filesystems/vfs.txt for more details.
  289. permission is an inode permission check that is called on many or all
  290. directory inodes on the way down a path walk (to check for exec permission). It
  291. must now be rcu-walk aware (mask & MAY_NOT_BLOCK). See
  292. Documentation/filesystems/vfs.txt for more details.
  293. --
  294. [mandatory]
  295. In ->fallocate() you must check the mode option passed in. If your
  296. filesystem does not support hole punching (deallocating space in the middle of a
  297. file) you must return -EOPNOTSUPP if FALLOC_FL_PUNCH_HOLE is set in mode.
  298. Currently you can only have FALLOC_FL_PUNCH_HOLE with FALLOC_FL_KEEP_SIZE set,
  299. so the i_size should not change when hole punching, even when puching the end of
  300. a file off.
  301. --
  302. [mandatory]
  303. ->get_sb() is gone. Switch to use of ->mount(). Typically it's just
  304. a matter of switching from calling get_sb_... to mount_... and changing the
  305. function type. If you were doing it manually, just switch from setting ->mnt_root
  306. to some pointer to returning that pointer. On errors return ERR_PTR(...).
  307. --
  308. [mandatory]
  309. ->permission() and generic_permission()have lost flags
  310. argument; instead of passing IPERM_FLAG_RCU we add MAY_NOT_BLOCK into mask.
  311. generic_permission() has also lost the check_acl argument; ACL checking
  312. has been taken to VFS and filesystems need to provide a non-NULL ->i_op->get_acl
  313. to read an ACL from disk.
  314. --
  315. [mandatory]
  316. If you implement your own ->llseek() you must handle SEEK_HOLE and
  317. SEEK_DATA. You can hanle this by returning -EINVAL, but it would be nicer to
  318. support it in some way. The generic handler assumes that the entire file is
  319. data and there is a virtual hole at the end of the file. So if the provided
  320. offset is less than i_size and SEEK_DATA is specified, return the same offset.
  321. If the above is true for the offset and you are given SEEK_HOLE, return the end
  322. of the file. If the offset is i_size or greater return -ENXIO in either case.
  323. [mandatory]
  324. If you have your own ->fsync() you must make sure to call
  325. filemap_write_and_wait_range() so that all dirty pages are synced out properly.
  326. You must also keep in mind that ->fsync() is not called with i_mutex held
  327. anymore, so if you require i_mutex locking you must make sure to take it and
  328. release it yourself.
  329. --
  330. [mandatory]
  331. d_alloc_root() is gone, along with a lot of bugs caused by code
  332. misusing it. Replacement: d_make_root(inode). The difference is,
  333. d_make_root() drops the reference to inode if dentry allocation fails.
  334. --
  335. [mandatory]
  336. The witch is dead! Well, 2/3 of it, anyway. ->d_revalidate() and
  337. ->lookup() do *not* take struct nameidata anymore; just the flags.
  338. --
  339. [mandatory]
  340. ->create() doesn't take struct nameidata *; unlike the previous
  341. two, it gets "is it an O_EXCL or equivalent?" boolean argument. Note that
  342. local filesystems can ignore tha argument - they are guaranteed that the
  343. object doesn't exist. It's remote/distributed ones that might care...
  344. --
  345. [mandatory]
  346. FS_REVAL_DOT is gone; if you used to have it, add ->d_weak_revalidate()
  347. in your dentry operations instead.
  348. --
  349. [mandatory]
  350. vfs_readdir() is gone; switch to iterate_dir() instead
  351. --
  352. [mandatory]
  353. ->readdir() is gone now; switch to ->iterate()
  354. [mandatory]
  355. vfs_follow_link has been removed. Filesystems must use nd_set_link
  356. from ->follow_link for normal symlinks, or nd_jump_link for magic
  357. /proc/<pid> style links.
  358. --
  359. [mandatory]
  360. iget5_locked()/ilookup5()/ilookup5_nowait() test() callback used to be
  361. called with both ->i_lock and inode_hash_lock held; the former is *not*
  362. taken anymore, so verify that your callbacks do not rely on it (none
  363. of the in-tree instances did). inode_hash_lock is still held,
  364. of course, so they are still serialized wrt removal from inode hash,
  365. as well as wrt set() callback of iget5_locked().
  366. --
  367. [mandatory]
  368. d_materialise_unique() is gone; d_splice_alias() does everything you
  369. need now. Remember that they have opposite orders of arguments ;-/
  370. --
  371. [mandatory]
  372. f_dentry is gone; use f_path.dentry, or, better yet, see if you can avoid
  373. it entirely.
  374. --
  375. [mandatory]
  376. never call ->read() and ->write() directly; use __vfs_{read,write} or
  377. wrappers; instead of checking for ->write or ->read being NULL, look for
  378. FMODE_CAN_{WRITE,READ} in file->f_mode.
  379. --
  380. [mandatory]
  381. do _not_ use new_sync_{read,write} for ->read/->write; leave it NULL
  382. instead.
  383. --
  384. [mandatory]
  385. ->aio_read/->aio_write are gone. Use ->read_iter/->write_iter.
  386. ---
  387. [recommended]
  388. for embedded ("fast") symlinks just set inode->i_link to wherever the
  389. symlink body is and use simple_follow_link() as ->follow_link().
  390. --
  391. [mandatory]
  392. calling conventions for ->follow_link() have changed. Instead of returning
  393. cookie and using nd_set_link() to store the body to traverse, we return
  394. the body to traverse and store the cookie using explicit void ** argument.
  395. nameidata isn't passed at all - nd_jump_link() doesn't need it and
  396. nd_[gs]et_link() is gone.
  397. --
  398. [mandatory]
  399. calling conventions for ->put_link() have changed. It gets inode instead of
  400. dentry, it does not get nameidata at all and it gets called only when cookie
  401. is non-NULL. Note that link body isn't available anymore, so if you need it,
  402. store it as cookie.
  403. --
  404. [mandatory]
  405. __fd_install() & fd_install() can now sleep. Callers should not
  406. hold a spinlock or other resources that do not allow a schedule.