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) {
61 btrfs_util_qgroup_inherit_get_groups(self
->inherit
, &arr
, &n
);
63 return list_from_uint64_array(arr
, n
);
65 return PyObject_GenericGetAttr((PyObject
*)self
, nameobj
);
69 static PyObject
*QgroupInherit_add_group(QgroupInherit
*self
, PyObject
*args
,
72 static char *keywords
[] = {"qgroupid", NULL
};
73 enum btrfs_util_error err
;
76 if (!PyArg_ParseTupleAndKeywords(args
, kwds
, "K:add_group", keywords
,
80 err
= btrfs_util_qgroup_inherit_add_group(&self
->inherit
, qgroupid
);
82 SetFromBtrfsUtilError(err
);
89 static PyMethodDef QgroupInherit_methods
[] = {
90 {"add_group", (PyCFunction
)QgroupInherit_add_group
,
91 METH_VARARGS
| METH_KEYWORDS
,
92 "add_group(qgroupid)\n\n"
93 "Add a qgroup to inherit from.\n\n"
95 "qgroupid -- ID of qgroup to add"},
99 #define QgroupInherit_DOC \
100 "QgroupInherit() -> new qgroup inheritance specifier\n\n" \
101 "Create a new object which specifies what qgroups to inherit\n" \
102 "from for create_subvolume() and create_snapshot()"
104 PyTypeObject QgroupInherit_type
= {
105 PyVarObject_HEAD_INIT(NULL
, 0)
106 "btrfsutil.QgroupInherit", /* tp_name */
107 sizeof(QgroupInherit
), /* tp_basicsize */
109 (destructor
)QgroupInherit_dealloc
, /* tp_dealloc */
111 NULL
, /* tp_getattr */
112 NULL
, /* tp_setattr */
113 NULL
, /* tp_as_async */
115 NULL
, /* tp_as_number */
116 NULL
, /* tp_as_sequence */
117 NULL
, /* tp_as_mapping */
121 (getattrofunc
)QgroupInherit_getattro
, /* tp_getattro */
122 NULL
, /* tp_setattro */
123 NULL
, /* tp_as_buffer */
124 Py_TPFLAGS_DEFAULT
, /* tp_flags */
125 QgroupInherit_DOC
, /* tp_doc */
126 NULL
, /* tp_traverse */
128 NULL
, /* tp_richcompare */
129 0, /* tp_weaklistoffset */
131 NULL
, /* tp_iternext */
132 QgroupInherit_methods
, /* tp_methods */
133 NULL
, /* tp_members */
134 NULL
, /* tp_getset */
137 NULL
, /* tp_descr_get */
138 NULL
, /* tp_descr_set */
139 0, /* tp_dictoffset */
140 (initproc
)QgroupInherit_init
, /* tp_init */