aufs5-loopback.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. SPDX-License-Identifier: GPL-2.0
  2. aufs5.15.41 loopback patch
  3. diff --git a/drivers/block/loop.c b/drivers/block/loop.c
  4. index 7a9e40b97831..5ed06240cc9c 100644
  5. --- a/drivers/block/loop.c
  6. +++ b/drivers/block/loop.c
  7. @@ -673,6 +673,15 @@ static inline void loop_update_dio(struct loop_device *lo)
  8. lo->use_dio);
  9. }
  10. +static struct file *loop_real_file(struct file *file)
  11. +{
  12. + struct file *f = NULL;
  13. +
  14. + if (file->f_path.dentry->d_sb->s_op->real_loop)
  15. + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
  16. + return f;
  17. +}
  18. +
  19. static void loop_reread_partitions(struct loop_device *lo)
  20. {
  21. int rc;
  22. @@ -730,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  23. {
  24. struct file *file = fget(arg);
  25. struct file *old_file;
  26. + struct file *f, *virt_file = NULL, *old_virt_file;
  27. int error;
  28. bool partscan;
  29. bool is_loop;
  30. @@ -749,11 +759,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  31. if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
  32. goto out_err;
  33. + f = loop_real_file(file);
  34. + if (f) {
  35. + virt_file = file;
  36. + file = f;
  37. + get_file(file);
  38. + }
  39. +
  40. error = loop_validate_file(file, bdev);
  41. if (error)
  42. goto out_err;
  43. old_file = lo->lo_backing_file;
  44. + old_virt_file = lo->lo_backing_virt_file;
  45. error = -EINVAL;
  46. @@ -766,6 +784,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  47. blk_mq_freeze_queue(lo->lo_queue);
  48. mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
  49. lo->lo_backing_file = file;
  50. + lo->lo_backing_virt_file = virt_file;
  51. lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
  52. mapping_set_gfp_mask(file->f_mapping,
  53. lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
  54. @@ -788,6 +807,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  55. * dependency.
  56. */
  57. fput(old_file);
  58. + if (old_virt_file)
  59. + fput(old_virt_file);
  60. if (partscan)
  61. loop_reread_partitions(lo);
  62. return 0;
  63. @@ -796,6 +817,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  64. loop_global_unlock(lo, is_loop);
  65. out_putf:
  66. fput(file);
  67. + if (virt_file)
  68. + fput(virt_file);
  69. goto done;
  70. }
  71. @@ -1201,6 +1224,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
  72. const struct loop_config *config)
  73. {
  74. struct file *file = fget(config->fd);
  75. + struct file *f, *virt_file = NULL;
  76. struct inode *inode;
  77. struct address_space *mapping;
  78. int error;
  79. @@ -1216,6 +1240,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
  80. /* This is safe, since we have a reference from open(). */
  81. __module_get(THIS_MODULE);
  82. + f = loop_real_file(file);
  83. + if (f) {
  84. + virt_file = file;
  85. + file = f;
  86. + get_file(file);
  87. + }
  88. +
  89. /*
  90. * If we don't hold exclusive handle for the device, upgrade to it
  91. * here to avoid changing device under exclusive owner.
  92. @@ -1281,6 +1312,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
  93. lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
  94. lo->lo_device = bdev;
  95. lo->lo_backing_file = file;
  96. + lo->lo_backing_virt_file = virt_file;
  97. lo->old_gfp_mask = mapping_gfp_mask(mapping);
  98. mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
  99. @@ -1331,6 +1363,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
  100. bd_abort_claiming(bdev, loop_configure);
  101. out_putf:
  102. fput(file);
  103. + if (virt_file)
  104. + fput(virt_file);
  105. /* This is safe: open() is still holding a reference. */
  106. module_put(THIS_MODULE);
  107. return error;
  108. @@ -1339,6 +1373,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
  109. static int __loop_clr_fd(struct loop_device *lo, bool release)
  110. {
  111. struct file *filp = NULL;
  112. + struct file *virt_filp = lo->lo_backing_virt_file;
  113. gfp_t gfp = lo->old_gfp_mask;
  114. struct block_device *bdev = lo->lo_device;
  115. int err = 0;
  116. @@ -1390,6 +1425,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
  117. spin_lock_irq(&lo->lo_lock);
  118. lo->lo_backing_file = NULL;
  119. + lo->lo_backing_virt_file = NULL;
  120. spin_unlock_irq(&lo->lo_lock);
  121. loop_release_xfer(lo);
  122. @@ -1470,6 +1506,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
  123. */
  124. if (filp)
  125. fput(filp);
  126. + if (virt_filp)
  127. + fput(virt_filp);
  128. return err;
  129. }
  130. diff --git a/drivers/block/loop.h b/drivers/block/loop.h
  131. index 04c88dd6eabd..0ff3ba22ee17 100644
  132. --- a/drivers/block/loop.h
  133. +++ b/drivers/block/loop.h
  134. @@ -46,7 +46,7 @@ struct loop_device {
  135. int (*ioctl)(struct loop_device *, int cmd,
  136. unsigned long arg);
  137. - struct file * lo_backing_file;
  138. + struct file *lo_backing_file, *lo_backing_virt_file;
  139. struct block_device *lo_device;
  140. void *key_data;
  141. diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
  142. index c2924d055ebd..4efde401dbf4 100644
  143. --- a/fs/aufs/f_op.c
  144. +++ b/fs/aufs/f_op.c
  145. @@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
  146. if (IS_ERR(h_file))
  147. goto out;
  148. - if (au_test_loopback_kthread()) {
  149. + if (0 && au_test_loopback_kthread()) {
  150. au_warn_loopback(h_file->f_path.dentry->d_sb);
  151. if (file->f_mapping != h_file->f_mapping) {
  152. file->f_mapping = h_file->f_mapping;
  153. diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
  154. index 74347bd75b38..5ef888a1d53f 100644
  155. --- a/fs/aufs/loop.c
  156. +++ b/fs/aufs/loop.c
  157. @@ -133,3 +133,19 @@ void au_loopback_fin(void)
  158. symbol_put(loop_backing_file);
  159. au_kfree_try_rcu(au_warn_loopback_array);
  160. }
  161. +
  162. +/* ---------------------------------------------------------------------- */
  163. +
  164. +/* support the loopback block device insude aufs */
  165. +
  166. +struct file *aufs_real_loop(struct file *file)
  167. +{
  168. + struct file *f;
  169. +
  170. + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
  171. + fi_read_lock(file);
  172. + f = au_hf_top(file);
  173. + fi_read_unlock(file);
  174. + AuDebugOn(!f);
  175. + return f;
  176. +}
  177. diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
  178. index 7293bee427f9..3345c098d0d4 100644
  179. --- a/fs/aufs/loop.h
  180. +++ b/fs/aufs/loop.h
  181. @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
  182. int au_loopback_init(void);
  183. void au_loopback_fin(void);
  184. +
  185. +struct file *aufs_real_loop(struct file *file);
  186. #else
  187. AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
  188. @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
  189. AuStubInt0(au_loopback_init, void)
  190. AuStubVoid(au_loopback_fin, void)
  191. +
  192. +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
  193. #endif /* BLK_DEV_LOOP */
  194. #endif /* __KERNEL__ */
  195. diff --git a/fs/aufs/super.c b/fs/aufs/super.c
  196. index 90043afec51c..0835f6da42d9 100644
  197. --- a/fs/aufs/super.c
  198. +++ b/fs/aufs/super.c
  199. @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
  200. .show_options = aufs_show_options,
  201. .statfs = aufs_statfs,
  202. .put_super = aufs_put_super,
  203. - .sync_fs = aufs_sync_fs
  204. + .sync_fs = aufs_sync_fs,
  205. +#ifdef CONFIG_AUFS_BDEV_LOOP
  206. + .real_loop = aufs_real_loop
  207. +#endif
  208. };
  209. /* ---------------------------------------------------------------------- */
  210. diff --git a/include/linux/fs.h b/include/linux/fs.h
  211. index e60d8ad85400..2ac5317f9b79 100644
  212. --- a/include/linux/fs.h
  213. +++ b/include/linux/fs.h
  214. @@ -2226,6 +2226,10 @@ struct super_operations {
  215. struct shrink_control *);
  216. long (*free_cached_objects)(struct super_block *,
  217. struct shrink_control *);
  218. +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
  219. + /* and aufs */
  220. + struct file *(*real_loop)(struct file *);
  221. +#endif
  222. };
  223. /*