Skip to content

Commit a2c925d

Browse files
authored
Merge pull request #16 from dlech/master
poll support
2 parents 2c088b6 + 6c3990f commit a2c925d

4 files changed

Lines changed: 76 additions & 7 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
build
22
dist
33
fuse_python.egg-info
4+
__pycache__
5+
*.pyc
6+
*.so

AUTHORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ Contributions
1111

1212
hello.py by Andrew Straw <strawman@astraw.com>
1313
threading related code cleaned up by Miklos Szeredi <miklos@szeredi.hu>
14-
IOCTL support by Cédric Carrée
14+
IOCTL support by Cédric Carrée
15+
poll support by David Lechner <david@lechnology.com>

fuse.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from os import environ
2424
import re
2525
from fuseparts import __version__
26-
from fuseparts._fuse import main, FuseGetContext, FuseInvalidate
26+
from fuseparts._fuse import main, FuseGetContext, FuseInvalidate, FuseNotifyPoll
2727
from fuseparts._fuse import FuseError, FuseAPIVersion
2828
from fuseparts.subbedopts import SubOptsHive, SubbedOptFormatter
2929
from fuseparts.subbedopts import SubbedOptIndentedFormatter, SubbedOptParse
@@ -645,7 +645,7 @@ class Fuse(object):
645645
'statfs', 'fsync', 'create', 'opendir', 'releasedir', 'fsyncdir',
646646
'flush', 'fgetattr', 'ftruncate', 'getxattr', 'listxattr',
647647
'setxattr', 'removexattr', 'access', 'lock', 'utimens', 'bmap',
648-
'fsinit', 'fsdestroy', 'ioctl']
648+
'fsinit', 'fsdestroy', 'ioctl', 'poll']
649649

650650
fusage = "%prog [mountpoint] [options]"
651651

@@ -793,6 +793,9 @@ def GetContext(self):
793793
def Invalidate(self, path):
794794
return FuseInvalidate(self, path)
795795

796+
def NotifyPoll(self, pollhandle):
797+
return FuseNotifyPoll(pollhandle)
798+
796799
def fuseoptref(cls):
797800
"""
798801
Find out which options are recognized by the library.

fuseparts/_fusemodule.c

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static PyObject *getattr_cb=NULL, *readlink_cb=NULL, *readdir_cb=NULL,
5858
*releasedir_cb=NULL, *fsyncdir_cb=NULL, *flush_cb=NULL, *ftruncate_cb=NULL,
5959
*fgetattr_cb=NULL, *getxattr_cb=NULL, *listxattr_cb=NULL, *setxattr_cb=NULL,
6060
*removexattr_cb=NULL, *access_cb=NULL, *lock_cb = NULL, *utimens_cb = NULL,
61-
*bmap_cb = NULL, *fsinit_cb=NULL, *fsdestroy_cb = NULL, *ioctl_cb = NULL;
61+
*bmap_cb = NULL, *fsinit_cb=NULL, *fsdestroy_cb = NULL, *ioctl_cb = NULL,
62+
*poll_cb = NULL;
6263

6364

6465
static PyObject *Py_FuseError;
@@ -991,6 +992,44 @@ ioctl_func(const char *path, int cmd, void *arg,
991992
}
992993
EPILOGUE
993994
}
995+
996+
static const char pollhandle_name[] = "pollhandle";
997+
998+
static void
999+
pollhandle_destructor(PyObject *p)
1000+
{
1001+
struct fuse_pollhandle *ph;
1002+
1003+
ph = PyCapsule_GetPointer(p, pollhandle_name);
1004+
fuse_pollhandle_destroy(ph);
1005+
}
1006+
1007+
static int
1008+
poll_func(const char *path, struct fuse_file_info *fi,
1009+
struct fuse_pollhandle *ph, unsigned *reventsp)
1010+
{
1011+
PyObject *pollhandle = Py_None;
1012+
1013+
if (ph)
1014+
pollhandle = PyCapsule_New(ph, pollhandle_name, pollhandle_destructor);
1015+
1016+
PROLOGUE(PYO_CALLWITHFI(fi, poll_cb, sO, path, pollhandle));
1017+
1018+
OUT_DECREF:
1019+
Py_DECREF(v);
1020+
OUT:
1021+
if (ph)
1022+
Py_DECREF(pollhandle);
1023+
1024+
PYUNLOCK();
1025+
1026+
if (ret > 0) {
1027+
*reventsp = ret;
1028+
ret = 0;
1029+
}
1030+
1031+
return ret;
1032+
}
9941033
#endif
9951034

9961035
static int
@@ -1036,13 +1075,14 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
10361075
"create", "opendir", "releasedir", "fsyncdir", "flush",
10371076
"ftruncate", "fgetattr", "getxattr", "listxattr", "setxattr",
10381077
"removexattr", "access", "lock", "utimens", "bmap",
1039-
"fsinit", "fsdestroy", "ioctl", "fuse_args", "multithreaded", NULL
1078+
"fsinit", "fsdestroy", "ioctl", "poll", "fuse_args",
1079+
"multithreaded", NULL
10401080
};
10411081

10421082
memset(&op, 0, sizeof(op));
10431083

10441084
if (!PyArg_ParseTupleAndKeywords(args, kw,
1045-
"|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi",
1085+
"|OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOi",
10461086
kwlist, &getattr_cb, &readlink_cb,
10471087
&readdir_cb, &mknod_cb, &mkdir_cb,
10481088
&unlink_cb, &rmdir_cb, &symlink_cb,
@@ -1058,7 +1098,7 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
10581098
&removexattr_cb, &access_cb,
10591099
&lock_cb, &utimens_cb, &bmap_cb,
10601100
&fsinit_cb, &fsdestroy_cb, &ioctl_cb,
1061-
&fargseq, &multithreaded))
1101+
&poll_cb, &fargseq, &multithreaded))
10621102
return NULL;
10631103

10641104
#define DO_ONE_ATTR_AS(fname, pyname) \
@@ -1120,6 +1160,7 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
11201160
#endif
11211161
#if FUSE_VERSION >= 28
11221162
DO_ONE_ATTR(ioctl);
1163+
DO_ONE_ATTR(poll);
11231164
#endif
11241165

11251166
#undef DO_ONE_ATTR
@@ -1282,11 +1323,32 @@ FuseAPIVersion(PyObject *self, PyObject *args)
12821323
return favers;
12831324
}
12841325

1326+
static const char FuseNotifyPoll__doc__[] = "Notify IO readiness event.";
1327+
1328+
static PyObject *
1329+
FuseNotifyPoll(PyObject *self, PyObject *arg)
1330+
{
1331+
struct fuse_pollhandle *ph;
1332+
int ret;
1333+
1334+
ph = PyCapsule_GetPointer(arg, pollhandle_name);
1335+
if (!ph) {
1336+
PyErr_SetString(PyExc_TypeError,
1337+
"pollhandle is not a FUSE poll handle");
1338+
return NULL;
1339+
}
1340+
1341+
ret = fuse_notify_poll(ph);
1342+
1343+
return PyInt_FromLong(ret);
1344+
}
1345+
12851346
static PyMethodDef Fuse_methods[] = {
12861347
{"main", (PyCFunction)Fuse_main, METH_VARARGS|METH_KEYWORDS},
12871348
{"FuseGetContext", (PyCFunction)FuseGetContext, METH_VARARGS, FuseGetContext__doc__},
12881349
{"FuseInvalidate", (PyCFunction)FuseInvalidate, METH_VARARGS, FuseInvalidate__doc__},
12891350
{"FuseAPIVersion", (PyCFunction)FuseAPIVersion, METH_NOARGS, FuseAPIVersion__doc__},
1351+
{"FuseNotifyPoll", (PyCFunction)FuseNotifyPoll, METH_O, FuseNotifyPoll__doc__},
12901352
{NULL, NULL} /* sentinel */
12911353
};
12921354

0 commit comments

Comments
 (0)