[vhffs-dev] [941] adaptative quota cache, cache values are upgraded when a new block or file is written.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 941
Author:   gradator
Date:     2007-09-21 16:48:22 +0000 (Fri, 21 Sep 2007)

Log Message:
-----------
adaptative quota cache, cache values are upgraded when a new block or file is written. Note: this is not perfect, just useful to prevent abuse, still need to timeout to fetch the real value

Modified Paths:
--------------
    trunk/vhffs-fs/vhffsfs.c


Modified: trunk/vhffs-fs/vhffsfs.c
===================================================================
--- trunk/vhffs-fs/vhffsfs.c	2007-09-21 15:59:36 UTC (rev 940)
+++ trunk/vhffs-fs/vhffsfs.c	2007-09-21 16:48:22 UTC (rev 941)
@@ -1034,7 +1034,7 @@
 #endif
 
 /* return 0 if the gid is not over quota, 1 if over quota, -errno in case of error */
-int vhffsfs_checkquota_gid_with_realpath(char *realpath, gid_t gid)  {
+int vhffsfs_checkquota_gid_with_realpath(char *realpath, gid_t gid, size_t newblocks, int newfiles)  {
 	int mode = 0;  /* 0 = do nothing, 1 = data, 2 = repository */
 	struct dqblk *dq = NULL;
 	int ret = 0;
@@ -1080,6 +1080,9 @@
 	// try to fetch quota from cache
 	dq = vhffsfs_checkquota_cache_lookup(key);
 	if(dq)  {
+		/* we should lock here but an error in quota computation is not important at all */
+		dq->dqb_curspace += newblocks;
+		dq->dqb_curinodes += newfiles;
 		if(dq->dqb_curspace > dq->dqb_bhardlimit  ||  dq->dqb_curinodes > dq->dqb_ihardlimit) ret = 1;
 		vhffsfs_checkquota_cache_unref(key);
 		free(key);
@@ -1129,6 +1132,9 @@
 		}
 
 		dq = vhffsfs_checkquota_cache_add(key, gid, path, dq);
+		/* we should lock here but an error in quota computation is not important at all */
+		dq->dqb_curspace += newblocks;
+		dq->dqb_curinodes += newfiles;
 #endif
 		if(dq->dqb_curspace > dq->dqb_bhardlimit  ||  dq->dqb_curinodes > dq->dqb_ihardlimit) ret = 1;
 #ifdef WITH_CHECKQUOTA_CACHE
@@ -1304,7 +1310,7 @@
 	if(!rpath) return -ENOENT;
 
 #ifdef WITH_CHECKQUOTA
-	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid, 0, 1);
 	if(res)  {
 		free(rpath);
 		return -EDQUOT;
@@ -1334,7 +1340,7 @@
 	if(!rpath) return -ENOENT;
 
 #ifdef WITH_CHECKQUOTA
-	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid, 0, 1);
 	if(res)  {
 		free(rpath);
 		return -EDQUOT;
@@ -1404,7 +1410,7 @@
 	}
 
 #ifdef WITH_CHECKQUOTA
-	res = vhffsfs_checkquota_gid_with_realpath(rto, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rto, gid, 0, 1);
 	if(res)  {
 		free(rfrom);
 		free(rto);
@@ -1463,7 +1469,7 @@
 	}
 
 #ifdef WITH_CHECKQUOTA
-	res = vhffsfs_checkquota_gid_with_realpath(rto, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rto, gid, 0, 1);
 	if(res)  {
 		free(rfrom);
 		free(rto);
@@ -1573,7 +1579,7 @@
 	if(!rpath) return -ENOENT;
 
 #ifdef WITH_CHECKQUOTA
-	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid, 0, 1);
 	if(res)  {
 		free(rpath);
 		return -EDQUOT;
@@ -1636,7 +1642,7 @@
 	rpath = vhffsfs_realpath(path, &uid, &gid);
 	if(!rpath) return -ENOENT;
 
-	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid);
+	res = vhffsfs_checkquota_gid_with_realpath(rpath, gid, size, 0);
 	free(rpath);
 	if(res) return -EDQUOT;
 #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/