fcntl: rename F_OWNER_GID to F_OWNER_PGRP
[safe/jmp/linux-2.6] / fs / gfs2 / acl.c
index 9ef4cf2..3fc4e3a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License v.2.
+ * of the GNU General Public License version 2.
  */
 
 #include <linux/sched.h>
 #include <linux/gfs2_ondisk.h>
 
 #include "gfs2.h"
-#include "lm_interface.h"
 #include "incore.h"
 #include "acl.h"
-#include "eaops.h"
-#include "eattr.h"
+#include "xattr.h"
 #include "glock.h"
 #include "inode.h"
 #include "meta_io.h"
@@ -32,8 +30,7 @@
 #define ACL_DEFAULT 0
 
 int gfs2_acl_validate_set(struct gfs2_inode *ip, int access,
-                     struct gfs2_ea_request *er,
-                     int *remove, mode_t *mode)
+                         struct gfs2_ea_request *er, int *remove, mode_t *mode)
 {
        struct posix_acl *acl;
        int error;
@@ -65,9 +62,8 @@ int gfs2_acl_validate_set(struct gfs2_inode *ip, int access,
                        error = 0;
        }
 
- out:
+out:
        posix_acl_release(acl);
-
        return error;
 }
 
@@ -75,40 +71,30 @@ int gfs2_acl_validate_remove(struct gfs2_inode *ip, int access)
 {
        if (!GFS2_SB(&ip->i_inode)->sd_args.ar_posix_acl)
                return -EOPNOTSUPP;
-       if (current->fsuid != ip->i_di.di_uid && !capable(CAP_FOWNER))
+       if (!is_owner_or_cap(&ip->i_inode))
                return -EPERM;
-       if (S_ISLNK(ip->i_di.di_mode))
+       if (S_ISLNK(ip->i_inode.i_mode))
                return -EOPNOTSUPP;
-       if (!access && !S_ISDIR(ip->i_di.di_mode))
+       if (!access && !S_ISDIR(ip->i_inode.i_mode))
                return -EACCES;
 
        return 0;
 }
 
-static int acl_get(struct gfs2_inode *ip, int access, struct posix_acl **acl,
-                  struct gfs2_ea_location *el, char **data, unsigned int *len)
+static int acl_get(struct gfs2_inode *ip, const char *name,
+                  struct posix_acl **acl, struct gfs2_ea_location *el,
+                  char **datap, unsigned int *lenp)
 {
-       struct gfs2_ea_request er;
-       struct gfs2_ea_location el_this;
+       char *data;
+       unsigned int len;
        int error;
 
-       if (!ip->i_di.di_eattr)
-               return 0;
-
-       memset(&er, 0, sizeof(struct gfs2_ea_request));
-       if (access) {
-               er.er_name = GFS2_POSIX_ACL_ACCESS;
-               er.er_name_len = GFS2_POSIX_ACL_ACCESS_LEN;
-       } else {
-               er.er_name = GFS2_POSIX_ACL_DEFAULT;
-               er.er_name_len = GFS2_POSIX_ACL_DEFAULT_LEN;
-       }
-       er.er_type = GFS2_EATYPE_SYS;
+       el->el_bh = NULL;
 
-       if (!el)
-               el = &el_this;
+       if (!ip->i_eattr)
+               return 0;
 
-       error = gfs2_ea_find(ip, &er, el);
+       error = gfs2_ea_find(ip, GFS2_EATYPE_SYS, name, el);
        if (error)
                return error;
        if (!el->el_ea)
@@ -116,51 +102,50 @@ static int acl_get(struct gfs2_inode *ip, int access, struct posix_acl **acl,
        if (!GFS2_EA_DATA_LEN(el->el_ea))
                goto out;
 
-       er.er_data_len = GFS2_EA_DATA_LEN(el->el_ea);
-       er.er_data = kmalloc(er.er_data_len, GFP_KERNEL);
+       len = GFS2_EA_DATA_LEN(el->el_ea);
+       data = kmalloc(len, GFP_NOFS);
        error = -ENOMEM;
-       if (!er.er_data)
+       if (!data)
                goto out;
 
-       error = gfs2_ea_get_copy(ip, el, er.er_data);
-       if (error)
+       error = gfs2_ea_get_copy(ip, el, data, len);
+       if (error < 0)
                goto out_kfree;
+       error = 0;
 
        if (acl) {
-               *acl = posix_acl_from_xattr(er.er_data, er.er_data_len);
+               *acl = posix_acl_from_xattr(data, len);
                if (IS_ERR(*acl))
                        error = PTR_ERR(*acl);
        }
 
- out_kfree:
-       if (error || !data)
-               kfree(er.er_data);
-       else {
-               *data = er.er_data;
-               *len = er.er_data_len;
+out_kfree:
+       if (error || !datap) {
+               kfree(data);
+       else {
+               *datap = data;
+               *lenp = len;
        }
-
- out:
-       if (error || el == &el_this)
-               brelse(el->el_bh);
-
+out:
        return error;
 }
 
 /**
- * gfs2_check_acl_locked - Check an ACL to see if we're allowed to do something
+ * gfs2_check_acl - Check an ACL to see if we're allowed to do something
  * @inode: the file we want to do something to
  * @mask: what we want to do
  *
  * Returns: errno
  */
 
-int gfs2_check_acl_locked(struct inode *inode, int mask)
+int gfs2_check_acl(struct inode *inode, int mask)
 {
+       struct gfs2_ea_location el;
        struct posix_acl *acl = NULL;
        int error;
 
-       error = acl_get(GFS2_I(inode), ACL_ACCESS, &acl, NULL, NULL, NULL);
+       error = acl_get(GFS2_I(inode), GFS2_POSIX_ACL_ACCESS, &acl, &el, NULL, NULL);
+       brelse(el.el_bh);
        if (error)
                return error;
 
@@ -173,23 +158,6 @@ int gfs2_check_acl_locked(struct inode *inode, int mask)
        return -EAGAIN;
 }
 
-int gfs2_check_acl(struct inode *inode, int mask)
-{
-       struct gfs2_inode *ip = GFS2_I(inode);
-       struct gfs2_holder i_gh;
-       int error;
-
-       error = gfs2_glock_nq_init(ip->i_gl,
-                                  LM_ST_SHARED, LM_FLAG_ANY,
-                                  &i_gh);
-       if (!error) {
-               error = gfs2_check_acl_locked(inode, mask);
-               gfs2_glock_dq_uninit(&i_gh);
-       }
-       
-       return error;
-}
-
 static int munge_mode(struct gfs2_inode *ip, mode_t mode)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
@@ -203,10 +171,10 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode)
        error = gfs2_meta_inode_buffer(ip, &dibh);
        if (!error) {
                gfs2_assert_withdraw(sdp,
-                               (ip->i_di.di_mode & S_IFMT) == (mode & S_IFMT));
-               ip->i_di.di_mode = mode;
+                               (ip->i_inode.i_mode & S_IFMT) == (mode & S_IFMT));
+               ip->i_inode.i_mode = mode;
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
-               gfs2_dinode_out(&ip->i_di, dibh->b_data);
+               gfs2_dinode_out(ip, dibh->b_data);
                brelse(dibh);
        }
 
@@ -217,42 +185,40 @@ static int munge_mode(struct gfs2_inode *ip, mode_t mode)
 
 int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip)
 {
+       struct gfs2_ea_location el;
        struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
        struct posix_acl *acl = NULL, *clone;
-       struct gfs2_ea_request er;
-       mode_t mode = ip->i_di.di_mode;
+       mode_t mode = ip->i_inode.i_mode;
+       char *data = NULL;
+       unsigned int len;
        int error;
 
        if (!sdp->sd_args.ar_posix_acl)
                return 0;
-       if (S_ISLNK(ip->i_di.di_mode))
+       if (S_ISLNK(ip->i_inode.i_mode))
                return 0;
 
-       memset(&er, 0, sizeof(struct gfs2_ea_request));
-       er.er_type = GFS2_EATYPE_SYS;
-
-       error = acl_get(dip, ACL_DEFAULT, &acl, NULL,
-                       &er.er_data, &er.er_data_len);
+       error = acl_get(dip, GFS2_POSIX_ACL_DEFAULT, &acl, &el, &data, &len);
+       brelse(el.el_bh);
        if (error)
                return error;
        if (!acl) {
-               mode &= ~current->fs->umask;
-               if (mode != ip->i_di.di_mode)
+               mode &= ~current_umask();
+               if (mode != ip->i_inode.i_mode)
                        error = munge_mode(ip, mode);
                return error;
        }
 
-       clone = posix_acl_clone(acl, GFP_KERNEL);
+       clone = posix_acl_clone(acl, GFP_NOFS);
        error = -ENOMEM;
        if (!clone)
                goto out;
        posix_acl_release(acl);
        acl = clone;
 
-       if (S_ISDIR(ip->i_di.di_mode)) {
-               er.er_name = GFS2_POSIX_ACL_DEFAULT;
-               er.er_name_len = GFS2_POSIX_ACL_DEFAULT_LEN;
-               error = gfs2_system_eaops.eo_set(ip, &er);
+       if (S_ISDIR(ip->i_inode.i_mode)) {
+               error = gfs2_xattr_set(&ip->i_inode, GFS2_EATYPE_SYS,
+                                      GFS2_POSIX_ACL_DEFAULT, data, len, 0);
                if (error)
                        goto out;
        }
@@ -260,21 +226,19 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct gfs2_inode *ip)
        error = posix_acl_create_masq(acl, &mode);
        if (error < 0)
                goto out;
-       if (error > 0) {
-               er.er_name = GFS2_POSIX_ACL_ACCESS;
-               er.er_name_len = GFS2_POSIX_ACL_ACCESS_LEN;
-               posix_acl_to_xattr(acl, er.er_data, er.er_data_len);
-               er.er_mode = mode;
-               er.er_flags = GFS2_ERF_MODE;
-               error = gfs2_system_eaops.eo_set(ip, &er);
-               if (error)
-                       goto out;
-       } else
-               munge_mode(ip, mode);
+       if (error == 0)
+               goto munge;
 
- out:
+       posix_acl_to_xattr(acl, data, len);
+       error = gfs2_xattr_set(&ip->i_inode, GFS2_EATYPE_SYS,
+                              GFS2_POSIX_ACL_ACCESS, data, len, 0);
+       if (error)
+               goto out;
+munge:
+       error = munge_mode(ip, mode);
+out:
        posix_acl_release(acl);
-       kfree(er.er_data);
+       kfree(data);
        return error;
 }
 
@@ -286,13 +250,13 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
        unsigned int len;
        int error;
 
-       error = acl_get(ip, ACL_ACCESS, &acl, &el, &data, &len);
+       error = acl_get(ip, GFS2_POSIX_ACL_ACCESS, &acl, &el, &data, &len);
        if (error)
-               return error;
+               goto out_brelse;
        if (!acl)
                return gfs2_setattr_simple(ip, attr);
 
-       clone = posix_acl_clone(acl, GFP_KERNEL);
+       clone = posix_acl_clone(acl, GFP_NOFS);
        error = -ENOMEM;
        if (!clone)
                goto out;
@@ -305,11 +269,11 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
                error = gfs2_ea_acl_chmod(ip, &el, attr, data);
        }
 
- out:
+out:
        posix_acl_release(acl);
-       brelse(el.el_bh);
        kfree(data);
-
+out_brelse:
+       brelse(el.el_bh);
        return error;
 }