aufs6-loopback.patch 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. SPDX-License-Identifier: GPL-2.0
  2. aufs6.6.63 loopback patch
  3. diff --git a/drivers/block/loop.c b/drivers/block/loop.c
  4. index 73dae3b1bd4e..ae84fb81acbf 100644
  5. --- a/drivers/block/loop.c
  6. +++ b/drivers/block/loop.c
  7. @@ -54,7 +54,7 @@ struct loop_device {
  8. int lo_flags;
  9. char lo_file_name[LO_NAME_SIZE];
  10. - struct file * lo_backing_file;
  11. + struct file *lo_backing_file, *lo_backing_virt_file;
  12. struct block_device *lo_device;
  13. gfp_t old_gfp_mask;
  14. @@ -505,6 +505,15 @@ static inline void loop_update_dio(struct loop_device *lo)
  15. lo->use_dio);
  16. }
  17. +static struct file *loop_real_file(struct file *file)
  18. +{
  19. + struct file *f = NULL;
  20. +
  21. + if (file->f_path.dentry->d_sb->s_op->real_loop)
  22. + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
  23. + return f;
  24. +}
  25. +
  26. static void loop_reread_partitions(struct loop_device *lo)
  27. {
  28. int rc;
  29. @@ -562,6 +571,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  30. {
  31. struct file *file = fget(arg);
  32. struct file *old_file;
  33. + struct file *f, *virt_file = NULL, *old_virt_file;
  34. int error;
  35. bool partscan;
  36. bool is_loop;
  37. @@ -585,11 +595,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  38. if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
  39. goto out_err;
  40. + f = loop_real_file(file);
  41. + if (f) {
  42. + virt_file = file;
  43. + file = f;
  44. + get_file(file);
  45. + }
  46. +
  47. error = loop_validate_file(file, bdev);
  48. if (error)
  49. goto out_err;
  50. old_file = lo->lo_backing_file;
  51. + old_virt_file = lo->lo_backing_virt_file;
  52. error = -EINVAL;
  53. @@ -602,6 +620,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  54. blk_mq_freeze_queue(lo->lo_queue);
  55. mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
  56. lo->lo_backing_file = file;
  57. + lo->lo_backing_virt_file = virt_file;
  58. lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
  59. mapping_set_gfp_mask(file->f_mapping,
  60. lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
  61. @@ -624,6 +643,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  62. * dependency.
  63. */
  64. fput(old_file);
  65. + if (old_virt_file)
  66. + fput(old_virt_file);
  67. if (partscan)
  68. loop_reread_partitions(lo);
  69. @@ -637,6 +658,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
  70. loop_global_unlock(lo, is_loop);
  71. out_putf:
  72. fput(file);
  73. + if (virt_file)
  74. + fput(virt_file);
  75. goto done;
  76. }
  77. @@ -1008,6 +1031,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
  78. const struct loop_config *config)
  79. {
  80. struct file *file = fget(config->fd);
  81. + struct file *f, *virt_file = NULL;
  82. struct inode *inode;
  83. struct address_space *mapping;
  84. int error;
  85. @@ -1023,6 +1047,13 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
  86. /* This is safe, since we have a reference from open(). */
  87. __module_get(THIS_MODULE);
  88. + f = loop_real_file(file);
  89. + if (f) {
  90. + virt_file = file;
  91. + file = f;
  92. + get_file(file);
  93. + }
  94. +
  95. /*
  96. * If we don't hold exclusive handle for the device, upgrade to it
  97. * here to avoid changing device under exclusive owner.
  98. @@ -1086,6 +1117,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
  99. lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
  100. lo->lo_device = bdev;
  101. lo->lo_backing_file = file;
  102. + lo->lo_backing_virt_file = virt_file;
  103. lo->old_gfp_mask = mapping_gfp_mask(mapping);
  104. mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
  105. @@ -1141,6 +1173,8 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
  106. bd_abort_claiming(bdev, loop_configure);
  107. out_putf:
  108. fput(file);
  109. + if (virt_file)
  110. + fput(virt_file);
  111. /* This is safe: open() is still holding a reference. */
  112. module_put(THIS_MODULE);
  113. return error;
  114. @@ -1149,6 +1183,7 @@ static int loop_configure(struct loop_device *lo, blk_mode_t mode,
  115. static void __loop_clr_fd(struct loop_device *lo, bool release)
  116. {
  117. struct file *filp;
  118. + struct file *virt_filp = lo->lo_backing_virt_file;
  119. gfp_t gfp = lo->old_gfp_mask;
  120. if (test_bit(QUEUE_FLAG_WC, &lo->lo_queue->queue_flags))
  121. @@ -1165,6 +1200,7 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
  122. spin_lock_irq(&lo->lo_lock);
  123. filp = lo->lo_backing_file;
  124. lo->lo_backing_file = NULL;
  125. + lo->lo_backing_virt_file = NULL;
  126. spin_unlock_irq(&lo->lo_lock);
  127. lo->lo_device = NULL;
  128. @@ -1227,6 +1263,8 @@ static void __loop_clr_fd(struct loop_device *lo, bool release)
  129. * fput can take open_mutex which is usually taken before lo_mutex.
  130. */
  131. fput(filp);
  132. + if (virt_filp)
  133. + fput(virt_filp);
  134. }
  135. static int loop_clr_fd(struct loop_device *lo)
  136. diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
  137. index d109c1392d60..dfe82d9c6292 100644
  138. --- a/fs/aufs/f_op.c
  139. +++ b/fs/aufs/f_op.c
  140. @@ -317,7 +317,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
  141. if (IS_ERR(h_file))
  142. goto out;
  143. - if (au_test_loopback_kthread()) {
  144. + if (0 && au_test_loopback_kthread()) {
  145. au_warn_loopback(h_file->f_path.dentry->d_sb);
  146. if (file->f_mapping != h_file->f_mapping) {
  147. file->f_mapping = h_file->f_mapping;
  148. diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
  149. index 58043e31e5f3..e2bfae6f9d59 100644
  150. --- a/fs/aufs/loop.c
  151. +++ b/fs/aufs/loop.c
  152. @@ -133,3 +133,19 @@ void au_loopback_fin(void)
  153. symbol_put(loop_backing_file);
  154. au_kfree_try_rcu(au_warn_loopback_array);
  155. }
  156. +
  157. +/* ---------------------------------------------------------------------- */
  158. +
  159. +/* support the loopback block device insude aufs */
  160. +
  161. +struct file *aufs_real_loop(struct file *file)
  162. +{
  163. + struct file *f;
  164. +
  165. + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
  166. + fi_read_lock(file);
  167. + f = au_hf_top(file);
  168. + fi_read_unlock(file);
  169. + AuDebugOn(!f);
  170. + return f;
  171. +}
  172. diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
  173. index 03d4908a6c03..34d356e181d5 100644
  174. --- a/fs/aufs/loop.h
  175. +++ b/fs/aufs/loop.h
  176. @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
  177. int au_loopback_init(void);
  178. void au_loopback_fin(void);
  179. +
  180. +struct file *aufs_real_loop(struct file *file);
  181. #else
  182. AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
  183. @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
  184. AuStubInt0(au_loopback_init, void)
  185. AuStubVoid(au_loopback_fin, void)
  186. +
  187. +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
  188. #endif /* BLK_DEV_LOOP */
  189. #endif /* __KERNEL__ */
  190. diff --git a/fs/aufs/super.c b/fs/aufs/super.c
  191. index 6da6270e98ca..5f9bbcd90851 100644
  192. --- a/fs/aufs/super.c
  193. +++ b/fs/aufs/super.c
  194. @@ -758,7 +758,10 @@ const struct super_operations aufs_sop = {
  195. .show_options = aufs_show_options,
  196. .statfs = aufs_statfs,
  197. .put_super = aufs_put_super,
  198. - .sync_fs = aufs_sync_fs
  199. + .sync_fs = aufs_sync_fs,
  200. +#ifdef CONFIG_AUFS_BDEV_LOOP
  201. + .real_loop = aufs_real_loop
  202. +#endif
  203. };
  204. /* ---------------------------------------------------------------------- */
  205. diff --git a/include/linux/fs.h b/include/linux/fs.h
  206. index c572420129a5..5b434c0e85ab 100644
  207. --- a/include/linux/fs.h
  208. +++ b/include/linux/fs.h
  209. @@ -2089,6 +2089,11 @@ struct super_operations {
  210. long (*free_cached_objects)(struct super_block *,
  211. struct shrink_control *);
  212. void (*shutdown)(struct super_block *sb);
  213. +
  214. +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
  215. + /* and aufs */
  216. + struct file *(*real_loop)(struct file *);
  217. +#endif
  218. };
  219. /*