wok view linux/stuff/aufs3-loopback.patch @ rev 25336

updated suricata (5.0.2 -> 6.0.6)
author Hans-G?nter Theisgen
date Sat Jul 23 17:54:01 2022 +0100 (2022-07-23)
parents
children
line source
1 aufs3.16 loopback patch
3 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
4 index 30efd68..77b31b4 100644
5 --- a/drivers/block/loop.c
6 +++ b/drivers/block/loop.c
7 @@ -514,7 +514,7 @@ out:
8 }
10 struct switch_request {
11 - struct file *file;
12 + struct file *file, *virt_file;
13 struct completion wait;
14 };
16 @@ -576,7 +576,8 @@ static int loop_thread(void *data)
17 * First it needs to flush existing IO, it does this by sending a magic
18 * BIO down the pipe. The completion of this BIO does the actual switch.
19 */
20 -static int loop_switch(struct loop_device *lo, struct file *file)
21 +static int loop_switch(struct loop_device *lo, struct file *file,
22 + struct file *virt_file)
23 {
24 struct switch_request w;
25 struct bio *bio = bio_alloc(GFP_KERNEL, 0);
26 @@ -584,6 +585,7 @@ static int loop_switch(struct loop_device *lo, struct file *file)
27 return -ENOMEM;
28 init_completion(&w.wait);
29 w.file = file;
30 + w.virt_file = virt_file;
31 bio->bi_private = &w;
32 bio->bi_bdev = NULL;
33 loop_make_request(lo->lo_queue, bio);
34 @@ -600,7 +602,7 @@ static int loop_flush(struct loop_device *lo)
35 if (!lo->lo_thread)
36 return 0;
38 - return loop_switch(lo, NULL);
39 + return loop_switch(lo, NULL, NULL);
40 }
42 /*
43 @@ -619,6 +621,7 @@ static void do_loop_switch(struct loop_device *lo, struct switch_request *p)
44 mapping = file->f_mapping;
45 mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
46 lo->lo_backing_file = file;
47 + lo->lo_backing_virt_file = p->virt_file;
48 lo->lo_blocksize = S_ISBLK(mapping->host->i_mode) ?
49 mapping->host->i_bdev->bd_block_size : PAGE_SIZE;
50 lo->old_gfp_mask = mapping_gfp_mask(mapping);
51 @@ -627,6 +630,13 @@ out:
52 complete(&p->wait);
53 }
55 +static struct file *loop_real_file(struct file *file)
56 +{
57 + struct file *f = NULL;
58 + if (file->f_dentry->d_sb->s_op->real_loop)
59 + f = file->f_dentry->d_sb->s_op->real_loop(file);
60 + return f;
61 +}
63 /*
64 * loop_change_fd switched the backing store of a loopback device to
65 @@ -640,6 +650,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
66 unsigned int arg)
67 {
68 struct file *file, *old_file;
69 + struct file *f, *virt_file = NULL, *old_virt_file;
70 struct inode *inode;
71 int error;
73 @@ -656,9 +667,16 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
74 file = fget(arg);
75 if (!file)
76 goto out;
77 + f = loop_real_file(file);
78 + if (f) {
79 + virt_file = file;
80 + file = f;
81 + get_file(file);
82 + }
84 inode = file->f_mapping->host;
85 old_file = lo->lo_backing_file;
86 + old_virt_file = lo->lo_backing_virt_file;
88 error = -EINVAL;
90 @@ -670,17 +688,21 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
91 goto out_putf;
93 /* and ... switch */
94 - error = loop_switch(lo, file);
95 + error = loop_switch(lo, file, virt_file);
96 if (error)
97 goto out_putf;
99 fput(old_file);
100 + if (old_virt_file)
101 + fput(old_virt_file);
102 if (lo->lo_flags & LO_FLAGS_PARTSCAN)
103 ioctl_by_bdev(bdev, BLKRRPART, 0);
104 return 0;
106 out_putf:
107 fput(file);
108 + if (virt_file)
109 + fput(virt_file);
110 out:
111 return error;
112 }
113 @@ -841,7 +863,7 @@ static void loop_config_discard(struct loop_device *lo)
114 static int loop_set_fd(struct loop_device *lo, fmode_t mode,
115 struct block_device *bdev, unsigned int arg)
116 {
117 - struct file *file, *f;
118 + struct file *file, *f, *virt_file = NULL;
119 struct inode *inode;
120 struct address_space *mapping;
121 unsigned lo_blocksize;
122 @@ -856,6 +878,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
123 file = fget(arg);
124 if (!file)
125 goto out;
126 + f = loop_real_file(file);
127 + if (f) {
128 + virt_file = file;
129 + file = f;
130 + get_file(file);
131 + }
133 error = -EBUSY;
134 if (lo->lo_state != Lo_unbound)
135 @@ -904,6 +932,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode,
136 lo->lo_device = bdev;
137 lo->lo_flags = lo_flags;
138 lo->lo_backing_file = file;
139 + lo->lo_backing_virt_file = virt_file;
140 lo->transfer = transfer_none;
141 lo->ioctl = NULL;
142 lo->lo_sizelimit = 0;
143 @@ -948,6 +977,7 @@ out_clr:
144 lo->lo_thread = NULL;
145 lo->lo_device = NULL;
146 lo->lo_backing_file = NULL;
147 + lo->lo_backing_virt_file = NULL;
148 lo->lo_flags = 0;
149 set_capacity(lo->lo_disk, 0);
150 invalidate_bdev(bdev);
151 @@ -957,6 +987,8 @@ out_clr:
152 lo->lo_state = Lo_unbound;
153 out_putf:
154 fput(file);
155 + if (virt_file)
156 + fput(virt_file);
157 out:
158 /* This is safe: open() is still holding a reference. */
159 module_put(THIS_MODULE);
160 @@ -1003,6 +1035,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer,
161 static int loop_clr_fd(struct loop_device *lo)
162 {
163 struct file *filp = lo->lo_backing_file;
164 + struct file *virt_filp = lo->lo_backing_virt_file;
165 gfp_t gfp = lo->old_gfp_mask;
166 struct block_device *bdev = lo->lo_device;
168 @@ -1036,6 +1069,7 @@ static int loop_clr_fd(struct loop_device *lo)
170 spin_lock_irq(&lo->lo_lock);
171 lo->lo_backing_file = NULL;
172 + lo->lo_backing_virt_file = NULL;
173 spin_unlock_irq(&lo->lo_lock);
175 loop_release_xfer(lo);
176 @@ -1078,6 +1112,8 @@ static int loop_clr_fd(struct loop_device *lo)
177 * bd_mutex which is usually taken before lo_ctl_mutex.
178 */
179 fput(filp);
180 + if (virt_filp)
181 + fput(virt_filp);
182 return 0;
183 }
185 diff --git a/drivers/block/loop.h b/drivers/block/loop.h
186 index 90df5d6..cb91822 100644
187 --- a/drivers/block/loop.h
188 +++ b/drivers/block/loop.h
189 @@ -44,7 +44,7 @@ struct loop_device {
190 int (*ioctl)(struct loop_device *, int cmd,
191 unsigned long arg);
193 - struct file * lo_backing_file;
194 + struct file * lo_backing_file, *lo_backing_virt_file;
195 struct block_device *lo_device;
196 unsigned lo_blocksize;
197 void *key_data;
198 diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
199 index 95ff59f..79cc7b6 100644
200 --- a/fs/aufs/f_op.c
201 +++ b/fs/aufs/f_op.c
202 @@ -398,7 +398,7 @@ static ssize_t aufs_splice_read(struct file *file, loff_t *ppos,
203 if (IS_ERR(h_file))
204 goto out;
206 - if (au_test_loopback_kthread()) {
207 + if (0 && au_test_loopback_kthread()) {
208 au_warn_loopback(h_file->f_dentry->d_sb);
209 if (file->f_mapping != h_file->f_mapping) {
210 file->f_mapping = h_file->f_mapping;
211 diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
212 index 2a3e245..e2ac602 100644
213 --- a/fs/aufs/loop.c
214 +++ b/fs/aufs/loop.c
215 @@ -130,3 +130,19 @@ void au_loopback_fin(void)
216 symbol_put(loop_backing_file);
217 kfree(au_warn_loopback_array);
218 }
219 +
220 +/* ---------------------------------------------------------------------- */
221 +
222 +/* support the loopback block device insude aufs */
223 +
224 +struct file *aufs_real_loop(struct file *file)
225 +{
226 + struct file *f;
227 +
228 + BUG_ON(!au_test_aufs(file->f_dentry->d_sb));
229 + fi_read_lock(file);
230 + f = au_hf_top(file);
231 + fi_read_unlock(file);
232 + AuDebugOn(!f);
233 + return f;
234 +}
235 diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
236 index 6d9864d..3322557 100644
237 --- a/fs/aufs/loop.h
238 +++ b/fs/aufs/loop.h
239 @@ -25,7 +25,11 @@ void au_warn_loopback(struct super_block *h_sb);
241 int au_loopback_init(void);
242 void au_loopback_fin(void);
243 +
244 +struct file *aufs_real_loop(struct file *file);
245 #else
246 +AuStub(struct file *, loop_backing_file, return NULL)
247 +
248 AuStubInt0(au_test_loopback_overlap, struct super_block *sb,
249 struct dentry *h_adding)
250 AuStubInt0(au_test_loopback_kthread, void)
251 @@ -33,6 +37,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
253 AuStubInt0(au_loopback_init, void)
254 AuStubVoid(au_loopback_fin, void)
255 +
256 +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
257 #endif /* BLK_DEV_LOOP */
259 #endif /* __KERNEL__ */
260 diff --git a/fs/aufs/super.c b/fs/aufs/super.c
261 index 52ee100..bd545df 100644
262 --- a/fs/aufs/super.c
263 +++ b/fs/aufs/super.c
264 @@ -810,7 +810,10 @@ static const struct super_operations aufs_sop = {
265 .statfs = aufs_statfs,
266 .put_super = aufs_put_super,
267 .sync_fs = aufs_sync_fs,
268 - .remount_fs = aufs_remount_fs
269 + .remount_fs = aufs_remount_fs,
270 +#ifdef CONFIG_AUFS_BDEV_LOOP
271 + .real_loop = aufs_real_loop
272 +#endif
273 };
275 /* ---------------------------------------------------------------------- */
276 diff --git a/include/linux/fs.h b/include/linux/fs.h
277 index 2f32b35..f94f0e6 100644
278 --- a/include/linux/fs.h
279 +++ b/include/linux/fs.h
280 @@ -1561,6 +1561,10 @@ struct super_operations {
281 int (*bdev_try_to_free_page)(struct super_block*, struct page*, gfp_t);
282 long (*nr_cached_objects)(struct super_block *, int);
283 long (*free_cached_objects)(struct super_block *, long, int);
284 +#if defined(CONFIG_BLK_DEV_LOOP) || defined(CONFIG_BLK_DEV_LOOP_MODULE)
285 + /* and aufs */
286 + struct file *(*real_loop)(struct file *);
287 +#endif
288 };
290 /*