Skip to content

Commit 43d193f

Browse files
author
Miklos Szeredi
committed
ovl: enumerate private xattrs
Instead of passing the xattr name down to the ovl_do_*xattr() accessor functions, pass an enumerated value. The enum can use the same names as the the previous #define for each xattr name. Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 610afc0 commit 43d193f

3 files changed

Lines changed: 59 additions & 26 deletions

File tree

fs/overlayfs/namei.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ int ovl_check_fb_len(struct ovl_fb *fb, int fb_len)
106106
}
107107

108108
static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry,
109-
const char *name)
109+
enum ovl_xattr ox)
110110
{
111111
int res, err;
112112
struct ovl_fh *fh = NULL;
113113

114-
res = ovl_do_getxattr(ofs, dentry, name, NULL, 0);
114+
res = ovl_do_getxattr(ofs, dentry, ox, NULL, 0);
115115
if (res < 0) {
116116
if (res == -ENODATA || res == -EOPNOTSUPP)
117117
return NULL;
@@ -125,7 +125,7 @@ static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *dentry,
125125
if (!fh)
126126
return ERR_PTR(-ENOMEM);
127127

128-
res = ovl_do_getxattr(ofs, dentry, name, fh->buf, res);
128+
res = ovl_do_getxattr(ofs, dentry, ox, fh->buf, res);
129129
if (res < 0)
130130
goto fail;
131131

@@ -416,9 +416,9 @@ static int ovl_check_origin(struct ovl_fs *ofs, struct dentry *upperdentry,
416416
* Return 0 on match, -ESTALE on mismatch, < 0 on error.
417417
*/
418418
static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
419-
const char *name, const struct ovl_fh *fh)
419+
enum ovl_xattr ox, const struct ovl_fh *fh)
420420
{
421-
struct ovl_fh *ofh = ovl_get_fh(ofs, dentry, name);
421+
struct ovl_fh *ofh = ovl_get_fh(ofs, dentry, ox);
422422
int err = 0;
423423

424424
if (!ofh)
@@ -443,7 +443,7 @@ static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
443443
* Return 0 on match, -ESTALE on mismatch, -ENODATA on no xattr, < 0 on error.
444444
*/
445445
int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
446-
const char *name, struct dentry *real, bool is_upper,
446+
enum ovl_xattr ox, struct dentry *real, bool is_upper,
447447
bool set)
448448
{
449449
struct inode *inode;
@@ -457,9 +457,9 @@ int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
457457
goto fail;
458458
}
459459

460-
err = ovl_verify_fh(ofs, dentry, name, fh);
460+
err = ovl_verify_fh(ofs, dentry, ox, fh);
461461
if (set && err == -ENODATA)
462-
err = ovl_do_setxattr(ofs, dentry, name, fh->buf, fh->fb.len);
462+
err = ovl_do_setxattr(ofs, dentry, ox, fh->buf, fh->fb.len);
463463
if (err)
464464
goto fail;
465465

fs/overlayfs/overlayfs.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ enum ovl_path_type {
2323
#define OVL_TYPE_ORIGIN(type) ((type) & __OVL_PATH_ORIGIN)
2424

2525
#define OVL_XATTR_PREFIX XATTR_TRUSTED_PREFIX "overlay."
26-
#define OVL_XATTR_OPAQUE OVL_XATTR_PREFIX "opaque"
27-
#define OVL_XATTR_REDIRECT OVL_XATTR_PREFIX "redirect"
28-
#define OVL_XATTR_ORIGIN OVL_XATTR_PREFIX "origin"
29-
#define OVL_XATTR_IMPURE OVL_XATTR_PREFIX "impure"
30-
#define OVL_XATTR_NLINK OVL_XATTR_PREFIX "nlink"
31-
#define OVL_XATTR_UPPER OVL_XATTR_PREFIX "upper"
32-
#define OVL_XATTR_METACOPY OVL_XATTR_PREFIX "metacopy"
26+
27+
enum ovl_xattr {
28+
OVL_XATTR_OPAQUE,
29+
OVL_XATTR_REDIRECT,
30+
OVL_XATTR_ORIGIN,
31+
OVL_XATTR_IMPURE,
32+
OVL_XATTR_NLINK,
33+
OVL_XATTR_UPPER,
34+
OVL_XATTR_METACOPY,
35+
};
3336

3437
enum ovl_inode_flag {
3538
/* Pure upper dir that may contain non pure upper entries */
@@ -110,6 +113,12 @@ struct ovl_fh {
110113
#define OVL_FH_FID_OFFSET (OVL_FH_WIRE_OFFSET + \
111114
offsetof(struct ovl_fb, fid))
112115

116+
extern const char *ovl_xattr_table[];
117+
static inline const char *ovl_xattr(struct ovl_fs *ofs, enum ovl_xattr ox)
118+
{
119+
return ovl_xattr_table[ox];
120+
}
121+
113122
static inline int ovl_do_rmdir(struct inode *dir, struct dentry *dentry)
114123
{
115124
int err = vfs_rmdir(dir, dentry);
@@ -171,25 +180,28 @@ static inline int ovl_do_symlink(struct inode *dir, struct dentry *dentry,
171180
}
172181

173182
static inline ssize_t ovl_do_getxattr(struct ovl_fs *ofs, struct dentry *dentry,
174-
const char *name, void *value,
183+
enum ovl_xattr ox, void *value,
175184
size_t size)
176185
{
186+
const char *name = ovl_xattr(ofs, ox);
177187
return vfs_getxattr(dentry, name, value, size);
178188
}
179189

180190
static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
181-
const char *name, const void *value,
191+
enum ovl_xattr ox, const void *value,
182192
size_t size)
183193
{
194+
const char *name = ovl_xattr(ofs, ox);
184195
int err = vfs_setxattr(dentry, name, value, size, 0);
185196
pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, 0) = %i\n",
186197
dentry, name, min((int)size, 48), value, size, err);
187198
return err;
188199
}
189200

190201
static inline int ovl_do_removexattr(struct ovl_fs *ofs, struct dentry *dentry,
191-
const char *name)
202+
enum ovl_xattr ox)
192203
{
204+
const char *name = ovl_xattr(ofs, ox);
193205
int err = vfs_removexattr(dentry, name);
194206
pr_debug("removexattr(%pd2, \"%s\") = %i\n", dentry, name, err);
195207
return err;
@@ -291,9 +303,9 @@ void ovl_copy_up_end(struct dentry *dentry);
291303
bool ovl_already_copied_up(struct dentry *dentry, int flags);
292304
bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry);
293305
bool ovl_check_dir_xattr(struct super_block *sb, struct dentry *dentry,
294-
const char *name);
306+
enum ovl_xattr ox);
295307
int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
296-
const char *name, const void *value, size_t size,
308+
enum ovl_xattr ox, const void *value, size_t size,
297309
int xerr);
298310
int ovl_set_impure(struct dentry *dentry, struct dentry *upperdentry);
299311
void ovl_set_flag(unsigned long flag, struct inode *inode);
@@ -376,7 +388,7 @@ struct dentry *ovl_decode_real_fh(struct ovl_fh *fh, struct vfsmount *mnt,
376388
int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,
377389
struct dentry *upperdentry, struct ovl_path **stackp);
378390
int ovl_verify_set_fh(struct ovl_fs *ofs, struct dentry *dentry,
379-
const char *name, struct dentry *real, bool is_upper,
391+
enum ovl_xattr ox, struct dentry *real, bool is_upper,
380392
bool set);
381393
struct dentry *ovl_index_upper(struct ovl_fs *ofs, struct dentry *index);
382394
int ovl_verify_index(struct ovl_fs *ofs, struct dentry *index);

fs/overlayfs/util.c

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -558,23 +558,44 @@ bool ovl_check_origin_xattr(struct ovl_fs *ofs, struct dentry *dentry)
558558
}
559559

560560
bool ovl_check_dir_xattr(struct super_block *sb, struct dentry *dentry,
561-
const char *name)
561+
enum ovl_xattr ox)
562562
{
563563
int res;
564564
char val;
565565

566566
if (!d_is_dir(dentry))
567567
return false;
568568

569-
res = ovl_do_getxattr(OVL_FS(sb), dentry, name, &val, 1);
569+
res = ovl_do_getxattr(OVL_FS(sb), dentry, ox, &val, 1);
570570
if (res == 1 && val == 'y')
571571
return true;
572572

573573
return false;
574574
}
575575

576+
#define OVL_XATTR_OPAQUE_POSTFIX "opaque"
577+
#define OVL_XATTR_REDIRECT_POSTFIX "redirect"
578+
#define OVL_XATTR_ORIGIN_POSTFIX "origin"
579+
#define OVL_XATTR_IMPURE_POSTFIX "impure"
580+
#define OVL_XATTR_NLINK_POSTFIX "nlink"
581+
#define OVL_XATTR_UPPER_POSTFIX "upper"
582+
#define OVL_XATTR_METACOPY_POSTFIX "metacopy"
583+
584+
#define OVL_XATTR_TAB_ENTRY(x) \
585+
[x] = OVL_XATTR_PREFIX x ## _POSTFIX
586+
587+
const char *ovl_xattr_table[] = {
588+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_OPAQUE),
589+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_REDIRECT),
590+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_ORIGIN),
591+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_IMPURE),
592+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_NLINK),
593+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_UPPER),
594+
OVL_XATTR_TAB_ENTRY(OVL_XATTR_METACOPY),
595+
};
596+
576597
int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
577-
const char *name, const void *value, size_t size,
598+
enum ovl_xattr ox, const void *value, size_t size,
578599
int xerr)
579600
{
580601
int err;
@@ -583,10 +604,10 @@ int ovl_check_setxattr(struct dentry *dentry, struct dentry *upperdentry,
583604
if (ofs->noxattr)
584605
return xerr;
585606

586-
err = ovl_do_setxattr(ofs, upperdentry, name, value, size);
607+
err = ovl_do_setxattr(ofs, upperdentry, ox, value, size);
587608

588609
if (err == -EOPNOTSUPP) {
589-
pr_warn("cannot set %s xattr on upper\n", name);
610+
pr_warn("cannot set %s xattr on upper\n", ovl_xattr(ofs, ox));
590611
ofs->noxattr = true;
591612
return xerr;
592613
}

0 commit comments

Comments
 (0)