Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 11 Aug 2008 23:35:56 GMT
From:      Edward Tomasz Napierala <trasz@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 147191 for review
Message-ID:  <200808112335.m7BNZumY099610@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=147191

Change 147191 by trasz@trasz_traszkan on 2008/08/11 23:35:24

	Centralize ACL allocation and freeing.

Affected files ...

.. //depot/projects/soc2008/trasz_nfs4acl/sys/kern/subr_acl_nfs4.c#21 edit
.. //depot/projects/soc2008/trasz_nfs4acl/sys/kern/vfs_acl.c#10 edit
.. //depot/projects/soc2008/trasz_nfs4acl/sys/sys/acl.h#19 edit
.. //depot/projects/soc2008/trasz_nfs4acl/sys/ufs/ufs/ufs_vnops.c#12 edit

Differences ...

==== //depot/projects/soc2008/trasz_nfs4acl/sys/kern/subr_acl_nfs4.c#21 (text+ko) ====

@@ -331,9 +331,6 @@
 	    *a1, *a2, *a3, *a4, *a5, *a6;
 	mode_t amode;
 
-	/* XXX: Move it somewhere. */
-	aclp->acl_magic = ACL_MAGIC;
-
 	/*
 	 * NFSv4 Minor Version 1, draft-ietf-nfsv4-minorversion1-03.txt
 	 *

==== //depot/projects/soc2008/trasz_nfs4acl/sys/kern/vfs_acl.c#10 (text+ko) ====

@@ -76,7 +76,6 @@
 	
 	bzero(dest, sizeof(*dest));
 
-	dest->acl_magic = ACL_MAGIC;
 	dest->acl_cnt = source->acl_cnt;
 
 	for (i = 0; i < dest->acl_cnt; i++) {
@@ -202,7 +201,7 @@
 	struct mount *mp;
 	int error;
 
-	inkernelacl = uma_zalloc(acl_zone, M_WAITOK);
+	inkernelacl = acl_alloc();
 	error = copyin_acl(aclp, inkernelacl, type);
 	if (error != 0)
 		goto out_free;
@@ -235,7 +234,7 @@
 	VOP_UNLOCK(vp, 0);
 	vn_finished_write(mp);
 out_free:
-	uma_zfree(acl_zone, inkernelacl);
+	acl_free(inkernelacl);
 	return(error);
 }
 
@@ -249,7 +248,7 @@
 	struct acl *inkernelacl;
 	int error;
 
-	inkernelacl = uma_zalloc(acl_zone, M_WAITOK);
+	inkernelacl = acl_alloc();
 	VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
 	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
 #ifdef MAC
@@ -268,7 +267,7 @@
 	VOP_UNLOCK(vp, 0);
 	if (error == 0)
 		error = copyout_acl(inkernelacl, aclp, type);
-	uma_zfree(acl_zone, inkernelacl);
+	acl_free(inkernelacl);
 	return (error);
 }
 
@@ -310,7 +309,7 @@
 	struct acl *inkernelacl;
 	int error;
 
-	inkernelacl = uma_zalloc(acl_zone, M_WAITOK);
+	inkernelacl = acl_alloc();
 	error = copyin_acl(aclp, inkernelacl, type);
 	if (error != 0)
 		goto out_free;
@@ -329,7 +328,7 @@
 	error = VOP_ACLCHECK(vp, type_unold(type), inkernelacl,
 	    td->td_ucred, td);
 out_free:
-	uma_zfree(acl_zone, inkernelacl);
+	acl_free(inkernelacl);
 	return (error);
 }
 
@@ -574,6 +573,43 @@
 	return (error);
 }
 
+/*
+ * Allocate "struct acl" instance.
+ */
+struct acl *
+acl_alloc(void)
+{
+	struct acl *aclp;
+
+	aclp = uma_zalloc(acl_zone, M_WAITOK | M_ZERO);
+	aclp->acl_magic = ACL_MAGIC;
+	aclp->acl_length = ACL_MAX_ENTRIES;
+	aclp->acl_cnt = 0;
+
+	return (aclp);
+}
+
+/*
+ * Free "struct acl".
+ */
+void
+acl_free(struct acl *aclp)
+{
+	uma_zfree(acl_zone, aclp);
+}
+
+/*
+ * Return the size, in bytes, required to store ACL with "cnt" entries.
+ */
+int
+acl_size_for_cnt(int cnt)
+{
+	int size = sizeof(struct acl) - (ACL_MAX_ENTRIES - cnt) *
+		sizeof(struct acl_entry);
+
+	return size;
+}
+
 /* ARGUSED */
 
 static void

==== //depot/projects/soc2008/trasz_nfs4acl/sys/sys/acl.h#19 (text+ko) ====

@@ -238,11 +238,6 @@
 #define ACL_TEXT_NUMERIC_IDS	0x02
 #define ACL_TEXT_APPEND_ID	0x04
 
-#ifdef _KERNEL
-
-extern uma_zone_t	acl_zone;
-
-#endif
 /*
  * POSIX.1e ACLs are capable of expressing the read, write, and execute bits
  * of the POSIX mode field.  We provide two masks: one that defines the bits
@@ -282,6 +277,9 @@
 int			acl_posix1e_check(struct acl *acl);
 int 			acl_nfs4_check(const struct acl *aclp, int is_directory);
 
+struct acl		*acl_alloc(void);
+void			acl_free(struct acl *aclp);
+int			acl_size_for_cnt(int cnt);
 #else /* !_KERNEL */
 
 /*

==== //depot/projects/soc2008/trasz_nfs4acl/sys/ufs/ufs/ufs_vnops.c#12 (text+ko) ====

@@ -344,7 +344,7 @@
 		else
 			type = ACL_TYPE_ACCESS;
 
-		acl = uma_zalloc(acl_zone, M_WAITOK);
+		acl = acl_alloc();
 		error = VOP_GETACL(vp, type, acl, ap->a_cred,
 		    ap->a_td);
 		switch (error) {
@@ -373,7 +373,7 @@
 			error = vaccess(vp->v_type, ip->i_mode, ip->i_uid,
 			    ip->i_gid, ap->a_mode, ap->a_cred, NULL);
 		}
-		uma_zfree(acl_zone, acl);
+		acl_free(acl);
 	} else
 #endif /* !UFS_ACL */
 		error = vaccess(vp->v_type, ip->i_mode, ip->i_uid, ip->i_gid,
@@ -659,7 +659,7 @@
 	int error;
 	struct acl *aclp;
 
-	aclp = uma_zalloc(acl_zone, M_WAITOK);
+	aclp = acl_alloc();
 
 	error = VOP_GETACL(vp, ACL_TYPE_NFS4, aclp, cred, td);
 	/*
@@ -676,7 +676,7 @@
 	error = VOP_SETACL(vp, ACL_TYPE_NFS4, aclp, cred, td);
 
 out:
-	uma_zfree(acl_zone, aclp);
+	acl_free(aclp);
 
 	return (error);
 }
@@ -1428,8 +1428,8 @@
 	int error;
 	struct acl *parent_aclp, *child_aclp;
 
-	parent_aclp = uma_zalloc(acl_zone, M_WAITOK);
-	child_aclp = uma_zalloc(acl_zone, M_WAITOK | M_ZERO);
+	parent_aclp = acl_alloc();
+	child_aclp = acl_alloc();
 
 	error = VOP_GETACL(parentvp, ACL_TYPE_NFS4, parent_aclp, cred, td);
 	if (error)
@@ -1445,8 +1445,8 @@
 		goto out;
 
 out:
-	uma_zfree(acl_zone, parent_aclp);
-	uma_zfree(acl_zone, child_aclp);
+	acl_free(parent_aclp);
+	acl_free(child_aclp);
 
 	return (error);
 }
@@ -1564,8 +1564,8 @@
 #ifdef UFS_ACL
 	acl = dacl = NULL;
 	if ((dvp->v_mount->mnt_flag & MNT_ACLS) != 0) {
-		acl = uma_zalloc(acl_zone, M_WAITOK);
-		dacl = uma_zalloc(acl_zone, M_WAITOK);
+		acl = acl_alloc();
+		dacl = acl_alloc();
 
 		/*
 		 * Retrieve default ACL from parent, if any.
@@ -1595,16 +1595,16 @@
 			 */
 			ip->i_mode = dmode;
 			DIP_SET(ip, i_mode, dmode);
-			uma_zfree(acl_zone, acl);
-			uma_zfree(acl_zone, dacl);
+			acl_free(acl);
+			acl_free(dacl);
 			dacl = acl = NULL;
 			break;
 		
 		default:
 			UFS_VFREE(tvp, ip->i_number, dmode);
 			vput(tvp);
-			uma_zfree(acl_zone, acl);
-			uma_zfree(acl_zone, dacl);
+			acl_free(acl);
+			acl_free(dacl);
 			return (error);
 		}
 	} else {
@@ -1674,13 +1674,13 @@
 			break;
 
 		default:
-			uma_zfree(acl_zone, acl);
-			uma_zfree(acl_zone, dacl);
+			acl_free(acl);
+			acl_free(dacl);
 			dacl = acl = NULL;
 			goto bad;
 		}
-		uma_zfree(acl_zone, acl);
-		uma_zfree(acl_zone, dacl);
+		acl_free(acl);
+		acl_free(dacl);
 		dacl = acl = NULL;
 	}
 
@@ -1753,9 +1753,9 @@
 	} else {
 #ifdef UFS_ACL
 		if (acl != NULL)
-			uma_zfree(acl_zone, acl);
+			acl_free(acl);
 		if (dacl != NULL)
-			uma_zfree(acl_zone, dacl);
+			acl_free(dacl);
 #endif
 		dp->i_effnlink--;
 		dp->i_nlink--;
@@ -2401,7 +2401,7 @@
 #ifdef UFS_ACL
 	acl = NULL;
 	if ((dvp->v_mount->mnt_flag & MNT_ACLS) != 0) {
-		acl = uma_zalloc(acl_zone, M_WAITOK);
+		acl = acl_alloc();
 
 		/*
 		 * Retrieve default ACL for parent, if any.
@@ -2436,14 +2436,14 @@
 			 */
 			ip->i_mode = mode;
 			DIP_SET(ip, i_mode, mode);
-			uma_zfree(acl_zone, acl);
+			acl_free(acl);
 			acl = NULL;
 			break;
 	
 		default:
 			UFS_VFREE(tvp, ip->i_number, mode);
 			vput(tvp);
-			uma_zfree(acl_zone, acl);
+			acl_free(acl);
 			acl = NULL;
 			return (error);
 		}
@@ -2509,10 +2509,10 @@
 			break;
 
 		default:
-			uma_zfree(acl_zone, acl);
+			acl_free(acl);
 			goto bad;
 		}
-		uma_zfree(acl_zone, acl);
+		acl_free(acl);
 	}
 
 	if (dvp->v_mount->mnt_flag & MNT_NFS4ACLS) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200808112335.m7BNZumY099610>