From patchwork Tue Mar 29 08:30:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 12794554 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 390E4C433EF for ; Tue, 29 Mar 2022 08:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233916AbiC2Ic3 (ORCPT ); Tue, 29 Mar 2022 04:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230520AbiC2Ic2 (ORCPT ); Tue, 29 Mar 2022 04:32:28 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A796B47048 for ; Tue, 29 Mar 2022 01:30:45 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E61AB1FD46; Tue, 29 Mar 2022 08:30:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1648542643; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/n1gwH4ZY6/0M9Asni/zbJwZi04ikJOaT8z+RPPKWjA=; b=udB+eT3DAD+tFnmb6R6pDC41QxqaCxTllWk0BxpTaoNXC8G7GnRD3tAw0X242MUN+/B/2I VVsVajlNCuCn1KiVDjCfBRnDWritZ7ZAUusgpAYLy5dmE4pWIjWJ+UBaA4mF8MMsff9f0x DDP/G9Y7RkbTB5pnmY5vq3WKbLe/o90= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A37E313AB1; Tue, 29 Mar 2022 08:30:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jyvVJLPDQmLbLAAAMHmgww (envelope-from ); Tue, 29 Mar 2022 08:30:43 +0000 From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 1/2] btrfs-progs: fi show: Print missing device for a mounted file system Date: Tue, 29 Mar 2022 11:30:41 +0300 Message-Id: <20220329083042.1248264-1-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Currently when a device is missing for a mounted filesystem the output that is produced is unhelpful: Label: none uuid: 139ef309-021f-4b98-a3a8-ce230a83b1e2 Total devices 2 FS bytes used 128.00KiB devid 1 size 5.00GiB used 1.26GiB path /dev/loop0 *** Some devices missing While the context which prints this is perfectly capable of showing which device exactly is missing, like so: Label: none uuid: 4a85a40b-9b79-4bde-8e52-c65a550a176b Total devices 2 FS bytes used 128.00KiB devid 1 size 5.00GiB used 1.26GiB path /dev/loop0 devid 2 size 0 used 0 path /dev/loop1 ***MISSING*** This is a lot more usable output as it presents the user with the id of the missing device and its path. Signed-off-by: Nikolay Borisov --- Resending this series as it seems to have fallen through the cracks. cmds/filesystem.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) -- 2.17.1 diff --git a/cmds/filesystem.c b/cmds/filesystem.c index 7cd08fcd5f62..fe32838a25bf 100644 --- a/cmds/filesystem.c +++ b/cmds/filesystem.c @@ -296,7 +296,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, { int i; int fd; - int missing = 0; char uuidbuf[BTRFS_UUID_UNPARSED_SIZE]; struct btrfs_ioctl_dev_info_args *tmp_dev_info; int ret; @@ -326,8 +325,10 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, /* Add check for missing devices even mounted */ fd = open((char *)tmp_dev_info->path, O_RDONLY); if (fd < 0) { - missing = 1; + printf("\tdevid %4llu size 0 used 0 path %s MISSING\n", + tmp_dev_info->devid, tmp_dev_info->path); continue; + } close(fd); canonical_path = path_canonicalize((char *)tmp_dev_info->path); @@ -340,8 +341,6 @@ static int print_one_fs(struct btrfs_ioctl_fs_info_args *fs_info, free(canonical_path); } - if (missing) - printf("\t*** Some devices missing\n"); printf("\n"); return 0; } From patchwork Tue Mar 29 08:30:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 12794555 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72E11C433FE for ; Tue, 29 Mar 2022 08:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233926AbiC2Ica (ORCPT ); Tue, 29 Mar 2022 04:32:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233705AbiC2Ic3 (ORCPT ); Tue, 29 Mar 2022 04:32:29 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A80AC47058 for ; Tue, 29 Mar 2022 01:30:45 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 412581FD50; Tue, 29 Mar 2022 08:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1648542644; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S3GGRTLERp7dw/MNrn1+gZP8VxEP4EY1Kzfoa/hTdmI=; b=Ka7vw9i9kwv0wnxlnFYvTIFACM1wquEVdx45HZXVqBgdcdw+lyIY7lChx19VDRnwAJ59tf Mj+17Y13E8vOQOiuy3LZGyK8V4XrCCwyD8lf5ORecxKx2iIu+agqKUynfdS9Kdw3DOdzro erlLoabXLxh1Bj86XBD1VLwKAC38Xnc= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id EDCF513AB1; Tue, 29 Mar 2022 08:30:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id OCceN7PDQmLbLAAAMHmgww (envelope-from ); Tue, 29 Mar 2022 08:30:43 +0000 From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 2/2] btrfs-progs: tests: Add test for fi show Date: Tue, 29 Mar 2022 11:30:42 +0300 Message-Id: <20220329083042.1248264-2-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220329083042.1248264-1-nborisov@suse.com> References: <20220329083042.1248264-1-nborisov@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add a test to ensure that 'btrfs fi show' on a mounted filesyste, which has a missing device will explicitly print which device is missing. Signed-off-by: Nikolay Borisov --- tests/cli-tests/016-fi-show-missing/test.sh | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 tests/cli-tests/016-fi-show-missing/test.sh diff --git a/tests/cli-tests/016-fi-show-missing/test.sh b/tests/cli-tests/016-fi-show-missing/test.sh new file mode 100755 index 000000000000..e24a85d05410 --- /dev/null +++ b/tests/cli-tests/016-fi-show-missing/test.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Test that if a device is missing for a mounted filesystem, btrfs fi show will +# show which device exactly is missing. + +source "$TEST_TOP/common" + +check_prereq mkfs.btrfs +check_prereq btrfs + +setup_root_helper +setup_loopdevs 2 +prepare_loopdevs + +dev1=${loopdevs[1]} +dev2=${loopdevs[2]} + +run_check $SUDO_HELPER "$TOP"/mkfs.btrfs -f -draid1 $dev1 $dev2 +# move the device, changing its path, simulating the device being missing +mv $dev2 /dev/loop-non-existent + +run_check $SUDO_HELPER mount -o degraded $dev1 $TEST_MNT + +if ! run_check_stdout $SUDO_HELPER "$TOP"/btrfs fi show $TEST_MNT | \ + grep -q "$dev2 MISSING"; then + + _fail "Didn't find exact missing device" +fi + +mv /dev/loop-non-existent $dev2 + +run_check $SUDO_HELPER umount $TEST_MNT + +cleanup_loopdevs +