From patchwork Mon Mar 15 20:02:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12140595 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 38C0AC433E6 for ; Mon, 15 Mar 2021 20:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0194664F4B for ; Mon, 15 Mar 2021 20:04:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233953AbhCOUDi (ORCPT ); Mon, 15 Mar 2021 16:03:38 -0400 Received: from mail-ej1-f46.google.com ([209.85.218.46]:33712 "EHLO mail-ej1-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233947AbhCOUDM (ORCPT ); Mon, 15 Mar 2021 16:03:12 -0400 Received: by mail-ej1-f46.google.com with SMTP id jt13so68452059ejb.0; Mon, 15 Mar 2021 13:03:11 -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=8g9BTEw5cXK8BEbWg9s2vlc3/G9KI2ob9t2ObMjWarw=; b=Fz8FFQxzAL9tX20K/L5eeJ5E1wD2HC/d/FB8OnbgEeg7CgaWcjQqPgX35YxZuM9MzX 8Nhrivk0iD+CEr47tpwIHC9mrsRnbIIx3B3Mi0ieAd9KvOvjt+5Km7rmsBM/bV1d4PuI 5vgIx3AoUAhQNw0nmk/wYHgg4eBVYsRfuuplBBmWQrmPLVIKQPKt9nB/niSaR46L17ui 2dXFCiI2eFK++Lkewcn/Ys5vTr53YjFxJT2fh4jBLuMA+Qk0KELwTdmd5G980BacJD9j oIIDkRH59eomFDOsd+yFZthVPJlAu4oha1ArGUHypoHSmEEgYb2WcqT1EZorc5fFV8Fs /SfA== X-Gm-Message-State: AOAM532P+yPmA/yfC59YQlaGqMYABZZhUOeVTMZvi9iwz5RzwYdiIg16 0vvdpM9ALxYD8mVM99pPjrzL+fEZBlPflA== X-Google-Smtp-Source: ABdhPJxlFVm09S5cvJx2HpIRxw1HVJAgESec3ReO0bsgBmooLvC4DyVbOu+jaLxI+QSFDfvllh5hcQ== X-Received: by 2002:a17:907:9e6:: with SMTP id ce6mr25172779ejc.207.1615838590529; Mon, 15 Mar 2021 13:03:10 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-188-216-41-250.cust.vodafonedsl.it. [188.216.41.250]) by smtp.gmail.com with ESMTPSA id x21sm8551210eds.53.2021.03.15.13.03.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 13:03:09 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Jens Axboe , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke Subject: [PATCH -next 1/5] block: add disk sequence number Date: Mon, 15 Mar 2021 21:02:38 +0100 Message-Id: <20210315200242.67355-2-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315200242.67355-1-mcroce@linux.microsoft.com> References: <20210315200242.67355-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 sequence number to the disk devices. This number is put in the uevent so userspace can correlate events when a driver reuses a device, like the loop one. 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 8c8f543572e6..92debcb9e061 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1215,8 +1215,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, @@ -1388,6 +1397,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: @@ -1938,3 +1949,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 f364619092cc..632141b360d2 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; }; /* @@ -326,6 +327,7 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, #endif /* CONFIG_SYSFS */ extern struct rw_semaphore bdev_lookup_sem; +extern void inc_diskseq(struct gendisk *disk); dev_t blk_lookup_devt(const char *name, int partno); void blk_request_module(dev_t devt); From patchwork Mon Mar 15 20:02:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12140597 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 77FC3C433DB for ; Mon, 15 Mar 2021 20:04:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 389C564F50 for ; Mon, 15 Mar 2021 20:04:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233981AbhCOUDj (ORCPT ); Mon, 15 Mar 2021 16:03:39 -0400 Received: from mail-ed1-f43.google.com ([209.85.208.43]:39838 "EHLO mail-ed1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233950AbhCOUDW (ORCPT ); Mon, 15 Mar 2021 16:03:22 -0400 Received: by mail-ed1-f43.google.com with SMTP id bf3so18797394edb.6; Mon, 15 Mar 2021 13:03:21 -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=PkEBTQQrAWt7QcNipJG5buCi2jRQQ6g6Fca4O51wY5Q=; b=fG3Vy5Siod/fTIZnl1KkrxS7Y/WkH2sixbBJprMjoT7CRCZNGq49awjcPx/i/x48KZ +4IwUGYM797ClgX0sB2ypracyR79R9w8vRf4P/7PVoInYlplTf4wemNtSr9ohBew33KW sPJrSNyfj/zS66rkT39V9PvraBHDlns8ZVtF8cGOPnvvthcMh5bj7sJ9XNqaUnEJZmTD BvUfZ0icTBE5Nvhb2wXYzVRqk3q5wpSBJMD/oOMeRarFKOUEyODfGDo29g+nU/yXk0hw 05njmdnNfZK6w5mucmOyuere3xBxxGunNOucS02t/mOyX0FglQCkRafBdDb/n2SHbd+R YnHg== X-Gm-Message-State: AOAM532/oWlnmmcokHx3D/cOOjgXI0Ep9WlxbXxBlNrnV3iXPGb7vXas qhQp3MPAjPISArAVYO6SMe3wbNPKS1uVjA== X-Google-Smtp-Source: ABdhPJyNiNaYH6YrJrOURMkyP3WP5we/k2e2MFDLCnGL67kn/AFEzJYHBMztDjoMSyYxT/KPdK92Rw== X-Received: by 2002:a05:6402:12cf:: with SMTP id k15mr31093245edx.192.1615838601126; Mon, 15 Mar 2021 13:03:21 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-188-216-41-250.cust.vodafonedsl.it. [188.216.41.250]) by smtp.gmail.com with ESMTPSA id x21sm8551210eds.53.2021.03.15.13.03.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 13:03:20 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Jens Axboe , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke Subject: [PATCH -next 2/5] block: add ioctl to read the disk sequence number Date: Mon, 15 Mar 2021 21:02:39 +0100 Message-Id: <20210315200242.67355-3-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315200242.67355-1-mcroce@linux.microsoft.com> References: <20210315200242.67355-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. 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 ff241e663c01..266315d00942 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -467,6 +467,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 f44eb0a04afd..5dc72bbdd9b7 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-131 are reserved for zoned block devices * (see uapi/linux/blkzoned.h) From patchwork Mon Mar 15 20:02:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12140599 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 8F5D3C43333 for ; Mon, 15 Mar 2021 20:04:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4D6FA64E83 for ; Mon, 15 Mar 2021 20:04:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233947AbhCOUDk (ORCPT ); Mon, 15 Mar 2021 16:03:40 -0400 Received: from mail-ed1-f49.google.com ([209.85.208.49]:33453 "EHLO mail-ed1-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233951AbhCOUDY (ORCPT ); Mon, 15 Mar 2021 16:03:24 -0400 Received: by mail-ed1-f49.google.com with SMTP id w18so18833519edc.0; Mon, 15 Mar 2021 13:03:23 -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=unr0lspPbExoMGaeory8crjBzhS6zdKvWVCk960aOU8=; b=tHGuTWArVlnyWL96Q2qsOFW3yVRN6lP8hVWhh82OCtrYJ7KHsbrfwbYXpLHDs+mt8o uHN6V4WL0Vs23l1xsBxB3g9pscXIBJhoeqHkYU1KBydaYfg3OrtfHyVm/AsFEW46dwUh bGExCzkkcxMndbqOA9zrrCb78p9V+MJDeg/ZiEPSW3EZfBOwxlLlc6GSOXwI9tOZpiv1 LhYOkyiTsQtf33454f2flWelWsdarlrwjZZEE1iL4iRSBENubaEPiWEnsCkUr+FHZAXd I2Znj19xwfq9DbCu8ZGWpqUP350Au/nBo6v56leVhcHBf6AfgJgy9gjxU7fhGb6WeCHx gUcg== X-Gm-Message-State: AOAM5317WgsWDdvQHfHzIu9a4cHDoOb20/F6OmLSDCQ1ux2e5dRoiRTP DUib/onmhaD1mU9JquWqwDU0NoYbDc9GaA== X-Google-Smtp-Source: ABdhPJw0N/kDWEh6kOqJlt94kMa0MzE7BuOPpXhECb38QCm2ntvmtWHsfe7q1B138tAx+Xg1wutazA== X-Received: by 2002:a05:6402:5189:: with SMTP id q9mr31635414edd.168.1615838602881; Mon, 15 Mar 2021 13:03:22 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-188-216-41-250.cust.vodafonedsl.it. [188.216.41.250]) by smtp.gmail.com with ESMTPSA id x21sm8551210eds.53.2021.03.15.13.03.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 13:03:22 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Jens Axboe , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke Subject: [PATCH -next 3/5] block: refactor sysfs code Date: Mon, 15 Mar 2021 21:02:40 +0100 Message-Id: <20210315200242.67355-4-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315200242.67355-1-mcroce@linux.microsoft.com> References: <20210315200242.67355-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. 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 92debcb9e061..57d92ea7ae05 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -41,6 +41,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) { @@ -628,6 +629,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); } @@ -1838,7 +1840,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, @@ -1909,13 +1911,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; @@ -1940,7 +1945,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 Mon Mar 15 20:02:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12140601 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 9C343C433DB for ; Mon, 15 Mar 2021 20:04:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B16264F4B for ; Mon, 15 Mar 2021 20:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234038AbhCOUEJ (ORCPT ); Mon, 15 Mar 2021 16:04:09 -0400 Received: from mail-ej1-f50.google.com ([209.85.218.50]:37007 "EHLO mail-ej1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233956AbhCOUDi (ORCPT ); Mon, 15 Mar 2021 16:03:38 -0400 Received: by mail-ej1-f50.google.com with SMTP id bm21so68386263ejb.4; Mon, 15 Mar 2021 13:03:36 -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=Jj0zDPT2eMcpk7VXig4zM0b2an7HEf8fKRrEJVtcizM=; b=WLAI2MXGdCgxj+06DmtGszKUbEQg6GWtelcIXogBQrmK8QIYpBrhaQUP+dkez/dVlj /R53ldRNPs8Bvjp/EXdCY8g+0Wyk6aiIgb0F9FnnmIM4yiCCADqvrBgTBclhjr3FR4dm UFpdsYcFTr6ZZAQHtecAbv6kSqZklg+OwaPNB4KFxzFrx+6bZj5I8FQAbvAPuUEtokYn ytiLKJnAULWFc3MPuqqRs1+V3dxF56XeWX6Mc+MD7J7Abiz07ttFL52RmlovigkOqkxj p7dIBwgf9ABje8I16lDwapuo/p7K1TEMgNwZUzdlUaiV2qNLhSIb6zqpsdg+0J5ZBWGY ccHw== X-Gm-Message-State: AOAM531vpS/v5t5mB0pNRtiEMbtNIPuP9884E5Bz8dq4xlPoyoWSfbNe fepBZfiLHnSLmapa5EGfPGnLBtGgtzeFgA== X-Google-Smtp-Source: ABdhPJwHuxFC1/fxvXnG/nGf2cgzI69PNuS4CkzYFReqpiQTI2SRbo3Fu5bUBbama8j0gv9TbpUb+A== X-Received: by 2002:a17:906:8a6e:: with SMTP id hy14mr26063470ejc.356.1615838616004; Mon, 15 Mar 2021 13:03:36 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-188-216-41-250.cust.vodafonedsl.it. [188.216.41.250]) by smtp.gmail.com with ESMTPSA id x21sm8551210eds.53.2021.03.15.13.03.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 13:03:35 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Jens Axboe , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke Subject: [PATCH -next 4/5] block: export diskseq in sysfs Date: Mon, 15 Mar 2021 21:02:41 +0100 Message-Id: <20210315200242.67355-5-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315200242.67355-1-mcroce@linux.microsoft.com> References: <20210315200242.67355-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. 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 57d92ea7ae05..6a7ed426def0 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -1764,6 +1764,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) { @@ -1834,16 +1835,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 Mon Mar 15 20:02:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matteo Croce X-Patchwork-Id: 12140603 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=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 BEBAEC433E6 for ; Mon, 15 Mar 2021 20:04:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 977A264F5C for ; Mon, 15 Mar 2021 20:04:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234041AbhCOUEK (ORCPT ); Mon, 15 Mar 2021 16:04:10 -0400 Received: from mail-ej1-f53.google.com ([209.85.218.53]:36847 "EHLO mail-ej1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233925AbhCOUDs (ORCPT ); Mon, 15 Mar 2021 16:03:48 -0400 Received: by mail-ej1-f53.google.com with SMTP id e19so68488837ejt.3; Mon, 15 Mar 2021 13:03:47 -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=DV40QsbLmfrHazcRS7XkP3bcaAXUsBsn36zxNtb6dP8=; b=W/7sucFbvFG462CxXMsQbGlcfthxTZTvUHcC+eZbyKe8XG6M4RsEUPYA5pgtxTA+lx 5LDaL6RRALZ5RglKs3qWWasrTOBK3XejloHhcalHbQtP7M8Lh0O4LwzONSvF+GPxDFBY iRxGXiYNr0Z1+qX+97wpYRp4cTqiFax1DNL2NRkZj04+M+mMGHYNIGfoXnWjuVaTVV+q wR11dQhpg3C/9vvirwHyjI2JNFgaD5BfSbouJBSGGf2TVe0z/wWedI45dVRv7XLTS5eX QgOitvNNkB0xoyYgGD2dfTVObiStCSWBtOnrfc9KE6Kh7q7VYRLUwAC3yWGQGGIs0Qqg MKGQ== X-Gm-Message-State: AOAM5316eqv9aC4a17sQw27RzODO2MT3+4YvvemZlE1J6Jswzu6u7FUl 5bgi5Ns1asyiStzh28INbYNff7T5rhSTfg== X-Google-Smtp-Source: ABdhPJwGlvmSof040MXGMHe7UCZDixkNuAVv/Swr1OfG+JI694yceu9KyDg8F0XNHDSgvIxlf2OLUg== X-Received: by 2002:a17:906:be9:: with SMTP id z9mr25347682ejg.35.1615838627191; Mon, 15 Mar 2021 13:03:47 -0700 (PDT) Received: from msft-t490s.teknoraver.net (net-188-216-41-250.cust.vodafonedsl.it. [188.216.41.250]) by smtp.gmail.com with ESMTPSA id x21sm8551210eds.53.2021.03.15.13.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Mar 2021 13:03:46 -0700 (PDT) From: Matteo Croce To: linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Lennart Poettering , Luca Boccassi , Jens Axboe , Alexander Viro , Damien Le Moal , Tejun Heo , =?utf-8?q?Javier_Gonz=C3=A1lez?= , Niklas Cassel , Johannes Thumshirn , Hannes Reinecke Subject: [PATCH -next 5/5] loop: increment sequence number Date: Mon, 15 Mar 2021 21:02:42 +0100 Message-Id: <20210315200242.67355-6-mcroce@linux.microsoft.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315200242.67355-1-mcroce@linux.microsoft.com> References: <20210315200242.67355-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. [1] https://github.com/systemd/systemd/issues/17469#issuecomment-762919781 Signed-off-by: Matteo Croce --- drivers/block/loop.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index a370cde3ddd4..1541ccff81f9 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -734,6 +734,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; @@ -1122,6 +1123,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;