aufs5-loopback.patch 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. SPDX-License-Identifier: GPL-2.0
  2. aufs5.1 loopback patch
  3. diff --git a/drivers/block/loop.c b/drivers/block/loop.c
  4. index 7e18c8c72dcc..33f8813e97d6 100644
  5. --- a/drivers/block/loop.c
  6. +++ b/drivers/block/loop.c
  7. @@ -625,6 +625,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. struct block_device *bdev)
  21. {
  22. @@ -678,6 +687,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  23. unsigned int arg)
  24. {
  25. struct file *file = NULL, *old_file;
  26. + struct file *f, *virt_file = NULL, *old_virt_file;
  27. int error;
  28. bool partscan;
  29. @@ -697,12 +707,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  30. file = fget(arg);
  31. if (!file)
  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. error = loop_validate_file(file, bdev);
  40. if (error)
  41. goto out_err;
  42. old_file = lo->lo_backing_file;
  43. + old_virt_file = lo->lo_backing_virt_file;
  44. error = -EINVAL;
  45. @@ -714,6 +731,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  46. blk_mq_freeze_queue(lo->lo_queue);
  47. mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
  48. lo->lo_backing_file = file;
  49. + lo->lo_backing_virt_file = virt_file;
  50. lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
  51. mapping_set_gfp_mask(file->f_mapping,
  52. lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
  53. @@ -727,6 +745,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  54. * dependency.
  55. */
  56. fput(old_file);
  57. + if (old_virt_file)
  58. + fput(old_virt_file);
  59. if (partscan)
  60. loop_reread_partitions(lo, bdev);
  61. return 0;
  62. @@ -735,6 +755,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  63. mutex_unlock(&loop_ctl_mutex);
  64. if (file)
  65. fput(file);
  66. + if (virt_file)
  67. + fput(virt_file);
  68. return error;
  69. }
  70. @@ -921,7 +943,7 @@ static int loop_prepare_queue(struct loop_device *lo)
  71. static int loop_set_fd(struct loop_device *lo, fmode_t mode,
  72. struct block_device *bdev, unsigned int arg)
  73. {
  74. - struct file *file;
  75. + struct file *file, *f, *virt_file = NULL;
  76. struct inode *inode;
  77. struct address_space *mapping;
  78. int lo_flags = 0;
  79. @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
  80. file = fget(arg);
  81. if (!file)
  82. goto out;
  83. + f = loop_real_file(file);
  84. + if (f) {
  85. + virt_file = file;
  86. + file = f;
  87. + get_file(file);
  88. + }
  89. error = mutex_lock_killable(&loop_ctl_mutex);
  90. if (error)
  91. @@ -972,6 +1000,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
  92. lo->lo_device = bdev;
  93. lo->lo_flags = lo_flags;
  94. lo->lo_backing_file = file;
  95. + lo->lo_backing_virt_file = virt_file;
  96. lo->transfer = NULL;
  97. lo->ioctl = NULL;
  98. lo->lo_sizelimit = 0;
  99. @@ -1009,6 +1038,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
  100. mutex_unlock(&loop_ctl_mutex);
  101. out_putf:
  102. fput(file);
  103. + if (virt_file)
  104. + fput(virt_file);
  105. out:
  106. /* This is safe: open() is still holding a reference. */
  107. module_put(THIS_MODULE);
  108. @@ -1055,6 +1086,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
  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. @@ -1078,6 +1110,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. @@ -1160,6 +1193,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 af75a5ee4094..1e6ee5a4f623 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 0309f0d502ff..19feb4f3cb5f 100644
  143. --- a/fs/aufs/f_op.c
  144. +++ b/fs/aufs/f_op.c
  145. @@ -359,7 +359,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 9ba35a878ecd..4ed0ff03d5ab 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 c42cbe71ed4b..255e2d3763e7 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)
  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 73255f63b80c..f04e211cbf89 100644
  197. --- a/fs/aufs/super.c
  198. +++ b/fs/aufs/super.c
  199. @@ -846,7 +846,10 @@ static const struct super_operations aufs_sop = {
  200. .statfs = aufs_statfs,
  201. .put_super = aufs_put_super,
  202. .sync_fs = aufs_sync_fs,
  203. - .remount_fs = aufs_remount_fs
  204. + .remount_fs = aufs_remount_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 77933034b50a..9a9b195fb847 100644
  212. --- a/include/linux/fs.h
  213. +++ b/include/linux/fs.h
  214. @@ -1940,6 +1940,10 @@ struct super_operations {
  215. struct shrink_control *);
  216. long (*free_cached_objects)(struct super_block *,
  217. struct shrink_control *);
  218. +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
  219. + /* and aufs */
  220. + struct file *(*real_loop)(struct file *);
  221. +#endif
  222. };
  223. /*