2 * Copyright (C) 2018 Facebook
4 * This file is part of libbtrfsutil.
6 * libbtrfsutil is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * libbtrfsutil is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with libbtrfsutil. If not, see <http://www.gnu.org/licenses/>.
20 #include "btrfsutilpy.h"
22 static void QgroupInherit_dealloc(QgroupInherit *self)
24 btrfs_util_destroy_qgroup_inherit(self->inherit);
25 Py_TYPE(self)->tp_free((PyObject *)self);
28 static int QgroupInherit_init(QgroupInherit *self, PyObject *args,
31 static char *keywords[] = {NULL};
32 enum btrfs_util_error err;
34 if (!PyArg_ParseTupleAndKeywords(args, kwds, ":QgroupInherit",
38 err = btrfs_util_create_qgroup_inherit(0, &self->inherit);
40 SetFromBtrfsUtilError(err);
47 static PyObject *QgroupInherit_getattro(QgroupInherit *self, PyObject *nameobj)
49 const char *name = "";
51 if (PyUnicode_Check(nameobj)) {
52 name = PyUnicode_AsUTF8(nameobj);
57 if (strcmp(name, "groups") == 0) {
62 btrfs_util_qgroup_inherit_get_groups(self->inherit, &arr, &n);
67 for (i = 0; i < n; i++) {
68 tmp = PyLong_FromUnsignedLongLong(arr[i]);
73 PyList_SET_ITEM(ret, i, tmp);
78 return PyObject_GenericGetAttr((PyObject *)self, nameobj);
82 static PyObject *QgroupInherit_add_group(QgroupInherit *self, PyObject *args,
85 static char *keywords[] = {"qgroupid", NULL};
86 enum btrfs_util_error err;
89 if (!PyArg_ParseTupleAndKeywords(args, kwds, "K:add_group", keywords,
93 err = btrfs_util_qgroup_inherit_add_group(&self->inherit, qgroupid);
95 SetFromBtrfsUtilError(err);
102 static PyMethodDef QgroupInherit_methods[] = {
103 {"add_group", (PyCFunction)QgroupInherit_add_group,
104 METH_VARARGS | METH_KEYWORDS,
105 "add_group(qgroupid)\n\n"
106 "Add a qgroup to inherit from.\n\n"
108 "qgroupid -- ID of qgroup to add"},
112 #define QgroupInherit_DOC \
113 "QgroupInherit() -> new qgroup inheritance specifier\n\n" \
114 "Create a new object which specifies what qgroups to inherit\n" \
115 "from for create_subvolume() and create_snapshot()"
117 PyTypeObject QgroupInherit_type = {
118 PyVarObject_HEAD_INIT(NULL, 0)
119 "btrfsutil.QgroupInherit", /* tp_name */
120 sizeof(QgroupInherit), /* tp_basicsize */
122 (destructor)QgroupInherit_dealloc, /* tp_dealloc */
124 NULL, /* tp_getattr */
125 NULL, /* tp_setattr */
126 NULL, /* tp_as_async */
128 NULL, /* tp_as_number */
129 NULL, /* tp_as_sequence */
130 NULL, /* tp_as_mapping */
134 (getattrofunc)QgroupInherit_getattro, /* tp_getattro */
135 NULL, /* tp_setattro */
136 NULL, /* tp_as_buffer */
137 Py_TPFLAGS_DEFAULT, /* tp_flags */
138 QgroupInherit_DOC, /* tp_doc */
139 NULL, /* tp_traverse */
141 NULL, /* tp_richcompare */
142 0, /* tp_weaklistoffset */
144 NULL, /* tp_iternext */
145 QgroupInherit_methods, /* tp_methods */
146 NULL, /* tp_members */
147 NULL, /* tp_getset */
150 NULL, /* tp_descr_get */
151 NULL, /* tp_descr_set */
152 0, /* tp_dictoffset */
153 (initproc)QgroupInherit_init, /* tp_init */