Re: [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()
On 2018/02/24 8:33, Omar Sandoval wrote: > On Fri, Feb 23, 2018 at 11:12:56AM +0900, Misono, Tomohiro wrote: >> >> On 2018/02/16 4:04, Omar Sandoval wrote: >>> From: Omar Sandoval>>> >>> Signed-off-by: Omar Sandoval >>> --- >>> libbtrfsutil/btrfsutil.h| 21 +++ >>> libbtrfsutil/python/btrfsutilpy.h | 3 + >>> libbtrfsutil/python/module.c| 30 ++ >>> libbtrfsutil/python/qgroup.c| 17 +- >>> libbtrfsutil/python/subvolume.c | 30 ++ >>> libbtrfsutil/python/tests/test_subvolume.py | 8 +++ >>> libbtrfsutil/subvolume.c| 89 >>> + >>> 7 files changed, 183 insertions(+), 15 deletions(-) >>> >>> diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h >>> index 00c86174..677ab3c1 100644 >>> --- a/libbtrfsutil/btrfsutil.h >>> +++ b/libbtrfsutil/btrfsutil.h >>> @@ -534,6 +534,27 @@ enum btrfs_util_error >>> btrfs_util_subvolume_iterator_next_info(struct btrfs_util_ >>> char **path_ret, >>> struct >>> btrfs_util_subvolume_info *subvol); >>> >>> +/** >>> + * btrfs_util_deleted_subvolumes() - Get a list of subvolume which have >>> been >>> + * deleted but not yet cleaned up. >>> + * @path: Path on a Btrfs filesystem. >>> + * @ids: Returned array of subvolume IDs. >>> + * @n: Returned number of IDs in the @ids array. >>> + * >>> + * This requires appropriate privilege (CAP_SYS_ADMIN). >>> + * >>> + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. >>> + */ >>> +enum btrfs_util_error btrfs_util_deleted_subvolumes(const char *path, >>> + uint64_t **ids, >>> + size_t *n); >>> + >>> +/** >>> + * btrfs_util_deleted_subvolumes_fd() - See >>> btrfs_util_deleted_subvolumes(). >>> + */ >>> +enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd, uint64_t >>> **ids, >>> + size_t *n); >>> + >>> /** >>> * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance >>> specifier >>> * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot(). >>> diff --git a/libbtrfsutil/python/btrfsutilpy.h >>> b/libbtrfsutil/python/btrfsutilpy.h >>> index b3ec047f..be5122e2 100644 >>> --- a/libbtrfsutil/python/btrfsutilpy.h >>> +++ b/libbtrfsutil/python/btrfsutilpy.h >>> @@ -54,6 +54,8 @@ struct path_arg { >>> int path_converter(PyObject *o, void *p); >>> void path_cleanup(struct path_arg *path); >>> >>> +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n); >>> + >>> void SetFromBtrfsUtilError(enum btrfs_util_error err); >>> void SetFromBtrfsUtilErrorWithPath(enum btrfs_util_error err, >>>struct path_arg *path); >>> @@ -72,6 +74,7 @@ PyObject *set_default_subvolume(PyObject *self, PyObject >>> *args, PyObject *kwds); >>> PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds); >>> PyObject *create_snapshot(PyObject *self, PyObject *args, PyObject *kwds); >>> PyObject *delete_subvolume(PyObject *self, PyObject *args, PyObject *kwds); >>> +PyObject *deleted_subvolumes(PyObject *self, PyObject *args, PyObject >>> *kwds); >>> >>> void add_module_constants(PyObject *m); >>> >>> diff --git a/libbtrfsutil/python/module.c b/libbtrfsutil/python/module.c >>> index e995a1be..eaa062ac 100644 >>> --- a/libbtrfsutil/python/module.c >>> +++ b/libbtrfsutil/python/module.c >>> @@ -125,6 +125,29 @@ err: >>> return 0; >>> } >>> >>> +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n) >>> +{ >>> +PyObject *ret; >>> +size_t i; >>> + >>> +ret = PyList_New(n); >>> +if (!ret) >>> + return NULL; >>> + >>> +for (i = 0; i < n; i++) { >>> + PyObject *tmp; >>> + >>> + tmp = PyLong_FromUnsignedLongLong(arr[i]); >>> + if (!tmp) { >>> + Py_DECREF(ret); >>> + return NULL; >>> + } >>> + PyList_SET_ITEM(ret, i, tmp); >>> +} >>> + >>> +return ret; >>> +} >>> + >>> void path_cleanup(struct path_arg *path) >>> { >>> Py_CLEAR(path->object); >>> @@ -214,6 +237,13 @@ static PyMethodDef btrfsutil_methods[] = { >>> "path -- string, bytes, or path-like object\n" >>> "recursive -- if the given subvolume has child subvolumes, delete\n" >>> "them instead of failing"}, >>> + {"deleted_subvolumes", (PyCFunction)deleted_subvolumes, >>> +METH_VARARGS | METH_KEYWORDS, >>> +"deleted_subvolumes(path)\n\n" >>> +"Get the list of subvolume IDs which have been deleted but not yet\n" >>> +"cleaned up\n\n" >>> +"Arguments:\n" >>> +"path -- string, bytes, path-like object, or open file descriptor"}, >>> {}, >>> }; >>> >>> diff --git a/libbtrfsutil/python/qgroup.c
Re: [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()
On Fri, Feb 23, 2018 at 11:12:56AM +0900, Misono, Tomohiro wrote: > > On 2018/02/16 4:04, Omar Sandoval wrote: > > From: Omar Sandoval> > > > Signed-off-by: Omar Sandoval > > --- > > libbtrfsutil/btrfsutil.h| 21 +++ > > libbtrfsutil/python/btrfsutilpy.h | 3 + > > libbtrfsutil/python/module.c| 30 ++ > > libbtrfsutil/python/qgroup.c| 17 +- > > libbtrfsutil/python/subvolume.c | 30 ++ > > libbtrfsutil/python/tests/test_subvolume.py | 8 +++ > > libbtrfsutil/subvolume.c| 89 > > + > > 7 files changed, 183 insertions(+), 15 deletions(-) > > > > diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h > > index 00c86174..677ab3c1 100644 > > --- a/libbtrfsutil/btrfsutil.h > > +++ b/libbtrfsutil/btrfsutil.h > > @@ -534,6 +534,27 @@ enum btrfs_util_error > > btrfs_util_subvolume_iterator_next_info(struct btrfs_util_ > > char **path_ret, > > struct > > btrfs_util_subvolume_info *subvol); > > > > +/** > > + * btrfs_util_deleted_subvolumes() - Get a list of subvolume which have > > been > > + * deleted but not yet cleaned up. > > + * @path: Path on a Btrfs filesystem. > > + * @ids: Returned array of subvolume IDs. > > + * @n: Returned number of IDs in the @ids array. > > + * > > + * This requires appropriate privilege (CAP_SYS_ADMIN). > > + * > > + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. > > + */ > > +enum btrfs_util_error btrfs_util_deleted_subvolumes(const char *path, > > + uint64_t **ids, > > + size_t *n); > > + > > +/** > > + * btrfs_util_deleted_subvolumes_fd() - See > > btrfs_util_deleted_subvolumes(). > > + */ > > +enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd, uint64_t > > **ids, > > + size_t *n); > > + > > /** > > * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance > > specifier > > * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot(). > > diff --git a/libbtrfsutil/python/btrfsutilpy.h > > b/libbtrfsutil/python/btrfsutilpy.h > > index b3ec047f..be5122e2 100644 > > --- a/libbtrfsutil/python/btrfsutilpy.h > > +++ b/libbtrfsutil/python/btrfsutilpy.h > > @@ -54,6 +54,8 @@ struct path_arg { > > int path_converter(PyObject *o, void *p); > > void path_cleanup(struct path_arg *path); > > > > +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n); > > + > > void SetFromBtrfsUtilError(enum btrfs_util_error err); > > void SetFromBtrfsUtilErrorWithPath(enum btrfs_util_error err, > >struct path_arg *path); > > @@ -72,6 +74,7 @@ PyObject *set_default_subvolume(PyObject *self, PyObject > > *args, PyObject *kwds); > > PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds); > > PyObject *create_snapshot(PyObject *self, PyObject *args, PyObject *kwds); > > PyObject *delete_subvolume(PyObject *self, PyObject *args, PyObject *kwds); > > +PyObject *deleted_subvolumes(PyObject *self, PyObject *args, PyObject > > *kwds); > > > > void add_module_constants(PyObject *m); > > > > diff --git a/libbtrfsutil/python/module.c b/libbtrfsutil/python/module.c > > index e995a1be..eaa062ac 100644 > > --- a/libbtrfsutil/python/module.c > > +++ b/libbtrfsutil/python/module.c > > @@ -125,6 +125,29 @@ err: > > return 0; > > } > > > > +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n) > > +{ > > +PyObject *ret; > > +size_t i; > > + > > +ret = PyList_New(n); > > +if (!ret) > > + return NULL; > > + > > +for (i = 0; i < n; i++) { > > + PyObject *tmp; > > + > > + tmp = PyLong_FromUnsignedLongLong(arr[i]); > > + if (!tmp) { > > + Py_DECREF(ret); > > + return NULL; > > + } > > + PyList_SET_ITEM(ret, i, tmp); > > +} > > + > > +return ret; > > +} > > + > > void path_cleanup(struct path_arg *path) > > { > > Py_CLEAR(path->object); > > @@ -214,6 +237,13 @@ static PyMethodDef btrfsutil_methods[] = { > > "path -- string, bytes, or path-like object\n" > > "recursive -- if the given subvolume has child subvolumes, delete\n" > > "them instead of failing"}, > > + {"deleted_subvolumes", (PyCFunction)deleted_subvolumes, > > +METH_VARARGS | METH_KEYWORDS, > > +"deleted_subvolumes(path)\n\n" > > +"Get the list of subvolume IDs which have been deleted but not yet\n" > > +"cleaned up\n\n" > > +"Arguments:\n" > > +"path -- string, bytes, path-like object, or open file descriptor"}, > > {}, > > }; > > > > diff --git a/libbtrfsutil/python/qgroup.c b/libbtrfsutil/python/qgroup.c > > index
Re: [PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()
On 2018/02/16 4:04, Omar Sandoval wrote: > From: Omar Sandoval> > Signed-off-by: Omar Sandoval > --- > libbtrfsutil/btrfsutil.h| 21 +++ > libbtrfsutil/python/btrfsutilpy.h | 3 + > libbtrfsutil/python/module.c| 30 ++ > libbtrfsutil/python/qgroup.c| 17 +- > libbtrfsutil/python/subvolume.c | 30 ++ > libbtrfsutil/python/tests/test_subvolume.py | 8 +++ > libbtrfsutil/subvolume.c| 89 > + > 7 files changed, 183 insertions(+), 15 deletions(-) > > diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h > index 00c86174..677ab3c1 100644 > --- a/libbtrfsutil/btrfsutil.h > +++ b/libbtrfsutil/btrfsutil.h > @@ -534,6 +534,27 @@ enum btrfs_util_error > btrfs_util_subvolume_iterator_next_info(struct btrfs_util_ > char **path_ret, > struct > btrfs_util_subvolume_info *subvol); > > +/** > + * btrfs_util_deleted_subvolumes() - Get a list of subvolume which have been > + * deleted but not yet cleaned up. > + * @path: Path on a Btrfs filesystem. > + * @ids: Returned array of subvolume IDs. > + * @n: Returned number of IDs in the @ids array. > + * > + * This requires appropriate privilege (CAP_SYS_ADMIN). > + * > + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. > + */ > +enum btrfs_util_error btrfs_util_deleted_subvolumes(const char *path, > + uint64_t **ids, > + size_t *n); > + > +/** > + * btrfs_util_deleted_subvolumes_fd() - See btrfs_util_deleted_subvolumes(). > + */ > +enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd, uint64_t > **ids, > +size_t *n); > + > /** > * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance specifier > * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot(). > diff --git a/libbtrfsutil/python/btrfsutilpy.h > b/libbtrfsutil/python/btrfsutilpy.h > index b3ec047f..be5122e2 100644 > --- a/libbtrfsutil/python/btrfsutilpy.h > +++ b/libbtrfsutil/python/btrfsutilpy.h > @@ -54,6 +54,8 @@ struct path_arg { > int path_converter(PyObject *o, void *p); > void path_cleanup(struct path_arg *path); > > +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n); > + > void SetFromBtrfsUtilError(enum btrfs_util_error err); > void SetFromBtrfsUtilErrorWithPath(enum btrfs_util_error err, > struct path_arg *path); > @@ -72,6 +74,7 @@ PyObject *set_default_subvolume(PyObject *self, PyObject > *args, PyObject *kwds); > PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds); > PyObject *create_snapshot(PyObject *self, PyObject *args, PyObject *kwds); > PyObject *delete_subvolume(PyObject *self, PyObject *args, PyObject *kwds); > +PyObject *deleted_subvolumes(PyObject *self, PyObject *args, PyObject *kwds); > > void add_module_constants(PyObject *m); > > diff --git a/libbtrfsutil/python/module.c b/libbtrfsutil/python/module.c > index e995a1be..eaa062ac 100644 > --- a/libbtrfsutil/python/module.c > +++ b/libbtrfsutil/python/module.c > @@ -125,6 +125,29 @@ err: > return 0; > } > > +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n) > +{ > +PyObject *ret; > +size_t i; > + > +ret = PyList_New(n); > +if (!ret) > + return NULL; > + > +for (i = 0; i < n; i++) { > + PyObject *tmp; > + > + tmp = PyLong_FromUnsignedLongLong(arr[i]); > + if (!tmp) { > + Py_DECREF(ret); > + return NULL; > + } > + PyList_SET_ITEM(ret, i, tmp); > +} > + > +return ret; > +} > + > void path_cleanup(struct path_arg *path) > { > Py_CLEAR(path->object); > @@ -214,6 +237,13 @@ static PyMethodDef btrfsutil_methods[] = { >"path -- string, bytes, or path-like object\n" >"recursive -- if the given subvolume has child subvolumes, delete\n" >"them instead of failing"}, > + {"deleted_subvolumes", (PyCFunction)deleted_subvolumes, > + METH_VARARGS | METH_KEYWORDS, > + "deleted_subvolumes(path)\n\n" > + "Get the list of subvolume IDs which have been deleted but not yet\n" > + "cleaned up\n\n" > + "Arguments:\n" > + "path -- string, bytes, path-like object, or open file descriptor"}, > {}, > }; > > diff --git a/libbtrfsutil/python/qgroup.c b/libbtrfsutil/python/qgroup.c > index 69716d92..44ac5ebc 100644 > --- a/libbtrfsutil/python/qgroup.c > +++ b/libbtrfsutil/python/qgroup.c > @@ -55,25 +55,12 @@ static PyObject *QgroupInherit_getattro(QgroupInherit > *self, PyObject *nameobj) > } > > if (strcmp(name, "groups") == 0) { > - PyObject *ret,
[PATCH v2 14/27] libbtrfsutil: add btrfs_util_deleted_subvolumes()
From: Omar SandovalSigned-off-by: Omar Sandoval --- libbtrfsutil/btrfsutil.h| 21 +++ libbtrfsutil/python/btrfsutilpy.h | 3 + libbtrfsutil/python/module.c| 30 ++ libbtrfsutil/python/qgroup.c| 17 +- libbtrfsutil/python/subvolume.c | 30 ++ libbtrfsutil/python/tests/test_subvolume.py | 8 +++ libbtrfsutil/subvolume.c| 89 + 7 files changed, 183 insertions(+), 15 deletions(-) diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h index 00c86174..677ab3c1 100644 --- a/libbtrfsutil/btrfsutil.h +++ b/libbtrfsutil/btrfsutil.h @@ -534,6 +534,27 @@ enum btrfs_util_error btrfs_util_subvolume_iterator_next_info(struct btrfs_util_ char **path_ret, struct btrfs_util_subvolume_info *subvol); +/** + * btrfs_util_deleted_subvolumes() - Get a list of subvolume which have been + * deleted but not yet cleaned up. + * @path: Path on a Btrfs filesystem. + * @ids: Returned array of subvolume IDs. + * @n: Returned number of IDs in the @ids array. + * + * This requires appropriate privilege (CAP_SYS_ADMIN). + * + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. + */ +enum btrfs_util_error btrfs_util_deleted_subvolumes(const char *path, + uint64_t **ids, + size_t *n); + +/** + * btrfs_util_deleted_subvolumes_fd() - See btrfs_util_deleted_subvolumes(). + */ +enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd, uint64_t **ids, + size_t *n); + /** * btrfs_util_create_qgroup_inherit() - Create a qgroup inheritance specifier * for btrfs_util_create_subvolume() or btrfs_util_create_snapshot(). diff --git a/libbtrfsutil/python/btrfsutilpy.h b/libbtrfsutil/python/btrfsutilpy.h index b3ec047f..be5122e2 100644 --- a/libbtrfsutil/python/btrfsutilpy.h +++ b/libbtrfsutil/python/btrfsutilpy.h @@ -54,6 +54,8 @@ struct path_arg { int path_converter(PyObject *o, void *p); void path_cleanup(struct path_arg *path); +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n); + void SetFromBtrfsUtilError(enum btrfs_util_error err); void SetFromBtrfsUtilErrorWithPath(enum btrfs_util_error err, struct path_arg *path); @@ -72,6 +74,7 @@ PyObject *set_default_subvolume(PyObject *self, PyObject *args, PyObject *kwds); PyObject *create_subvolume(PyObject *self, PyObject *args, PyObject *kwds); PyObject *create_snapshot(PyObject *self, PyObject *args, PyObject *kwds); PyObject *delete_subvolume(PyObject *self, PyObject *args, PyObject *kwds); +PyObject *deleted_subvolumes(PyObject *self, PyObject *args, PyObject *kwds); void add_module_constants(PyObject *m); diff --git a/libbtrfsutil/python/module.c b/libbtrfsutil/python/module.c index e995a1be..eaa062ac 100644 --- a/libbtrfsutil/python/module.c +++ b/libbtrfsutil/python/module.c @@ -125,6 +125,29 @@ err: return 0; } +PyObject *list_from_uint64_array(const uint64_t *arr, size_t n) +{ +PyObject *ret; +size_t i; + +ret = PyList_New(n); +if (!ret) + return NULL; + +for (i = 0; i < n; i++) { + PyObject *tmp; + + tmp = PyLong_FromUnsignedLongLong(arr[i]); + if (!tmp) { + Py_DECREF(ret); + return NULL; + } + PyList_SET_ITEM(ret, i, tmp); +} + +return ret; +} + void path_cleanup(struct path_arg *path) { Py_CLEAR(path->object); @@ -214,6 +237,13 @@ static PyMethodDef btrfsutil_methods[] = { "path -- string, bytes, or path-like object\n" "recursive -- if the given subvolume has child subvolumes, delete\n" "them instead of failing"}, + {"deleted_subvolumes", (PyCFunction)deleted_subvolumes, +METH_VARARGS | METH_KEYWORDS, +"deleted_subvolumes(path)\n\n" +"Get the list of subvolume IDs which have been deleted but not yet\n" +"cleaned up\n\n" +"Arguments:\n" +"path -- string, bytes, path-like object, or open file descriptor"}, {}, }; diff --git a/libbtrfsutil/python/qgroup.c b/libbtrfsutil/python/qgroup.c index 69716d92..44ac5ebc 100644 --- a/libbtrfsutil/python/qgroup.c +++ b/libbtrfsutil/python/qgroup.c @@ -55,25 +55,12 @@ static PyObject *QgroupInherit_getattro(QgroupInherit *self, PyObject *nameobj) } if (strcmp(name, "groups") == 0) { - PyObject *ret, *tmp; const uint64_t *arr; - size_t n, i; + size_t n; btrfs_util_qgroup_inherit_get_groups(self->inherit, , ); - ret = PyList_New(n); - if (!ret) - return NULL; - -