Re: [PATCH v2 26/27] btrfs-progs: use libbtrfsutil for subvolume list

2018-02-23 Thread Omar Sandoval
On Fri, Feb 23, 2018 at 11:26:35AM +0900, Misono, Tomohiro wrote:
> 
> 
> On 2018/02/16 4:05, Omar Sandoval wrote:
> > From: Omar Sandoval 
> 
> > +static struct subvol_list *btrfs_list_deleted_subvols(int fd,
> > + struct 
> > btrfs_list_filter_set *filter_set)
> > +{
> > +   struct subvol_list *subvols = NULL;
> > +   uint64_t *ids = NULL;
> > +   size_t i, n;
> > +   enum btrfs_util_error err;
> > +   int ret = -1;
> > +
> > +   err = btrfs_util_deleted_subvolumes_fd(fd, , );
> > +   if (err) {
> > +   error_btrfs_util(err);
> > +   return NULL;
> > +   }
> > +
> > +   subvols = malloc(sizeof(*subvols) + n * sizeof(subvols->subvols[0]));
> > +   if (!subvols) {
> > +   error("out of memory");
> > +   goto out;
> > +   }
> > +
> > +   subvols->num = 0;
> > +   for (i = 0; i < n; i++) {
> > +   struct listed_subvol *subvol = >subvols[subvols->num];
> > +
> > +   err = btrfs_util_subvolume_info_fd(fd, ids[i], >info);
> > +   if (err) {
> 
> I think there is a small chance that subvolume would be removed from tree 
> between 
> btrfs_util_deleted_subvolumes_fd() and btrfs_util_subvolume_info_fd().
> So, error of BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND should be ignored.

Thanks, since this patch isn't in the devel branch in, I'll fold the fix
in.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 26/27] btrfs-progs: use libbtrfsutil for subvolume list

2018-02-22 Thread Misono, Tomohiro


On 2018/02/16 4:05, Omar Sandoval wrote:
> From: Omar Sandoval 

> +static struct subvol_list *btrfs_list_deleted_subvols(int fd,
> +   struct 
> btrfs_list_filter_set *filter_set)
> +{
> + struct subvol_list *subvols = NULL;
> + uint64_t *ids = NULL;
> + size_t i, n;
> + enum btrfs_util_error err;
> + int ret = -1;
> +
> + err = btrfs_util_deleted_subvolumes_fd(fd, , );
> + if (err) {
> + error_btrfs_util(err);
> + return NULL;
> + }
> +
> + subvols = malloc(sizeof(*subvols) + n * sizeof(subvols->subvols[0]));
> + if (!subvols) {
> + error("out of memory");
> + goto out;
> + }
> +
> + subvols->num = 0;
> + for (i = 0; i < n; i++) {
> + struct listed_subvol *subvol = >subvols[subvols->num];
> +
> + err = btrfs_util_subvolume_info_fd(fd, ids[i], >info);
> + if (err) {

I think there is a small chance that subvolume would be removed from tree 
between 
btrfs_util_deleted_subvolumes_fd() and btrfs_util_subvolume_info_fd().
So, error of BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND should be ignored.

> + error_btrfs_util(err);
> + goto out;
> + }
> +
> + subvol->path = strdup("DELETED");
> + if (!subvol->path)
> + goto out;
> +
> + if (!filters_match(subvol, filter_set)) {
> + free(subvol->path);
> + continue;
> + }
> +
> + subvols->num++;
> + }
> +
> + ret = 0;
> +out:
> + if (ret) {
> + free_subvol_list(subvols);
> + subvols = NULL;
> + free(ids);
> + }
> + return subvols;
> +}

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html