1f169c0eaSGlenn Lagasse /*
2f169c0eaSGlenn Lagasse * CDDL HEADER START
3f169c0eaSGlenn Lagasse *
4f169c0eaSGlenn Lagasse * The contents of this file are subject to the terms of the
5f169c0eaSGlenn Lagasse * Common Development and Distribution License (the "License").
6f169c0eaSGlenn Lagasse * You may not use this file except in compliance with the License.
7f169c0eaSGlenn Lagasse *
8f169c0eaSGlenn Lagasse * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9f169c0eaSGlenn Lagasse * or http://www.opensolaris.org/os/licensing.
10f169c0eaSGlenn Lagasse * See the License for the specific language governing permissions
11f169c0eaSGlenn Lagasse * and limitations under the License.
12f169c0eaSGlenn Lagasse *
13f169c0eaSGlenn Lagasse * When distributing Covered Code, include this CDDL HEADER in each
14f169c0eaSGlenn Lagasse * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15f169c0eaSGlenn Lagasse * If applicable, add the following below this CDDL HEADER, with the
16f169c0eaSGlenn Lagasse * fields enclosed by brackets "[]" replaced with your own identifying
17f169c0eaSGlenn Lagasse * information: Portions Copyright [yyyy] [name of copyright owner]
18f169c0eaSGlenn Lagasse *
19f169c0eaSGlenn Lagasse * CDDL HEADER END
20f169c0eaSGlenn Lagasse */
21f169c0eaSGlenn Lagasse
22f169c0eaSGlenn Lagasse /*
23f169c0eaSGlenn Lagasse * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24f5c2e7eaSTheo Schlossnagle * Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
25f169c0eaSGlenn Lagasse */
26f169c0eaSGlenn Lagasse
27f169c0eaSGlenn Lagasse #include <Python.h>
28f169c0eaSGlenn Lagasse #include <sys/varargs.h>
29f169c0eaSGlenn Lagasse #include <stdio.h>
30f169c0eaSGlenn Lagasse #include <libnvpair.h>
31f169c0eaSGlenn Lagasse
32f169c0eaSGlenn Lagasse #include <libbe.h>
33f169c0eaSGlenn Lagasse #include <libbe_priv.h>
34f169c0eaSGlenn Lagasse
35f169c0eaSGlenn Lagasse enum {
36f169c0eaSGlenn Lagasse BE_PY_SUCCESS = 0,
37f169c0eaSGlenn Lagasse BE_PY_ERR_APPEND = 6000,
38f169c0eaSGlenn Lagasse BE_PY_ERR_DICT,
39f169c0eaSGlenn Lagasse BE_PY_ERR_LIST,
40f169c0eaSGlenn Lagasse BE_PY_ERR_NVLIST,
41f169c0eaSGlenn Lagasse BE_PY_ERR_PARSETUPLE,
42f169c0eaSGlenn Lagasse BE_PY_ERR_PRINT_ERR,
43f169c0eaSGlenn Lagasse BE_PY_ERR_VAR_CONV,
44f169c0eaSGlenn Lagasse } bePyErr;
45f169c0eaSGlenn Lagasse
46f169c0eaSGlenn Lagasse /*
47f169c0eaSGlenn Lagasse * public libbe functions
48f169c0eaSGlenn Lagasse */
49f169c0eaSGlenn Lagasse
50f169c0eaSGlenn Lagasse PyObject *beCreateSnapshot(PyObject *, PyObject *);
51f169c0eaSGlenn Lagasse PyObject *beCopy(PyObject *, PyObject *);
52f169c0eaSGlenn Lagasse PyObject *beList(PyObject *, PyObject *);
53f169c0eaSGlenn Lagasse PyObject *beActivate(PyObject *, PyObject *);
54f169c0eaSGlenn Lagasse PyObject *beDestroy(PyObject *, PyObject *);
55f169c0eaSGlenn Lagasse PyObject *beDestroySnapshot(PyObject *, PyObject *);
56f169c0eaSGlenn Lagasse PyObject *beRename(PyObject *, PyObject *);
57f169c0eaSGlenn Lagasse PyObject *beMount(PyObject *, PyObject *);
58f169c0eaSGlenn Lagasse PyObject *beUnmount(PyObject *, PyObject *);
59f169c0eaSGlenn Lagasse PyObject *bePrintErrors(PyObject *, PyObject *);
60f169c0eaSGlenn Lagasse PyObject *beGetErrDesc(PyObject *, PyObject *);
61f169c0eaSGlenn Lagasse char *beMapLibbePyErrorToString(int);
62f169c0eaSGlenn Lagasse void initlibbe_py();
63f169c0eaSGlenn Lagasse
64f169c0eaSGlenn Lagasse static boolean_t convertBEInfoToDictionary(be_node_list_t *be,
65f169c0eaSGlenn Lagasse PyObject **listDict);
66f169c0eaSGlenn Lagasse static boolean_t convertDatasetInfoToDictionary(be_dataset_list_t *ds,
67f169c0eaSGlenn Lagasse PyObject **listDict);
68f169c0eaSGlenn Lagasse static boolean_t convertSnapshotInfoToDictionary(be_snapshot_list_t *ss,
69f169c0eaSGlenn Lagasse PyObject **listDict);
70f169c0eaSGlenn Lagasse static boolean_t convertPyArgsToNvlist(nvlist_t **nvList, int numArgs, ...);
71f169c0eaSGlenn Lagasse
72f169c0eaSGlenn Lagasse
73f169c0eaSGlenn Lagasse /* ~~~~~~~~~~~~~~~ */
74f169c0eaSGlenn Lagasse /* Public Funtions */
75f169c0eaSGlenn Lagasse /* ~~~~~~~~~~~~~~~ */
76f169c0eaSGlenn Lagasse
77f169c0eaSGlenn Lagasse /*
78f169c0eaSGlenn Lagasse * Function: beCreateSnapshot
79f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and
80f169c0eaSGlenn Lagasse * call libbe:be_create_snapshot to create a
81f169c0eaSGlenn Lagasse * snapshot of all the datasets within a BE
82f169c0eaSGlenn Lagasse * Parameters:
83f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
84f169c0eaSGlenn Lagasse * beName - The name of the BE to create a snapshot of
85f169c0eaSGlenn Lagasse * snapName - The name of the snapshot to create (optional)
86f169c0eaSGlenn Lagasse *
87f169c0eaSGlenn Lagasse * The following public attribute values. defined by libbe.h,
88f169c0eaSGlenn Lagasse * are used by this function:
89f169c0eaSGlenn Lagasse *
90f169c0eaSGlenn Lagasse * Returns a pointer to a python object and an optional snapshot name:
91f169c0eaSGlenn Lagasse * 0, [snapName] - Success
92f169c0eaSGlenn Lagasse * 1, [snapName] - Failure
93f169c0eaSGlenn Lagasse * Scope:
94f169c0eaSGlenn Lagasse * Public
95f169c0eaSGlenn Lagasse */
96f169c0eaSGlenn Lagasse /* ARGSUSED */
97f169c0eaSGlenn Lagasse PyObject *
beCreateSnapshot(PyObject * self,PyObject * args)98f169c0eaSGlenn Lagasse beCreateSnapshot(PyObject *self, PyObject *args)
99f169c0eaSGlenn Lagasse {
100f169c0eaSGlenn Lagasse char *beName = NULL;
101f169c0eaSGlenn Lagasse char *snapName = NULL;
102f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
103f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
104f169c0eaSGlenn Lagasse PyObject *retVals = NULL;
105f169c0eaSGlenn Lagasse
106f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "z|z", &beName, &snapName)) {
107f169c0eaSGlenn Lagasse return (Py_BuildValue("[is]", BE_PY_ERR_PARSETUPLE, NULL));
108f169c0eaSGlenn Lagasse }
109f169c0eaSGlenn Lagasse
110f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 4,
111f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, beName,
112f169c0eaSGlenn Lagasse BE_ATTR_SNAP_NAME, snapName)) {
113f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
114f169c0eaSGlenn Lagasse return (Py_BuildValue("[is]", BE_PY_ERR_NVLIST, NULL));
115f169c0eaSGlenn Lagasse }
116f169c0eaSGlenn Lagasse
117f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
118f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
119f169c0eaSGlenn Lagasse }
120f169c0eaSGlenn Lagasse
121f169c0eaSGlenn Lagasse if ((ret = be_create_snapshot(beAttrs)) != 0) {
122f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
123f169c0eaSGlenn Lagasse return (Py_BuildValue("[is]", ret, NULL));
124f169c0eaSGlenn Lagasse }
125f169c0eaSGlenn Lagasse if (snapName == NULL) {
126f169c0eaSGlenn Lagasse if (nvlist_lookup_pairs(beAttrs, NV_FLAG_NOENTOK,
127f169c0eaSGlenn Lagasse BE_ATTR_SNAP_NAME, DATA_TYPE_STRING, &snapName,
128f169c0eaSGlenn Lagasse NULL) != 0) {
129f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
130f169c0eaSGlenn Lagasse return (Py_BuildValue("[is]",
131f169c0eaSGlenn Lagasse BE_PY_ERR_NVLIST, NULL));
132f169c0eaSGlenn Lagasse }
133f169c0eaSGlenn Lagasse retVals = Py_BuildValue("[is]", ret, snapName);
134f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
135f169c0eaSGlenn Lagasse return (retVals);
136f169c0eaSGlenn Lagasse }
137f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
138f169c0eaSGlenn Lagasse
139f169c0eaSGlenn Lagasse return (Py_BuildValue("[is]", ret, NULL));
140f169c0eaSGlenn Lagasse }
141f169c0eaSGlenn Lagasse
142f169c0eaSGlenn Lagasse /*
143f169c0eaSGlenn Lagasse * Function: beCopy
144f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_copy
145f169c0eaSGlenn Lagasse * to create a Boot Environment
146f169c0eaSGlenn Lagasse * Parameters:
147f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
148f169c0eaSGlenn Lagasse * trgtBeName - The name of the BE to create
149f169c0eaSGlenn Lagasse * srcBeName - The name of the BE used to create trgtBeName (optional)
150f169c0eaSGlenn Lagasse * rpool - The pool to create the new BE in (optional)
151f169c0eaSGlenn Lagasse * srcSnapName - The snapshot name (optional)
152f169c0eaSGlenn Lagasse * beNameProperties - The properties to use when creating
153f169c0eaSGlenn Lagasse * the BE (optional)
154f169c0eaSGlenn Lagasse *
155f169c0eaSGlenn Lagasse * Returns a pointer to a python object. That Python object will consist of
156f169c0eaSGlenn Lagasse * the return code and optional attributes, trgtBeName and snapshotName
157f169c0eaSGlenn Lagasse * BE_SUCCESS, [trgtBeName], [trgtSnapName] - Success
158f169c0eaSGlenn Lagasse * 1, [trgtBeName], [trgtSnapName] - Failure
159f169c0eaSGlenn Lagasse * Scope:
160f169c0eaSGlenn Lagasse * Public
161f169c0eaSGlenn Lagasse */
162f169c0eaSGlenn Lagasse /* ARGSUSED */
163f169c0eaSGlenn Lagasse PyObject *
beCopy(PyObject * self,PyObject * args)164f169c0eaSGlenn Lagasse beCopy(PyObject *self, PyObject *args)
165f169c0eaSGlenn Lagasse {
166f169c0eaSGlenn Lagasse char *trgtBeName = NULL;
167f169c0eaSGlenn Lagasse char *srcBeName = NULL;
168f169c0eaSGlenn Lagasse char *srcSnapName = NULL;
169f169c0eaSGlenn Lagasse char *trgtSnapName = NULL;
170f169c0eaSGlenn Lagasse char *rpool = NULL;
171f169c0eaSGlenn Lagasse char *beDescription = NULL;
172f5c2e7eaSTheo Schlossnagle Py_ssize_t pos = 0;
173f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
174f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
175f169c0eaSGlenn Lagasse nvlist_t *beProps = NULL;
176f169c0eaSGlenn Lagasse PyObject *beNameProperties = NULL;
177f169c0eaSGlenn Lagasse PyObject *pkey = NULL;
178f169c0eaSGlenn Lagasse PyObject *pvalue = NULL;
179f169c0eaSGlenn Lagasse PyObject *retVals = NULL;
180f169c0eaSGlenn Lagasse
181f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "|zzzzOz", &trgtBeName, &srcBeName,
182f169c0eaSGlenn Lagasse &srcSnapName, &rpool, &beNameProperties, &beDescription)) {
183f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_PARSETUPLE,
184f169c0eaSGlenn Lagasse NULL, NULL));
185f169c0eaSGlenn Lagasse }
186f169c0eaSGlenn Lagasse
187f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 10,
188f169c0eaSGlenn Lagasse BE_ATTR_NEW_BE_NAME, trgtBeName,
189f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, srcBeName,
190f169c0eaSGlenn Lagasse BE_ATTR_SNAP_NAME, srcSnapName,
191f169c0eaSGlenn Lagasse BE_ATTR_NEW_BE_POOL, rpool,
192f169c0eaSGlenn Lagasse BE_ATTR_NEW_BE_DESC, beDescription)) {
193f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
194f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST, NULL, NULL));
195f169c0eaSGlenn Lagasse }
196f169c0eaSGlenn Lagasse
197f169c0eaSGlenn Lagasse if (beNameProperties != NULL) {
198f169c0eaSGlenn Lagasse if (nvlist_alloc(&beProps, NV_UNIQUE_NAME, 0) != 0) {
199f169c0eaSGlenn Lagasse (void) printf("nvlist_alloc failed.\n");
200f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
201f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
202f169c0eaSGlenn Lagasse NULL, NULL));
203f169c0eaSGlenn Lagasse }
204f169c0eaSGlenn Lagasse while (PyDict_Next(beNameProperties, &pos, &pkey, &pvalue)) {
205f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beProps, 2,
206f169c0eaSGlenn Lagasse PyString_AsString(pkey),
207f169c0eaSGlenn Lagasse PyString_AsString(pvalue))) {
208f169c0eaSGlenn Lagasse nvlist_free(beProps);
209f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
210f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
211f169c0eaSGlenn Lagasse NULL, NULL));
212f169c0eaSGlenn Lagasse }
213f169c0eaSGlenn Lagasse }
214f169c0eaSGlenn Lagasse }
215f169c0eaSGlenn Lagasse
216f169c0eaSGlenn Lagasse if (beProps != NULL && beAttrs != NULL &&
217f169c0eaSGlenn Lagasse nvlist_add_nvlist(beAttrs, BE_ATTR_ZFS_PROPERTIES,
218f169c0eaSGlenn Lagasse beProps) != 0) {
219f169c0eaSGlenn Lagasse nvlist_free(beProps);
220f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
221f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
222f169c0eaSGlenn Lagasse NULL, NULL));
223f169c0eaSGlenn Lagasse }
224f169c0eaSGlenn Lagasse
225*e2dcee57SJosef 'Jeff' Sipek nvlist_free(beProps);
226f169c0eaSGlenn Lagasse
227f169c0eaSGlenn Lagasse if (trgtBeName == NULL) {
228f169c0eaSGlenn Lagasse /*
229f169c0eaSGlenn Lagasse * Caller wants to get back the BE_ATTR_NEW_BE_NAME and
230f169c0eaSGlenn Lagasse * BE_ATTR_SNAP_NAME
231f169c0eaSGlenn Lagasse */
232f169c0eaSGlenn Lagasse if ((ret = be_copy(beAttrs)) != BE_SUCCESS) {
233f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
234f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", ret, NULL, NULL));
235f169c0eaSGlenn Lagasse }
236f169c0eaSGlenn Lagasse
237f169c0eaSGlenn Lagasse /*
238f169c0eaSGlenn Lagasse * When no trgtBeName is passed to be_copy, be_copy
239f169c0eaSGlenn Lagasse * returns an auto generated beName and snapshot name.
240f169c0eaSGlenn Lagasse */
241f169c0eaSGlenn Lagasse if (nvlist_lookup_string(beAttrs, BE_ATTR_NEW_BE_NAME,
242f169c0eaSGlenn Lagasse &trgtBeName) != 0) {
243f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
244f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
245f169c0eaSGlenn Lagasse NULL, NULL));
246f169c0eaSGlenn Lagasse }
247f169c0eaSGlenn Lagasse if (nvlist_lookup_string(beAttrs, BE_ATTR_SNAP_NAME,
248f169c0eaSGlenn Lagasse &trgtSnapName) != 0) {
249f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
250f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", BE_PY_ERR_NVLIST,
251f169c0eaSGlenn Lagasse NULL, NULL));
252f169c0eaSGlenn Lagasse }
253f169c0eaSGlenn Lagasse
254f169c0eaSGlenn Lagasse retVals = Py_BuildValue("[iss]", BE_PY_SUCCESS,
255f169c0eaSGlenn Lagasse trgtBeName, trgtSnapName);
256f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
257f169c0eaSGlenn Lagasse return (retVals);
258f169c0eaSGlenn Lagasse
259f169c0eaSGlenn Lagasse } else {
260f169c0eaSGlenn Lagasse ret = be_copy(beAttrs);
261f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
262f169c0eaSGlenn Lagasse return (Py_BuildValue("[iss]", ret, NULL, NULL));
263f169c0eaSGlenn Lagasse }
264f169c0eaSGlenn Lagasse }
265f169c0eaSGlenn Lagasse
266f169c0eaSGlenn Lagasse /*
267f169c0eaSGlenn Lagasse * Function: beList
268f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_list
269f169c0eaSGlenn Lagasse * to gather information about Boot Environments
270f169c0eaSGlenn Lagasse * Parameters:
271f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
272f169c0eaSGlenn Lagasse * beName - The name of the BE to list (optional)
273f169c0eaSGlenn Lagasse *
274f169c0eaSGlenn Lagasse * Returns a pointer to a python object. That Python object will consist of
275f169c0eaSGlenn Lagasse * the return code and a list of Dicts or NULL.
276f169c0eaSGlenn Lagasse * BE_PY_SUCCESS, listOfDicts - Success
277f169c0eaSGlenn Lagasse * bePyErr or be_errno_t, NULL - Failure
278f169c0eaSGlenn Lagasse * Scope:
279f169c0eaSGlenn Lagasse * Public
280f169c0eaSGlenn Lagasse */
281f169c0eaSGlenn Lagasse /* ARGSUSED */
282f169c0eaSGlenn Lagasse PyObject *
beList(PyObject * self,PyObject * args)283f169c0eaSGlenn Lagasse beList(PyObject *self, PyObject *args)
284f169c0eaSGlenn Lagasse {
285f169c0eaSGlenn Lagasse char *beName = NULL;
286f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
287f169c0eaSGlenn Lagasse be_node_list_t *list = NULL;
288f169c0eaSGlenn Lagasse be_node_list_t *be = NULL;
289f169c0eaSGlenn Lagasse PyObject *dict = NULL;
290f169c0eaSGlenn Lagasse PyObject *listOfDicts = NULL;
291f169c0eaSGlenn Lagasse
292f169c0eaSGlenn Lagasse if ((listOfDicts = PyList_New(0)) == NULL) {
293f169c0eaSGlenn Lagasse ret = BE_PY_ERR_DICT;
294f169c0eaSGlenn Lagasse listOfDicts = Py_None;
295f169c0eaSGlenn Lagasse goto done;
296f169c0eaSGlenn Lagasse }
297f169c0eaSGlenn Lagasse
298f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "|z", &beName)) {
299f169c0eaSGlenn Lagasse ret = BE_PY_ERR_PARSETUPLE;
300f169c0eaSGlenn Lagasse goto done;
301f169c0eaSGlenn Lagasse }
302f169c0eaSGlenn Lagasse
303f169c0eaSGlenn Lagasse if ((ret = be_list(beName, &list)) != BE_SUCCESS) {
304f169c0eaSGlenn Lagasse goto done;
305f169c0eaSGlenn Lagasse }
306f169c0eaSGlenn Lagasse
307f169c0eaSGlenn Lagasse for (be = list; be != NULL; be = be->be_next_node) {
308f169c0eaSGlenn Lagasse be_dataset_list_t *ds = be->be_node_datasets;
309f169c0eaSGlenn Lagasse be_snapshot_list_t *ss = be->be_node_snapshots;
310f169c0eaSGlenn Lagasse
311f169c0eaSGlenn Lagasse if ((dict = PyDict_New()) == NULL) {
312f169c0eaSGlenn Lagasse ret = BE_PY_ERR_DICT;
313f169c0eaSGlenn Lagasse goto done;
314f169c0eaSGlenn Lagasse }
315f169c0eaSGlenn Lagasse
316f169c0eaSGlenn Lagasse if (!convertBEInfoToDictionary(be, &dict)) {
317f169c0eaSGlenn Lagasse /* LINTED */
318f169c0eaSGlenn Lagasse Py_DECREF(dict);
319f169c0eaSGlenn Lagasse ret = BE_PY_ERR_VAR_CONV;
320f169c0eaSGlenn Lagasse goto done;
321f169c0eaSGlenn Lagasse }
322f169c0eaSGlenn Lagasse
323f169c0eaSGlenn Lagasse if (PyList_Append(listOfDicts, dict) != 0) {
324f169c0eaSGlenn Lagasse /* LINTED */
325f169c0eaSGlenn Lagasse Py_DECREF(dict);
326f169c0eaSGlenn Lagasse ret = BE_PY_ERR_APPEND;
327f169c0eaSGlenn Lagasse goto done;
328f169c0eaSGlenn Lagasse }
329f169c0eaSGlenn Lagasse
330f169c0eaSGlenn Lagasse /* LINTED */
331f169c0eaSGlenn Lagasse Py_DECREF(dict);
332f169c0eaSGlenn Lagasse
333f169c0eaSGlenn Lagasse while (ds != NULL) {
334f169c0eaSGlenn Lagasse if ((dict = PyDict_New()) == NULL) {
335f169c0eaSGlenn Lagasse ret = BE_PY_ERR_DICT;
336f169c0eaSGlenn Lagasse goto done;
337f169c0eaSGlenn Lagasse }
338f169c0eaSGlenn Lagasse
339f169c0eaSGlenn Lagasse if (!convertDatasetInfoToDictionary(ds, &dict)) {
340f169c0eaSGlenn Lagasse /* LINTED */
341f169c0eaSGlenn Lagasse Py_DECREF(dict);
342f169c0eaSGlenn Lagasse ret = BE_PY_ERR_VAR_CONV;
343f169c0eaSGlenn Lagasse goto done;
344f169c0eaSGlenn Lagasse }
345f169c0eaSGlenn Lagasse
346f169c0eaSGlenn Lagasse if (PyList_Append(listOfDicts, dict) != 0) {
347f169c0eaSGlenn Lagasse /* LINTED */
348f169c0eaSGlenn Lagasse Py_DECREF(dict);
349f169c0eaSGlenn Lagasse ret = BE_PY_ERR_APPEND;
350f169c0eaSGlenn Lagasse goto done;
351f169c0eaSGlenn Lagasse }
352f169c0eaSGlenn Lagasse
353f169c0eaSGlenn Lagasse ds = ds->be_next_dataset;
354f169c0eaSGlenn Lagasse
355f169c0eaSGlenn Lagasse /* LINTED */
356f169c0eaSGlenn Lagasse Py_DECREF(dict);
357f169c0eaSGlenn Lagasse }
358f169c0eaSGlenn Lagasse
359f169c0eaSGlenn Lagasse
360f169c0eaSGlenn Lagasse while (ss != NULL) {
361f169c0eaSGlenn Lagasse if ((dict = PyDict_New()) == NULL) {
362f169c0eaSGlenn Lagasse /* LINTED */
363f169c0eaSGlenn Lagasse Py_DECREF(dict);
364f169c0eaSGlenn Lagasse ret = BE_PY_ERR_DICT;
365f169c0eaSGlenn Lagasse goto done;
366f169c0eaSGlenn Lagasse }
367f169c0eaSGlenn Lagasse
368f169c0eaSGlenn Lagasse if (!convertSnapshotInfoToDictionary(ss, &dict)) {
369f169c0eaSGlenn Lagasse /* LINTED */
370f169c0eaSGlenn Lagasse Py_DECREF(dict);
371f169c0eaSGlenn Lagasse ret = BE_PY_ERR_VAR_CONV;
372f169c0eaSGlenn Lagasse goto done;
373f169c0eaSGlenn Lagasse }
374f169c0eaSGlenn Lagasse
375f169c0eaSGlenn Lagasse if (PyList_Append(listOfDicts, dict) != 0) {
376f169c0eaSGlenn Lagasse /* LINTED */
377f169c0eaSGlenn Lagasse Py_DECREF(dict);
378f169c0eaSGlenn Lagasse ret = BE_PY_ERR_APPEND;
379f169c0eaSGlenn Lagasse goto done;
380f169c0eaSGlenn Lagasse }
381f169c0eaSGlenn Lagasse
382f169c0eaSGlenn Lagasse ss = ss->be_next_snapshot;
383f169c0eaSGlenn Lagasse
384f169c0eaSGlenn Lagasse /* LINTED */
385f169c0eaSGlenn Lagasse Py_DECREF(dict);
386f169c0eaSGlenn Lagasse }
387f169c0eaSGlenn Lagasse }
388f169c0eaSGlenn Lagasse
389f169c0eaSGlenn Lagasse done:
390f169c0eaSGlenn Lagasse if (list != NULL)
391f169c0eaSGlenn Lagasse be_free_list(list);
392f169c0eaSGlenn Lagasse return (Py_BuildValue("[iO]", ret, listOfDicts));
393f169c0eaSGlenn Lagasse }
394f169c0eaSGlenn Lagasse
395f169c0eaSGlenn Lagasse /*
396f169c0eaSGlenn Lagasse * Function: beActivate
397f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_activate
398f169c0eaSGlenn Lagasse * to activate a Boot Environment
399f169c0eaSGlenn Lagasse * Parameters:
400f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
401f169c0eaSGlenn Lagasse * beName - The name of the BE to activate
402f169c0eaSGlenn Lagasse *
403f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
404f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
405f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
406f169c0eaSGlenn Lagasse * Scope:
407f169c0eaSGlenn Lagasse * Public
408f169c0eaSGlenn Lagasse */
409f169c0eaSGlenn Lagasse /* ARGSUSED */
410f169c0eaSGlenn Lagasse PyObject *
beActivate(PyObject * self,PyObject * args)411f169c0eaSGlenn Lagasse beActivate(PyObject *self, PyObject *args)
412f169c0eaSGlenn Lagasse {
413f169c0eaSGlenn Lagasse char *beName = NULL;
414f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
415f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
416f169c0eaSGlenn Lagasse
417f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "z", &beName)) {
418f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
419f169c0eaSGlenn Lagasse }
420f169c0eaSGlenn Lagasse
421f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 2, BE_ATTR_ORIG_BE_NAME, beName)) {
422f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
423f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
424f169c0eaSGlenn Lagasse }
425f169c0eaSGlenn Lagasse
426f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
427f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
428f169c0eaSGlenn Lagasse }
429f169c0eaSGlenn Lagasse
430f169c0eaSGlenn Lagasse ret = be_activate(beAttrs);
431f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
432f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
433f169c0eaSGlenn Lagasse }
434f169c0eaSGlenn Lagasse
435f169c0eaSGlenn Lagasse /*
436f169c0eaSGlenn Lagasse * Function: beDestroy
437f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_destroy
438f169c0eaSGlenn Lagasse * to destroy a Boot Environment
439f169c0eaSGlenn Lagasse * Parameters:
440f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
441f169c0eaSGlenn Lagasse * beName - The name of the BE to destroy
442f169c0eaSGlenn Lagasse *
443f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
444f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
445f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
446f169c0eaSGlenn Lagasse * Scope:
447f169c0eaSGlenn Lagasse * Public
448f169c0eaSGlenn Lagasse */
449f169c0eaSGlenn Lagasse /* ARGSUSED */
450f169c0eaSGlenn Lagasse PyObject *
beDestroy(PyObject * self,PyObject * args)451f169c0eaSGlenn Lagasse beDestroy(PyObject *self, PyObject *args)
452f169c0eaSGlenn Lagasse {
453f169c0eaSGlenn Lagasse char *beName = NULL;
454f169c0eaSGlenn Lagasse int destroy_snaps = 0;
455f169c0eaSGlenn Lagasse int force_unmount = 0;
456f169c0eaSGlenn Lagasse int destroy_flags = 0;
457f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
458f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
459f169c0eaSGlenn Lagasse
460f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "z|ii", &beName, &destroy_snaps,
461f169c0eaSGlenn Lagasse &force_unmount)) {
462f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
463f169c0eaSGlenn Lagasse }
464f169c0eaSGlenn Lagasse
465f169c0eaSGlenn Lagasse if (destroy_snaps == 1)
466f169c0eaSGlenn Lagasse destroy_flags |= BE_DESTROY_FLAG_SNAPSHOTS;
467f169c0eaSGlenn Lagasse
468f169c0eaSGlenn Lagasse if (force_unmount == 1)
469f169c0eaSGlenn Lagasse destroy_flags |= BE_DESTROY_FLAG_FORCE_UNMOUNT;
470f169c0eaSGlenn Lagasse
471f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 2, BE_ATTR_ORIG_BE_NAME, beName)) {
472f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
473f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
474f169c0eaSGlenn Lagasse }
475f169c0eaSGlenn Lagasse
476f169c0eaSGlenn Lagasse if (nvlist_add_uint16(beAttrs, BE_ATTR_DESTROY_FLAGS, destroy_flags)
477f169c0eaSGlenn Lagasse != 0) {
478f169c0eaSGlenn Lagasse (void) printf("nvlist_add_uint16 failed for "
479f169c0eaSGlenn Lagasse "BE_ATTR_DESTROY_FLAGS (%d).\n", destroy_flags);
480f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
481f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
482f169c0eaSGlenn Lagasse }
483f169c0eaSGlenn Lagasse
484f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
485f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
486f169c0eaSGlenn Lagasse }
487f169c0eaSGlenn Lagasse
488f169c0eaSGlenn Lagasse ret = be_destroy(beAttrs);
489f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
490f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
491f169c0eaSGlenn Lagasse }
492f169c0eaSGlenn Lagasse
493f169c0eaSGlenn Lagasse /*
494f169c0eaSGlenn Lagasse * Function: beDestroySnapshot
495f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_destroy
496f169c0eaSGlenn Lagasse * to destroy a snapshot of a Boot Environment
497f169c0eaSGlenn Lagasse * Parameters:
498f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
499f169c0eaSGlenn Lagasse * beName - The name of the BE to destroy
500f169c0eaSGlenn Lagasse * snapName - The name of the snapshot to destroy
501f169c0eaSGlenn Lagasse *
502f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
503f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
504f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
505f169c0eaSGlenn Lagasse * Scope:
506f169c0eaSGlenn Lagasse * Public
507f169c0eaSGlenn Lagasse */
508f169c0eaSGlenn Lagasse /* ARGSUSED */
509f169c0eaSGlenn Lagasse PyObject *
beDestroySnapshot(PyObject * self,PyObject * args)510f169c0eaSGlenn Lagasse beDestroySnapshot(PyObject *self, PyObject *args)
511f169c0eaSGlenn Lagasse {
512f169c0eaSGlenn Lagasse char *beName = NULL;
513f169c0eaSGlenn Lagasse char *snapName = NULL;
514f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
515f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
516f169c0eaSGlenn Lagasse
517f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "zz", &beName, &snapName)) {
518f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
519f169c0eaSGlenn Lagasse }
520f169c0eaSGlenn Lagasse
521f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 4,
522f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, beName,
523f169c0eaSGlenn Lagasse BE_ATTR_SNAP_NAME, snapName)) {
524f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
525f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
526f169c0eaSGlenn Lagasse }
527f169c0eaSGlenn Lagasse
528f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
529f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
530f169c0eaSGlenn Lagasse }
531f169c0eaSGlenn Lagasse
532f169c0eaSGlenn Lagasse ret = be_destroy_snapshot(beAttrs);
533f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
534f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
535f169c0eaSGlenn Lagasse }
536f169c0eaSGlenn Lagasse
537f169c0eaSGlenn Lagasse /*
538f169c0eaSGlenn Lagasse * Function: beRename
539f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_rename
540f169c0eaSGlenn Lagasse * to rename a Boot Environment
541f169c0eaSGlenn Lagasse * Parameters:
542f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
543f169c0eaSGlenn Lagasse * oldBeName - The name of the old Boot Environment
544f169c0eaSGlenn Lagasse * newBeName - The name of the new Boot Environment
545f169c0eaSGlenn Lagasse *
546f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
547f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
548f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
549f169c0eaSGlenn Lagasse * Scope:
550f169c0eaSGlenn Lagasse * Public
551f169c0eaSGlenn Lagasse */
552f169c0eaSGlenn Lagasse /* ARGSUSED */
553f169c0eaSGlenn Lagasse PyObject *
beRename(PyObject * self,PyObject * args)554f169c0eaSGlenn Lagasse beRename(PyObject *self, PyObject *args)
555f169c0eaSGlenn Lagasse {
556f169c0eaSGlenn Lagasse char *oldBeName = NULL;
557f169c0eaSGlenn Lagasse char *newBeName = NULL;
558f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
559f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
560f169c0eaSGlenn Lagasse
561f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "zz", &oldBeName, &newBeName)) {
562f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
563f169c0eaSGlenn Lagasse }
564f169c0eaSGlenn Lagasse
565f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 4,
566f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, oldBeName,
567f169c0eaSGlenn Lagasse BE_ATTR_NEW_BE_NAME, newBeName)) {
568f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
569f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
570f169c0eaSGlenn Lagasse }
571f169c0eaSGlenn Lagasse
572f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
573f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
574f169c0eaSGlenn Lagasse }
575f169c0eaSGlenn Lagasse
576f169c0eaSGlenn Lagasse ret = be_rename(beAttrs);
577f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
578f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
579f169c0eaSGlenn Lagasse }
580f169c0eaSGlenn Lagasse
581f169c0eaSGlenn Lagasse /*
582f169c0eaSGlenn Lagasse * Function: beMount
583f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_mount
584f169c0eaSGlenn Lagasse * to mount a Boot Environment
585f169c0eaSGlenn Lagasse * Parameters:
586f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
587f169c0eaSGlenn Lagasse * beName - The name of the Boot Environment to mount
588f169c0eaSGlenn Lagasse * mountpoint - The path of the mountpoint to mount the
589f169c0eaSGlenn Lagasse * Boot Environment on (optional)
590f169c0eaSGlenn Lagasse *
591f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
592f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
593f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
594f169c0eaSGlenn Lagasse * Scope:
595f169c0eaSGlenn Lagasse * Public
596f169c0eaSGlenn Lagasse */
597f169c0eaSGlenn Lagasse /* ARGSUSED */
598f169c0eaSGlenn Lagasse PyObject *
beMount(PyObject * self,PyObject * args)599f169c0eaSGlenn Lagasse beMount(PyObject *self, PyObject *args)
600f169c0eaSGlenn Lagasse {
601f169c0eaSGlenn Lagasse char *beName = NULL;
602f169c0eaSGlenn Lagasse char *mountpoint = NULL;
603f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
604f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
605f169c0eaSGlenn Lagasse
606f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "zz", &beName, &mountpoint)) {
607f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
608f169c0eaSGlenn Lagasse }
609f169c0eaSGlenn Lagasse
610f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 4,
611f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, beName,
612f169c0eaSGlenn Lagasse BE_ATTR_MOUNTPOINT, mountpoint)) {
613f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
614f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
615f169c0eaSGlenn Lagasse }
616f169c0eaSGlenn Lagasse
617f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
618f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
619f169c0eaSGlenn Lagasse }
620f169c0eaSGlenn Lagasse
621f169c0eaSGlenn Lagasse ret = be_mount(beAttrs);
622f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
623f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
624f169c0eaSGlenn Lagasse }
625f169c0eaSGlenn Lagasse
626f169c0eaSGlenn Lagasse /*
627f169c0eaSGlenn Lagasse * Function: beUnmount
628f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_unmount
629f169c0eaSGlenn Lagasse * to unmount a Boot Environment
630f169c0eaSGlenn Lagasse * Parameters:
631f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
632f169c0eaSGlenn Lagasse * beName - The name of the Boot Environment to unmount
633f169c0eaSGlenn Lagasse *
634f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
635f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
636f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
637f169c0eaSGlenn Lagasse * Scope:
638f169c0eaSGlenn Lagasse * Public
639f169c0eaSGlenn Lagasse */
640f169c0eaSGlenn Lagasse /* ARGSUSED */
641f169c0eaSGlenn Lagasse PyObject *
beUnmount(PyObject * self,PyObject * args)642f169c0eaSGlenn Lagasse beUnmount(PyObject *self, PyObject *args)
643f169c0eaSGlenn Lagasse {
644f169c0eaSGlenn Lagasse char *beName = NULL;
645f169c0eaSGlenn Lagasse int force_unmount = 0;
646f169c0eaSGlenn Lagasse int unmount_flags = 0;
647f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
648f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
649f169c0eaSGlenn Lagasse
650f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "z|i", &beName, &force_unmount)) {
651f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
652f169c0eaSGlenn Lagasse }
653f169c0eaSGlenn Lagasse
654f169c0eaSGlenn Lagasse if (force_unmount == 1)
655f169c0eaSGlenn Lagasse unmount_flags |= BE_UNMOUNT_FLAG_FORCE;
656f169c0eaSGlenn Lagasse
657f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 2,
658f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, beName)) {
659f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
660f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
661f169c0eaSGlenn Lagasse }
662f169c0eaSGlenn Lagasse
663f169c0eaSGlenn Lagasse if (nvlist_add_uint16(beAttrs, BE_ATTR_UNMOUNT_FLAGS, unmount_flags)
664f169c0eaSGlenn Lagasse != 0) {
665f169c0eaSGlenn Lagasse (void) printf("nvlist_add_uint16 failed for "
666f169c0eaSGlenn Lagasse "BE_ATTR_UNMOUNT_FLAGS (%d).\n", unmount_flags);
667f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
668f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
669f169c0eaSGlenn Lagasse }
670f169c0eaSGlenn Lagasse
671f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
672f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
673f169c0eaSGlenn Lagasse }
674f169c0eaSGlenn Lagasse
675f169c0eaSGlenn Lagasse ret = be_unmount(beAttrs);
676f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
677f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
678f169c0eaSGlenn Lagasse }
679f169c0eaSGlenn Lagasse
680f169c0eaSGlenn Lagasse /*
681f169c0eaSGlenn Lagasse * Function: beRollback
682f169c0eaSGlenn Lagasse * Description: Convert Python args to nvlist pairs and call libbe:be_rollback
683f169c0eaSGlenn Lagasse * to rollback a Boot Environment to a previously taken
684f169c0eaSGlenn Lagasse * snapshot.
685f169c0eaSGlenn Lagasse * Parameters:
686f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
687f169c0eaSGlenn Lagasse * beName - The name of the Boot Environment to unmount
688f169c0eaSGlenn Lagasse *
689f169c0eaSGlenn Lagasse * Returns a pointer to a python object:
690f169c0eaSGlenn Lagasse * BE_SUCCESS - Success
691f169c0eaSGlenn Lagasse * bePyErr or be_errno_t - Failure
692f169c0eaSGlenn Lagasse * Scope:
693f169c0eaSGlenn Lagasse * Public
694f169c0eaSGlenn Lagasse */
695f169c0eaSGlenn Lagasse /* ARGSUSED */
696f169c0eaSGlenn Lagasse PyObject *
beRollback(PyObject * self,PyObject * args)697f169c0eaSGlenn Lagasse beRollback(PyObject *self, PyObject *args)
698f169c0eaSGlenn Lagasse {
699f169c0eaSGlenn Lagasse char *beName = NULL;
700f169c0eaSGlenn Lagasse char *snapName = NULL;
701f169c0eaSGlenn Lagasse int ret = BE_PY_SUCCESS;
702f169c0eaSGlenn Lagasse nvlist_t *beAttrs = NULL;
703f169c0eaSGlenn Lagasse
704f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "zz", &beName, &snapName)) {
705f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PARSETUPLE));
706f169c0eaSGlenn Lagasse }
707f169c0eaSGlenn Lagasse
708f169c0eaSGlenn Lagasse if (!convertPyArgsToNvlist(&beAttrs, 4,
709f169c0eaSGlenn Lagasse BE_ATTR_ORIG_BE_NAME, beName,
710f169c0eaSGlenn Lagasse BE_ATTR_SNAP_NAME, snapName)) {
711f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
712f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
713f169c0eaSGlenn Lagasse }
714f169c0eaSGlenn Lagasse
715f169c0eaSGlenn Lagasse if (beAttrs == NULL) {
716f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_NVLIST));
717f169c0eaSGlenn Lagasse }
718f169c0eaSGlenn Lagasse
719f169c0eaSGlenn Lagasse ret = be_rollback(beAttrs);
720f169c0eaSGlenn Lagasse nvlist_free(beAttrs);
721f169c0eaSGlenn Lagasse return (Py_BuildValue("i", ret));
722f169c0eaSGlenn Lagasse }
723f169c0eaSGlenn Lagasse
724f169c0eaSGlenn Lagasse /*
725f169c0eaSGlenn Lagasse * Function: bePrintErrors
726f169c0eaSGlenn Lagasse * Description: Convert Python args to boolean and call libbe_print_errors to
727f169c0eaSGlenn Lagasse * turn on/off error output for the library.
728f169c0eaSGlenn Lagasse * Parameter:
729f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
730f169c0eaSGlenn Lagasse * print_errors - Boolean that turns library error
731f169c0eaSGlenn Lagasse * printing on or off.
732f169c0eaSGlenn Lagasse * Parameters:
733f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
734f169c0eaSGlenn Lagasse * 0 - do not print errors - Python boolean "False"
735f169c0eaSGlenn Lagasse * 1 - print errors - Python boolean "True"
736f169c0eaSGlenn Lagasse *
737f169c0eaSGlenn Lagasse * Returns 1 on missing or invalid argument, 0 otherwise
738f169c0eaSGlenn Lagasse * Scope:
739f169c0eaSGlenn Lagasse * Public
740f169c0eaSGlenn Lagasse */
741f169c0eaSGlenn Lagasse /* ARGSUSED */
742f169c0eaSGlenn Lagasse PyObject *
bePrintErrors(PyObject * self,PyObject * args)743f169c0eaSGlenn Lagasse bePrintErrors(PyObject *self, PyObject *args)
744f169c0eaSGlenn Lagasse {
745f169c0eaSGlenn Lagasse int print_errors;
746f169c0eaSGlenn Lagasse
747f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "i", &print_errors) ||
748f169c0eaSGlenn Lagasse (print_errors != 1 && print_errors != 0))
749f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_ERR_PRINT_ERR));
750f169c0eaSGlenn Lagasse libbe_print_errors(print_errors == 1);
751f169c0eaSGlenn Lagasse return (Py_BuildValue("i", BE_PY_SUCCESS));
752f169c0eaSGlenn Lagasse }
753f169c0eaSGlenn Lagasse
754f169c0eaSGlenn Lagasse /*
755f169c0eaSGlenn Lagasse * Function: beGetErrDesc
756f169c0eaSGlenn Lagasse * Description: Convert Python args to an int and call be_err_to_str to
757f169c0eaSGlenn Lagasse * map an error code to an error string.
758f169c0eaSGlenn Lagasse * Parameter:
759f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
760f169c0eaSGlenn Lagasse * errCode - value to map to an error string.
761f169c0eaSGlenn Lagasse *
762f169c0eaSGlenn Lagasse * Returns: error string or NULL
763f169c0eaSGlenn Lagasse * Scope:
764f169c0eaSGlenn Lagasse * Public
765f169c0eaSGlenn Lagasse */
766f169c0eaSGlenn Lagasse /* ARGSUSED */
767f169c0eaSGlenn Lagasse PyObject *
beGetErrDesc(PyObject * self,PyObject * args)768f169c0eaSGlenn Lagasse beGetErrDesc(PyObject *self, PyObject *args)
769f169c0eaSGlenn Lagasse {
770f169c0eaSGlenn Lagasse int errCode = 0;
771f169c0eaSGlenn Lagasse char *beErrStr = NULL;
772f169c0eaSGlenn Lagasse
773f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "i", &errCode)) {
774f169c0eaSGlenn Lagasse return (Py_BuildValue("s", NULL));
775f169c0eaSGlenn Lagasse }
776f169c0eaSGlenn Lagasse
777f169c0eaSGlenn Lagasse /*
778f169c0eaSGlenn Lagasse * First check libbe_py errors. If NULL is returned check error codes
779f169c0eaSGlenn Lagasse * in libbe.
780f169c0eaSGlenn Lagasse */
781f169c0eaSGlenn Lagasse
782f169c0eaSGlenn Lagasse if ((beErrStr = beMapLibbePyErrorToString(errCode)) == NULL) {
783f169c0eaSGlenn Lagasse beErrStr = be_err_to_str(errCode);
784f169c0eaSGlenn Lagasse }
785f169c0eaSGlenn Lagasse
786f169c0eaSGlenn Lagasse return (Py_BuildValue("s", beErrStr));
787f169c0eaSGlenn Lagasse }
788f169c0eaSGlenn Lagasse
789f169c0eaSGlenn Lagasse /*
790f169c0eaSGlenn Lagasse * Function: beVerifyBEName
791f169c0eaSGlenn Lagasse * Description: Call be_valid_be_name() to verify the BE name.
792f169c0eaSGlenn Lagasse * Parameter:
793f169c0eaSGlenn Lagasse * args - pointer to a python object containing:
794f169c0eaSGlenn Lagasse * string - value to map to a string.
795f169c0eaSGlenn Lagasse *
796f169c0eaSGlenn Lagasse * Returns: 0 for success or 1 for failure
797f169c0eaSGlenn Lagasse * Scope:
798f169c0eaSGlenn Lagasse * Public
799f169c0eaSGlenn Lagasse */
800f169c0eaSGlenn Lagasse /* ARGSUSED */
801f169c0eaSGlenn Lagasse PyObject *
beVerifyBEName(PyObject * self,PyObject * args)802f169c0eaSGlenn Lagasse beVerifyBEName(PyObject *self, PyObject *args)
803f169c0eaSGlenn Lagasse {
804f169c0eaSGlenn Lagasse char *string = NULL;
805f169c0eaSGlenn Lagasse
806f169c0eaSGlenn Lagasse if (!PyArg_ParseTuple(args, "s", &string)) {
807f169c0eaSGlenn Lagasse return (Py_BuildValue("i", 1));
808f169c0eaSGlenn Lagasse }
809f169c0eaSGlenn Lagasse
810f169c0eaSGlenn Lagasse if (be_valid_be_name(string)) {
811f169c0eaSGlenn Lagasse return (Py_BuildValue("i", 0));
812f169c0eaSGlenn Lagasse } else {
813f169c0eaSGlenn Lagasse return (Py_BuildValue("i", 1));
814f169c0eaSGlenn Lagasse }
815f169c0eaSGlenn Lagasse }
816f169c0eaSGlenn Lagasse
817f169c0eaSGlenn Lagasse /* ~~~~~~~~~~~~~~~~~ */
818f169c0eaSGlenn Lagasse /* Private Functions */
819f169c0eaSGlenn Lagasse /* ~~~~~~~~~~~~~~~~~ */
820f169c0eaSGlenn Lagasse
821f169c0eaSGlenn Lagasse static boolean_t
convertBEInfoToDictionary(be_node_list_t * be,PyObject ** listDict)822f169c0eaSGlenn Lagasse convertBEInfoToDictionary(be_node_list_t *be, PyObject **listDict)
823f169c0eaSGlenn Lagasse {
824f169c0eaSGlenn Lagasse if (be->be_node_name != NULL) {
825f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_ORIG_BE_NAME,
826f169c0eaSGlenn Lagasse PyString_FromString(be->be_node_name)) != 0) {
827f169c0eaSGlenn Lagasse return (B_FALSE);
828f169c0eaSGlenn Lagasse }
829f169c0eaSGlenn Lagasse }
830f169c0eaSGlenn Lagasse
831f169c0eaSGlenn Lagasse if (be->be_rpool != NULL) {
832f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_ORIG_BE_POOL,
833f169c0eaSGlenn Lagasse PyString_FromString(be->be_rpool)) != 0) {
834f169c0eaSGlenn Lagasse return (B_FALSE);
835f169c0eaSGlenn Lagasse }
836f169c0eaSGlenn Lagasse }
837f169c0eaSGlenn Lagasse
838f169c0eaSGlenn Lagasse if (be->be_mntpt != NULL) {
839f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTPOINT,
840f169c0eaSGlenn Lagasse PyString_FromString(be->be_mntpt)) != 0) {
841f169c0eaSGlenn Lagasse return (B_FALSE);
842f169c0eaSGlenn Lagasse }
843f169c0eaSGlenn Lagasse }
844f169c0eaSGlenn Lagasse
845f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTED,
846f169c0eaSGlenn Lagasse (be->be_mounted ? Py_True : Py_False)) != 0) {
847f169c0eaSGlenn Lagasse return (B_FALSE);
848f169c0eaSGlenn Lagasse }
849f169c0eaSGlenn Lagasse
850f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_ACTIVE,
851f169c0eaSGlenn Lagasse (be->be_active ? Py_True : Py_False)) != 0) {
852f169c0eaSGlenn Lagasse return (B_FALSE);
853f169c0eaSGlenn Lagasse }
854f169c0eaSGlenn Lagasse
855f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_ACTIVE_ON_BOOT,
856f169c0eaSGlenn Lagasse (be->be_active_on_boot ? Py_True : Py_False)) != 0) {
857f169c0eaSGlenn Lagasse return (B_FALSE);
858f169c0eaSGlenn Lagasse }
859f169c0eaSGlenn Lagasse
860a74909fdSAlexander Pyhalov if (PyDict_SetItemString(*listDict, BE_ATTR_GLOBAL_ACTIVE,
861a74909fdSAlexander Pyhalov (be->be_global_active ? Py_True : Py_False)) != 0) {
862a74909fdSAlexander Pyhalov return (B_FALSE);
863a74909fdSAlexander Pyhalov }
864a74909fdSAlexander Pyhalov
865f169c0eaSGlenn Lagasse if (be->be_space_used != 0) {
866f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_SPACE,
867f169c0eaSGlenn Lagasse PyLong_FromUnsignedLongLong(be->be_space_used)) != 0) {
868f169c0eaSGlenn Lagasse return (B_FALSE);
869f169c0eaSGlenn Lagasse }
870f169c0eaSGlenn Lagasse }
871f169c0eaSGlenn Lagasse
872f169c0eaSGlenn Lagasse if (be->be_root_ds != NULL) {
873f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_ROOT_DS,
874f169c0eaSGlenn Lagasse PyString_FromString(be->be_root_ds)) != 0) {
875f169c0eaSGlenn Lagasse return (B_FALSE);
876f169c0eaSGlenn Lagasse }
877f169c0eaSGlenn Lagasse }
878f169c0eaSGlenn Lagasse
879f169c0eaSGlenn Lagasse if (be->be_node_creation != NULL) {
880f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_DATE,
881f169c0eaSGlenn Lagasse PyLong_FromLong(be->be_node_creation)) != 0) {
882f169c0eaSGlenn Lagasse return (B_FALSE);
883f169c0eaSGlenn Lagasse }
884f169c0eaSGlenn Lagasse }
885f169c0eaSGlenn Lagasse
886f169c0eaSGlenn Lagasse if (be->be_policy_type != NULL) {
887f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
888f169c0eaSGlenn Lagasse PyString_FromString(be->be_policy_type)) != 0) {
889f169c0eaSGlenn Lagasse return (B_FALSE);
890f169c0eaSGlenn Lagasse }
891f169c0eaSGlenn Lagasse }
892f169c0eaSGlenn Lagasse
893f169c0eaSGlenn Lagasse if (be->be_uuid_str != NULL) {
894f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_UUID_STR,
895f169c0eaSGlenn Lagasse PyString_FromString(be->be_uuid_str)) != 0) {
896f169c0eaSGlenn Lagasse return (B_FALSE);
897f169c0eaSGlenn Lagasse }
898f169c0eaSGlenn Lagasse }
899f169c0eaSGlenn Lagasse
900f169c0eaSGlenn Lagasse return (B_TRUE);
901f169c0eaSGlenn Lagasse }
902f169c0eaSGlenn Lagasse
903f169c0eaSGlenn Lagasse static boolean_t
convertDatasetInfoToDictionary(be_dataset_list_t * ds,PyObject ** listDict)904f169c0eaSGlenn Lagasse convertDatasetInfoToDictionary(be_dataset_list_t *ds, PyObject **listDict)
905f169c0eaSGlenn Lagasse {
906f169c0eaSGlenn Lagasse if (ds->be_dataset_name != NULL) {
907f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_DATASET,
908f169c0eaSGlenn Lagasse PyString_FromString(ds->be_dataset_name)) != 0) {
909f169c0eaSGlenn Lagasse return (B_FALSE);
910f169c0eaSGlenn Lagasse }
911f169c0eaSGlenn Lagasse }
912f169c0eaSGlenn Lagasse
913f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_STATUS,
914f169c0eaSGlenn Lagasse (ds->be_ds_mounted ? Py_True : Py_False)) != 0) {
915f169c0eaSGlenn Lagasse return (B_FALSE);
916f169c0eaSGlenn Lagasse }
917f169c0eaSGlenn Lagasse
918f169c0eaSGlenn Lagasse if (ds->be_ds_mntpt != NULL) {
919f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTPOINT,
920f169c0eaSGlenn Lagasse PyString_FromString(ds->be_ds_mntpt)) != 0) {
921f169c0eaSGlenn Lagasse return (B_FALSE);
922f169c0eaSGlenn Lagasse }
923f169c0eaSGlenn Lagasse }
924f169c0eaSGlenn Lagasse
925f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_MOUNTED,
926f169c0eaSGlenn Lagasse (ds->be_ds_mounted ? Py_True : Py_False)) != 0) {
927f169c0eaSGlenn Lagasse return (B_FALSE);
928f169c0eaSGlenn Lagasse }
929f169c0eaSGlenn Lagasse
930f169c0eaSGlenn Lagasse if (ds->be_ds_space_used != 0) {
931f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_SPACE,
932f169c0eaSGlenn Lagasse PyLong_FromUnsignedLongLong(ds->be_ds_space_used))
933f169c0eaSGlenn Lagasse != 0) {
934f169c0eaSGlenn Lagasse return (B_FALSE);
935f169c0eaSGlenn Lagasse }
936f169c0eaSGlenn Lagasse }
937f169c0eaSGlenn Lagasse
938f169c0eaSGlenn Lagasse if (ds->be_dataset_name != 0) {
939f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_DATASET,
940f169c0eaSGlenn Lagasse PyString_FromString(ds->be_dataset_name)) != 0) {
941f169c0eaSGlenn Lagasse return (B_FALSE);
942f169c0eaSGlenn Lagasse }
943f169c0eaSGlenn Lagasse }
944f169c0eaSGlenn Lagasse
945f169c0eaSGlenn Lagasse if (ds->be_ds_plcy_type != NULL) {
946f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
947f169c0eaSGlenn Lagasse PyString_FromString(ds->be_ds_plcy_type)) != 0) {
948f169c0eaSGlenn Lagasse return (B_FALSE);
949f169c0eaSGlenn Lagasse }
950f169c0eaSGlenn Lagasse }
951f169c0eaSGlenn Lagasse
952f169c0eaSGlenn Lagasse if (ds->be_ds_creation != NULL) {
953f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_DATE,
954f169c0eaSGlenn Lagasse PyLong_FromLong(ds->be_ds_creation)) != 0) {
955f169c0eaSGlenn Lagasse return (B_FALSE);
956f169c0eaSGlenn Lagasse }
957f169c0eaSGlenn Lagasse }
958f169c0eaSGlenn Lagasse
959f169c0eaSGlenn Lagasse return (B_TRUE);
960f169c0eaSGlenn Lagasse }
961f169c0eaSGlenn Lagasse
962f169c0eaSGlenn Lagasse static boolean_t
convertSnapshotInfoToDictionary(be_snapshot_list_t * ss,PyObject ** listDict)963f169c0eaSGlenn Lagasse convertSnapshotInfoToDictionary(be_snapshot_list_t *ss, PyObject **listDict)
964f169c0eaSGlenn Lagasse {
965f169c0eaSGlenn Lagasse if (ss->be_snapshot_name != NULL) {
966f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_SNAP_NAME,
967f169c0eaSGlenn Lagasse PyString_FromString(ss->be_snapshot_name)) != 0) {
968f169c0eaSGlenn Lagasse return (B_FALSE);
969f169c0eaSGlenn Lagasse }
970f169c0eaSGlenn Lagasse }
971f169c0eaSGlenn Lagasse
972f169c0eaSGlenn Lagasse if (ss->be_snapshot_creation != NULL) {
973f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_DATE,
974f169c0eaSGlenn Lagasse PyLong_FromLong(ss->be_snapshot_creation)) != 0) {
975f169c0eaSGlenn Lagasse return (B_FALSE);
976f169c0eaSGlenn Lagasse }
977f169c0eaSGlenn Lagasse }
978f169c0eaSGlenn Lagasse
979f169c0eaSGlenn Lagasse if (ss->be_snapshot_type != NULL) {
980f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_POLICY,
981f169c0eaSGlenn Lagasse PyString_FromString(ss->be_snapshot_type)) != 0) {
982f169c0eaSGlenn Lagasse return (B_FALSE);
983f169c0eaSGlenn Lagasse }
984f169c0eaSGlenn Lagasse }
985f169c0eaSGlenn Lagasse
986f169c0eaSGlenn Lagasse if (ss->be_snapshot_space_used != 0) {
987f169c0eaSGlenn Lagasse if (PyDict_SetItemString(*listDict, BE_ATTR_SPACE,
988f169c0eaSGlenn Lagasse PyLong_FromUnsignedLongLong(ss->be_snapshot_space_used))
989f169c0eaSGlenn Lagasse != 0) {
990f169c0eaSGlenn Lagasse return (B_FALSE);
991f169c0eaSGlenn Lagasse }
992f169c0eaSGlenn Lagasse }
993f169c0eaSGlenn Lagasse
994f169c0eaSGlenn Lagasse return (B_TRUE);
995f169c0eaSGlenn Lagasse }
996f169c0eaSGlenn Lagasse
997f169c0eaSGlenn Lagasse /*
998f169c0eaSGlenn Lagasse * Convert string arguments to nvlist attributes
999f169c0eaSGlenn Lagasse */
1000f169c0eaSGlenn Lagasse
1001f169c0eaSGlenn Lagasse static boolean_t
convertPyArgsToNvlist(nvlist_t ** nvList,int numArgs,...)1002f169c0eaSGlenn Lagasse convertPyArgsToNvlist(nvlist_t **nvList, int numArgs, ...)
1003f169c0eaSGlenn Lagasse {
1004f169c0eaSGlenn Lagasse char *pt, *pt2;
1005f169c0eaSGlenn Lagasse va_list ap;
1006f169c0eaSGlenn Lagasse int i;
1007f169c0eaSGlenn Lagasse
1008f169c0eaSGlenn Lagasse if (*nvList == NULL) {
1009f169c0eaSGlenn Lagasse if (nvlist_alloc(nvList, NV_UNIQUE_NAME, 0) != 0) {
1010f169c0eaSGlenn Lagasse (void) printf("nvlist_alloc failed.\n");
1011f169c0eaSGlenn Lagasse return (B_FALSE);
1012f169c0eaSGlenn Lagasse }
1013f169c0eaSGlenn Lagasse }
1014f169c0eaSGlenn Lagasse
1015f169c0eaSGlenn Lagasse va_start(ap, numArgs);
1016f169c0eaSGlenn Lagasse
1017f169c0eaSGlenn Lagasse for (i = 0; i < numArgs; i += 2) {
1018f169c0eaSGlenn Lagasse if ((pt = va_arg(ap, char *)) == NULL ||
1019f169c0eaSGlenn Lagasse (pt2 = va_arg(ap, char *)) == NULL) {
1020f169c0eaSGlenn Lagasse continue;
1021f169c0eaSGlenn Lagasse }
1022f169c0eaSGlenn Lagasse if (nvlist_add_string(*nvList, pt, pt2) != 0) {
1023f169c0eaSGlenn Lagasse (void) printf("nvlist_add_string failed for %s (%s).\n",
1024f169c0eaSGlenn Lagasse pt, pt2);
1025f169c0eaSGlenn Lagasse nvlist_free(*nvList);
1026f169c0eaSGlenn Lagasse return (B_FALSE);
1027f169c0eaSGlenn Lagasse }
1028f169c0eaSGlenn Lagasse }
1029f169c0eaSGlenn Lagasse
1030f169c0eaSGlenn Lagasse va_end(ap);
1031f169c0eaSGlenn Lagasse
1032f169c0eaSGlenn Lagasse return (B_TRUE);
1033f169c0eaSGlenn Lagasse }
1034f169c0eaSGlenn Lagasse
1035f169c0eaSGlenn Lagasse /*
1036f169c0eaSGlenn Lagasse * Function: beMapLibbePyErrorToString
1037f169c0eaSGlenn Lagasse * Description: Convert Python args to an int and map an error code to an
1038f169c0eaSGlenn Lagasse * error string.
1039f169c0eaSGlenn Lagasse * Parameter:
1040f169c0eaSGlenn Lagasse * errCode - value to map to an error string.
1041f169c0eaSGlenn Lagasse *
1042f169c0eaSGlenn Lagasse * Returns error string or NULL
1043f169c0eaSGlenn Lagasse * Scope:
1044f169c0eaSGlenn Lagasse * Public
1045f169c0eaSGlenn Lagasse */
1046f169c0eaSGlenn Lagasse
1047f169c0eaSGlenn Lagasse char *
beMapLibbePyErrorToString(int errCode)1048f169c0eaSGlenn Lagasse beMapLibbePyErrorToString(int errCode)
1049f169c0eaSGlenn Lagasse {
1050f169c0eaSGlenn Lagasse switch (errCode) {
1051f169c0eaSGlenn Lagasse case BE_PY_ERR_APPEND:
1052f169c0eaSGlenn Lagasse return ("Unable to append a dictionary to a list "
1053f169c0eaSGlenn Lagasse "of dictinaries.");
1054f169c0eaSGlenn Lagasse case BE_PY_ERR_DICT:
1055f169c0eaSGlenn Lagasse return ("Creation of a Python dictionary failed.");
1056f169c0eaSGlenn Lagasse case BE_PY_ERR_LIST:
1057f169c0eaSGlenn Lagasse return ("beList() failed.");
1058f169c0eaSGlenn Lagasse case BE_PY_ERR_NVLIST:
1059f169c0eaSGlenn Lagasse return ("An nvlist operation failed.");
1060f169c0eaSGlenn Lagasse case BE_PY_ERR_PARSETUPLE:
1061f169c0eaSGlenn Lagasse return ("PyArg_ParseTuple() failed to convert variable to C.");
1062f169c0eaSGlenn Lagasse case BE_PY_ERR_PRINT_ERR:
1063f169c0eaSGlenn Lagasse return ("bePrintErrors() failed.");
1064f169c0eaSGlenn Lagasse case BE_PY_ERR_VAR_CONV:
1065f169c0eaSGlenn Lagasse return ("Unable to add variables to a Python dictionary.");
1066f169c0eaSGlenn Lagasse default:
1067f169c0eaSGlenn Lagasse return (NULL);
1068f169c0eaSGlenn Lagasse }
1069f169c0eaSGlenn Lagasse }
1070f169c0eaSGlenn Lagasse
1071f169c0eaSGlenn Lagasse /* Private python initialization structure */
1072f169c0eaSGlenn Lagasse
1073f169c0eaSGlenn Lagasse static struct PyMethodDef libbeMethods[] = {
1074f169c0eaSGlenn Lagasse {"beCopy", (PyCFunction)beCopy, METH_VARARGS, "Create/Copy a BE."},
1075f169c0eaSGlenn Lagasse {"beCreateSnapshot", (PyCFunction)beCreateSnapshot, METH_VARARGS,
1076f169c0eaSGlenn Lagasse "Create a snapshot."},
1077f169c0eaSGlenn Lagasse {"beDestroy", (PyCFunction)beDestroy, METH_VARARGS, "Destroy a BE."},
1078f169c0eaSGlenn Lagasse {"beDestroySnapshot", (PyCFunction)beDestroySnapshot, METH_VARARGS,
1079f169c0eaSGlenn Lagasse "Destroy a snapshot."},
1080f169c0eaSGlenn Lagasse {"beMount", (PyCFunction)beMount, METH_VARARGS, "Mount a BE."},
1081f169c0eaSGlenn Lagasse {"beUnmount", (PyCFunction)beUnmount, METH_VARARGS, "Unmount a BE."},
1082f169c0eaSGlenn Lagasse {"beList", (PyCFunction)beList, METH_VARARGS, "List BE info."},
1083f169c0eaSGlenn Lagasse {"beRename", (PyCFunction)beRename, METH_VARARGS, "Rename a BE."},
1084f169c0eaSGlenn Lagasse {"beActivate", (PyCFunction)beActivate, METH_VARARGS, "Activate a BE."},
1085f169c0eaSGlenn Lagasse {"beRollback", (PyCFunction)beRollback, METH_VARARGS, "Rollback a BE."},
1086f169c0eaSGlenn Lagasse {"bePrintErrors", (PyCFunction)bePrintErrors, METH_VARARGS,
1087f169c0eaSGlenn Lagasse "Enable/disable error printing."},
1088f169c0eaSGlenn Lagasse {"beGetErrDesc", (PyCFunction)beGetErrDesc, METH_VARARGS,
1089f169c0eaSGlenn Lagasse "Map Error codes to strings."},
1090f169c0eaSGlenn Lagasse {"beVerifyBEName", (PyCFunction)beVerifyBEName, METH_VARARGS,
1091f169c0eaSGlenn Lagasse "Verify BE name."},
1092f169c0eaSGlenn Lagasse {NULL, NULL, 0, NULL}
1093f169c0eaSGlenn Lagasse };
1094f169c0eaSGlenn Lagasse
1095f169c0eaSGlenn Lagasse void
initlibbe_py()1096f169c0eaSGlenn Lagasse initlibbe_py()
1097f169c0eaSGlenn Lagasse {
1098f169c0eaSGlenn Lagasse /* PyMODINIT_FUNC; */
1099f169c0eaSGlenn Lagasse (void) Py_InitModule("libbe_py", libbeMethods);
1100f169c0eaSGlenn Lagasse }
1101