From patchwork Thu Feb 15 19:05:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10223399 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 A936D602CB for ; Thu, 15 Feb 2018 19:05:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A97C29406 for ; Thu, 15 Feb 2018 19:05:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E07629485; Thu, 15 Feb 2018 19:05:57 +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 320FD29406 for ; Thu, 15 Feb 2018 19:05:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1167181AbeBOTFy (ORCPT ); Thu, 15 Feb 2018 14:05:54 -0500 Received: from mail-pl0-f65.google.com ([209.85.160.65]:43845 "EHLO mail-pl0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1161962AbeBOTFv (ORCPT ); Thu, 15 Feb 2018 14:05:51 -0500 Received: by mail-pl0-f65.google.com with SMTP id f4so343073plr.10 for ; Thu, 15 Feb 2018 11:05:51 -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=JiUWEb8/4ZBKymmEb/Ke4bHiSmahxz7t3XbIXW6QRmU=; b=rz9M8kKLahnfzTfUQfLLW/VdUO66/DjwoBwFTSJSoD6JV+/Bz6rVcH01H80TxSGyr5 RHkZ29KZnnT5QbQv0TpHgvNpfHAxIHLF8jE8wAwkzZaWPfgKy3EaiKs3/ZSaCfpYB+Fi ul72nBXbhrrRWpg1JbLhrt8WaaNPbrHOWyJBDaTGH1IQgd9ep1G24LNPgmcz5INEm0PN tUvv32D621VhCAGSVQ/nclecunxAMnbLwhOdZUVzI89Iw7du9xLaUpSs/IiyMCiix32F omc2l8AmhFvC1yHrAt96TMbY2EXUv7WfHE/SUhmw0JkoJcnlRn5QRlpaPyVuHX5OkcIw 375Q== 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=JiUWEb8/4ZBKymmEb/Ke4bHiSmahxz7t3XbIXW6QRmU=; b=PRb4YTiudUXFZVgWu99wXnbwFxotEUHKaSa5XuUmErUCJ8MFJq81+50kPqj8bEBqxs e6XXqXUP0GcV5zUFqqQ0Ln5jO2WC7QFA5eCh7NGzxXFnqswTyRfTRcAnp9C+wGUmGTUx irqntaZpQ7zRWGPhoCQe/LER60F4Ydbzs24uBSsjffJiB3gjfl7/PWDO3e3aGqzXHSli gKvU9GuEK8dgBtp+rhg8OoW3jwY2gUaukXOE2t2hF63r17VssX53YuCwjCdpqOz+iIFk XGdWiJ2QslIg+h+detV3eu9Iu49PtWOWoFBrDrEb9kdjjC7oF5MVQxk8Szm20Q8QSd1t ihPA== X-Gm-Message-State: APf1xPCT5sQmMLUAMfYRVjonXjEme7kl9nYBX8Wfj/4+2iO72dC+PBgK vmqBQtvxsOV9l/5MctETlNOmnXmLSl4= X-Google-Smtp-Source: AH8x2261W5tuLYGUbevy3rJiPVYv0d8Bjl+TfDX1TjzhKlU0HgTCLdSighs4LmImIIu4FsdBQo3Pig== X-Received: by 2002:a17:902:2f03:: with SMTP id s3-v6mr3521096plb.112.1518721550227; Thu, 15 Feb 2018 11:05:50 -0800 (PST) Received: from vader.thefacebook.com ([2620:10d:c090:200::6:4a19]) by smtp.gmail.com with ESMTPSA id p1sm40467428pgr.44.2018.02.15.11.05.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:05:49 -0800 (PST) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH v2 21/27] btrfs-progs: use libbtrfsutil for subvol delete Date: Thu, 15 Feb 2018 11:05:06 -0800 Message-Id: <849123d7f52564b88cafe1582cdd227a4e18e3a7.1518720598.git.osandov@fb.com> 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 | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index ea436ba0..68768914 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; } @@ -313,11 +308,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': %m", dname, vname); + + err = btrfs_util_delete_subvolume_fd(fd, vname, 0); + if (err) { + error_btrfs_util(err); ret = 1; goto out; }