socsvn commit: r237552 - in soc2012/gpf/pefs_kmod: sbin/pefs sys/fs/pefs

gpf at FreeBSD.org gpf at FreeBSD.org
Tue Jun 12 14:05:46 UTC 2012


Author: gpf
Date: Tue Jun 12 14:05:43 2012
New Revision: 237552
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=237552

Log:
  - try to acquire a vnode for .pefs.checksum during pefs_mount [buggy]
  

Modified:
  soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h
  soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c

Modified: soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c	Tue Jun 12 13:57:56 2012	(r237551)
+++ soc2012/gpf/pefs_kmod/sbin/pefs/pefs_checksum.c	Tue Jun 12 14:05:43 2012	(r237552)
@@ -924,7 +924,7 @@
  * 		A1) semantic checks:
  * 			A1a) file should reside in pefs filesystem & file should be regular file.
  * 			A1b) if symlink, acquire and save the absolute path of the symlink's
- * 				target. Try to stat() the target but don't do anything else.
+ * 				target. Try to lstat() the target but don't do anything else.
  * 			A1c) If hardlink, save a reference to this file entry in our rb tree.
  * 			rb-tree uses inodes as keys and is used in part C to print warnings.
  * 			A1d) Open and store file descriptors to file & parent_directory.

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h	Tue Jun 12 13:57:56 2012	(r237551)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs.h	Tue Jun 12 14:05:43 2012	(r237552)
@@ -118,6 +118,13 @@
 	char			ptk_tweak[PEFS_TWEAK_SIZE];
 };
 
+/* XXXgpf: fill this in */
+#define PEFS_FILE_CHECKSUM		".pefs.checksum"
+
+struct pefs_checksum {
+	int	pcs_int;
+};
+
 #define	PN_HASKEY			0x000001
 #define	PN_WANTRECYCLE			0x000100
 #define	PN_LOCKBUF_SMALL		0x001000
@@ -138,12 +145,14 @@
 #define	PM_ROOT_CANRECURSE		0x01
 #define	PM_DIRCACHE			0x02
 #define	PM_ASYNCRECLAIM			0x04
+#define PM_CHECKSUM				0x08
 
 struct pefs_mount {
 	struct mount		*pm_lowervfs;
 	struct vnode		*pm_rootvp;
 	struct mtx		pm_keys_lock;
 	struct pefs_key_head	pm_keys;
+	struct pefs_checksum	pm_checksum;
 	int			pm_flags;
 };
 

Modified: soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c
==============================================================================
--- soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c	Tue Jun 12 13:57:56 2012	(r237551)
+++ soc2012/gpf/pefs_kmod/sys/fs/pefs/pefs_vfsops.c	Tue Jun 12 14:05:43 2012	(r237552)
@@ -72,6 +72,7 @@
 	"dircache",
 	"nodircache",
 	"asyncreclaim",
+	"checksum",
 	NULL
 };
 
@@ -119,6 +120,65 @@
 	return (0);
 }
 
+/* xxxgpf: tmp 4 dbg purposes */
+static void
+pefs_dbg_vnode(struct vnode *vp, char *str)
+{
+	printf("%s is locked: %d\n", str, VOP_ISLOCKED(vp));
+	printf("%s usecount: %d\n", str, vp->v_usecount);
+	printf("%s holdcnt: %d\n", str, vp->v_holdcnt);
+	printf("%s writecount: %d\n", str, vp->v_writecount);
+}
+
+/*
+ * XXXgpf:
+ * get vp for checksum
+ * read header info
+ * then read index into 2 huge mallocd char*s
+ * should also worry about pefs_init(), pefs_uninit(), and unmount
+ */
+static int
+pefs_checksum_load(struct mount *mp)
+{
+	struct nameidata nd, *ndp = &nd;
+	struct pefs_mount *pm;
+	struct vnode *checksumvp;
+	char path[MAXPATHLEN + 1];
+	int error;
+
+	pm = VFS_TO_PEFS(mp);
+
+	printf("from = %s\n", mp->mnt_stat.f_mntfromname);
+	//printf("to = %s\n", mp->mnt_stat.f_mntonname);
+	snprintf(path, sizeof(path), "%s/%s", mp->mnt_stat.f_mntfromname, PEFS_FILE_CHECKSUM);
+	printf("path = %s\n", path);
+
+	pefs_dbg_vnode(pm->pm_rootvp, "start rootvp");
+
+	NDINIT(ndp, LOOKUP, 0, UIO_SYSSPACE, path, curthread);
+	error = namei(ndp);
+	
+	pefs_dbg_vnode(pm->pm_rootvp, "after namei rootvp");
+
+	if (error != 0) {
+		printf("pefs_checksum_load: namei error %d\n", error);
+		// tmp change
+		return (0);
+	}
+
+	checksumvp = ndp->ni_vp;
+	NDFREE(ndp, NDF_NO_VP_RELE);
+
+	/* XXXgpf: temporary vrele of checksumvp */
+	pefs_dbg_vnode(checksumvp, "before vrele checksumvp");
+	vrele(checksumvp);
+	pefs_dbg_vnode(checksumvp, "after vrele checksumvp");
+
+	pefs_dbg_vnode(pm->pm_rootvp, "end rootvp");
+	
+	return (0);
+}
+
 /*
  * Mount null layer
  */
@@ -131,7 +191,7 @@
 	struct pefs_mount *pm;
 	char *from, *from_free;
 	int isvnunlocked = 0, len;
-	int opt_dircache, opt_asyncreclaim;
+	int opt_checksum, opt_dircache, opt_asyncreclaim;
 	int error = 0;
 
 	PEFSDEBUG("pefs_mount(mp = %p)\n", (void *)mp);
@@ -155,6 +215,12 @@
 		vfs_deleteopt(mp->mnt_optnew, "asyncreclaim");
 		opt_asyncreclaim = 1;
 	}
+	opt_checksum = -1;
+	if (vfs_flagopt(mp->mnt_optnew, "checksum", NULL, 0)) {
+		vfs_deleteopt(mp->mnt_optnew, "checksum");
+		printf("checksum!\n");
+		opt_checksum = 1;
+	}
 
 	if (mp->mnt_flag & MNT_UPDATE) {
 		error = EOPNOTSUPP;
@@ -170,6 +236,9 @@
 			    PM_ASYNCRECLAIM, "asyncreclaim");
 			error = 0;
 		}
+		/*
+		 * XXXgpf: should we allow opt_checksum with MNT_UPDATE?
+		 */
 		return (error);
 	}
 
@@ -262,6 +331,7 @@
 		pm->pm_flags |= PM_ROOT_CANRECURSE;
 	pefs_opt_set(mp, opt_dircache, pm, PM_DIRCACHE, "dircache");
 	pefs_opt_set(mp, opt_asyncreclaim, pm, PM_ASYNCRECLAIM, "asyncreclaim");
+	pefs_opt_set(mp, opt_checksum, pm, PM_CHECKSUM, "checksum");
 
 	/*
 	 * Save reference.  Each mount also holds
@@ -302,6 +372,17 @@
 	mp->mnt_data =  pm;
 	vfs_getnewfsid(mp);
 
+	if ((pm->pm_flags & PM_CHECKSUM) != 0) {
+		pefs_dbg_vnode(lowerrootvp, "BEFORE lowerootvp");
+		error = pefs_checksum_load(mp);
+		pefs_dbg_vnode(lowerrootvp, "AFTER lowerootvp");
+		if (error != 0) {
+			/* XXXgpf: what should be done for lowerrootvp? vput? */
+			free(pm, M_PEFSMNT);
+			return (error);
+		}
+	}
+
 	PEFSDEBUG("pefs_mount: lower %s, alias at %s\n",
 		mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
 	return (0);


More information about the svn-soc-all mailing list