aufs5-loopback.patch 7.22 KB
Newer Older
J. R. Okajima's avatar
J. R. Okajima committed
1
2
3
4
SPDX-License-Identifier: GPL-2.0
aufs5.x-rcN loopback patch

diff --git a/drivers/block/loop.c b/drivers/block/loop.c
J. R. Okajima's avatar
J. R. Okajima committed
5
index e65f941a4181a..ce11efab143b7 100644
J. R. Okajima's avatar
J. R. Okajima committed
6
7
--- a/drivers/block/loop.c
+++ b/drivers/block/loop.c
J. R. Okajima's avatar
J. R. Okajima committed
8
@@ -685,6 +685,15 @@ static inline void loop_update_dio(struct loop_device *lo)
J. R. Okajima's avatar
J. R. Okajima committed
9
 				lo->use_dio);
J. R. Okajima's avatar
J. R. Okajima committed
10
11
12
13
14
15
16
17
18
19
20
 }
 
+static struct file *loop_real_file(struct file *file)
+{
+	struct file *f = NULL;
+
+	if (file->f_path.dentry->d_sb->s_op->real_loop)
+		f = file->f_path.dentry->d_sb->s_op->real_loop(file);
+	return f;
+}
+
J. R. Okajima's avatar
J. R. Okajima committed
21
 static void loop_reread_partitions(struct loop_device *lo)
J. R. Okajima's avatar
J. R. Okajima committed
22
 {
J. R. Okajima's avatar
J. R. Okajima committed
23
 	int rc;
J. R. Okajima's avatar
J. R. Okajima committed
24
@@ -742,6 +751,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
J. R. Okajima's avatar
J. R. Okajima committed
25
 {
J. R. Okajima's avatar
J. R. Okajima committed
26
27
28
29
30
31
32
33
 	struct file *file = fget(arg);
 	struct file *old_file;
+	struct file *f, *virt_file = NULL, *old_virt_file;
 	int error;
 	bool partscan;
 	bool is_loop;
@@ -761,11 +771,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 	if (!(lo->lo_flags & LO_FLAGS_READ_ONLY))
J. R. Okajima's avatar
J. R. Okajima committed
34
 		goto out_err;
J. R. Okajima's avatar
J. R. Okajima committed
35
 
J. R. Okajima's avatar
J. R. Okajima committed
36
37
38
39
40
41
+	f = loop_real_file(file);
+	if (f) {
+		virt_file = file;
+		file = f;
+		get_file(file);
+	}
J. R. Okajima's avatar
J. R. Okajima committed
42
+
J. R. Okajima's avatar
J. R. Okajima committed
43
44
45
46
47
48
49
50
51
 	error = loop_validate_file(file, bdev);
 	if (error)
 		goto out_err;
 
 	old_file = lo->lo_backing_file;
+	old_virt_file = lo->lo_backing_virt_file;
 
 	error = -EINVAL;
 
J. R. Okajima's avatar
J. R. Okajima committed
52
@@ -777,6 +795,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
J. R. Okajima's avatar
J. R. Okajima committed
53
54
55
56
57
58
59
 	blk_mq_freeze_queue(lo->lo_queue);
 	mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask);
 	lo->lo_backing_file = file;
+	lo->lo_backing_virt_file = virt_file;
 	lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping);
 	mapping_set_gfp_mask(file->f_mapping,
 			     lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
J. R. Okajima's avatar
J. R. Okajima committed
60
@@ -799,6 +818,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
J. R. Okajima's avatar
J. R. Okajima committed
61
62
63
64
65
66
 	 * dependency.
 	 */
 	fput(old_file);
+	if (old_virt_file)
+		fput(old_virt_file);
 	if (partscan)
J. R. Okajima's avatar
J. R. Okajima committed
67
 		loop_reread_partitions(lo);
J. R. Okajima's avatar
J. R. Okajima committed
68
 	return 0;
J. R. Okajima's avatar
J. R. Okajima committed
69
70
71
72
@@ -807,6 +828,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev,
 	loop_global_unlock(lo, is_loop);
 out_putf:
 	fput(file);
J. R. Okajima's avatar
J. R. Okajima committed
73
74
75
76
77
+	if (virt_file)
+		fput(virt_file);
 	return error;
 }
 
J. R. Okajima's avatar
J. R. Okajima committed
78
@@ -1207,6 +1230,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
J. R. Okajima's avatar
J. R. Okajima committed
79
 			  const struct loop_config *config)
J. R. Okajima's avatar
J. R. Okajima committed
80
 {
J. R. Okajima's avatar
J. R. Okajima committed
81
82
83
 	struct file *file = fget(config->fd);
+	struct file *f, *virt_file = NULL;
 	struct inode *inode;
J. R. Okajima's avatar
J. R. Okajima committed
84
 	struct address_space *mapping;
J. R. Okajima's avatar
J. R. Okajima committed
85
86
87
88
89
 	int error;
@@ -1222,6 +1246,13 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
 	/* This is safe, since we have a reference from open(). */
 	__module_get(THIS_MODULE);
 
J. R. Okajima's avatar
J. R. Okajima committed
90
91
92
93
94
95
+	f = loop_real_file(file);
+	if (f) {
+		virt_file = file;
+		file = f;
+		get_file(file);
+	}
J. R. Okajima's avatar
J. R. Okajima committed
96
+
J. R. Okajima's avatar
J. R. Okajima committed
97
98
 	/*
 	 * If we don't hold exclusive handle for the device, upgrade to it
J. R. Okajima's avatar
J. R. Okajima committed
99
100
 	 * here to avoid changing device under exclusive owner.
@@ -1286,6 +1317,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
J. R. Okajima's avatar
J. R. Okajima committed
101
 	lo->use_dio = lo->lo_flags & LO_FLAGS_DIRECT_IO;
J. R. Okajima's avatar
J. R. Okajima committed
102
103
104
 	lo->lo_device = bdev;
 	lo->lo_backing_file = file;
+	lo->lo_backing_virt_file = virt_file;
J. R. Okajima's avatar
J. R. Okajima committed
105
106
107
 	lo->old_gfp_mask = mapping_gfp_mask(mapping);
 	mapping_set_gfp_mask(mapping, lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS));
 
J. R. Okajima's avatar
J. R. Okajima committed
108
@@ -1340,6 +1372,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
J. R. Okajima's avatar
J. R. Okajima committed
109
 		bd_abort_claiming(bdev, loop_configure);
J. R. Okajima's avatar
J. R. Okajima committed
110
111
112
113
114
115
 out_putf:
 	fput(file);
+	if (virt_file)
+		fput(virt_file);
 	/* This is safe: open() is still holding a reference. */
 	module_put(THIS_MODULE);
J. R. Okajima's avatar
J. R. Okajima committed
116
117
 	return error;
@@ -1348,6 +1382,7 @@ static int loop_configure(struct loop_device *lo, fmode_t mode,
J. R. Okajima's avatar
J. R. Okajima committed
118
119
120
121
122
123
124
 static int __loop_clr_fd(struct loop_device *lo, bool release)
 {
 	struct file *filp = NULL;
+	struct file *virt_filp = lo->lo_backing_virt_file;
 	gfp_t gfp = lo->old_gfp_mask;
 	struct block_device *bdev = lo->lo_device;
 	int err = 0;
J. R. Okajima's avatar
J. R. Okajima committed
125
@@ -1399,6 +1434,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
J. R. Okajima's avatar
J. R. Okajima committed
126
127
128
129
130
131
132
 
 	spin_lock_irq(&lo->lo_lock);
 	lo->lo_backing_file = NULL;
+	lo->lo_backing_virt_file = NULL;
 	spin_unlock_irq(&lo->lo_lock);
 
 	loop_release_xfer(lo);
J. R. Okajima's avatar
J. R. Okajima committed
133
@@ -1479,6 +1515,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release)
J. R. Okajima's avatar
J. R. Okajima committed
134
135
136
137
138
139
140
141
142
 	 */
 	if (filp)
 		fput(filp);
+	if (virt_filp)
+		fput(virt_filp);
 	return err;
 }
 
diff --git a/drivers/block/loop.h b/drivers/block/loop.h
J. R. Okajima's avatar
J. R. Okajima committed
143
index 1988899db63ac..ff866d85aceac 100644
J. R. Okajima's avatar
J. R. Okajima committed
144
145
--- a/drivers/block/loop.h
+++ b/drivers/block/loop.h
J. R. Okajima's avatar
J. R. Okajima committed
146
@@ -46,7 +46,7 @@ struct loop_device {
J. R. Okajima's avatar
J. R. Okajima committed
147
148
149
150
 	int		(*ioctl)(struct loop_device *, int cmd, 
 				 unsigned long arg); 
 
-	struct file *	lo_backing_file;
J. R. Okajima's avatar
J. R. Okajima committed
151
+	struct file	*lo_backing_file, *lo_backing_virt_file;
J. R. Okajima's avatar
J. R. Okajima committed
152
153
154
155
 	struct block_device *lo_device;
 	void		*key_data; 
 
diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c
J. R. Okajima's avatar
J. R. Okajima committed
156
index 9f58ba0cb769f..1c2267a5a2ae1 100644
J. R. Okajima's avatar
J. R. Okajima committed
157
158
--- a/fs/aufs/f_op.c
+++ b/fs/aufs/f_op.c
J. R. Okajima's avatar
J. R. Okajima committed
159
@@ -304,7 +304,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter)
J. R. Okajima's avatar
J. R. Okajima committed
160
161
162
163
164
165
166
167
168
 	if (IS_ERR(h_file))
 		goto out;
 
-	if (au_test_loopback_kthread()) {
+	if (0 && au_test_loopback_kthread()) {
 		au_warn_loopback(h_file->f_path.dentry->d_sb);
 		if (file->f_mapping != h_file->f_mapping) {
 			file->f_mapping = h_file->f_mapping;
diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c
J. R. Okajima's avatar
J. R. Okajima committed
169
index a8b63acc62045..9d97c3af5686a 100644
J. R. Okajima's avatar
J. R. Okajima committed
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
--- a/fs/aufs/loop.c
+++ b/fs/aufs/loop.c
@@ -133,3 +133,19 @@ void au_loopback_fin(void)
 		symbol_put(loop_backing_file);
 	au_kfree_try_rcu(au_warn_loopback_array);
 }
+
+/* ---------------------------------------------------------------------- */
+
+/* support the loopback block device insude aufs */
+
+struct file *aufs_real_loop(struct file *file)
+{
+	struct file *f;
+
+	BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb));
+	fi_read_lock(file);
+	f = au_hf_top(file);
+	fi_read_unlock(file);
+	AuDebugOn(!f);
+	return f;
+}
diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h
J. R. Okajima's avatar
J. R. Okajima committed
193
index 94f4f80ae33bf..ca1194354aff4 100644
J. R. Okajima's avatar
J. R. Okajima committed
194
195
196
197
198
199
200
201
202
--- a/fs/aufs/loop.h
+++ b/fs/aufs/loop.h
@@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb);
 
 int au_loopback_init(void);
 void au_loopback_fin(void);
+
+struct file *aufs_real_loop(struct file *file);
 #else
J. R. Okajima's avatar
J. R. Okajima committed
203
 AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb)
J. R. Okajima's avatar
J. R. Okajima committed
204
205
206
207
208
209
210
211
212
213
214
 
@@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb)
 
 AuStubInt0(au_loopback_init, void)
 AuStubVoid(au_loopback_fin, void)
+
+AuStub(struct file *, aufs_real_loop, return NULL, struct file *file)
 #endif /* BLK_DEV_LOOP */
 
 #endif /* __KERNEL__ */
diff --git a/fs/aufs/super.c b/fs/aufs/super.c
J. R. Okajima's avatar
J. R. Okajima committed
215
index d252963a87b53..ecfc5fc96ad8c 100644
J. R. Okajima's avatar
J. R. Okajima committed
216
217
--- a/fs/aufs/super.c
+++ b/fs/aufs/super.c
J. R. Okajima's avatar
J. R. Okajima committed
218
@@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = {
J. R. Okajima's avatar
J. R. Okajima committed
219
220
221
222
223
224
225
226
227
228
229
230
 	.statfs		= aufs_statfs,
 	.put_super	= aufs_put_super,
 	.sync_fs	= aufs_sync_fs,
-	.remount_fs	= aufs_remount_fs
+	.remount_fs	= aufs_remount_fs,
+#ifdef CONFIG_AUFS_BDEV_LOOP
+	.real_loop	= aufs_real_loop
+#endif
 };
 
 /* ---------------------------------------------------------------------- */
diff --git a/include/linux/fs.h b/include/linux/fs.h
J. R. Okajima's avatar
J. R. Okajima committed
231
index ffeed3ccd2d62..6a8e599051b77 100644
J. R. Okajima's avatar
J. R. Okajima committed
232
233
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
J. R. Okajima's avatar
J. R. Okajima committed
234
@@ -2177,6 +2177,10 @@ struct super_operations {
J. R. Okajima's avatar
J. R. Okajima committed
235
236
237
 				  struct shrink_control *);
 	long (*free_cached_objects)(struct super_block *,
 				    struct shrink_control *);
J. R. Okajima's avatar
J. R. Okajima committed
238
+#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE)
J. R. Okajima's avatar
J. R. Okajima committed
239
240
241
242
243
244
+	/* and aufs */
+	struct file *(*real_loop)(struct file *);
+#endif
 };
 
 /*