summaryrefslogtreecommitdiff
path: root/libbtrfsutil/python/subvolume.c
diff options
context:
space:
mode:
authorOmar Sandoval <osandov@fb.com>2018-01-18 13:15:32 -0800
committerDavid Sterba <dsterba@suse.com>2018-03-06 11:28:36 +0100
commitf676a8ad118ecba7fbf4edc77b91f788c6fa7e7c (patch)
tree53734d782f62cdb026106a79cc203dead1878a79 /libbtrfsutil/python/subvolume.c
parent92d4035074dd5234f1c3fd263947dde1f9bb288e (diff)
libbtrfsutil: add btrfs_util_create_subvolume()
Doing the ioctl() directly isn't too bad, but passing in a full path is more convenient than opening the parent and passing the path component. 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.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/libbtrfsutil/python/subvolume.c b/libbtrfsutil/python/subvolume.c
index 4aab06a5..6f2080ee 100644
--- a/libbtrfsutil/python/subvolume.c
+++ b/libbtrfsutil/python/subvolume.c
@@ -71,3 +71,32 @@ PyObject *subvolume_id(PyObject *self, PyObject *args, PyObject *kwds)
path_cleanup(&path);
return PyLong_FromUnsignedLongLong(id);
}
+
+PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds)
+{
+ static char *keywords[] = {"path", "async", "qgroup_inherit", NULL};
+ struct path_arg path = {.allow_fd = false};
+ enum btrfs_util_error err;
+ int async = 0;
+ QgroupInherit *inherit = NULL;
+ uint64_t transid;
+
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O&|pO!:create_subvolume",
+ keywords, &path_converter, &path,
+ &async, &QgroupInherit_type, &inherit))
+ return NULL;
+
+ err = btrfs_util_create_subvolume(path.path, 0, async ? &transid : NULL,
+ inherit ? inherit->inherit : NULL);
+ if (err) {
+ SetFromBtrfsUtilErrorWithPath(err, &path);
+ path_cleanup(&path);
+ return NULL;
+ }
+
+ path_cleanup(&path);
+ if (async)
+ return PyLong_FromUnsignedLongLong(transid);
+ else
+ Py_RETURN_NONE;
+}