Skip to content

Commit e409de9

Browse files
Andreas GruenbacherAl Viro
Andreas Gruenbacher
authored and
Al Viro
committed
9p: xattr simplifications
Now that the xattr handler is passed to the xattr handler operations, we can use the same get and set operations for the user, trusted, and security xattr namespaces. In those namespaces, we can access the full attribute name by "reattaching" the name prefix the vfs has skipped for us. Add a xattr_full_name helper to make this obvious in the code. For the "system.posix_acl_access" and "system.posix_acl_default" attributes, handler->prefix is the full attribute name; the suffix is the empty string. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Cc: Eric Van Hensbergen <ericvh@gmail.com> Cc: Ron Minnich <rminnich@sandia.gov> Cc: Latchesar Ionkov <lucho@ionkov.net> Cc: v9fs-developer@lists.sourceforge.net Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent d9a82a0 commit e409de9

File tree

9 files changed

+83
-306
lines changed

9 files changed

+83
-306
lines changed

fs/9p/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ obj-$(CONFIG_9P_FS) := 9p.o
1010
vfs_dentry.o \
1111
v9fs.o \
1212
fid.o \
13-
xattr.o \
14-
xattr_user.o \
15-
xattr_trusted.o
13+
xattr.o
1614

1715
9p-$(CONFIG_9P_FSCACHE) += cache.o
1816
9p-$(CONFIG_9P_FS_POSIX_ACL) += acl.o
19-
9p-$(CONFIG_9P_FS_SECURITY) += xattr_security.o

fs/9p/acl.c

Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,12 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
212212
return 0;
213213
}
214214

215-
static int v9fs_remote_get_acl(struct dentry *dentry, const char *name,
216-
void *buffer, size_t size, int type)
217-
{
218-
char *full_name;
219-
220-
switch (type) {
221-
case ACL_TYPE_ACCESS:
222-
full_name = POSIX_ACL_XATTR_ACCESS;
223-
break;
224-
case ACL_TYPE_DEFAULT:
225-
full_name = POSIX_ACL_XATTR_DEFAULT;
226-
break;
227-
default:
228-
BUG();
229-
}
230-
return v9fs_xattr_get(dentry, full_name, buffer, size);
231-
}
232-
233215
static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
234216
struct dentry *dentry, const char *name,
235217
void *buffer, size_t size)
236218
{
237219
struct v9fs_session_info *v9ses;
238220
struct posix_acl *acl;
239-
int type = handler->flags;
240221
int error;
241222

242223
if (strcmp(name, "") != 0)
@@ -247,9 +228,9 @@ static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
247228
* We allow set/get/list of acl when access=client is not specified
248229
*/
249230
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
250-
return v9fs_remote_get_acl(dentry, name, buffer, size, type);
231+
return v9fs_xattr_get(dentry, handler->prefix, buffer, size);
251232

252-
acl = v9fs_get_cached_acl(d_inode(dentry), type);
233+
acl = v9fs_get_cached_acl(d_inode(dentry), handler->flags);
253234
if (IS_ERR(acl))
254235
return PTR_ERR(acl);
255236
if (acl == NULL)
@@ -260,26 +241,6 @@ static int v9fs_xattr_get_acl(const struct xattr_handler *handler,
260241
return error;
261242
}
262243

263-
static int v9fs_remote_set_acl(struct dentry *dentry, const char *name,
264-
const void *value, size_t size,
265-
int flags, int type)
266-
{
267-
char *full_name;
268-
269-
switch (type) {
270-
case ACL_TYPE_ACCESS:
271-
full_name = POSIX_ACL_XATTR_ACCESS;
272-
break;
273-
case ACL_TYPE_DEFAULT:
274-
full_name = POSIX_ACL_XATTR_DEFAULT;
275-
break;
276-
default:
277-
BUG();
278-
}
279-
return v9fs_xattr_set(dentry, full_name, value, size, flags);
280-
}
281-
282-
283244
static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
284245
struct dentry *dentry, const char *name,
285246
const void *value, size_t size, int flags)
@@ -298,8 +259,8 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
298259
* xattr value. We leave it to the server to validate
299260
*/
300261
if ((v9ses->flags & V9FS_ACCESS_MASK) != V9FS_ACCESS_CLIENT)
301-
return v9fs_remote_set_acl(dentry, name,
302-
value, size, flags, handler->flags);
262+
return v9fs_xattr_set(dentry, handler->prefix, value, size,
263+
flags);
303264

304265
if (S_ISLNK(inode->i_mode))
305266
return -EOPNOTSUPP;
@@ -320,7 +281,6 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
320281

321282
switch (handler->flags) {
322283
case ACL_TYPE_ACCESS:
323-
name = POSIX_ACL_XATTR_ACCESS;
324284
if (acl) {
325285
umode_t mode = inode->i_mode;
326286
retval = posix_acl_equiv_mode(acl, &mode);
@@ -351,7 +311,6 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
351311
}
352312
break;
353313
case ACL_TYPE_DEFAULT:
354-
name = POSIX_ACL_XATTR_DEFAULT;
355314
if (!S_ISDIR(inode->i_mode)) {
356315
retval = acl ? -EINVAL : 0;
357316
goto err_out;
@@ -360,7 +319,7 @@ static int v9fs_xattr_set_acl(const struct xattr_handler *handler,
360319
default:
361320
BUG();
362321
}
363-
retval = v9fs_xattr_set(dentry, name, value, size, flags);
322+
retval = v9fs_xattr_set(dentry, handler->prefix, value, size, flags);
364323
if (!retval)
365324
set_cached_acl(inode, handler->flags, acl);
366325
err_out:

fs/9p/xattr.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,48 @@ ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
137137
return v9fs_xattr_get(dentry, NULL, buffer, buffer_size);
138138
}
139139

140+
static int v9fs_xattr_handler_get(const struct xattr_handler *handler,
141+
struct dentry *dentry, const char *name,
142+
void *buffer, size_t size)
143+
{
144+
const char *full_name = xattr_full_name(handler, name);
145+
146+
if (strcmp(name, "") == 0)
147+
return -EINVAL;
148+
return v9fs_xattr_get(dentry, full_name, buffer, size);
149+
}
150+
151+
static int v9fs_xattr_handler_set(const struct xattr_handler *handler,
152+
struct dentry *dentry, const char *name,
153+
const void *value, size_t size, int flags)
154+
{
155+
const char *full_name = xattr_full_name(handler, name);
156+
157+
if (strcmp(name, "") == 0)
158+
return -EINVAL;
159+
return v9fs_xattr_set(dentry, full_name, value, size, flags);
160+
}
161+
162+
static struct xattr_handler v9fs_xattr_user_handler = {
163+
.prefix = XATTR_USER_PREFIX,
164+
.get = v9fs_xattr_handler_get,
165+
.set = v9fs_xattr_handler_set,
166+
};
167+
168+
static struct xattr_handler v9fs_xattr_trusted_handler = {
169+
.prefix = XATTR_TRUSTED_PREFIX,
170+
.get = v9fs_xattr_handler_get,
171+
.set = v9fs_xattr_handler_set,
172+
};
173+
174+
#ifdef CONFIG_9P_FS_SECURITY
175+
static struct xattr_handler v9fs_xattr_security_handler = {
176+
.prefix = XATTR_SECURITY_PREFIX,
177+
.get = v9fs_xattr_handler_get,
178+
.set = v9fs_xattr_handler_set,
179+
};
180+
#endif
181+
140182
const struct xattr_handler *v9fs_xattr_handlers[] = {
141183
&v9fs_xattr_user_handler,
142184
&v9fs_xattr_trusted_handler,

fs/9p/xattr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
#include <net/9p/client.h>
2020

2121
extern const struct xattr_handler *v9fs_xattr_handlers[];
22-
extern struct xattr_handler v9fs_xattr_user_handler;
23-
extern struct xattr_handler v9fs_xattr_trusted_handler;
24-
extern struct xattr_handler v9fs_xattr_security_handler;
2522
extern const struct xattr_handler v9fs_xattr_acl_access_handler;
2623
extern const struct xattr_handler v9fs_xattr_acl_default_handler;
2724

fs/9p/xattr_security.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

fs/9p/xattr_trusted.c

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)