socsvn commit: r238269 - in soc2012/gpf/pefs_kmod/sys: fs/pefs modules/pefs

gpf at FreeBSD.org gpf at FreeBSD.org
Mon Jun 25 14:53:21 UTC 2012


Author: gpf
Date: Mon Jun 25 14:53:18 2012
New Revision: 238269
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238269

Log:
  - move checksum code in checksum.c and a few minor changes
  

Modified:
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_subr.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vnops.c
  soc2012/gpf/pefs_kmod/sys/modules/pefs/Makefile

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h	Mon Jun 25 12:30:51 2012	(r238268)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h	Mon Jun 25 14:53:18 2012	(r238269)
@@ -118,28 +118,6 @@
 	char			ptk_tweak[PEFS_TWEAK_SIZE];
 };
 
-/* XXXgpf: fill this in */
-#define PEFS_FILE_CHECKSUM		".pefs.checksum"
-#define PEFS_CFH_SIZE 16
-#define PEFS_HT_CELL_SIZE 16
-
-struct pefs_checksum_index_entry {
-	uint32_t pcie_nhashes;
-	uint32_t pcie_offset;
-	uint64_t pcie_file_id;
-};
-
-struct pefs_checksum {
-	uint8_t pcs_version;
-	uint8_t pcs_reserved;
-	uint8_t pcs_hash_len;
-	uint8_t pcs_hash_algo[8];
-	uint8_t pcs_offset_to_hash_table;
-	uint32_t pcs_hash_table_size;
-	char *pcs_table1, *pcs_table2;
-	struct vnode *pcs_checksumvp;
-};
-
 #define	PN_HASKEY			0x000001
 #define	PN_WANTRECYCLE			0x000100
 #define	PN_LOCKBUF_SMALL		0x001000
@@ -155,7 +133,7 @@
 	void			*pn_buf_large;
 	int			pn_flags;
 	struct pefs_tkey	pn_tkey;
-	void				*pn_checksum_index_entry;
+	char				*pn_checksum_index_entry;
 };
 
 #define	PM_ROOT_CANRECURSE		0x01
@@ -163,6 +141,17 @@
 #define	PM_ASYNCRECLAIM			0x04
 #define PM_CHECKSUM				0x08
 
+struct pefs_checksum {
+	uint8_t pcs_version;
+	uint8_t pcs_reserved;
+	uint8_t pcs_hash_len;
+	uint8_t pcs_hash_algo[8];
+	uint8_t pcs_offset_to_hash_table;
+	uint32_t pcs_hash_table_size;
+	char *pcs_table1, *pcs_table2;
+	struct vnode *pcs_checksumvp;
+};
+
 struct pefs_mount {
 	struct mount		*pm_lowervfs;
 	struct vnode		*pm_rootvp;

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_subr.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_subr.c	Mon Jun 25 12:30:51 2012	(r238268)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_subr.c	Mon Jun 25 14:53:18 2012	(r238269)
@@ -400,6 +400,7 @@
 		PEFSDEBUG("pefs_node_get: creating node without key: %p\n", pn);
 
 	pn->pn_vnode = vp;
+	pn->pn_checksum_index_entry = NULL;
 	vp->v_type = lvp->v_type;
 	vp->v_data = pn;
 	vp->v_vnlock = lvp->v_vnlock;

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c	Mon Jun 25 12:30:51 2012	(r238268)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c	Mon Jun 25 14:53:18 2012	(r238269)
@@ -47,6 +47,7 @@
 #include <sys/vnode.h>
 
 #include <fs/pefs/pefs.h>
+#include <fs/pefs/pefs_checksum.h>
 
 struct pefs_opt_descr {
 	char	*fs;

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vnops.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vnops.c	Mon Jun 25 12:30:51 2012	(r238268)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vnops.c	Mon Jun 25 14:53:18 2012	(r238269)
@@ -56,8 +56,6 @@
 #include <sys/proc.h>
 #include <sys/sched.h>
 #include <sys/unistd.h>
-#include <sys/endian.h>
-#include <sys/fnv_hash.h>
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_object.h>
@@ -66,6 +64,7 @@
 #include <vm/vnode_pager.h>
 
 #include <fs/pefs/pefs.h>
+#include <fs/pefs/pefs_checksum.h>
 #include <fs/pefs/pefs_dircache.h>
 
 #define	DIRENT_MINSIZE		(sizeof(struct dirent) - (MAXNAMLEN + 1))
@@ -472,101 +471,9 @@
 	return (0);
 }
 
-/*
- * XXXgpf: [TODO] move most, if not all, of the checksum code to a different .c
- */
-static uint32_t
-pefs_checksum_hash1(struct pefs_checksum *pc, struct pefs_checksum_index_entry *pcie)
-{
-	uint32_t nbucket;
-
-	nbucket = pcie->pcie_file_id % pc->pcs_hash_table_size;
-	printf("hash1: goto bucket %d\n", nbucket);
-	return (nbucket);
-}
-
-static uint32_t
-pefs_checksum_hash2(struct pefs_checksum *pc, struct pefs_checksum_index_entry *pcie)
-{
-	uint32_t nbucket;
-
-	nbucket = fnv_64_buf(&(pcie->pcie_file_id), sizeof(pcie->pcie_file_id), FNV1_64_INIT)
-			% pc->pcs_hash_table_size;
-	printf("hash2: goto bucket %d\n", nbucket);
-
-	return (nbucket);
-}
-
-static void
-pefs_checksum_index_lookup(struct pefs_checksum_index_entry *pcie, struct vnode *vp)
-{
-	struct pefs_checksum_index_entry target_pcie;
-	struct pefs_mount *pm = VFS_TO_PEFS(vp->v_mount);
-	struct pefs_checksum *pcs = &(pm->pm_checksum);
-	struct pefs_node *pn = VP_TO_PN(vp);
-	char *start, *p;
-	uint32_t pos;
-
-	pos = pefs_checksum_hash1(pcs, pcie);
-	start = &(pcs->pcs_table1[pos * PEFS_HT_CELL_SIZE]);
-	p = start;
-
-	memcpy(&(target_pcie.pcie_nhashes), p, sizeof(target_pcie.pcie_nhashes));
-	target_pcie.pcie_nhashes = le32toh(target_pcie.pcie_nhashes);
-	if (target_pcie.pcie_nhashes != 0) {
-		p+=sizeof(target_pcie.pcie_nhashes);
-
-		memcpy(&(target_pcie.pcie_offset), p, sizeof(target_pcie.pcie_offset));
-		target_pcie.pcie_offset = le32toh(target_pcie.pcie_offset);
-		p+=sizeof(target_pcie.pcie_offset);
-
-		memcpy(&(target_pcie.pcie_file_id), p, sizeof(target_pcie.pcie_file_id));
-		target_pcie.pcie_file_id = le64toh(target_pcie.pcie_file_id);
-		printf("cell %d:\n", pos);
-		printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
-			target_pcie.pcie_nhashes, target_pcie.pcie_offset, target_pcie.pcie_file_id);
-
-		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
-			pn->pn_checksum_index_entry = start;
-			printf("checksum lookup: found1!\n");
-			return;
-		}
-	}
-
-	pos = pefs_checksum_hash2(pcs, pcie);
-	start = &(pcs->pcs_table2[pos * PEFS_HT_CELL_SIZE]);
-	p = start;
-
-	memcpy(&(target_pcie.pcie_nhashes), p, sizeof(target_pcie.pcie_nhashes));
-	target_pcie.pcie_nhashes = le32toh(target_pcie.pcie_nhashes);
-	if (target_pcie.pcie_nhashes != 0) {
-		p+=sizeof(target_pcie.pcie_nhashes);
-
-		memcpy(&(target_pcie.pcie_offset), p, sizeof(target_pcie.pcie_offset));
-		target_pcie.pcie_offset = le32toh(target_pcie.pcie_offset);
-		p+=sizeof(target_pcie.pcie_offset);
-
-		memcpy(&(target_pcie.pcie_file_id), p, sizeof(target_pcie.pcie_file_id));
-		target_pcie.pcie_file_id = le64toh(target_pcie.pcie_file_id);
-		printf("cell %d:\n", pos);
-		printf("\thashes = %d\n\toffset = %d\n\tfile id = %llu\n",
-			target_pcie.pcie_nhashes, target_pcie.pcie_offset, target_pcie.pcie_file_id);
-
-		if (target_pcie.pcie_file_id == pcie->pcie_file_id) {
-			pn->pn_checksum_index_entry = start;
-			printf("checksum lookup: found2!\n");
-			return;
-		}
-	}
-
-	printf("checksum lookup: not found!\n");
-	pn->pn_checksum_index_entry = NULL;
-}
-
 static int
 pefs_lookup(struct vop_cachedlookup_args *ap)
 {
-	struct pefs_checksum_index_entry pcie;
 	struct componentname *cnp = ap->a_cnp;
 	struct pefs_mount *pm;
 	struct vnode *vp = NULL;
@@ -576,10 +483,8 @@
 	struct pefs_enccn enccn;
 	struct pefs_node *dpn = VP_TO_PN(dvp);
 	uint64_t flags = cnp->cn_flags;
-	char *enc_name, *buf;
 	int nokey_lookup, skip_lookup;
-	int error, r;
-	size_t enc_name_len, buf_len;
+	int error;
 
 	printf("pefs_lookup: op=%lx, name=%.*s\n",
 	    cnp->cn_nameiop, (int)cnp->cn_namelen, cnp->cn_nameptr);
@@ -654,52 +559,19 @@
 			else
 				error = pefs_node_get_haskey(dvp->v_mount, lvp,
 				    &vp, &enccn.pec_tkey);
-
 			if (error != 0) {
 				vput(lvp);
 			} else {
 				pm = VFS_TO_PEFS(vp->v_mount);
-				if ((pm->pm_flags & PM_CHECKSUM) != 0 && cnp->cn_nameiop == LOOKUP &&
-					(vp->v_type == VREG || vp->v_type == VLNK)) {
-					printf("gpf: checksum code @ lookup\n");
+				if ((pm->pm_flags & PM_CHECKSUM) != 0) {
 					if (nokey_lookup) {
 						printf("cnp name=%.*s\n",(int)cnp->cn_namelen, cnp->cn_nameptr);
-						enc_name = cnp->cn_nameptr;
-						enc_name_len = cnp->cn_namelen;
+						pefs_checksum_lookup(cnp->cn_nameptr, cnp->cn_namelen, cnp, vp);
 					}
 					else {
 						printf("enccnp name=%.*s\n",(int)enccn.pec_cn.cn_namelen, enccn.pec_cn.cn_nameptr);
-						enc_name = enccn.pec_cn.cn_nameptr;
-						enc_name_len = enccn.pec_cn.cn_namelen;
+						pefs_checksum_lookup(enccn.pec_cn.cn_nameptr, enccn.pec_cn.cn_namelen, cnp, vp);
 					}
-
-					/* XXXgpf: What if user wants integrity checking for .pefs.db or .conf? */
-					/* XXXgpf: [TODO] move this check to a mini function */
-					if (strncmp(enc_name, ".pefs.db", enc_name_len) != 0 &&
-						strncmp(enc_name, ".pefs.conf", enc_name_len) != 0 &&
-						strncmp(enc_name, ".pefs.checksum", enc_name_len) != 0)
-					{
-						enc_name++;
-						enc_name_len--;
-						buf_len = MAXNAMLEN + 1;
-						buf = malloc(buf_len, M_TEMP, M_WAITOK);
-
-						r = pefs_name_pton(enc_name, enc_name_len, buf, buf_len);
-						if (r <= 0) {
-							/* XXXgpf: I sincerely doubt an error can occur here */
-							error = EINVAL;
-							printf("name_pton error: %d\n", error);
-						}
-						else {
-							memcpy(&(pcie.pcie_file_id), buf, sizeof(pcie.pcie_file_id));
-							pcie.pcie_file_id = be64toh(pcie.pcie_file_id);
-							printf("id to lookup: %llu\n", pcie.pcie_file_id);
-							pefs_checksum_index_lookup(&pcie, vp);
-						}
-
-						free(buf, M_TEMP);
-					}
-
 				}
 				*ap->a_vpp = vp;
 				if ((cnp->cn_flags & MAKEENTRY) &&

Modified: soc2012/gpf/pefs_kmod/sys/modules/pefs/Makefile
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/modules/pefs/Makefile	Mon Jun 25 12:30:51 2012	(r238268)
+++ soc2012/gpf/pefs_kmod/sys/modules/pefs/Makefile	Mon Jun 25 14:53:18 2012	(r238269)
@@ -6,7 +6,8 @@
 SRCS=	vnode_if.h \
 	pefs_subr.c pefs_vfsops.c pefs_vnops.c pefs_xbase64.c pefs_crypto.c \
 	pefs_dircache.c \
-	pefs_xts.c vmac.c
+	pefs_xts.c vmac.c \
+	pefs_checksum.c
 
 .if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
 SRCS+=	pefs_aesni.c


More information about the svn-soc-all mailing list