blob: 3dc693a78de2209d54c2b1f4f8e0491f8e0a6b2d [file] [log] [blame]
Miklos Szeredie9be9d52014-10-24 00:14:38 +02001/*
2 *
3 * Copyright (C) 2011 Novell Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 */
9
10#include <linux/fs.h>
11#include <linux/slab.h>
Ingo Molnar5b825c32017-02-02 17:54:15 +010012#include <linux/cred.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +020013#include <linux/xattr.h>
Miklos Szeredi5201dc42016-09-01 11:11:59 +020014#include <linux/posix_acl.h>
Miklos Szeredie9be9d52014-10-24 00:14:38 +020015#include "overlayfs.h"
16
Miklos Szeredie9be9d52014-10-24 00:14:38 +020017int ovl_setattr(struct dentry *dentry, struct iattr *attr)
18{
19 int err;
20 struct dentry *upperdentry;
Vivek Goyal1175b6b2016-07-01 16:34:28 -040021 const struct cred *old_cred;
Miklos Szeredie9be9d52014-10-24 00:14:38 +020022
Miklos Szeredicf9a6782015-12-11 16:30:49 +010023 /*
24 * Check for permissions before trying to copy-up. This is redundant
25 * since it will be rechecked later by ->setattr() on upper dentry. But
26 * without this, copy-up can be triggered by just about anybody.
27 *
28 * We don't initialize inode->size, which just means that
29 * inode_newsize_ok() will always check against MAX_LFS_FILESIZE and not
30 * check for a swapfile (which this won't be anyway).
31 */
Jan Kara31051c82016-05-26 16:55:18 +020032 err = setattr_prepare(dentry, attr);
Miklos Szeredicf9a6782015-12-11 16:30:49 +010033 if (err)
34 return err;
35
Miklos Szeredie9be9d52014-10-24 00:14:38 +020036 err = ovl_want_write(dentry);
37 if (err)
38 goto out;
39
Miklos Szerediacff81e2015-12-04 19:18:48 +010040 err = ovl_copy_up(dentry);
41 if (!err) {
42 upperdentry = ovl_dentry_upper(dentry);
43
Miklos Szeredib99c2d92016-07-04 16:49:48 +020044 if (attr->ia_valid & (ATTR_KILL_SUID|ATTR_KILL_SGID))
45 attr->ia_valid &= ~ATTR_MODE;
46
Al Viro59551022016-01-22 15:40:57 -050047 inode_lock(upperdentry->d_inode);
Vivek Goyal1175b6b2016-07-01 16:34:28 -040048 old_cred = ovl_override_creds(dentry->d_sb);
Miklos Szeredie9be9d52014-10-24 00:14:38 +020049 err = notify_change(upperdentry, attr, NULL);
Vivek Goyal1175b6b2016-07-01 16:34:28 -040050 revert_creds(old_cred);
Konstantin Khlebnikovb81de062016-01-31 16:21:29 +030051 if (!err)
52 ovl_copyattr(upperdentry->d_inode, dentry->d_inode);
Al Viro59551022016-01-22 15:40:57 -050053 inode_unlock(upperdentry->d_inode);
Miklos Szeredie9be9d52014-10-24 00:14:38 +020054 }
55 ovl_drop_write(dentry);
56out:
57 return err;
58}
59
David Howellsa528d352017-01-31 16:46:22 +000060static int ovl_getattr(const struct path *path, struct kstat *stat,
61 u32 request_mask, unsigned int flags)
Miklos Szeredie9be9d52014-10-24 00:14:38 +020062{
David Howellsa528d352017-01-31 16:46:22 +000063 struct dentry *dentry = path->dentry;
Amir Goldstein72b608f2017-04-24 00:25:49 +030064 enum ovl_path_type type;
Miklos Szeredie9be9d52014-10-24 00:14:38 +020065 struct path realpath;
Vivek Goyal1175b6b2016-07-01 16:34:28 -040066 const struct cred *old_cred;
67 int err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +020068
Amir Goldstein72b608f2017-04-24 00:25:49 +030069 type = ovl_path_real(dentry, &realpath);
Vivek Goyal1175b6b2016-07-01 16:34:28 -040070 old_cred = ovl_override_creds(dentry->d_sb);
David Howellsa528d352017-01-31 16:46:22 +000071 err = vfs_getattr(&realpath, stat, request_mask, flags);
Amir Goldstein72b608f2017-04-24 00:25:49 +030072 if (err)
73 goto out;
74
75 /*
76 * When all layers are on the same fs, all real inode number are
77 * unique, so we use the overlay st_dev, which is friendly to du -x.
78 *
79 * We also use st_ino of the copy up origin, if we know it.
80 * This guaranties constant st_dev/st_ino across copy up.
81 *
82 * If filesystem supports NFS export ops, this also guaranties
83 * persistent st_ino across mount cycle.
84 */
85 if (ovl_same_sb(dentry->d_sb)) {
86 if (OVL_TYPE_ORIGIN(type)) {
87 struct kstat lowerstat;
88
89 ovl_path_lower(dentry, &realpath);
90 err = vfs_getattr(&realpath, &lowerstat,
91 STATX_INO | STATX_NLINK, flags);
92 if (err)
93 goto out;
94
95 WARN_ON_ONCE(stat->dev != lowerstat.dev);
96 /*
97 * Lower hardlinks are broken on copy up to different
98 * upper files, so we cannot use the lower origin st_ino
99 * for those different files, even for the same fs case.
100 */
101 if (lowerstat.nlink == 1)
102 stat->ino = lowerstat.ino;
103 }
104 stat->dev = dentry->d_sb->s_dev;
105 }
106out:
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400107 revert_creds(old_cred);
Amir Goldstein72b608f2017-04-24 00:25:49 +0300108
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400109 return err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200110}
111
112int ovl_permission(struct inode *inode, int mask)
113{
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200114 bool is_upper;
Miklos Szeredi39b681f2016-07-29 12:05:24 +0200115 struct inode *realinode = ovl_inode_real(inode, &is_upper);
Vivek Goyalc0ca3d72016-07-01 16:34:27 -0400116 const struct cred *old_cred;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200117 int err;
118
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200119 /* Careful in RCU walk mode */
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200120 if (!realinode) {
121 WARN_ON(!(mask & MAY_NOT_BLOCK));
Miklos Szeredia999d7e2016-07-29 12:05:23 +0200122 return -ECHILD;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200123 }
124
Vivek Goyalc0ca3d72016-07-01 16:34:27 -0400125 /*
126 * Check overlay inode with the creds of task and underlying inode
127 * with creds of mounter
128 */
129 err = generic_permission(inode, mask);
130 if (err)
131 return err;
132
133 old_cred = ovl_override_creds(inode->i_sb);
Vivek Goyal500cac32016-07-13 11:00:14 -0400134 if (!is_upper && !special_file(realinode->i_mode) && mask & MAY_WRITE) {
Vivek Goyal754f8cb2016-07-01 16:34:29 -0400135 mask &= ~(MAY_WRITE | MAY_APPEND);
Vivek Goyal500cac32016-07-13 11:00:14 -0400136 /* Make sure mounter can read file for copy up later */
137 mask |= MAY_READ;
138 }
Miklos Szeredi9c630eb2016-07-29 12:05:23 +0200139 err = inode_permission(realinode, mask);
Vivek Goyalc0ca3d72016-07-01 16:34:27 -0400140 revert_creds(old_cred);
141
142 return err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200143}
144
Al Viro6b255392015-11-17 10:20:54 -0500145static const char *ovl_get_link(struct dentry *dentry,
Al Virofceef392015-12-29 15:58:39 -0500146 struct inode *inode,
147 struct delayed_call *done)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200148{
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400149 const struct cred *old_cred;
150 const char *p;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200151
Al Viro6b255392015-11-17 10:20:54 -0500152 if (!dentry)
153 return ERR_PTR(-ECHILD);
154
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400155 old_cred = ovl_override_creds(dentry->d_sb);
Miklos Szeredi77642352016-10-04 14:40:45 +0200156 p = vfs_get_link(ovl_dentry_real(dentry), done);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400157 revert_creds(old_cred);
158 return p;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200159}
160
Miklos Szeredi09562542016-08-08 15:08:49 +0200161bool ovl_is_private_xattr(const char *name)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200162{
Andreas Gruenbacherfe2b7592016-08-22 17:59:22 +0200163 return strncmp(name, OVL_XATTR_PREFIX,
164 sizeof(OVL_XATTR_PREFIX) - 1) == 0;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200165}
166
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200167int ovl_xattr_set(struct dentry *dentry, const char *name, const void *value,
168 size_t size, int flags)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200169{
170 int err;
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200171 struct path realpath;
172 enum ovl_path_type type = ovl_path_real(dentry, &realpath);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400173 const struct cred *old_cred;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200174
175 err = ovl_want_write(dentry);
176 if (err)
177 goto out;
178
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200179 if (!value && !OVL_TYPE_UPPER(type)) {
180 err = vfs_getxattr(realpath.dentry, name, NULL, 0);
181 if (err < 0)
182 goto out_drop_write;
183 }
184
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200185 err = ovl_copy_up(dentry);
186 if (err)
187 goto out_drop_write;
188
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200189 if (!OVL_TYPE_UPPER(type))
190 ovl_path_upper(dentry, &realpath);
191
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400192 old_cred = ovl_override_creds(dentry->d_sb);
Andreas Gruenbacher0e585cc2016-08-22 17:22:11 +0200193 if (value)
194 err = vfs_setxattr(realpath.dentry, name, value, size, flags);
195 else {
196 WARN_ON(flags != XATTR_REPLACE);
197 err = vfs_removexattr(realpath.dentry, name);
198 }
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400199 revert_creds(old_cred);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200200
201out_drop_write:
202 ovl_drop_write(dentry);
203out:
204 return err;
205}
206
Andreas Gruenbacher0eb45fc2016-08-22 17:52:55 +0200207int ovl_xattr_get(struct dentry *dentry, const char *name,
208 void *value, size_t size)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200209{
Miklos Szeredib5817552016-06-06 16:21:37 +0200210 struct dentry *realdentry = ovl_dentry_real(dentry);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400211 ssize_t res;
212 const struct cred *old_cred;
Miklos Szeredi52148462014-11-20 16:40:00 +0100213
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400214 old_cred = ovl_override_creds(dentry->d_sb);
215 res = vfs_getxattr(realdentry, name, value, size);
216 revert_creds(old_cred);
217 return res;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200218}
219
220ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
221{
Miklos Szeredib5817552016-06-06 16:21:37 +0200222 struct dentry *realdentry = ovl_dentry_real(dentry);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200223 ssize_t res;
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200224 size_t len;
225 char *s;
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400226 const struct cred *old_cred;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200227
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400228 old_cred = ovl_override_creds(dentry->d_sb);
Miklos Szeredib5817552016-06-06 16:21:37 +0200229 res = vfs_listxattr(realdentry, list, size);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400230 revert_creds(old_cred);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200231 if (res <= 0 || size == 0)
232 return res;
233
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200234 /* filter out private xattrs */
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200235 for (s = list, len = res; len;) {
236 size_t slen = strnlen(s, len) + 1;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200237
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200238 /* underlying fs providing us with an broken xattr list? */
239 if (WARN_ON(slen > len))
240 return -EIO;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200241
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200242 len -= slen;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200243 if (ovl_is_private_xattr(s)) {
244 res -= slen;
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200245 memmove(s, s + slen, len);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200246 } else {
Miklos Szeredi7cb35112016-09-01 11:12:00 +0200247 s += slen;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200248 }
249 }
250
251 return res;
252}
253
Vivek Goyal39a25b22016-07-01 16:34:26 -0400254struct posix_acl *ovl_get_acl(struct inode *inode, int type)
255{
Miklos Szeredi39b681f2016-07-29 12:05:24 +0200256 struct inode *realinode = ovl_inode_real(inode, NULL);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400257 const struct cred *old_cred;
258 struct posix_acl *acl;
Vivek Goyal39a25b22016-07-01 16:34:26 -0400259
Miklos Szeredi5201dc42016-09-01 11:11:59 +0200260 if (!IS_ENABLED(CONFIG_FS_POSIX_ACL) || !IS_POSIXACL(realinode))
Vivek Goyal39a25b22016-07-01 16:34:26 -0400261 return NULL;
262
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400263 old_cred = ovl_override_creds(inode->i_sb);
Miklos Szeredi5201dc42016-09-01 11:11:59 +0200264 acl = get_acl(realinode, type);
Vivek Goyal1175b6b2016-07-01 16:34:28 -0400265 revert_creds(old_cred);
266
267 return acl;
Vivek Goyal39a25b22016-07-01 16:34:26 -0400268}
269
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200270static bool ovl_open_need_copy_up(int flags, enum ovl_path_type type,
271 struct dentry *realdentry)
272{
Miklos Szeredi1afaba12014-12-13 00:59:42 +0100273 if (OVL_TYPE_UPPER(type))
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200274 return false;
275
276 if (special_file(realdentry->d_inode->i_mode))
277 return false;
278
279 if (!(OPEN_FMODE(flags) & FMODE_WRITE) && !(flags & O_TRUNC))
280 return false;
281
282 return true;
283}
284
Miklos Szeredi2d902672016-06-30 08:53:27 +0200285int ovl_open_maybe_copy_up(struct dentry *dentry, unsigned int file_flags)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200286{
Miklos Szeredi2d902672016-06-30 08:53:27 +0200287 int err = 0;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200288 struct path realpath;
289 enum ovl_path_type type;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200290
291 type = ovl_path_real(dentry, &realpath);
David Howells4bacc9c2015-06-18 14:32:31 +0100292 if (ovl_open_need_copy_up(file_flags, type, realpath.dentry)) {
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200293 err = ovl_want_write(dentry);
Miklos Szeredi2d902672016-06-30 08:53:27 +0200294 if (!err) {
Amir Goldstein9aba6522016-11-12 21:36:03 +0200295 err = ovl_copy_up_flags(dentry, file_flags);
Miklos Szeredi2d902672016-06-30 08:53:27 +0200296 ovl_drop_write(dentry);
297 }
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200298 }
299
Miklos Szeredi2d902672016-06-30 08:53:27 +0200300 return err;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200301}
302
Miklos Szeredid719e8f2016-07-29 12:05:23 +0200303int ovl_update_time(struct inode *inode, struct timespec *ts, int flags)
304{
305 struct dentry *alias;
306 struct path upperpath;
307
308 if (!(flags & S_ATIME))
309 return 0;
310
311 alias = d_find_any_alias(inode);
312 if (!alias)
313 return 0;
314
315 ovl_path_upper(alias, &upperpath);
316 if (upperpath.dentry) {
317 touch_atime(&upperpath);
318 inode->i_atime = d_inode(upperpath.dentry)->i_atime;
319 }
320
321 dput(alias);
322
323 return 0;
324}
325
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200326static const struct inode_operations ovl_file_inode_operations = {
327 .setattr = ovl_setattr,
328 .permission = ovl_permission,
329 .getattr = ovl_getattr,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200330 .listxattr = ovl_listxattr,
Vivek Goyal39a25b22016-07-01 16:34:26 -0400331 .get_acl = ovl_get_acl,
Miklos Szeredid719e8f2016-07-29 12:05:23 +0200332 .update_time = ovl_update_time,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200333};
334
335static const struct inode_operations ovl_symlink_inode_operations = {
336 .setattr = ovl_setattr,
Al Viro6b255392015-11-17 10:20:54 -0500337 .get_link = ovl_get_link,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200338 .getattr = ovl_getattr,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200339 .listxattr = ovl_listxattr,
Miklos Szeredid719e8f2016-07-29 12:05:23 +0200340 .update_time = ovl_update_time,
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200341};
342
Amir Goldsteinb1eaa952017-01-11 12:07:46 +0200343/*
344 * It is possible to stack overlayfs instance on top of another
345 * overlayfs instance as lower layer. We need to annonate the
346 * stackable i_mutex locks according to stack level of the super
347 * block instance. An overlayfs instance can never be in stack
348 * depth 0 (there is always a real fs below it). An overlayfs
349 * inode lock will use the lockdep annotaion ovl_i_mutex_key[depth].
350 *
351 * For example, here is a snip from /proc/lockdep_chains after
352 * dir_iterate of nested overlayfs:
353 *
354 * [...] &ovl_i_mutex_dir_key[depth] (stack_depth=2)
355 * [...] &ovl_i_mutex_dir_key[depth]#2 (stack_depth=1)
356 * [...] &type->i_mutex_dir_key (stack_depth=0)
357 */
358#define OVL_MAX_NESTING FILESYSTEM_MAX_STACK_DEPTH
359
360static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
361{
362#ifdef CONFIG_LOCKDEP
363 static struct lock_class_key ovl_i_mutex_key[OVL_MAX_NESTING];
364 static struct lock_class_key ovl_i_mutex_dir_key[OVL_MAX_NESTING];
365
366 int depth = inode->i_sb->s_stack_depth - 1;
367
368 if (WARN_ON_ONCE(depth < 0 || depth >= OVL_MAX_NESTING))
369 depth = 0;
370
371 if (S_ISDIR(inode->i_mode))
372 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_dir_key[depth]);
373 else
374 lockdep_set_class(&inode->i_rwsem, &ovl_i_mutex_key[depth]);
375#endif
376}
377
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100378static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev)
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200379{
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200380 inode->i_ino = get_next_ino();
381 inode->i_mode = mode;
Miklos Szeredid719e8f2016-07-29 12:05:23 +0200382 inode->i_flags |= S_NOCMTIME;
Miklos Szeredi2a3a2a32016-09-01 11:11:59 +0200383#ifdef CONFIG_FS_POSIX_ACL
384 inode->i_acl = inode->i_default_acl = ACL_DONT_CACHE;
385#endif
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200386
Amir Goldsteinb1eaa952017-01-11 12:07:46 +0200387 ovl_lockdep_annotate_inode_mutex_key(inode);
388
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100389 switch (mode & S_IFMT) {
390 case S_IFREG:
391 inode->i_op = &ovl_file_inode_operations;
392 break;
393
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200394 case S_IFDIR:
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200395 inode->i_op = &ovl_dir_inode_operations;
396 inode->i_fop = &ovl_dir_operations;
397 break;
398
399 case S_IFLNK:
400 inode->i_op = &ovl_symlink_inode_operations;
401 break;
402
Miklos Szeredi51f7e522016-07-29 12:05:24 +0200403 default:
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200404 inode->i_op = &ovl_file_inode_operations;
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100405 init_special_inode(inode, mode, rdev);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200406 break;
Miklos Szeredi51f7e522016-07-29 12:05:24 +0200407 }
408}
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200409
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100410struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev)
Miklos Szeredi51f7e522016-07-29 12:05:24 +0200411{
412 struct inode *inode;
413
414 inode = new_inode(sb);
415 if (inode)
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100416 ovl_fill_inode(inode, mode, rdev);
Miklos Szeredi51f7e522016-07-29 12:05:24 +0200417
418 return inode;
419}
420
421static int ovl_inode_test(struct inode *inode, void *data)
422{
423 return ovl_inode_real(inode, NULL) == data;
424}
425
426static int ovl_inode_set(struct inode *inode, void *data)
427{
428 inode->i_private = (void *) (((unsigned long) data) | OVL_ISUPPER_MASK);
429 return 0;
430}
431
432struct inode *ovl_get_inode(struct super_block *sb, struct inode *realinode)
433
434{
435 struct inode *inode;
436
437 inode = iget5_locked(sb, (unsigned long) realinode,
438 ovl_inode_test, ovl_inode_set, realinode);
439 if (inode && inode->i_state & I_NEW) {
Miklos Szeredica4c8a32016-12-16 11:02:55 +0100440 ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev);
Miklos Szeredi51f7e522016-07-29 12:05:24 +0200441 set_nlink(inode, realinode->i_nlink);
442 unlock_new_inode(inode);
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200443 }
444
445 return inode;
Miklos Szeredie9be9d52014-10-24 00:14:38 +0200446}