Fix warning about uninitialized variable
[platform/upstream/btrfs-progs.git] / libbtrfsutil / python / filesystem.c
1 /*
2  * Copyright (C) 2018 Facebook
3  *
4  * This file is part of libbtrfsutil.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #include "btrfsutilpy.h"
21
22 PyObject *filesystem_sync(PyObject *self, PyObject *args, PyObject *kwds)
23 {
24         static char *keywords[] = {"path", NULL};
25         struct path_arg path = {.allow_fd = true};
26         enum btrfs_util_error err;
27
28         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:sync", keywords,
29                                          &path_converter, &path))
30                 return NULL;
31
32         if (path.path)
33                 err = btrfs_util_sync(path.path);
34         else
35                 err = btrfs_util_sync_fd(path.fd);
36         if (err) {
37                 SetFromBtrfsUtilErrorWithPath(err, &path);
38                 path_cleanup(&path);
39                 return NULL;
40         }
41
42         path_cleanup(&path);
43         Py_RETURN_NONE;
44 }
45
46 PyObject *start_sync(PyObject *self, PyObject *args, PyObject *kwds)
47 {
48         static char *keywords[] = {"path", NULL};
49         struct path_arg path = {.allow_fd = true};
50         uint64_t transid;
51         enum btrfs_util_error err;
52
53         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:start_sync", keywords,
54                                          &path_converter, &path))
55                 return NULL;
56
57         if (path.path)
58                 err = btrfs_util_start_sync(path.path, &transid);
59         else
60                 err = btrfs_util_start_sync_fd(path.fd, &transid);
61         if (err) {
62                 SetFromBtrfsUtilErrorWithPath(err, &path);
63                 path_cleanup(&path);
64                 return NULL;
65         }
66
67         path_cleanup(&path);
68         return PyLong_FromUnsignedLongLong(transid);
69 }
70
71 PyObject *wait_sync(PyObject *self, PyObject *args, PyObject *kwds)
72 {
73         static char *keywords[] = {"path", "transid", NULL};
74         struct path_arg path = {.allow_fd = true};
75         unsigned long long transid = 0;
76         enum btrfs_util_error err;
77
78         if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|K:wait_sync", keywords,
79                                          &path_converter, &path, &transid))
80                 return NULL;
81
82         if (path.path)
83                 err = btrfs_util_wait_sync(path.path, transid);
84         else
85                 err = btrfs_util_wait_sync_fd(path.fd, transid);
86         if (err) {
87                 SetFromBtrfsUtilErrorWithPath(err, &path);
88                 path_cleanup(&path);
89                 return NULL;
90         }
91
92         path_cleanup(&path);
93         Py_RETURN_NONE;
94 }