From patchwork Thu Mar 29 07:53:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 10314655 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 B5AEC60353 for ; Thu, 29 Mar 2018 07:54:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB8132A166 for ; Thu, 29 Mar 2018 07:54:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FE9D2A1D6; Thu, 29 Mar 2018 07:54:09 +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 7EEDE2A166 for ; Thu, 29 Mar 2018 07:54:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751973AbeC2HyG (ORCPT ); Thu, 29 Mar 2018 03:54:06 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:45963 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751169AbeC2HyE (ORCPT ); Thu, 29 Mar 2018 03:54:04 -0400 Received: by mail-pf0-f193.google.com with SMTP id l27so2702386pfk.12 for ; Thu, 29 Mar 2018 00:54:04 -0700 (PDT) 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=b6H8ZUt/9pHQCvbVgfm0oZnKAUtF7GGxuF2YjTQcF/8=; b=wF4+FIamN8JzPGmlTfSfugxyk44Hro8d5AJ0OVre34eKCw1fm48zvwJSU13QlmpJ9S dgQEUXdkLp/t9sJt6bRsBqwqcZxuTaXJHkcgQY6c7Tmsd+6qG6Dqk31hcTWRqfkcP/5S +k0ng14s83GCXaTMqmEyLcYWxn5R6SryQLZRtcxQwPS8474cwdQyrQ+F0ivXVgFFP95a x6M8/aIH3Ohw+Gq79cQ073N+hyE4Noxon5nxILXtMqX80tEJxVpccnAhP2Vtw1C7mVh/ 6edAxXFbd66RgNGYNLu+LLmvmCNeex2ub98l23j6MK07xMDg0zoInJftf36eCfU5P+Ny OuHg== 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=b6H8ZUt/9pHQCvbVgfm0oZnKAUtF7GGxuF2YjTQcF/8=; b=FLR57FAG5EY1VhyMfQVCXjb//GcpZsjgHAL+U1ycvUH1Juy+B5s8d1N9KYHb3ZV0Do NbQc3XCi+2g3W9P+QjsIfDhyFDL6Wj/DvAjFv1BgxXMK2FZUdnLT53kqky2X1/PviFba ir3QuPjH+SfEPuJ7GAfJlRI1ARHGVqoDfOqvJWJOuidgj2UpZYLxsruNT8kzU9EeG9Lu 0kVwMLFtMSSL8EnXgAk1hNPgVI0jMOMme5dk7eYkSLz9Q89cue3amzczIHiD/8EdfwgO rbuH07BJRnqpIcfPEDxuA6GA73Z9zRRs1Fua8qEs5InjjIKuVlX9E2fRNr66++Jx0+jx KezQ== X-Gm-Message-State: AElRT7H+yPbfMQNScZFPmyhxmTk54RxlFzyERmjxfONL2nPvPyubIchZ XmZiqakq1OYdIz0txdQc4oTg3Mr5wp4= X-Google-Smtp-Source: AIpwx4+9SDSMeYDfRQMnSnNbB1DHmSlS3YIDrsQZIYF9TxZ0C98bv961wbj+ag2d345ve5WuBx1GTQ== X-Received: by 10.98.108.69 with SMTP id h66mr5483318pfc.43.1522310043856; Thu, 29 Mar 2018 00:54:03 -0700 (PDT) Received: from localhost.localdomain ([2601:602:8801:8110:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id j65sm9763790pge.58.2018.03.29.00.54.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Mar 2018 00:54:03 -0700 (PDT) From: Omar Sandoval To: linux-btrfs@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 1/5] libbtrfsutil: don't return free space cache inodes from deleted_subvolumes() Date: Thu, 29 Mar 2018 00:53:53 -0700 Message-Id: <4e26593120026bc81403d4eccb1557d00dc82fe8.1522309741.git.osandov@fb.com> X-Mailer: git-send-email 2.16.3 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 Deleted free space cache inodes also get an orphan item in the root tree, but we shouldn't report those as deleted subvolumes. Deleted subvolumes will still have the root item, so we can just do an extra tree search. Reported-by: Tomohiro Misono Signed-off-by: Omar Sandoval --- libbtrfsutil/subvolume.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/libbtrfsutil/subvolume.c b/libbtrfsutil/subvolume.c index d9728281..d6c0ced8 100644 --- a/libbtrfsutil/subvolume.c +++ b/libbtrfsutil/subvolume.c @@ -1339,21 +1339,31 @@ PUBLIC enum btrfs_util_error btrfs_util_deleted_subvolumes_fd(int fd, } header = (struct btrfs_ioctl_search_header *)(search.buf + buf_off); - if (*n >= capacity) { - size_t new_capacity = capacity ? capacity * 2 : 1; - uint64_t *new_ids; - new_ids = reallocarray(*ids, new_capacity, - sizeof(**ids)); - if (!new_ids) - return BTRFS_UTIL_ERROR_NO_MEMORY; - - *ids = new_ids; - capacity = new_capacity; + /* + * The orphan item might be for a free space cache inode, so + * check if there's a matching root item. + */ + err = btrfs_util_subvolume_info_fd(fd, header->offset, NULL); + if (!err) { + if (*n >= capacity) { + size_t new_capacity; + uint64_t *new_ids; + + new_capacity = capacity ? capacity * 2 : 1; + new_ids = reallocarray(*ids, new_capacity, + sizeof(**ids)); + if (!new_ids) + return BTRFS_UTIL_ERROR_NO_MEMORY; + + *ids = new_ids; + capacity = new_capacity; + } + (*ids)[(*n)++] = header->offset; + } else if (err != BTRFS_UTIL_ERROR_SUBVOLUME_NOT_FOUND) { + goto out; } - (*ids)[(*n)++] = header->offset; - items_pos++; buf_off += sizeof(*header) + header->len; search.key.min_offset = header->offset + 1;