Skip to content

Commit 420a62d

Browse files
committed
ovl: Move xattr support to new xattrs.c file
This moves the code from super.c and inode.c, and makes ovl_xattr_get/set() static. This is in preparation for doing more work on xattrs support. Signed-off-by: Alexander Larsson <[email protected]> Reviewed-by: Amir Goldstein <[email protected]> Signed-off-by: Amir Goldstein <[email protected]>
1 parent 5b02bfc commit 420a62d

File tree

5 files changed

+207
-196
lines changed

5 files changed

+207
-196
lines changed

fs/overlayfs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
obj-$(CONFIG_OVERLAY_FS) += overlay.o
77

88
overlay-objs := super.o namei.o util.o inode.o file.o dir.o readdir.o \
9-
copy_up.o export.o params.o
9+
copy_up.o export.o params.o xattrs.o

fs/overlayfs/inode.c

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -339,128 +339,6 @@ static const char *ovl_get_link(struct dentry *dentry,
339339
return p;
340340
}
341341

342-
bool ovl_is_private_xattr(struct super_block *sb, const char *name)
343-
{
344-
struct ovl_fs *ofs = OVL_FS(sb);
345-
346-
if (ofs->config.userxattr)
347-
return strncmp(name, OVL_XATTR_USER_PREFIX,
348-
sizeof(OVL_XATTR_USER_PREFIX) - 1) == 0;
349-
else
350-
return strncmp(name, OVL_XATTR_TRUSTED_PREFIX,
351-
sizeof(OVL_XATTR_TRUSTED_PREFIX) - 1) == 0;
352-
}
353-
354-
int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
355-
const void *value, size_t size, int flags)
356-
{
357-
int err;
358-
struct ovl_fs *ofs = OVL_FS(dentry->d_sb);
359-
struct dentry *upperdentry = ovl_i_dentry_upper(inode);
360-
struct dentry *realdentry = upperdentry ?: ovl_dentry_lower(dentry);
361-
struct path realpath;
362-
const struct cred *old_cred;
363-
364-
if (!value && !upperdentry) {
365-
ovl_path_lower(dentry, &realpath);
366-
old_cred = ovl_override_creds(dentry->d_sb);
367-
err = vfs_getxattr(mnt_idmap(realpath.mnt), realdentry, name, NULL, 0);
368-
revert_creds(old_cred);
369-
if (err < 0)
370-
goto out;
371-
}
372-
373-
if (!upperdentry) {
374-
err = ovl_copy_up(dentry);
375-
if (err)
376-
goto out;
377-
378-
realdentry = ovl_dentry_upper(dentry);
379-
}
380-
381-
err = ovl_want_write(dentry);
382-
if (err)
383-
goto out;
384-
385-
old_cred = ovl_override_creds(dentry->d_sb);
386-
if (value) {
387-
err = ovl_do_setxattr(ofs, realdentry, name, value, size,
388-
flags);
389-
} else {
390-
WARN_ON(flags != XATTR_REPLACE);
391-
err = ovl_do_removexattr(ofs, realdentry, name);
392-
}
393-
revert_creds(old_cred);
394-
ovl_drop_write(dentry);
395-
396-
/* copy c/mtime */
397-
ovl_copyattr(inode);
398-
out:
399-
return err;
400-
}
401-
402-
int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
403-
void *value, size_t size)
404-
{
405-
ssize_t res;
406-
const struct cred *old_cred;
407-
struct path realpath;
408-
409-
ovl_i_path_real(inode, &realpath);
410-
old_cred = ovl_override_creds(dentry->d_sb);
411-
res = vfs_getxattr(mnt_idmap(realpath.mnt), realpath.dentry, name, value, size);
412-
revert_creds(old_cred);
413-
return res;
414-
}
415-
416-
static bool ovl_can_list(struct super_block *sb, const char *s)
417-
{
418-
/* Never list private (.overlay) */
419-
if (ovl_is_private_xattr(sb, s))
420-
return false;
421-
422-
/* List all non-trusted xattrs */
423-
if (strncmp(s, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) != 0)
424-
return true;
425-
426-
/* list other trusted for superuser only */
427-
return ns_capable_noaudit(&init_user_ns, CAP_SYS_ADMIN);
428-
}
429-
430-
ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size)
431-
{
432-
struct dentry *realdentry = ovl_dentry_real(dentry);
433-
ssize_t res;
434-
size_t len;
435-
char *s;
436-
const struct cred *old_cred;
437-
438-
old_cred = ovl_override_creds(dentry->d_sb);
439-
res = vfs_listxattr(realdentry, list, size);
440-
revert_creds(old_cred);
441-
if (res <= 0 || size == 0)
442-
return res;
443-
444-
/* filter out private xattrs */
445-
for (s = list, len = res; len;) {
446-
size_t slen = strnlen(s, len) + 1;
447-
448-
/* underlying fs providing us with an broken xattr list? */
449-
if (WARN_ON(slen > len))
450-
return -EIO;
451-
452-
len -= slen;
453-
if (!ovl_can_list(dentry->d_sb, s)) {
454-
res -= slen;
455-
memmove(s, s + slen, len);
456-
} else {
457-
s += slen;
458-
}
459-
}
460-
461-
return res;
462-
}
463-
464342
#ifdef CONFIG_FS_POSIX_ACL
465343
/*
466344
* Apply the idmapping of the layer to POSIX ACLs. The caller must pass a clone

fs/overlayfs/overlayfs.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -699,17 +699,8 @@ int ovl_set_nlink_lower(struct dentry *dentry);
699699
unsigned int ovl_get_nlink(struct ovl_fs *ofs, struct dentry *lowerdentry,
700700
struct dentry *upperdentry,
701701
unsigned int fallback);
702-
int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
703-
struct iattr *attr);
704-
int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
705-
struct kstat *stat, u32 request_mask, unsigned int flags);
706702
int ovl_permission(struct mnt_idmap *idmap, struct inode *inode,
707703
int mask);
708-
int ovl_xattr_set(struct dentry *dentry, struct inode *inode, const char *name,
709-
const void *value, size_t size, int flags);
710-
int ovl_xattr_get(struct dentry *dentry, struct inode *inode, const char *name,
711-
void *value, size_t size);
712-
ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);
713704

714705
#ifdef CONFIG_FS_POSIX_ACL
715706
struct posix_acl *do_ovl_get_acl(struct mnt_idmap *idmap,
@@ -846,3 +837,12 @@ static inline bool ovl_force_readonly(struct ovl_fs *ofs)
846837
{
847838
return (!ovl_upper_mnt(ofs) || !ofs->workdir);
848839
}
840+
841+
/* xattr.c */
842+
843+
const struct xattr_handler * const *ovl_xattr_handlers(struct ovl_fs *ofs);
844+
int ovl_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
845+
struct iattr *attr);
846+
int ovl_getattr(struct mnt_idmap *idmap, const struct path *path,
847+
struct kstat *stat, u32 request_mask, unsigned int flags);
848+
ssize_t ovl_listxattr(struct dentry *dentry, char *list, size_t size);

fs/overlayfs/super.c

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -445,68 +445,6 @@ static bool ovl_workdir_ok(struct dentry *workdir, struct dentry *upperdir)
445445
return ok;
446446
}
447447

448-
static int ovl_own_xattr_get(const struct xattr_handler *handler,
449-
struct dentry *dentry, struct inode *inode,
450-
const char *name, void *buffer, size_t size)
451-
{
452-
return -EOPNOTSUPP;
453-
}
454-
455-
static int ovl_own_xattr_set(const struct xattr_handler *handler,
456-
struct mnt_idmap *idmap,
457-
struct dentry *dentry, struct inode *inode,
458-
const char *name, const void *value,
459-
size_t size, int flags)
460-
{
461-
return -EOPNOTSUPP;
462-
}
463-
464-
static int ovl_other_xattr_get(const struct xattr_handler *handler,
465-
struct dentry *dentry, struct inode *inode,
466-
const char *name, void *buffer, size_t size)
467-
{
468-
return ovl_xattr_get(dentry, inode, name, buffer, size);
469-
}
470-
471-
static int ovl_other_xattr_set(const struct xattr_handler *handler,
472-
struct mnt_idmap *idmap,
473-
struct dentry *dentry, struct inode *inode,
474-
const char *name, const void *value,
475-
size_t size, int flags)
476-
{
477-
return ovl_xattr_set(dentry, inode, name, value, size, flags);
478-
}
479-
480-
static const struct xattr_handler ovl_own_trusted_xattr_handler = {
481-
.prefix = OVL_XATTR_TRUSTED_PREFIX,
482-
.get = ovl_own_xattr_get,
483-
.set = ovl_own_xattr_set,
484-
};
485-
486-
static const struct xattr_handler ovl_own_user_xattr_handler = {
487-
.prefix = OVL_XATTR_USER_PREFIX,
488-
.get = ovl_own_xattr_get,
489-
.set = ovl_own_xattr_set,
490-
};
491-
492-
static const struct xattr_handler ovl_other_xattr_handler = {
493-
.prefix = "", /* catch all */
494-
.get = ovl_other_xattr_get,
495-
.set = ovl_other_xattr_set,
496-
};
497-
498-
static const struct xattr_handler * const ovl_trusted_xattr_handlers[] = {
499-
&ovl_own_trusted_xattr_handler,
500-
&ovl_other_xattr_handler,
501-
NULL
502-
};
503-
504-
static const struct xattr_handler * const ovl_user_xattr_handlers[] = {
505-
&ovl_own_user_xattr_handler,
506-
&ovl_other_xattr_handler,
507-
NULL
508-
};
509-
510448
static int ovl_setup_trap(struct super_block *sb, struct dentry *dir,
511449
struct inode **ptrap, const char *name)
512450
{
@@ -1501,8 +1439,7 @@ int ovl_fill_super(struct super_block *sb, struct fs_context *fc)
15011439
cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
15021440

15031441
sb->s_magic = OVERLAYFS_SUPER_MAGIC;
1504-
sb->s_xattr = ofs->config.userxattr ? ovl_user_xattr_handlers :
1505-
ovl_trusted_xattr_handlers;
1442+
sb->s_xattr = ovl_xattr_handlers(ofs);
15061443
sb->s_fs_info = ofs;
15071444
#ifdef CONFIG_FS_POSIX_ACL
15081445
sb->s_flags |= SB_POSIXACL;

0 commit comments

Comments
 (0)