Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to get ZFS object properties #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions src/py_zfs_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ PyDoc_STRVAR(py_zfs_resource_get_properties__doc__,
"-------\n"
"TypeError:\n"
" The specified properties is not a python set.\n\n"
"TypeError:\n"
" The underlying libzfs handle does not support property retrieval.\n\n"
"ValueError:\n"
" One of the specified properties is not supported for the ZFS type of the\n"
" underlying ZFS resource. For example, requesting a zvol property for a\n"
Expand All @@ -98,18 +96,6 @@ PyObject *py_zfs_resource_get_properties(PyObject *self,
"get_source",
NULL
};
if (res->is_simple) {
PyErr_SetString(PyExc_TypeError,
"Properties may not be retrieved on "
"simple ZFS handles. Simple handles are "
"created when iterating with the \"fast\" "
"keyword argument. If property information "
"is required, then the method call that "
"created this handle object should be "
"converted to use the slower variant."
);
return NULL;
}

if (!PyArg_ParseTupleAndKeywords(args_unused, kwargs,
"|$Op",
Expand All @@ -129,6 +115,20 @@ PyObject *py_zfs_resource_get_properties(PyObject *self,
return NULL;
}

if (res->is_simple) {
/*
* We have simple handle that lacks property information.
* This means we _must_ refresh properties before
* generating python object
*/
Py_BEGIN_ALLOW_THREADS
// This call does not touch ZFS errno and
usaleem-ix marked this conversation as resolved.
Show resolved Hide resolved
// so we don't need to take mutex
zfs_refresh_properties(res->obj.zhp);
res->is_simple = B_FALSE;
Py_END_ALLOW_THREADS
}

return py_zfs_get_properties(&res->obj, prop_set, get_source);
}

Expand Down Expand Up @@ -162,8 +162,6 @@ PyDoc_STRVAR(py_zfs_resource_asdict__doc__,
"-------\n"
"TypeError:\n"
" The specified properties is not a python set.\n\n"
"TypeError:\n"
" The underlying libzfs handle does not support property retrieval.\n\n"
"ValueError:\n"
" One of the specified properties is not supported for the ZFS type of the\n"
" underlying ZFS resource. For example, requesting a zvol property for a\n"
Expand Down Expand Up @@ -200,24 +198,26 @@ PyObject *py_zfs_resource_asdict(PyObject *self,
if (prop_set != NULL) {
PyObject *zfsprops = NULL;

if (res->is_simple) {
PyErr_SetString(PyExc_TypeError,
"Properties may not be retrieved on "
"simple ZFS handles. Simple handles are "
"created when iterating with the \"fast\" "
"keyword argument. If property information "
"is required, then the method call that "
"created this handle object should be "
"converted to use the slower variant."
);
return NULL;
}

if (!PySet_Check(prop_set)) {
PyErr_SetString(PyExc_TypeError,
"properties must be a set.");
return NULL;
}

if (res->is_simple) {
/*
* We have simple handle that lacks property information.
* This means we _must_ refresh properties before
* generating python object
*/
Py_BEGIN_ALLOW_THREADS
// This call does not touch ZFS errno and
// so we don't need to take mutex
zfs_refresh_properties(res->obj.zhp);
res->is_simple = B_FALSE;
Py_END_ALLOW_THREADS
}

zfsprops = py_zfs_get_properties(&res->obj, prop_set, get_source);
if (zfsprops == NULL)
return NULL;
Expand Down