From patchwork Wed Jun 23 10:58:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339563 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5400BC48BE5 for ; Wed, 23 Jun 2021 10:59:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3430C61166 for ; Wed, 23 Jun 2021 10:59:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230135AbhFWLCG (ORCPT ); Wed, 23 Jun 2021 07:02:06 -0400 Received: from mail-wr1-f50.google.com ([209.85.221.50]:33379 "EHLO mail-wr1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230030AbhFWLCF (ORCPT ); Wed, 23 Jun 2021 07:02:05 -0400 Received: by mail-wr1-f50.google.com with SMTP id d11so2200147wrm.0; Wed, 23 Jun 2021 03:59:48 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=3DPuzTQf5i//60Egy7t0JK45QLGYkeuhTcZ4qyrJF2Q=; b=QHh6nSjmKLtSs3xhgnYvjIHKfRKDeNjmDys3VQCHHHUc1SdDUF6O1dhaJH2knCAUKF +kas3sSPMd3swkfrQJjiA+N6dlPcQtFBux2bXDL23xOg1Q4+37MHT7ENJJ8KLD+lTjx4 8ZfEdG0blK61M5yZMc6+1XNqmB1jjUeBYlztBiezHN8OXZdH0or5pnVtC8YplCauvowF MoTLZdVJqzBH8u2L90XH4sKPjxBUnnsh5wlTQ4OG13dU2HAqCPR30WyYWGTbCRKqeruN 61BtCe+h9tjy4GgzwwFmmm7pXualj50HSd6EzD2FXzgXshuYExOo3jblT/texcNVmQLD ioqw== X-Gm-Message-State: AOAM533Fy4FBTAUD79PHRaCPGxlZtrziH0AvefSt26iccUcE/gSLNPkd cLoBcbW3Rj1eiCKnQtgqTR6XUoZ6ZLEI1Q== X-Google-Smtp-Source: ABdhPJwPvauXSCj+gS+SHMy12LE2IiuMDMEOc9jf+z6vkeE9bJ0CDWIYXAOMvF1JZ0m4GGYQE0W3yg== X-Received: by 2002:a05:6000:1245:: with SMTP id j5mr10683561wrx.371.1624445987343; Wed, 23 Jun 2021 03:59:47 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:46 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 1/6] block: add disk sequence number Date: Wed, 23 Jun 2021 12:58:53 +0200 Message-Id: <20210623105858.6978-2-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce Add a monotonically increasing number to disk devices. This number is put in the uevent so userspace can correlate events when a driver reuses a device, like cdrom or loop. $ udevadm info /sys/class/block/* |grep -e DEVNAME -e DISKSEQ E: DEVNAME=/dev/loop0 E: DISKSEQ=1 E: DEVNAME=/dev/loop1 E: DISKSEQ=2 E: DEVNAME=/dev/loop2 E: DISKSEQ=3 E: DEVNAME=/dev/loop3 E: DISKSEQ=4 E: DEVNAME=/dev/loop4 E: DISKSEQ=5 E: DEVNAME=/dev/loop5 E: DISKSEQ=6 E: DEVNAME=/dev/loop6 E: DISKSEQ=7 E: DEVNAME=/dev/loop7 E: DISKSEQ=8 E: DEVNAME=/dev/nvme0n1 E: DISKSEQ=9 E: DEVNAME=/dev/nvme0n1p1 E: DISKSEQ=9 E: DEVNAME=/dev/nvme0n1p2 E: DISKSEQ=9 E: DEVNAME=/dev/nvme0n1p3 E: DISKSEQ=9 E: DEVNAME=/dev/nvme0n1p4 E: DISKSEQ=9 E: DEVNAME=/dev/nvme0n1p5 E: DISKSEQ=9 E: DEVNAME=/dev/sda E: DISKSEQ=10 E: DEVNAME=/dev/sda1 E: DISKSEQ=10 E: DEVNAME=/dev/sda2 E: DISKSEQ=10 Signed-off-by: Matteo Croce --- block/genhd.c | 19 +++++++++++++++++++ include/linux/genhd.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 9f8cb7beaad1..c96b667136ee 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1129,8 +1129,17 @@ static void disk_release(struct device *dev) blk_put_queue(disk->queue); kfree(disk); } + +static int block_uevent(struct device *dev, struct kobj_uevent_env *env) +{ + struct gendisk *disk = dev_to_disk(dev); + + return add_uevent_var(env, "DISKSEQ=%llu", disk->diskseq); +} + struct class block_class = { .name = "block", + .dev_uevent = block_uevent, }; static char *block_devnode(struct device *dev, umode_t *mode, @@ -1304,6 +1313,8 @@ struct gendisk *__alloc_disk_node(int minors, int node_id) disk_to_dev(disk)->class = &block_class; disk_to_dev(disk)->type = &disk_type; device_initialize(disk_to_dev(disk)); + inc_diskseq(disk); + return disk; out_destroy_part_tbl: @@ -1854,3 +1865,11 @@ static void disk_release_events(struct gendisk *disk) WARN_ON_ONCE(disk->ev && disk->ev->block != 1); kfree(disk->ev); } + +void inc_diskseq(struct gendisk *disk) +{ + static atomic64_t diskseq; + + disk->diskseq = atomic64_inc_return(&diskseq); +} +EXPORT_SYMBOL_GPL(inc_diskseq); diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 6fc26f7bdf71..a0d04250a2db 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -167,6 +167,7 @@ struct gendisk { int node_id; struct badblocks *bb; struct lockdep_map lockdep_map; + u64 diskseq; }; /* @@ -306,6 +307,7 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, } #endif /* CONFIG_SYSFS */ +void inc_diskseq(struct gendisk *disk); dev_t blk_lookup_devt(const char *name, int partno); void blk_request_module(dev_t devt); #ifdef CONFIG_BLOCK From patchwork Wed Jun 23 10:58:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339565 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1523FC4743C for ; Wed, 23 Jun 2021 10:59:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EB8406108E for ; Wed, 23 Jun 2021 10:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230182AbhFWLCK (ORCPT ); Wed, 23 Jun 2021 07:02:10 -0400 Received: from mail-wr1-f48.google.com ([209.85.221.48]:33385 "EHLO mail-wr1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbhFWLCJ (ORCPT ); Wed, 23 Jun 2021 07:02:09 -0400 Received: by mail-wr1-f48.google.com with SMTP id d11so2200329wrm.0; Wed, 23 Jun 2021 03:59:50 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=aJu1+YCrkeg1VrMRtE/40B8yQYYhV/BJgPpoTp2RURs=; b=nFvMg7PVYmtnD+YGQLAR7G7X1h+cBy4317unAM44+D/o81afAofnKztFWqlW3FBNNH 1HpDpKQ3fsG9jkEnuFy0pqfQt8uLs7xkRvxldHpss2Oa2Svd8XZDHwdVG+NHJFUZYhfQ 9+kdvhRKaXLGE2WVtl8Qq7xS8cf4aZKe2QSLLvAe1tFquzSg7eYKNPyu6K4WVOKXfkvV n+xAVUcNkXapsLMMeeoDXIQ+1avx5YpNauJMRGeDNKx41QfvLIQC91UeRvEGx9vFvskO 3t27lai2cqac34QrCsPjKdRTpzJkb1mI3eHGxc3zMjvVyI2yxW3JbwUe3x5pdqO/nrJJ /e9Q== X-Gm-Message-State: AOAM532ZrWy78A0s4bjYvRLdRgLMP/6yrUx6PmvW6ePJFJyqEPsTjcFe tiHkGEtbBxHRA6h4CO0fL3+M9ZR+dhHaQQ== X-Google-Smtp-Source: ABdhPJzPlLp3WHs6yTVEK2Y51Df5ofPOSUEgqWhrBhjrpHROc+LqUnoP+63NfjJzIfbcCZFzogB17A== X-Received: by 2002:a05:6000:144b:: with SMTP id v11mr8805568wrx.421.1624445990205; Wed, 23 Jun 2021 03:59:50 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:49 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 2/6] block: add ioctl to read the disk sequence number Date: Wed, 23 Jun 2021 12:58:54 +0200 Message-Id: <20210623105858.6978-3-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce Add a new BLKGETDISKSEQ ioctl which retrieves the disk sequence number from the genhd structure. # ./getdiskseq /dev/loop* /dev/loop0: 13 /dev/loop0p1: 13 /dev/loop0p2: 13 /dev/loop0p3: 13 /dev/loop1: 14 /dev/loop1p1: 14 /dev/loop1p2: 14 /dev/loop2: 5 /dev/loop3: 6 Signed-off-by: Matteo Croce --- block/ioctl.c | 2 ++ include/uapi/linux/fs.h | 1 + 2 files changed, 3 insertions(+) diff --git a/block/ioctl.c b/block/ioctl.c index 8ba1ed8defd0..32b339bbaf95 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -469,6 +469,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, fmode_t mode, BLKDEV_DISCARD_SECURE); case BLKZEROOUT: return blk_ioctl_zeroout(bdev, mode, arg); + case BLKGETDISKSEQ: + return put_u64(argp, bdev->bd_disk->diskseq); case BLKREPORTZONE: return blkdev_report_zones_ioctl(bdev, mode, cmd, arg); case BLKRESETZONE: diff --git a/include/uapi/linux/fs.h b/include/uapi/linux/fs.h index 4c32e97dcdf0..bdf7b404b3e7 100644 --- a/include/uapi/linux/fs.h +++ b/include/uapi/linux/fs.h @@ -184,6 +184,7 @@ struct fsxattr { #define BLKSECDISCARD _IO(0x12,125) #define BLKROTATIONAL _IO(0x12,126) #define BLKZEROOUT _IO(0x12,127) +#define BLKGETDISKSEQ _IOR(0x12,128,__u64) /* * A jump here: 130-136 are reserved for zoned block devices * (see uapi/linux/blkzoned.h) From patchwork Wed Jun 23 10:58:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339567 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FE8AC4743C for ; Wed, 23 Jun 2021 10:59:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 43EF261003 for ; Wed, 23 Jun 2021 10:59:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230232AbhFWLCM (ORCPT ); Wed, 23 Jun 2021 07:02:12 -0400 Received: from mail-wm1-f46.google.com ([209.85.128.46]:37432 "EHLO mail-wm1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230204AbhFWLCL (ORCPT ); Wed, 23 Jun 2021 07:02:11 -0400 Received: by mail-wm1-f46.google.com with SMTP id f16-20020a05600c1550b02901b00c1be4abso3712395wmg.2; Wed, 23 Jun 2021 03:59:53 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=dJGFJi2SWlwPX3gSxotAaJdmgPvABu9igSaT3WLpCGg=; b=XXnX7uVTNeUCm7fU8JJk5RB8k/eRheauKRIs6JDVvrKFJj94CYVdtIa7BdVnIhGGt5 sHH3hNHwhhpSClRi6dadag5YNqpRajKIenHCFYnfXP9QDIG+Vbc6z0aKOxiDecCgiLuo MkNKH1h/hygZCT5bO2IBLfve2yJs84Jjn8aJUM0db4b1ZaDmKd+UtaOWIx2wePVIjpqN Ap2rFKd1LJ73mfFDloLfmH76uAPI2HdQq8+k4JHl6mKvFButLr3un3mEmFDy35FnIxgv wSTFkZXEtSTjfWmA96eQCpMVZQ5cTdL0mJ0iZFWaPEsT2iAmcxCKuCLealGsLrMgdoiK Af+w== X-Gm-Message-State: AOAM531HTlNwT5BGyKwep3PrIBK8/kLgkDOaR7vcPGlDAFfTFq0frAPU xQOTY5eb7DButFW7DcKJskNI+89rVyP8+A== X-Google-Smtp-Source: ABdhPJxXAM0wmpLWavin8GYnUa25ByXouTBeczdOFAg+LMqLZ4X874wCN+/F6t9F5NrOmR3x8FaKXQ== X-Received: by 2002:a1c:de8a:: with SMTP id v132mr9834645wmg.27.1624445992655; Wed, 23 Jun 2021 03:59:52 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:52 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 3/6] block: refactor sysfs code Date: Wed, 23 Jun 2021 12:58:55 +0200 Message-Id: <20210623105858.6978-4-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce Move the sysfs register code from a function named disk_add_events() to a new function named disk_add_sysfs(). Also, rename the attribute list with a more generic name than disk_events_attrs. This is a prerequisite patch to export diskseq in sysfs later. Signed-off-by: Matteo Croce --- block/genhd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index c96b667136ee..610dd86fd4b6 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -39,6 +39,7 @@ static void disk_alloc_events(struct gendisk *disk); static void disk_add_events(struct gendisk *disk); static void disk_del_events(struct gendisk *disk); static void disk_release_events(struct gendisk *disk); +static void disk_add_sysfs(struct gendisk *disk); void set_capacity(struct gendisk *disk, sector_t sectors) { @@ -560,6 +561,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, */ WARN_ON_ONCE(!blk_get_queue(disk->queue)); + disk_add_sysfs(disk); disk_add_events(disk); blk_integrity_add(disk); } @@ -1754,7 +1756,7 @@ static const DEVICE_ATTR(events_poll_msecs, 0644, disk_events_poll_msecs_show, disk_events_poll_msecs_store); -static const struct attribute *disk_events_attrs[] = { +static const struct attribute *disk_sysfs_attrs[] = { &dev_attr_events.attr, &dev_attr_events_async.attr, &dev_attr_events_poll_msecs.attr, @@ -1825,13 +1827,16 @@ static void disk_alloc_events(struct gendisk *disk) disk->ev = ev; } -static void disk_add_events(struct gendisk *disk) +static void disk_add_sysfs(struct gendisk *disk) { /* FIXME: error handling */ - if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_events_attrs) < 0) + if (sysfs_create_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs) < 0) pr_warn("%s: failed to create sysfs files for events\n", disk->disk_name); +} +static void disk_add_events(struct gendisk *disk) +{ if (!disk->ev) return; @@ -1856,7 +1861,7 @@ static void disk_del_events(struct gendisk *disk) mutex_unlock(&disk_events_mutex); } - sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_events_attrs); + sysfs_remove_files(&disk_to_dev(disk)->kobj, disk_sysfs_attrs); } static void disk_release_events(struct gendisk *disk) From patchwork Wed Jun 23 10:58:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339569 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 01644C48BC2 for ; Wed, 23 Jun 2021 11:00:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E01E16100B for ; Wed, 23 Jun 2021 11:00:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230291AbhFWLCS (ORCPT ); Wed, 23 Jun 2021 07:02:18 -0400 Received: from mail-wr1-f46.google.com ([209.85.221.46]:35722 "EHLO mail-wr1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbhFWLCO (ORCPT ); Wed, 23 Jun 2021 07:02:14 -0400 Received: by mail-wr1-f46.google.com with SMTP id m18so2159729wrv.2; Wed, 23 Jun 2021 03:59:55 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=BlKb/nN8ZAtxyPllpUsysxr5X0Gh4ewsJLKk2TVLQgg=; b=b4ZiE42tBgTTQbFpdBrnf6c1kLeydm/34NTulrKfTQt7xxAwMoz5E46UwuYb1Brwgh 0ooto5QMHhPS1Q5d1PXePsJOwqDGjUJUCBji5QcX+NdPsD4A97WsCeTEk9COOPcCL1aB kaNw2jF+Kj/5BuZ/zeXoTCsx6D09Mv5JO4RR70thqx2iuHDKU0f0NM2aRQvnSsRbppwO EyJREblRGI7Uy5+zpua2/capfAr6LKfHB9A02dFUoTgFfR2zKsu1LbbqG9IbeCSc5o01 g92OkIumMX8ZWGMlcEm2VHxw9FRnlo9/fBrYyD3eXJ5NvyTjWZCypbikgDMk2E6RCk9k s8pg== X-Gm-Message-State: AOAM5307OtHm6Cm/VSoFBgC33Gd16nObRowUL1SeQxyOYDr48kByc6uy KUs4e1aVqSHxkDG0ctLQ9MA6sC/Qv+Rc5Q== X-Google-Smtp-Source: ABdhPJzXuCLqP7tliLA63JKixyiAA9O5ocuKf/Ly6bU8IGr8jrDuSyCxWJwrjsk1f5pZE6HlP260dw== X-Received: by 2002:a5d:69cb:: with SMTP id s11mr10905377wrw.240.1624445995119; Wed, 23 Jun 2021 03:59:55 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:54 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 4/6] block: export diskseq in sysfs Date: Wed, 23 Jun 2021 12:58:56 +0200 Message-Id: <20210623105858.6978-5-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce Add a new sysfs handle to export the new diskseq value. Place it in /block//diskseq and document it. $ grep . /sys/class/block/*/diskseq /sys/class/block/loop0/diskseq:13 /sys/class/block/loop1/diskseq:14 /sys/class/block/loop2/diskseq:5 /sys/class/block/loop3/diskseq:6 /sys/class/block/ram0/diskseq:1 /sys/class/block/ram1/diskseq:2 /sys/class/block/vda/diskseq:7 Signed-off-by: Matteo Croce --- Documentation/ABI/testing/sysfs-block | 12 ++++++++++++ block/genhd.c | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-block b/Documentation/ABI/testing/sysfs-block index e34cdeeeb9d4..a0ed87386639 100644 --- a/Documentation/ABI/testing/sysfs-block +++ b/Documentation/ABI/testing/sysfs-block @@ -28,6 +28,18 @@ Description: For more details refer Documentation/admin-guide/iostats.rst +What: /sys/block//diskseq +Date: February 2021 +Contact: Matteo Croce +Description: + The /sys/block//diskseq files reports the disk + sequence number, which is a monotonically increasing + number assigned to every drive. + Some devices, like the loop device, refresh such number + every time the backing file is changed. + The value type is 64 bit unsigned. + + What: /sys/block///stat Date: February 2008 Contact: Jerome Marchand diff --git a/block/genhd.c b/block/genhd.c index 610dd86fd4b6..768d8d5d1eca 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1680,6 +1680,7 @@ static void disk_check_events(struct disk_events *ev, * events_async : list of events which can be detected w/o polling * (always empty, only for backwards compatibility) * events_poll_msecs : polling interval, 0: disable, -1: system default + * diskseq : disk sequence number, since boot */ static ssize_t __disk_events_show(unsigned int events, char *buf) { @@ -1750,16 +1751,26 @@ static ssize_t disk_events_poll_msecs_store(struct device *dev, return count; } +static ssize_t diskseq_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct gendisk *disk = dev_to_disk(dev); + + return sprintf(buf, "%llu\n", disk->diskseq); +} + static const DEVICE_ATTR(events, 0444, disk_events_show, NULL); static const DEVICE_ATTR(events_async, 0444, disk_events_async_show, NULL); static const DEVICE_ATTR(events_poll_msecs, 0644, disk_events_poll_msecs_show, disk_events_poll_msecs_store); +static const DEVICE_ATTR(diskseq, 0444, diskseq_show, NULL); static const struct attribute *disk_sysfs_attrs[] = { &dev_attr_events.attr, &dev_attr_events_async.attr, &dev_attr_events_poll_msecs.attr, + &dev_attr_diskseq.attr, NULL, }; From patchwork Wed Jun 23 10:58:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339571 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41068C48BC2 for ; Wed, 23 Jun 2021 11:00:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E27D6100A for ; Wed, 23 Jun 2021 11:00:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbhFWLCW (ORCPT ); Wed, 23 Jun 2021 07:02:22 -0400 Received: from mail-wm1-f44.google.com ([209.85.128.44]:43742 "EHLO mail-wm1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230292AbhFWLCQ (ORCPT ); Wed, 23 Jun 2021 07:02:16 -0400 Received: by mail-wm1-f44.google.com with SMTP id p8-20020a7bcc880000b02901dbb595a9f1so1051229wma.2; Wed, 23 Jun 2021 03:59:58 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=l8WXhUdDCLyoaqLE/ASdptZOs5V4AdT2Ca24aztnZxs=; b=GQt4gDX+BzpqgdlH3SnalvvHlwe/tZdRwTXa8Pyan6VwJHqMoGCoye65vzOynHA0Ue cBzlaukInvBQe88WqQuXqksa6woQZ6H6uugo+L2VE7NgiV9A3nwV62YTuKNIA6stjAmM fZnPAj9+RySFxZPZ3mY9uEkAlGC+j2MaHry0a3vpgwmwUimEtRi5uqhK3BNB+cf6LTAG tIUmjDVo1rFkoSa8zxOThzTQEUYSqOLpSM7cO6j0Wiay+5+E5xPrHIfqyU3hpDpjiNjC PQQ9Q3KzI4LfST7lAv4adJAxJhIjH7OKO0XuaHBwln2BAvN+dW0tR+bUBX95IsOCyHQt +Yiw== X-Gm-Message-State: AOAM531BE37U9ndYAR7iuPPj7sgi/b1NfeJuy2LQWb7R6ipHW/gbAaW+ J0g/JBFzN1FTah3Z7Oeh5+O2OEpGCCfruw== X-Google-Smtp-Source: ABdhPJxqlC8kPRYJureYms4UjWCazY4rKJs4g//PH6vLYW5YmB65+cNXHoGoHZAxDB1J709YJgfiEQ== X-Received: by 2002:a7b:ca43:: with SMTP id m3mr9891587wml.74.1624445997681; Wed, 23 Jun 2021 03:59:57 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:57 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 5/6] block: increment sequence number Date: Wed, 23 Jun 2021 12:58:57 +0200 Message-Id: <20210623105858.6978-6-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce Increment the disk sequence number when the media has changed, i.e. on DISK_EVENT_MEDIA_CHANGE event. $ cat /sys/class/block/sr0/diskseq 12 $ eject $ cat /sys/class/block/sr0/diskseq 22 Signed-off-by: Matteo Croce --- block/genhd.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/genhd.c b/block/genhd.c index 768d8d5d1eca..9d58e0ea18ae 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1657,6 +1657,9 @@ static void disk_check_events(struct disk_events *ev, spin_unlock_irq(&ev->lock); + if (events & DISK_EVENT_MEDIA_CHANGE) + inc_diskseq(disk); + /* * Tell userland about new events. Only the events listed in * @disk->events are reported, and only if DISK_EVENT_FLAG_UEVENT From patchwork Wed Jun 23 10:58:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12339573 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-21.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5204C4743C for ; Wed, 23 Jun 2021 11:00:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D54066100B for ; Wed, 23 Jun 2021 11:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230409AbhFWLCZ (ORCPT ); Wed, 23 Jun 2021 07:02:25 -0400 Received: from mail-wm1-f48.google.com ([209.85.128.48]:36440 "EHLO mail-wm1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230334AbhFWLCS (ORCPT ); Wed, 23 Jun 2021 07:02:18 -0400 Received: by mail-wm1-f48.google.com with SMTP id m41-20020a05600c3b29b02901dcd3733f24so3711482wms.1; Wed, 23 Jun 2021 04:00:00 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=lIaKl1OxDgMFf5G0f4ixWy1oghSZADo8i4vWnrvSFg8=; b=LcRYKQVSvYVc0icirqjWbpg325Cj/8kmUZmIsJP+CqzkwO8z3/m+oYcg2bRUukDw8x diFzNSYOF48l886Qy043DaHwzJO3o1jZyBrN//NWbB1Ajyf4H2RHP7SM3giOwP1V8Wmz NN8ClGltNHMhITLlxpVqTt/RwkaC6zYn/yVkQ2JO7ne8lB/skTPh9IplWY3lScBBcvsx botOvINEKQOT0XTE8u+TFUq6Vj/FkBWDdLZDdvLW0GLMjGd0iIjhsMKEYKE71GN9Bz4b YGMN+pnxDbMw6gxqvG+B5QmujDeUSonVbKyRKYgWPuSbtttSAvLJJKcS/L1JH7CkiLMR llgA== X-Gm-Message-State: AOAM531f+ksIBuYB1GBgQwPPTDtB2YAT0Or5tG90cJbFGRsboK074kFm r/ZYS8UxTcO6SzOgiRtOcMXRprWaKmC28g== X-Google-Smtp-Source: ABdhPJxWj9Nb+u4BTe2iujl/CcCTRNgLWbT5Kxb9Px4/vUMPtmzVRpUE28NaJcK84X4U2ey32Y1qzA== X-Received: by 2002:a7b:c395:: with SMTP id s21mr10296924wmj.164.1624446000174; Wed, 23 Jun 2021 04:00:00 -0700 (PDT) Received: from msft-t490s.. (mob-176-246-29-26.net.vodafone.it. [176.246.29.26]) by smtp.gmail.com with ESMTPSA id r2sm2659458wrv.39.2021.06.23.03.59.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Jun 2021 03:59:59 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, Jens Axboe Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke , Matthew Wilcox , Christoph Hellwig , JeffleXu Subject: [PATCH v3 6/6] loop: increment sequence number Date: Wed, 23 Jun 2021 12:58:58 +0200 Message-Id: <20210623105858.6978-7-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210623105858.6978-1-mcroce@linux.microsoft.com> References: <20210623105858.6978-1-mcroce@linux.microsoft.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org From: Matteo Croce On a very loaded system, if there are many events queued up from multiple attach/detach cycles, it's impossible to match them up with the LOOP_CONFIGURE or LOOP_SET_FD call, since we don't know where the position of our own association in the queue is[1]. Not even an empty uevent queue is a reliable indication that we already received the uevent we were waiting for, since with multi-partition block devices each partition's event is queued asynchronously and might be delivered later. Increment the disk sequence number when setting or changing the backing file, so the userspace knows which backing file generated the event: # udevadm monitor -kp |grep -e ^DEVNAME -e ^DISKSEQ & [1] 263 # losetup -fP 3part [ 12.309974] loop0: detected capacity change from 0 to 2048 DEVNAME=/dev/loop0 DISKSEQ=8 [ 12.360252] loop0: p1 p2 p3 DEVNAME=/dev/loop0 DISKSEQ=8 DEVNAME=/dev/loop0p1 DISKSEQ=8 DEVNAME=/dev/loop0p2 DISKSEQ=8 DEVNAME=/dev/loop0p3 DISKSEQ=8 # losetup -D DEVNAME=/dev/loop0 DISKSEQ=9 DEVNAME=/dev/loop0p1 DISKSEQ=9 DEVNAME=/dev/loop0p2 DISKSEQ=9 DEVNAME=/dev/loop0p3 DISKSEQ=9 # losetup -fP 2part [ 29.001344] loop0: detected capacity change from 0 to 2048 DEVNAME=/dev/loop0 DISKSEQ=10 [ 29.040226] loop0: p1 p2 DEVNAME=/dev/loop0 DISKSEQ=10 DEVNAME=/dev/loop0p1 DISKSEQ=10 DEVNAME=/dev/loop0p2 DISKSEQ=10 [1] https://github.com/systemd/systemd/issues/17469#issuecomment-762919781 Signed-off-by: Matteo Croce --- drivers/block/loop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 76e12f3482a9..b1c638d23306 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -735,6 +735,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, goto out_err; /* and ... switch */ + inc_diskseq(lo->lo_disk); blk_mq_freeze_queue(lo->lo_queue); mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); lo->lo_backing_file = file; @@ -1123,6 +1124,8 @@ static int loop_configure(struct loop_device *lo, fmode_t mode, if (error) goto out_unlock; + inc_diskseq(lo->lo_disk); + if (!(file->f_mode & FMODE_WRITE) || !(mode & FMODE_WRITE) || !file->f_op->write_iter) lo->lo_flags |= LO_FLAGS_READ_ONLY; @@ -1223,6 +1226,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) lo->lo_backing_file = NULL; spin_unlock_irq(&lo->lo_lock); + inc_diskseq(lo->lo_disk); + loop_release_xfer(lo); lo->transfer = NULL; lo->ioctl = NULL;