Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ecryptfs: Switch to generic xattr handlers

Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

authored by

Andreas Gruenbacher and committed by
Al Viro
4b899da5 bba0bd31

+51 -14
+2
fs/ecryptfs/ecryptfs_kernel.h
··· 715 715 int ecryptfs_derive_iv(char *iv, struct ecryptfs_crypt_stat *crypt_stat, 716 716 loff_t offset); 717 717 718 + extern const struct xattr_handler *ecryptfs_xattr_handlers[]; 719 + 718 720 #endif /* #ifndef ECRYPTFS_KERNEL_H */
+48 -14
fs/ecryptfs/inode.c
··· 1066 1066 return rc; 1067 1067 } 1068 1068 1069 - static int ecryptfs_removexattr(struct dentry *dentry, const char *name) 1069 + static int ecryptfs_removexattr(struct dentry *dentry, struct inode *inode, 1070 + const char *name) 1070 1071 { 1071 1072 int rc = 0; 1072 1073 struct dentry *lower_dentry; 1074 + struct inode *lower_inode; 1073 1075 1074 1076 lower_dentry = ecryptfs_dentry_to_lower(dentry); 1075 - if (!d_inode(lower_dentry)->i_op->removexattr) { 1077 + lower_inode = ecryptfs_inode_to_lower(inode); 1078 + if (!lower_inode->i_op->removexattr) { 1076 1079 rc = -EOPNOTSUPP; 1077 1080 goto out; 1078 1081 } 1079 - inode_lock(d_inode(lower_dentry)); 1080 - rc = d_inode(lower_dentry)->i_op->removexattr(lower_dentry, name); 1081 - inode_unlock(d_inode(lower_dentry)); 1082 + inode_lock(lower_inode); 1083 + rc = lower_inode->i_op->removexattr(lower_dentry, name); 1084 + inode_unlock(lower_inode); 1082 1085 out: 1083 1086 return rc; 1084 1087 } ··· 1092 1089 .permission = ecryptfs_permission, 1093 1090 .setattr = ecryptfs_setattr, 1094 1091 .getattr = ecryptfs_getattr_link, 1095 - .setxattr = ecryptfs_setxattr, 1096 - .getxattr = ecryptfs_getxattr, 1092 + .setxattr = generic_setxattr, 1093 + .getxattr = generic_getxattr, 1097 1094 .listxattr = ecryptfs_listxattr, 1098 - .removexattr = ecryptfs_removexattr 1095 + .removexattr = generic_removexattr 1099 1096 }; 1100 1097 1101 1098 const struct inode_operations ecryptfs_dir_iops = { ··· 1110 1107 .rename = ecryptfs_rename, 1111 1108 .permission = ecryptfs_permission, 1112 1109 .setattr = ecryptfs_setattr, 1113 - .setxattr = ecryptfs_setxattr, 1114 - .getxattr = ecryptfs_getxattr, 1110 + .setxattr = generic_setxattr, 1111 + .getxattr = generic_getxattr, 1115 1112 .listxattr = ecryptfs_listxattr, 1116 - .removexattr = ecryptfs_removexattr 1113 + .removexattr = generic_removexattr 1117 1114 }; 1118 1115 1119 1116 const struct inode_operations ecryptfs_main_iops = { 1120 1117 .permission = ecryptfs_permission, 1121 1118 .setattr = ecryptfs_setattr, 1122 1119 .getattr = ecryptfs_getattr, 1123 - .setxattr = ecryptfs_setxattr, 1124 - .getxattr = ecryptfs_getxattr, 1120 + .setxattr = generic_setxattr, 1121 + .getxattr = generic_getxattr, 1125 1122 .listxattr = ecryptfs_listxattr, 1126 - .removexattr = ecryptfs_removexattr 1123 + .removexattr = generic_removexattr 1124 + }; 1125 + 1126 + static int ecryptfs_xattr_get(const struct xattr_handler *handler, 1127 + struct dentry *dentry, struct inode *inode, 1128 + const char *name, void *buffer, size_t size) 1129 + { 1130 + return ecryptfs_getxattr(dentry, inode, name, buffer, size); 1131 + } 1132 + 1133 + static int ecryptfs_xattr_set(const struct xattr_handler *handler, 1134 + struct dentry *dentry, struct inode *inode, 1135 + const char *name, const void *value, size_t size, 1136 + int flags) 1137 + { 1138 + if (value) 1139 + return ecryptfs_setxattr(dentry, inode, name, value, size, flags); 1140 + else { 1141 + BUG_ON(flags != XATTR_REPLACE); 1142 + return ecryptfs_removexattr(dentry, inode, name); 1143 + } 1144 + } 1145 + 1146 + const struct xattr_handler ecryptfs_xattr_handler = { 1147 + .prefix = "", /* match anything */ 1148 + .get = ecryptfs_xattr_get, 1149 + .set = ecryptfs_xattr_set, 1150 + }; 1151 + 1152 + const struct xattr_handler *ecryptfs_xattr_handlers[] = { 1153 + &ecryptfs_xattr_handler, 1154 + NULL 1127 1155 };
+1
fs/ecryptfs/main.c
··· 529 529 /* ->kill_sb() will take care of sbi after that point */ 530 530 sbi = NULL; 531 531 s->s_op = &ecryptfs_sops; 532 + s->s_xattr = ecryptfs_xattr_handlers; 532 533 s->s_d_op = &ecryptfs_dops; 533 534 534 535 err = "Reading sb failed";