2016-12-16 18:02:56 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Novell Inc.
|
|
|
|
* Copyright (C) 2016 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/mount.h>
|
|
|
|
#include <linux/slab.h>
|
2017-02-03 00:54:15 +08:00
|
|
|
#include <linux/cred.h>
|
2016-12-16 18:02:56 +08:00
|
|
|
#include <linux/xattr.h>
|
2017-06-21 20:28:36 +08:00
|
|
|
#include <linux/exportfs.h>
|
|
|
|
#include <linux/uuid.h>
|
2017-06-21 18:46:12 +08:00
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/ratelimit.h>
|
2016-12-16 18:02:56 +08:00
|
|
|
#include "overlayfs.h"
|
|
|
|
|
|
|
|
int ovl_want_write(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
return mnt_want_write(ofs->upper_mnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_drop_write(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
mnt_drop_write(ofs->upper_mnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *ovl_workdir(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
return ofs->workdir;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct cred *ovl_override_creds(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
|
|
|
return override_creds(ofs->creator_cred);
|
|
|
|
}
|
|
|
|
|
2017-03-22 20:42:21 +08:00
|
|
|
struct super_block *ovl_same_sb(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
2018-03-29 01:22:41 +08:00
|
|
|
if (!ofs->numlowerfs)
|
|
|
|
return ofs->upper_mnt->mnt_sb;
|
|
|
|
else if (ofs->numlowerfs == 1 && !ofs->upper_mnt)
|
|
|
|
return ofs->lower_fs[0].sb;
|
|
|
|
else
|
|
|
|
return NULL;
|
2017-03-22 20:42:21 +08:00
|
|
|
}
|
|
|
|
|
2017-11-07 19:55:04 +08:00
|
|
|
/*
|
|
|
|
* Check if underlying fs supports file handles and try to determine encoding
|
|
|
|
* type, in order to deduce maximum inode number used by fs.
|
|
|
|
*
|
|
|
|
* Return 0 if file handles are not supported.
|
|
|
|
* Return 1 (FILEID_INO32_GEN) if fs uses the default 32bit inode encoding.
|
|
|
|
* Return -1 if fs uses a non default encoding with unknown inode size.
|
|
|
|
*/
|
|
|
|
int ovl_can_decode_fh(struct super_block *sb)
|
2017-06-21 20:28:36 +08:00
|
|
|
{
|
2017-11-07 19:55:04 +08:00
|
|
|
if (!sb->s_export_op || !sb->s_export_op->fh_to_dentry ||
|
|
|
|
uuid_is_null(&sb->s_uuid))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return sb->s_export_op->encode_fh ? -1 : FILEID_INO32_GEN;
|
2017-06-21 20:28:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *ovl_indexdir(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
|
|
|
return ofs->indexdir;
|
|
|
|
}
|
|
|
|
|
2018-01-19 17:26:53 +08:00
|
|
|
/* Index all files on copy up. For now only enabled for NFS export */
|
|
|
|
bool ovl_index_all(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
|
|
|
return ofs->config.nfs_export && ofs->config.index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify lower origin on lookup. For now only enabled for NFS export */
|
|
|
|
bool ovl_verify_lower(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
|
|
|
return ofs->config.nfs_export && ofs->config.index;
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:02:56 +08:00
|
|
|
struct ovl_entry *ovl_alloc_entry(unsigned int numlower)
|
|
|
|
{
|
|
|
|
size_t size = offsetof(struct ovl_entry, lowerstack[numlower]);
|
|
|
|
struct ovl_entry *oe = kzalloc(size, GFP_KERNEL);
|
|
|
|
|
|
|
|
if (oe)
|
|
|
|
oe->numlower = numlower;
|
|
|
|
|
|
|
|
return oe;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ovl_dentry_remote(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return dentry->d_flags &
|
|
|
|
(DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE |
|
|
|
|
DCACHE_OP_REAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ovl_dentry_weird(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return dentry->d_flags & (DCACHE_NEED_AUTOMOUNT |
|
|
|
|
DCACHE_MANAGE_TRANSIT |
|
|
|
|
DCACHE_OP_HASH |
|
|
|
|
DCACHE_OP_COMPARE);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum ovl_path_type ovl_path_type(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_entry *oe = dentry->d_fsdata;
|
|
|
|
enum ovl_path_type type = 0;
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
if (ovl_dentry_upper(dentry)) {
|
2016-12-16 18:02:56 +08:00
|
|
|
type = __OVL_PATH_UPPER;
|
|
|
|
|
|
|
|
/*
|
2017-04-24 04:12:34 +08:00
|
|
|
* Non-dir dentry can hold lower dentry of its copy up origin.
|
2016-12-16 18:02:56 +08:00
|
|
|
*/
|
2017-04-24 04:12:34 +08:00
|
|
|
if (oe->numlower) {
|
|
|
|
type |= __OVL_PATH_ORIGIN;
|
|
|
|
if (d_is_dir(dentry))
|
|
|
|
type |= __OVL_PATH_MERGE;
|
|
|
|
}
|
2016-12-16 18:02:56 +08:00
|
|
|
} else {
|
|
|
|
if (oe->numlower > 1)
|
|
|
|
type |= __OVL_PATH_MERGE;
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_path_upper(struct dentry *dentry, struct path *path)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
|
|
|
|
path->mnt = ofs->upper_mnt;
|
2017-07-05 04:03:16 +08:00
|
|
|
path->dentry = ovl_dentry_upper(dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_path_lower(struct dentry *dentry, struct path *path)
|
|
|
|
{
|
|
|
|
struct ovl_entry *oe = dentry->d_fsdata;
|
|
|
|
|
2017-07-24 14:57:54 +08:00
|
|
|
if (oe->numlower) {
|
|
|
|
path->mnt = oe->lowerstack[0].layer->mnt;
|
|
|
|
path->dentry = oe->lowerstack[0].dentry;
|
|
|
|
} else {
|
|
|
|
*path = (struct path) { };
|
|
|
|
}
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
enum ovl_path_type ovl_path_real(struct dentry *dentry, struct path *path)
|
|
|
|
{
|
|
|
|
enum ovl_path_type type = ovl_path_type(dentry);
|
|
|
|
|
|
|
|
if (!OVL_TYPE_UPPER(type))
|
|
|
|
ovl_path_lower(dentry, path);
|
|
|
|
else
|
|
|
|
ovl_path_upper(dentry, path);
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *ovl_dentry_upper(struct dentry *dentry)
|
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
return ovl_upperdentry_dereference(OVL_I(d_inode(dentry)));
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *ovl_dentry_lower(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_entry *oe = dentry->d_fsdata;
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
return oe->numlower ? oe->lowerstack[0].dentry : NULL;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-11-09 01:39:51 +08:00
|
|
|
struct ovl_layer *ovl_layer_lower(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct ovl_entry *oe = dentry->d_fsdata;
|
|
|
|
|
|
|
|
return oe->numlower ? oe->lowerstack[0].layer : NULL;
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:02:56 +08:00
|
|
|
struct dentry *ovl_dentry_real(struct dentry *dentry)
|
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
return ovl_dentry_upper(dentry) ?: ovl_dentry_lower(dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-20 17:08:21 +08:00
|
|
|
struct dentry *ovl_i_dentry_upper(struct inode *inode)
|
|
|
|
{
|
|
|
|
return ovl_upperdentry_dereference(OVL_I(inode));
|
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *ovl_inode_upper(struct inode *inode)
|
2017-07-05 04:03:16 +08:00
|
|
|
{
|
2017-07-20 17:08:21 +08:00
|
|
|
struct dentry *upperdentry = ovl_i_dentry_upper(inode);
|
2017-07-05 04:03:16 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
return upperdentry ? d_inode(upperdentry) : NULL;
|
|
|
|
}
|
2017-07-05 04:03:16 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *ovl_inode_lower(struct inode *inode)
|
|
|
|
{
|
|
|
|
return OVL_I(inode)->lower;
|
|
|
|
}
|
2017-07-05 04:03:16 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *ovl_inode_real(struct inode *inode)
|
|
|
|
{
|
|
|
|
return ovl_inode_upper(inode) ?: ovl_inode_lower(inode);
|
2017-07-05 04:03:16 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
|
2017-07-28 03:54:06 +08:00
|
|
|
struct ovl_dir_cache *ovl_dir_cache(struct inode *inode)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2017-07-28 03:54:06 +08:00
|
|
|
return OVL_I(inode)->cache;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-28 03:54:06 +08:00
|
|
|
void ovl_set_dir_cache(struct inode *inode, struct ovl_dir_cache *cache)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2017-07-28 03:54:06 +08:00
|
|
|
OVL_I(inode)->cache = cache;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2018-01-15 01:25:31 +08:00
|
|
|
void ovl_dentry_set_flag(unsigned long flag, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
set_bit(flag, &OVL_E(dentry)->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_dentry_clear_flag(unsigned long flag, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
clear_bit(flag, &OVL_E(dentry)->flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ovl_dentry_test_flag(unsigned long flag, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return test_bit(flag, &OVL_E(dentry)->flags);
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:02:56 +08:00
|
|
|
bool ovl_dentry_is_opaque(struct dentry *dentry)
|
|
|
|
{
|
2018-01-15 01:25:31 +08:00
|
|
|
return ovl_dentry_test_flag(OVL_E_OPAQUE, dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ovl_dentry_is_whiteout(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return !dentry->d_inode && ovl_dentry_is_opaque(dentry);
|
|
|
|
}
|
|
|
|
|
2016-12-16 18:02:57 +08:00
|
|
|
void ovl_dentry_set_opaque(struct dentry *dentry)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2018-01-15 01:25:31 +08:00
|
|
|
ovl_dentry_set_flag(OVL_E_OPAQUE, dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:18 +08:00
|
|
|
/*
|
2017-10-15 23:00:20 +08:00
|
|
|
* For hard links and decoded file handles, it's possible for ovl_dentry_upper()
|
|
|
|
* to return positive, while there's no actual upper alias for the inode.
|
|
|
|
* Copy up code needs to know about the existence of the upper alias, so it
|
|
|
|
* can't use ovl_dentry_upper().
|
2017-07-05 04:03:18 +08:00
|
|
|
*/
|
|
|
|
bool ovl_dentry_has_upper_alias(struct dentry *dentry)
|
|
|
|
{
|
2018-01-15 01:25:31 +08:00
|
|
|
return ovl_dentry_test_flag(OVL_E_UPPER_ALIAS, dentry);
|
2017-07-05 04:03:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_dentry_set_upper_alias(struct dentry *dentry)
|
|
|
|
{
|
2018-01-15 01:25:31 +08:00
|
|
|
ovl_dentry_set_flag(OVL_E_UPPER_ALIAS, dentry);
|
2017-07-05 04:03:18 +08:00
|
|
|
}
|
|
|
|
|
2016-12-16 18:02:56 +08:00
|
|
|
bool ovl_redirect_dir(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct ovl_fs *ofs = sb->s_fs_info;
|
|
|
|
|
2017-05-17 05:12:41 +08:00
|
|
|
return ofs->config.redirect_dir && !ofs->noxattr;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *ovl_dentry_get_redirect(struct dentry *dentry)
|
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
return OVL_I(d_inode(dentry))->redirect;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect)
|
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
struct ovl_inode *oi = OVL_I(d_inode(dentry));
|
2016-12-16 18:02:56 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
kfree(oi->redirect);
|
|
|
|
oi->redirect = redirect;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
|
|
|
|
struct dentry *lowerdentry)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2018-03-16 05:39:01 +08:00
|
|
|
struct inode *realinode = d_inode(upperdentry ?: lowerdentry);
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
if (upperdentry)
|
|
|
|
OVL_I(inode)->__upperdentry = upperdentry;
|
|
|
|
if (lowerdentry)
|
2018-01-15 00:35:40 +08:00
|
|
|
OVL_I(inode)->lower = igrab(d_inode(lowerdentry));
|
2016-12-16 18:02:56 +08:00
|
|
|
|
2018-03-16 05:39:01 +08:00
|
|
|
ovl_copyattr(realinode, inode);
|
|
|
|
if (!inode->i_ino)
|
|
|
|
inode->i_ino = realinode->i_ino;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
void ovl_inode_update(struct inode *inode, struct dentry *upperdentry)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *upperinode = d_inode(upperdentry);
|
2017-07-05 04:03:16 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
WARN_ON(OVL_I(inode)->__upperdentry);
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
/*
|
2017-07-05 04:03:16 +08:00
|
|
|
* Make sure upperdentry is consistent before making it visible
|
2017-07-05 04:03:16 +08:00
|
|
|
*/
|
|
|
|
smp_wmb();
|
2017-07-05 04:03:16 +08:00
|
|
|
OVL_I(inode)->__upperdentry = upperdentry;
|
2018-01-15 00:35:40 +08:00
|
|
|
if (inode_unhashed(inode)) {
|
2018-03-16 05:39:01 +08:00
|
|
|
if (!inode->i_ino)
|
|
|
|
inode->i_ino = upperinode->i_ino;
|
2017-07-05 04:03:16 +08:00
|
|
|
inode->i_private = upperinode;
|
2016-12-16 18:02:56 +08:00
|
|
|
__insert_inode_hash(inode, (unsigned long) upperinode);
|
2017-07-05 04:03:16 +08:00
|
|
|
}
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-28 03:54:06 +08:00
|
|
|
void ovl_dentry_version_inc(struct dentry *dentry, bool impurity)
|
2016-12-16 18:02:56 +08:00
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
WARN_ON(!inode_is_locked(inode));
|
2017-07-28 03:54:06 +08:00
|
|
|
/*
|
|
|
|
* Version is used by readdir code to keep cache consistent. For merge
|
|
|
|
* dirs all changes need to be noted. For non-merge dirs, cache only
|
|
|
|
* contains impure (ones which have been copied up and have origins)
|
|
|
|
* entries, so only need to note changes to impure entries.
|
|
|
|
*/
|
|
|
|
if (OVL_TYPE_MERGE(ovl_path_type(dentry)) || impurity)
|
|
|
|
OVL_I(inode)->version++;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 ovl_dentry_version_get(struct dentry *dentry)
|
|
|
|
{
|
2017-07-05 04:03:16 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2016-12-16 18:02:56 +08:00
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
WARN_ON(!inode_is_locked(inode));
|
|
|
|
return OVL_I(inode)->version;
|
2016-12-16 18:02:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ovl_is_whiteout(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct inode *inode = dentry->d_inode;
|
|
|
|
|
|
|
|
return inode && IS_WHITEOUT(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct file *ovl_path_open(struct path *path, int flags)
|
|
|
|
{
|
|
|
|
return dentry_open(path, flags | O_NOATIME, current_cred());
|
|
|
|
}
|
2017-01-17 12:34:56 +08:00
|
|
|
|
|
|
|
int ovl_copy_up_start(struct dentry *dentry)
|
|
|
|
{
|
2017-06-21 20:28:51 +08:00
|
|
|
struct ovl_inode *oi = OVL_I(d_inode(dentry));
|
2017-01-17 12:34:56 +08:00
|
|
|
int err;
|
|
|
|
|
2017-06-21 20:28:51 +08:00
|
|
|
err = mutex_lock_interruptible(&oi->lock);
|
2017-06-20 20:25:46 +08:00
|
|
|
if (!err && ovl_dentry_has_upper_alias(dentry)) {
|
2017-06-21 20:28:51 +08:00
|
|
|
err = 1; /* Already copied up */
|
|
|
|
mutex_unlock(&oi->lock);
|
2017-01-17 12:34:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_copy_up_end(struct dentry *dentry)
|
|
|
|
{
|
2017-06-21 20:28:51 +08:00
|
|
|
mutex_unlock(&OVL_I(d_inode(dentry))->lock);
|
2017-01-17 12:34:56 +08:00
|
|
|
}
|
2017-05-17 05:12:40 +08:00
|
|
|
|
2017-06-25 21:37:17 +08:00
|
|
|
bool ovl_check_origin_xattr(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
|
|
|
res = vfs_getxattr(dentry, OVL_XATTR_ORIGIN, NULL, 0);
|
|
|
|
|
|
|
|
/* Zero size value means "copied up but origin unknown" */
|
|
|
|
if (res >= 0)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-24 20:29:33 +08:00
|
|
|
bool ovl_check_dir_xattr(struct dentry *dentry, const char *name)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
char val;
|
|
|
|
|
|
|
|
if (!d_is_dir(dentry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
res = vfs_getxattr(dentry, name, &val, 1);
|
|
|
|
if (res == 1 && val == 'y')
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 05:12:40 +08:00
|
|
|
int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
|
|
|
|
const char *name, const void *value, size_t size,
|
|
|
|
int xerr)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
struct ovl_fs *ofs = dentry->d_sb->s_fs_info;
|
|
|
|
|
|
|
|
if (ofs->noxattr)
|
|
|
|
return xerr;
|
|
|
|
|
|
|
|
err = ovl_do_setxattr(upperdentry, name, value, size, 0);
|
|
|
|
|
|
|
|
if (err == -EOPNOTSUPP) {
|
|
|
|
pr_warn("overlayfs: cannot set %s xattr on upper\n", name);
|
|
|
|
ofs->noxattr = true;
|
|
|
|
return xerr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2017-05-24 20:29:33 +08:00
|
|
|
|
|
|
|
int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry)
|
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
if (ovl_test_flag(OVL_IMPURE, d_inode(dentry)))
|
2017-05-24 20:29:33 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not fail when upper doesn't support xattrs.
|
|
|
|
* Upper inodes won't have origin nor redirect xattr anyway.
|
|
|
|
*/
|
|
|
|
err = ovl_check_setxattr(dentry, upperdentry, OVL_XATTR_IMPURE,
|
|
|
|
"y", 1, 0);
|
|
|
|
if (!err)
|
2017-07-05 04:03:16 +08:00
|
|
|
ovl_set_flag(OVL_IMPURE, d_inode(dentry));
|
2017-05-24 20:29:33 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2017-07-05 04:03:16 +08:00
|
|
|
|
|
|
|
void ovl_set_flag(unsigned long flag, struct inode *inode)
|
|
|
|
{
|
|
|
|
set_bit(flag, &OVL_I(inode)->flags);
|
|
|
|
}
|
|
|
|
|
2017-07-28 03:54:06 +08:00
|
|
|
void ovl_clear_flag(unsigned long flag, struct inode *inode)
|
|
|
|
{
|
|
|
|
clear_bit(flag, &OVL_I(inode)->flags);
|
|
|
|
}
|
|
|
|
|
2017-07-05 04:03:16 +08:00
|
|
|
bool ovl_test_flag(unsigned long flag, struct inode *inode)
|
|
|
|
{
|
|
|
|
return test_bit(flag, &OVL_I(inode)->flags);
|
|
|
|
}
|
2017-06-21 20:28:32 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must hold a reference to inode to prevent it from being freed while
|
|
|
|
* it is marked inuse.
|
|
|
|
*/
|
|
|
|
bool ovl_inuse_trylock(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct inode *inode = d_inode(dentry);
|
|
|
|
bool locked = false;
|
|
|
|
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
if (!(inode->i_state & I_OVL_INUSE)) {
|
|
|
|
inode->i_state |= I_OVL_INUSE;
|
|
|
|
locked = true;
|
|
|
|
}
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
|
|
|
|
return locked;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_inuse_unlock(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
if (dentry) {
|
|
|
|
struct inode *inode = d_inode(dentry);
|
|
|
|
|
|
|
|
spin_lock(&inode->i_lock);
|
|
|
|
WARN_ON(!(inode->i_state & I_OVL_INUSE));
|
|
|
|
inode->i_state &= ~I_OVL_INUSE;
|
|
|
|
spin_unlock(&inode->i_lock);
|
|
|
|
}
|
|
|
|
}
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
|
2017-09-26 12:55:26 +08:00
|
|
|
/*
|
|
|
|
* Does this overlay dentry need to be indexed on copy up?
|
|
|
|
*/
|
|
|
|
bool ovl_need_index(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct dentry *lower = ovl_dentry_lower(dentry);
|
|
|
|
|
|
|
|
if (!lower || !ovl_indexdir(dentry->d_sb))
|
|
|
|
return false;
|
|
|
|
|
2017-11-22 06:08:21 +08:00
|
|
|
/* Index all files for NFS export and consistency verification */
|
2018-01-11 20:01:08 +08:00
|
|
|
if (ovl_index_all(dentry->d_sb))
|
2017-11-22 06:08:21 +08:00
|
|
|
return true;
|
|
|
|
|
2017-09-26 12:55:26 +08:00
|
|
|
/* Index only lower hardlinks on copy up */
|
|
|
|
if (!d_is_dir(lower) && d_inode(lower)->i_nlink > 1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-09-24 22:36:26 +08:00
|
|
|
/* Caller must hold OVL_I(inode)->lock */
|
2017-06-21 18:46:12 +08:00
|
|
|
static void ovl_cleanup_index(struct dentry *dentry)
|
|
|
|
{
|
2017-10-24 22:38:33 +08:00
|
|
|
struct dentry *indexdir = ovl_indexdir(dentry->d_sb);
|
|
|
|
struct inode *dir = indexdir->d_inode;
|
2017-06-21 18:46:12 +08:00
|
|
|
struct dentry *lowerdentry = ovl_dentry_lower(dentry);
|
|
|
|
struct dentry *upperdentry = ovl_dentry_upper(dentry);
|
|
|
|
struct dentry *index = NULL;
|
|
|
|
struct inode *inode;
|
|
|
|
struct qstr name;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = ovl_get_index_name(lowerdentry, &name);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
inode = d_inode(upperdentry);
|
2017-09-26 12:40:37 +08:00
|
|
|
if (!S_ISDIR(inode->i_mode) && inode->i_nlink != 1) {
|
2017-06-21 18:46:12 +08:00
|
|
|
pr_warn_ratelimited("overlayfs: cleanup linked index (%pd2, ino=%lu, nlink=%u)\n",
|
|
|
|
upperdentry, inode->i_ino, inode->i_nlink);
|
|
|
|
/*
|
|
|
|
* We either have a bug with persistent union nlink or a lower
|
|
|
|
* hardlink was added while overlay is mounted. Adding a lower
|
|
|
|
* hardlink and then unlinking all overlay hardlinks would drop
|
|
|
|
* overlay nlink to zero before all upper inodes are unlinked.
|
|
|
|
* As a safety measure, when that situation is detected, set
|
|
|
|
* the overlay nlink to the index inode nlink minus one for the
|
|
|
|
* index entry itself.
|
|
|
|
*/
|
|
|
|
set_nlink(d_inode(dentry), inode->i_nlink - 1);
|
|
|
|
ovl_set_nlink_upper(dentry);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode_lock_nested(dir, I_MUTEX_PARENT);
|
2017-10-24 22:38:33 +08:00
|
|
|
index = lookup_one_len(name.name, indexdir, name.len);
|
2017-06-21 18:46:12 +08:00
|
|
|
err = PTR_ERR(index);
|
2017-10-24 22:38:33 +08:00
|
|
|
if (IS_ERR(index)) {
|
2017-09-24 22:36:26 +08:00
|
|
|
index = NULL;
|
2017-10-24 22:38:33 +08:00
|
|
|
} else if (ovl_index_all(dentry->d_sb)) {
|
|
|
|
/* Whiteout orphan index to block future open by handle */
|
|
|
|
err = ovl_cleanup_and_whiteout(indexdir, dir, index);
|
|
|
|
} else {
|
|
|
|
/* Cleanup orphan index entries */
|
|
|
|
err = ovl_cleanup(dir, index);
|
|
|
|
}
|
2017-09-24 22:36:26 +08:00
|
|
|
|
2017-06-21 18:46:12 +08:00
|
|
|
inode_unlock(dir);
|
|
|
|
if (err)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
out:
|
|
|
|
dput(index);
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
pr_err("overlayfs: cleanup index of '%pd2' failed (%i)\n", dentry, err);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
/*
|
|
|
|
* Operations that change overlay inode and upper inode nlink need to be
|
|
|
|
* synchronized with copy up for persistent nlink accounting.
|
|
|
|
*/
|
|
|
|
int ovl_nlink_start(struct dentry *dentry, bool *locked)
|
|
|
|
{
|
|
|
|
struct ovl_inode *oi = OVL_I(d_inode(dentry));
|
|
|
|
const struct cred *old_cred;
|
|
|
|
int err;
|
|
|
|
|
2017-09-26 12:40:37 +08:00
|
|
|
if (!d_inode(dentry))
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* With inodes index is enabled, we store the union overlay nlink
|
2017-09-26 12:55:26 +08:00
|
|
|
* in an xattr on the index inode. When whiting out an indexed lower,
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
* we need to decrement the overlay persistent nlink, but before the
|
|
|
|
* first copy up, we have no upper index inode to store the xattr.
|
|
|
|
*
|
2017-09-26 12:55:26 +08:00
|
|
|
* As a workaround, before whiteout/rename over an indexed lower,
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
* copy up to create the upper index. Creating the upper index will
|
|
|
|
* initialize the overlay nlink, so it could be dropped if unlink
|
|
|
|
* or rename succeeds.
|
|
|
|
*
|
|
|
|
* TODO: implement metadata only index copy up when called with
|
|
|
|
* ovl_copy_up_flags(dentry, O_PATH).
|
|
|
|
*/
|
2017-09-26 12:55:26 +08:00
|
|
|
if (ovl_need_index(dentry) && !ovl_dentry_has_upper_alias(dentry)) {
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
err = ovl_copy_up(dentry);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mutex_lock_interruptible(&oi->lock);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2017-09-26 12:40:37 +08:00
|
|
|
if (d_is_dir(dentry) || !ovl_test_flag(OVL_INDEX, d_inode(dentry)))
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
old_cred = ovl_override_creds(dentry->d_sb);
|
|
|
|
/*
|
|
|
|
* The overlay inode nlink should be incremented/decremented IFF the
|
|
|
|
* upper operation succeeds, along with nlink change of upper inode.
|
|
|
|
* Therefore, before link/unlink/rename, we store the union nlink
|
|
|
|
* value relative to the upper inode nlink in an upper inode xattr.
|
|
|
|
*/
|
|
|
|
err = ovl_set_nlink_upper(dentry);
|
|
|
|
revert_creds(old_cred);
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (err)
|
|
|
|
mutex_unlock(&oi->lock);
|
|
|
|
else
|
|
|
|
*locked = true;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ovl_nlink_end(struct dentry *dentry, bool locked)
|
|
|
|
{
|
2017-06-21 18:46:12 +08:00
|
|
|
if (locked) {
|
|
|
|
if (ovl_test_flag(OVL_INDEX, d_inode(dentry)) &&
|
|
|
|
d_inode(dentry)->i_nlink == 0) {
|
|
|
|
const struct cred *old_cred;
|
|
|
|
|
|
|
|
old_cred = ovl_override_creds(dentry->d_sb);
|
|
|
|
ovl_cleanup_index(dentry);
|
|
|
|
revert_creds(old_cred);
|
|
|
|
}
|
|
|
|
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
mutex_unlock(&OVL_I(d_inode(dentry))->lock);
|
2017-06-21 18:46:12 +08:00
|
|
|
}
|
ovl: persistent overlay inode nlink for indexed inodes
With inodes index enabled, an overlay inode nlink counts the union of upper
and non-covered lower hardlinks. During the lifetime of a non-pure upper
inode, the following nlink modifying operations can happen:
1. Lower hardlink copy up
2. Upper hardlink created, unlinked or renamed over
3. Lower hardlink whiteout or renamed over
For the first, copy up case, the union nlink does not change, whether the
operation succeeds or fails, but the upper inode nlink may change.
Therefore, before copy up, we store the union nlink value relative to the
lower inode nlink in the index inode xattr trusted.overlay.nlink.
For the second, upper hardlink case, the union nlink should be incremented
or decremented IFF the operation succeeds, aligned with nlink change of the
upper inode. Therefore, before link/unlink/rename, we store the union nlink
value relative to the upper inode nlink in the index inode.
For the last, lower cover up case, we simplify things by preceding the
whiteout or cover up with copy up. This makes sure that there is an index
upper inode where the nlink xattr can be stored before the copied up upper
entry is unlink.
Return the overlay inode nlinks for indexed upper inodes on stat(2).
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
2017-06-20 20:35:14 +08:00
|
|
|
}
|
2017-09-25 21:39:55 +08:00
|
|
|
|
|
|
|
int ovl_lock_rename_workdir(struct dentry *workdir, struct dentry *upperdir)
|
|
|
|
{
|
|
|
|
/* Workdir should not be the same as upperdir */
|
|
|
|
if (workdir == upperdir)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
/* Workdir should not be subdir of upperdir and vice versa */
|
|
|
|
if (lock_rename(workdir, upperdir) != NULL)
|
|
|
|
goto err_unlock;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_unlock:
|
|
|
|
unlock_rename(workdir, upperdir);
|
|
|
|
err:
|
|
|
|
pr_err("overlayfs: failed to lock workdir+upperdir\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|