From patchwork Wed Jun 6 03:01:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: james harvey X-Patchwork-Id: 10449555 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 D71AE60146 for ; Wed, 6 Jun 2018 03:01:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C3EC229B6F for ; Wed, 6 Jun 2018 03:01:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8CB429B75; Wed, 6 Jun 2018 03:01:10 +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=-7.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, MAILING_LIST_MULTI, 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 76B3C29B6F for ; Wed, 6 Jun 2018 03:01:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752783AbeFFDBH (ORCPT ); Tue, 5 Jun 2018 23:01:07 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:42694 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752574AbeFFDBG (ORCPT ); Tue, 5 Jun 2018 23:01:06 -0400 Received: by mail-oi0-f65.google.com with SMTP id k190-v6so4074069oib.9 for ; Tue, 05 Jun 2018 20:01:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=cppYKfQL3dW8UpUf2Uq7jRb2icqkz+rjVr5aUMc70Y8=; b=CtB0QFo5xR/GaD1ce2jZQAHabvTvsTuNzVNAVNBFP/5RhXZH3Ds5YgGaLlxgc56nHK Oc0eGKsFo6LAcMfsc1r5uQ5FU6b9rl3NnvlmH80/hukkosTe4CGHp5BdPGLQmITco2bw l5x3ZTeZVgoOPuxeIq207X4SJ/sXPZYa1PXsrrscqHbYtILWO4g7EDaI/KLpPi+MeRLZ wuias0EzkC6GtR1qXSDnu8xRmqRkPWfql7wN9wN8IFxzX4fpNcDLk485iVsIxczPYQpG nExIPQJb7HetjEw0YN91McZk58Yg5dbGFLVrgFQoFv2LsBiZ1w74s1lP+jK/nP5jBhHz veXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=cppYKfQL3dW8UpUf2Uq7jRb2icqkz+rjVr5aUMc70Y8=; b=O8ypakTjUW/DXolMjUFytzXJrIGqitG11pgjORnxM79mbuww1dlsc62rpdo2aoz1dG FHFwQsztWtjCIz/sBdkZxcOV3EQoRiZ00zJ7eQMIex0jy9DQwNCZG/LjvXbZUscV244D hLDZjP72GhU+omDx0d2ZnZHJvrQ0n8Qzvji5s1EDO9vKxFlZrXkleQlzFYnnaT3C3Ohh 5uNG0btrzfOXgHsMAtBly7kksJY1P+r2zjuM4hVcNU2Q1YKswsiP9eYBfJsX2UhdX5mj Rbt7kL6d20Y/p+Vz2Ahtr+fyJCUfiixJnGXjYcbObQj6D9wveSxFyqQC1ZVqz2HRxhJR tWhw== X-Gm-Message-State: APt69E0vCo8pvjstC8U9Fk9v5Le3qUHZcaBFiFwEKs+PZHqd7ydKPoqh 6ddaCDBTf4y245aFGd0bvUroo/YBbn2wqvZ9excAtA== X-Google-Smtp-Source: ADUXVKKtpe1OyGKph9wQ6TjhlKgRBi6IeHQ8AjR/gNVizYQOn1YMTmhej4utqw/U0z25npQLuECIRrFlWAV9YoSt7UA= X-Received: by 2002:aca:f2d7:: with SMTP id q206-v6mr657848oih.99.1528254065727; Tue, 05 Jun 2018 20:01:05 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:3535:0:0:0:0:0 with HTTP; Tue, 5 Jun 2018 20:01:05 -0700 (PDT) From: james harvey Date: Tue, 5 Jun 2018 23:01:05 -0400 Message-ID: Subject: [PATCH v2] btrfs-progs: device: Added verbose option to scan To: Btrfs BTRFS 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 Only works when device(s) not specified. At verbose level 1, for each registered btrfs filesystem, compactly show fs uuid, and for each of its devices, the device id, name, and uuid. At verbose level 2, show everything for the fs and its devices. Previous behavior of print_all_devices(), which is used by chunk-recover and super-recover, is unaffected. (diff doesn't show the patch most optimally.) Signed-off-by: James Harvey --- cmds-device.c | 20 ++++++++++++--- utils.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++----- utils.h | 5 ++-- 3 files changed, 84 insertions(+), 11 deletions(-) -- 2.17.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/cmds-device.c b/cmds-device.c index 86459d1b..a2ed71ab 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -254,9 +254,13 @@ static int cmd_device_delete(int argc, char **argv) } static const char * const cmd_device_scan_usage[] = { - "btrfs device scan [(-d|--all-devices)| [...]]", + "btrfs device scan [([-v] -d|--all-devices)| [...]]", "Scan devices for a btrfs filesystem", " -d|--all-devices (deprecated)", + " -v|--verbose (For each registered btrfs filesystem, show fs uuid, and for", + " each of its devices, show device id, name, and uuid. May", + " be given a second time to show more information. Only works", + " when device(s) not specified.)", NULL }; @@ -265,22 +269,27 @@ static int cmd_device_scan(int argc, char **argv) int i; int devstart; int all = 0; + int verbose = 0; int ret = 0; while (1) { int c; static const struct option long_options[] = { { "all-devices", no_argument, NULL, 'd'}, + { "verbose", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0} }; - c = getopt_long(argc, argv, "d", long_options, NULL); + c = getopt_long(argc, argv, "dv", long_options, NULL); if (c < 0) break; switch (c) { case 'd': all = 1; break; + case 'v': + ++verbose; + break; default: usage(cmd_device_scan_usage); } @@ -290,11 +299,16 @@ static int cmd_device_scan(int argc, char **argv) if (all && check_argc_max(argc - optind, 1)) usage(cmd_device_scan_usage); + if (devstart < argc) { + printf("Verbose mode does not work when device(s) are specified\n\n"); + usage(cmd_device_scan_usage); + } + if (all || argc - optind == 0) { printf("Scanning for Btrfs filesystems\n"); ret = btrfs_scan_devices(); error_on(ret, "error %d while scanning", ret); - ret = btrfs_register_all_devices(); + ret = btrfs_register_all_devices(verbose); error_on(ret, "there are %d errors while registering devices", ret); goto out; } diff --git a/utils.c b/utils.c index d81d4980..b5ee08a3 100644 --- a/utils.c +++ b/utils.c @@ -1004,7 +1004,7 @@ int btrfs_register_one_device(const char *fname) * Register all devices in the fs_uuid list created in the user * space. Ensure btrfs_scan_devices() is called before this func. */ -int btrfs_register_all_devices(void) +int btrfs_register_all_devices(int verbose) { int err = 0; int ret = 0; @@ -1015,7 +1015,15 @@ int btrfs_register_all_devices(void) all_uuids = btrfs_scanned_uuids(); list_for_each_entry(fs_devices, all_uuids, list) { + if (verbose == 2) + printf("--------------------------------------------------\n"); + if (verbose) + print_fs_devices_info(fs_devices, verbose); list_for_each_entry(device, &fs_devices->devices, dev_list) { + if (verbose == 2) + printf("\n"); + if (verbose) + print_device_info(device, " ", verbose); if (*device->name) err = btrfs_register_one_device(device->name); @@ -1023,6 +1031,9 @@ int btrfs_register_all_devices(void) ret++; } } + /* Separate possible ERROR summary. (May be unnecessary.) */ + if (verbose == 2) + printf("--------------------------------------------------\n"); return ret; } @@ -2573,12 +2584,59 @@ unsigned long total_memory(void) return si.totalram * si.mem_unit; /* bytes */ } -void print_device_info(struct btrfs_device *device, char *prefix) +void print_fs_devices_info(struct btrfs_fs_devices *fs_devices, int mode) { - if (prefix) + char fs_uuid[BTRFS_UUID_UNPARSED_SIZE]; + + uuid_unparse(fs_devices->fsid, fs_uuid); + + if (mode <= 1) { + printf("fs uuid %-36s\n", *fs_uuid ? fs_uuid : ""); + } else { + printf("fs uuid: %-36s\n", *fs_uuid ? fs_uuid : ""); + printf("latest_devid: %llu\n", fs_devices->latest_devid); + printf("latest_trans: %llu\n", fs_devices->latest_trans); + printf("lowest_devid: %llu\n", fs_devices->lowest_devid); + printf("latest_bdev: %d\n", fs_devices->latest_bdev); + printf("lowest_bdev: %d\n", fs_devices->lowest_bdev); + printf("seeding: %d\n", fs_devices->seeding); + } +} + +void print_device_info(struct btrfs_device *device, char *prefix, int mode) +{ + char dev_uuid[BTRFS_UUID_UNPARSED_SIZE]; + + if (prefix && mode <= 1) printf("%s", prefix); - printf("Device: id = %llu, name = %s\n", - device->devid, device->name); + if (mode <= 0) { + printf("Device: id = %llu, name = %s\n", + device->devid, device->name ? device->name : ""); + } else if (mode == 1) { + uuid_unparse(device->uuid, dev_uuid); + printf("devid %llu (%s, uuid %-36ss)\n", device->devid, + device->name ? device->name : "", + *dev_uuid ? dev_uuid : ""); + } else { + uuid_unparse(device->uuid, dev_uuid); + printf("devid: %llu\n", device->devid); + printf("name: %s\n", device->name ? device->name : ""); + printf("device uuid: %s\n", *dev_uuid ? dev_uuid : ""); + printf("generation (trans): %llu\n", device->generation); + printf("total_ios: %llu\n", device->total_ios); + printf("fd: %d\n", device->fd); + printf("writeable: %d\n", device->writeable); + printf("label: %s\n", device->label ? device->label : ""); + printf("total_devs: %llu\n", device->total_devs); + printf("super_bytes_used: %llu\n", device->super_bytes_used); + printf("total_bytes (size in memory): %llu\n", + device->total_bytes); + printf("bytes_used: %llu\n", device->bytes_used); + printf("io_align: %lu\n", (unsigned long) device->io_align); + printf("io_width: %lu\n", (unsigned long) device->io_width); + printf("sector_size: %lu\n", (unsigned long) device->sector_size); + printf("type: %llu\n", device->type); + } } void print_all_devices(struct list_head *devices) @@ -2587,6 +2645,6 @@ void print_all_devices(struct list_head *devices) printf("All Devices:\n"); list_for_each_entry(dev, devices, dev_list) - print_device_info(dev, "\t"); + print_device_info(dev, "\t", 0); printf("\n"); } diff --git a/utils.h b/utils.h index 403de481..9203f52b 100644 --- a/utils.h +++ b/utils.h @@ -87,7 +87,7 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, u32 sectorsize); int btrfs_scan_for_fsid(int run_ioctls); int btrfs_register_one_device(const char *fname); -int btrfs_register_all_devices(void); +int btrfs_register_all_devices(int verbose); char *canonicalize_dm_name(const char *ptname); char *canonicalize_path(const char *path); int check_mounted(const char *devicename); @@ -167,7 +167,8 @@ int prefixcmp(const char *str, const char *prefix); unsigned long total_memory(void); -void print_device_info(struct btrfs_device *device, char *prefix); +void print_fs_devices_info(struct btrfs_fs_devices *fs_devices, int mode); +void print_device_info(struct btrfs_device *device, char *prefix, int mode); void print_all_devices(struct list_head *devices); /*