diff options
author | Omar Sandoval <osandov@fb.com> | 2018-01-18 13:51:16 -0800 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2018-03-06 11:28:36 +0100 |
commit | 624e0233e09a034a0b8a6da445f725706ef2d9f8 (patch) | |
tree | 1a2ecdcafebb55127f97728bec3b5e8fed47dd5c /libbtrfsutil/python/subvolume.c | |
parent | 172c0d1a1218187f20460988a3c3d6212748f825 (diff) |
libbtrfsutil: add btrfs_util_[gs]et_default_subvolume()
set_default_subvolume() is a trivial ioctl(), but there's no ioctl() for
get_default_subvolume(), so we need to search the root tree.
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'libbtrfsutil/python/subvolume.c')
-rw-r--r-- | libbtrfsutil/python/subvolume.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/libbtrfsutil/python/subvolume.c b/libbtrfsutil/python/subvolume.c index 76487865..fa3ec4a7 100644 --- a/libbtrfsutil/python/subvolume.c +++ b/libbtrfsutil/python/subvolume.c @@ -270,6 +270,56 @@ PyObject *set_subvolume_read_only(PyObject *self, PyObject *args, PyObject *kwds Py_RETURN_NONE; } +PyObject *get_default_subvolume(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"path", NULL}; + struct path_arg path = {.allow_fd = true}; + enum btrfs_util_error err; + uint64_t id; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&:get_default_subvolume", + keywords, &path_converter, &path)) + return NULL; + + if (path.path) + err = btrfs_util_get_default_subvolume(path.path, &id); + else + err = btrfs_util_get_default_subvolume_fd(path.fd, &id); + if (err) { + SetFromBtrfsUtilErrorWithPath(err, &path); + path_cleanup(&path); + return NULL; + } + + path_cleanup(&path); + return PyLong_FromUnsignedLongLong(id); +} + +PyObject *set_default_subvolume(PyObject *self, PyObject *args, PyObject *kwds) +{ + static char *keywords[] = {"path", "id", NULL}; + struct path_arg path = {.allow_fd = true}; + enum btrfs_util_error err; + uint64_t id = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|K:set_default_subvolume", + keywords, &path_converter, &path, &id)) + return NULL; + + if (path.path) + err = btrfs_util_set_default_subvolume(path.path, id); + else + err = btrfs_util_set_default_subvolume_fd(path.fd, id); + if (err) { + SetFromBtrfsUtilErrorWithPath(err, &path); + path_cleanup(&path); + return NULL; + } + + path_cleanup(&path); + Py_RETURN_NONE; +} + PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds) { static char *keywords[] = {"path", "async", "qgroup_inherit", NULL}; |