wok-current view linux/stuff/aufs4-loopback.patch @ rev 25698

Fix ntfs-3g receipt
author Stanislas Leduc <shann@slitaz.org>
date Tue Apr 16 19:01:01 2024 +0000 (2 months ago)
parents
children
line source
1 SPDX-License-Identifier: GPL-2.0
2 aufs4.19 loopback patch
4 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
5 index 9e534a36c5941..74cd74e6374b0 100644
6 --- a/drivers/block/loop.c
7 +++ b/drivers/block/loop.c
8 @@ -626,6 +626,15 @@ static inline void loop_update_dio(struct loop_device *lo)
9 lo->use_dio);
10 }
12 +static struct file *loop_real_file(struct file *file)
13 +{
14 + struct file *f = NULL;
15 +
16 + if (file->f_path.dentry->d_sb->s_op->real_loop)
17 + f = file->f_path.dentry->d_sb->s_op->real_loop(file);
18 + return f;
19 +}
20 +
21 static void loop_reread_partitions(struct loop_device *lo,
22 struct block_device *bdev)
23 {
24 @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
25 unsigned int arg)
26 {
27 struct file *file, *old_file;
28 + struct file *f, *virt_file = NULL, *old_virt_file;
29 int error;
31 error = -ENXIO;
32 @@ -705,12 +715,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
33 file = fget(arg);
34 if (!file)
35 goto out;
36 + f = loop_real_file(file);
37 + if (f) {
38 + virt_file = file;
39 + file = f;
40 + get_file(file);
41 + }
43 error = loop_validate_file(file, bdev);
44 if (error)
45 goto out_putf;
47 old_file = lo->lo_backing_file;
48 + old_virt_file = lo->lo_backing_virt_file;
50 error = -EINVAL;
52 @@ -722,6 +739,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
53 blk_mq_freeze_queue(lo->lo_queue);
54 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
55 lo->lo_backing_file = file;
56 + lo->lo_backing_virt_file = virt_file;
57 lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
58 mapping_set_gfp_mask(file->f_mapping,
59 lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
60 @@ -729,12 +747,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
61 blk_mq_unfreeze_queue(lo->lo_queue);
63 fput(old_file);
64 + if (old_virt_file)
65 + fput(old_virt_file);
66 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
67 loop_reread_partitions(lo, bdev);
68 return 0;
70 out_putf:
71 fput(file);
72 + if (virt_file)
73 + fput(virt_file);
74 out:
75 return error;
76 }
77 @@ -922,7 +944,7 @@ static int loop_prepare_queue(struct loop_device *lo)
78 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
79 struct block_device *bdev, unsigned int arg)
80 {
81 - struct file *file;
82 + struct file *file, *f, *virt_file = NULL;
83 struct inode *inode;
84 struct address_space *mapping;
85 int lo_flags = 0;
86 @@ -936,6 +958,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
87 file = fget(arg);
88 if (!file)
89 goto out;
90 + f = loop_real_file(file);
91 + if (f) {
92 + virt_file = file;
93 + file = f;
94 + get_file(file);
95 + }
97 error = -EBUSY;
98 if (lo->lo_state != Lo_unbound)
99 @@ -968,6 +996,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
100 lo->lo_device = bdev;
101 lo->lo_flags = lo_flags;
102 lo->lo_backing_file = file;
103 + lo->lo_backing_virt_file = virt_file;
104 lo->transfer = NULL;
105 lo->ioctl = NULL;
106 lo->lo_sizelimit = 0;
107 @@ -1001,6 +1030,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
109 out_putf:
110 fput(file);
111 + if (virt_file)
112 + fput(virt_file);
113 out:
114 /* This is safe: open() is still holding a reference. */
115 module_put(THIS_MODULE);
116 @@ -1047,6 +1078,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
117 static int loop_clr_fd(struct loop_device *lo)
118 {
119 struct file *filp = lo->lo_backing_file;
120 + struct file *virt_filp = lo->lo_backing_virt_file;
121 gfp_t gfp = lo->old_gfp_mask;
122 struct block_device *bdev = lo->lo_device;
124 @@ -1078,6 +1110,7 @@ static int loop_clr_fd(struct loop_device *lo)
125 spin_lock_irq(&lo->lo_lock);
126 lo->lo_state = Lo_rundown;
127 lo->lo_backing_file = NULL;
128 + lo->lo_backing_virt_file = NULL;
129 spin_unlock_irq(&lo->lo_lock);
131 loop_release_xfer(lo);
132 @@ -1126,6 +1159,8 @@ static int loop_clr_fd(struct loop_device *lo)
133 * bd_mutex which is usually taken before lo_ctl_mutex.
134 */
135 fput(filp);
136 + if (virt_filp)
137 + fput(virt_filp);
138 return 0;
139 }
141 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
142 index 4d42c7af7de75..a15dd5bff5eae 100644
143 --- a/drivers/block/loop.h
144 +++ b/drivers/block/loop.h
145 @@ -46,7 +46,7 @@ struct loop_device {
146 int (*ioctl)(struct loop_device *, int cmd,
147 unsigned long arg);
149 - struct file * lo_backing_file;
150 + struct file *lo_backing_file, *lo_backing_virt_file;
151 struct block_device *lo_device;
152 void *key_data;
154 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
155 index 6fb4a4ed8cc7f..ba9a959f2db27 100644
156 --- a/fs/aufs/f_op.c
157 +++ b/fs/aufs/f_op.c
158 @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
159 if (IS_ERR(h_file))
160 goto out;
162 - if (au_test_loopback_kthread()) {
163 + if (0 && au_test_loopback_kthread()) {
164 au_warn_loopback(h_file->f_path.dentry->d_sb);
165 if (file->f_mapping != h_file->f_mapping) {
166 file->f_mapping = h_file->f_mapping;
167 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
168 index 50e80bd1d589d..d0f9777267f99 100644
169 --- a/fs/aufs/loop.c
170 +++ b/fs/aufs/loop.c
171 @@ -133,3 +133,19 @@ void au_loopback_fin(void)
172 symbol_put(loop_backing_file);
173 au_kfree_try_rcu(au_warn_loopback_array);
174 }
175 +
176 +/* ---------------------------------------------------------------------- */
177 +
178 +/* support the loopback block device insude aufs */
179 +
180 +struct file *aufs_real_loop(struct file *file)
181 +{
182 + struct file *f;
183 +
184 + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
185 + fi_read_lock(file);
186 + f = au_hf_top(file);
187 + fi_read_unlock(file);
188 + AuDebugOn(!f);
189 + return f;
190 +}
191 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
192 index 94f4f80ae33bf..ca1194354aff4 100644
193 --- a/fs/aufs/loop.h
194 +++ b/fs/aufs/loop.h
195 @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
197 int au_loopback_init(void);
198 void au_loopback_fin(void);
199 +
200 +struct file *aufs_real_loop(struct file *file);
201 #else
202 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
204 @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
206 AuStubInt0(au_loopback_init, void)
207 AuStubVoid(au_loopback_fin, void)
208 +
209 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
210 #endif /* BLK_DEV_LOOP */
212 #endif /* __KERNEL__ */
213 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
214 index e3b81808a78a7..eff4f475de060 100644
215 --- a/fs/aufs/super.c
216 +++ b/fs/aufs/super.c
217 @@ -846,7 +846,10 @@ static const struct super_operations aufs_sop = {
218 .statfs = aufs_statfs,
219 .put_super = aufs_put_super,
220 .sync_fs = aufs_sync_fs,
221 - .remount_fs = aufs_remount_fs
222 + .remount_fs = aufs_remount_fs,
223 +#ifdef CONFIG_AUFS_BDEV_LOOP
224 + .real_loop = aufs_real_loop
225 +#endif
226 };
228 /* ---------------------------------------------------------------------- */
229 diff --git a/include/linux/fs.h b/include/linux/fs.h
230 index 41da4219febfe..72fe934fd55b0 100644
231 --- a/include/linux/fs.h
232 +++ b/include/linux/fs.h
233 @@ -1882,6 +1882,10 @@ struct super_operations {
234 struct shrink_control *);
235 long (*free_cached_objects)(struct super_block *,
236 struct shrink_control *);
237 +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
238 + /* and aufs */
239 + struct file *(*real_loop)(struct file *);
240 +#endif
241 };
243 /*