}
+static PyObject *fadvise_done(PyObject *self, PyObject *args)
+{
+ int fd = -1;
+ long long ofs = 0;
+ if (!PyArg_ParseTuple(args, "iL", &fd, &ofs))
+ return NULL;
+#ifdef POSIX_FADV_DONTNEED
+ posix_fadvise(fd, 0, ofs, POSIX_FADV_DONTNEED);
+#endif
+ return Py_BuildValue("");
+}
+
+
// Currently the Linux kernel and FUSE disagree over the type for
// FS_IOC_GETFLAGS and FS_IOC_SETFLAGS. The kernel actually uses int,
// but FUSE chose long (matching the declaration in linux/fs.h). So
"Return a random 20-byte string" },
{ "open_noatime", open_noatime, METH_VARARGS,
"open() the given filename for read with O_NOATIME if possible" },
+ { "fadvise_done", fadvise_done, METH_VARARGS,
+ "Inform the kernel that we're finished with earlier parts of a file" },
#ifdef BUP_HAVE_FILE_ATTRS
{ "get_linux_file_attr", bup_get_linux_file_attr, METH_VARARGS,
"Return the Linux attributes for the given file." },
progress(filenum, len(b))
b = f.read(BLOB_READ_SIZE)
ofs += len(b)
+ # Warning: ofs == 0 means 'done with the whole file'
+ # This will only happen here when the file is empty
+ fadvise_done(f, ofs)
if not b:
break
yield b
except:
pass
raise
+
+
+def fadvise_done(f, ofs):
+ assert(ofs >= 0)
+ if ofs > 0 and hasattr(f, 'fileno'):
+ _helpers.fadvise_done(f.fileno(), ofs)