Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 1 | /* |
| 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/namei.h> |
| 12 | #include <linux/xattr.h> |
| 13 | #include <linux/security.h> |
| 14 | #include <linux/cred.h> |
| 15 | #include "overlayfs.h" |
| 16 | |
| 17 | void ovl_cleanup(struct inode *wdir, struct dentry *wdentry) |
| 18 | { |
| 19 | int err; |
| 20 | |
| 21 | dget(wdentry); |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 22 | if (d_is_dir(wdentry)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 23 | err = ovl_do_rmdir(wdir, wdentry); |
| 24 | else |
| 25 | err = ovl_do_unlink(wdir, wdentry); |
| 26 | dput(wdentry); |
| 27 | |
| 28 | if (err) { |
| 29 | pr_err("overlayfs: cleanup of '%pd2' failed (%i)\n", |
| 30 | wdentry, err); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | struct dentry *ovl_lookup_temp(struct dentry *workdir, struct dentry *dentry) |
| 35 | { |
| 36 | struct dentry *temp; |
| 37 | char name[20]; |
| 38 | |
| 39 | snprintf(name, sizeof(name), "#%lx", (unsigned long) dentry); |
| 40 | |
| 41 | temp = lookup_one_len(name, workdir, strlen(name)); |
| 42 | if (!IS_ERR(temp) && temp->d_inode) { |
| 43 | pr_err("overlayfs: workdir/%s already exists\n", name); |
| 44 | dput(temp); |
| 45 | temp = ERR_PTR(-EIO); |
| 46 | } |
| 47 | |
| 48 | return temp; |
| 49 | } |
| 50 | |
| 51 | /* caller holds i_mutex on workdir */ |
| 52 | static struct dentry *ovl_whiteout(struct dentry *workdir, |
| 53 | struct dentry *dentry) |
| 54 | { |
| 55 | int err; |
| 56 | struct dentry *whiteout; |
| 57 | struct inode *wdir = workdir->d_inode; |
| 58 | |
| 59 | whiteout = ovl_lookup_temp(workdir, dentry); |
| 60 | if (IS_ERR(whiteout)) |
| 61 | return whiteout; |
| 62 | |
| 63 | err = ovl_do_whiteout(wdir, whiteout); |
| 64 | if (err) { |
| 65 | dput(whiteout); |
| 66 | whiteout = ERR_PTR(err); |
| 67 | } |
| 68 | |
| 69 | return whiteout; |
| 70 | } |
| 71 | |
| 72 | int ovl_create_real(struct inode *dir, struct dentry *newdentry, |
| 73 | struct kstat *stat, const char *link, |
| 74 | struct dentry *hardlink, bool debug) |
| 75 | { |
| 76 | int err; |
| 77 | |
| 78 | if (newdentry->d_inode) |
| 79 | return -ESTALE; |
| 80 | |
| 81 | if (hardlink) { |
| 82 | err = ovl_do_link(hardlink, dir, newdentry, debug); |
| 83 | } else { |
| 84 | switch (stat->mode & S_IFMT) { |
| 85 | case S_IFREG: |
| 86 | err = ovl_do_create(dir, newdentry, stat->mode, debug); |
| 87 | break; |
| 88 | |
| 89 | case S_IFDIR: |
| 90 | err = ovl_do_mkdir(dir, newdentry, stat->mode, debug); |
| 91 | break; |
| 92 | |
| 93 | case S_IFCHR: |
| 94 | case S_IFBLK: |
| 95 | case S_IFIFO: |
| 96 | case S_IFSOCK: |
| 97 | err = ovl_do_mknod(dir, newdentry, |
| 98 | stat->mode, stat->rdev, debug); |
| 99 | break; |
| 100 | |
| 101 | case S_IFLNK: |
| 102 | err = ovl_do_symlink(dir, newdentry, link, debug); |
| 103 | break; |
| 104 | |
| 105 | default: |
| 106 | err = -EPERM; |
| 107 | } |
| 108 | } |
| 109 | if (!err && WARN_ON(!newdentry->d_inode)) { |
| 110 | /* |
| 111 | * Not quite sure if non-instantiated dentry is legal or not. |
| 112 | * VFS doesn't seem to care so check and warn here. |
| 113 | */ |
| 114 | err = -ENOENT; |
| 115 | } |
| 116 | return err; |
| 117 | } |
| 118 | |
| 119 | static int ovl_set_opaque(struct dentry *upperdentry) |
| 120 | { |
hujianyang | cead89b | 2014-11-24 18:25:21 +0800 | [diff] [blame] | 121 | return ovl_do_setxattr(upperdentry, OVL_XATTR_OPAQUE, "y", 1, 0); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static void ovl_remove_opaque(struct dentry *upperdentry) |
| 125 | { |
| 126 | int err; |
| 127 | |
hujianyang | cead89b | 2014-11-24 18:25:21 +0800 | [diff] [blame] | 128 | err = ovl_do_removexattr(upperdentry, OVL_XATTR_OPAQUE); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 129 | if (err) { |
| 130 | pr_warn("overlayfs: failed to remove opaque from '%s' (%i)\n", |
| 131 | upperdentry->d_name.name, err); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | static int ovl_dir_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 136 | struct kstat *stat) |
| 137 | { |
| 138 | int err; |
| 139 | enum ovl_path_type type; |
| 140 | struct path realpath; |
| 141 | |
| 142 | type = ovl_path_real(dentry, &realpath); |
| 143 | err = vfs_getattr(&realpath, stat); |
| 144 | if (err) |
| 145 | return err; |
| 146 | |
| 147 | stat->dev = dentry->d_sb->s_dev; |
| 148 | stat->ino = dentry->d_inode->i_ino; |
| 149 | |
| 150 | /* |
| 151 | * It's probably not worth it to count subdirs to get the |
| 152 | * correct link count. nlink=1 seems to pacify 'find' and |
| 153 | * other utilities. |
| 154 | */ |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 155 | if (OVL_TYPE_MERGE(type)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 156 | stat->nlink = 1; |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 161 | /* Common operations required to be done after creation of file on upper */ |
| 162 | static void ovl_instantiate(struct dentry *dentry, struct inode *inode, |
| 163 | struct dentry *newdentry) |
| 164 | { |
| 165 | ovl_dentry_version_inc(dentry->d_parent); |
| 166 | ovl_dentry_update(dentry, newdentry); |
| 167 | ovl_copyattr(newdentry->d_inode, inode); |
| 168 | d_instantiate(dentry, inode); |
| 169 | } |
| 170 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 171 | static int ovl_create_upper(struct dentry *dentry, struct inode *inode, |
| 172 | struct kstat *stat, const char *link, |
| 173 | struct dentry *hardlink) |
| 174 | { |
| 175 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 176 | struct inode *udir = upperdir->d_inode; |
| 177 | struct dentry *newdentry; |
| 178 | int err; |
| 179 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 180 | inode_lock_nested(udir, I_MUTEX_PARENT); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 181 | newdentry = lookup_one_len(dentry->d_name.name, upperdir, |
| 182 | dentry->d_name.len); |
| 183 | err = PTR_ERR(newdentry); |
| 184 | if (IS_ERR(newdentry)) |
| 185 | goto out_unlock; |
| 186 | err = ovl_create_real(udir, newdentry, stat, link, hardlink, false); |
| 187 | if (err) |
| 188 | goto out_dput; |
| 189 | |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 190 | ovl_instantiate(dentry, inode, newdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 191 | newdentry = NULL; |
| 192 | out_dput: |
| 193 | dput(newdentry); |
| 194 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 195 | inode_unlock(udir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 196 | return err; |
| 197 | } |
| 198 | |
| 199 | static int ovl_lock_rename_workdir(struct dentry *workdir, |
| 200 | struct dentry *upperdir) |
| 201 | { |
| 202 | /* Workdir should not be the same as upperdir */ |
| 203 | if (workdir == upperdir) |
| 204 | goto err; |
| 205 | |
| 206 | /* Workdir should not be subdir of upperdir and vice versa */ |
| 207 | if (lock_rename(workdir, upperdir) != NULL) |
| 208 | goto err_unlock; |
| 209 | |
| 210 | return 0; |
| 211 | |
| 212 | err_unlock: |
| 213 | unlock_rename(workdir, upperdir); |
| 214 | err: |
| 215 | pr_err("overlayfs: failed to lock workdir+upperdir\n"); |
| 216 | return -EIO; |
| 217 | } |
| 218 | |
| 219 | static struct dentry *ovl_clear_empty(struct dentry *dentry, |
| 220 | struct list_head *list) |
| 221 | { |
| 222 | struct dentry *workdir = ovl_workdir(dentry); |
| 223 | struct inode *wdir = workdir->d_inode; |
| 224 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 225 | struct inode *udir = upperdir->d_inode; |
| 226 | struct path upperpath; |
| 227 | struct dentry *upper; |
| 228 | struct dentry *opaquedir; |
| 229 | struct kstat stat; |
| 230 | int err; |
| 231 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 232 | if (WARN_ON(!workdir)) |
| 233 | return ERR_PTR(-EROFS); |
| 234 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 235 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 236 | if (err) |
| 237 | goto out; |
| 238 | |
| 239 | ovl_path_upper(dentry, &upperpath); |
| 240 | err = vfs_getattr(&upperpath, &stat); |
| 241 | if (err) |
| 242 | goto out_unlock; |
| 243 | |
| 244 | err = -ESTALE; |
| 245 | if (!S_ISDIR(stat.mode)) |
| 246 | goto out_unlock; |
| 247 | upper = upperpath.dentry; |
| 248 | if (upper->d_parent->d_inode != udir) |
| 249 | goto out_unlock; |
| 250 | |
| 251 | opaquedir = ovl_lookup_temp(workdir, dentry); |
| 252 | err = PTR_ERR(opaquedir); |
| 253 | if (IS_ERR(opaquedir)) |
| 254 | goto out_unlock; |
| 255 | |
| 256 | err = ovl_create_real(wdir, opaquedir, &stat, NULL, NULL, true); |
| 257 | if (err) |
| 258 | goto out_dput; |
| 259 | |
| 260 | err = ovl_copy_xattr(upper, opaquedir); |
| 261 | if (err) |
| 262 | goto out_cleanup; |
| 263 | |
| 264 | err = ovl_set_opaque(opaquedir); |
| 265 | if (err) |
| 266 | goto out_cleanup; |
| 267 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 268 | inode_lock(opaquedir->d_inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 269 | err = ovl_set_attr(opaquedir, &stat); |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 270 | inode_unlock(opaquedir->d_inode); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 271 | if (err) |
| 272 | goto out_cleanup; |
| 273 | |
| 274 | err = ovl_do_rename(wdir, opaquedir, udir, upper, RENAME_EXCHANGE); |
| 275 | if (err) |
| 276 | goto out_cleanup; |
| 277 | |
| 278 | ovl_cleanup_whiteouts(upper, list); |
| 279 | ovl_cleanup(wdir, upper); |
| 280 | unlock_rename(workdir, upperdir); |
| 281 | |
| 282 | /* dentry's upper doesn't match now, get rid of it */ |
| 283 | d_drop(dentry); |
| 284 | |
| 285 | return opaquedir; |
| 286 | |
| 287 | out_cleanup: |
| 288 | ovl_cleanup(wdir, opaquedir); |
| 289 | out_dput: |
| 290 | dput(opaquedir); |
| 291 | out_unlock: |
| 292 | unlock_rename(workdir, upperdir); |
| 293 | out: |
| 294 | return ERR_PTR(err); |
| 295 | } |
| 296 | |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 297 | static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 298 | { |
| 299 | int err; |
| 300 | struct dentry *ret = NULL; |
| 301 | LIST_HEAD(list); |
| 302 | |
| 303 | err = ovl_check_empty_dir(dentry, &list); |
| 304 | if (err) |
| 305 | ret = ERR_PTR(err); |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 306 | else { |
| 307 | /* |
| 308 | * If no upperdentry then skip clearing whiteouts. |
| 309 | * |
| 310 | * Can race with copy-up, since we don't hold the upperdir |
| 311 | * mutex. Doesn't matter, since copy-up can't create a |
| 312 | * non-empty directory from an empty one. |
| 313 | */ |
| 314 | if (ovl_dentry_upper(dentry)) |
| 315 | ret = ovl_clear_empty(dentry, &list); |
| 316 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 317 | |
| 318 | ovl_cache_free(&list); |
| 319 | |
| 320 | return ret; |
| 321 | } |
| 322 | |
| 323 | static int ovl_create_over_whiteout(struct dentry *dentry, struct inode *inode, |
| 324 | struct kstat *stat, const char *link, |
| 325 | struct dentry *hardlink) |
| 326 | { |
| 327 | struct dentry *workdir = ovl_workdir(dentry); |
| 328 | struct inode *wdir = workdir->d_inode; |
| 329 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 330 | struct inode *udir = upperdir->d_inode; |
| 331 | struct dentry *upper; |
| 332 | struct dentry *newdentry; |
| 333 | int err; |
| 334 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 335 | if (WARN_ON(!workdir)) |
| 336 | return -EROFS; |
| 337 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 338 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 339 | if (err) |
| 340 | goto out; |
| 341 | |
| 342 | newdentry = ovl_lookup_temp(workdir, dentry); |
| 343 | err = PTR_ERR(newdentry); |
| 344 | if (IS_ERR(newdentry)) |
| 345 | goto out_unlock; |
| 346 | |
| 347 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 348 | dentry->d_name.len); |
| 349 | err = PTR_ERR(upper); |
| 350 | if (IS_ERR(upper)) |
| 351 | goto out_dput; |
| 352 | |
| 353 | err = ovl_create_real(wdir, newdentry, stat, link, hardlink, true); |
| 354 | if (err) |
| 355 | goto out_dput2; |
| 356 | |
| 357 | if (S_ISDIR(stat->mode)) { |
| 358 | err = ovl_set_opaque(newdentry); |
| 359 | if (err) |
| 360 | goto out_cleanup; |
| 361 | |
| 362 | err = ovl_do_rename(wdir, newdentry, udir, upper, |
| 363 | RENAME_EXCHANGE); |
| 364 | if (err) |
| 365 | goto out_cleanup; |
| 366 | |
| 367 | ovl_cleanup(wdir, upper); |
| 368 | } else { |
| 369 | err = ovl_do_rename(wdir, newdentry, udir, upper, 0); |
| 370 | if (err) |
| 371 | goto out_cleanup; |
| 372 | } |
Vivek Goyal | 72e4848 | 2016-06-16 10:09:14 -0400 | [diff] [blame] | 373 | ovl_instantiate(dentry, inode, newdentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 374 | newdentry = NULL; |
| 375 | out_dput2: |
| 376 | dput(upper); |
| 377 | out_dput: |
| 378 | dput(newdentry); |
| 379 | out_unlock: |
| 380 | unlock_rename(workdir, upperdir); |
| 381 | out: |
| 382 | return err; |
| 383 | |
| 384 | out_cleanup: |
| 385 | ovl_cleanup(wdir, newdentry); |
| 386 | goto out_dput2; |
| 387 | } |
| 388 | |
| 389 | static int ovl_create_or_link(struct dentry *dentry, int mode, dev_t rdev, |
| 390 | const char *link, struct dentry *hardlink) |
| 391 | { |
| 392 | int err; |
| 393 | struct inode *inode; |
| 394 | struct kstat stat = { |
| 395 | .mode = mode, |
| 396 | .rdev = rdev, |
| 397 | }; |
| 398 | |
| 399 | err = -ENOMEM; |
| 400 | inode = ovl_new_inode(dentry->d_sb, mode, dentry->d_fsdata); |
| 401 | if (!inode) |
| 402 | goto out; |
| 403 | |
| 404 | err = ovl_copy_up(dentry->d_parent); |
| 405 | if (err) |
| 406 | goto out_iput; |
| 407 | |
| 408 | if (!ovl_dentry_is_opaque(dentry)) { |
| 409 | err = ovl_create_upper(dentry, inode, &stat, link, hardlink); |
| 410 | } else { |
| 411 | const struct cred *old_cred; |
Miklos Szeredi | d0e13f5 | 2016-06-15 14:18:59 +0200 | [diff] [blame] | 412 | struct cred *override_cred; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 413 | |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 414 | old_cred = ovl_override_creds(dentry->d_sb); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 415 | |
Miklos Szeredi | d0e13f5 | 2016-06-15 14:18:59 +0200 | [diff] [blame] | 416 | err = -ENOMEM; |
| 417 | override_cred = prepare_creds(); |
| 418 | if (override_cred) { |
| 419 | override_cred->fsuid = old_cred->fsuid; |
| 420 | override_cred->fsgid = old_cred->fsgid; |
| 421 | put_cred(override_creds(override_cred)); |
| 422 | put_cred(override_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 423 | |
Miklos Szeredi | d0e13f5 | 2016-06-15 14:18:59 +0200 | [diff] [blame] | 424 | err = ovl_create_over_whiteout(dentry, inode, &stat, |
| 425 | link, hardlink); |
| 426 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 427 | revert_creds(old_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | if (!err) |
| 431 | inode = NULL; |
| 432 | out_iput: |
| 433 | iput(inode); |
| 434 | out: |
| 435 | return err; |
| 436 | } |
| 437 | |
| 438 | static int ovl_create_object(struct dentry *dentry, int mode, dev_t rdev, |
| 439 | const char *link) |
| 440 | { |
| 441 | int err; |
| 442 | |
| 443 | err = ovl_want_write(dentry); |
| 444 | if (!err) { |
| 445 | err = ovl_create_or_link(dentry, mode, rdev, link, NULL); |
| 446 | ovl_drop_write(dentry); |
| 447 | } |
| 448 | |
| 449 | return err; |
| 450 | } |
| 451 | |
| 452 | static int ovl_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 453 | bool excl) |
| 454 | { |
| 455 | return ovl_create_object(dentry, (mode & 07777) | S_IFREG, 0, NULL); |
| 456 | } |
| 457 | |
| 458 | static int ovl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
| 459 | { |
| 460 | return ovl_create_object(dentry, (mode & 07777) | S_IFDIR, 0, NULL); |
| 461 | } |
| 462 | |
| 463 | static int ovl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
| 464 | dev_t rdev) |
| 465 | { |
| 466 | /* Don't allow creation of "whiteout" on overlay */ |
| 467 | if (S_ISCHR(mode) && rdev == WHITEOUT_DEV) |
| 468 | return -EPERM; |
| 469 | |
| 470 | return ovl_create_object(dentry, mode, rdev, NULL); |
| 471 | } |
| 472 | |
| 473 | static int ovl_symlink(struct inode *dir, struct dentry *dentry, |
| 474 | const char *link) |
| 475 | { |
| 476 | return ovl_create_object(dentry, S_IFLNK, 0, link); |
| 477 | } |
| 478 | |
| 479 | static int ovl_link(struct dentry *old, struct inode *newdir, |
| 480 | struct dentry *new) |
| 481 | { |
| 482 | int err; |
| 483 | struct dentry *upper; |
| 484 | |
| 485 | err = ovl_want_write(old); |
| 486 | if (err) |
| 487 | goto out; |
| 488 | |
| 489 | err = ovl_copy_up(old); |
| 490 | if (err) |
| 491 | goto out_drop_write; |
| 492 | |
| 493 | upper = ovl_dentry_upper(old); |
| 494 | err = ovl_create_or_link(new, upper->d_inode->i_mode, 0, NULL, upper); |
| 495 | |
| 496 | out_drop_write: |
| 497 | ovl_drop_write(old); |
| 498 | out: |
| 499 | return err; |
| 500 | } |
| 501 | |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 502 | static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 503 | { |
| 504 | struct dentry *workdir = ovl_workdir(dentry); |
| 505 | struct inode *wdir = workdir->d_inode; |
| 506 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 507 | struct inode *udir = upperdir->d_inode; |
| 508 | struct dentry *whiteout; |
| 509 | struct dentry *upper; |
| 510 | struct dentry *opaquedir = NULL; |
| 511 | int err; |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 512 | int flags = 0; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 513 | |
Miklos Szeredi | cc6f67b | 2015-05-19 14:30:12 +0200 | [diff] [blame] | 514 | if (WARN_ON(!workdir)) |
| 515 | return -EROFS; |
| 516 | |
Miklos Szeredi | d377c5e | 2015-05-14 10:04:44 +0200 | [diff] [blame] | 517 | if (is_dir) { |
| 518 | if (OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) { |
| 519 | opaquedir = ovl_check_empty_and_clear(dentry); |
| 520 | err = PTR_ERR(opaquedir); |
| 521 | if (IS_ERR(opaquedir)) |
| 522 | goto out; |
| 523 | } else { |
| 524 | LIST_HEAD(list); |
| 525 | |
| 526 | /* |
| 527 | * When removing an empty opaque directory, then it |
| 528 | * makes no sense to replace it with an exact replica of |
| 529 | * itself. But emptiness still needs to be checked. |
| 530 | */ |
| 531 | err = ovl_check_empty_dir(dentry, &list); |
| 532 | ovl_cache_free(&list); |
| 533 | if (err) |
| 534 | goto out; |
| 535 | } |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | err = ovl_lock_rename_workdir(workdir, upperdir); |
| 539 | if (err) |
| 540 | goto out_dput; |
| 541 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 542 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 543 | dentry->d_name.len); |
| 544 | err = PTR_ERR(upper); |
| 545 | if (IS_ERR(upper)) |
| 546 | goto out_unlock; |
| 547 | |
| 548 | err = -ESTALE; |
| 549 | if ((opaquedir && upper != opaquedir) || |
| 550 | (!opaquedir && ovl_dentry_upper(dentry) && |
| 551 | upper != ovl_dentry_upper(dentry))) { |
| 552 | goto out_dput_upper; |
| 553 | } |
| 554 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 555 | whiteout = ovl_whiteout(workdir, dentry); |
| 556 | err = PTR_ERR(whiteout); |
| 557 | if (IS_ERR(whiteout)) |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 558 | goto out_dput_upper; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 559 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 560 | if (d_is_dir(upper)) |
| 561 | flags = RENAME_EXCHANGE; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 562 | |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 563 | err = ovl_do_rename(wdir, whiteout, udir, upper, flags); |
| 564 | if (err) |
| 565 | goto kill_whiteout; |
| 566 | if (flags) |
| 567 | ovl_cleanup(wdir, upper); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 568 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 569 | ovl_dentry_version_inc(dentry->d_parent); |
| 570 | out_d_drop: |
| 571 | d_drop(dentry); |
| 572 | dput(whiteout); |
Maxim Patlasov | cfc9fde | 2016-07-21 18:24:26 -0700 | [diff] [blame] | 573 | out_dput_upper: |
| 574 | dput(upper); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 575 | out_unlock: |
| 576 | unlock_rename(workdir, upperdir); |
| 577 | out_dput: |
| 578 | dput(opaquedir); |
| 579 | out: |
| 580 | return err; |
| 581 | |
| 582 | kill_whiteout: |
| 583 | ovl_cleanup(wdir, whiteout); |
| 584 | goto out_d_drop; |
| 585 | } |
| 586 | |
| 587 | static int ovl_remove_upper(struct dentry *dentry, bool is_dir) |
| 588 | { |
| 589 | struct dentry *upperdir = ovl_dentry_upper(dentry->d_parent); |
| 590 | struct inode *dir = upperdir->d_inode; |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 591 | struct dentry *upper; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 592 | int err; |
| 593 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 594 | inode_lock_nested(dir, I_MUTEX_PARENT); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 595 | upper = lookup_one_len(dentry->d_name.name, upperdir, |
| 596 | dentry->d_name.len); |
| 597 | err = PTR_ERR(upper); |
| 598 | if (IS_ERR(upper)) |
| 599 | goto out_unlock; |
| 600 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 601 | err = -ESTALE; |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 602 | if (upper == ovl_dentry_upper(dentry)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 603 | if (is_dir) |
| 604 | err = vfs_rmdir(dir, upper); |
| 605 | else |
| 606 | err = vfs_unlink(dir, upper, NULL); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 607 | ovl_dentry_version_inc(dentry->d_parent); |
| 608 | } |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 609 | dput(upper); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 610 | |
| 611 | /* |
| 612 | * Keeping this dentry hashed would mean having to release |
| 613 | * upperpath/lowerpath, which could only be done if we are the |
| 614 | * sole user of this dentry. Too tricky... Just unhash for |
| 615 | * now. |
| 616 | */ |
Rui Wang | ce9113b | 2016-01-08 23:09:59 +0800 | [diff] [blame] | 617 | if (!err) |
| 618 | d_drop(dentry); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 619 | out_unlock: |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 620 | inode_unlock(dir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 621 | |
| 622 | return err; |
| 623 | } |
| 624 | |
| 625 | static inline int ovl_check_sticky(struct dentry *dentry) |
| 626 | { |
| 627 | struct inode *dir = ovl_dentry_real(dentry->d_parent)->d_inode; |
| 628 | struct inode *inode = ovl_dentry_real(dentry)->d_inode; |
| 629 | |
| 630 | if (check_sticky(dir, inode)) |
| 631 | return -EPERM; |
| 632 | |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static int ovl_do_remove(struct dentry *dentry, bool is_dir) |
| 637 | { |
| 638 | enum ovl_path_type type; |
| 639 | int err; |
| 640 | |
| 641 | err = ovl_check_sticky(dentry); |
| 642 | if (err) |
| 643 | goto out; |
| 644 | |
| 645 | err = ovl_want_write(dentry); |
| 646 | if (err) |
| 647 | goto out; |
| 648 | |
| 649 | err = ovl_copy_up(dentry->d_parent); |
| 650 | if (err) |
| 651 | goto out_drop_write; |
| 652 | |
| 653 | type = ovl_path_type(dentry); |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 654 | if (OVL_TYPE_PURE_UPPER(type)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 655 | err = ovl_remove_upper(dentry, is_dir); |
| 656 | } else { |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 657 | const struct cred *old_cred = ovl_override_creds(dentry->d_sb); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 658 | |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 659 | err = ovl_remove_and_whiteout(dentry, is_dir); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 660 | |
| 661 | revert_creds(old_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 662 | } |
| 663 | out_drop_write: |
| 664 | ovl_drop_write(dentry); |
| 665 | out: |
| 666 | return err; |
| 667 | } |
| 668 | |
| 669 | static int ovl_unlink(struct inode *dir, struct dentry *dentry) |
| 670 | { |
| 671 | return ovl_do_remove(dentry, false); |
| 672 | } |
| 673 | |
| 674 | static int ovl_rmdir(struct inode *dir, struct dentry *dentry) |
| 675 | { |
| 676 | return ovl_do_remove(dentry, true); |
| 677 | } |
| 678 | |
| 679 | static int ovl_rename2(struct inode *olddir, struct dentry *old, |
| 680 | struct inode *newdir, struct dentry *new, |
| 681 | unsigned int flags) |
| 682 | { |
| 683 | int err; |
| 684 | enum ovl_path_type old_type; |
| 685 | enum ovl_path_type new_type; |
| 686 | struct dentry *old_upperdir; |
| 687 | struct dentry *new_upperdir; |
| 688 | struct dentry *olddentry; |
| 689 | struct dentry *newdentry; |
| 690 | struct dentry *trap; |
| 691 | bool old_opaque; |
| 692 | bool new_opaque; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 693 | bool cleanup_whiteout = false; |
| 694 | bool overwrite = !(flags & RENAME_EXCHANGE); |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 695 | bool is_dir = d_is_dir(old); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 696 | bool new_is_dir = false; |
| 697 | struct dentry *opaquedir = NULL; |
| 698 | const struct cred *old_cred = NULL; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 699 | |
| 700 | err = -EINVAL; |
| 701 | if (flags & ~(RENAME_EXCHANGE | RENAME_NOREPLACE)) |
| 702 | goto out; |
| 703 | |
| 704 | flags &= ~RENAME_NOREPLACE; |
| 705 | |
| 706 | err = ovl_check_sticky(old); |
| 707 | if (err) |
| 708 | goto out; |
| 709 | |
| 710 | /* Don't copy up directory trees */ |
| 711 | old_type = ovl_path_type(old); |
| 712 | err = -EXDEV; |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 713 | if (OVL_TYPE_MERGE_OR_LOWER(old_type) && is_dir) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 714 | goto out; |
| 715 | |
| 716 | if (new->d_inode) { |
| 717 | err = ovl_check_sticky(new); |
| 718 | if (err) |
| 719 | goto out; |
| 720 | |
David Howells | e36cb0b | 2015-01-29 12:02:35 +0000 | [diff] [blame] | 721 | if (d_is_dir(new)) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 722 | new_is_dir = true; |
| 723 | |
| 724 | new_type = ovl_path_type(new); |
| 725 | err = -EXDEV; |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 726 | if (!overwrite && OVL_TYPE_MERGE_OR_LOWER(new_type) && new_is_dir) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 727 | goto out; |
| 728 | |
| 729 | err = 0; |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 730 | if (!OVL_TYPE_UPPER(new_type) && !OVL_TYPE_UPPER(old_type)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 731 | if (ovl_dentry_lower(old)->d_inode == |
| 732 | ovl_dentry_lower(new)->d_inode) |
| 733 | goto out; |
| 734 | } |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 735 | if (OVL_TYPE_UPPER(new_type) && OVL_TYPE_UPPER(old_type)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 736 | if (ovl_dentry_upper(old)->d_inode == |
| 737 | ovl_dentry_upper(new)->d_inode) |
| 738 | goto out; |
| 739 | } |
| 740 | } else { |
| 741 | if (ovl_dentry_is_opaque(new)) |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 742 | new_type = __OVL_PATH_UPPER; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 743 | else |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 744 | new_type = __OVL_PATH_UPPER | __OVL_PATH_PURE; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | err = ovl_want_write(old); |
| 748 | if (err) |
| 749 | goto out; |
| 750 | |
| 751 | err = ovl_copy_up(old); |
| 752 | if (err) |
| 753 | goto out_drop_write; |
| 754 | |
| 755 | err = ovl_copy_up(new->d_parent); |
| 756 | if (err) |
| 757 | goto out_drop_write; |
| 758 | if (!overwrite) { |
| 759 | err = ovl_copy_up(new); |
| 760 | if (err) |
| 761 | goto out_drop_write; |
| 762 | } |
| 763 | |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 764 | old_opaque = !OVL_TYPE_PURE_UPPER(old_type); |
| 765 | new_opaque = !OVL_TYPE_PURE_UPPER(new_type); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 766 | |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 767 | if (old_opaque || new_opaque) |
| 768 | old_cred = ovl_override_creds(old->d_sb); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 769 | |
Miklos Szeredi | 1afaba1 | 2014-12-13 00:59:42 +0100 | [diff] [blame] | 770 | if (overwrite && OVL_TYPE_MERGE_OR_LOWER(new_type) && new_is_dir) { |
Miklos Szeredi | a105d68 | 2014-11-20 16:39:59 +0100 | [diff] [blame] | 771 | opaquedir = ovl_check_empty_and_clear(new); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 772 | err = PTR_ERR(opaquedir); |
| 773 | if (IS_ERR(opaquedir)) { |
| 774 | opaquedir = NULL; |
| 775 | goto out_revert_creds; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | if (overwrite) { |
| 780 | if (old_opaque) { |
| 781 | if (new->d_inode || !new_opaque) { |
| 782 | /* Whiteout source */ |
| 783 | flags |= RENAME_WHITEOUT; |
| 784 | } else { |
| 785 | /* Switch whiteouts */ |
| 786 | flags |= RENAME_EXCHANGE; |
| 787 | } |
| 788 | } else if (is_dir && !new->d_inode && new_opaque) { |
| 789 | flags |= RENAME_EXCHANGE; |
| 790 | cleanup_whiteout = true; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | old_upperdir = ovl_dentry_upper(old->d_parent); |
| 795 | new_upperdir = ovl_dentry_upper(new->d_parent); |
| 796 | |
| 797 | trap = lock_rename(new_upperdir, old_upperdir); |
| 798 | |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 799 | |
| 800 | olddentry = lookup_one_len(old->d_name.name, old_upperdir, |
| 801 | old->d_name.len); |
| 802 | err = PTR_ERR(olddentry); |
| 803 | if (IS_ERR(olddentry)) |
| 804 | goto out_unlock; |
| 805 | |
| 806 | err = -ESTALE; |
| 807 | if (olddentry != ovl_dentry_upper(old)) |
| 808 | goto out_dput_old; |
| 809 | |
| 810 | newdentry = lookup_one_len(new->d_name.name, new_upperdir, |
| 811 | new->d_name.len); |
| 812 | err = PTR_ERR(newdentry); |
| 813 | if (IS_ERR(newdentry)) |
| 814 | goto out_dput_old; |
| 815 | |
| 816 | err = -ESTALE; |
| 817 | if (ovl_dentry_upper(new)) { |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 818 | if (opaquedir) { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 819 | if (newdentry != opaquedir) |
| 820 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 821 | } else { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 822 | if (newdentry != ovl_dentry_upper(new)) |
| 823 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 824 | } |
| 825 | } else { |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 826 | if (!d_is_negative(newdentry) && |
| 827 | (!new_opaque || !ovl_is_whiteout(newdentry))) |
| 828 | goto out_dput; |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 829 | } |
| 830 | |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 831 | if (olddentry == trap) |
| 832 | goto out_dput; |
| 833 | if (newdentry == trap) |
| 834 | goto out_dput; |
| 835 | |
| 836 | if (is_dir && !old_opaque && new_opaque) { |
| 837 | err = ovl_set_opaque(olddentry); |
| 838 | if (err) |
| 839 | goto out_dput; |
| 840 | } |
| 841 | if (!overwrite && new_is_dir && old_opaque && !new_opaque) { |
| 842 | err = ovl_set_opaque(newdentry); |
| 843 | if (err) |
| 844 | goto out_dput; |
| 845 | } |
| 846 | |
| 847 | if (old_opaque || new_opaque) { |
| 848 | err = ovl_do_rename(old_upperdir->d_inode, olddentry, |
| 849 | new_upperdir->d_inode, newdentry, |
| 850 | flags); |
| 851 | } else { |
| 852 | /* No debug for the plain case */ |
| 853 | BUG_ON(flags & ~RENAME_EXCHANGE); |
| 854 | err = vfs_rename(old_upperdir->d_inode, olddentry, |
| 855 | new_upperdir->d_inode, newdentry, |
| 856 | NULL, flags); |
| 857 | } |
| 858 | |
| 859 | if (err) { |
| 860 | if (is_dir && !old_opaque && new_opaque) |
| 861 | ovl_remove_opaque(olddentry); |
| 862 | if (!overwrite && new_is_dir && old_opaque && !new_opaque) |
| 863 | ovl_remove_opaque(newdentry); |
| 864 | goto out_dput; |
| 865 | } |
| 866 | |
| 867 | if (is_dir && old_opaque && !new_opaque) |
| 868 | ovl_remove_opaque(olddentry); |
| 869 | if (!overwrite && new_is_dir && !old_opaque && new_opaque) |
| 870 | ovl_remove_opaque(newdentry); |
| 871 | |
Konstantin Khlebnikov | 45d1173 | 2016-01-31 16:17:53 +0300 | [diff] [blame] | 872 | /* |
| 873 | * Old dentry now lives in different location. Dentries in |
| 874 | * lowerstack are stale. We cannot drop them here because |
| 875 | * access to them is lockless. This could be only pure upper |
| 876 | * or opaque directory - numlower is zero. Or upper non-dir |
| 877 | * entry - its pureness is tracked by flag opaque. |
| 878 | */ |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 879 | if (old_opaque != new_opaque) { |
| 880 | ovl_dentry_set_opaque(old, new_opaque); |
| 881 | if (!overwrite) |
| 882 | ovl_dentry_set_opaque(new, old_opaque); |
| 883 | } |
| 884 | |
| 885 | if (cleanup_whiteout) |
| 886 | ovl_cleanup(old_upperdir->d_inode, newdentry); |
| 887 | |
| 888 | ovl_dentry_version_inc(old->d_parent); |
| 889 | ovl_dentry_version_inc(new->d_parent); |
| 890 | |
| 891 | out_dput: |
| 892 | dput(newdentry); |
Miklos Szeredi | 11f3710 | 2016-03-21 17:31:44 +0100 | [diff] [blame] | 893 | out_dput_old: |
| 894 | dput(olddentry); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 895 | out_unlock: |
| 896 | unlock_rename(new_upperdir, old_upperdir); |
| 897 | out_revert_creds: |
Antonio Murdaca | 3fe6e52 | 2016-04-07 15:48:25 +0200 | [diff] [blame] | 898 | if (old_opaque || new_opaque) |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 899 | revert_creds(old_cred); |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 900 | out_drop_write: |
| 901 | ovl_drop_write(old); |
| 902 | out: |
| 903 | dput(opaquedir); |
| 904 | return err; |
| 905 | } |
| 906 | |
| 907 | const struct inode_operations ovl_dir_inode_operations = { |
| 908 | .lookup = ovl_lookup, |
| 909 | .mkdir = ovl_mkdir, |
| 910 | .symlink = ovl_symlink, |
| 911 | .unlink = ovl_unlink, |
| 912 | .rmdir = ovl_rmdir, |
| 913 | .rename2 = ovl_rename2, |
| 914 | .link = ovl_link, |
| 915 | .setattr = ovl_setattr, |
| 916 | .create = ovl_create, |
| 917 | .mknod = ovl_mknod, |
| 918 | .permission = ovl_permission, |
| 919 | .getattr = ovl_dir_getattr, |
| 920 | .setxattr = ovl_setxattr, |
| 921 | .getxattr = ovl_getxattr, |
| 922 | .listxattr = ovl_listxattr, |
| 923 | .removexattr = ovl_removexattr, |
Vivek Goyal | 39a25b2 | 2016-07-01 16:34:26 -0400 | [diff] [blame^] | 924 | .get_acl = ovl_get_acl, |
Miklos Szeredi | e9be9d5 | 2014-10-24 00:14:38 +0200 | [diff] [blame] | 925 | }; |