ocfs2: add security EA and ACL support v2
Subsystems (3)
cover ocfs2: add security EA and ACL support v2
Hi,
These three patches fix the problems in the version one. And them base on the Tao's patches:
ocfs2/xattr: Remove unused restore_extent_block and ocfs2/xattr: Merge xattr set transaction.
The first patch fix some problem in xattr code. The second patch add security EA support. The third patch add ACL support.
Best regards,
tiger
PATCH 1/3 ocfs2/xattr: some fix in xattr
This patch fix some function declaration problem in xattr.
--- fs/ocfs2/xattr.c | 39 +++++++++++++++++++++++++-------------- fs/ocfs2/xattr.h | 26 ++++---------------------- 2 files changed, 29 insertions(+), 36 deletions(-)
fs/ocfs2/xattr.c +25 -14
@@ -147,6 +147,24 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,static int ocfs2_delete_xattr_index_block (struct inode *inode,struct buffer_head *xb_bh); +static inline u16 ocfs2_xattr_buckets_per_cluster (struct ocfs2_super *osb) +{ +return (1 << osb->s_clustersize_bits) /OCFS2_XATTR_BUCKET_SIZE ; +} + +static inline u16 ocfs2_blocks_per_xattr_bucket (struct super_block *sb) +{ +return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); +} + +static inline u16 ocfs2_xattr_max_xe_in_bucket (struct super_block *sb) +{ +u16 len = sb->s_blocksize - + offsetof(struct ocfs2_xattr_header , xh_entries); + +return len /sizeof (struct ocfs2_xattr_entry ); +} +static inline const char *ocfs2_xattr_prefix (int name_index) {struct xattr_handler *handler =NULL ;
@@ -800,11 +818,11 @@ cleanup:* Copy an extended attribute into the buffer provided. * Buffer is NULL to compute the size of buffer required. */ -int ocfs2_xattr_get (struct inode *inode, -int name_index, -const char *name, -void *buffer, -size_t buffer_size) +static int ocfs2_xattr_get (struct inode *inode, +int name_index, +const char *name, +void *buffer, +size_t buffer_size) {int ret;struct ocfs2_dinode *di =NULL ;
@@ -4823,14 +4841,11 @@ out:/* * 'trusted' attributes support */ - -#define XATTR_TRUSTED_PREFIX "trusted." -static size_t ocfs2_xattr_trusted_list (struct inode *inode,char *list,size_t list_size,const char *name,size_t name_len) { -const size_t prefix_len =sizeof (XATTR_TRUSTED_PREFIX ) -1 ; +const size_t prefix_len =XATTR_TRUSTED_PREFIX_LEN ;const size_t total_len = prefix_len + name_len +1 ;if (list && total_len <= list_size) {
@@ -4867,18 +4882,14 @@ struct xattr_handler ocfs2_xattr_trusted_handler = { .set = ocfs2_xattr_trusted_set, }; -/* * 'user' attributes support */ - -#define XATTR_USER_PREFIX "user." -static size_t ocfs2_xattr_user_list (struct inode *inode,char *list,size_t list_size,const char *name,size_t name_len) { -const size_t prefix_len =sizeof (XATTR_USER_PREFIX ) -1 ; +const size_t prefix_len =XATTR_USER_PREFIX_LEN ;const size_t total_len = prefix_len + name_len +1 ;struct ocfs2_super *osb =OCFS2_SB (inode->i_sb);
fs/ocfs2/xattr.h +4 -22
@@ -40,29 +40,11 @@ enum ocfs2_xattr_type {extern struct xattr_handler ocfs2_xattr_user_handler;extern struct xattr_handler ocfs2_xattr_trusted_handler; - -extern ssize_t ocfs2_listxattr (struct dentry *,char *,size_t ); -extern int ocfs2_xattr_get (struct inode *,int ,const char *,void *,size_t ); -extern int ocfs2_xattr_set (struct inode *,int ,const char *,const void *, -size_t ,int ); -extern int ocfs2_xattr_remove (struct inode *inode,struct buffer_head *di_bh);extern struct xattr_handler *ocfs2_xattr_handlers[]; -static inline u16 ocfs2_xattr_buckets_per_cluster (struct ocfs2_super *osb) -{ -return (1 << osb->s_clustersize_bits) /OCFS2_XATTR_BUCKET_SIZE ; -} - -static inline u16 ocfs2_blocks_per_xattr_bucket (struct super_block *sb) -{ -return OCFS2_XATTR_BUCKET_SIZE / (1 << sb->s_blocksize_bits); -} - -static inline u16 ocfs2_xattr_max_xe_in_bucket (struct super_block *sb) -{ -u16 len = sb->s_blocksize - - offsetof(struct ocfs2_xattr_header , xh_entries); +ssize_t ocfs2_listxattr (struct dentry *,char *,size_t ); +int ocfs2_xattr_set (struct inode *,int ,const char *,const void *, +size_t ,int ); +int ocfs2_xattr_remove (struct inode *,struct buffer_head *); -return len /sizeof (struct ocfs2_xattr_entry ); -}#endif /* OCFS2_XATTR_H */
Signature · 1 line
1.5.4.1
PATCH 2/3 ocfs2/xattr: Add security xattr support in ocfs2
In reply to Tiger YangThis patch add security extended attributes support in ocfs2.
--- fs/ocfs2/namei.c | 6 ++ fs/ocfs2/xattr.c | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/xattr.h | 5 ++ 3 files changed, 153 insertions(+), 0 deletions(-)
fs/ocfs2/namei.c +6 -0
@@ -300,6 +300,12 @@ static int ocfs2_mknod(struct inode *dir,inc_nlink (dir); } + status =ocfs2_init_security (handle, inode, dir, new_fe_bh); +if (status <0 ) { +mlog_errno (status); + goto leave; + } + status =ocfs2_add_entry (handle, dentry, inode,OCFS2_I (inode)->ip_blkno, parent_fe_bh, de_bh);
fs/ocfs2/xattr.c +142 -0
172 lines not on this page · raw message
fs/ocfs2/xattr.h +5 -0
@@ -40,11 +40,16 @@ enum ocfs2_xattr_type {extern struct xattr_handler ocfs2_xattr_user_handler;extern struct xattr_handler ocfs2_xattr_trusted_handler; +extern struct xattr_handler ocfs2_xattr_security_handler;extern struct xattr_handler *ocfs2_xattr_handlers[];ssize_t ocfs2_listxattr (struct dentry *,char *,size_t );int ocfs2_xattr_set (struct inode *,int ,const char *,const void *,size_t ,int ); +int ocfs2_xattr_set_handle (handle_t *,struct inode *,struct buffer_head *, +int ,const char *,const void *,size_t ,int );int ocfs2_xattr_remove (struct inode *,struct buffer_head *); +int ocfs2_init_security (handle_t *,struct inode *, +struct inode *,struct buffer_head *);#endif /* OCFS2_XATTR_H */
Signature · 1 line
1.5.4.1
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
In reply to Tiger YangThis patch add POSIX access control list in ocfs2.
--- Documentation/filesystems/ocfs2.txt | 4 +- fs/Kconfig | 9 + fs/ocfs2/Makefile | 1 + fs/ocfs2/acl.c | 528 +++++++++++++++++++++++++++++++++++ fs/ocfs2/acl.h | 65 +++++ fs/ocfs2/file.c | 10 +- fs/ocfs2/namei.c | 7 + fs/ocfs2/ocfs2.h | 1 + fs/ocfs2/super.c | 33 +++ fs/ocfs2/xattr.c | 50 +++- fs/ocfs2/xattr.h | 10 +- 11 files changed, 701 insertions(+), 17 deletions(-) create mode 100644 fs/ocfs2/acl.c create mode 100644 fs/ocfs2/acl.h
Documentation/filesystems/ocfs2.txt +2 -2
@@ -28,13 +28,11 @@ Manish Singh <[email protected]> Caveats ======= Features which OCFS2 does not support yet: - - extended attributes - quotas - cluster aware flock - cluster aware lockf - Directory change notification (F_NOTIFY) - Distributed Caching (F_SETLEASE/F_GETLEASE/break_lease) - - POSIX ACLs Mount options =============
@@ -82,3 +80,5 @@ inode64 Indicates that Ocfs2 is allowed to create inodes at bits of significance. user_xattr (*) Enables Extended User Attributes. nouser_xattr Disables Extended User Attributes. +acl Enables POSIX Access Control Lists support. +noacl (*) Disables POSIX Access Control Lists support.
fs/Kconfig +9 -0
@@ -507,6 +507,15 @@ config OCFS2_COMPAT_JBD is backwards compatible with JBD. It is safe to say N here. However, if you really want to use the original JBD, say Y here. +config OCFS2_FS_POSIX_ACL + bool "OCFS2 POSIX Access Control Lists" + depends on OCFS2_FS + select FS_POSIX_ACL + default n + help + Posix Access Control Lists (ACLs) support permissions for users and + groups beyond the owner/group/world scheme. + endif # BLOCK config DNOTIFY
fs/ocfs2/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_OCFS2_FS) += \ obj-$(CONFIG_OCFS2_FS_O2CB) += ocfs2_stack_o2cb.o obj-$(CONFIG_OCFS2_FS_USERSPACE_CLUSTER) += ocfs2_stack_user.o +obj-$(CONFIG_OCFS2_FS_POSIX_ACL) += acl.o ocfs2-objs := \ alloc.o \
fs/ocfs2/acl.c new file +528 -0
528 lines not on this page · raw message
fs/ocfs2/acl.h new file +65 -0
65 lines not on this page · raw message
fs/ocfs2/file.c +9 -1
@@ -56,6 +56,7 @@#include "suballoc.h" #include "super.h" #include "xattr.h" +#include "acl.h" #include "buffer_head_io.h"
@@ -976,6 +977,13 @@ int ocfs2_setattr(struct dentry *dentry, struct iattr *attr) goto bail_commit; } +if (attr->ia_valid &ATTR_MODE ) { + status =ocfs2_acl_chmod (handle, inode, bh); +if (status <0 ) +mlog_errno (status); + goto bail_commit; + } + status =ocfs2_mark_inode_dirty (handle, inode, bh);if (status <0 )mlog_errno (status);
@@ -1036,7 +1044,7 @@ int ocfs2_permission(struct inode *inode, int mask) goto out; } - ret =generic_permission (inode, mask,NULL ); + ret =generic_permission (inode, mask, ocfs2_check_acl);ocfs2_inode_unlock (inode,0 ); out:
fs/ocfs2/namei.c +7 -0
@@ -61,6 +61,7 @@#include "sysfile.h" #include "uptodate.h" #include "xattr.h" +#include "acl.h" #include "buffer_head_io.h"
@@ -300,6 +301,12 @@ static int ocfs2_mknod(struct inode *dir,inc_nlink (dir); } + status =ocfs2_init_acl (handle, inode, dir, new_fe_bh, parent_fe_bh); +if (status <0 ) { +mlog_errno (status); + goto leave; + } + status =ocfs2_init_security (handle, inode, dir, new_fe_bh);if (status <0 ) {mlog_errno (status);
fs/ocfs2/ocfs2.h +1 -0
@@ -195,6 +195,7 @@ enum ocfs2_mount_optionsOCFS2_MOUNT_LOCALFLOCKS =1 <<5 ,/* No cluster aware user file locks */ OCFS2_MOUNT_NOUSERXATTR =1 <<6 ,/* No user xattr */ OCFS2_MOUNT_INODE64 =1 <<7 ,/* Allow inode numbers > 2^32 */ + OCFS2_MOUNT_POSIX_ACL = 1 << 8, /* POSIX access control lists */ };#define OCFS2_OSB_SOFT_RO 0x0001
fs/ocfs2/super.c +33 -0
@@ -158,6 +158,8 @@ enum { Opt_user_xattr, Opt_nouser_xattr, Opt_inode64, + Opt_acl, + Opt_noacl, Opt_err, };
@@ -180,6 +182,8 @@ static match_table_t tokens = { {Opt_user_xattr, "user_xattr"}, {Opt_nouser_xattr, "nouser_xattr"}, {Opt_inode64, "inode64"}, + {Opt_acl, "acl"}, + {Opt_noacl, "noacl"}, {Opt_err, NULL} };
@@ -466,6 +470,8 @@ unlock_osb:if (!ret) {/* Only save off the new mount options in case of a successful * remount. */ +if (!(osb->s_feature_incompat &OCFS2_FEATURE_INCOMPAT_XATTR )) + parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL ; osb->s_mount_opt = parsed_options.mount_opt; osb->s_atime_quantum = parsed_options.atime_quantum; osb->preferred_slot = parsed_options.slot;
@@ -651,6 +657,10 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) }brelse (bh); bh =NULL ; + +if (!(osb->s_feature_incompat &OCFS2_FEATURE_INCOMPAT_XATTR )) + parsed_options.mount_opt &= ~OCFS2_MOUNT_POSIX_ACL ; + osb->s_mount_opt = parsed_options.mount_opt; osb->s_atime_quantum = parsed_options.atime_quantum; osb->preferred_slot = parsed_options.slot;
@@ -664,6 +674,9 @@ static int ocfs2_fill_super(struct super_block *sb, void *data, int silent) sb->s_magic =OCFS2_SUPER_MAGIC ; + sb->s_flags = (sb->s_flags & ~MS_POSIXACL ) | + ((osb->s_mount_opt &OCFS2_MOUNT_POSIX_ACL ) ?MS_POSIXACL :0 ); +/* Hard readonly mode only if: bdev_read_only, MS_RDONLY, * heartbeat=none */ if (bdev_read_only (sb->s_bdev)) {
@@ -945,6 +958,19 @@ static int ocfs2_parse_options(struct super_block *sb,case Opt_inode64: mopt->mount_opt |=OCFS2_MOUNT_INODE64 ;break ; +#ifdef CONFIG_OCFS2_FS_POSIX_ACL +case Opt_acl: + mopt->mount_opt |=OCFS2_MOUNT_POSIX_ACL ; +break ; +case Opt_noacl: + mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL ; +break ; +#else +case Opt_acl: +case Opt_noacl: +printk (KERN_INFO "ocfs2 (no)acl options not supported\n" ); +break ; +#endif default :mlog (ML_ERROR , "Unrecognized mount option \"%s\" "
@@ -1017,6 +1043,13 @@ static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)if (opts &OCFS2_MOUNT_INODE64 )seq_printf (s,",inode64" ); +#ifdef CONFIG_OCFS2_FS_POSIX_ACL +if (opts &OCFS2_MOUNT_POSIX_ACL ) +seq_printf (s,",acl" ); +else +seq_printf (s,",noacl" ); +#endif +return 0 ; }
fs/ocfs2/xattr.c +38 -12
86 lines not on this page · raw message
fs/ocfs2/xattr.h +8 -2
@@ -41,15 +41,21 @@ enum ocfs2_xattr_type {extern struct xattr_handler ocfs2_xattr_user_handler;extern struct xattr_handler ocfs2_xattr_trusted_handler;extern struct xattr_handler ocfs2_xattr_security_handler; +#ifdef CONFIG_OCFS2_FS_POSIX_ACL +extern struct xattr_handler ocfs2_xattr_acl_access_handler; +extern struct xattr_handler ocfs2_xattr_acl_default_handler; +#endif extern struct xattr_handler *ocfs2_xattr_handlers[];ssize_t ocfs2_listxattr (struct dentry *,char *,size_t ); +int ocfs2_xattr_get_nolock (struct inode *,struct buffer_head *,int , +const char *,void *,size_t );int ocfs2_xattr_set (struct inode *,int ,const char *,const void *,size_t ,int );int ocfs2_xattr_set_handle (handle_t *,struct inode *,struct buffer_head *,int ,const char *,const void *,size_t ,int );int ocfs2_xattr_remove (struct inode *,struct buffer_head *); -int ocfs2_init_security (handle_t *,struct inode *, -struct inode *,struct buffer_head *); +int ocfs2_init_security (handle_t *,struct inode *,struct inode *, +struct buffer_head *);#endif /* OCFS2_XATTR_H */
Signature · 1 line
1.5.4.1
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
Documentation/filesystems/ocfs2.txt Manish Singh <[email protected]> · line 33
Quoted 12 lines · Tiger Yang
Documentation/filesystems/ocfs2.txt +0
-1@@ -28,13 +28,11 @@ Manish Singh <[email protected]> Caveats ======= Features which OCFS2 does not support yet: - - extended attributes - quotas - cluster aware flock - cluster aware lockf
These two (flock/lockf) are now supported thanks to Mark.
Quoted 3 lines
Documentation/filesystems/ocfs2.txt +0
-1- Directory change notification (F_NOTIFY) - Distributed Caching (F_SETLEASE/F_GETLEASE/break_lease) - - POSIX ACLs
...
Quoted 6 lines
fs/ocfs2/acl.c new file +0
-0
fs/ocfs2/acl.c line 9
Quoted 9 lines
fs/ocfs2/acl.c new file +9
-0@@ -0,0 +1,528 @@ +/* -*- mode: c; c-basic-offset: 8; -*- +* vim: noexpandtab sw=8 ts=8 sts=0: +* +* acl.c +* +* Copyright (C) 2008 Oracle. All rights reserved. +* +* CREDITS: +* Lots of code in this file is taken from ext3.
You should mention the copyright on that ext3 code:
* Copyright (C) 2001-2003 Andreas Gruenbacher, <[email protected]>
It's his code you are copying, with his copyright.
fs/ocfs2/acl.c line 14
Quoted 5 lines
fs/ocfs2/acl.c new file +5
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public +* License as published by the Free Software Foundation; either +* version 2 of the License, or (at your option) any later version.
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
fs/ocfs2/acl.c line 24
Quoted 10 lines
fs/ocfs2/acl.c new file +10
-0+* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +* You should have received a copy of the GNU General Public +* License along with this program; if not, write to the +* Free Software Foundation, Inc., 59 Temple Place - Suite 330, +* Boston, MA 021110-1307, USA.
Leave out the last paragraph. They've moved, and they recommend
leaving out the address.
Joel
Signature · 9 lines
"The real reason GNU ls is 8-bit-clean is so that they can start using ISO-8859-1 option characters." - Christopher Davis (ckd at loiosh.kei.com) Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
Joel Becker Wrote:
Quoted 28 lines · Tiger Yang
Quoted 9 lines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.Quoted 11 lines
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
Quoted 3 lines
Leave out the last paragraph. They've moved, and they recommend
leaving out the address.
hi tiger, you can use this new license.
http://kernel.us.oracle.com/~smushran/license.txt
Regards,
Tao
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
Quoted 2 lines · Tao Ma
hi tiger, you can use this new license.
http://kernel.us.oracle.com/~smushran/license.txt
Can you fix the license in xattr.c too? And the copyrights from
there should go in your CREDITS section if you really did copy code.
Joel
Signature · 10 lines
"It is not the function of our government to keep the citizen from falling into error; it is the function of the citizen to keep the government from falling into error." - Robert H. Jackson Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
Yes. I can and I already did in the first patch of my v3 patches of acl.
fs/ocfs2/xattr.c +4 -9
@@ -3,25 +3,20 @@* * xattr.c * -* Copyright (C) 2008 Oracle. All rights reserved. +* Copyright (C) 2004, 2008 Oracle. All rights reserved. * * CREDITS: -* Lots of code in this file is taken from ext3. +* Lots of code in this file is copy from linux/fs/ext3/xattr.c. +* Copyright (C) 2001-2003 Andreas Gruenbacher, <[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public -* License as published by the Free Software Foundation; either -* version 2 of the License, or (at your option) any later version. +* License version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. -* -* You should have received a copy of the GNU General Public -* License along with this program; if not, write to the -* Free Software Foundation, Inc., 59 Temple Place - Suite 330, -* Boston, MA 021110-1307, USA. */
is this ok?
regards,
tiger
Quoted 9 lines · Joel Becker
Quoted 2 lines · Tao Ma
hi tiger, you can use this new license.
http://kernel.us.oracle.com/~smushran/license.txtCan you fix the license in
xattr.ctoo? And the copyrights from
there should go in your CREDITS section if you really did copy code.Joel
PATCH 3/3 ocfs2/xattr: Add POSIX ACLs support in ocfs2
In reply to Tiger Yanga bug fix.
thanks,
tiger
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fix.patch
Type: text/x-patch
Size: 440 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/ocfs2-devel/attachments/20081016/3bc73233/attachment.bin