From patchwork Fri Jan 26 18:41:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10186773 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0378D601D5 for ; Fri, 26 Jan 2018 18:42:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E938729EC8 for ; Fri, 26 Jan 2018 18:42:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD02629ED0; Fri, 26 Jan 2018 18:42:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 71D6229EC8 for ; Fri, 26 Jan 2018 18:42:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752338AbeAZSmd (ORCPT ); Fri, 26 Jan 2018 13:42:33 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:33393 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751516AbeAZSlm (ORCPT ); Fri, 26 Jan 2018 13:41:42 -0500 Received: by mail-pg0-f66.google.com with SMTP id u1so794225pgr.0 for ; Fri, 26 Jan 2018 10:41:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=3a6R38k9ArDD9HVid+wknQBvKXKulacDpbSv1SJyPHE=; b=giYlBJeq0Es9Udzjp+NaPQQWfAtxXHB8omzr3qJK4f8OH4EtkfPF8jPUluSy/dRLGB +/+OOu7l2hBuZhmw/DdJigwlio+9VCuKKYfYwaHhk2J9dArNRnB1ayubFU5Td6sYn/U0 0PAqXhB8/IYKb8lYR2KuJtC4dvPHamyHjRCL3/61cg91ZeQsfPHPsZ28sTvOKj1rRGIj 5Sbvgq1KIezEZXnUkAL8tkhzsFsnPe0nXIjOftgnsCDgnHDyeQtx4NUQ5No3Fc5HOwe3 l341hXjoBEyDOwTOHzkUxO0nnd89jVBYK7DUAnX1XagZWRv2DSJtUsuVxw3NXPsKg+4m UF2Q== 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:in-reply-to:references; bh=3a6R38k9ArDD9HVid+wknQBvKXKulacDpbSv1SJyPHE=; b=CPF/HXZlbLk6ZFlwxFJyIK4DAe7Vp2f3PDbPJeKzFw/YYX99mk5xl9Z0SH0qDb9iCk XcvbnFbrPG5QBgo/xrO4FJV7t7QYRErR7au4MFu3KH7ia4UTAltyUQx+6AJWPMXoIa1h pmYFwLS/NeIh0PQFFHm38fMmQNlqw3yB8hquGvBUNwGskoiOl8m+MsjkWSdxlyhfrbsH Roa8PqhI1ChhRx0FlFkR2sK2e9MwCcErIEX6yCUVfNgoZWImbj0RFF3aQOCSw4E7vvt9 LQmehYqrMLxloZRCQElPNfD8vgXpvK8vpqcKlVS1O/igzlwUFGbfIGk5L/ZAKog18mus HQiQ== X-Gm-Message-State: AKwxytdZvDLC2GmzOhOAEll6SQLmJFdxYWYqtF7P8MRigMjuc1LHoJGr J9psIHWP81ECEINhcevoL4j30uWMwHU= X-Google-Smtp-Source: AH8x224rg/EyRD4052Wd309XSEkTVfVtJRBc7GUdpd/puhCGODVoGfhRKT/VX3jLZCcOLFGyjoxyjw== X-Received: by 2002:a17:902:8d85:: with SMTP id v5-v6mr14948160plo.37.1516992101857; Fri, 26 Jan 2018 10:41:41 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:7f96]) by smtp.gmail.com with ESMTPSA id y29sm19627400pff.24.2018.01.26.10.41.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 10:41:41 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 20/26] btrfs-progs: use libbtrfsutil for subvol delete Date: Fri, 26 Jan 2018 10:41:08 -0800 Message-Id: X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Most of the interesting part of this command is the commit mode, so this only saves a little bit of code. Signed-off-by: Omar Sandoval --- cmds-subvolume.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index 6b474fe4..c5e03011 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -225,7 +225,6 @@ static int cmd_subvol_delete(int argc, char **argv) int res, ret = 0; int cnt; int fd = -1; - struct btrfs_ioctl_vol_args args; char *dname, *vname, *cpath; char *dupdname = NULL; char *dupvname = NULL; @@ -237,6 +236,7 @@ static int cmd_subvol_delete(int argc, char **argv) char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct seen_fsid *seen_fsid_hash[SEEN_FSID_HASH_SIZE] = { NULL, }; enum { COMMIT_AFTER = 1, COMMIT_EACH = 2 }; + enum btrfs_util_error err; while (1) { int c; @@ -280,14 +280,9 @@ static int cmd_subvol_delete(int argc, char **argv) again: path = argv[cnt]; - res = test_issubvolume(path); - if (res < 0) { - error("cannot access subvolume %s: %s", path, strerror(-res)); - ret = 1; - goto out; - } - if (!res) { - error("not a subvolume: %s", path); + err = btrfs_util_is_subvolume(path); + if (err) { + error_btrfs_util(err); ret = 1; goto out; } @@ -314,12 +309,10 @@ again: printf("Delete subvolume (%s): '%s/%s'\n", commit_mode == COMMIT_EACH || (commit_mode == COMMIT_AFTER && cnt + 1 == argc) ? "commit" : "no-commit", dname, vname); - memset(&args, 0, sizeof(args)); - strncpy_null(args.name, vname); - res = ioctl(fd, BTRFS_IOC_SNAP_DESTROY, &args); - if(res < 0 ){ - error("cannot delete '%s/%s': %s", dname, vname, - strerror(errno)); + + err = btrfs_util_f_delete_subvolume(fd, vname, 0); + if (err) { + error_btrfs_util(err); ret = 1; goto out; }