vfsub.h 9.05 KB
Newer Older
1
2
/* SPDX-License-Identifier: GPL-2.0 */
/*
3
 * Copyright (C) 2005-2020 Junjiro R. Okajima
4
5
6
7
8
9
10
11
12
13
14
15
 */

/*
 * sub-routines for VFS
 */

#ifndef __AUFS_VFSUB_H__
#define __AUFS_VFSUB_H__

#ifdef __KERNEL__

#include <linux/fs.h>
16
#include <linux/mount.h>
J. R. Okajima's avatar
J. R. Okajima committed
17
18
#include <linux/posix_acl.h>
#include <linux/xattr.h>
19
20
#include "debug.h"

21
22
/* copied from linux/fs/internal.h */
/* todo: BAD approach!! */
23
extern void __mnt_drop_write(struct vfsmount *);
24
25
extern struct file *alloc_empty_file(int, const struct cred *);

J. R. Okajima's avatar
J. R. Okajima committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* ---------------------------------------------------------------------- */

/* lock subclass for lower inode */
/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */
/* reduce? gave up. */
enum {
	AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */
	AuLsc_I_PARENT,		/* lower inode, parent first */
	AuLsc_I_PARENT2,	/* copyup dirs */
	AuLsc_I_PARENT3,	/* copyup wh */
	AuLsc_I_CHILD,
	AuLsc_I_CHILD2,
	AuLsc_I_End
};

41
42
43
44
/* to debug easier, do not make them inlined functions */
#define MtxMustLock(mtx)	AuDebugOn(!mutex_is_locked(mtx))
#define IMustLock(i)		AuDebugOn(!inode_is_locked(i))

J. R. Okajima's avatar
J. R. Okajima committed
45
/* ---------------------------------------------------------------------- */
J. R. Okajima's avatar
J. R. Okajima committed
46

J. R. Okajima's avatar
J. R. Okajima committed
47
48
49
50
51
52
static inline void vfsub_drop_nlink(struct inode *inode)
{
	AuDebugOn(!inode->i_nlink);
	drop_nlink(inode);
}

J. R. Okajima's avatar
J. R. Okajima committed
53
54
55
56
57
58
59
static inline void vfsub_dead_dir(struct inode *inode)
{
	AuDebugOn(!S_ISDIR(inode->i_mode));
	inode->i_flags |= S_DEAD;
	clear_nlink(inode);
}

J. R. Okajima's avatar
J. R. Okajima committed
60
61
62
63
64
65
66
67
static inline int vfsub_native_ro(struct inode *inode)
{
	return sb_rdonly(inode->i_sb)
		|| IS_RDONLY(inode)
		/* || IS_APPEND(inode) */
		|| IS_IMMUTABLE(inode);
}

68
69
70
71
72
73
#ifdef CONFIG_AUFS_BR_FUSE
int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb);
#else
AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb);
#endif

J. R. Okajima's avatar
J. R. Okajima committed
74
75
76
int vfsub_sync_filesystem(struct super_block *h_sb, int wait);

/* ---------------------------------------------------------------------- */
J. R. Okajima's avatar
J. R. Okajima committed
77

78
int vfsub_update_h_iattr(struct path *h_path, int *did);
J. R. Okajima's avatar
J. R. Okajima committed
79
80
struct file *vfsub_dentry_open(struct path *path, int flags);
struct file *vfsub_filp_open(const char *path, int oflags, int mode);
81
82
83
84
85
86
87
88
89
struct au_branch;
struct vfsub_aopen_args {
	struct file		*file;
	unsigned int		open_flag;
	umode_t			create_mode;
	struct au_branch	*br;
};
int vfsub_atomic_open(struct inode *dir, struct dentry *dentry,
		      struct vfsub_aopen_args *args);
90
91
int vfsub_kern_path(const char *name, unsigned int flags, struct path *path);

J. R. Okajima's avatar
J. R. Okajima committed
92
93
struct dentry *vfsub_lookup_one_len_unlocked(const char *name,
					     struct dentry *parent, int len);
J. R. Okajima's avatar
J. R. Okajima committed
94
95
96
struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent,
				    int len);

97
98
99
100
101
102
struct vfsub_lkup_one_args {
	struct dentry **errp;
	struct qstr *name;
	struct dentry *parent;
};

J. R. Okajima's avatar
J. R. Okajima committed
103
104
105
106
107
108
static inline struct dentry *vfsub_lkup_one(struct qstr *name,
					    struct dentry *parent)
{
	return vfsub_lookup_one_len(name->name, parent, name->len);
}

109
110
void vfsub_call_lkup_one(void *args);

J. R. Okajima's avatar
J. R. Okajima committed
111
112
/* ---------------------------------------------------------------------- */

113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
static inline int vfsub_mnt_want_write(struct vfsmount *mnt)
{
	int err;

	lockdep_off();
	err = mnt_want_write(mnt);
	lockdep_on();
	return err;
}

static inline void vfsub_mnt_drop_write(struct vfsmount *mnt)
{
	lockdep_off();
	mnt_drop_write(mnt);
	lockdep_on();
}

J. R. Okajima's avatar
J. R. Okajima committed
130
131
132
133
134
135
136
137
138
#if 0 /* reserved */
static inline void vfsub_mnt_drop_write_file(struct file *file)
{
	lockdep_off();
	mnt_drop_write_file(file);
	lockdep_on();
}
#endif

139
140
/* ---------------------------------------------------------------------- */

141
142
143
144
145
146
struct au_hinode;
struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1,
				 struct dentry *d2, struct au_hinode *hdir2);
void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1,
			 struct dentry *d2, struct au_hinode *hdir2);

147
148
int vfsub_create(struct inode *dir, struct path *path, int mode,
		 bool want_excl);
J. R. Okajima's avatar
J. R. Okajima committed
149
150
151
int vfsub_symlink(struct inode *dir, struct path *path,
		  const char *symname);
int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev);
152
153
int vfsub_link(struct dentry *src_dentry, struct inode *dir,
	       struct path *path, struct inode **delegated_inode);
J. R. Okajima's avatar
J. R. Okajima committed
154
155
156
int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry,
		 struct inode *hdir, struct path *path,
		 struct inode **delegated_inode, unsigned int flags);
157
158
int vfsub_mkdir(struct inode *dir, struct path *path, int mode);
int vfsub_rmdir(struct inode *dir, struct path *path);
159
160
161

/* ---------------------------------------------------------------------- */

162
163
164
165
166
167
168
169
ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count,
		     loff_t *ppos);
ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count,
			loff_t *ppos);
ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count,
		      loff_t *ppos);
ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count,
		      loff_t *ppos);
J. R. Okajima's avatar
J. R. Okajima committed
170
int vfsub_flush(struct file *file, fl_owner_t id);
J. R. Okajima's avatar
J. R. Okajima committed
171
int vfsub_iterate_dir(struct file *file, struct dir_context *ctx);
172

J. R. Okajima's avatar
J. R. Okajima committed
173
174
175
176
177
static inline loff_t vfsub_f_size_read(struct file *file)
{
	return i_size_read(file_inode(file));
}

J. R. Okajima's avatar
J. R. Okajima committed
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
static inline unsigned int vfsub_file_flags(struct file *file)
{
	unsigned int flags;

	spin_lock(&file->f_lock);
	flags = file->f_flags;
	spin_unlock(&file->f_lock);

	return flags;
}

static inline int vfsub_file_execed(struct file *file)
{
	/* todo: direct access f_flags */
	return !!(vfsub_file_flags(file) & __FMODE_EXEC);
}

J. R. Okajima's avatar
J. R. Okajima committed
195
196
197
198
199
200
201
202
#if 0 /* reserved */
static inline void vfsub_file_accessed(struct file *h_file)
{
	file_accessed(h_file);
	vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/
}
#endif

J. R. Okajima's avatar
J. R. Okajima committed
203
204
205
206
207
208
209
210
211
#if 0 /* reserved */
static inline void vfsub_touch_atime(struct vfsmount *h_mnt,
				     struct dentry *h_dentry)
{
	struct path h_path = {
		.dentry	= h_dentry,
		.mnt	= h_mnt
	};
	touch_atime(&h_path);
212
	vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/
J. R. Okajima's avatar
J. R. Okajima committed
213
214
215
}
#endif

216
217
218
219
220
221
222
static inline int vfsub_update_time(struct inode *h_inode,
				    struct timespec64 *ts, int flags)
{
	return update_time(h_inode, ts, flags);
	/* no vfsub_update_h_iattr() since we don't have struct path */
}

J. R. Okajima's avatar
J. R. Okajima committed
223
#ifdef CONFIG_FS_POSIX_ACL
224
225
static inline int vfsub_acl_chmod(struct user_namespace *h_userns,
				  struct inode *h_inode, umode_t h_mode)
J. R. Okajima's avatar
J. R. Okajima committed
226
227
228
{
	int err;

229
	err = posix_acl_chmod(h_userns, h_inode, h_mode);
J. R. Okajima's avatar
J. R. Okajima committed
230
231
232
233
234
	if (err == -EOPNOTSUPP)
		err = 0;
	return err;
}
#else
235
236
AuStubInt0(vfsub_acl_chmod, struct user_namespace *h_userns,
	   struct inode *h_inode, umode_t h_mode);
J. R. Okajima's avatar
J. R. Okajima committed
237
238
#endif

J. R. Okajima's avatar
J. R. Okajima committed
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
long vfsub_splice_to(struct file *in, loff_t *ppos,
		     struct pipe_inode_info *pipe, size_t len,
		     unsigned int flags);
long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out,
		       loff_t *ppos, size_t len, unsigned int flags);

static inline long vfsub_truncate(struct path *path, loff_t length)
{
	long err;

	lockdep_off();
	err = vfs_truncate(path, length);
	lockdep_on();
	return err;
}

int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr,
		struct file *h_file);
int vfsub_fsync(struct file *file, struct path *path, int datasync);

J. R. Okajima's avatar
J. R. Okajima committed
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/*
 * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such
 * ioctl.
 */
static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst,
					    loff_t len)
{
	loff_t err;

	lockdep_off();
	err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0);
	lockdep_on();

	return err;
}

J. R. Okajima's avatar
J. R. Okajima committed
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/* copy_file_range(2) is a systemcall */
static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos,
					    struct file *dst, loff_t dst_pos,
					    size_t len, unsigned int flags)
{
	ssize_t ssz;

	lockdep_off();
	ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags);
	lockdep_on();

	return ssz;
}

J. R. Okajima's avatar
J. R. Okajima committed
289
290
291
292
293
294
295
296
297
298
299
300
/* ---------------------------------------------------------------------- */

static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin)
{
	loff_t err;

	lockdep_off();
	err = vfs_llseek(file, offset, origin);
	lockdep_on();
	return err;
}

J. R. Okajima's avatar
J. R. Okajima committed
301
302
/* ---------------------------------------------------------------------- */

303
304
int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode);
int vfsub_sio_rmdir(struct inode *dir, struct path *path);
J. R. Okajima's avatar
J. R. Okajima committed
305
306
307
308
int vfsub_sio_notify_change(struct path *path, struct iattr *ia,
			    struct inode **delegated_inode);
int vfsub_notify_change(struct path *path, struct iattr *ia,
			struct inode **delegated_inode);
J. R. Okajima's avatar
J. R. Okajima committed
309
310
311
int vfsub_unlink(struct inode *dir, struct path *path,
		 struct inode **delegated_inode, int force);

J. R. Okajima's avatar
J. R. Okajima committed
312
313
314
315
316
static inline int vfsub_getattr(const struct path *path, struct kstat *st)
{
	return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT);
}

J. R. Okajima's avatar
J. R. Okajima committed
317
318
/* ---------------------------------------------------------------------- */

319
320
static inline int vfsub_setxattr(struct user_namespace *userns,
				 struct dentry *dentry, const char *name,
J. R. Okajima's avatar
J. R. Okajima committed
321
322
323
324
325
				 const void *value, size_t size, int flags)
{
	int err;

	lockdep_off();
326
	err = vfs_setxattr(userns, dentry, name, value, size, flags);
J. R. Okajima's avatar
J. R. Okajima committed
327
328
329
330
331
	lockdep_on();

	return err;
}

332
333
static inline int vfsub_removexattr(struct user_namespace *userns,
				    struct dentry *dentry, const char *name)
J. R. Okajima's avatar
J. R. Okajima committed
334
335
336
337
{
	int err;

	lockdep_off();
338
	err = vfs_removexattr(userns, dentry, name);
J. R. Okajima's avatar
J. R. Okajima committed
339
340
341
342
343
	lockdep_on();

	return err;
}

344
345
#endif /* __KERNEL__ */
#endif /* __AUFS_VFSUB_H__ */