Commit 05895219 authored by Ondrej Mosnacek's avatar Ondrej Mosnacek Committed by Paul Moore

kernfs: clean up struct kernfs_iattrs

Right now, kernfs_iattrs embeds the whole struct iattr, even though it
doesn't really use half of its fields... This both leads to wasting
space and makes the code look awkward. Let's just list the few fields
we need directly in struct kernfs_iattrs.
Signed-off-by: default avatarOndrej Mosnacek <omosnace@redhat.com>
Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
[PM: merged a number of chunks manually due to fuzz]
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent ccd19d4c
...@@ -795,9 +795,8 @@ int kernfs_add_one(struct kernfs_node *kn) ...@@ -795,9 +795,8 @@ int kernfs_add_one(struct kernfs_node *kn)
/* Update timestamps on the parent */ /* Update timestamps on the parent */
ps_iattr = parent->iattr; ps_iattr = parent->iattr;
if (ps_iattr) { if (ps_iattr) {
struct iattr *ps_iattrs = &ps_iattr->ia_iattr; ktime_get_real_ts64(&ps_iattr->ia_ctime);
ktime_get_real_ts64(&ps_iattrs->ia_ctime); ps_iattr->ia_mtime = ps_iattr->ia_ctime;
ps_iattrs->ia_mtime = ps_iattrs->ia_ctime;
} }
mutex_unlock(&kernfs_mutex); mutex_unlock(&kernfs_mutex);
...@@ -1329,9 +1328,8 @@ static void __kernfs_remove(struct kernfs_node *kn) ...@@ -1329,9 +1328,8 @@ static void __kernfs_remove(struct kernfs_node *kn)
/* update timestamps on the parent */ /* update timestamps on the parent */
if (ps_iattr) { if (ps_iattr) {
ktime_get_real_ts64(&ps_iattr->ia_iattr.ia_ctime); ktime_get_real_ts64(&ps_iattr->ia_ctime);
ps_iattr->ia_iattr.ia_mtime = ps_iattr->ia_mtime = ps_iattr->ia_ctime;
ps_iattr->ia_iattr.ia_ctime;
} }
kernfs_put(pos); kernfs_put(pos);
......
...@@ -35,7 +35,6 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn) ...@@ -35,7 +35,6 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
{ {
static DEFINE_MUTEX(iattr_mutex); static DEFINE_MUTEX(iattr_mutex);
struct kernfs_iattrs *ret; struct kernfs_iattrs *ret;
struct iattr *iattrs;
mutex_lock(&iattr_mutex); mutex_lock(&iattr_mutex);
...@@ -45,16 +44,14 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn) ...@@ -45,16 +44,14 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL); kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL);
if (!kn->iattr) if (!kn->iattr)
goto out_unlock; goto out_unlock;
iattrs = &kn->iattr->ia_iattr;
/* assign default attributes */ /* assign default attributes */
iattrs->ia_mode = kn->mode; kn->iattr->ia_uid = GLOBAL_ROOT_UID;
iattrs->ia_uid = GLOBAL_ROOT_UID; kn->iattr->ia_gid = GLOBAL_ROOT_GID;
iattrs->ia_gid = GLOBAL_ROOT_GID;
ktime_get_real_ts64(&iattrs->ia_atime); ktime_get_real_ts64(&kn->iattr->ia_atime);
iattrs->ia_mtime = iattrs->ia_atime; kn->iattr->ia_mtime = kn->iattr->ia_atime;
iattrs->ia_ctime = iattrs->ia_atime; kn->iattr->ia_ctime = kn->iattr->ia_atime;
simple_xattrs_init(&kn->iattr->xattrs); simple_xattrs_init(&kn->iattr->xattrs);
out_unlock: out_unlock:
...@@ -66,29 +63,24 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn) ...@@ -66,29 +63,24 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr) int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{ {
struct kernfs_iattrs *attrs; struct kernfs_iattrs *attrs;
struct iattr *iattrs;
unsigned int ia_valid = iattr->ia_valid; unsigned int ia_valid = iattr->ia_valid;
attrs = kernfs_iattrs(kn); attrs = kernfs_iattrs(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENOMEM;
iattrs = &attrs->ia_iattr;
if (ia_valid & ATTR_UID) if (ia_valid & ATTR_UID)
iattrs->ia_uid = iattr->ia_uid; attrs->ia_uid = iattr->ia_uid;
if (ia_valid & ATTR_GID) if (ia_valid & ATTR_GID)
iattrs->ia_gid = iattr->ia_gid; attrs->ia_gid = iattr->ia_gid;
if (ia_valid & ATTR_ATIME) if (ia_valid & ATTR_ATIME)
iattrs->ia_atime = iattr->ia_atime; attrs->ia_atime = iattr->ia_atime;
if (ia_valid & ATTR_MTIME) if (ia_valid & ATTR_MTIME)
iattrs->ia_mtime = iattr->ia_mtime; attrs->ia_mtime = iattr->ia_mtime;
if (ia_valid & ATTR_CTIME) if (ia_valid & ATTR_CTIME)
iattrs->ia_ctime = iattr->ia_ctime; attrs->ia_ctime = iattr->ia_ctime;
if (ia_valid & ATTR_MODE) { if (ia_valid & ATTR_MODE)
umode_t mode = iattr->ia_mode; kn->mode = iattr->ia_mode;
iattrs->ia_mode = kn->mode = mode;
}
return 0; return 0;
} }
...@@ -171,14 +163,15 @@ static inline void set_default_inode_attr(struct inode *inode, umode_t mode) ...@@ -171,14 +163,15 @@ static inline void set_default_inode_attr(struct inode *inode, umode_t mode)
inode->i_ctime = current_time(inode); inode->i_ctime = current_time(inode);
} }
static inline void set_inode_attr(struct inode *inode, struct iattr *iattr) static inline void set_inode_attr(struct inode *inode,
struct kernfs_iattrs *attrs)
{ {
struct super_block *sb = inode->i_sb; struct super_block *sb = inode->i_sb;
inode->i_uid = iattr->ia_uid; inode->i_uid = attrs->ia_uid;
inode->i_gid = iattr->ia_gid; inode->i_gid = attrs->ia_gid;
inode->i_atime = timespec64_trunc(iattr->ia_atime, sb->s_time_gran); inode->i_atime = timespec64_trunc(attrs->ia_atime, sb->s_time_gran);
inode->i_mtime = timespec64_trunc(iattr->ia_mtime, sb->s_time_gran); inode->i_mtime = timespec64_trunc(attrs->ia_mtime, sb->s_time_gran);
inode->i_ctime = timespec64_trunc(iattr->ia_ctime, sb->s_time_gran); inode->i_ctime = timespec64_trunc(attrs->ia_ctime, sb->s_time_gran);
} }
static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
...@@ -191,7 +184,7 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode) ...@@ -191,7 +184,7 @@ static void kernfs_refresh_inode(struct kernfs_node *kn, struct inode *inode)
* kernfs_node has non-default attributes get them from * kernfs_node has non-default attributes get them from
* persistent copy in kernfs_node. * persistent copy in kernfs_node.
*/ */
set_inode_attr(inode, &attrs->ia_iattr); set_inode_attr(inode, attrs);
security_inode_notifysecctx(inode, attrs->ia_secdata, security_inode_notifysecctx(inode, attrs->ia_secdata,
attrs->ia_secdata_len); attrs->ia_secdata_len);
} }
......
...@@ -20,7 +20,11 @@ ...@@ -20,7 +20,11 @@
#include <linux/fs_context.h> #include <linux/fs_context.h>
struct kernfs_iattrs { struct kernfs_iattrs {
struct iattr ia_iattr; kuid_t ia_uid;
kgid_t ia_gid;
struct timespec64 ia_atime;
struct timespec64 ia_mtime;
struct timespec64 ia_ctime;
void *ia_secdata; void *ia_secdata;
u32 ia_secdata_len; u32 ia_secdata_len;
......
...@@ -33,8 +33,8 @@ struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, ...@@ -33,8 +33,8 @@ struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
kgid_t gid = GLOBAL_ROOT_GID; kgid_t gid = GLOBAL_ROOT_GID;
if (target->iattr) { if (target->iattr) {
uid = target->iattr->ia_iattr.ia_uid; uid = target->iattr->ia_uid;
gid = target->iattr->ia_iattr.ia_gid; gid = target->iattr->ia_gid;
} }
kn = kernfs_new_node(parent, name, S_IFLNK|S_IRWXUGO, uid, gid, kn = kernfs_new_node(parent, name, S_IFLNK|S_IRWXUGO, uid, gid,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment