From patchwork Mon Jan 27 02:49:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11352085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 62E9E92A for ; Mon, 27 Jan 2020 02:47:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 417042071E for ; Mon, 27 Jan 2020 02:47:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BSvjLm6O" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727107AbgA0CrQ (ORCPT ); Sun, 26 Jan 2020 21:47:16 -0500 Received: from mail-qv1-f66.google.com ([209.85.219.66]:39960 "EHLO mail-qv1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgA0CrP (ORCPT ); Sun, 26 Jan 2020 21:47:15 -0500 Received: by mail-qv1-f66.google.com with SMTP id dp13so3824608qvb.7 for ; Sun, 26 Jan 2020 18:47:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qbkQGPFAWmKYo0rZ1cMDbYcu7w8CMW/6+w5W7pmoMrs=; b=BSvjLm6OTNj5lou5iePulrXmnc0M8FhBirxjNMMjXAKrGIHhxwI4S6lPUhC8Oa5cgs 7XjSICxl3Sr6dJgwm12owXeETOBAMfYUm2BK51iwS795S+w7TLoyGByQBKDlsjkJ1cGz 1Ro5BlcY4TrcZQgf/+EqkSdOJGl8zHM7JxWzZaDm1CSZXMSFVSc+BrOgp9scWKHKLdQ/ h5+vrrA/j8TifBlrvYYpSMRdox3SBNFbmMHnP4uBWSiN+SVlCINbIJsLsF82dtLwIW8l vuepMZRRkoapXg3ToQ1rPKKxReGEGS47CJh5IiePGXUtoe6u4W4QS5SY0Xiy3o2+qGTd WNuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qbkQGPFAWmKYo0rZ1cMDbYcu7w8CMW/6+w5W7pmoMrs=; b=OgZuYiOPedejsESPucVcnnDpXLKnehf9hPn1Or3Yt/F4EBKdOoANCdrjKu7/Nu828S ZwFlJwiPCxyTHjh1Ts0q0OGa14T7+h9nYq/zfDwDbcH0bfA3fPPscRUs5HdgB2sdhNOm c6bZquMMNK8GNkL7YtWvE9mKGnh0+/Yfi06d+NzH7yqSAF+vnhmplZR2jX98l/iysmYY FgIXunZnEep6vfo0am+Gw3idMf3A0y8c3Uk084qtKt82Eh1inpoN3fnudiePkePsZuBL 0V5w1pl39/VBG8EGmqgvdbvBJUgsOVJOBiDP514YTfYCPGMHFgc7wm6PjEJL4U2QcEpG d4Fg== X-Gm-Message-State: APjAAAUJdiN0UEeHDW6G9Zwzp8xwr/3ydVEywbWCUFtrTLHiP2opmHfK 7s8rhsBkvEI6Utjezfb9S9w= X-Google-Smtp-Source: APXvYqwW/ernVyHwUSeF+bAiMnitjQUpQcp/Iq0EuUv7H6vxj/hqWZZqONLV9UEDfhj0M77A8DGQaw== X-Received: by 2002:a05:6214:94b:: with SMTP id dn11mr14497756qvb.12.1580093234730; Sun, 26 Jan 2020 18:47:14 -0800 (PST) Received: from localhost.localdomain (200.146.53.109.dynamic.dialup.gvt.net.br. [200.146.53.109]) by smtp.gmail.com with ESMTPSA id c184sm8643337qke.118.2020.01.26.18.47.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 18:47:14 -0800 (PST) From: Marcos Paulo de Souza Cc: dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, Marcos Paulo de Souza Subject: [PATCH 1/5] btrfs-progs: add IOC_SNAP_DESTROY_V2 to ioctl.h Date: Sun, 26 Jan 2020 23:49:50 -0300 Message-Id: <20200127024954.16916-1-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza This ioctl will make possible to delete a subvolume/snapshot by using the subvolume id. Signed-off-by: Marcos Paulo de Souza --- ioctl.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ioctl.h b/ioctl.h index 1d53c100..d4cf71de 100644 --- a/ioctl.h +++ b/ioctl.h @@ -53,12 +53,14 @@ BUILD_ASSERT(sizeof(struct btrfs_ioctl_vol_args) == 4096); #define BTRFS_SUBVOL_RDONLY (1ULL << 1) #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2) #define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3) +#define BTRFS_SUBVOL_BY_ID (1ULL << 4) #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \ (BTRFS_SUBVOL_CREATE_ASYNC | \ BTRFS_SUBVOL_RDONLY | \ BTRFS_SUBVOL_QGROUP_INHERIT | \ - BTRFS_DEVICE_SPEC_BY_ID) + BTRFS_DEVICE_SPEC_BY_ID | \ + BTRFS_SUBVOL_BY_ID) #define BTRFS_FSID_SIZE 16 #define BTRFS_UUID_SIZE 16 @@ -103,7 +105,10 @@ struct btrfs_ioctl_vol_args_v2 { __u64 unused[4]; }; union { - char name[BTRFS_SUBVOL_NAME_MAX + 1]; + union { + char name[BTRFS_SUBVOL_NAME_MAX + 1]; + __u64 subvolid; + }; __u64 devid; }; }; @@ -940,6 +945,9 @@ static inline char *btrfs_err_str(enum btrfs_err_code err_code) struct btrfs_ioctl_get_subvol_rootref_args) #define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \ struct btrfs_ioctl_ino_lookup_user_args) +#define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \ + struct btrfs_ioctl_vol_args_v2) + #ifdef __cplusplus } #endif From patchwork Mon Jan 27 02:49:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11352087 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EE9A6139A for ; Mon, 27 Jan 2020 02:47:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD7672071E for ; Mon, 27 Jan 2020 02:47:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="TvBPYk5u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727322AbgA0CrS (ORCPT ); Sun, 26 Jan 2020 21:47:18 -0500 Received: from mail-qv1-f68.google.com ([209.85.219.68]:44399 "EHLO mail-qv1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgA0CrS (ORCPT ); Sun, 26 Jan 2020 21:47:18 -0500 Received: by mail-qv1-f68.google.com with SMTP id n8so3812421qvg.11 for ; Sun, 26 Jan 2020 18:47:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sl1KikS52sGJPVrPLK+8FiRqIhEolxXqPVH9h+iV/qM=; b=TvBPYk5uBJKRUMKdn/5PjFzXhl77yWTsuqkUIE9aCSHtnWp6h/g5Fr6zJO93QAxIQW iED1kveOiXox4N6IFgoT3ogXoBoonDedjJ/9nu4T8eiWYl5kkY4JitUZhpb8W/s3ZTc/ Nakdg84Czr+SuDW73vVZ4v20nliWhEd+sRNcd2ycL42jCLewVe+uAcePQ0WKpARN7Tlp gNE/hZMoIQ7+oX9obj/gZL1RXcVoIKshpmBhDgIyBt7OCX7L3WMIvOEudxr0Wy/H5zob Sx1A7m3AxqvloUI9Ta8XuD30Se38TsynYN9Xixe7H/pJ3IlGZvl0KGQqmEzrK2EOteC3 bLTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sl1KikS52sGJPVrPLK+8FiRqIhEolxXqPVH9h+iV/qM=; b=pQpZz6HT022Nb9I+FQ2HkZlq+oOTTjUmZ0hR+4qP+40vLu+osPDpCveZP7SA1bljFX qbrKzYrDR5EiHFC/d2+3zRweYSJski2G1ZcbEHSIjVjBAiVYdPrc66qf3+jjeMENc5Zs jqwOgFHItlzGa+w2i7rWJyyt8FJPFcg/TOh8uueMdng1FEV5RTT4W5PpLIPKIwJKF+Tr 8KkYd6fsoS/9sWeVxR2fre0B72EjFVt9LHFML9LIPgT/+tAT+KBOU3VL9jqOPDrvjhD3 QDo4DCaJkspSRuGfMyqFYtkDLxYu95JUuby98PB8d5kC96um5FjyEOqmTVLpH5LCXTyv kVlg== X-Gm-Message-State: APjAAAUVWLShceFf3A+WUE2UBNS1j4HcOsl0vpxwRdFnH3VB0TYbb22G p3M+rryzl/LEsXutrbzS5So= X-Google-Smtp-Source: APXvYqyHqZXWPpceO9hzmQaUmASYiR+1ccnOi1M0S+OCCjxv6BIQSEJK+470cz2BY1p8IHXTTCdtoA== X-Received: by 2002:a05:6214:15cf:: with SMTP id p15mr14705117qvz.140.1580093237219; Sun, 26 Jan 2020 18:47:17 -0800 (PST) Received: from localhost.localdomain (200.146.53.109.dynamic.dialup.gvt.net.br. [200.146.53.109]) by smtp.gmail.com with ESMTPSA id c184sm8643337qke.118.2020.01.26.18.47.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 18:47:16 -0800 (PST) From: Marcos Paulo de Souza Cc: dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, Marcos Paulo de Souza Subject: [PATCH 2/5] libbtrfsutil: add IOC_SNAP_DESTROY_V2 to ioctl.h Date: Sun, 26 Jan 2020 23:49:51 -0300 Message-Id: <20200127024954.16916-2-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200127024954.16916-1-marcos.souza.org@gmail.com> References: <20200127024954.16916-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza This ioctl will make possible to delete a subvolume/snapshot by using the subvolume id. Signed-off-by: Marcos Paulo de Souza --- libbtrfsutil/btrfs.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libbtrfsutil/btrfs.h b/libbtrfsutil/btrfs.h index c9a61b30..fe478ab1 100644 --- a/libbtrfsutil/btrfs.h +++ b/libbtrfsutil/btrfs.h @@ -36,12 +36,14 @@ struct btrfs_ioctl_vol_args { #define BTRFS_DEVICE_PATH_NAME_MAX 1024 #define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3) +#define BTRFS_SUBVOL_BY_ID (1ULL << 4) #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \ (BTRFS_SUBVOL_CREATE_ASYNC | \ BTRFS_SUBVOL_RDONLY | \ BTRFS_SUBVOL_QGROUP_INHERIT | \ - BTRFS_DEVICE_SPEC_BY_ID) + BTRFS_DEVICE_SPEC_BY_ID | \ + BTRFS_SUBVOL_BY_ID) #define BTRFS_FSID_SIZE 16 #define BTRFS_UUID_SIZE 16 @@ -118,7 +120,10 @@ struct btrfs_ioctl_vol_args_v2 { __u64 unused[4]; }; union { - char name[BTRFS_SUBVOL_NAME_MAX + 1]; + union { + char name[BTRFS_SUBVOL_NAME_MAX + 1]; + __u64 subvolid; + }; __u64 devid; }; }; @@ -942,5 +947,7 @@ enum btrfs_err_code { struct btrfs_ioctl_get_subvol_rootref_args) #define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \ struct btrfs_ioctl_ino_lookup_user_args) +#define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \ + struct btrfs_ioctl_vol_args_v2) #endif /* _LINUX_BTRFS_H */ From patchwork Mon Jan 27 02:49:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11352089 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 034EB139A for ; Mon, 27 Jan 2020 02:47:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D566020842 for ; Mon, 27 Jan 2020 02:47:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="tE0UNT8t" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727493AbgA0CrV (ORCPT ); Sun, 26 Jan 2020 21:47:21 -0500 Received: from mail-qt1-f193.google.com ([209.85.160.193]:38981 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgA0CrU (ORCPT ); Sun, 26 Jan 2020 21:47:20 -0500 Received: by mail-qt1-f193.google.com with SMTP id e5so6324720qtm.6 for ; Sun, 26 Jan 2020 18:47:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9DsQHVRV327tp3DbyccS7hNtTNVjtFoplk31KZ1Ukis=; b=tE0UNT8tDyYdJYp1yLhaspKlQKpjcLDNIxXPmCGXGOn9FM0s5jo3yopKhUVC+FmMve tCH67ox0MG2wHrFBCorhbNOtlWNAG79TcQejVbi2LTokrXi9wyvtDEhKRuAPJfn5nCyl PpQgIG51NJoxwtC+1EeODx7MKmyRcCPLubm4Jpkmg0cgRvAjPfNmsncmM3BsGoFwvd/+ ihiXkcx33St2VUXLIDTWnOoofqgTuu0K8NuaxA3Zw5xbSIN82M/VnYSPedVLvfjUi0QW n3SEqPAzljw8LFwVo+mJa5uFenC42YDB4BN736idVQsHwBUwkhHUQc0o4HcQOefqVsnu Nz3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9DsQHVRV327tp3DbyccS7hNtTNVjtFoplk31KZ1Ukis=; b=mENY4GPhtw3MVUfMoswqG6IChTYGuFCjsUAQ62y6iswTJrvorRjpEEHbARTZjWLX3e xEeDIrSltvNMNnU6VoKX7x7eX5gZqeUsv6yfd9qX4xIFQX/1ZEgZOfPGCCxeLtCp+h1D vZe1rwU6fh/UOjGNcPC/EhCRob8P5P72bXBmc9wzJn6hen9gvgVOilaFWxFBiwWYe1Iw j8oEtDmGZXTAJrNcEbMoKD/IUETAroM9Z3z4u9jnkHJr67tLFE9jCbagRoEaGKn/bloD rbQcDyQUUvSy/8Q7h9BeqOcTBcgWzXGDeb7Q/meJCgYR4/ypzJmhtnIwAPvFqjWur7IF ysMA== X-Gm-Message-State: APjAAAXGBpnaLTg+CIY+YSJrXmtzYBGccDN6YPV9RHHLPXZu0M5AoPAC 4Aa0R7EbwPSxauW5oVmkH5Ftxssn X-Google-Smtp-Source: APXvYqyJEa73zdjh6IxzYn9i6jGzcqj7+4TUaX12lGjQLQpmc4aHSAK5Ktql3K3Apl6ZUaiWVB0gKA== X-Received: by 2002:ac8:3a02:: with SMTP id w2mr13469664qte.351.1580093239529; Sun, 26 Jan 2020 18:47:19 -0800 (PST) Received: from localhost.localdomain (200.146.53.109.dynamic.dialup.gvt.net.br. [200.146.53.109]) by smtp.gmail.com with ESMTPSA id c184sm8643337qke.118.2020.01.26.18.47.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 18:47:18 -0800 (PST) From: Marcos Paulo de Souza Cc: dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, Marcos Paulo de Souza Subject: [PATCH 3/5] libbtrfsutil: Introduce btrfs_util_delete_subvolume_by_id_fd Date: Sun, 26 Jan 2020 23:49:52 -0300 Message-Id: <20200127024954.16916-3-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200127024954.16916-1-marcos.souza.org@gmail.com> References: <20200127024954.16916-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza This new function will use the new BTRFS_IOC_SNAP_DESTROY_V2 to delete a subvolume using it's id. The parent_fs argument should be a mount point. Signed-off-by: Marcos Paulo de Souza --- libbtrfsutil/btrfsutil.h | 11 +++++++++++ libbtrfsutil/subvolume.c | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libbtrfsutil/btrfsutil.h b/libbtrfsutil/btrfsutil.h index 0442af6e..c4cab2e0 100644 --- a/libbtrfsutil/btrfsutil.h +++ b/libbtrfsutil/btrfsutil.h @@ -488,6 +488,17 @@ enum btrfs_util_error btrfs_util_delete_subvolume_fd(int parent_fd, const char *name, int flags); +/** + * btrfs_util_delete_subvolume_by_id() - Delete a subvolume or snapshot using + * subvolume id. + * @path: Path of the subvolume to delete. + * @subvolid: Subvolume id of the subvolume or snapshot to be deleted. + * + * Return: %BTRFS_UTIL_OK on success, non-zero error code on failure. + */ +enum btrfs_util_error btrfs_util_delete_subvolume_by_id_fd(int parent_fd, + uint64_t subvolid); + struct btrfs_util_subvolume_iterator; /** diff --git a/libbtrfsutil/subvolume.c b/libbtrfsutil/subvolume.c index 3f8343a2..55d0cd26 100644 --- a/libbtrfsutil/subvolume.c +++ b/libbtrfsutil/subvolume.c @@ -1290,6 +1290,22 @@ PUBLIC enum btrfs_util_error btrfs_util_delete_subvolume_fd(int parent_fd, return BTRFS_UTIL_OK; } +PUBLIC enum btrfs_util_error btrfs_util_delete_subvolume_by_id_fd(int parent_fd, + uint64_t subvolid) +{ + struct btrfs_ioctl_vol_args_v2 args = {}; + int ret; + + args.flags = BTRFS_SUBVOL_BY_ID; + args.subvolid = subvolid; + + ret = ioctl(parent_fd, BTRFS_IOC_SNAP_DESTROY_V2, &args); + if (ret == -1) + return BTRFS_UTIL_ERROR_SNAP_DESTROY_FAILED; + + return BTRFS_UTIL_OK; +} + PUBLIC void btrfs_util_destroy_subvolume_iterator(struct btrfs_util_subvolume_iterator *iter) { if (iter) { From patchwork Mon Jan 27 02:49:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11352091 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3E8B692A for ; Mon, 27 Jan 2020 02:47:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 12FFE2071E for ; Mon, 27 Jan 2020 02:47:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="n0ezzwIJ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727586AbgA0CrX (ORCPT ); Sun, 26 Jan 2020 21:47:23 -0500 Received: from mail-qk1-f172.google.com ([209.85.222.172]:41431 "EHLO mail-qk1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgA0CrX (ORCPT ); Sun, 26 Jan 2020 21:47:23 -0500 Received: by mail-qk1-f172.google.com with SMTP id s187so8265452qke.8 for ; Sun, 26 Jan 2020 18:47:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4Slwdzsq8Gdqll49vleBRs/CnCEz67npALxWW2ArsCA=; b=n0ezzwIJBUtlRDs+WAQ4Oj7FQgFiA0jvBgf4ChnB1Ed3n7biVZSNTiNbud5EyiPo+Q 4CJcWE9/QHr9kRlA1rUT3sDRfMk6ck9ZNM1kv54LMfEKoQGrKhTMbYmNzJG6LrVKWcal o4SRPMaQGu0fd5RU932HG++qs6TnmyMhbMetbw2p2blZabssSRyVXhpV5MolljgkrI54 X+PXj5FR/5nZ+MFcwcGpzUDPlChtb1HhVrh1WvJqthxTKOzuQ/Uwl41vZlq4r4mJw/5a B6DIlEcTSAzy3oe9HrmO1sU65wOLaZs+DIoG96hcG0wq7fntGHCWJDo/haT8JI9+6oYq /02A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4Slwdzsq8Gdqll49vleBRs/CnCEz67npALxWW2ArsCA=; b=VW/GHHUKk9DII3sMapgFKx2PWxE1GXsc2d+mDhXlLPEN9AhH7eErE8Bd3gC4qKZvFi cP4laD9hs1v71zftqNMKHUX+gg1OmFdJLfqhNKG2ae4weugO2wPUlVTgOBFYteddDq+Y knq/M73EtTYUgaagS20V6StFrV5gb/DM/zQB+uzE1wsz0bBMKZaV0Xz2dqN19U9a2Ap3 WvzRhQlz+6cmT3g5XnqROOmLFTeHx/yw/fTVMsQPczOe3FaYD74f2yHXIcqvevbxJtmm Zf5j0oiG1U90NmPEo8iKBjDzzblvWcHMJDkXRirDxFsdSOUJZ3x3jxAaCNOXvEg7cWtm aVGg== X-Gm-Message-State: APjAAAWT8EHugs715P0KFC3G8XkrmOB/tJO6aiBovs3BJYg66Q83FWbN MlvSyYZ1Ws2j+J1JMGL+2KE= X-Google-Smtp-Source: APXvYqzABoV0SczrskbgEVV62R7+AiWjxpIUyV/ZGi16oqhTVMMficwi648XlufbmUHmUu6F7+hm1Q== X-Received: by 2002:a37:7bc7:: with SMTP id w190mr14583923qkc.193.1580093241778; Sun, 26 Jan 2020 18:47:21 -0800 (PST) Received: from localhost.localdomain (200.146.53.109.dynamic.dialup.gvt.net.br. [200.146.53.109]) by smtp.gmail.com with ESMTPSA id c184sm8643337qke.118.2020.01.26.18.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 18:47:21 -0800 (PST) From: Marcos Paulo de Souza Cc: dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, Marcos Paulo de Souza Subject: [PATCH 4/5] cmds: subvolume: Add --subvolid argument to subvol_delete Date: Sun, 26 Jan 2020 23:49:53 -0300 Message-Id: <20200127024954.16916-4-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200127024954.16916-1-marcos.souza.org@gmail.com> References: <20200127024954.16916-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza This can be used when a system has a file system mounted from a subvolume, rather than the root file system, like below: / |- @subvol1 |- @subvol2 \- @subvol_default If only @subvol_default is mounted, we have no path to reach @subvol1 and @subvol2, thus no way to delete them. This patch introduces a new argument to specify the subvolume id of the subvolume/snapshot to be deleted. Fixes: #152 Signed-off-by: Marcos Paulo de Souza --- Documentation/btrfs-subvolume.asciidoc | 8 ++- cmds/subvolume.c | 53 ++++++++++++++++--- tests/misc-tests/038-delete-subvolume/test.sh | 40 ++++++++++++++ 3 files changed, 94 insertions(+), 7 deletions(-) create mode 100755 tests/misc-tests/038-delete-subvolume/test.sh diff --git a/Documentation/btrfs-subvolume.asciidoc b/Documentation/btrfs-subvolume.asciidoc index 6c0af2f8..9ebfcdfe 100644 --- a/Documentation/btrfs-subvolume.asciidoc +++ b/Documentation/btrfs-subvolume.asciidoc @@ -59,12 +59,15 @@ directory. Add the newly created subvolume to a qgroup. This option can be given multiple times. -*delete* [options] [...]:: +*delete* [options] <[ [...]] | [-s|--subvolid ]>:: Delete the subvolume(s) from the filesystem. + If is not a subvolume, btrfs returns an error but continues if there are more arguments to process. + +If --subvolid if used, must point to a btrfs filesystem. See `btrfs +subvolume list` how to get the subvolume id. ++ The corresponding directory is removed instantly but the data blocks are removed later in the background. The command returns immediately. See `btrfs subvolume sync` how to wait until the subvolume gets completely removed. @@ -84,6 +87,9 @@ wait for transaction commit after deleting each subvolume. + -v|--verbose:::: verbose output of operations. ++ +-s|--subvolid:::: +subvolume id of the to be removed subvolume from *find-new* :: List the recently modified files in a subvolume, after generation. diff --git a/cmds/subvolume.c b/cmds/subvolume.c index 7a5fd79b..074fc11c 100644 --- a/cmds/subvolume.c +++ b/cmds/subvolume.c @@ -222,7 +222,8 @@ static int wait_for_commit(int fd) } static const char * const cmd_subvol_delete_usage[] = { - "btrfs subvolume delete [options] [...]", + "btrfs subvolume delete [options] [...]\n" + "btrfs subvolume delete [options] -s|--subvolid ", "Delete subvolume(s)", "Delete subvolumes from the filesystem. The corresponding directory", "is removed instantly but the data blocks are removed later.", @@ -234,6 +235,7 @@ static const char * const cmd_subvol_delete_usage[] = { "-c|--commit-after wait for transaction commit at the end of the operation", "-C|--commit-each wait for transaction commit after deleting each subvolume", "-v|--verbose verbose output of operations", + "-s|--subvolid subvolume id of the to be removed subvolume", NULL }; @@ -246,12 +248,14 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd, char *dname, *vname, *cpath; char *dupdname = NULL; char *dupvname = NULL; - char *path; + char *path = NULL; DIR *dirstream = NULL; int verbose = 0; int commit_mode = 0; u8 fsid[BTRFS_FSID_SIZE]; + u64 subvolid = 0; char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; + char full_volpath[BTRFS_SUBVOL_NAME_MAX]; struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, }; enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 }; enum btrfs_util_error err; @@ -262,11 +266,12 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd, static const struct option long_options[] = { {"commit-after", no_argument, NULL, 'c'}, {"commit-each", no_argument, NULL, 'C'}, + {"subvolid", required_argument, NULL, 's'}, {"verbose", no_argument, NULL, 'v'}, {NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "cCv", long_options, NULL); + c = getopt_long(argc, argv, "cCvs:", long_options, NULL); if (c < 0) break; @@ -280,6 +285,9 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd, case 'v': verbose++; break; + case 's': + subvolid = arg_strtou64(optarg); + break; default: usage_unknown_option(cmd, argv); } @@ -288,6 +296,10 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd, if (check_argc_min(argc - optind, 1)) return 1; + /* when using --subvolid, ensure that we have only one argument */ + if (subvolid > 0 && check_argc_exact(argc - optind, 1)) + return 1; + if (verbose > 0) { printf("Transaction commit: %s\n", !commit_mode ? "none (default)" : @@ -296,6 +308,23 @@ static int cmd_subvol_delete(const struct cmd_struct *cmd, cnt = optind; + /* check the following syntax: subvolume delete --subvolid */ + if (subvolid > 0) { + char *subvol; + + path = argv[cnt]; + err = btrfs_util_subvolume_path(path, subvolid, &subvol); + if (err) { + error_btrfs_util(err); + ret = 1; + goto out; + } + + /* build new volpath using the volume name found */ + sprintf(full_volpath, "%s/%s", path, subvol); + free(subvol); + } + again: path = argv[cnt]; @@ -318,17 +347,29 @@ again: vname = basename(dupvname); free(cpath); + /* when subvolid is passed, will point to the mount point */ + if (subvolid > 0) + dname = dupvname; + fd = btrfs_open_dir(dname, &dirstream, 1); if (fd < 0) { ret = 1; goto out; } - printf("Delete subvolume (%s): '%s/%s'\n", + printf("Delete subvolume (%s): ", commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc) - ? "commit" : "no-commit", dname, vname); + ? "commit" : "no-commit"); + + if (subvolid == 0) + printf("'%s/%s'\n", dname, vname); + else + printf("'%s'\n", full_volpath); - err = btrfs_util_delete_subvolume_fd(fd, vname, 0); + if (subvolid == 0) + err = btrfs_util_delete_subvolume_fd(fd, vname, 0); + else + err = btrfs_util_delete_subvolume_by_id_fd(fd, subvolid); if (err) { error_btrfs_util(err); ret = 1; diff --git a/tests/misc-tests/038-delete-subvolume/test.sh b/tests/misc-tests/038-delete-subvolume/test.sh new file mode 100755 index 00000000..d81ae120 --- /dev/null +++ b/tests/misc-tests/038-delete-subvolume/test.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# test btrfs subvolume delete --subvolid + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +prepare_test_dev + +run_check_mkfs_test_dev +run_check_mount_test_dev + +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol1 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol2 +run_check $SUDO_HELPER "$TOP/btrfs" subvolume create "$TEST_MNT"/mysubvol3 + +# subvolid expected failures +run_mustfail "subvolume delete --subvolid expects an integer" \ + $SUDO_HELPER "$TOP/btrfs" subvolume delete --subvolid aaa "$TEST_MNT" + +run_mustfail "subvolume delete --subvolid with invalid unexisting subvolume" \ + $SUDO_HELPER "$TOP/btrfs" subvolume delete --subvolid 999 "$TEST_MNT" + +run_mustfail "subvolume delete --subvolid expects only one extra argument: the mountpoint" \ + $SUDO_HELPER "$TOP/btrfs" subvolume delete --subvolid 256 "$TEST_MNT" "$TEST_MNT" + +# delete the recently created subvol using the subvolid +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete --subvolid 256 "$TEST_MNT" + +run_check_umount_test_dev + +run_check_mount_test_dev -o subvol=mysubvol2 +# when mounted the subvolume mysubvol3, mysubvol2 is not reachable by the +# current mount point, but "subvolume delete --subvolid " should be able to +# delete it +run_check $SUDO_HELPER "$TOP/btrfs" subvolume delete --subvolid 258 "$TEST_MNT" + +run_check_umount_test_dev From patchwork Mon Jan 27 02:49:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcos Paulo de Souza X-Patchwork-Id: 11352093 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DC3F139A for ; Mon, 27 Jan 2020 02:47:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E06F020842 for ; Mon, 27 Jan 2020 02:47:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FoRhfxbz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727754AbgA0CrZ (ORCPT ); Sun, 26 Jan 2020 21:47:25 -0500 Received: from mail-qt1-f180.google.com ([209.85.160.180]:39460 "EHLO mail-qt1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726545AbgA0CrZ (ORCPT ); Sun, 26 Jan 2020 21:47:25 -0500 Received: by mail-qt1-f180.google.com with SMTP id e5so6324787qtm.6 for ; Sun, 26 Jan 2020 18:47:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G3gHsLGyThxtsAoVwHF8B9pxmbxKl20RDFTmByMp9Z0=; b=FoRhfxbz4BlbNixQYE5TriapScximDnKLj5BEqu15W/d8dDpCYhqZBXIxTgFU+/SfB H9VEfdFXQe+qs8Lz0bgDJLd5sVEuu6vdwDteyXOahyaww+3nQFMrTYFzQMHjX1GxpY5w EnnTxkdRT9O/Y0xttZzAeQsgIF8p+xlTF/v4Zyra7w2R5MYofuVMNbt2wK/w5rc9bbga K1Fv3wf+Zt+Sj3r/aQsLB4hrXuSiXcXYZpDjszeYyg/nHiwf9NVjv+Q8ralE9r8ezsLN CZPcIoQoD3Ww7UWLH9H4qRmpuubh5ubprWG52MH391M3c2JvDyrAUVMcKwZeDpPwPnyt /P6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G3gHsLGyThxtsAoVwHF8B9pxmbxKl20RDFTmByMp9Z0=; b=txqClnJs1sIlnBignYG/3Vnz+nBjoyu/+Pfl9IPzk54XDc3yEWx+fIxy5RCh3n0UPf I07lhXvJWJisfEcmFsMF3ix+iwBK9ZKUZomAV2XjQbmv68IEA6BhkR3PrjtcM3PUhZgk DWpCz3nFsCrkeYARQ7vXsbrqbN5DT+TfVO+a3TfQUbXn+AvQsC/oynKkfJskIvUYBdeG OhDKwBkPdQd9U6mXVZrJiB4M1zi0rf32pLsv5vVdfsVINZZ7rzTS3zLJ7tZs11pFGhYD SqTLdk7l0ExSo5yk2n/y92ozZg7GqWGmUKAnrLFew9UjusfoeM6CoOV3zdJd1kRf1pVn vGmw== X-Gm-Message-State: APjAAAVc2k+twfX4zWinWSMBPO1BeN+89YGUtNY0IZWUzrIf99fbS5vA t/SmuXZsZDGI/1mXHdNU19o= X-Google-Smtp-Source: APXvYqwzyjEnYJXdd5qQ4ndOwSNJHHJmB4JxH1tj/cBce8jpOraeBlEy8bTymlbql9F1axgRBDlaPw== X-Received: by 2002:ac8:134b:: with SMTP id f11mr8132479qtj.336.1580093244033; Sun, 26 Jan 2020 18:47:24 -0800 (PST) Received: from localhost.localdomain (200.146.53.109.dynamic.dialup.gvt.net.br. [200.146.53.109]) by smtp.gmail.com with ESMTPSA id c184sm8643337qke.118.2020.01.26.18.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 18:47:23 -0800 (PST) From: Marcos Paulo de Souza Cc: dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, Marcos Paulo de Souza Subject: [PATCH 5/5] VERSION: bump version Date: Sun, 26 Jan 2020 23:49:54 -0300 Message-Id: <20200127024954.16916-5-marcos.souza.org@gmail.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20200127024954.16916-1-marcos.souza.org@gmail.com> References: <20200127024954.16916-1-marcos.souza.org@gmail.com> MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Marcos Paulo de Souza As a new symbol was created, bump the library version. Signed-off-by: Marcos Paulo de Souza --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index cce56663..4ef789b0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v5.4.1 +v5.5