commit 265a0d7d4b00c0933773a5119d5bd17947e23dbb
parent f9e03620ab77a3690599fc0ca1460d22194388f2
Author: Antoine Amarilli <a3nm@a3nm.net>
Date: Fri, 28 Dec 2012 23:59:54 +0100
remove debug, comments, +TODO
Diffstat:
5 files changed, 28 insertions(+), 20 deletions(-)
diff --git a/COPYING b/COPYING
@@ -0,0 +1,21 @@
+Copyright (C) 2012 by Antoine Amarilli
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
diff --git a/TODO b/TODO
@@ -1,3 +1,4 @@
- fail more gracefully for missing endpoints
- partial reads, or bufferize as much as needed
- don't cache for a small read
+- cachefs inherits from loopfs or from metacachefs
diff --git a/cachefs.py b/cachefs.py
@@ -1,5 +1,7 @@
#!/usr/bin/python
+"""FUSE filesystem to maintain a fixed-size cache for a hierarchy"""
+
import fuse
import errno
import logging
@@ -63,11 +65,9 @@ class Cache:
self.addFile(full)
def addFile(self, path):
- print "adding %s" % path
self.files[path] = File(self, path)
heapq.heappush(self.heap, (time.time(), self.files[path]))
self.currentSize += self.files[path].size
- print "my size be now %d" % self.currentSize
def resizeFile(self, path, newSize):
f = self.files[path]
@@ -114,12 +114,9 @@ class CacheFS(fuse.Fuse):
self.parser.add_option('--size', dest='size', metavar='SIZE',
type='int', help="maximal size of cache")
- print self
-
def fsinit(self):
options = self.cmdline[0]
args = self.cmdline[1]
- print args
self.sourceRoot = args[0]
self.cacheRoot = options.cache
self.db = options.db
@@ -128,7 +125,6 @@ class CacheFS(fuse.Fuse):
vfs = os.statvfs(self.cacheRoot)
# half of available space on the cache fs
self.size = (vfs.f_bavail * vfs.f_bsize) / 2
- print "size is %d" % self.size
try:
with open(self.db, 'rb') as f:
self.cache = pickle.load(f)
@@ -138,7 +134,6 @@ class CacheFS(fuse.Fuse):
if (self.cache.maxSize > self.size):
self.makeRoom(self.cache.maxSize - self.size)
self.cache.maxSize = self.size
- print self.cache.maxSize
def fsdestroy(self):
@@ -156,14 +151,12 @@ class CacheFS(fuse.Fuse):
# TODO adjust for the available size of the underlying FS
if bytes > self.cache.maxSize:
raise FileTooBigException()
- print("now current free size is %d and must fit %d" %
- (self.cache.freeSize, bytes))
while bytes > self.cache.freeSize:
f = self.cache.oldestFile()
self.cache.deleteFile(f.path)
print("remove %s" % self.cachePath("/"+f.path))
os.unlink(self.cachePath("/"+f.path))
- print("now current size is %d" % self.cache.currentSize)
+ print("current size is now %d" % self.cache.currentSize)
def registerHit(self, path):
"""register a hit for path in the cache"""
@@ -289,7 +282,6 @@ class CacheFS(fuse.Fuse):
"f_flag", "f_frsize", "f_namemax"]))
stv.f_bfree = (self.cache.maxSize - self.cache.currentSize)/stv.f_bsize
stv.f_bavail = stv.f_bfree
- print ("maxsize %d bzide %d" % (self.cache.maxSize, stv.f_bsize))
stv.f_blocks = self.cache.maxSize/stv.f_bsize
return stv
@@ -334,7 +326,7 @@ class CacheFS(fuse.Fuse):
def write(self, path, data, offset):
wasCached = self.isCached(path)
- print "writing to a %s file" % ("cached" if wasCached else "notcached")
+ print "writing to a %s file" % ("cached" if wasCached else "non-cached")
retval = self.doWrite(self.sourcePath(path), data, offset)
if retval > 0 and wasCached:
self.makeRoom(len(data))
@@ -347,12 +339,6 @@ class CacheFS(fuse.Fuse):
if __name__ == "__main__":
- #if len(sys.argv) != 6:
- # print("Usage: %s SOURCE CACHE SIZE DB MOUNTPOINT" % sys.argv[0])
- # sys.exit(1)
- #logging.getLogger().setLevel(logging.DEBUG)
- #cachefs = CacheFS(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
-
cachefs = CacheFS()
fuse_opts = cachefs.parse(['-o', 'fsname=cachefs'] + sys.argv[1:])
cachefs.main()
diff --git a/loopfs.py b/loopfs.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-"""LoopFS -- a loopback file system with FUSE"""
+"""Dummy loopback FUSE filesystem"""
import fuse
import errno
diff --git a/metacachefs.py b/metacachefs.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-"""MetaCacheFS -- a file system to cache metadata"""
+"""FUSE filesystem to cache all metadata in memory for a hierarchy"""
import fuse
import errno