Skip to content

Commit

Permalink
Created new branch for ACL support. Changes are pulled from Massimo M…
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhare committed Jan 26, 2011
1 parent b533bfd commit 23cd086
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 46 deletions.
13 changes: 12 additions & 1 deletion include/lzfs_xattr.h
Expand Up @@ -12,7 +12,8 @@ ssize_t
lzfs_listxattr(struct dentry *dentry, char *buffer, size_t size);

extern struct xattr_handler lzfs_xattr_user_handler;

extern struct xattr_handler lzfs_xattr_acl_access_handler;
extern struct xattr_handler lzfs_xattr_acl_default_handler;
extern struct xattr_handler lzfs_xattr_security_handler;

int
Expand All @@ -23,5 +24,15 @@ lzfs_removexattr(struct dentry *dentry, const char *name);

int
lzfs_init_security(struct dentry *dentry, struct inode *dir);

int
lzfs_vnop_setattr(struct dentry *dentry, struct iattr *iattr);
int
lzfs_check_acl(struct inode *inode, int mask);
int
lzfs_acl_chmod(struct inode *inode);
int
lzfs_acl_init(struct inode *inode, struct inode *dir);

#endif /* _LZFS_XATTR_H */

1 change: 1 addition & 0 deletions module/Makefile.in
Expand Up @@ -14,6 +14,7 @@ lzfs-objs += lzfs_exportfs.o
lzfs-objs += lzfs_xattr.o
lzfs-objs += lzfs_xattr_user.o
lzfs-objs += lzfs_xattr_security.o
lzfs-objs += lzfs_xattr_acl.o


INSTALL=/usr/bin/install
Expand Down
1 change: 1 addition & 0 deletions module/lzfs_super.c
Expand Up @@ -258,6 +258,7 @@ lzfs_fill_super(struct super_block *sb, void *data, int silent)
sb->s_op = &lzfs_ops;
sb->s_time_gran = 1;
sb->s_flags = MS_ACTIVE;
sb->s_flags |= MS_POSIXACL;
sb->s_export_op = &zfs_export_ops;
sb->s_xattr = lzfs_xattr_handlers;
error = zfs_domount(vfsp, data);
Expand Down
20 changes: 11 additions & 9 deletions module/lzfs_vnops.c
Expand Up @@ -128,6 +128,7 @@ lzfs_vnop_create(struct inode *dir, struct dentry *dentry, int mode,
}
d_instantiate(dentry, LZFS_VTOI(vp));
se_err = lzfs_init_security(dentry, dir);
lzfs_acl_init(dentry->d_inode,dir);
if(se_err) {
tsd_exit();
SEXIT;
Expand Down Expand Up @@ -309,6 +310,7 @@ lzfs_vnop_symlink (struct inode *dir, struct dentry *dentry,
}
d_instantiate(dentry, LZFS_VTOI(vp));
se_err = lzfs_init_security(dentry, dir);
lzfs_acl_init(dentry->d_inode,dir);
if(se_err) {
tsd_exit();
SEXIT;
Expand Down Expand Up @@ -352,6 +354,7 @@ lzfs_vnop_mkdir(struct inode *dir, struct dentry *dentry, int mode)
}
d_instantiate(dentry, LZFS_VTOI(vp));
se_err = lzfs_init_security(dentry, dir);
lzfs_acl_init(dentry->d_inode,dir);
if(se_err) {
tsd_exit();
SEXIT;
Expand Down Expand Up @@ -428,7 +431,9 @@ lzfs_vnop_mknod(struct inode * dir, struct dentry *dentry, int mode,
return PTR_ERR(ERR_PTR(-err));
}
d_instantiate(dentry, LZFS_VTOI(vp));
init_special_inode(dentry->d_inode,mode,rdev);
se_err = lzfs_init_security(dentry, dir);
lzfs_acl_init(dentry->d_inode,dir);
if(se_err) {
tsd_exit();
SEXIT;
Expand Down Expand Up @@ -526,6 +531,9 @@ lzfs_vnop_setattr(struct dentry *dentry, struct iattr *iattr)

err = zfs_setattr(vp, vap, 0, (struct cred *)cred, NULL);
kfree(vap);
if(mask & ATTR_MODE){
lzfs_acl_chmod(inode);
}
put_cred(cred);
tsd_exit();
SEXIT;
Expand All @@ -534,12 +542,6 @@ lzfs_vnop_setattr(struct dentry *dentry, struct iattr *iattr)
return 0;
}

int
lzfs_vnop_permission(struct inode *inode, int mask)
{
return generic_permission(inode, mask, NULL);
}

static void lzfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
{
char *buf = nd_get_link(nd);
Expand Down Expand Up @@ -1036,7 +1038,7 @@ lzfs_vnop_write (struct file *filep, const char __user *buf, size_t len,

/*
* fops->open is not needed for default operations, but in case mmap is
* called on an opened file we need strcut file *, save it in vnode_t
* called on an opened file we need struct file *, save it in vnode_t
* */
static int lzfs_vnop_open(struct inode *inode, struct file *file)
{
Expand Down Expand Up @@ -1194,7 +1196,7 @@ const struct inode_operations zfs_inode_operations = {
.mknod = lzfs_vnop_mknod,
.rename = lzfs_vnop_rename,
.setattr = lzfs_vnop_setattr,
.permission = lzfs_vnop_permission,
.check_acl = lzfs_check_acl,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = lzfs_listxattr,
Expand Down Expand Up @@ -1225,7 +1227,7 @@ const struct inode_operations zfs_dir_inode_operations ={
.mknod = lzfs_vnop_mknod,
.rename = lzfs_vnop_rename,
.setattr = lzfs_vnop_setattr,
.permission = lzfs_vnop_permission,
.check_acl = lzfs_check_acl,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.listxattr = lzfs_listxattr,
Expand Down
35 changes: 21 additions & 14 deletions module/lzfs_xattr.c
Expand Up @@ -52,10 +52,17 @@ lzfs_xattr_get(struct inode *inode, const char *name,
xattr_name = strncpy(xattr_name, "security.", 9);
xattr_name = strncat(xattr_name, name, strlen(name));
}
else if(index==2){
xattr_name = kzalloc(strlen(name), GFP_KERNEL);
xattr_name = strncpy(xattr_name, name,strlen(name));
}
err = zfs_lookup(vp, (char *) xattr_name, &xvp, NULL, 0, NULL,
(struct cred *) cred, NULL, NULL, NULL);
kfree(xattr_name);
if(err) {
if(err == ENOENT) {
return -ENODATA;
}
return -err;
}
xinode = LZFS_VTOI(xvp);
Expand Down Expand Up @@ -115,9 +122,9 @@ struct listxattr_buf {
size_t size;
size_t pos;
char *buf;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
struct inode *inode;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
struct dentry *dentry;
#endif
};
Expand All @@ -135,33 +142,33 @@ static int listxattr_filler(void *buf, const char *name, int namelen,
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
const struct xattr_handler *handler;
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
handler = find_xattr_handler_prefix(
b->inode->i_sb->s_xattr,
name);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
handler = find_xattr_handler_prefix(
b->dentry->d_sb->s_xattr,
name);
#endif
if (!handler)
return 0;
if (b->buf) {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
size = handler->list(b->inode, b->buf + b->pos,
b->size, name, namelen);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
size = handler->list(b->dentry, b->buf + b->pos,
b->size, name, namelen,
handler->flags);
#endif
if (size > b->size)
return -ERANGE;
} else {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
size = handler->list(b->inode, NULL,
0, name, namelen);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
size = handler->list(b->dentry, NULL,
0, name, namelen, handler->flags);
#endif
Expand All @@ -181,9 +188,9 @@ lzfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
loff_t pos = 0;

struct listxattr_buf buf = {
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
.inode = dentry->d_inode,
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
.dentry = dentry,
#endif
.buf = buffer,
Expand Down Expand Up @@ -225,9 +232,9 @@ lzfs_removexattr(struct dentry *dentry, const char *name)

if (!handler)
return -EOPNOTSUPP;
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
return handler->set(inode, name, NULL, 0, XATTR_REPLACE);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)
return handler->set(dentry, name, NULL, 0, XATTR_REPLACE,
handler->flags);
#endif
Expand All @@ -241,9 +248,9 @@ const struct xattr_handler *lzfs_xattr_handlers[] = {
&lzfs_xattr_user_handler,
#ifdef HAVE_ZPL
&lzfs_xattr_trusted_handler, // TODO
&lzfs_xattr_acl_access_handler, // TODO
&lzfs_xattr_acl_default_handler,// TODO
#endif /* HAVE_ZPL */
&lzfs_xattr_acl_access_handler,
&lzfs_xattr_acl_default_handler,
&lzfs_xattr_security_handler,
NULL
};

0 comments on commit 23cd086

Please sign in to comment.